/** * Gets the variables of the {@link Graph} as a {@code Map}. */ public default Map<String, Object> asMap() { final Map<String, Object> map = keys().stream() .map(key -> Pair.with(key, get(key).get())) .collect(Collectors.toMap(Pair::getValue0, Pair::getValue1)); return Collections.unmodifiableMap(map); }
@GET @Timed @Path("{key}") @Produces(APPLICATION_JSON_WITH_CHARSET) public Map<String, Object> get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("key") String key) { LOG.debug("Graph [{}] get variable by key '{}'", graph, key); HugeGraph g = graph(manager, graph); Optional<?> object = g.variables().get(key); if (!object.isPresent()) { throw new NotFoundException(String.format( "Variable '%s' does not exist", key)); } return ImmutableMap.of(key, object.get()); }
final Map map = variables.<Map>get("aKey").get(); assertEquals(((Map) value).size(), map.size()); ((Map) value).keySet().forEach(k -> assertEquals(((Map) value).get(k), map.get(k))); else if (value instanceof List) tryCommit(graph, graph -> { final List l = variables.<List>get("aKey").get(); assertEquals(((List) value).size(), l.size()); for (int ix = 0; ix < ((List) value).size(); ix++) { else if (value instanceof MockSerializable) tryCommit(graph, graph -> { final MockSerializable mock = variables.<MockSerializable>get("aKey").get(); assertEquals(((MockSerializable) value).getTestField(), mock.getTestField()); }); else if (value instanceof boolean[]) tryCommit(graph, graph -> { final boolean[] l = variables.<boolean[]>get("aKey").get(); assertEquals(((boolean[]) value).length, l.length); for (int ix = 0; ix < ((boolean[]) value).length; ix++) { else if (value instanceof double[]) tryCommit(graph, graph -> { final double[] l = variables.<double[]>get("aKey").get(); assertEquals(((double[]) value).length, l.length); for (int ix = 0; ix < ((double[]) value).length; ix++) { else if (value instanceof float[]) tryCommit(graph, graph -> {
final Map map = variables.<Map>get("aKey").get(); assertEquals(((Map) value).size(), map.size()); ((Map) value).keySet().forEach(k -> assertEquals(((Map) value).get(k), map.get(k))); else if (value instanceof List) tryCommit(graph, graph -> { final List l = variables.<List>get("aKey").get(); assertEquals(((List) value).size(), l.size()); for (int ix = 0; ix < ((List) value).size(); ix++) { else if (value instanceof MockSerializable) tryCommit(graph, graph -> { final MockSerializable mock = variables.<MockSerializable>get("aKey").get(); assertEquals(((MockSerializable) value).getTestField(), mock.getTestField()); }); else if (value instanceof boolean[]) tryCommit(graph, graph -> { final boolean[] l = variables.<boolean[]>get("aKey").get(); assertEquals(((boolean[]) value).length, l.length); for (int ix = 0; ix < ((boolean[]) value).length; ix++) { else if (value instanceof double[]) tryCommit(graph, graph -> { final double[] l = variables.<double[]>get("aKey").get(); assertEquals(((double[]) value).length, l.length); for (int ix = 0; ix < ((double[]) value).length; ix++) { else if (value instanceof float[]) tryCommit(graph, graph -> {
private void ensureGraphFormatIsCompatible() { ChronoGraph txGraph = this.graph.tx().createThreadedTx(); String formatVersionString = (String) txGraph.variables().get(ChronoSphereGraphFormat.VARIABLES__GRAPH_FORMAT_VERSION).orElse(null); ChronosVersion currentVersion = ChronosVersion.getCurrentVersion(); if (formatVersionString == null) {
@Test public void canMergeConflictingGraphVariables() { ChronoGraph g = this.getGraph(); { // initial commit g.variables().set("hello", "world"); g.variables().set("foo", "bar"); g.tx().commit(); } ChronoGraph g1 = g.tx().createThreadedTx(); ChronoGraph g2 = g.tx().createThreadedTx(); g1.variables().set("hello", "john"); g1.variables().remove("foo"); g1.variables().set("john", "doe"); g1.tx().commit(); g2.variables().set("hello", "jack"); g2.variables().set("foo", "baz"); g2.variables().set("jane", "doe"); g2.tx().commit(); assertThat(g.variables().get("hello").orElse(null), is("jack")); assertThat(g.variables().get("foo").orElse(null), is("baz")); assertThat(g.variables().get("john").orElse(null), is("doe")); assertThat(g.variables().get("jane").orElse(null), is("doe")); }
/** * Gets the variables of the {@link Graph} as a {@code Map}. */ public default Map<String, Object> asMap() { final Map<String, Object> map = keys().stream() .map(key -> Pair.with(key, get(key).get())) .collect(Collectors.toMap(Pair::getValue0, Pair::getValue1)); return Collections.unmodifiableMap(map); }
@Test public void testDocumentGraphMetadataHasContentFromJCas() throws UIMAException { DocumentGraphOptions options = DocumentGraphOptions.builder().withContent(true).build(); DocumentGraphFactory factory = createfactory(options); JCas jCas = JCasFactory.createJCas(); JCasTestGraphUtil.populateJcas(jCas); Graph graph = factory.create(jCas); Variables variables = graph.variables(); assertEquals(JCasTestGraphUtil.CONTENT, variables.get(FIELD_CONTENT).orElse("")); }
public static void testVariables(final HugeGraph graph) { // variables test Graph.Variables variables = graph.variables(); variables.set("owner", "zhangyi"); variables.set("time", 3); variables.set("owner", "zhangyi1"); variables.keys(); graph.tx().commit(); variables.remove("time"); variables.get("time"); variables.get("owner"); variables.remove("owner"); variables.get("owner"); }