Java Code Examples for org.javatuples.Pair#setAt0()

The following examples show how to use org.javatuples.Pair#setAt0() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CypherQueryGraphHelper.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * createActorObjectEdge.
 * @param activity activity
 * @return pair (query, parameterMap)
 */
public Pair<String, Map<String, Object>> createActorObjectEdge(Activity activity) {

  Pair queryPlusParameters = new Pair(null, new HashMap<>());

  ObjectNode object = MAPPER.convertValue(activity, ObjectNode.class);
  object = PropertyUtil.getInstance(MAPPER).cleanProperties(object);
  Map<String, Object> props = PropertyUtil.getInstance(MAPPER).flattenToMap(object);

  ST mergeEdge = new ST(createEdgeStatementTemplate);
  mergeEdge.add("s_id", activity.getActor().getId());
  mergeEdge.add("s_type", activity.getActor().getObjectType());
  mergeEdge.add("d_id", activity.getObject().getId());
  mergeEdge.add("d_type", activity.getObject().getObjectType());
  mergeEdge.add("r_id", activity.getId());
  mergeEdge.add("r_type", activity.getVerb());
  mergeEdge.add("r_props", getActorObjectEdgePropertyCreater(props));

  String statement = mergeEdge.render();
  queryPlusParameters = queryPlusParameters.setAt0(statement);
  queryPlusParameters = queryPlusParameters.setAt1(props);

  LOGGER.debug("createActorObjectEdge: ({},{})", statement, props);

  return queryPlusParameters;
}
 
Example 2
Source File: CypherQueryGraphHelper.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * createActorTargetEdge.
 * @param activity activity
 * @return pair (query, parameterMap)
 */
public Pair<String, Map<String, Object>> createActorTargetEdge(Activity activity) {

  Pair queryPlusParameters = new Pair(null, new HashMap<>());

  ObjectNode object = MAPPER.convertValue(activity, ObjectNode.class);
  object = PropertyUtil.getInstance(MAPPER).cleanProperties(object);
  Map<String, Object> props = PropertyUtil.getInstance(MAPPER).flattenToMap(object);

  ST mergeEdge = new ST(createEdgeStatementTemplate);
  mergeEdge.add("s_id", activity.getActor().getId());
  mergeEdge.add("s_type", activity.getActor().getObjectType());
  mergeEdge.add("d_id", activity.getTarget().getId());
  mergeEdge.add("d_type", activity.getTarget().getObjectType());
  mergeEdge.add("r_id", activity.getId());
  mergeEdge.add("r_type", activity.getVerb());
  mergeEdge.add("r_props", getActorTargetEdgePropertyCreater(props));

  String statement = mergeEdge.render();
  queryPlusParameters = queryPlusParameters.setAt0(statement);
  queryPlusParameters = queryPlusParameters.setAt1(props);

  LOGGER.debug("createActorObjectEdge: ({},{})", statement, props);

  return queryPlusParameters;
}
 
Example 3
Source File: CypherQueryGraphHelper.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * mergeVertexRequest.
 * @param activityObject activityObject
 * @return pair (query, parameterMap)
 */
public Pair<String, Map<String, Object>> mergeVertexRequest(ActivityObject activityObject) {

  Objects.requireNonNull(activityObject.getObjectType());

  Pair queryPlusParameters = new Pair(null, new HashMap<>());

  List<String> labels = getLabels(activityObject);

  ST mergeVertex = new ST(mergeVertexStatementTemplate);
  mergeVertex.add("id", activityObject.getId());
  mergeVertex.add("type", activityObject.getObjectType());
  if ( labels.size() > 0 ) {
    mergeVertex.add("labels", String.join(" ", labels));
  }
  String query = mergeVertex.render();

  ObjectNode object = MAPPER.convertValue(activityObject, ObjectNode.class);
  object = PropertyUtil.getInstance(MAPPER).cleanProperties(object);
  Map<String, Object> props = PropertyUtil.getInstance(MAPPER).flattenToMap(object);

  LOGGER.debug("mergeVertexRequest: ({},{})", query, props);

  queryPlusParameters = queryPlusParameters.setAt0(query);
  queryPlusParameters = queryPlusParameters.setAt1(props);

  return queryPlusParameters;
}
 
Example 4
Source File: JavaTuplesUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenSetValueInTuple_thenGetANewTuple() {
    Pair<String, Integer> john = Pair.with("john", 32);
    Pair<String, Integer> alex = john.setAt0("alex");
    assertThat(john.toString()).isNotEqualTo(alex.toString());
}