org.waveprotocol.wave.federation.proto.ProtocolWaveletOperationProtoImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.waveprotocol.wave.federation.proto.ProtocolWaveletOperationProtoImpl.java

Source

/**
 * 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.federation.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.federation.ProtocolWaveletOperation.MutateDocument;
import org.waveprotocol.wave.federation.ProtocolDocumentOperation;
import org.waveprotocol.wave.federation.proto.ProtocolWaveletOperationProtoImpl.MutateDocumentProtoImpl;
import org.waveprotocol.wave.federation.proto.ProtocolDocumentOperationProtoImpl;

/**
 * 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.federation.ProtocolWaveletOperation;
import org.waveprotocol.wave.federation.ProtocolWaveletOperationUtil;

/**
 * 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.federation.ProtocolWaveletOperation.MutateDocument;
import org.waveprotocol.wave.federation.ProtocolWaveletOperationUtil.MutateDocumentUtil;
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 ProtocolWaveletOperation.
 *
 * Generated from org/waveprotocol/wave/federation/federation.protodevel. 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 ProtocolWaveletOperationProtoImpl implements ProtocolWaveletOperation,
        // 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.federation.Proto.ProtocolWaveletOperation> {

    /**
     * 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 static final class MutateDocumentProtoImpl implements MutateDocument,
            // 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.federation.Proto.ProtocolWaveletOperation.MutateDocument> {
        private org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument proto = null;
        private org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument.Builder protoBuilder = org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument
                .newBuilder();

        public MutateDocumentProtoImpl() {
        }

        public MutateDocumentProtoImpl(
                org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument proto) {
            this.proto = proto;
        }

        public MutateDocumentProtoImpl(MutateDocument message) {
            copyFrom(message);
        }

        @Override
        public org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument getPB() {
            switchToProto();
            return proto;
        }

        @Override
        public void setPB(org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument proto) {
            this.proto = proto;
            this.protoBuilder = null;
        }

        @Override
        public void copyFrom(MutateDocument 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.
             */
            setDocumentId(message.getDocumentId());

            /**
             * 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.
             */
            setDocumentOperation(new ProtocolDocumentOperationProtoImpl(message.getDocumentOperation()));
        }

        /**
         * 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 String getDocumentId() {
            switchToProto();
            return proto.getDocumentId();
        }

        @Override
        public void setDocumentId(String value) {
            switchToProtoBuilder();
            protoBuilder.setDocumentId(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 ProtocolDocumentOperationProtoImpl getDocumentOperation() {
            switchToProto();
            return new ProtocolDocumentOperationProtoImpl(proto.getDocumentOperation());
        }

        @Override
        public void setDocumentOperation(ProtocolDocumentOperation value) {
            switchToProtoBuilder();
            protoBuilder.clearDocumentOperation();
            protoBuilder.setDocumentOperation(getOrCreateProtocolDocumentOperationProtoImpl(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.
         */

        /** Get or create a ProtocolDocumentOperationProtoImpl from a ProtocolDocumentOperation. */
        private ProtocolDocumentOperationProtoImpl getOrCreateProtocolDocumentOperationProtoImpl(
                ProtocolDocumentOperation message) {
            if (message instanceof ProtocolDocumentOperationProtoImpl) {
                return (ProtocolDocumentOperationProtoImpl) message;
            } else {
                ProtocolDocumentOperationProtoImpl messageImpl = new ProtocolDocumentOperationProtoImpl();
                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.federation.Proto.ProtocolWaveletOperation.MutateDocument
                                .newBuilder()
                        : org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument
                                .newBuilder(proto);
                proto = null;
            }
        }

        private void invalidateAll() {
            proto = null;
            protoBuilder = org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.MutateDocument
                    .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.
             */
            json.add("1", new JsonPrimitive(getDocumentId()));

            /**
             * 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) getDocumentOperation()).toGson(raw, gson);
                json.add("2", elem);
            }
            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");
                setDocumentId(elem.getAsString());
            }

            /**
             * 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");
                {
                    ProtocolDocumentOperationProtoImpl payload = new ProtocolDocumentOperationProtoImpl();
                    GsonUtil.extractJsonObject(payload, elem, gson, raw);
                    setDocumentOperation(payload);
                }
            }
        }

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

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

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

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

    }

    private org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation proto = null;
    private org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.Builder protoBuilder = org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation
            .newBuilder();

    public ProtocolWaveletOperationProtoImpl() {
    }

    public ProtocolWaveletOperationProtoImpl(
            org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation proto) {
        this.proto = proto;
    }

    public ProtocolWaveletOperationProtoImpl(ProtocolWaveletOperation message) {
        copyFrom(message);
    }

    @Override
    public org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation getPB() {
        switchToProto();
        return proto;
    }

    @Override
    public void setPB(org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation proto) {
        this.proto = proto;
        this.protoBuilder = null;
    }

    @Override
    public void copyFrom(ProtocolWaveletOperation 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.
         */
        if (message.hasAddParticipant()) {
            setAddParticipant(message.getAddParticipant());
        } else {
            clearAddParticipant();
        }

        /**
         * 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.hasRemoveParticipant()) {
            setRemoveParticipant(message.getRemoveParticipant());
        } else {
            clearRemoveParticipant();
        }

        /**
         * 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.hasMutateDocument()) {
            setMutateDocument(new MutateDocumentProtoImpl(message.getMutateDocument()));
        } else {
            clearMutateDocument();
        }

        /**
         * 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.hasNoOp()) {
            setNoOp(message.getNoOp());
        } else {
            clearNoOp();
        }
    }

    /**
     * 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 hasAddParticipant() {
        switchToProto();
        return proto.hasAddParticipant();
    }

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

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

    @Override
    public void setAddParticipant(String value) {
        switchToProtoBuilder();
        protoBuilder.setAddParticipant(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 hasRemoveParticipant() {
        switchToProto();
        return proto.hasRemoveParticipant();
    }

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

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

    @Override
    public void setRemoveParticipant(String value) {
        switchToProtoBuilder();
        protoBuilder.setRemoveParticipant(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 hasMutateDocument() {
        switchToProto();
        return proto.hasMutateDocument();
    }

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

    @Override
    public MutateDocumentProtoImpl getMutateDocument() {
        switchToProto();
        return new MutateDocumentProtoImpl(proto.getMutateDocument());
    }

    @Override
    public void setMutateDocument(MutateDocument value) {
        switchToProtoBuilder();
        protoBuilder.clearMutateDocument();
        protoBuilder.setMutateDocument(getOrCreateMutateDocumentProtoImpl(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 hasNoOp() {
        switchToProto();
        return proto.hasNoOp();
    }

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

    @Override
    public boolean getNoOp() {
        switchToProto();
        return proto.getNoOp();
    }

    @Override
    public void setNoOp(boolean value) {
        switchToProtoBuilder();
        protoBuilder.setNoOp(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 MutateDocumentProtoImpl from a MutateDocument. */
    private MutateDocumentProtoImpl getOrCreateMutateDocumentProtoImpl(MutateDocument message) {
        if (message instanceof MutateDocumentProtoImpl) {
            return (MutateDocumentProtoImpl) message;
        } else {
            MutateDocumentProtoImpl messageImpl = new MutateDocumentProtoImpl();
            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 ProtocolDocumentOperationProtoImpl from a ProtocolDocumentOperation. */
    private ProtocolDocumentOperationProtoImpl getOrCreateProtocolDocumentOperationProtoImpl(
            ProtocolDocumentOperation message) {
        if (message instanceof ProtocolDocumentOperationProtoImpl) {
            return (ProtocolDocumentOperationProtoImpl) message;
        } else {
            ProtocolDocumentOperationProtoImpl messageImpl = new ProtocolDocumentOperationProtoImpl();
            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.federation.Proto.ProtocolWaveletOperation.newBuilder()
                    : org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.newBuilder(proto);
            proto = null;
        }
    }

    private void invalidateAll() {
        proto = null;
        protoBuilder = org.waveprotocol.wave.federation.Proto.ProtocolWaveletOperation.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.
         */
        if (hasAddParticipant()) {
            json.add("1", new JsonPrimitive(getAddParticipant()));
        }

        /**
         * 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 (hasRemoveParticipant()) {
            json.add("2", new JsonPrimitive(getRemoveParticipant()));
        }

        /**
         * 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 (hasMutateDocument()) {
            {
                JsonElement elem = ((GsonSerializable) getMutateDocument()).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 (hasNoOp()) {
            json.add("4", new JsonPrimitive(getNoOp()));
        }
        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");
            if (!elem.isJsonNull()) {
                setAddParticipant(elem.getAsString());
            }
        }

        /**
         * 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");
            if (!elem.isJsonNull()) {
                setRemoveParticipant(elem.getAsString());
            }
        }

        /**
         * 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()) {
                {
                    MutateDocumentProtoImpl payload = new MutateDocumentProtoImpl();
                    GsonUtil.extractJsonObject(payload, elem, gson, raw);
                    setMutateDocument(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()) {
                setNoOp(elem.getAsBoolean());
            }
        }
    }

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

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

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

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

}