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.base.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 PurgeResult implements org.apache.thrift.TBase<PurgeResult, PurgeResult._Fields>, java.io.Serializable, Cloneable, Comparable<PurgeResult> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct( "PurgeResult"); private static final org.apache.thrift.protocol.TField IS_FINISHED_FIELD_DESC = new org.apache.thrift.protocol.TField( "isFinished", org.apache.thrift.protocol.TType.BOOL, (short) 1); private static final org.apache.thrift.protocol.TField PURGED_FIELD_DESC = new org.apache.thrift.protocol.TField( "purged", org.apache.thrift.protocol.TType.SET, (short) 2); private static final org.apache.thrift.protocol.TField UNPURGED_FIELD_DESC = new org.apache.thrift.protocol.TField( "unpurged", org.apache.thrift.protocol.TType.SET, (short) 3); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new PurgeResultStandardSchemeFactory()); schemes.put(TupleScheme.class, new PurgeResultTupleSchemeFactory()); } public boolean isFinished; // required public Set<Long> purged; // optional public Set<Long> unpurged; // 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 { IS_FINISHED((short) 1, "isFinished"), PURGED((short) 2, "purged"), UNPURGED((short) 3, "unpurged"); 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: // IS_FINISHED return IS_FINISHED; case 2: // PURGED return PURGED; case 3: // UNPURGED return UNPURGED; 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 __ISFINISHED_ISSET_ID = 0; private byte __isset_bitfield = 0; private _Fields optionals[] = { _Fields.PURGED, _Fields.UNPURGED }; 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.IS_FINISHED, new org.apache.thrift.meta_data.FieldMetaData("isFinished", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); tmpMap.put(_Fields.PURGED, new org.apache.thrift.meta_data.FieldMetaData("purged", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)))); tmpMap.put(_Fields.UNPURGED, new org.apache.thrift.meta_data.FieldMetaData("unpurged", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(PurgeResult.class, metaDataMap); } public PurgeResult() { } public PurgeResult(boolean isFinished) { this(); this.isFinished = isFinished; setIsFinishedIsSet(true); } /** * Performs a deep copy on <i>other</i>. */ public PurgeResult(PurgeResult other) { __isset_bitfield = other.__isset_bitfield; this.isFinished = other.isFinished; if (other.isSetPurged()) { Set<Long> __this__purged = new HashSet<Long>(other.purged); this.purged = __this__purged; } if (other.isSetUnpurged()) { Set<Long> __this__unpurged = new HashSet<Long>(other.unpurged); this.unpurged = __this__unpurged; } } public PurgeResult deepCopy() { return new PurgeResult(this); } @Override public void clear() { setIsFinishedIsSet(false); this.isFinished = false; this.purged = null; this.unpurged = null; } public boolean isIsFinished() { return this.isFinished; } public PurgeResult setIsFinished(boolean isFinished) { this.isFinished = isFinished; setIsFinishedIsSet(true); return this; } public void unsetIsFinished() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __ISFINISHED_ISSET_ID); } /** Returns true if field isFinished is set (has been assigned a value) and false otherwise */ public boolean isSetIsFinished() { return EncodingUtils.testBit(__isset_bitfield, __ISFINISHED_ISSET_ID); } public void setIsFinishedIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __ISFINISHED_ISSET_ID, value); } public int getPurgedSize() { return (this.purged == null) ? 0 : this.purged.size(); } public java.util.Iterator<Long> getPurgedIterator() { return (this.purged == null) ? null : this.purged.iterator(); } public void addToPurged(long elem) { if (this.purged == null) { this.purged = new HashSet<Long>(); } this.purged.add(elem); } public Set<Long> getPurged() { return this.purged; } public PurgeResult setPurged(Set<Long> purged) { this.purged = purged; return this; } public void unsetPurged() { this.purged = null; } /** Returns true if field purged is set (has been assigned a value) and false otherwise */ public boolean isSetPurged() { return this.purged != null; } public void setPurgedIsSet(boolean value) { if (!value) { this.purged = null; } } public int getUnpurgedSize() { return (this.unpurged == null) ? 0 : this.unpurged.size(); } public java.util.Iterator<Long> getUnpurgedIterator() { return (this.unpurged == null) ? null : this.unpurged.iterator(); } public void addToUnpurged(long elem) { if (this.unpurged == null) { this.unpurged = new HashSet<Long>(); } this.unpurged.add(elem); } public Set<Long> getUnpurged() { return this.unpurged; } public PurgeResult setUnpurged(Set<Long> unpurged) { this.unpurged = unpurged; return this; } public void unsetUnpurged() { this.unpurged = null; } /** Returns true if field unpurged is set (has been assigned a value) and false otherwise */ public boolean isSetUnpurged() { return this.unpurged != null; } public void setUnpurgedIsSet(boolean value) { if (!value) { this.unpurged = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case IS_FINISHED: if (value == null) { unsetIsFinished(); } else { setIsFinished((Boolean) value); } break; case PURGED: if (value == null) { unsetPurged(); } else { setPurged((Set<Long>) value); } break; case UNPURGED: if (value == null) { unsetUnpurged(); } else { setUnpurged((Set<Long>) value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case IS_FINISHED: return Boolean.valueOf(isIsFinished()); case PURGED: return getPurged(); case UNPURGED: return getUnpurged(); } 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 IS_FINISHED: return isSetIsFinished(); case PURGED: return isSetPurged(); case UNPURGED: return isSetUnpurged(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof PurgeResult) return this.equals((PurgeResult) that); return false; } public boolean equals(PurgeResult that) { if (that == null) return false; boolean this_present_isFinished = true; boolean that_present_isFinished = true; if (this_present_isFinished || that_present_isFinished) { if (!(this_present_isFinished && that_present_isFinished)) return false; if (this.isFinished != that.isFinished) return false; } boolean this_present_purged = true && this.isSetPurged(); boolean that_present_purged = true && that.isSetPurged(); if (this_present_purged || that_present_purged) { if (!(this_present_purged && that_present_purged)) return false; if (!this.purged.equals(that.purged)) return false; } boolean this_present_unpurged = true && this.isSetUnpurged(); boolean that_present_unpurged = true && that.isSetUnpurged(); if (this_present_unpurged || that_present_unpurged) { if (!(this_present_unpurged && that_present_unpurged)) return false; if (!this.unpurged.equals(that.unpurged)) return false; } return true; } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); boolean present_isFinished = true; builder.append(present_isFinished); if (present_isFinished) builder.append(isFinished); boolean present_purged = true && (isSetPurged()); builder.append(present_purged); if (present_purged) builder.append(purged); boolean present_unpurged = true && (isSetUnpurged()); builder.append(present_unpurged); if (present_unpurged) builder.append(unpurged); return builder.toHashCode(); } @Override public int compareTo(PurgeResult other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; lastComparison = Boolean.valueOf(isSetIsFinished()).compareTo(other.isSetIsFinished()); if (lastComparison != 0) { return lastComparison; } if (isSetIsFinished()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.isFinished, other.isFinished); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetPurged()).compareTo(other.isSetPurged()); if (lastComparison != 0) { return lastComparison; } if (isSetPurged()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.purged, other.purged); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetUnpurged()).compareTo(other.isSetUnpurged()); if (lastComparison != 0) { return lastComparison; } if (isSetUnpurged()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unpurged, other.unpurged); 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("PurgeResult("); boolean first = true; sb.append("isFinished:"); sb.append(this.isFinished); first = false; if (isSetPurged()) { if (!first) sb.append(", "); sb.append("purged:"); if (this.purged == null) { sb.append("null"); } else { sb.append(this.purged); } first = false; } if (isSetUnpurged()) { if (!first) sb.append(", "); sb.append("unpurged:"); if (this.unpurged == null) { sb.append("null"); } else { sb.append(this.unpurged); } first = false; } sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // alas, we cannot check 'isFinished' because it's a primitive and you chose the non-beans generator. // 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 PurgeResultStandardSchemeFactory implements SchemeFactory { public PurgeResultStandardScheme getScheme() { return new PurgeResultStandardScheme(); } } private static class PurgeResultStandardScheme extends StandardScheme<PurgeResult> { public void read(org.apache.thrift.protocol.TProtocol iprot, PurgeResult 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: // IS_FINISHED if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) { struct.isFinished = iprot.readBool(); struct.setIsFinishedIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // PURGED if (schemeField.type == org.apache.thrift.protocol.TType.SET) { { org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); struct.purged = new HashSet<Long>(2 * _set0.size); for (int _i1 = 0; _i1 < _set0.size; ++_i1) { long _elem2; _elem2 = iprot.readI64(); struct.purged.add(_elem2); } iprot.readSetEnd(); } struct.setPurgedIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 3: // UNPURGED if (schemeField.type == org.apache.thrift.protocol.TType.SET) { { org.apache.thrift.protocol.TSet _set3 = iprot.readSetBegin(); struct.unpurged = new HashSet<Long>(2 * _set3.size); for (int _i4 = 0; _i4 < _set3.size; ++_i4) { long _elem5; _elem5 = iprot.readI64(); struct.unpurged.add(_elem5); } iprot.readSetEnd(); } struct.setUnpurgedIsSet(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 if (!struct.isSetIsFinished()) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'isFinished' was not found in serialized data! Struct: " + toString()); } struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, PurgeResult struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(IS_FINISHED_FIELD_DESC); oprot.writeBool(struct.isFinished); oprot.writeFieldEnd(); if (struct.purged != null) { if (struct.isSetPurged()) { oprot.writeFieldBegin(PURGED_FIELD_DESC); { oprot.writeSetBegin(new org.apache.thrift.protocol.TSet( org.apache.thrift.protocol.TType.I64, struct.purged.size())); for (long _iter6 : struct.purged) { oprot.writeI64(_iter6); } oprot.writeSetEnd(); } oprot.writeFieldEnd(); } } if (struct.unpurged != null) { if (struct.isSetUnpurged()) { oprot.writeFieldBegin(UNPURGED_FIELD_DESC); { oprot.writeSetBegin(new org.apache.thrift.protocol.TSet( org.apache.thrift.protocol.TType.I64, struct.unpurged.size())); for (long _iter7 : struct.unpurged) { oprot.writeI64(_iter7); } oprot.writeSetEnd(); } oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class PurgeResultTupleSchemeFactory implements SchemeFactory { public PurgeResultTupleScheme getScheme() { return new PurgeResultTupleScheme(); } } private static class PurgeResultTupleScheme extends TupleScheme<PurgeResult> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, PurgeResult struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; oprot.writeBool(struct.isFinished); BitSet optionals = new BitSet(); if (struct.isSetPurged()) { optionals.set(0); } if (struct.isSetUnpurged()) { optionals.set(1); } oprot.writeBitSet(optionals, 2); if (struct.isSetPurged()) { { oprot.writeI32(struct.purged.size()); for (long _iter8 : struct.purged) { oprot.writeI64(_iter8); } } } if (struct.isSetUnpurged()) { { oprot.writeI32(struct.unpurged.size()); for (long _iter9 : struct.unpurged) { oprot.writeI64(_iter9); } } } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, PurgeResult struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; struct.isFinished = iprot.readBool(); struct.setIsFinishedIsSet(true); BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { { org.apache.thrift.protocol.TSet _set10 = new org.apache.thrift.protocol.TSet( org.apache.thrift.protocol.TType.I64, iprot.readI32()); struct.purged = new HashSet<Long>(2 * _set10.size); for (int _i11 = 0; _i11 < _set10.size; ++_i11) { long _elem12; _elem12 = iprot.readI64(); struct.purged.add(_elem12); } } struct.setPurgedIsSet(true); } if (incoming.get(1)) { { org.apache.thrift.protocol.TSet _set13 = new org.apache.thrift.protocol.TSet( org.apache.thrift.protocol.TType.I64, iprot.readI32()); struct.unpurged = new HashSet<Long>(2 * _set13.size); for (int _i14 = 0; _i14 < _set13.size; ++_i14) { long _elem15; _elem15 = iprot.readI64(); struct.unpurged.add(_elem15); } } struct.setUnpurgedIsSet(true); } } } }