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.services.provenance.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 AddDocumentResult implements org.apache.thrift.TBase<AddDocumentResult, AddDocumentResult._Fields>, java.io.Serializable, Cloneable, Comparable<AddDocumentResult> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct( "AddDocumentResult"); private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField( "status", org.apache.thrift.protocol.TType.I32, (short) 1); private static final org.apache.thrift.protocol.TField DOCUMENT_ID_FIELD_DESC = new org.apache.thrift.protocol.TField( "documentId", org.apache.thrift.protocol.TType.I64, (short) 2); private static final org.apache.thrift.protocol.TField PARENTS_NOT_FOUND_FIELD_DESC = new org.apache.thrift.protocol.TField( "parentsNotFound", 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 AddDocumentResultStandardSchemeFactory()); schemes.put(TupleScheme.class, new AddDocumentResultTupleSchemeFactory()); } /** * * @see AddDocumentStatus */ public AddDocumentStatus status; // required public long documentId; // optional public List<String> parentsNotFound; // 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 { /** * * @see AddDocumentStatus */ STATUS((short) 1, "status"), DOCUMENT_ID((short) 2, "documentId"), PARENTS_NOT_FOUND((short) 3, "parentsNotFound"); 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: // STATUS return STATUS; case 2: // DOCUMENT_ID return DOCUMENT_ID; case 3: // PARENTS_NOT_FOUND return PARENTS_NOT_FOUND; 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 __DOCUMENTID_ISSET_ID = 0; private byte __isset_bitfield = 0; private _Fields optionals[] = { _Fields.DOCUMENT_ID, _Fields.PARENTS_NOT_FOUND }; 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.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, AddDocumentStatus.class))); tmpMap.put(_Fields.DOCUMENT_ID, new org.apache.thrift.meta_data.FieldMetaData("documentId", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); tmpMap.put(_Fields.PARENTS_NOT_FOUND, new org.apache.thrift.meta_data.FieldMetaData("parentsNotFound", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, new org.apache.thrift.meta_data.FieldValueMetaData( org.apache.thrift.protocol.TType.STRING)))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(AddDocumentResult.class, metaDataMap); } public AddDocumentResult() { } public AddDocumentResult(AddDocumentStatus status) { this(); this.status = status; } /** * Performs a deep copy on <i>other</i>. */ public AddDocumentResult(AddDocumentResult other) { __isset_bitfield = other.__isset_bitfield; if (other.isSetStatus()) { this.status = other.status; } this.documentId = other.documentId; if (other.isSetParentsNotFound()) { List<String> __this__parentsNotFound = new ArrayList<String>(other.parentsNotFound); this.parentsNotFound = __this__parentsNotFound; } } public AddDocumentResult deepCopy() { return new AddDocumentResult(this); } @Override public void clear() { this.status = null; setDocumentIdIsSet(false); this.documentId = 0; this.parentsNotFound = null; } /** * * @see AddDocumentStatus */ public AddDocumentStatus getStatus() { return this.status; } /** * * @see AddDocumentStatus */ public AddDocumentResult setStatus(AddDocumentStatus status) { this.status = status; return this; } public void unsetStatus() { this.status = null; } /** Returns true if field status is set (has been assigned a value) and false otherwise */ public boolean isSetStatus() { return this.status != null; } public void setStatusIsSet(boolean value) { if (!value) { this.status = null; } } public long getDocumentId() { return this.documentId; } public AddDocumentResult setDocumentId(long documentId) { this.documentId = documentId; setDocumentIdIsSet(true); return this; } public void unsetDocumentId() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __DOCUMENTID_ISSET_ID); } /** Returns true if field documentId is set (has been assigned a value) and false otherwise */ public boolean isSetDocumentId() { return EncodingUtils.testBit(__isset_bitfield, __DOCUMENTID_ISSET_ID); } public void setDocumentIdIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __DOCUMENTID_ISSET_ID, value); } public int getParentsNotFoundSize() { return (this.parentsNotFound == null) ? 0 : this.parentsNotFound.size(); } public java.util.Iterator<String> getParentsNotFoundIterator() { return (this.parentsNotFound == null) ? null : this.parentsNotFound.iterator(); } public void addToParentsNotFound(String elem) { if (this.parentsNotFound == null) { this.parentsNotFound = new ArrayList<String>(); } this.parentsNotFound.add(elem); } public List<String> getParentsNotFound() { return this.parentsNotFound; } public AddDocumentResult setParentsNotFound(List<String> parentsNotFound) { this.parentsNotFound = parentsNotFound; return this; } public void unsetParentsNotFound() { this.parentsNotFound = null; } /** Returns true if field parentsNotFound is set (has been assigned a value) and false otherwise */ public boolean isSetParentsNotFound() { return this.parentsNotFound != null; } public void setParentsNotFoundIsSet(boolean value) { if (!value) { this.parentsNotFound = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case STATUS: if (value == null) { unsetStatus(); } else { setStatus((AddDocumentStatus) value); } break; case DOCUMENT_ID: if (value == null) { unsetDocumentId(); } else { setDocumentId((Long) value); } break; case PARENTS_NOT_FOUND: if (value == null) { unsetParentsNotFound(); } else { setParentsNotFound((List<String>) value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case STATUS: return getStatus(); case DOCUMENT_ID: return Long.valueOf(getDocumentId()); case PARENTS_NOT_FOUND: return getParentsNotFound(); } 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 STATUS: return isSetStatus(); case DOCUMENT_ID: return isSetDocumentId(); case PARENTS_NOT_FOUND: return isSetParentsNotFound(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof AddDocumentResult) return this.equals((AddDocumentResult) that); return false; } public boolean equals(AddDocumentResult that) { if (that == null) return false; boolean this_present_status = true && this.isSetStatus(); boolean that_present_status = true && that.isSetStatus(); if (this_present_status || that_present_status) { if (!(this_present_status && that_present_status)) return false; if (!this.status.equals(that.status)) return false; } boolean this_present_documentId = true && this.isSetDocumentId(); boolean that_present_documentId = true && that.isSetDocumentId(); if (this_present_documentId || that_present_documentId) { if (!(this_present_documentId && that_present_documentId)) return false; if (this.documentId != that.documentId) return false; } boolean this_present_parentsNotFound = true && this.isSetParentsNotFound(); boolean that_present_parentsNotFound = true && that.isSetParentsNotFound(); if (this_present_parentsNotFound || that_present_parentsNotFound) { if (!(this_present_parentsNotFound && that_present_parentsNotFound)) return false; if (!this.parentsNotFound.equals(that.parentsNotFound)) return false; } return true; } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); boolean present_status = true && (isSetStatus()); builder.append(present_status); if (present_status) builder.append(status.getValue()); boolean present_documentId = true && (isSetDocumentId()); builder.append(present_documentId); if (present_documentId) builder.append(documentId); boolean present_parentsNotFound = true && (isSetParentsNotFound()); builder.append(present_parentsNotFound); if (present_parentsNotFound) builder.append(parentsNotFound); return builder.toHashCode(); } @Override public int compareTo(AddDocumentResult other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; lastComparison = Boolean.valueOf(isSetStatus()).compareTo(other.isSetStatus()); if (lastComparison != 0) { return lastComparison; } if (isSetStatus()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, other.status); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetDocumentId()).compareTo(other.isSetDocumentId()); if (lastComparison != 0) { return lastComparison; } if (isSetDocumentId()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.documentId, other.documentId); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetParentsNotFound()).compareTo(other.isSetParentsNotFound()); if (lastComparison != 0) { return lastComparison; } if (isSetParentsNotFound()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.parentsNotFound, other.parentsNotFound); 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("AddDocumentResult("); boolean first = true; sb.append("status:"); if (this.status == null) { sb.append("null"); } else { sb.append(this.status); } first = false; if (isSetDocumentId()) { if (!first) sb.append(", "); sb.append("documentId:"); sb.append(this.documentId); first = false; } if (isSetParentsNotFound()) { if (!first) sb.append(", "); sb.append("parentsNotFound:"); if (this.parentsNotFound == null) { sb.append("null"); } else { sb.append(this.parentsNotFound); } first = false; } sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields if (status == null) { throw new org.apache.thrift.protocol.TProtocolException( "Required field 'status' was not present! Struct: " + toString()); } // 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 AddDocumentResultStandardSchemeFactory implements SchemeFactory { public AddDocumentResultStandardScheme getScheme() { return new AddDocumentResultStandardScheme(); } } private static class AddDocumentResultStandardScheme extends StandardScheme<AddDocumentResult> { public void read(org.apache.thrift.protocol.TProtocol iprot, AddDocumentResult 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: // STATUS if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.status = AddDocumentStatus.findByValue(iprot.readI32()); struct.setStatusIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // DOCUMENT_ID if (schemeField.type == org.apache.thrift.protocol.TType.I64) { struct.documentId = iprot.readI64(); struct.setDocumentIdIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 3: // PARENTS_NOT_FOUND if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { { org.apache.thrift.protocol.TList _list182 = iprot.readListBegin(); struct.parentsNotFound = new ArrayList<String>(_list182.size); for (int _i183 = 0; _i183 < _list182.size; ++_i183) { String _elem184; _elem184 = iprot.readString(); struct.parentsNotFound.add(_elem184); } iprot.readListEnd(); } struct.setParentsNotFoundIsSet(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, AddDocumentResult struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.status != null) { oprot.writeFieldBegin(STATUS_FIELD_DESC); oprot.writeI32(struct.status.getValue()); oprot.writeFieldEnd(); } if (struct.isSetDocumentId()) { oprot.writeFieldBegin(DOCUMENT_ID_FIELD_DESC); oprot.writeI64(struct.documentId); oprot.writeFieldEnd(); } if (struct.parentsNotFound != null) { if (struct.isSetParentsNotFound()) { oprot.writeFieldBegin(PARENTS_NOT_FOUND_FIELD_DESC); { oprot.writeListBegin(new org.apache.thrift.protocol.TList( org.apache.thrift.protocol.TType.STRING, struct.parentsNotFound.size())); for (String _iter185 : struct.parentsNotFound) { oprot.writeString(_iter185); } oprot.writeListEnd(); } oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class AddDocumentResultTupleSchemeFactory implements SchemeFactory { public AddDocumentResultTupleScheme getScheme() { return new AddDocumentResultTupleScheme(); } } private static class AddDocumentResultTupleScheme extends TupleScheme<AddDocumentResult> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, AddDocumentResult struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; oprot.writeI32(struct.status.getValue()); BitSet optionals = new BitSet(); if (struct.isSetDocumentId()) { optionals.set(0); } if (struct.isSetParentsNotFound()) { optionals.set(1); } oprot.writeBitSet(optionals, 2); if (struct.isSetDocumentId()) { oprot.writeI64(struct.documentId); } if (struct.isSetParentsNotFound()) { { oprot.writeI32(struct.parentsNotFound.size()); for (String _iter186 : struct.parentsNotFound) { oprot.writeString(_iter186); } } } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, AddDocumentResult struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; struct.status = AddDocumentStatus.findByValue(iprot.readI32()); struct.setStatusIsSet(true); BitSet incoming = iprot.readBitSet(2); if (incoming.get(0)) { struct.documentId = iprot.readI64(); struct.setDocumentIdIsSet(true); } if (incoming.get(1)) { { org.apache.thrift.protocol.TList _list187 = new org.apache.thrift.protocol.TList( org.apache.thrift.protocol.TType.STRING, iprot.readI32()); struct.parentsNotFound = new ArrayList<String>(_list187.size); for (int _i188 = 0; _i188 < _list187.size; ++_i188) { String _elem189; _elem189 = iprot.readString(); struct.parentsNotFound.add(_elem189); } } struct.setParentsNotFoundIsSet(true); } } } }