Search in sources :

Example 1 with VertexiumObject

use of org.vertexium.VertexiumObject in project vertexium by visallo.

the class DefaultGraphQueryIterableWithAggregations method getElementsByProperty.

private <TKey> Map<TKey, List<T>> getElementsByProperty(Iterator<T> it, String propertyName, ValueConverter<TKey> valueConverter) {
    Map<TKey, List<T>> elementsByProperty = new HashMap<>();
    while (it.hasNext()) {
        T vertexiumObject = it.next();
        Iterable<Object> values = vertexiumObject.getPropertyValues(propertyName);
        for (Object value : values) {
            TKey convertedValue = valueConverter.convert(value);
            elementsByProperty.computeIfAbsent(convertedValue, k -> new ArrayList<>()).add(vertexiumObject);
        }
    }
    return elementsByProperty;
}
Also used : java.util(java.util) VertexiumException(org.vertexium.VertexiumException) Collectors(java.util.stream.Collectors) VertexiumObject(org.vertexium.VertexiumObject) VertexiumObject(org.vertexium.VertexiumObject)

Example 2 with VertexiumObject

use of org.vertexium.VertexiumObject in project vertexium by visallo.

the class SortContainersComparator method compare.

private int compare(QueryBase.SortContainer sortContainer, T vertexiumObject1, T vertexiumObject2) {
    if (vertexiumObject1 instanceof VertexiumObject && vertexiumObject2 instanceof VertexiumObject) {
        VertexiumObject elem1 = (VertexiumObject) vertexiumObject1;
        VertexiumObject elem2 = (VertexiumObject) vertexiumObject2;
        List<Object> elem1PropertyValues = toList(elem1.getPropertyValues(sortContainer.propertyName));
        List<Object> elem2PropertyValues = toList(elem2.getPropertyValues(sortContainer.propertyName));
        if (elem1PropertyValues.size() > 0 && elem2PropertyValues.size() == 0) {
            return -1;
        } else if (elem2PropertyValues.size() > 0 && elem1PropertyValues.size() == 0) {
            return 1;
        } else {
            for (Object elem1PropertyValue : elem1PropertyValues) {
                for (Object elem2PropertyValue : elem2PropertyValues) {
                    int result = comparePropertyValues(elem1PropertyValue, elem2PropertyValue);
                    if (result != 0) {
                        return sortContainer.direction == SortDirection.ASCENDING ? result : -result;
                    }
                }
            }
        }
        return 0;
    } else {
        throw new VertexiumException("unexpected searchable item combination: " + vertexiumObject1.getClass().getName() + ", " + vertexiumObject2.getClass().getName());
    }
}
Also used : VertexiumObject(org.vertexium.VertexiumObject) VertexiumObject(org.vertexium.VertexiumObject) VertexiumException(org.vertexium.VertexiumException)

Aggregations

VertexiumException (org.vertexium.VertexiumException)2 VertexiumObject (org.vertexium.VertexiumObject)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1