use of uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator in project Gaffer by gchq.
the class MaxTest method builderShouldCreatePopulatedOperation.
@Test
@Override
public void builderShouldCreatePopulatedOperation() {
// Given
final Max max = new Max.Builder().input(new Entity.Builder().group(TestGroups.ENTITY).property("property", 1).build(), new Entity.Builder().group(TestGroups.ENTITY).property("property", 2).build()).comparators(new ElementPropertyComparator() {
@Override
public int compare(final Element e1, final Element e2) {
return 0;
}
}).build();
// Then
assertThat(max.getInput()).hasSize(2);
List properties = Streams.toStream(max.getInput()).map(e -> e.getProperty("property")).collect(toList());
assertThat(properties).containsOnly(1, 2);
}
use of uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator in project Gaffer by gchq.
the class SortTest method shouldShallowCloneOperation.
@Test
@Override
public void shouldShallowCloneOperation() {
// Given
final Entity input = new Entity.Builder().group(TestGroups.ENTITY).property("property", 1).build();
final ElementPropertyComparator comparator = new ElementPropertyComparator();
final Boolean deDuplicate = false;
final int resultLimit = 5;
final Sort sort = new Sort.Builder().input(input).comparators(comparator).resultLimit(resultLimit).deduplicate(deDuplicate).build();
// When
Sort clone = sort.shallowClone();
// Then
assertNotSame(sort, clone);
assertThat(clone.getInput().iterator().next()).isEqualTo(input);
assertThat(clone.getComparators().iterator().next()).isEqualTo(comparator);
assertEquals(deDuplicate, clone.isDeduplicate());
assertTrue(clone.getResultLimit().equals(resultLimit));
}
use of uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator in project Gaffer by gchq.
the class MinHandler method getMin.
private Element getMin(final Iterable<? extends Element> elements, final Min operation) {
Element minElement = null;
final List<Comparator<Element>> comparators = operation.getComparators();
if (1 == comparators.size() && comparators.get(0) instanceof ElementPropertyComparator) {
final ElementPropertyComparator propertyComparator = (ElementPropertyComparator) comparators.get(0);
Object minProperty = null;
for (final Element element : elements) {
if (null == element || !propertyComparator.getGroups().contains(element.getGroup())) {
continue;
}
final Object property = element.getProperty(propertyComparator.getProperty());
if (null == property) {
continue;
}
if (null == minElement || propertyComparator._compare(property, minProperty) < 0) {
minElement = element;
minProperty = property;
}
}
} else {
final Comparator<Element> combinedComparator = operation.getCombinedComparator();
if (null != combinedComparator) {
for (final Element element : elements) {
if (null == element) {
continue;
}
if (null == minElement) {
minElement = element;
}
if (combinedComparator.compare(element, minElement) < 0) {
minElement = element;
}
}
}
}
return minElement;
}
Aggregations