Java tutorial
/* 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; public class TermsFacetResult implements org.apache.thrift.TBase<TermsFacetResult, TermsFacetResult._Fields>, java.io.Serializable, Cloneable, Comparable<TermsFacetResult> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct( "TermsFacetResult"); private static final org.apache.thrift.protocol.TField TOTAL_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField( "totalCount", org.apache.thrift.protocol.TType.I64, (short) 1); private static final org.apache.thrift.protocol.TField OTHER_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField( "otherCount", org.apache.thrift.protocol.TType.I64, (short) 2); private static final org.apache.thrift.protocol.TField MISSING_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField( "missingCount", org.apache.thrift.protocol.TType.I64, (short) 3); private static final org.apache.thrift.protocol.TField ENTRIES_FIELD_DESC = new org.apache.thrift.protocol.TField( "entries", org.apache.thrift.protocol.TType.LIST, (short) 4); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new TermsFacetResultStandardSchemeFactory()); schemes.put(TupleScheme.class, new TermsFacetResultTupleSchemeFactory()); } public long totalCount; // required public long otherCount; // required public long missingCount; // required public List<TermsFacetEntry> entries; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { TOTAL_COUNT((short) 1, "totalCount"), OTHER_COUNT((short) 2, "otherCount"), MISSING_COUNT((short) 3, "missingCount"), ENTRIES((short) 4, "entries"); 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: // TOTAL_COUNT return TOTAL_COUNT; case 2: // OTHER_COUNT return OTHER_COUNT; case 3: // MISSING_COUNT return MISSING_COUNT; case 4: // ENTRIES return ENTRIES; 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 __TOTALCOUNT_ISSET_ID = 0; private static final int __OTHERCOUNT_ISSET_ID = 1; private static final int __MISSINGCOUNT_ISSET_ID = 2; private byte __isset_bitfield = 0; 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.TOTAL_COUNT, new org.apache.thrift.meta_data.FieldMetaData("totalCount", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.OTHER_COUNT, new org.apache.thrift.meta_data.FieldMetaData("otherCount", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.MISSING_COUNT, new org.apache.thrift.meta_data.FieldMetaData("missingCount", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.ENTRIES, new org.apache.thrift.meta_data.FieldMetaData("entries", org.apache.thrift.TFieldRequirementType.DEFAULT, 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, TermsFacetEntry.class)))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TermsFacetResult.class, metaDataMap); } public TermsFacetResult() { } public TermsFacetResult(long totalCount, long otherCount, long missingCount, List<TermsFacetEntry> entries) { this(); this.totalCount = totalCount; setTotalCountIsSet(true); this.otherCount = otherCount; setOtherCountIsSet(true); this.missingCount = missingCount; setMissingCountIsSet(true); this.entries = entries; } /** * Performs a deep copy on <i>other</i>. */ public TermsFacetResult(TermsFacetResult other) { __isset_bitfield = other.__isset_bitfield; this.totalCount = other.totalCount; this.otherCount = other.otherCount; this.missingCount = other.missingCount; if (other.isSetEntries()) { List<TermsFacetEntry> __this__entries = new ArrayList<TermsFacetEntry>(other.entries.size()); for (TermsFacetEntry other_element : other.entries) { __this__entries.add(new TermsFacetEntry(other_element)); } this.entries = __this__entries; } } public TermsFacetResult deepCopy() { return new TermsFacetResult(this); } @Override public void clear() { setTotalCountIsSet(false); this.totalCount = 0; setOtherCountIsSet(false); this.otherCount = 0; setMissingCountIsSet(false); this.missingCount = 0; this.entries = null; } public long getTotalCount() { return this.totalCount; } public TermsFacetResult setTotalCount(long totalCount) { this.totalCount = totalCount; setTotalCountIsSet(true); return this; } public void unsetTotalCount() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TOTALCOUNT_ISSET_ID); } /** Returns true if field totalCount is set (has been assigned a value) and false otherwise */ public boolean isSetTotalCount() { return EncodingUtils.testBit(__isset_bitfield, __TOTALCOUNT_ISSET_ID); } public void setTotalCountIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TOTALCOUNT_ISSET_ID, value); } public long getOtherCount() { return this.otherCount; } public TermsFacetResult setOtherCount(long otherCount) { this.otherCount = otherCount; setOtherCountIsSet(true); return this; } public void unsetOtherCount() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __OTHERCOUNT_ISSET_ID); } /** Returns true if field otherCount is set (has been assigned a value) and false otherwise */ public boolean isSetOtherCount() { return EncodingUtils.testBit(__isset_bitfield, __OTHERCOUNT_ISSET_ID); } public void setOtherCountIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __OTHERCOUNT_ISSET_ID, value); } public long getMissingCount() { return this.missingCount; } public TermsFacetResult setMissingCount(long missingCount) { this.missingCount = missingCount; setMissingCountIsSet(true); return this; } public void unsetMissingCount() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __MISSINGCOUNT_ISSET_ID); } /** Returns true if field missingCount is set (has been assigned a value) and false otherwise */ public boolean isSetMissingCount() { return EncodingUtils.testBit(__isset_bitfield, __MISSINGCOUNT_ISSET_ID); } public void setMissingCountIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __MISSINGCOUNT_ISSET_ID, value); } public int getEntriesSize() { return (this.entries == null) ? 0 : this.entries.size(); } public java.util.Iterator<TermsFacetEntry> getEntriesIterator() { return (this.entries == null) ? null : this.entries.iterator(); } public void addToEntries(TermsFacetEntry elem) { if (this.entries == null) { this.entries = new ArrayList<TermsFacetEntry>(); } this.entries.add(elem); } public List<TermsFacetEntry> getEntries() { return this.entries; } public TermsFacetResult setEntries(List<TermsFacetEntry> entries) { this.entries = entries; return this; } public void unsetEntries() { this.entries = null; } /** Returns true if field entries is set (has been assigned a value) and false otherwise */ public boolean isSetEntries() { return this.entries != null; } public void setEntriesIsSet(boolean value) { if (!value) { this.entries = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case TOTAL_COUNT: if (value == null) { unsetTotalCount(); } else { setTotalCount((Long) value); } break; case OTHER_COUNT: if (value == null) { unsetOtherCount(); } else { setOtherCount((Long) value); } break; case MISSING_COUNT: if (value == null) { unsetMissingCount(); } else { setMissingCount((Long) value); } break; case ENTRIES: if (value == null) { unsetEntries(); } else { setEntries((List<TermsFacetEntry>) value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case TOTAL_COUNT: return Long.valueOf(getTotalCount()); case OTHER_COUNT: return Long.valueOf(getOtherCount()); case MISSING_COUNT: return Long.valueOf(getMissingCount()); case ENTRIES: return getEntries(); } 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 TOTAL_COUNT: return isSetTotalCount(); case OTHER_COUNT: return isSetOtherCount(); case MISSING_COUNT: return isSetMissingCount(); case ENTRIES: return isSetEntries(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof TermsFacetResult) return this.equals((TermsFacetResult) that); return false; } public boolean equals(TermsFacetResult that) { if (that == null) return false; boolean this_present_totalCount = true; boolean that_present_totalCount = true; if (this_present_totalCount || that_present_totalCount) { if (!(this_present_totalCount && that_present_totalCount)) return false; if (this.totalCount != that.totalCount) return false; } boolean this_present_otherCount = true; boolean that_present_otherCount = true; if (this_present_otherCount || that_present_otherCount) { if (!(this_present_otherCount && that_present_otherCount)) return false; if (this.otherCount != that.otherCount) return false; } boolean this_present_missingCount = true; boolean that_present_missingCount = true; if (this_present_missingCount || that_present_missingCount) { if (!(this_present_missingCount && that_present_missingCount)) return false; if (this.missingCount != that.missingCount) return false; } boolean this_present_entries = true && this.isSetEntries(); boolean that_present_entries = true && that.isSetEntries(); if (this_present_entries || that_present_entries) { if (!(this_present_entries && that_present_entries)) return false; if (!this.entries.equals(that.entries)) return false; } return true; } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); boolean present_totalCount = true; builder.append(present_totalCount); if (present_totalCount) builder.append(totalCount); boolean present_otherCount = true; builder.append(present_otherCount); if (present_otherCount) builder.append(otherCount); boolean present_missingCount = true; builder.append(present_missingCount); if (present_missingCount) builder.append(missingCount); boolean present_entries = true && (isSetEntries()); builder.append(present_entries); if (present_entries) builder.append(entries); return builder.toHashCode(); } @Override public int compareTo(TermsFacetResult other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; lastComparison = Boolean.valueOf(isSetTotalCount()).compareTo(other.isSetTotalCount()); if (lastComparison != 0) { return lastComparison; } if (isSetTotalCount()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.totalCount, other.totalCount); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetOtherCount()).compareTo(other.isSetOtherCount()); if (lastComparison != 0) { return lastComparison; } if (isSetOtherCount()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.otherCount, other.otherCount); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetMissingCount()).compareTo(other.isSetMissingCount()); if (lastComparison != 0) { return lastComparison; } if (isSetMissingCount()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.missingCount, other.missingCount); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetEntries()).compareTo(other.isSetEntries()); if (lastComparison != 0) { return lastComparison; } if (isSetEntries()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.entries, other.entries); 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("TermsFacetResult("); boolean first = true; sb.append("totalCount:"); sb.append(this.totalCount); first = false; if (!first) sb.append(", "); sb.append("otherCount:"); sb.append(this.otherCount); first = false; if (!first) sb.append(", "); sb.append("missingCount:"); sb.append(this.missingCount); first = false; if (!first) sb.append(", "); sb.append("entries:"); if (this.entries == null) { sb.append("null"); } else { sb.append(this.entries); } 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 TermsFacetResultStandardSchemeFactory implements SchemeFactory { public TermsFacetResultStandardScheme getScheme() { return new TermsFacetResultStandardScheme(); } } private static class TermsFacetResultStandardScheme extends StandardScheme<TermsFacetResult> { public void read(org.apache.thrift.protocol.TProtocol iprot, TermsFacetResult 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: // TOTAL_COUNT if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.totalCount = iprot.readI64(); struct.setTotalCountIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // OTHER_COUNT if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.otherCount = iprot.readI64(); struct.setOtherCountIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 3: // MISSING_COUNT if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.missingCount = iprot.readI64(); struct.setMissingCountIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 4: // ENTRIES if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { { org.apache.thrift.protocol.TList _list72 = iprot.readListBegin(); struct.entries = new ArrayList<TermsFacetEntry>(_list72.size); for (int _i73 = 0; _i73 < _list72.size; ++_i73) { TermsFacetEntry _elem74; _elem74 = new TermsFacetEntry(); _elem74.read(iprot); struct.entries.add(_elem74); } iprot.readListEnd(); } struct.setEntriesIsSet(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, TermsFacetResult struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(TOTAL_COUNT_FIELD_DESC); oprot.writeI64(struct.totalCount); oprot.writeFieldEnd(); oprot.writeFieldBegin(OTHER_COUNT_FIELD_DESC); oprot.writeI64(struct.otherCount); oprot.writeFieldEnd(); oprot.writeFieldBegin(MISSING_COUNT_FIELD_DESC); oprot.writeI64(struct.missingCount); oprot.writeFieldEnd(); if (struct.entries != null) { oprot.writeFieldBegin(ENTRIES_FIELD_DESC); { oprot.writeListBegin(new org.apache.thrift.protocol.TList( org.apache.thrift.protocol.TType.STRUCT, struct.entries.size())); for (TermsFacetEntry _iter75 : struct.entries) { _iter75.write(oprot); } oprot.writeListEnd(); } oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class TermsFacetResultTupleSchemeFactory implements SchemeFactory { public TermsFacetResultTupleScheme getScheme() { return new TermsFacetResultTupleScheme(); } } private static class TermsFacetResultTupleScheme extends TupleScheme<TermsFacetResult> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, TermsFacetResult struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetTotalCount()) { optionals.set(0); } if (struct.isSetOtherCount()) { optionals.set(1); } if (struct.isSetMissingCount()) { optionals.set(2); } if (struct.isSetEntries()) { optionals.set(3); } oprot.writeBitSet(optionals, 4); if (struct.isSetTotalCount()) { oprot.writeI64(struct.totalCount); } if (struct.isSetOtherCount()) { oprot.writeI64(struct.otherCount); } if (struct.isSetMissingCount()) { oprot.writeI64(struct.missingCount); } if (struct.isSetEntries()) { { oprot.writeI32(struct.entries.size()); for (TermsFacetEntry _iter76 : struct.entries) { _iter76.write(oprot); } } } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, TermsFacetResult struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(4); if (incoming.get(0)) { struct.totalCount = iprot.readI64(); struct.setTotalCountIsSet(true); } if (incoming.get(1)) { struct.otherCount = iprot.readI64(); struct.setOtherCountIsSet(true); } if (incoming.get(2)) { struct.missingCount = iprot.readI64(); struct.setMissingCountIsSet(true); } if (incoming.get(3)) { { org.apache.thrift.protocol.TList _list77 = new org.apache.thrift.protocol.TList( org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); struct.entries = new ArrayList<TermsFacetEntry>(_list77.size); for (int _i78 = 0; _i78 < _list77.size; ++_i78) { TermsFacetEntry _elem79; _elem79 = new TermsFacetEntry(); _elem79.read(iprot); struct.entries.add(_elem79); } } struct.setEntriesIsSet(true); } } } }