/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */

/*
This program was generated by the following Python script:

#!/usr/bin/python2.5

# Remove this when Python 2.6 hits the streets.
from __future__ import with_statement

import sys
import os.path


# Quines the easy way.
with open(sys.argv[0], 'r') as handle:
  source = handle.read()

with open(os.path.join(os.path.dirname(sys.argv[0]), 'EqualityTest.java'), 'w') as out:
  print >> out, ("/""*" r"""
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 """ "*""/")
  print >> out
  print >> out, "/""*"
  print >> out, "This program was generated by the following Python script:"
  print >> out
  out.write(source)
  print >> out, "*""/"

  print >> out, r'''
package org.apache.thrift.test;

// Generated code
import thrift.test.*;

/'''r'''**
 *'''r'''/
public class EqualityTest {
  public static void main(String[] args) throws Exception {
    JavaTestHelper lhs, rhs;
'''

  vals = {
    'int': ("1", "2"),
    'obj': ("\"foo\"", "\"bar\""),
    'bin': ("new byte[]{1,2}", "new byte[]{3,4}"),
  }
  matrix = (
    (False,False),
    (False,True ),
    (True ,False),
    (True ,True ),
  )

  for type in ('int', 'obj', 'bin'):
    for option in ('req', 'opt'):
      nulls = matrix[0:1] if type == 'int' else matrix[-1::-1]
      issets = matrix
      for is_null in nulls:
        for is_set in issets:
          # isset is implied for non-primitives, so only consider the case
          # where isset and non-null match.
          if type != 'int' and list(is_set) != [ not null for null in is_null ]:
            continue
          for equal in (True, False):
            print >> out
            print >> out, "    lhs = new JavaTestHelper();"
            print >> out, "    rhs = new JavaTestHelper();"
            print >> out, "    lhs." + option + "_" + type, "=", vals[type][0] + ";"
            print >> out, "    rhs." + option + "_" + type, "=", vals[type][0 if equal else 1] + ";"
            isset_setter = "set" + option[0].upper() + option[1:] + "_" + type + "IsSet"
            if (type == 'int' and is_set[0]): print >> out, "    lhs." + isset_setter + "(true);"
            if (type == 'int' and is_set[1]): print >> out, "    rhs." + isset_setter + "(true);"
            if (is_null[0]): print >> out, "    lhs." + option + "_" + type, "= null;"
            if (is_null[1]): print >> out, "    rhs." + option + "_" + type, "= null;"
            this_present = not is_null[0] and (option == 'req' or is_set[0])
            that_present = not is_null[1] and (option == 'req' or is_set[1])
            print >> out, "    // this_present = " + repr(this_present)
            print >> out, "    // that_present = " + repr(that_present)
            is_equal = \
                (not this_present and not that_present) or \
                (this_present and that_present and equal)
            eq_str = 'true' if is_equal else 'false'

            print >> out, "    if (lhs.equals(rhs) != "+eq_str+")"
            print >> out, "      throw new RuntimeException(\"Failure\");"
            if is_equal:
              print >> out, "    if (lhs.hashCode() != rhs.hashCode())"
              print >> out, "      throw new RuntimeException(\"Failure\");"

  print >> out, r'''
  }
}
'''
*/

package org.apache.thrift.test;

// Generated code
import java.nio.ByteBuffer;
import thrift.test.JavaTestHelper;

/** */
public class EqualityTest {
  public static void main(String[] args) throws Exception {
    JavaTestHelper lhs, rhs;

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 1;
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 2;
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 1;
    rhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 2;
    rhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 1;
    lhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 2;
    lhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 1;
    lhs.setReq_intIsSet(true);
    rhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_int = 1;
    rhs.req_int = 2;
    lhs.setReq_intIsSet(true);
    rhs.setReq_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 1;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 2;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 1;
    rhs.setOpt_intIsSet(true);
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 2;
    rhs.setOpt_intIsSet(true);
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 1;
    lhs.setOpt_intIsSet(true);
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 2;
    lhs.setOpt_intIsSet(true);
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 1;
    lhs.setOpt_intIsSet(true);
    rhs.setOpt_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_int = 1;
    rhs.opt_int = 2;
    lhs.setOpt_intIsSet(true);
    rhs.setOpt_intIsSet(true);
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "foo";
    lhs.req_obj = null;
    rhs.req_obj = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "bar";
    lhs.req_obj = null;
    rhs.req_obj = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "foo";
    lhs.req_obj = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "bar";
    lhs.req_obj = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "foo";
    rhs.req_obj = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "bar";
    rhs.req_obj = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "foo";
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_obj = "foo";
    rhs.req_obj = "bar";
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "foo";
    lhs.opt_obj = null;
    rhs.opt_obj = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "bar";
    lhs.opt_obj = null;
    rhs.opt_obj = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "foo";
    lhs.opt_obj = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "bar";
    lhs.opt_obj = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "foo";
    rhs.opt_obj = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "bar";
    rhs.opt_obj = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "foo";
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_obj = "foo";
    rhs.opt_obj = "bar";
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    lhs.req_bin = null;
    rhs.req_bin = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {3, 4});
    lhs.req_bin = null;
    rhs.req_bin = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    lhs.req_bin = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {3, 4});
    lhs.req_bin = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {3, 4});
    rhs.req_bin = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.req_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.req_bin = ByteBuffer.wrap(new byte[] {3, 4});
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    lhs.opt_bin = null;
    rhs.opt_bin = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {3, 4});
    lhs.opt_bin = null;
    rhs.opt_bin = null;
    // this_present = False
    // that_present = False
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    lhs.opt_bin = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {3, 4});
    lhs.opt_bin = null;
    // this_present = False
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {3, 4});
    rhs.opt_bin = null;
    // this_present = True
    // that_present = False
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != true) throw new RuntimeException("Failure");
    if (lhs.hashCode() != rhs.hashCode()) throw new RuntimeException("Failure");

    lhs = new JavaTestHelper();
    rhs = new JavaTestHelper();
    lhs.opt_bin = ByteBuffer.wrap(new byte[] {1, 2});
    rhs.opt_bin = ByteBuffer.wrap(new byte[] {3, 4});
    // this_present = True
    // that_present = True
    if (lhs.equals(rhs) != false) throw new RuntimeException("Failure");
  }
}
