@Override public void addGraphId(GradoopId graphId) { if (graphIds == null) { graphIds = new GradoopIdSet(); } graphIds.add(graphId); }
@Test public void testAddAllGradoopIds() throws Exception { GradoopId id1 = GradoopId.get(); GradoopId id2 = GradoopId.get(); GradoopIdSet list1 = new GradoopIdSet(); list1.add(id1); list1.add(id2); GradoopIdSet list2 = new GradoopIdSet(); list2.addAll(list1); assertThat(list2.size(), is(2)); assertTrue(list2.contains(id1)); assertTrue(list2.contains(id2)); list2.addAll(list1); assertThat(list2.size(), is(2)); }
@Override public void reduce(Iterable<Tuple2<T, GradoopId>> iterable, Collector<Tuple2<T, GradoopIdSet>> collector) throws Exception { Iterator<Tuple2<T, GradoopId>> it = iterable.iterator(); Tuple2<T, GradoopId> firstTuple = it.next(); T firstField = firstTuple.f0; GradoopIdSet secondField = GradoopIdSet.fromExisting(firstTuple.f1); while (it.hasNext()) { GradoopId id = it.next().f1; secondField.add(id); } collector.collect(new Tuple2<>(firstField, secondField)); } }
@Override public void reduce(Iterable<Tuple2<T, GradoopId>> iterable, Collector<Tuple2<T, GradoopIdSet>> collector) throws Exception { Iterator<Tuple2<T, GradoopId>> it = iterable.iterator(); Tuple2<T, GradoopId> firstTuple = it.next(); T firstField = firstTuple.f0; GradoopIdSet secondField = GradoopIdSet.fromExisting(firstTuple.f1); while (it.hasNext()) { GradoopId id = it.next().f1; secondField.add(id); } collector.collect(new Tuple2<>(firstField, secondField)); } }
/** * Creates a {@code GradoopIDSet} from the long identifiers stored at the * given graph element. * * @param e graph element * @return GradoopIDSet for the given element */ private GradoopIdSet createGradoopIdSet(GraphElement e) { GradoopIdSet result = new GradoopIdSet(); for (Long graphId : e.getGraphs()) { result.add(graphHeadIds.get(graphId)); } return result; } }
@Override public GraphCollection getGraphs(final GradoopId... identifiers) { GradoopIdSet graphIds = new GradoopIdSet(); for (GradoopId id : identifiers) { graphIds.add(id); } return getGraphs(graphIds); }
@Override public void reduce(Iterable<GradoopId> iterable, Collector<GradoopIdSet> collector) throws Exception { GradoopIdSet ids = new GradoopIdSet(); for (GradoopId id : iterable) { ids.add(id); } collector.collect(ids); } }
@Override public void reduce(Iterable<GradoopId> iterable, Collector<GradoopIdSet> collector) throws Exception { GradoopIdSet ids = new GradoopIdSet(); for (GradoopId id : iterable) { ids.add(id); } collector.collect(ids); } }
/** * {@inheritDoc} */ @Override public GraphCollection getGraphs(final GradoopId... identifiers) { GradoopIdSet graphIds = new GradoopIdSet(); for (GradoopId id : identifiers) { graphIds.add(id); } return getGraphs(graphIds); }
@Override public void reduce(Iterable<Tuple2<GradoopId, GradoopId>> mappings, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { boolean first = true; GradoopId vertexId = null; GradoopIdSet btgIds = new GradoopIdSet(); for (Tuple2<GradoopId, GradoopId> pair : mappings) { if (first) { vertexId = pair.f0; first = false; } btgIds.add(pair.f1); } collector.collect(new Tuple2<>(vertexId, btgIds)); }
@Override public void reduce(Iterable<Tuple2<GradoopId, GradoopId>> mappings, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { boolean first = true; GradoopId vertexId = null; GradoopIdSet btgIds = new GradoopIdSet(); for (Tuple2<GradoopId, GradoopId> pair : mappings) { if (first) { vertexId = pair.f0; first = false; } btgIds.add(pair.f1); } collector.collect(new Tuple2<>(vertexId, btgIds)); }
@Override public void reduce(Iterable<Tuple2<GradoopId, GradoopId>> iterable, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { GradoopIdSet set = new GradoopIdSet(); boolean empty = true; GradoopId first = null; for (Tuple2<GradoopId, GradoopId> tuple : iterable) { set.add(tuple.f1); empty = false; first = tuple.f0; } if (!empty) { collector.collect(new Tuple2<>(first, set)); } } }
@Override public void reduce(Iterable<Tuple2<GradoopId, GradoopId>> iterable, Collector<Tuple2<GradoopId, GradoopIdSet>> collector) throws Exception { GradoopIdSet set = new GradoopIdSet(); boolean empty = true; GradoopId first = null; for (Tuple2<GradoopId, GradoopId> tuple : iterable) { set.add(tuple.f1); empty = false; first = tuple.f0; } if (!empty) { collector.collect(new Tuple2<>(first, set)); } } }
/** * Returns all edges that belong to the given graph variables. * * @param variables graph variables used in the GDL script * @return edges */ public Collection<E> getEdgesByGraphVariables(String... variables) { GradoopIdSet graphIds = new GradoopIdSet(); for (G graphHead : getGraphHeadsByVariables(variables)) { graphIds.add(graphHead.getId()); } return getEdgesByGraphIds(graphIds); }
/** * Returns all vertices that belong to the given graph variables. * * @param graphVariables graph variables used in the GDL script * @return vertices that are contained in the graphs */ public Collection<V> getVerticesByGraphVariables(String... graphVariables) { GradoopIdSet graphIds = new GradoopIdSet(); for (G graphHead : getGraphHeadsByVariables(graphVariables)) { graphIds.add(graphHead.getId()); } return getVerticesByGraphIds(graphIds); }
/** * Reads a set of Long values from a given json array. * * @param array json array * @return long values * @throws JSONException */ protected GradoopIdSet getArrayValues(JSONArray array) throws JSONException { GradoopIdSet result = new GradoopIdSet(); for (int i = 0; i < array.length(); i++) { result.add(GradoopId.fromString(array.getString(i))); } return result; } }
@Test public void testSize() throws Exception { GradoopId id1 = GradoopId.get(); GradoopId id2 = GradoopId.get(); GradoopIdSet ids = new GradoopIdSet(); assertThat(ids.size(), is(0)); ids.add(id1); assertThat(ids.size(), is(1)); ids.add(id1); assertThat(ids.size(), is(1)); ids.add(id2); assertThat(ids.size(), is(2)); }
@Test public void testResetGraphIds() { Properties propertiesMock = mock(Properties.class); GradoopIdSet idSet = new GradoopIdSet(); idSet.add(GradoopId.get()); GraphElement graphElementMock = mock(GraphElement.class, withSettings() .useConstructor(GradoopId.get(), "someLabel", propertiesMock, idSet) .defaultAnswer(CALLS_REAL_METHODS)); graphElementMock.resetGraphIds(); assertTrue(graphElementMock.getGraphIds().isEmpty()); } }
@Test public void testContains() throws Exception { GradoopId id1 = GradoopId.get(); GradoopId id2 = GradoopId.get(); GradoopIdSet ids = new GradoopIdSet(); ids.add(id1); assertThat(ids.size(), is(1)); assertTrue(ids.contains(id1)); assertFalse(ids.contains(id2)); }