/*******************************************************************************
 * Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the LGPL 3.0
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *
 * Contributors:
 *      Faiez Zalila - initial API and implementation and/or initial documentation
 *******************************************************************************/
/**
 * Autogenerated by Thrift Compiler (0.9.2)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package tts;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Generated;

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;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-2-8")
public class Net implements org.apache.thrift.TBase<Net, Net._Fields>, java.io.Serializable, Cloneable, Comparable<Net> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Net");

  private static final org.apache.thrift.protocol.TField PLACES_FIELD_DESC = new org.apache.thrift.protocol.TField("places", org.apache.thrift.protocol.TType.LIST, (short)1);
  private static final org.apache.thrift.protocol.TField TRANSITIONS_FIELD_DESC = new org.apache.thrift.protocol.TField("transitions", org.apache.thrift.protocol.TType.LIST, (short)2);
  private static final org.apache.thrift.protocol.TField TIMED_FIELD_DESC = new org.apache.thrift.protocol.TField("timed", org.apache.thrift.protocol.TType.BOOL, (short)3);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new NetStandardSchemeFactory());
    schemes.put(TupleScheme.class, new NetTupleSchemeFactory());
  }

  public List<Place> places; // required
  public List<Transition> transitions; // required
  public boolean timed; // 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 {
    PLACES((short)1, "places"),
    TRANSITIONS((short)2, "transitions"),
    TIMED((short)3, "timed");

    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: // PLACES
          return PLACES;
        case 2: // TRANSITIONS
          return TRANSITIONS;
        case 3: // TIMED
          return TIMED;
        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 __TIMED_ISSET_ID = 0;
  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.PLACES, new org.apache.thrift.meta_data.FieldMetaData("places", 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, Place.class))));
    tmpMap.put(_Fields.TRANSITIONS, new org.apache.thrift.meta_data.FieldMetaData("transitions", 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, Transition.class))));
    tmpMap.put(_Fields.TIMED, new org.apache.thrift.meta_data.FieldMetaData("timed", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Net.class, metaDataMap);
  }

  public Net() {
  }

  public Net(
    List<Place> places,
    List<Transition> transitions,
    boolean timed)
  {
    this();
    this.places = places;
    this.transitions = transitions;
    this.timed = timed;
    setTimedIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Net(Net other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetPlaces()) {
      List<Place> __this__places = new ArrayList<Place>(other.places.size());
      for (Place other_element : other.places) {
        __this__places.add(new Place(other_element));
      }
      this.places = __this__places;
    }
    if (other.isSetTransitions()) {
      List<Transition> __this__transitions = new ArrayList<Transition>(other.transitions.size());
      for (Transition other_element : other.transitions) {
        __this__transitions.add(new Transition(other_element));
      }
      this.transitions = __this__transitions;
    }
    this.timed = other.timed;
  }

  public Net deepCopy() {
    return new Net(this);
  }

  @Override
  public void clear() {
    this.places = null;
    this.transitions = null;
    setTimedIsSet(false);
    this.timed = false;
  }

  public int getPlacesSize() {
    return (this.places == null) ? 0 : this.places.size();
  }

  public java.util.Iterator<Place> getPlacesIterator() {
    return (this.places == null) ? null : this.places.iterator();
  }

  public void addToPlaces(Place elem) {
    if (this.places == null) {
      this.places = new ArrayList<Place>();
    }
    this.places.add(elem);
  }

  public List<Place> getPlaces() {
    return this.places;
  }

  public Net setPlaces(List<Place> places) {
    this.places = places;
    return this;
  }

  public void unsetPlaces() {
    this.places = null;
  }

  /** Returns true if field places is set (has been assigned a value) and false otherwise */
  public boolean isSetPlaces() {
    return this.places != null;
  }

  public void setPlacesIsSet(boolean value) {
    if (!value) {
      this.places = null;
    }
  }

  public int getTransitionsSize() {
    return (this.transitions == null) ? 0 : this.transitions.size();
  }

  public java.util.Iterator<Transition> getTransitionsIterator() {
    return (this.transitions == null) ? null : this.transitions.iterator();
  }

  public void addToTransitions(Transition elem) {
    if (this.transitions == null) {
      this.transitions = new ArrayList<Transition>();
    }
    this.transitions.add(elem);
  }

  public List<Transition> getTransitions() {
    return this.transitions;
  }

  public Net setTransitions(List<Transition> transitions) {
    this.transitions = transitions;
    return this;
  }

  public void unsetTransitions() {
    this.transitions = null;
  }

  /** Returns true if field transitions is set (has been assigned a value) and false otherwise */
  public boolean isSetTransitions() {
    return this.transitions != null;
  }

  public void setTransitionsIsSet(boolean value) {
    if (!value) {
      this.transitions = null;
    }
  }

  public boolean isTimed() {
    return this.timed;
  }

  public Net setTimed(boolean timed) {
    this.timed = timed;
    setTimedIsSet(true);
    return this;
  }

  public void unsetTimed() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TIMED_ISSET_ID);
  }

  /** Returns true if field timed is set (has been assigned a value) and false otherwise */
  public boolean isSetTimed() {
    return EncodingUtils.testBit(__isset_bitfield, __TIMED_ISSET_ID);
  }

  public void setTimedIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TIMED_ISSET_ID, value);
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case PLACES:
      if (value == null) {
        unsetPlaces();
      } else {
        setPlaces((List<Place>)value);
      }
      break;

    case TRANSITIONS:
      if (value == null) {
        unsetTransitions();
      } else {
        setTransitions((List<Transition>)value);
      }
      break;

    case TIMED:
      if (value == null) {
        unsetTimed();
      } else {
        setTimed((Boolean)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case PLACES:
      return getPlaces();

    case TRANSITIONS:
      return getTransitions();

    case TIMED:
      return Boolean.valueOf(isTimed());

    }
    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 PLACES:
      return isSetPlaces();
    case TRANSITIONS:
      return isSetTransitions();
    case TIMED:
      return isSetTimed();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof Net)
      return this.equals((Net)that);
    return false;
  }

  public boolean equals(Net that) {
    if (that == null)
      return false;

    boolean this_present_places = true && this.isSetPlaces();
    boolean that_present_places = true && that.isSetPlaces();
    if (this_present_places || that_present_places) {
      if (!(this_present_places && that_present_places))
        return false;
      if (!this.places.equals(that.places))
        return false;
    }

    boolean this_present_transitions = true && this.isSetTransitions();
    boolean that_present_transitions = true && that.isSetTransitions();
    if (this_present_transitions || that_present_transitions) {
      if (!(this_present_transitions && that_present_transitions))
        return false;
      if (!this.transitions.equals(that.transitions))
        return false;
    }

    boolean this_present_timed = true;
    boolean that_present_timed = true;
    if (this_present_timed || that_present_timed) {
      if (!(this_present_timed && that_present_timed))
        return false;
      if (this.timed != that.timed)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_places = true && (isSetPlaces());
    list.add(present_places);
    if (present_places)
      list.add(places);

    boolean present_transitions = true && (isSetTransitions());
    list.add(present_transitions);
    if (present_transitions)
      list.add(transitions);

    boolean present_timed = true;
    list.add(present_timed);
    if (present_timed)
      list.add(timed);

    return list.hashCode();
  }

  @Override
  public int compareTo(Net other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetPlaces()).compareTo(other.isSetPlaces());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPlaces()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.places, other.places);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTransitions()).compareTo(other.isSetTransitions());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTransitions()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.transitions, other.transitions);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTimed()).compareTo(other.isSetTimed());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTimed()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timed, other.timed);
      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("Net(");
    boolean first = true;

    sb.append("places:");
    if (this.places == null) {
      sb.append("null");
    } else {
      sb.append(this.places);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("transitions:");
    if (this.transitions == null) {
      sb.append("null");
    } else {
      sb.append(this.transitions);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("timed:");
    sb.append(this.timed);
    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 NetStandardSchemeFactory implements SchemeFactory {
    public NetStandardScheme getScheme() {
      return new NetStandardScheme();
    }
  }

  private static class NetStandardScheme extends StandardScheme<Net> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, Net 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: // PLACES
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList _list18 = iprot.readListBegin();
                struct.places = new ArrayList<Place>(_list18.size);
                Place _elem19;
                for (int _i20 = 0; _i20 < _list18.size; ++_i20)
                {
                  _elem19 = new Place();
                  _elem19.read(iprot);
                  struct.places.add(_elem19);
                }
                iprot.readListEnd();
              }
              struct.setPlacesIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // TRANSITIONS
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList _list21 = iprot.readListBegin();
                struct.transitions = new ArrayList<Transition>(_list21.size);
                Transition _elem22;
                for (int _i23 = 0; _i23 < _list21.size; ++_i23)
                {
                  _elem22 = new Transition();
                  _elem22.read(iprot);
                  struct.transitions.add(_elem22);
                }
                iprot.readListEnd();
              }
              struct.setTransitionsIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // TIMED
            if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
              struct.timed = iprot.readBool();
              struct.setTimedIsSet(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, Net struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.places != null) {
        oprot.writeFieldBegin(PLACES_FIELD_DESC);
        {
          oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.places.size()));
          for (Place _iter24 : struct.places)
          {
            _iter24.write(oprot);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      if (struct.transitions != null) {
        oprot.writeFieldBegin(TRANSITIONS_FIELD_DESC);
        {
          oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.transitions.size()));
          for (Transition _iter25 : struct.transitions)
          {
            _iter25.write(oprot);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(TIMED_FIELD_DESC);
      oprot.writeBool(struct.timed);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class NetTupleSchemeFactory implements SchemeFactory {
    public NetTupleScheme getScheme() {
      return new NetTupleScheme();
    }
  }

  private static class NetTupleScheme extends TupleScheme<Net> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, Net struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetPlaces()) {
        optionals.set(0);
      }
      if (struct.isSetTransitions()) {
        optionals.set(1);
      }
      if (struct.isSetTimed()) {
        optionals.set(2);
      }
      oprot.writeBitSet(optionals, 3);
      if (struct.isSetPlaces()) {
        {
          oprot.writeI32(struct.places.size());
          for (Place _iter26 : struct.places)
          {
            _iter26.write(oprot);
          }
        }
      }
      if (struct.isSetTransitions()) {
        {
          oprot.writeI32(struct.transitions.size());
          for (Transition _iter27 : struct.transitions)
          {
            _iter27.write(oprot);
          }
        }
      }
      if (struct.isSetTimed()) {
        oprot.writeBool(struct.timed);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, Net struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(3);
      if (incoming.get(0)) {
        {
          org.apache.thrift.protocol.TList _list28 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
          struct.places = new ArrayList<Place>(_list28.size);
          Place _elem29;
          for (int _i30 = 0; _i30 < _list28.size; ++_i30)
          {
            _elem29 = new Place();
            _elem29.read(iprot);
            struct.places.add(_elem29);
          }
        }
        struct.setPlacesIsSet(true);
      }
      if (incoming.get(1)) {
        {
          org.apache.thrift.protocol.TList _list31 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
          struct.transitions = new ArrayList<Transition>(_list31.size);
          Transition _elem32;
          for (int _i33 = 0; _i33 < _list31.size; ++_i33)
          {
            _elem32 = new Transition();
            _elem32.read(iprot);
            struct.transitions.add(_elem32);
          }
        }
        struct.setTransitionsIsSet(true);
      }
      if (incoming.get(2)) {
        struct.timed = iprot.readBool();
        struct.setTimedIsSet(true);
      }
    }
  }

}

