ezbake.data.elastic.thrift.PercolateRequest.java Source code

Java tutorial

Introduction

Here is the source code for ezbake.data.elastic.thrift.PercolateRequest.java

Source

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

/**
 * Autogenerated by Thrift Compiler (0.9.1)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package ezbake.data.elastic.thrift;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;

import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.EncodingUtils;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.server.AbstractNonblockingServer.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Defines options for percolating documents upon insert
 */
public class PercolateRequest implements org.apache.thrift.TBase<PercolateRequest, PercolateRequest._Fields>,
        java.io.Serializable, Cloneable, Comparable<PercolateRequest> {
    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct(
            "PercolateRequest");

    private static final org.apache.thrift.protocol.TField FILTER_JSON_FIELD_DESC = new org.apache.thrift.protocol.TField(
            "filterJson", org.apache.thrift.protocol.TType.STRING, (short) 1);
    private static final org.apache.thrift.protocol.TField MAX_MATCHES_FIELD_DESC = new org.apache.thrift.protocol.TField(
            "maxMatches", org.apache.thrift.protocol.TType.I32, (short) 2);
    private static final org.apache.thrift.protocol.TField FACETS_FIELD_DESC = new org.apache.thrift.protocol.TField(
            "facets", org.apache.thrift.protocol.TType.LIST, (short) 3);

    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
    static {
        schemes.put(StandardScheme.class, new PercolateRequestStandardSchemeFactory());
        schemes.put(TupleScheme.class, new PercolateRequestTupleSchemeFactory());
    }

    /**
     * Filter JSON to filter out queries that should not applySettings
     */
    public String filterJson; // optional
    /**
     * Maximum number of queries to return
     */
    public int maxMatches; // optional
    /**
     * Facets to request for the returned queries
     */
    public List<ezbake.data.elastic.thrift.Facet> facets; // optional

    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
        /**
         * Filter JSON to filter out queries that should not applySettings
         */
        FILTER_JSON((short) 1, "filterJson"),
        /**
         * Maximum number of queries to return
         */
        MAX_MATCHES((short) 2, "maxMatches"),
        /**
         * Facets to request for the returned queries
         */
        FACETS((short) 3, "facets");

        private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

        static {
            for (_Fields field : EnumSet.allOf(_Fields.class)) {
                byName.put(field.getFieldName(), field);
            }
        }

        /**
         * Find the _Fields constant that matches fieldId, or null if its not found.
         */
        public static _Fields findByThriftId(int fieldId) {
            switch (fieldId) {
            case 1: // FILTER_JSON
                return FILTER_JSON;
            case 2: // MAX_MATCHES
                return MAX_MATCHES;
            case 3: // FACETS
                return FACETS;
            default:
                return null;
            }
        }

        /**
         * Find the _Fields constant that matches fieldId, throwing an exception
         * if it is not found.
         */
        public static _Fields findByThriftIdOrThrow(int fieldId) {
            _Fields fields = findByThriftId(fieldId);
            if (fields == null)
                throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
            return fields;
        }

        /**
         * Find the _Fields constant that matches name, or null if its not found.
         */
        public static _Fields findByName(String name) {
            return byName.get(name);
        }

        private final short _thriftId;
        private final String _fieldName;

        _Fields(short thriftId, String fieldName) {
            _thriftId = thriftId;
            _fieldName = fieldName;
        }

        public short getThriftFieldId() {
            return _thriftId;
        }

        public String getFieldName() {
            return _fieldName;
        }
    }

    // isset id assignments
    private static final int __MAXMATCHES_ISSET_ID = 0;
    private byte __isset_bitfield = 0;
    private _Fields optionals[] = { _Fields.FILTER_JSON, _Fields.MAX_MATCHES, _Fields.FACETS };
    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
    static {
        Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(
                _Fields.class);
        tmpMap.put(_Fields.FILTER_JSON, new org.apache.thrift.meta_data.FieldMetaData("filterJson",
                org.apache.thrift.TFieldRequirementType.OPTIONAL,
                new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
        tmpMap.put(_Fields.MAX_MATCHES,
                new org.apache.thrift.meta_data.FieldMetaData("maxMatches",
                        org.apache.thrift.TFieldRequirementType.OPTIONAL,
                        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
        tmpMap.put(_Fields.FACETS,
                new org.apache.thrift.meta_data.FieldMetaData("facets",
                        org.apache.thrift.TFieldRequirementType.OPTIONAL,
                        new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
                                new org.apache.thrift.meta_data.StructMetaData(
                                        org.apache.thrift.protocol.TType.STRUCT,
                                        ezbake.data.elastic.thrift.Facet.class))));
        metaDataMap = Collections.unmodifiableMap(tmpMap);
        org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(PercolateRequest.class, metaDataMap);
    }

    public PercolateRequest() {
        this.maxMatches = 50;

    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public PercolateRequest(PercolateRequest other) {
        __isset_bitfield = other.__isset_bitfield;
        if (other.isSetFilterJson()) {
            this.filterJson = other.filterJson;
        }
        this.maxMatches = other.maxMatches;
        if (other.isSetFacets()) {
            List<ezbake.data.elastic.thrift.Facet> __this__facets = new ArrayList<ezbake.data.elastic.thrift.Facet>(
                    other.facets.size());
            for (ezbake.data.elastic.thrift.Facet other_element : other.facets) {
                __this__facets.add(new ezbake.data.elastic.thrift.Facet(other_element));
            }
            this.facets = __this__facets;
        }
    }

    public PercolateRequest deepCopy() {
        return new PercolateRequest(this);
    }

    @Override
    public void clear() {
        this.filterJson = null;
        this.maxMatches = 50;

        this.facets = null;
    }

    /**
     * Filter JSON to filter out queries that should not applySettings
     */
    public String getFilterJson() {
        return this.filterJson;
    }

    /**
     * Filter JSON to filter out queries that should not applySettings
     */
    public PercolateRequest setFilterJson(String filterJson) {
        this.filterJson = filterJson;
        return this;
    }

    public void unsetFilterJson() {
        this.filterJson = null;
    }

    /** Returns true if field filterJson is set (has been assigned a value) and false otherwise */
    public boolean isSetFilterJson() {
        return this.filterJson != null;
    }

    public void setFilterJsonIsSet(boolean value) {
        if (!value) {
            this.filterJson = null;
        }
    }

    /**
     * Maximum number of queries to return
     */
    public int getMaxMatches() {
        return this.maxMatches;
    }

    /**
     * Maximum number of queries to return
     */
    public PercolateRequest setMaxMatches(int maxMatches) {
        this.maxMatches = maxMatches;
        setMaxMatchesIsSet(true);
        return this;
    }

    public void unsetMaxMatches() {
        __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __MAXMATCHES_ISSET_ID);
    }

    /** Returns true if field maxMatches is set (has been assigned a value) and false otherwise */
    public boolean isSetMaxMatches() {
        return EncodingUtils.testBit(__isset_bitfield, __MAXMATCHES_ISSET_ID);
    }

    public void setMaxMatchesIsSet(boolean value) {
        __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __MAXMATCHES_ISSET_ID, value);
    }

    public int getFacetsSize() {
        return (this.facets == null) ? 0 : this.facets.size();
    }

    public java.util.Iterator<ezbake.data.elastic.thrift.Facet> getFacetsIterator() {
        return (this.facets == null) ? null : this.facets.iterator();
    }

    public void addToFacets(ezbake.data.elastic.thrift.Facet elem) {
        if (this.facets == null) {
            this.facets = new ArrayList<ezbake.data.elastic.thrift.Facet>();
        }
        this.facets.add(elem);
    }

    /**
     * Facets to request for the returned queries
     */
    public List<ezbake.data.elastic.thrift.Facet> getFacets() {
        return this.facets;
    }

    /**
     * Facets to request for the returned queries
     */
    public PercolateRequest setFacets(List<ezbake.data.elastic.thrift.Facet> facets) {
        this.facets = facets;
        return this;
    }

    public void unsetFacets() {
        this.facets = null;
    }

    /** Returns true if field facets is set (has been assigned a value) and false otherwise */
    public boolean isSetFacets() {
        return this.facets != null;
    }

    public void setFacetsIsSet(boolean value) {
        if (!value) {
            this.facets = null;
        }
    }

    public void setFieldValue(_Fields field, Object value) {
        switch (field) {
        case FILTER_JSON:
            if (value == null) {
                unsetFilterJson();
            } else {
                setFilterJson((String) value);
            }
            break;

        case MAX_MATCHES:
            if (value == null) {
                unsetMaxMatches();
            } else {
                setMaxMatches((Integer) value);
            }
            break;

        case FACETS:
            if (value == null) {
                unsetFacets();
            } else {
                setFacets((List<ezbake.data.elastic.thrift.Facet>) value);
            }
            break;

        }
    }

    public Object getFieldValue(_Fields field) {
        switch (field) {
        case FILTER_JSON:
            return getFilterJson();

        case MAX_MATCHES:
            return Integer.valueOf(getMaxMatches());

        case FACETS:
            return getFacets();

        }
        throw new IllegalStateException();
    }

    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
    public boolean isSet(_Fields field) {
        if (field == null) {
            throw new IllegalArgumentException();
        }

        switch (field) {
        case FILTER_JSON:
            return isSetFilterJson();
        case MAX_MATCHES:
            return isSetMaxMatches();
        case FACETS:
            return isSetFacets();
        }
        throw new IllegalStateException();
    }

    @Override
    public boolean equals(Object that) {
        if (that == null)
            return false;
        if (that instanceof PercolateRequest)
            return this.equals((PercolateRequest) that);
        return false;
    }

    public boolean equals(PercolateRequest that) {
        if (that == null)
            return false;

        boolean this_present_filterJson = true && this.isSetFilterJson();
        boolean that_present_filterJson = true && that.isSetFilterJson();
        if (this_present_filterJson || that_present_filterJson) {
            if (!(this_present_filterJson && that_present_filterJson))
                return false;
            if (!this.filterJson.equals(that.filterJson))
                return false;
        }

        boolean this_present_maxMatches = true && this.isSetMaxMatches();
        boolean that_present_maxMatches = true && that.isSetMaxMatches();
        if (this_present_maxMatches || that_present_maxMatches) {
            if (!(this_present_maxMatches && that_present_maxMatches))
                return false;
            if (this.maxMatches != that.maxMatches)
                return false;
        }

        boolean this_present_facets = true && this.isSetFacets();
        boolean that_present_facets = true && that.isSetFacets();
        if (this_present_facets || that_present_facets) {
            if (!(this_present_facets && that_present_facets))
                return false;
            if (!this.facets.equals(that.facets))
                return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        HashCodeBuilder builder = new HashCodeBuilder();

        boolean present_filterJson = true && (isSetFilterJson());
        builder.append(present_filterJson);
        if (present_filterJson)
            builder.append(filterJson);

        boolean present_maxMatches = true && (isSetMaxMatches());
        builder.append(present_maxMatches);
        if (present_maxMatches)
            builder.append(maxMatches);

        boolean present_facets = true && (isSetFacets());
        builder.append(present_facets);
        if (present_facets)
            builder.append(facets);

        return builder.toHashCode();
    }

    @Override
    public int compareTo(PercolateRequest other) {
        if (!getClass().equals(other.getClass())) {
            return getClass().getName().compareTo(other.getClass().getName());
        }

        int lastComparison = 0;

        lastComparison = Boolean.valueOf(isSetFilterJson()).compareTo(other.isSetFilterJson());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetFilterJson()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.filterJson, other.filterJson);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetMaxMatches()).compareTo(other.isSetMaxMatches());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetMaxMatches()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.maxMatches, other.maxMatches);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        lastComparison = Boolean.valueOf(isSetFacets()).compareTo(other.isSetFacets());
        if (lastComparison != 0) {
            return lastComparison;
        }
        if (isSetFacets()) {
            lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.facets, other.facets);
            if (lastComparison != 0) {
                return lastComparison;
            }
        }
        return 0;
    }

    public _Fields fieldForId(int fieldId) {
        return _Fields.findByThriftId(fieldId);
    }

    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
        schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
        schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("PercolateRequest(");
        boolean first = true;

        if (isSetFilterJson()) {
            sb.append("filterJson:");
            if (this.filterJson == null) {
                sb.append("null");
            } else {
                sb.append(this.filterJson);
            }
            first = false;
        }
        if (isSetMaxMatches()) {
            if (!first)
                sb.append(", ");
            sb.append("maxMatches:");
            sb.append(this.maxMatches);
            first = false;
        }
        if (isSetFacets()) {
            if (!first)
                sb.append(", ");
            sb.append("facets:");
            if (this.facets == null) {
                sb.append("null");
            } else {
                sb.append(this.facets);
            }
            first = false;
        }
        sb.append(")");
        return sb.toString();
    }

    public void validate() throws org.apache.thrift.TException {
        // check for required fields
        // check for sub-struct validity
    }

    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
        try {
            write(new org.apache.thrift.protocol.TCompactProtocol(
                    new org.apache.thrift.transport.TIOStreamTransport(out)));
        } catch (org.apache.thrift.TException te) {
            throw new java.io.IOException(te);
        }
    }

    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
        try {
            // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
            __isset_bitfield = 0;
            read(new org.apache.thrift.protocol.TCompactProtocol(
                    new org.apache.thrift.transport.TIOStreamTransport(in)));
        } catch (org.apache.thrift.TException te) {
            throw new java.io.IOException(te);
        }
    }

    private static class PercolateRequestStandardSchemeFactory implements SchemeFactory {
        public PercolateRequestStandardScheme getScheme() {
            return new PercolateRequestStandardScheme();
        }
    }

    private static class PercolateRequestStandardScheme extends StandardScheme<PercolateRequest> {

        public void read(org.apache.thrift.protocol.TProtocol iprot, PercolateRequest struct)
                throws org.apache.thrift.TException {
            org.apache.thrift.protocol.TField schemeField;
            iprot.readStructBegin();
            while (true) {
                schemeField = iprot.readFieldBegin();
                if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
                    break;
                }
                switch (schemeField.id) {
                case 1: // FILTER_JSON
                    if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
                        struct.filterJson = iprot.readString();
                        struct.setFilterJsonIsSet(true);
                    } else {
                        org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                    }
                    break;
                case 2: // MAX_MATCHES
                    if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
                        struct.maxMatches = iprot.readI32();
                        struct.setMaxMatchesIsSet(true);
                    } else {
                        org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                    }
                    break;
                case 3: // FACETS
                    if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
                        {
                            org.apache.thrift.protocol.TList _list52 = iprot.readListBegin();
                            struct.facets = new ArrayList<ezbake.data.elastic.thrift.Facet>(_list52.size);
                            for (int _i53 = 0; _i53 < _list52.size; ++_i53) {
                                ezbake.data.elastic.thrift.Facet _elem54;
                                _elem54 = new ezbake.data.elastic.thrift.Facet();
                                _elem54.read(iprot);
                                struct.facets.add(_elem54);
                            }
                            iprot.readListEnd();
                        }
                        struct.setFacetsIsSet(true);
                    } else {
                        org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                    }
                    break;
                default:
                    org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
                }
                iprot.readFieldEnd();
            }
            iprot.readStructEnd();

            // check for required fields of primitive type, which can't be checked in the validate method
            struct.validate();
        }

        public void write(org.apache.thrift.protocol.TProtocol oprot, PercolateRequest struct)
                throws org.apache.thrift.TException {
            struct.validate();

            oprot.writeStructBegin(STRUCT_DESC);
            if (struct.filterJson != null) {
                if (struct.isSetFilterJson()) {
                    oprot.writeFieldBegin(FILTER_JSON_FIELD_DESC);
                    oprot.writeString(struct.filterJson);
                    oprot.writeFieldEnd();
                }
            }
            if (struct.isSetMaxMatches()) {
                oprot.writeFieldBegin(MAX_MATCHES_FIELD_DESC);
                oprot.writeI32(struct.maxMatches);
                oprot.writeFieldEnd();
            }
            if (struct.facets != null) {
                if (struct.isSetFacets()) {
                    oprot.writeFieldBegin(FACETS_FIELD_DESC);
                    {
                        oprot.writeListBegin(new org.apache.thrift.protocol.TList(
                                org.apache.thrift.protocol.TType.STRUCT, struct.facets.size()));
                        for (ezbake.data.elastic.thrift.Facet _iter55 : struct.facets) {
                            _iter55.write(oprot);
                        }
                        oprot.writeListEnd();
                    }
                    oprot.writeFieldEnd();
                }
            }
            oprot.writeFieldStop();
            oprot.writeStructEnd();
        }

    }

    private static class PercolateRequestTupleSchemeFactory implements SchemeFactory {
        public PercolateRequestTupleScheme getScheme() {
            return new PercolateRequestTupleScheme();
        }
    }

    private static class PercolateRequestTupleScheme extends TupleScheme<PercolateRequest> {

        @Override
        public void write(org.apache.thrift.protocol.TProtocol prot, PercolateRequest struct)
                throws org.apache.thrift.TException {
            TTupleProtocol oprot = (TTupleProtocol) prot;
            BitSet optionals = new BitSet();
            if (struct.isSetFilterJson()) {
                optionals.set(0);
            }
            if (struct.isSetMaxMatches()) {
                optionals.set(1);
            }
            if (struct.isSetFacets()) {
                optionals.set(2);
            }
            oprot.writeBitSet(optionals, 3);
            if (struct.isSetFilterJson()) {
                oprot.writeString(struct.filterJson);
            }
            if (struct.isSetMaxMatches()) {
                oprot.writeI32(struct.maxMatches);
            }
            if (struct.isSetFacets()) {
                {
                    oprot.writeI32(struct.facets.size());
                    for (ezbake.data.elastic.thrift.Facet _iter56 : struct.facets) {
                        _iter56.write(oprot);
                    }
                }
            }
        }

        @Override
        public void read(org.apache.thrift.protocol.TProtocol prot, PercolateRequest struct)
                throws org.apache.thrift.TException {
            TTupleProtocol iprot = (TTupleProtocol) prot;
            BitSet incoming = iprot.readBitSet(3);
            if (incoming.get(0)) {
                struct.filterJson = iprot.readString();
                struct.setFilterJsonIsSet(true);
            }
            if (incoming.get(1)) {
                struct.maxMatches = iprot.readI32();
                struct.setMaxMatchesIsSet(true);
            }
            if (incoming.get(2)) {
                {
                    org.apache.thrift.protocol.TList _list57 = new org.apache.thrift.protocol.TList(
                            org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
                    struct.facets = new ArrayList<ezbake.data.elastic.thrift.Facet>(_list57.size);
                    for (int _i58 = 0; _i58 < _list57.size; ++_i58) {
                        ezbake.data.elastic.thrift.Facet _elem59;
                        _elem59 = new ezbake.data.elastic.thrift.Facet();
                        _elem59.read(iprot);
                        struct.facets.add(_elem59);
                    }
                }
                struct.setFacetsIsSet(true);
            }
        }
    }

}