Package org.waveprotocol.wave.diff.proto

Source Code of org.waveprotocol.wave.diff.proto.WaveletDiffSnapshotProtoImpl

/**
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.waveprotocol.wave.diff.proto;

import org.waveprotocol.wave.diff.DocumentDiffSnapshot;
import org.waveprotocol.wave.federation.ProtocolHashedVersion;
import org.waveprotocol.wave.diff.proto.DocumentDiffSnapshotProtoImpl;
import org.waveprotocol.wave.federation.proto.ProtocolHashedVersionProtoImpl;
import org.waveprotocol.wave.diff.WaveletDiffSnapshot;
import org.waveprotocol.wave.diff.WaveletDiffSnapshotUtil;
import org.waveprotocol.wave.communication.Blob;
import org.waveprotocol.wave.communication.Codec;
import org.waveprotocol.wave.communication.ProtoEnums;
import org.waveprotocol.wave.communication.proto.Int52;
import org.waveprotocol.wave.communication.proto.ProtoWrapper;
import org.waveprotocol.wave.communication.gson.GsonException;
import org.waveprotocol.wave.communication.gson.GsonSerializable;
import org.waveprotocol.wave.communication.gson.GsonUtil;
import org.waveprotocol.wave.communication.json.RawStringData;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Server implementation of WaveletDiffSnapshot.
*
* Generated from org/waveprotocol/wave/diff/diff.proto. Do not edit.
*/
// NOTE(kalman): It would be nicer to add a proto serialisation
// utility rather than having this class at all.
public final class WaveletDiffSnapshotProtoImpl
    implements WaveletDiffSnapshot,
