Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.concurrencycontrol.proto; /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import org.waveprotocol.wave.concurrencycontrol.ResponseStatus; import org.waveprotocol.wave.federation.ProtocolHashedVersion; import org.waveprotocol.wave.concurrencycontrol.proto.ResponseStatusProtoImpl; import org.waveprotocol.wave.federation.proto.ProtocolHashedVersionProtoImpl; /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import org.waveprotocol.wave.concurrencycontrol.SubmitDeltaResponse; import org.waveprotocol.wave.concurrencycontrol.SubmitDeltaResponseUtil; 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 SubmitDeltaResponse. * * Generated from org/waveprotocol/wave/concurrencycontrol/clientserver.proto. Do not edit. */ /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ // NOTE(kalman): It would be nicer to add a proto serialisation // utility rather than having this class at all. public final class SubmitDeltaResponseProtoImpl implements SubmitDeltaResponse, // 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.concurrencycontrol.ClientServer.SubmitDeltaResponse> { private org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse proto = null; private org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse.Builder protoBuilder = org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse .newBuilder(); public SubmitDeltaResponseProtoImpl() { } public SubmitDeltaResponseProtoImpl( org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse proto) { this.proto = proto; } public SubmitDeltaResponseProtoImpl(SubmitDeltaResponse message) { copyFrom(message); } @Override public org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse getPB() { switchToProto(); return proto; } @Override public void setPB(org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse proto) { this.proto = proto; this.protoBuilder = null; } @Override public void copyFrom(SubmitDeltaResponse message) { /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ setStatus(new ResponseStatusProtoImpl(message.getStatus())); /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ setOperationsApplied(message.getOperationsApplied()); /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (message.hasHashedVersionAfterApplication()) { setHashedVersionAfterApplication( new ProtocolHashedVersionProtoImpl(message.getHashedVersionAfterApplication())); } else { clearHashedVersionAfterApplication(); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (message.hasTimestampAfterApplication()) { setTimestampAfterApplication(message.getTimestampAfterApplication()); } else { clearTimestampAfterApplication(); } } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public ResponseStatusProtoImpl getStatus() { switchToProto(); return new ResponseStatusProtoImpl(proto.getStatus()); } @Override public void setStatus(ResponseStatus value) { switchToProtoBuilder(); protoBuilder.clearStatus(); protoBuilder.setStatus(getOrCreateResponseStatusProtoImpl(value).getPB()); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public int getOperationsApplied() { switchToProto(); return proto.getOperationsApplied(); } @Override public void setOperationsApplied(int value) { switchToProtoBuilder(); protoBuilder.setOperationsApplied(value); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public boolean hasHashedVersionAfterApplication() { switchToProto(); return proto.hasHashedVersionAfterApplication(); } @Override public void clearHashedVersionAfterApplication() { switchToProtoBuilder(); protoBuilder.clearHashedVersionAfterApplication(); } @Override public ProtocolHashedVersionProtoImpl getHashedVersionAfterApplication() { switchToProto(); return new ProtocolHashedVersionProtoImpl(proto.getHashedVersionAfterApplication()); } @Override public void setHashedVersionAfterApplication(ProtocolHashedVersion value) { switchToProtoBuilder(); protoBuilder.clearHashedVersionAfterApplication(); protoBuilder.setHashedVersionAfterApplication(getOrCreateProtocolHashedVersionProtoImpl(value).getPB()); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ @Override public boolean hasTimestampAfterApplication() { switchToProto(); return proto.hasTimestampAfterApplication(); } @Override public void clearTimestampAfterApplication() { switchToProtoBuilder(); protoBuilder.clearTimestampAfterApplication(); } @Override public long getTimestampAfterApplication() { switchToProto(); return proto.getTimestampAfterApplication(); } @Override public void setTimestampAfterApplication(long value) { switchToProtoBuilder(); protoBuilder.setTimestampAfterApplication(value); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** Get or create a ResponseStatusProtoImpl from a ResponseStatus. */ private ResponseStatusProtoImpl getOrCreateResponseStatusProtoImpl(ResponseStatus message) { if (message instanceof ResponseStatusProtoImpl) { return (ResponseStatusProtoImpl) message; } else { ResponseStatusProtoImpl messageImpl = new ResponseStatusProtoImpl(); messageImpl.copyFrom(message); return messageImpl; } } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** 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.concurrencycontrol.ClientServer.SubmitDeltaResponse.newBuilder() : org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse.newBuilder(proto); proto = null; } } private void invalidateAll() { proto = null; protoBuilder = org.waveprotocol.wave.concurrencycontrol.ClientServer.SubmitDeltaResponse.newBuilder(); } @Override public JsonElement toGson(RawStringData raw, Gson gson) { JsonObject json = new JsonObject(); /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ { JsonElement elem = ((GsonSerializable) getStatus()).toGson(raw, gson); json.add("1", elem); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ json.add("2", new JsonPrimitive(getOperationsApplied())); /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (hasHashedVersionAfterApplication()) { { JsonElement elem = ((GsonSerializable) getHashedVersionAfterApplication()).toGson(raw, gson); json.add("3", elem); } } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (hasTimestampAfterApplication()) { json.add("4", GsonUtil.toJson(getTimestampAfterApplication())); } 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(); /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (jsonObject.has("1")) { JsonElement elem = jsonObject.get("1"); { ResponseStatusProtoImpl payload = new ResponseStatusProtoImpl(); GsonUtil.extractJsonObject(payload, elem, gson, raw); setStatus(payload); } } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (jsonObject.has("2")) { JsonElement elem = jsonObject.get("2"); setOperationsApplied(elem.getAsInt()); } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (jsonObject.has("3")) { JsonElement elem = jsonObject.get("3"); if (!elem.isJsonNull()) { { ProtocolHashedVersionProtoImpl payload = new ProtocolHashedVersionProtoImpl(); GsonUtil.extractJsonObject(payload, elem, gson, raw); setHashedVersionAfterApplication(payload); } } } /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ if (jsonObject.has("4")) { JsonElement elem = jsonObject.get("4"); if (!elem.isJsonNull()) { setTimestampAfterApplication(GsonUtil.fromJson(elem)); } } } @Override public boolean equals(Object o) { if (this == o) { return true; } else if (o instanceof SubmitDeltaResponseProtoImpl) { return getPB().equals(((SubmitDeltaResponseProtoImpl) o).getPB()); } else { return false; } } @Override public boolean isEqualTo(Object o) { if (equals(o)) { return true; } else if (o instanceof SubmitDeltaResponse) { return SubmitDeltaResponseUtil.isEqual(this, (SubmitDeltaResponse) o); } else { return false; } } @Override public int hashCode() { return getPB().hashCode(); } @Override public String toString() { return getPB().toString(); } }