/** * Compares the given GradoopIds and returns the smaller one. It both are equal, the first * argument is returned. * * @param first first GradoopId * @param second second GradoopId * @return smaller GradoopId or first if equal */ public static GradoopId min(GradoopId first, GradoopId second) { int comparison = first.compareTo(second); return comparison == 0 ? first : (comparison < 0 ? first : second); }
@Override public int compare(EPGMElement a, EPGMElement b) { return a.getId().compareTo(b.getId()); } }
@Override public int compare(EPGMIdentifiable a, EPGMIdentifiable b) { return a.getId().compareTo(b.getId()); } }
@Override public int compare(EPGMElement a, EPGMElement b) { return a.getId().compareTo(b.getId()); } }
@Override public void updateVertex(Vertex<GradoopId, GradoopId> vertex, MessageIterator<GradoopId> messageIterator) throws Exception { GradoopId lastComponent = vertex.getValue(); GradoopId newComponent = lastComponent; for (GradoopId messageComponent : messageIterator) { if (messageComponent.compareTo(newComponent) < 0) { newComponent = messageComponent; } } if (!lastComponent.equals(newComponent)) { setNewVertexValue(newComponent); } } }
@Override public void updateVertex(Vertex<GradoopId, GradoopId> vertex, MessageIterator<GradoopId> messageIterator) throws Exception { GradoopId lastComponent = vertex.getValue(); GradoopId newComponent = lastComponent; for (GradoopId messageComponent : messageIterator) { if (messageComponent.compareTo(newComponent) < 0) { newComponent = messageComponent; } } if (!lastComponent.equals(newComponent)) { setNewVertexValue(newComponent); } } }
/** * Test the {@link GradoopId#min(GradoopId, GradoopId)} method. */ @Test public void testMin() { GradoopId first = GradoopId.get(); GradoopId second = GradoopId.get(); GradoopId min = GradoopId.min(first, second); assertTrue("First ID is smaller then the minimum.", first.compareTo(min) >= 0); assertTrue("Second ID is smaller then the minimum.", second.compareTo(min) >= 0); assertTrue(first == min || second == min); } }
@Override public int compareTo(PropertyValue o) { int result; if (this.isNull() && o.isNull()) { result = 0; } else if (this.isNumber() && o.isNumber()) { result = PropertyValueUtils.Numeric.compare(this, o); } else if (this.isBoolean() && o.isBoolean()) { result = Boolean.compare(this.getBoolean(), o.getBoolean()); } else if (this.isString() && o.isString()) { result = this.getString().compareTo(o.getString()); } else if (this.isGradoopId() && o.isGradoopId()) { result = this.getGradoopId().compareTo(o.getGradoopId()); } else if (this.isDate() && o.isDate()) { result = this.getDate().compareTo(o.getDate()); } else if (this.isTime() && o.isTime()) { result = this.getTime().compareTo(o.getTime()); } else if (this.isDateTime() && o.isDateTime()) { result = this.getDateTime().compareTo(o.getDateTime()); } else if (this.isMap() || o.isMap() || this.isList() || o.isList() || this.isSet() || o.isSet()) { throw new UnsupportedOperationException(String.format( "Method compareTo() is not supported for %s, %s", this.getClass(), o.getClass())); } else { throw new IllegalArgumentException(String.format( "Incompatible types: %s, %s", this.getClass(), o.getClass())); } return result; }