org.waveprotocol.box.search.proto.SearchResponseProtoImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.waveprotocol.box.search.proto.SearchResponseProtoImpl.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.box.search.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.box.search.SearchResponse.Digest;
import org.waveprotocol.box.search.proto.SearchResponseProtoImpl.DigestProtoImpl;

/**
 * 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.box.search.SearchResponse;
import org.waveprotocol.box.search.SearchResponseUtil;

/**
 * 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.box.search.SearchResponse.Digest;
import org.waveprotocol.box.search.SearchResponseUtil.DigestUtil;
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 SearchResponse.
 *
 * Generated from org/waveprotocol/box/search/search.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 SearchResponseProtoImpl implements SearchResponse,
        // 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.search.SearchProto.SearchResponse> {

    /**
     * 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 DigestProtoImpl implements Digest,
            // 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.search.SearchProto.SearchResponse.Digest> {
        private org.waveprotocol.box.search.SearchProto.SearchResponse.Digest proto = null;
        private org.waveprotocol.box.search.SearchProto.SearchResponse.Digest.Builder protoBuilder = org.waveprotocol.box.search.SearchProto.SearchResponse.Digest
                .newBuilder();

        public DigestProtoImpl() {
        }

        public DigestProtoImpl(org.waveprotocol.box.search.SearchProto.SearchResponse.Digest proto) {
            this.proto = proto;
        }

        public DigestProtoImpl(Digest message) {
            copyFrom(message);
        }

        @Override
        public org.waveprotocol.box.search.SearchProto.SearchResponse.Digest getPB() {
            switchToProto();
            return proto;
        }

        @Override
        public void setPB(org.waveprotocol.box.search.SearchProto.SearchResponse.Digest proto) {
            this.proto = proto;
            this.protoBuilder = null;
        }

        @Override
        public void copyFrom(Digest 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.
             */
            setTitle(message.getTitle());

            /**
             * 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.
             */
            setSnippet(message.getSnippet());

            /**
             * 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.
             */
            setWaveId(message.getWaveId());

            /**
             * 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.
             */
            setLastModified(message.getLastModified());

            /**
             * 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.
             */
            setUnreadCount(message.getUnreadCount());

            /**
             * 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.
             */
            setBlipCount(message.getBlipCount());

            /**
             * 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.
             */
            clearParticipants();
            for (String field : message.getParticipants()) {
                addParticipants(field);
            }

            /**
             * 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.
             */
            setAuthor(message.getAuthor());
        }

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

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

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

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

        @Override
        public void setLastModified(long value) {
            switchToProtoBuilder();
            protoBuilder.setLastModified(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 int getUnreadCount() {
            switchToProto();
            return proto.getUnreadCount();
        }

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

        @Override
        public void setBlipCount(int value) {
            switchToProtoBuilder();
            protoBuilder.setBlipCount(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 List<String> getParticipants() {
            switchToProto();
            return Collections.unmodifiableList(proto.getParticipantsList());
        }

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

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

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

        @Override
        public int getParticipantsSize() {
            switchToProto();
            return proto.getParticipantsCount();
        }

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

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

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

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

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

        private void switchToProtoBuilder() {
            if (protoBuilder == null) {
                protoBuilder = (proto == null)
                        ? org.waveprotocol.box.search.SearchProto.SearchResponse.Digest.newBuilder()
                        : org.waveprotocol.box.search.SearchProto.SearchResponse.Digest.newBuilder(proto);
                proto = null;
            }
        }

        private void invalidateAll() {
            proto = null;
            protoBuilder = org.waveprotocol.box.search.SearchProto.SearchResponse.Digest.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(getTitle()));

            /**
             * 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(getSnippet()));

            /**
             * 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("3", new JsonPrimitive(getWaveId()));

            /**
             * 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("4", GsonUtil.toJson(getLastModified()));

            /**
             * 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("5", new JsonPrimitive(getUnreadCount()));

            /**
             * 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("6", new JsonPrimitive(getBlipCount()));

            /**
             * 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.
             */
            {
                JsonArray array = new JsonArray();
                for (int i = 0; i < getParticipantsSize(); i++) {
                    array.add(new JsonPrimitive(getParticipants(i)));
                }
                json.add("7", array);
            }

            /**
             * 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("8", new JsonPrimitive(getAuthor()));
            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");
                setTitle(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");
                setSnippet(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");
                setWaveId(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("4")) {
                JsonElement elem = jsonObject.get("4");
                setLastModified(GsonUtil.fromJson(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 (jsonObject.has("5")) {
                JsonElement elem = jsonObject.get("5");
                setUnreadCount(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("6")) {
                JsonElement elem = jsonObject.get("6");
                setBlipCount(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("7")) {
                JsonElement elem = jsonObject.get("7");
                {
                    JsonArray array = elem.getAsJsonArray();
                    for (int i = 0; i < array.size(); i++) {
                        addParticipants(array.get(i).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("8")) {
                JsonElement elem = jsonObject.get("8");
                setAuthor(elem.getAsString());
            }
        }

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

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

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

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

    }

    private org.waveprotocol.box.search.SearchProto.SearchResponse proto = null;
    private org.waveprotocol.box.search.SearchProto.SearchResponse.Builder protoBuilder = org.waveprotocol.box.search.SearchProto.SearchResponse
            .newBuilder();

    public SearchResponseProtoImpl() {
    }

    public SearchResponseProtoImpl(org.waveprotocol.box.search.SearchProto.SearchResponse proto) {
        this.proto = proto;
    }

    public SearchResponseProtoImpl(SearchResponse message) {
        copyFrom(message);
    }

    @Override
    public org.waveprotocol.box.search.SearchProto.SearchResponse getPB() {
        switchToProto();
        return proto;
    }

    @Override
    public void setPB(org.waveprotocol.box.search.SearchProto.SearchResponse proto) {
        this.proto = proto;
        this.protoBuilder = null;
    }

    @Override
    public void copyFrom(SearchResponse 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.
         */
        setQuery(message.getQuery());

        /**
         * 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.
         */
        setTotalResults(message.getTotalResults());

        /**
         * 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.
         */
        clearDigests();
        for (Digest field : message.getDigests()) {
            addDigests(new DigestProtoImpl(field));
        }
    }

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

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

    @Override
    public void setTotalResults(int value) {
        switchToProtoBuilder();
        protoBuilder.setTotalResults(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 List<DigestProtoImpl> getDigests() {
        switchToProto();
        List<DigestProtoImpl> list = new ArrayList<DigestProtoImpl>();
        for (int i = 0; i < getDigestsSize(); i++) {
            DigestProtoImpl message = new DigestProtoImpl(proto.getDigests(i));
            list.add(message);
        }
        return list;
    }

    @Override
    public void addAllDigests(List<? extends Digest> values) {
        for (Digest message : values) {
            addDigests(message);
        }
    }

    @Override
    public DigestProtoImpl getDigests(int n) {
        switchToProto();
        return new DigestProtoImpl(proto.getDigests(n));
    }

    @Override
    public void setDigests(int n, Digest value) {
        switchToProtoBuilder();
        protoBuilder.setDigests(n, getOrCreateDigestProtoImpl(value).getPB());
    }

    @Override
    public int getDigestsSize() {
        switchToProto();
        return proto.getDigestsCount();
    }

    @Override
    public void addDigests(Digest value) {
        switchToProtoBuilder();
        protoBuilder.addDigests(getOrCreateDigestProtoImpl(value).getPB());
    }

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

    /**
     * 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 DigestProtoImpl from a Digest. */
    private DigestProtoImpl getOrCreateDigestProtoImpl(Digest message) {
        if (message instanceof DigestProtoImpl) {
            return (DigestProtoImpl) message;
        } else {
            DigestProtoImpl messageImpl = new DigestProtoImpl();
            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.search.SearchProto.SearchResponse.newBuilder()
                    : org.waveprotocol.box.search.SearchProto.SearchResponse.newBuilder(proto);
            proto = null;
        }
    }

    private void invalidateAll() {
        proto = null;
        protoBuilder = org.waveprotocol.box.search.SearchProto.SearchResponse.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(getQuery()));

        /**
         * 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(getTotalResults()));

        /**
         * 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.
         */
        {
            JsonArray array = new JsonArray();
            for (int i = 0; i < getDigestsSize(); i++) {
                JsonElement elem = ((GsonSerializable) getDigests(i)).toGson(raw, gson);
                // NOTE(kalman): if multistage parsing worked, split point would go here.
                array.add(elem);
            }
            json.add("3", 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();

        /**
         * 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");
            setQuery(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");
            setTotalResults(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");
            {
                JsonArray array = elem.getAsJsonArray();
                for (int i = 0; i < array.size(); i++) {
                    DigestProtoImpl payload = new DigestProtoImpl();
                    GsonUtil.extractJsonObject(payload, array.get(i), gson, raw);
                    addDigests(payload);
                }
            }
        }
    }

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

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

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

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

}