// Note: fully-qualified path is required for GsonSerializable and ProtoWrapper.
// An import of it is not resolved correctly from inner classes.
// This appears to be a javac bug. The Eclipse compiler handles it fine.
org.waveprotocol.wave.communication.gson.GsonSerializable,
org.waveprotocol.wave.communication.proto.ProtoWrapper<org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot> {
  private org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot proto = null;
  private org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot.Builder protoBuilder = org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot.newBuilder();
  public WaveletDiffSnapshotProtoImpl() {
  }

  public WaveletDiffSnapshotProtoImpl(org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot proto) {
    this.proto = proto;
  }

  public WaveletDiffSnapshotProtoImpl(WaveletDiffSnapshot message) {
    copyFrom(message);
  }

  @Override
  public org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot getPB() {
    switchToProto();
    return proto;
  }

  @Override
  public void setPB(org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot proto) {
    this.proto = proto;
    this.protoBuilder = null;
  }

  @Override
  public void copyFrom(WaveletDiffSnapshot message) {
    setWaveletId(message.getWaveletId());
    clearParticipant();
    for (String field : message.getParticipant()) {
      addParticipant(field);
    }
    clearAddedParticipant();
    for (String field : message.getAddedParticipant()) {
      addAddedParticipant(field);
    }
    clearRemovedParticipant();
    for (String field : message.getRemovedParticipant()) {
      addRemovedParticipant(field);
    }
    clearDocument();
    for (DocumentDiffSnapshot field : message.getDocument()) {
      addDocument(new DocumentDiffSnapshotProtoImpl(field));
    }
    setVersion(new ProtocolHashedVersionProtoImpl(message.getVersion()));
    setLastModifiedTime(message.getLastModifiedTime());
    setCreator(message.getCreator());
    setCreationTime(message.getCreationTime());
  }

  @Override
  public String getWaveletId() {
    switchToProto();
    return proto.getWaveletId();
  }

  @Override
  public void setWaveletId(String value) {
    switchToProtoBuilder();
    protoBuilder.setWaveletId(value);
  }

  @Override
  public List<String> getParticipant() {
    switchToProto();
    return Collections.unmodifiableList(proto.getParticipantList());
  }

  @Override
  public void addAllParticipant(List<String> values) {
    switchToProtoBuilder();
    protoBuilder.addAllParticipant(values);
  }

  @Override
  public String getParticipant(int n) {
    switchToProto();
    return proto.getParticipant(n);
  }

  @Override
  public void setParticipant(int n, String value) {
    switchToProtoBuilder();
    protoBuilder.setParticipant(n, value);
  }

  @Override
  public int getParticipantSize() {
    switchToProto();
    return proto.getParticipantCount();
  }

  @Override
  public void addParticipant(String value) {
    switchToProtoBuilder();
    protoBuilder.addParticipant(value);
  }

  @Override
  public void clearParticipant() {
    switchToProtoBuilder();
    protoBuilder.clearParticipant();
  }

  @Override
  public List<String> getAddedParticipant() {
    switchToProto();
    return Collections.unmodifiableList(proto.getAddedParticipantList());
  }

  @Override
  public void addAllAddedParticipant(List<String> values) {
    switchToProtoBuilder();
    protoBuilder.addAllAddedParticipant(values);
  }

  @Override
  public String getAddedParticipant(int n) {
    switchToProto();
    return proto.getAddedParticipant(n);
  }

  @Override
  public void setAddedParticipant(int n, String value) {
    switchToProtoBuilder();
    protoBuilder.setAddedParticipant(n, value);
  }

  @Override
  public int getAddedParticipantSize() {
    switchToProto();
    return proto.getAddedParticipantCount();
  }

  @Override
  public void addAddedParticipant(String value) {
    switchToProtoBuilder();
    protoBuilder.addAddedParticipant(value);
  }

  @Override
  public void clearAddedParticipant() {
    switchToProtoBuilder();
    protoBuilder.clearAddedParticipant();
  }

  @Override
  public List<String> getRemovedParticipant() {
    switchToProto();
    return Collections.unmodifiableList(proto.getRemovedParticipantList());
  }

  @Override
  public void addAllRemovedParticipant(List<String> values) {
    switchToProtoBuilder();
    protoBuilder.addAllRemovedParticipant(values);
  }

  @Override
  public String getRemovedParticipant(int n) {
    switchToProto();
    return proto.getRemovedParticipant(n);
  }

  @Override
  public void setRemovedParticipant(int n, String value) {
    switchToProtoBuilder();
    protoBuilder.setRemovedParticipant(n, value);
  }

  @Override
  public int getRemovedParticipantSize() {
    switchToProto();
    return proto.getRemovedParticipantCount();
  }

  @Override
  public void addRemovedParticipant(String value) {
    switchToProtoBuilder();
    protoBuilder.addRemovedParticipant(value);
  }

  @Override
  public void clearRemovedParticipant() {
    switchToProtoBuilder();
    protoBuilder.clearRemovedParticipant();
  }

  @Override
  public List<DocumentDiffSnapshotProtoImpl> getDocument() {
    switchToProto();
    List<DocumentDiffSnapshotProtoImpl> list = new ArrayList<DocumentDiffSnapshotProtoImpl>();
    for (int i = 0; i < getDocumentSize(); i++) {
      DocumentDiffSnapshotProtoImpl message = new DocumentDiffSnapshotProtoImpl(proto.getDocument(i));
      list.add(message);
    }
    return list;
  }

  @Override
  public void addAllDocument(List<? extends DocumentDiffSnapshot> values) {
    for (DocumentDiffSnapshot message : values) {
      addDocument(message);
    }
  }

  @Override
  public DocumentDiffSnapshotProtoImpl getDocument(int n) {
    switchToProto();
    return new DocumentDiffSnapshotProtoImpl(proto.getDocument(n));
  }

  @Override
  public void setDocument(int n, DocumentDiffSnapshot value) {
    switchToProtoBuilder();
    protoBuilder.setDocument(n, getOrCreateDocumentDiffSnapshotProtoImpl(value).getPB());
  }

  @Override
  public int getDocumentSize() {
    switchToProto();
    return proto.getDocumentCount();
  }

  @Override
  public void addDocument(DocumentDiffSnapshot value) {
    switchToProtoBuilder();
    protoBuilder.addDocument(getOrCreateDocumentDiffSnapshotProtoImpl(value).getPB());
  }

  @Override
  public void clearDocument() {
    switchToProtoBuilder();
    protoBuilder.clearDocument();
  }

  @Override
  public ProtocolHashedVersionProtoImpl getVersion() {
    switchToProto();
    return new ProtocolHashedVersionProtoImpl(proto.getVersion());
  }

  @Override
  public void setVersion(ProtocolHashedVersion value) {
    switchToProtoBuilder();
    protoBuilder.clearVersion();
    protoBuilder.setVersion(getOrCreateProtocolHashedVersionProtoImpl(value).getPB());
  }

  @Override
  public double getLastModifiedTime() {
    switchToProto();
    return proto.getLastModifiedTime();
  }

  @Override
  public void setLastModifiedTime(double value) {
    switchToProtoBuilder();
    protoBuilder.setLastModifiedTime(Int52.int52to64(value));
  }

  @Override
  public String getCreator() {
    switchToProto();
    return proto.getCreator();
  }

  @Override
  public void setCreator(String value) {
    switchToProtoBuilder();
    protoBuilder.setCreator(value);
  }

  @Override
  public double getCreationTime() {
    switchToProto();
    return proto.getCreationTime();
  }

  @Override
  public void setCreationTime(double value) {
    switchToProtoBuilder();
    protoBuilder.setCreationTime(Int52.int52to64(value));
  }

  /** Get or create a DocumentDiffSnapshotProtoImpl from a DocumentDiffSnapshot. */
  private DocumentDiffSnapshotProtoImpl getOrCreateDocumentDiffSnapshotProtoImpl(DocumentDiffSnapshot message) {
    if (message instanceof DocumentDiffSnapshotProtoImpl) {
      return (DocumentDiffSnapshotProtoImpl) message;
    } else {
      DocumentDiffSnapshotProtoImpl messageImpl = new DocumentDiffSnapshotProtoImpl();
      messageImpl.copyFrom(message);
      return messageImpl;
    }
  }

  /** Get or create a ProtocolHashedVersionProtoImpl from a ProtocolHashedVersion. */
  private ProtocolHashedVersionProtoImpl getOrCreateProtocolHashedVersionProtoImpl(ProtocolHashedVersion message) {
    if (message instanceof ProtocolHashedVersionProtoImpl) {
      return (ProtocolHashedVersionProtoImpl) message;
    } else {
      ProtocolHashedVersionProtoImpl messageImpl = new ProtocolHashedVersionProtoImpl();
      messageImpl.copyFrom(message);
      return messageImpl;
    }
  }

  private void switchToProto() {
    if (proto == null) {
      proto = protoBuilder.build();
      protoBuilder = null;
    }
  }

  private void switchToProtoBuilder() {
    if (protoBuilder == null) {
      protoBuilder = (proto == null)
          ? org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot.newBuilder()
          : org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot.newBuilder(proto);
      proto = null;
    }
  }

  private void invalidateAll() {
    proto = null;
    protoBuilder = org.waveprotocol.wave.diff.Diff.WaveletDiffSnapshot.newBuilder();
  }

  @Override
  public JsonElement toGson(RawStringData raw, Gson gson) {
    JsonObject json = new JsonObject();
    json.add("1", new JsonPrimitive(getWaveletId()));
    {
      JsonArray array = new JsonArray();
      for (int i = 0; i < getParticipantSize(); i++) {
        array.add(new JsonPrimitive(getParticipant(i)));
      }
      json.add("2", array);
    }
    {
      JsonArray array = new JsonArray();
      for (int i = 0; i < getAddedParticipantSize(); i++) {
        array.add(new JsonPrimitive(getAddedParticipant(i)));
      }
      json.add("21", array);
    }
    {
      JsonArray array = new JsonArray();
      for (int i = 0; i < getRemovedParticipantSize(); i++) {
        array.add(new JsonPrimitive(getRemovedParticipant(i)));
      }
      json.add("22", array);
    }
    {
      JsonArray array = new JsonArray();
      for (int i = 0; i < getDocumentSize(); i++) {
        JsonElement elem = ((GsonSerializable) getDocument(i)).toGson(raw, gson);
        // NOTE(kalman): if multistage parsing worked, split point would go here.
        array.add(elem);
      }
      json.add("3", array);
    }
    {
      JsonElement elem = ((GsonSerializable) getVersion()).toGson(raw, gson);
      json.add("4", elem);
    }
    json.add("5", new JsonPrimitive(getLastModifiedTime()));
    json.add("6", new JsonPrimitive(getCreator()));
    json.add("7", new JsonPrimitive(getCreationTime()));
    return json;
  }

  @Override
  public void fromGson(JsonElement json, Gson gson, RawStringData raw) throws GsonException {
    JsonObject jsonObject = json.getAsJsonObject();
    // NOTE: always check with has(...) as the json might not have all required
    // fields set; however these (obviously) will need to be set by other means
    // before accessing this object.
    invalidateAll();
    if (jsonObject.has("1")) {
      JsonElement elem = jsonObject.get("1");
      setWaveletId(elem.getAsString());
    }
    if (jsonObject.has("2")) {
      JsonElement elem = jsonObject.get("2");
      {
        JsonArray array = elem.getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
          addParticipant(array.get(i).getAsString());
        }
      }
    }
    if (jsonObject.has("21")) {
      JsonElement elem = jsonObject.get("21");
      {
        JsonArray array = elem.getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
          addAddedParticipant(array.get(i).getAsString());
        }
      }
    }
    if (jsonObject.has("22")) {
      JsonElement elem = jsonObject.get("22");
      {
        JsonArray array = elem.getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
          addRemovedParticipant(array.get(i).getAsString());
        }
      }
    }
    if (jsonObject.has("3")) {
      JsonElement elem = jsonObject.get("3");
      {
        JsonArray array = elem.getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
          DocumentDiffSnapshotProtoImpl payload = new DocumentDiffSnapshotProtoImpl();
          GsonUtil.extractJsonObject(payload, array.get(i), gson, raw);
          addDocument(payload);
        }
      }
    }
    if (jsonObject.has("4")) {
      JsonElement elem = jsonObject.get("4");
      {
        ProtocolHashedVersionProtoImpl payload = new ProtocolHashedVersionProtoImpl();
        GsonUtil.extractJsonObject(payload, elem, gson, raw);
        setVersion(payload);
      }
    }
    if (jsonObject.has("5")) {
      JsonElement elem = jsonObject.get("5");
      setLastModifiedTime(elem.getAsDouble());
    }
    if (jsonObject.has("6")) {
      JsonElement elem = jsonObject.get("6");
      setCreator(elem.getAsString());
    }
    if (jsonObject.has("7")) {
      JsonElement elem = jsonObject.get("7");
      setCreationTime(elem.getAsDouble());
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    } else if (o instanceof WaveletDiffSnapshotProtoImpl) {
      return getPB().equals(((WaveletDiffSnapshotProtoImpl) o).getPB());
    } else {
      return false;
    }
  }

  @Override
  public boolean isEqualTo(Object o) {
    if (equals(o)) {
      return true;
    } else if (o instanceof WaveletDiffSnapshot) {
      return WaveletDiffSnapshotUtil.isEqual(this, (WaveletDiffSnapshot) o);
    } else {
      return false;
    }
  }

  @Override
  public int hashCode() {
    return getPB().hashCode();
  }

  @Override
  public String toString() {
    return getPB().toString();
  }

}
TOP

Related Classes of org.waveprotocol.wave.diff.proto.WaveletDiffSnapshotProtoImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.