/**
* 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.box.profile.proto;
import org.waveprotocol.box.profile.ProfileResponse.FetchedProfile;
import org.waveprotocol.box.profile.proto.ProfileResponseProtoImpl.FetchedProfileProtoImpl;
import org.waveprotocol.box.profile.ProfileResponse;
import org.waveprotocol.box.profile.ProfileResponseUtil;
import org.waveprotocol.box.profile.ProfileResponse.FetchedProfile;
import org.waveprotocol.box.profile.ProfileResponseUtil.FetchedProfileUtil;
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 ProfileResponse.
*
* Generated from org/waveprotocol/box/profile/profiles.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 ProfileResponseProtoImpl
implements ProfileResponse,
// 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.box.profile.ProfilesProto.ProfileResponse> {
// NOTE(kalman): It would be nicer to add a proto serialisation
// utility rather than having this class at all.
public static final class FetchedProfileProtoImpl
implements FetchedProfile,
// 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.box.profile.ProfilesProto.ProfileResponse.FetchedProfile> {
private org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile proto = null;
private org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile.Builder protoBuilder = org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile.newBuilder();
public FetchedProfileProtoImpl() {
}
public FetchedProfileProtoImpl(org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile proto) {
this.proto = proto;
}
public FetchedProfileProtoImpl(FetchedProfile message) {
copyFrom(message);
}
@Override
public org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile getPB() {
switchToProto();
return proto;
}
@Override
public void setPB(org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile proto) {
this.proto = proto;
this.protoBuilder = null;
}
@Override
public void copyFrom(FetchedProfile message) {
setAddress(message.getAddress());
setName(message.getName());
setImageUrl(message.getImageUrl());
if (message.hasProfileUrl()) {
setProfileUrl(message.getProfileUrl());
} else {
clearProfileUrl();
}
}
@Override
public String getAddress() {
switchToProto();
return proto.getAddress();
}
@Override
public void setAddress(String value) {
switchToProtoBuilder();
protoBuilder.setAddress(value);
}
@Override
public String getName() {
switchToProto();
return proto.getName();
}
@Override
public void setName(String value) {
switchToProtoBuilder();
protoBuilder.setName(value);
}
@Override
public String getImageUrl() {
switchToProto();
return proto.getImageUrl();
}
@Override
public void setImageUrl(String value) {
switchToProtoBuilder();
protoBuilder.setImageUrl(value);
}
@Override
public boolean hasProfileUrl() {
switchToProto();
return proto.hasProfileUrl();
}
@Override
public void clearProfileUrl() {
switchToProtoBuilder();
protoBuilder.clearProfileUrl();
}
@Override
public String getProfileUrl() {
switchToProto();
return proto.getProfileUrl();
}
@Override
public void setProfileUrl(String value) {
switchToProtoBuilder();
protoBuilder.setProfileUrl(value);
}
private void switchToProto() {
if (proto == null) {
proto = protoBuilder.build();
protoBuilder = null;
}
}
private void switchToProtoBuilder() {
if (protoBuilder == null) {
protoBuilder = (proto == null)
? org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile.newBuilder()
: org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile.newBuilder(proto);
proto = null;
}
}
private void invalidateAll() {
proto = null;
protoBuilder = org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.FetchedProfile.newBuilder();
}
@Override
public JsonElement toGson(RawStringData raw, Gson gson) {
JsonObject json = new JsonObject();
json.add("1", new JsonPrimitive(getAddress()));
json.add("2", new JsonPrimitive(getName()));
json.add("3", new JsonPrimitive(getImageUrl()));
if (hasProfileUrl()) {
json.add("4", new JsonPrimitive(getProfileUrl()));
}
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");
setAddress(elem.getAsString());
}
if (jsonObject.has("2")) {
JsonElement elem = jsonObject.get("2");
setName(elem.getAsString());
}
if (jsonObject.has("3")) {
JsonElement elem = jsonObject.get("3");
setImageUrl(elem.getAsString());
}
if (jsonObject.has("4")) {
JsonElement elem = jsonObject.get("4");
if (!elem.isJsonNull()) {
setProfileUrl(elem.getAsString());
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof FetchedProfileProtoImpl) {
return getPB().equals(((FetchedProfileProtoImpl) o).getPB());
} else {
return false;
}
}
@Override
public boolean isEqualTo(Object o) {
if (equals(o)) {
return true;
} else if (o instanceof FetchedProfile) {
return FetchedProfileUtil.isEqual(this, (FetchedProfile) o);
} else {
return false;
}
}
@Override
public int hashCode() {
return getPB().hashCode();
}
@Override
public String toString() {
return getPB().toString();
}
}
private org.waveprotocol.box.profile.ProfilesProto.ProfileResponse proto = null;
private org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.Builder protoBuilder = org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.newBuilder();
public ProfileResponseProtoImpl() {
}
public ProfileResponseProtoImpl(org.waveprotocol.box.profile.ProfilesProto.ProfileResponse proto) {
this.proto = proto;
}
public ProfileResponseProtoImpl(ProfileResponse message) {
copyFrom(message);
}
@Override
public org.waveprotocol.box.profile.ProfilesProto.ProfileResponse getPB() {
switchToProto();
return proto;
}
@Override
public void setPB(org.waveprotocol.box.profile.ProfilesProto.ProfileResponse proto) {
this.proto = proto;
this.protoBuilder = null;
}
@Override
public void copyFrom(ProfileResponse message) {
clearProfiles();
for (FetchedProfile field : message.getProfiles()) {
addProfiles(new FetchedProfileProtoImpl(field));
}
}
@Override
public List<FetchedProfileProtoImpl> getProfiles() {
switchToProto();
List<FetchedProfileProtoImpl> list = new ArrayList<FetchedProfileProtoImpl>();
for (int i = 0; i < getProfilesSize(); i++) {
FetchedProfileProtoImpl message = new FetchedProfileProtoImpl(proto.getProfiles(i));
list.add(message);
}
return list;
}
@Override
public void addAllProfiles(List<? extends FetchedProfile> values) {
for (FetchedProfile message : values) {
addProfiles(message);
}
}
@Override
public FetchedProfileProtoImpl getProfiles(int n) {
switchToProto();
return new FetchedProfileProtoImpl(proto.getProfiles(n));
}
@Override
public void setProfiles(int n, FetchedProfile value) {
switchToProtoBuilder();
protoBuilder.setProfiles(n, getOrCreateFetchedProfileProtoImpl(value).getPB());
}
@Override
public int getProfilesSize() {
switchToProto();
return proto.getProfilesCount();
}
@Override
public void addProfiles(FetchedProfile value) {
switchToProtoBuilder();
protoBuilder.addProfiles(getOrCreateFetchedProfileProtoImpl(value).getPB());
}
@Override
public void clearProfiles() {
switchToProtoBuilder();
protoBuilder.clearProfiles();
}
/** Get or create a FetchedProfileProtoImpl from a FetchedProfile. */
private FetchedProfileProtoImpl getOrCreateFetchedProfileProtoImpl(FetchedProfile message) {
if (message instanceof FetchedProfileProtoImpl) {
return (FetchedProfileProtoImpl) message;
} else {
FetchedProfileProtoImpl messageImpl = new FetchedProfileProtoImpl();
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.box.profile.ProfilesProto.ProfileResponse.newBuilder()
: org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.newBuilder(proto);
proto = null;
}
}
private void invalidateAll() {
proto = null;
protoBuilder = org.waveprotocol.box.profile.ProfilesProto.ProfileResponse.newBuilder();
}
@Override
public JsonElement toGson(RawStringData raw, Gson gson) {
JsonObject json = new JsonObject();
{
JsonArray array = new JsonArray();
for (int i = 0; i < getProfilesSize(); i++) {
JsonElement elem = ((GsonSerializable) getProfiles(i)).toGson(raw, gson);
// NOTE(kalman): if multistage parsing worked, split point would go here.
array.add(elem);
}
json.add("1", array);
}
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");
{
JsonArray array = elem.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
FetchedProfileProtoImpl payload = new FetchedProfileProtoImpl();
GsonUtil.extractJsonObject(payload, array.get(i), gson, raw);
addProfiles(payload);
}
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof ProfileResponseProtoImpl) {
return getPB().equals(((ProfileResponseProtoImpl) o).getPB());
} else {
return false;
}
}
@Override
public boolean isEqualTo(Object o) {
if (equals(o)) {
return true;
} else if (o instanceof ProfileResponse) {
return ProfileResponseUtil.isEqual(this, (ProfileResponse) o);
} else {
return false;
}
}
@Override
public int hashCode() {
return getPB().hashCode();
}
@Override
public String toString() {
return getPB().toString();
}
}