@Test public void testCompareToDurationLT() throws DatatypeConfigurationException { System.out.println("TModelInstanceDetailsComparator.compare testCompareToDurationLT"); TModelInstanceDetails lhs = new TModelInstanceDetails(); lhs.getTModelInstanceInfo().add(new TModelInstanceInfo()); lhs.getTModelInstanceInfo().get(0).setTModelKey("hi"); lhs.getTModelInstanceInfo().get(0).setInstanceDetails(new InstanceDetails()); lhs.getTModelInstanceInfo().get(0).getInstanceDetails().setInstanceParms("P1Y"); TModelInstanceDetails rhs = new TModelInstanceDetails(); rhs.getTModelInstanceInfo().add(new TModelInstanceInfo()); rhs.getTModelInstanceInfo().get(0).setTModelKey("hi"); rhs.getTModelInstanceInfo().get(0).setInstanceDetails(new InstanceDetails()); rhs.getTModelInstanceInfo().get(0).getInstanceDetails().setInstanceParms("P3Y"); TModelInstanceDetailsComparator instance = new TModelInstanceDetailsComparator("hi", false, false, true); int result = instance.compare(lhs, rhs); Assert.assertTrue("result " + lhs.getTModelInstanceInfo().get(0).getInstanceDetails().getInstanceParms() + " compare to " + rhs.getTModelInstanceInfo().get(0).getInstanceDetails().getInstanceParms() + " " + result, result < 0); }
public int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs) throws IllegalArgumentException, NumberFormatException, NullPointerException, ArrayIndexOutOfBoundsException { if (lhs == null) { throw new IllegalArgumentException("lhs"); } if (rhs == null) { throw new IllegalArgumentException("rhs"); } if (lhs.getTModelInstanceInfo().isEmpty() || rhs.getTModelInstanceInfo().isEmpty()) { throw new IllegalArgumentException("no data to compare"); } InstanceDetails lhsc = null; InstanceDetails rhsc = null; for (int i = 0; i < lhs.getTModelInstanceInfo().size(); i++) { if (lhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { lhsc = lhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } for (int i = 0; i < rhs.getTModelInstanceInfo().size(); i++) { if (rhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { rhsc = rhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } if (lhsc == null) { throw new IllegalArgumentException(compareField + " not found for lhs"); } if (rhsc == null) { throw new IllegalArgumentException(compareField + " not found for rhs"); } if (lhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found lhs, but no data"); } if (rhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found rhs, but no data"); } if (isNumber) { Double l = Double.parseDouble(lhsc.getInstanceParms()); Double r = Double.parseDouble(rhsc.getInstanceParms()); return l.compareTo(r); } if (isDate) { XMLGregorianCalendar l = fac.newXMLGregorianCalendar(lhsc.getInstanceParms()); XMLGregorianCalendar r = fac.newXMLGregorianCalendar(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } if (isDuration) { Duration l = fac.newDuration(lhsc.getInstanceParms()); Duration r = fac.newDuration(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } return 0; }
TModelInstanceDetailsComparator { public int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs) throws IllegalArgumentException, NumberFormatException, NullPointerException, ArrayIndexOutOfBoundsException { if (lhs == null) { throw new IllegalArgumentException("lhs"); } if (rhs == null) { throw new IllegalArgumentException("rhs"); } if (lhs.getTModelInstanceInfo().isEmpty() || rhs.getTModelInstanceInfo().isEmpty()) { throw new IllegalArgumentException("no data to compare"); } InstanceDetails lhsc = null; InstanceDetails rhsc = null; for (int i = 0; i < lhs.getTModelInstanceInfo().size(); i++) { if (lhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { lhsc = lhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } for (int i = 0; i < rhs.getTModelInstanceInfo().size(); i++) { if (rhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { rhsc = rhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } if (lhsc == null) { throw new IllegalArgumentException(compareField + " not found for lhs"); } if (rhsc == null) { throw new IllegalArgumentException(compareField + " not found for rhs"); } if (lhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found lhs, but no data"); } if (rhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found rhs, but no data"); } if (isNumber) { Double l = Double.parseDouble(lhsc.getInstanceParms()); Double r = Double.parseDouble(rhsc.getInstanceParms()); return l.compareTo(r); } if (isDate) { XMLGregorianCalendar l = fac.newXMLGregorianCalendar(lhsc.getInstanceParms()); XMLGregorianCalendar r = fac.newXMLGregorianCalendar(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } if (isDuration) { Duration l = fac.newDuration(lhsc.getInstanceParms()); Duration r = fac.newDuration(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } return 0; } }
TModelInstanceDetailsComparator { public int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs) throws IllegalArgumentException, NumberFormatException, NullPointerException, ArrayIndexOutOfBoundsException { if (lhs == null) { throw new IllegalArgumentException("lhs"); } if (rhs == null) { throw new IllegalArgumentException("rhs"); } if (lhs.getTModelInstanceInfo().isEmpty() || rhs.getTModelInstanceInfo().isEmpty()) { throw new IllegalArgumentException("no data to compare"); } InstanceDetails lhsc = null; InstanceDetails rhsc = null; for (int i = 0; i < lhs.getTModelInstanceInfo().size(); i++) { if (lhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { lhsc = lhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } for (int i = 0; i < rhs.getTModelInstanceInfo().size(); i++) { if (rhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { rhsc = rhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } if (lhsc == null) { throw new IllegalArgumentException(compareField + " not found for lhs"); } if (rhsc == null) { throw new IllegalArgumentException(compareField + " not found for rhs"); } if (lhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found lhs, but no data"); } if (rhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found rhs, but no data"); } if (isNumber) { Double l = Double.parseDouble(lhsc.getInstanceParms()); Double r = Double.parseDouble(rhsc.getInstanceParms()); return l.compareTo(r); } if (isDate) { XMLGregorianCalendar l = fac.newXMLGregorianCalendar(lhsc.getInstanceParms()); XMLGregorianCalendar r = fac.newXMLGregorianCalendar(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } if (isDuration) { Duration l = fac.newDuration(lhsc.getInstanceParms()); Duration r = fac.newDuration(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } return 0; } TModelInstanceDetailsComparator(String TModelKey, boolean number, boolean XMLdate, boolean XMLduration); }
TModelInstanceDetailsComparator { public int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs) throws IllegalArgumentException, NumberFormatException, NullPointerException, ArrayIndexOutOfBoundsException { if (lhs == null) { throw new IllegalArgumentException("lhs"); } if (rhs == null) { throw new IllegalArgumentException("rhs"); } if (lhs.getTModelInstanceInfo().isEmpty() || rhs.getTModelInstanceInfo().isEmpty()) { throw new IllegalArgumentException("no data to compare"); } InstanceDetails lhsc = null; InstanceDetails rhsc = null; for (int i = 0; i < lhs.getTModelInstanceInfo().size(); i++) { if (lhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { lhsc = lhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } for (int i = 0; i < rhs.getTModelInstanceInfo().size(); i++) { if (rhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { rhsc = rhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } if (lhsc == null) { throw new IllegalArgumentException(compareField + " not found for lhs"); } if (rhsc == null) { throw new IllegalArgumentException(compareField + " not found for rhs"); } if (lhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found lhs, but no data"); } if (rhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found rhs, but no data"); } if (isNumber) { Double l = Double.parseDouble(lhsc.getInstanceParms()); Double r = Double.parseDouble(rhsc.getInstanceParms()); return l.compareTo(r); } if (isDate) { XMLGregorianCalendar l = fac.newXMLGregorianCalendar(lhsc.getInstanceParms()); XMLGregorianCalendar r = fac.newXMLGregorianCalendar(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } if (isDuration) { Duration l = fac.newDuration(lhsc.getInstanceParms()); Duration r = fac.newDuration(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } return 0; } TModelInstanceDetailsComparator(String TModelKey, boolean number, boolean XMLdate, boolean XMLduration); int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs); }
TModelInstanceDetailsComparator { public int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs) throws IllegalArgumentException, NumberFormatException, NullPointerException, ArrayIndexOutOfBoundsException { if (lhs == null) { throw new IllegalArgumentException("lhs"); } if (rhs == null) { throw new IllegalArgumentException("rhs"); } if (lhs.getTModelInstanceInfo().isEmpty() || rhs.getTModelInstanceInfo().isEmpty()) { throw new IllegalArgumentException("no data to compare"); } InstanceDetails lhsc = null; InstanceDetails rhsc = null; for (int i = 0; i < lhs.getTModelInstanceInfo().size(); i++) { if (lhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { lhsc = lhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } for (int i = 0; i < rhs.getTModelInstanceInfo().size(); i++) { if (rhs.getTModelInstanceInfo().get(i).getTModelKey().equalsIgnoreCase(compareField)) { rhsc = rhs.getTModelInstanceInfo().get(i).getInstanceDetails(); } } if (lhsc == null) { throw new IllegalArgumentException(compareField + " not found for lhs"); } if (rhsc == null) { throw new IllegalArgumentException(compareField + " not found for rhs"); } if (lhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found lhs, but no data"); } if (rhsc.getInstanceParms() == null) { throw new IllegalArgumentException(compareField + " found rhs, but no data"); } if (isNumber) { Double l = Double.parseDouble(lhsc.getInstanceParms()); Double r = Double.parseDouble(rhsc.getInstanceParms()); return l.compareTo(r); } if (isDate) { XMLGregorianCalendar l = fac.newXMLGregorianCalendar(lhsc.getInstanceParms()); XMLGregorianCalendar r = fac.newXMLGregorianCalendar(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } if (isDuration) { Duration l = fac.newDuration(lhsc.getInstanceParms()); Duration r = fac.newDuration(rhsc.getInstanceParms()); int x = l.compare(r); if (x == DatatypeConstants.LESSER) { return -1; } if (x == DatatypeConstants.GREATER) { return 1; } if (x == DatatypeConstants.EQUAL) { return 0; } throw new ArrayIndexOutOfBoundsException("cannot compare, result was " + x); } return 0; } TModelInstanceDetailsComparator(String TModelKey, boolean number, boolean XMLdate, boolean XMLduration); int compare(TModelInstanceDetails lhs, TModelInstanceDetails rhs);  }