/** * Call compareTo on the attribute values. If the attribute is not present * in the {@link ConnectorObject} return -1. */ public int compare(ConnectorObject obj) { int ret = -1; Attribute attr = obj.getAttributeByName(getName()); if (attr != null && attr.getValue().size() == 1) { // it must be a comparable because that's were testing against if (!(attr.getValue().get(0) instanceof Comparable)) { throw new IllegalArgumentException("Attribute value must be comparable!"); } // grab this value and the on from the attribute an compare.. Object o1 = attr.getValue().get(0); Object o2 = getValue(); ret = CollectionUtil.forceCompare(o1, o2); } return ret; } }
/** * Call compareTo on the attribute values. If the attribute is not present * in the {@link ConnectorObject} return -1. */ public int compare(ConnectorObject obj) { int ret = -1; Attribute attr = obj.getAttributeByName(getName()); if (attr != null && attr.getValue().size() == 1) { // it must be a comparable because that's were testing against if (!(attr.getValue().get(0) instanceof Comparable)) { final String ERR = "Attribute value must be comparable!"; throw new IllegalArgumentException(ERR); } // grab this value and the on from the attribute an compare.. Object o1 = attr.getValue().get(0); Object o2 = getValue(); ret = CollectionUtil.forceCompare(o1, o2); } return ret; } }
/** * Call compareTo on the attribute values. If the attribute is not present * in the {@link ConnectorObject} return -1. */ public int compare(ConnectorObject obj) { int ret = -1; Attribute attr = obj.getAttributeByName(getName()); if (attr != null && attr.getValue().size() == 1) { // it must be a comparable because that's were testing against if (!(attr.getValue().get(0) instanceof Comparable)) { throw new IllegalArgumentException("Attribute value must be comparable!"); } // grab this value and the on from the attribute an compare.. Object o1 = attr.getValue().get(0); Object o2 = getValue(); ret = CollectionUtil.forceCompare(o1, o2); } return ret; } }
@Test public void testForceCompare() { Integer i1 = 1, i2 = 2; int cmp = CollectionUtil.forceCompare(i1, i2); assertEquals(cmp, -1); }