Java tutorial
/** * Copyright (C) 2015 Etaia AS (oss@hubrick.com) * * 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.0) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated */ package com.hubrick.client.id.flurry.thrift; import org.apache.thrift.EncodingUtils; import org.apache.thrift.protocol.TTupleProtocol; 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 java.util.*; public class IdDetailed implements org.apache.thrift.TBase<IdDetailed, IdDetailed._Fields>, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct( "IdDetailed"); private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField( "id", org.apache.thrift.protocol.TType.I64, (short) 1); private static final org.apache.thrift.protocol.TField TIME_FIELD_DESC = new org.apache.thrift.protocol.TField( "time", org.apache.thrift.protocol.TType.I64, (short) 2); private static final org.apache.thrift.protocol.TField WORKER_FIELD_DESC = new org.apache.thrift.protocol.TField( "worker", org.apache.thrift.protocol.TType.I32, (short) 3); private static final org.apache.thrift.protocol.TField SEQUENCE_FIELD_DESC = new org.apache.thrift.protocol.TField( "sequence", org.apache.thrift.protocol.TType.I32, (short) 4); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new IdDetailedStandardSchemeFactory()); schemes.put(TupleScheme.class, new IdDetailedTupleSchemeFactory()); } public long id; // required public long time; // required public int worker; // required public int sequence; // 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 { ID((short) 1, "id"), TIME((short) 2, "time"), WORKER((short) 3, "worker"), SEQUENCE((short) 4, "sequence"); 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: // ID return ID; case 2: // TIME return TIME; case 3: // WORKER return WORKER; case 4: // SEQUENCE return SEQUENCE; 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 __ID_ISSET_ID = 0; private static final int __TIME_ISSET_ID = 1; private static final int __WORKER_ISSET_ID = 2; private static final int __SEQUENCE_ISSET_ID = 3; 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.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.TIME, new org.apache.thrift.meta_data.FieldMetaData("time", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.WORKER, new org.apache.thrift.meta_data.FieldMetaData("worker", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); tmpMap.put(_Fields.SEQUENCE, new org.apache.thrift.meta_data.FieldMetaData("sequence", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(IdDetailed.class, metaDataMap); } public IdDetailed() { } public IdDetailed(long id, long time, int worker, int sequence) { this(); this.id = id; setIdIsSet(true); this.time = time; setTimeIsSet(true); this.worker = worker; setWorkerIsSet(true); this.sequence = sequence; setSequenceIsSet(true); } /** * Performs a deep copy on <i>other</i>. */ public IdDetailed(IdDetailed other) { __isset_bitfield = other.__isset_bitfield; this.id = other.id; this.time = other.time; this.worker = other.worker; this.sequence = other.sequence; } public IdDetailed deepCopy() { return new IdDetailed(this); } @Override public void clear() { setIdIsSet(false); this.id = 0; setTimeIsSet(false); this.time = 0; setWorkerIsSet(false); this.worker = 0; setSequenceIsSet(false); this.sequence = 0; } public long getId() { return this.id; } public IdDetailed setId(long id) { this.id = id; setIdIsSet(true); return this; } public void unsetId() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __ID_ISSET_ID); } /** * Returns true if field id is set (has been assigned a value) and false otherwise */ public boolean isSetId() { return EncodingUtils.testBit(__isset_bitfield, __ID_ISSET_ID); } public void setIdIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __ID_ISSET_ID, value); } public long getTime() { return this.time; } public IdDetailed setTime(long time) { this.time = time; setTimeIsSet(true); return this; } public void unsetTime() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TIME_ISSET_ID); } /** * Returns true if field time is set (has been assigned a value) and false otherwise */ public boolean isSetTime() { return EncodingUtils.testBit(__isset_bitfield, __TIME_ISSET_ID); } public void setTimeIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TIME_ISSET_ID, value); } public int getWorker() { return this.worker; } public IdDetailed setWorker(int worker) { this.worker = worker; setWorkerIsSet(true); return this; } public void unsetWorker() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __WORKER_ISSET_ID); } /** * Returns true if field worker is set (has been assigned a value) and false otherwise */ public boolean isSetWorker() { return EncodingUtils.testBit(__isset_bitfield, __WORKER_ISSET_ID); } public void setWorkerIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __WORKER_ISSET_ID, value); } public int getSequence() { return this.sequence; } public IdDetailed setSequence(int sequence) { this.sequence = sequence; setSequenceIsSet(true); return this; } public void unsetSequence() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SEQUENCE_ISSET_ID); } /** * Returns true if field sequence is set (has been assigned a value) and false otherwise */ public boolean isSetSequence() { return EncodingUtils.testBit(__isset_bitfield, __SEQUENCE_ISSET_ID); } public void setSequenceIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SEQUENCE_ISSET_ID, value); } public void setFieldValue(_Fields field, Object value) { switch (field) { case ID: if (value == null) { unsetId(); } else { setId((Long) value); } break; case TIME: if (value == null) { unsetTime(); } else { setTime((Long) value); } break; case WORKER: if (value == null) { unsetWorker(); } else { setWorker((Integer) value); } break; case SEQUENCE: if (value == null) { unsetSequence(); } else { setSequence((Integer) value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case ID: return Long.valueOf(getId()); case TIME: return Long.valueOf(getTime()); case WORKER: return Integer.valueOf(getWorker()); case SEQUENCE: return Integer.valueOf(getSequence()); } 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 ID: return isSetId(); case TIME: return isSetTime(); case WORKER: return isSetWorker(); case SEQUENCE: return isSetSequence(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof IdDetailed) return this.equals((IdDetailed) that); return false; } public boolean equals(IdDetailed that) { if (that == null) return false; boolean this_present_id = true; boolean that_present_id = true; if (this_present_id || that_present_id) { if (!(this_present_id && that_present_id)) return false; if (this.id != that.id) return false; } boolean this_present_time = true; boolean that_present_time = true; if (this_present_time || that_present_time) { if (!(this_present_time && that_present_time)) return false; if (this.time != that.time) return false; } boolean this_present_worker = true; boolean that_present_worker = true; if (this_present_worker || that_present_worker) { if (!(this_present_worker && that_present_worker)) return false; if (this.worker != that.worker) return false; } boolean this_present_sequence = true; boolean that_present_sequence = true; if (this_present_sequence || that_present_sequence) { if (!(this_present_sequence && that_present_sequence)) return false; if (this.sequence != that.sequence) return false; } return true; } @Override public int hashCode() { return 0; } public int compareTo(IdDetailed other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; IdDetailed typedOther = (IdDetailed) other; lastComparison = Boolean.valueOf(isSetId()).compareTo(typedOther.isSetId()); if (lastComparison != 0) { return lastComparison; } if (isSetId()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, typedOther.id); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetTime()).compareTo(typedOther.isSetTime()); if (lastComparison != 0) { return lastComparison; } if (isSetTime()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.time, typedOther.time); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetWorker()).compareTo(typedOther.isSetWorker()); if (lastComparison != 0) { return lastComparison; } if (isSetWorker()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.worker, typedOther.worker); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetSequence()).compareTo(typedOther.isSetSequence()); if (lastComparison != 0) { return lastComparison; } if (isSetSequence()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sequence, typedOther.sequence); 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("IdDetailed("); boolean first = true; sb.append("id:"); sb.append(this.id); first = false; if (!first) sb.append(", "); sb.append("time:"); sb.append(this.time); first = false; if (!first) sb.append(", "); sb.append("worker:"); sb.append(this.worker); first = false; if (!first) sb.append(", "); sb.append("sequence:"); sb.append(this.sequence); first = false; sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // alas, we cannot check 'id' because it's a primitive and you chose the non-beans generator. // alas, we cannot check 'time' because it's a primitive and you chose the non-beans generator. // alas, we cannot check 'worker' because it's a primitive and you chose the non-beans generator. // alas, we cannot check 'sequence' 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 IdDetailedStandardSchemeFactory implements SchemeFactory { public IdDetailedStandardScheme getScheme() { return new IdDetailedStandardScheme(); } } private static class IdDetailedStandardScheme extends StandardScheme<IdDetailed> { public void read(org.apache.thrift.protocol.TProtocol iprot, IdDetailed 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: // ID if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.id = iprot.readI64(); struct.setIdIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // TIME if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.time = iprot.readI64(); struct.setTimeIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 3: // WORKER if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.worker = iprot.readI32(); struct.setWorkerIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 4: // SEQUENCE if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.sequence = iprot.readI32(); struct.setSequenceIsSet(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.isSetId()) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'id' was not found in serialized data! Struct: " + toString()); } if (!struct.isSetTime()) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'time' was not found in serialized data! Struct: " + toString()); } if (!struct.isSetWorker()) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'worker' was not found in serialized data! Struct: " + toString()); } if (!struct.isSetSequence()) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'sequence' was not found in serialized data! Struct: " + toString()); } struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, IdDetailed struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(ID_FIELD_DESC); oprot.writeI64(struct.id); oprot.writeFieldEnd(); oprot.writeFieldBegin(TIME_FIELD_DESC); oprot.writeI64(struct.time); oprot.writeFieldEnd(); oprot.writeFieldBegin(WORKER_FIELD_DESC); oprot.writeI32(struct.worker); oprot.writeFieldEnd(); oprot.writeFieldBegin(SEQUENCE_FIELD_DESC); oprot.writeI32(struct.sequence); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class IdDetailedTupleSchemeFactory implements SchemeFactory { public IdDetailedTupleScheme getScheme() { return new IdDetailedTupleScheme(); } } private static class IdDetailedTupleScheme extends TupleScheme<IdDetailed> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, IdDetailed struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; oprot.writeI64(struct.id); oprot.writeI64(struct.time); oprot.writeI32(struct.worker); oprot.writeI32(struct.sequence); } @Override public void read(org.apache.thrift.protocol.TProtocol prot, IdDetailed struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; struct.id = iprot.readI64(); struct.setIdIsSet(true); struct.time = iprot.readI64(); struct.setTimeIsSet(true); struct.worker = iprot.readI32(); struct.setWorkerIsSet(true); struct.sequence = iprot.readI32(); struct.setSequenceIsSet(true); } } }