001/**
002 * Copyright (c) 2012, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030/**
031 * Autogenerated by Thrift Compiler (0.7.0)
032 *
033 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
034 */
035package net.lag.kestrel.thrift;
036
037import java.nio.ByteBuffer;
038import java.util.BitSet;
039import java.util.Collections;
040import java.util.EnumMap;
041import java.util.EnumSet;
042import java.util.HashMap;
043import java.util.Map;
044
045import org.apache.commons.lang.builder.HashCodeBuilder;
046
047@SuppressWarnings({ "javadoc", "unused", "serial" })
048public class Item implements org.apache.thrift7.TBase<Item, Item._Fields>, java.io.Serializable, Cloneable {
049        private static final org.apache.thrift7.protocol.TStruct STRUCT_DESC = new org.apache.thrift7.protocol.TStruct("Item");
050
051        private static final org.apache.thrift7.protocol.TField DATA_FIELD_DESC = new org.apache.thrift7.protocol.TField(
052                        "data", org.apache.thrift7.protocol.TType.STRING, (short) 1);
053        private static final org.apache.thrift7.protocol.TField ID_FIELD_DESC = new org.apache.thrift7.protocol.TField("id",
054                        org.apache.thrift7.protocol.TType.I64, (short) 2);
055
056        private ByteBuffer data; // required
057        private long id; // required
058
059        /**
060         * The set of fields this struct contains, along with convenience methods
061         * for finding and manipulating them.
062         */
063        public enum _Fields implements org.apache.thrift7.TFieldIdEnum {
064                DATA((short) 1, "data"),
065                ID((short) 2, "id");
066
067                private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
068
069                static {
070                        for (final _Fields field : EnumSet.allOf(_Fields.class)) {
071                                byName.put(field.getFieldName(), field);
072                        }
073                }
074
075                /**
076                 * Find the _Fields constant that matches fieldId, or null if its not
077                 * found.
078                 */
079                public static _Fields findByThriftId(int fieldId) {
080                        switch (fieldId) {
081                        case 1: // DATA
082                                return DATA;
083                        case 2: // ID
084                                return ID;
085                        default:
086                                return null;
087                        }
088                }
089
090                /**
091                 * Find the _Fields constant that matches fieldId, throwing an exception
092                 * if it is not found.
093                 */
094                public static _Fields findByThriftIdOrThrow(int fieldId) {
095                        final _Fields fields = findByThriftId(fieldId);
096                        if (fields == null)
097                                throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
098                        return fields;
099                }
100
101                /**
102                 * Find the _Fields constant that matches name, or null if its not
103                 * found.
104                 */
105                public static _Fields findByName(String name) {
106                        return byName.get(name);
107                }
108
109                private final short _thriftId;
110                private final String _fieldName;
111
112                _Fields(short thriftId, String fieldName) {
113                        _thriftId = thriftId;
114                        _fieldName = fieldName;
115                }
116
117                @Override
118                public short getThriftFieldId() {
119                        return _thriftId;
120                }
121
122                @Override
123                public String getFieldName() {
124                        return _fieldName;
125                }
126        }
127
128        // isset id assignments
129        private static final int __ID_ISSET_ID = 0;
130        private BitSet __isset_bit_vector = new BitSet(1);
131
132        public static final Map<_Fields, org.apache.thrift7.meta_data.FieldMetaData> metaDataMap;
133        static {
134                final Map<_Fields, org.apache.thrift7.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift7.meta_data.FieldMetaData>(
135                                _Fields.class);
136                tmpMap.put(_Fields.DATA, new org.apache.thrift7.meta_data.FieldMetaData("data",
137                                org.apache.thrift7.TFieldRequirementType.DEFAULT,
138                                new org.apache.thrift7.meta_data.FieldValueMetaData(org.apache.thrift7.protocol.TType.STRING, true)));
139                tmpMap.put(_Fields.ID, new org.apache.thrift7.meta_data.FieldMetaData("id",
140                                org.apache.thrift7.TFieldRequirementType.DEFAULT,
141                                new org.apache.thrift7.meta_data.FieldValueMetaData(org.apache.thrift7.protocol.TType.I64)));
142                metaDataMap = Collections.unmodifiableMap(tmpMap);
143                org.apache.thrift7.meta_data.FieldMetaData.addStructMetaDataMap(Item.class, metaDataMap);
144        }
145
146        public Item() {
147        }
148
149        public Item(
150                        ByteBuffer data,
151                        long id)
152        {
153                this();
154                this.data = data;
155                this.id = id;
156                set_id_isSet(true);
157        }
158
159        /**
160         * Performs a deep copy on <i>other</i>.
161         */
162        public Item(Item other) {
163                __isset_bit_vector.clear();
164                __isset_bit_vector.or(other.__isset_bit_vector);
165                if (other.is_set_data()) {
166                        this.data = org.apache.thrift7.TBaseHelper.copyBinary(other.data);
167                        ;
168                }
169                this.id = other.id;
170        }
171
172        @Override
173        public Item deepCopy() {
174                return new Item(this);
175        }
176
177        @Override
178        public void clear() {
179                this.data = null;
180                set_id_isSet(false);
181                this.id = 0;
182        }
183
184        public byte[] get_data() {
185                set_data(org.apache.thrift7.TBaseHelper.rightSize(data));
186                return data == null ? null : data.array();
187        }
188
189        public ByteBuffer buffer_for_data() {
190                return data;
191        }
192
193        public void set_data(byte[] data) {
194                set_data(data == null ? (ByteBuffer) null : ByteBuffer.wrap(data));
195        }
196
197        public void set_data(ByteBuffer data) {
198                this.data = data;
199        }
200
201        public void unset_data() {
202                this.data = null;
203        }
204
205        /**
206         * Returns true if field data is set (has been assigned a value) and false
207         * otherwise
208         */
209        public boolean is_set_data() {
210                return this.data != null;
211        }
212
213        public void set_data_isSet(boolean value) {
214                if (!value) {
215                        this.data = null;
216                }
217        }
218
219        public long get_id() {
220                return this.id;
221        }
222
223        public void set_id(long id) {
224                this.id = id;
225                set_id_isSet(true);
226        }
227
228        public void unset_id() {
229                __isset_bit_vector.clear(__ID_ISSET_ID);
230        }
231
232        /**
233         * Returns true if field id is set (has been assigned a value) and false
234         * otherwise
235         */
236        public boolean is_set_id() {
237                return __isset_bit_vector.get(__ID_ISSET_ID);
238        }
239
240        public void set_id_isSet(boolean value) {
241                __isset_bit_vector.set(__ID_ISSET_ID, value);
242        }
243
244        @Override
245        public void setFieldValue(_Fields field, Object value) {
246                switch (field) {
247                case DATA:
248                        if (value == null) {
249                                unset_data();
250                        } else {
251                                set_data((ByteBuffer) value);
252                        }
253                        break;
254
255                case ID:
256                        if (value == null) {
257                                unset_id();
258                        } else {
259                                set_id((Long) value);
260                        }
261                        break;
262
263                }
264        }
265
266        @Override
267        public Object getFieldValue(_Fields field) {
268                switch (field) {
269                case DATA:
270                        return get_data();
271
272                case ID:
273                        return Long.valueOf(get_id());
274
275                }
276                throw new IllegalStateException();
277        }
278
279        /**
280         * Returns true if field corresponding to fieldID is set (has been assigned
281         * a value) and false otherwise
282         */
283        @Override
284        public boolean isSet(_Fields field) {
285                if (field == null) {
286                        throw new IllegalArgumentException();
287                }
288
289                switch (field) {
290                case DATA:
291                        return is_set_data();
292                case ID:
293                        return is_set_id();
294                }
295                throw new IllegalStateException();
296        }
297
298        @Override
299        public boolean equals(Object that) {
300                if (that == null)
301                        return false;
302                if (that instanceof Item)
303                        return this.equals((Item) that);
304                return false;
305        }
306
307        public boolean equals(Item that) {
308                if (that == null)
309                        return false;
310
311                final boolean this_present_data = true && this.is_set_data();
312                final boolean that_present_data = true && that.is_set_data();
313                if (this_present_data || that_present_data) {
314                        if (!(this_present_data && that_present_data))
315                                return false;
316                        if (!this.data.equals(that.data))
317                                return false;
318                }
319
320                final boolean this_present_id = true;
321                final boolean that_present_id = true;
322                if (this_present_id || that_present_id) {
323                        if (!(this_present_id && that_present_id))
324                                return false;
325                        if (this.id != that.id)
326                                return false;
327                }
328
329                return true;
330        }
331
332        @Override
333        public int hashCode() {
334                final HashCodeBuilder builder = new HashCodeBuilder();
335
336                final boolean present_data = true && (is_set_data());
337                builder.append(present_data);
338                if (present_data)
339                        builder.append(data);
340
341                final boolean present_id = true;
342                builder.append(present_id);
343                if (present_id)
344                        builder.append(id);
345
346                return builder.toHashCode();
347        }
348
349        @Override
350        public int compareTo(Item other) {
351                if (!getClass().equals(other.getClass())) {
352                        return getClass().getName().compareTo(other.getClass().getName());
353                }
354
355                int lastComparison = 0;
356                final Item typedOther = other;
357
358                lastComparison = Boolean.valueOf(is_set_data()).compareTo(typedOther.is_set_data());
359                if (lastComparison != 0) {
360                        return lastComparison;
361                }
362                if (is_set_data()) {
363                        lastComparison = org.apache.thrift7.TBaseHelper.compareTo(this.data, typedOther.data);
364                        if (lastComparison != 0) {
365                                return lastComparison;
366                        }
367                }
368                lastComparison = Boolean.valueOf(is_set_id()).compareTo(typedOther.is_set_id());
369                if (lastComparison != 0) {
370                        return lastComparison;
371                }
372                if (is_set_id()) {
373                        lastComparison = org.apache.thrift7.TBaseHelper.compareTo(this.id, typedOther.id);
374                        if (lastComparison != 0) {
375                                return lastComparison;
376                        }
377                }
378                return 0;
379        }
380
381        @Override
382        public _Fields fieldForId(int fieldId) {
383                return _Fields.findByThriftId(fieldId);
384        }
385
386        @Override
387        public void read(org.apache.thrift7.protocol.TProtocol iprot) throws org.apache.thrift7.TException {
388                org.apache.thrift7.protocol.TField field;
389                iprot.readStructBegin();
390                while (true)
391                {
392                        field = iprot.readFieldBegin();
393                        if (field.type == org.apache.thrift7.protocol.TType.STOP) {
394                                break;
395                        }
396                        switch (field.id) {
397                        case 1: // DATA
398                                if (field.type == org.apache.thrift7.protocol.TType.STRING) {
399                                        this.data = iprot.readBinary();
400                                } else {
401                                        org.apache.thrift7.protocol.TProtocolUtil.skip(iprot, field.type);
402                                }
403                                break;
404                        case 2: // ID
405                                if (field.type == org.apache.thrift7.protocol.TType.I64) {
406                                        this.id = iprot.readI64();
407                                        set_id_isSet(true);
408                                } else {
409                                        org.apache.thrift7.protocol.TProtocolUtil.skip(iprot, field.type);
410                                }
411                                break;
412                        default:
413                                org.apache.thrift7.protocol.TProtocolUtil.skip(iprot, field.type);
414                        }
415                        iprot.readFieldEnd();
416                }
417                iprot.readStructEnd();
418                validate();
419        }
420
421        @Override
422        public void write(org.apache.thrift7.protocol.TProtocol oprot) throws org.apache.thrift7.TException {
423                validate();
424
425                oprot.writeStructBegin(STRUCT_DESC);
426                if (this.data != null) {
427                        oprot.writeFieldBegin(DATA_FIELD_DESC);
428                        oprot.writeBinary(this.data);
429                        oprot.writeFieldEnd();
430                }
431                oprot.writeFieldBegin(ID_FIELD_DESC);
432                oprot.writeI64(this.id);
433                oprot.writeFieldEnd();
434                oprot.writeFieldStop();
435                oprot.writeStructEnd();
436        }
437
438        @Override
439        public String toString() {
440                final StringBuilder sb = new StringBuilder("Item(");
441                boolean first = true;
442
443                sb.append("data:");
444                if (this.data == null) {
445                        sb.append("null");
446                } else {
447                        org.apache.thrift7.TBaseHelper.toString(this.data, sb);
448                }
449                first = false;
450                if (!first)
451                        sb.append(", ");
452                sb.append("id:");
453                sb.append(this.id);
454                first = false;
455                sb.append(")");
456                return sb.toString();
457        }
458
459        public void validate() throws org.apache.thrift7.TException {
460                // check for required fields
461        }
462
463        private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
464                try {
465                        write(new org.apache.thrift7.protocol.TCompactProtocol(new org.apache.thrift7.transport.TIOStreamTransport(
466                                        out)));
467                } catch (final org.apache.thrift7.TException te) {
468                        throw new java.io.IOException(te);
469                }
470        }
471
472        private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
473                try {
474                        // it doesn't seem like you should have to do this, but java
475                        // serialization is wacky, and doesn't call the default constructor.
476                        __isset_bit_vector = new BitSet(1);
477                        read(new org.apache.thrift7.protocol.TCompactProtocol(new org.apache.thrift7.transport.TIOStreamTransport(in)));
478                } catch (final org.apache.thrift7.TException te) {
479                        throw new java.io.IOException(te);
480                }
481        }
482
483}