/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package com.ociweb.jnb.thrift.gen;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import org.apache.thrift.TFieldRequirementType;
import org.apache.thrift.meta_data.FieldMetaData;
import org.apache.thrift.meta_data.FieldValueMetaData;
import org.apache.thrift.meta_data.ListMetaData;
import org.apache.thrift.meta_data.StructMetaData;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TList;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolUtil;
import org.apache.thrift.protocol.TStruct;
import org.apache.thrift.protocol.TType;

@SuppressWarnings("serial")
public class Course implements TBase, java.io.Serializable, Cloneable {
    private static final TStruct STRUCT_DESC = new TStruct("Course");
    private static final TField ID_FIELD_DESC = new TField("id", TType.I32, (short) 1);
    private static final TField NUMBER_FIELD_DESC = new TField("number", TType.STRING, (short) 2);
    private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short) 3);
    private static final TField INSTRUCTOR_FIELD_DESC = new TField("instructor", TType.STRUCT, (short) 4);
    private static final TField ROOM_NUMBER_FIELD_DESC = new TField("roomNumber", TType.STRING, (short) 5);
    private static final TField STUDENTS_FIELD_DESC = new TField("students", TType.LIST, (short) 6);

    public int id;
    public static final int ID = 1;
    public String number;
    public static final int NUMBER = 2;
    public String name;
    public static final int NAME = 3;
    public Person instructor;
    public static final int INSTRUCTOR = 4;
    public String roomNumber;
    public static final int ROOMNUMBER = 5;
    public List<Person> students;
    public static final int STUDENTS = 6;

    private final Isset __isset = new Isset();

    private static final class Isset implements java.io.Serializable {
        public boolean id = false;
    }

    public static final Map<Integer, FieldMetaData> metaDataMap = Collections
            .unmodifiableMap(new HashMap<Integer, FieldMetaData>() {
                {
                    put(ID, new FieldMetaData("id", TFieldRequirementType.DEFAULT, new FieldValueMetaData(TType.I32)));
                    put(NUMBER, new FieldMetaData("number", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                    put(NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                    put(INSTRUCTOR, new FieldMetaData("instructor", TFieldRequirementType.DEFAULT, new StructMetaData(
                            TType.STRUCT, Person.class)));
                    put(ROOMNUMBER, new FieldMetaData("roomNumber", TFieldRequirementType.DEFAULT,
                            new FieldValueMetaData(TType.STRING)));
                    put(STUDENTS, new FieldMetaData("students", TFieldRequirementType.DEFAULT, new ListMetaData(
                            TType.LIST, new StructMetaData(TType.STRUCT, Person.class))));
                }
            });

    static {
        FieldMetaData.addStructMetaDataMap(Course.class, metaDataMap);
    }

    public Course() {
    }

    public Course(int id, String number, String name, Person instructor, String roomNumber, List<Person> students) {
        this();
        this.id = id;
        this.__isset.id = true;
        this.number = number;
        this.name = name;
        this.instructor = instructor;
        this.roomNumber = roomNumber;
        this.students = students;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public Course(Course other) {
        __isset.id = other.__isset.id;
        this.id = other.id;
        if (other.isSetNumber()) {
            this.number = other.number;
        }
        if (other.isSetName()) {
            this.name = other.name;
        }
        if (other.isSetInstructor()) {
            this.instructor = new Person(other.instructor);
        }
        if (other.isSetRoomNumber()) {
            this.roomNumber = other.roomNumber;
        }
        if (other.isSetStudents()) {
            List<Person> __this__students = new ArrayList<Person>();
            for (Person other_element : other.students) {
                __this__students.add(new Person(other_element));
            }
            this.students = __this__students;
        }
    }

    @Override
    public Course clone() {
        return new Course(this);
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
        this.__isset.id = true;
    }

    public void unsetId() {
        this.__isset.id = false;
    }

    // Returns true if field id is set (has been asigned a value) and false
    // otherwise
    public boolean isSetId() {
        return this.__isset.id;
    }

    public void setIdIsSet(boolean value) {
        this.__isset.id = value;
    }

    public String getNumber() {
        return this.number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public void unsetNumber() {
        this.number = null;
    }

    // Returns true if field number is set (has been asigned a value) and false
    // otherwise
    public boolean isSetNumber() {
        return this.number != null;
    }

    public void setNumberIsSet(boolean value) {
        if (!value) {
            this.number = null;
        }
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void unsetName() {
        this.name = null;
    }

    // Returns true if field name is set (has been asigned a value) and false
    // otherwise
    public boolean isSetName() {
        return this.name != null;
    }

    public void setNameIsSet(boolean value) {
        if (!value) {
            this.name = null;
        }
    }

    public Person getInstructor() {
        return this.instructor;
    }

    public void setInstructor(Person instructor) {
        this.instructor = instructor;
    }

    public void unsetInstructor() {
        this.instructor = null;
    }

    // Returns true if field instructor is set (has been asigned a value) and
    // false otherwise
    public boolean isSetInstructor() {
        return this.instructor != null;
    }

    public void setInstructorIsSet(boolean value) {
        if (!value) {
            this.instructor = null;
        }
    }

    public String getRoomNumber() {
        return this.roomNumber;
    }

    public void setRoomNumber(String roomNumber) {
        this.roomNumber = roomNumber;
    }

    public void unsetRoomNumber() {
        this.roomNumber = null;
    }

    // Returns true if field roomNumber is set (has been asigned a value) and
    // false otherwise
    public boolean isSetRoomNumber() {
        return this.roomNumber != null;
    }

    public void setRoomNumberIsSet(boolean value) {
        if (!value) {
            this.roomNumber = null;
        }
    }

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

    public java.util.Iterator<Person> getStudentsIterator() {
        return (this.students == null) ? null : this.students.iterator();
    }

    public void addToStudents(Person elem) {
        if (this.students == null) {
            this.students = new ArrayList<Person>();
        }
        this.students.add(elem);
    }

    public List<Person> getStudents() {
        return this.students;
    }

    public void setStudents(List<Person> students) {
        this.students = students;
    }

    public void unsetStudents() {
        this.students = null;
    }

    // Returns true if field students is set (has been asigned a value) and
    // false otherwise
    public boolean isSetStudents() {
        return this.students != null;
    }

    public void setStudentsIsSet(boolean value) {
        if (!value) {
            this.students = null;
        }
    }

    @SuppressWarnings("unchecked")
    public void setFieldValue(int fieldID, Object value) {
        switch (fieldID) {
        case ID:
            if (value == null) {
                unsetId();
            } else {
                setId((Integer) value);
            }
            break;

        case NUMBER:
            if (value == null) {
                unsetNumber();
            } else {
                setNumber((String) value);
            }
            break;

        case NAME:
            if (value == null) {
                unsetName();
            } else {
                setName((String) value);
            }
            break;

        case INSTRUCTOR:
            if (value == null) {
                unsetInstructor();
            } else {
                setInstructor((Person) value);
            }
            break;

        case ROOMNUMBER:
            if (value == null) {
                unsetRoomNumber();
            } else {
                setRoomNumber((String) value);
            }
            break;

        case STUDENTS:
            if (value == null) {
                unsetStudents();
            } else {
                setStudents((List<Person>) value);
            }
            break;

        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

    public Object getFieldValue(int fieldID) {
        switch (fieldID) {
        case ID:
            return new Integer(getId());

        case NUMBER:
            return getNumber();

        case NAME:
            return getName();

        case INSTRUCTOR:
            return getInstructor();

        case ROOMNUMBER:
            return getRoomNumber();

        case STUDENTS:
            return getStudents();

        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

    // Returns true if field corresponding to fieldID is set (has been asigned a
    // value) and false otherwise
    public boolean isSet(int fieldID) {
        switch (fieldID) {
        case ID:
            return isSetId();
        case NUMBER:
            return isSetNumber();
        case NAME:
            return isSetName();
        case INSTRUCTOR:
            return isSetInstructor();
        case ROOMNUMBER:
            return isSetRoomNumber();
        case STUDENTS:
            return isSetStudents();
        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

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

    public boolean equals(Course 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_number = true && this.isSetNumber();
        boolean that_present_number = true && that.isSetNumber();
        if (this_present_number || that_present_number) {
            if (!(this_present_number && that_present_number))
                return false;
            if (!this.number.equals(that.number))
                return false;
        }

        boolean this_present_name = true && this.isSetName();
        boolean that_present_name = true && that.isSetName();
        if (this_present_name || that_present_name) {
            if (!(this_present_name && that_present_name))
                return false;
            if (!this.name.equals(that.name))
                return false;
        }

        boolean this_present_instructor = true && this.isSetInstructor();
        boolean that_present_instructor = true && that.isSetInstructor();
        if (this_present_instructor || that_present_instructor) {
            if (!(this_present_instructor && that_present_instructor))
                return false;
            if (!this.instructor.equals(that.instructor))
                return false;
        }

        boolean this_present_roomNumber = true && this.isSetRoomNumber();
        boolean that_present_roomNumber = true && that.isSetRoomNumber();
        if (this_present_roomNumber || that_present_roomNumber) {
            if (!(this_present_roomNumber && that_present_roomNumber))
                return false;
            if (!this.roomNumber.equals(that.roomNumber))
                return false;
        }

        boolean this_present_students = true && this.isSetStudents();
        boolean that_present_students = true && that.isSetStudents();
        if (this_present_students || that_present_students) {
            if (!(this_present_students && that_present_students))
                return false;
            if (!this.students.equals(that.students))
                return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return 0;
    }

    public void read(TProtocol iprot) throws TException {
        TField field;
        iprot.readStructBegin();
        while (true) {
            field = iprot.readFieldBegin();
            if (field.type == TType.STOP) {
                break;
            }
            switch (field.id) {
            case ID:
                if (field.type == TType.I32) {
                    this.id = iprot.readI32();
                    this.__isset.id = true;
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case NUMBER:
                if (field.type == TType.STRING) {
                    this.number = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case NAME:
                if (field.type == TType.STRING) {
                    this.name = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case INSTRUCTOR:
                if (field.type == TType.STRUCT) {
                    this.instructor = new Person();
                    this.instructor.read(iprot);
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case ROOMNUMBER:
                if (field.type == TType.STRING) {
                    this.roomNumber = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case STUDENTS:
                if (field.type == TType.LIST) {
                    {
                        TList _list4 = iprot.readListBegin();
                        this.students = new ArrayList<Person>(_list4.size);
                        for (int _i5 = 0; _i5 < _list4.size; ++_i5) {
                            Person _elem6;
                            _elem6 = new Person();
                            _elem6.read(iprot);
                            this.students.add(_elem6);
                        }
                        iprot.readListEnd();
                    }
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            default:
                TProtocolUtil.skip(iprot, field.type);
                break;
            }
            iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked
        // in the validate method
        validate();
    }

    public void write(TProtocol oprot) throws TException {
        validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldBegin(ID_FIELD_DESC);
        oprot.writeI32(this.id);
        oprot.writeFieldEnd();
        if (this.number != null) {
            oprot.writeFieldBegin(NUMBER_FIELD_DESC);
            oprot.writeString(this.number);
            oprot.writeFieldEnd();
        }
        if (this.name != null) {
            oprot.writeFieldBegin(NAME_FIELD_DESC);
            oprot.writeString(this.name);
            oprot.writeFieldEnd();
        }
        if (this.instructor != null) {
            oprot.writeFieldBegin(INSTRUCTOR_FIELD_DESC);
            this.instructor.write(oprot);
            oprot.writeFieldEnd();
        }
        if (this.roomNumber != null) {
            oprot.writeFieldBegin(ROOM_NUMBER_FIELD_DESC);
            oprot.writeString(this.roomNumber);
            oprot.writeFieldEnd();
        }
        if (this.students != null) {
            oprot.writeFieldBegin(STUDENTS_FIELD_DESC);
            {
                oprot.writeListBegin(new TList(TType.STRUCT, this.students.size()));
                for (Person _iter7 : this.students) {
                    _iter7.write(oprot);
                }
                oprot.writeListEnd();
            }
            oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Course(");
        boolean first = true;

        sb.append("id:");
        sb.append(this.id);
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("number:");
        if (this.number == null) {
            sb.append("null");
        } else {
            sb.append(this.number);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("name:");
        if (this.name == null) {
            sb.append("null");
        } else {
            sb.append(this.name);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("instructor:");
        if (this.instructor == null) {
            sb.append("null");
        } else {
            sb.append(this.instructor);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("roomNumber:");
        if (this.roomNumber == null) {
            sb.append("null");
        } else {
            sb.append(this.roomNumber);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("students:");
        if (this.students == null) {
            sb.append("null");
        } else {
            sb.append(this.students);
        }
        first = false;
        sb.append(")");
        return sb.toString();
    }

    public void validate() throws TException {
        // check for required fields
        // check that fields of type enum have valid values
    }

}
