Пример #1
0
  private void splitJourneyLocation(
      ConcurrentMap<String, IRI> variableTypes,
      List<LDObject> journeyLocation,
      List<LDObject> journeyDatas,
      BindingSet bindings) {
    LDObject locationsData = new LDObject();
    LDObject journeyData = new LDObject();

    bindings
        .getBindingNames()
        .stream()
        .forEach(
            bindingName -> {
              org.openrdf.model.Value value = bindings.getBinding(bindingName).getValue();
              QueryResultsParser.updateVariableTypes(variableTypes, bindingName, value);

              if (Arrays.asList("id", "creationDate", "name", "status").contains(bindingName)) {
                journeyData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              } else {
                locationsData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              }

              if ("locationId".equalsIgnoreCase(bindingName)) {
                journeyData.addKeyValue(new KeyValue(bindingName, value.stringValue()));
              }
            });

    journeyLocation.add(locationsData);
    journeyDatas.add(journeyData);
  }
  @Override
  protected BindingSet getNextElement() throws QueryEvaluationException {
    if (hashTable == null) {
      setupHashTable();
    }

    while (currentScanElem == null) {
      if (scanList.size() > 0) {
        currentScanElem = scanList.remove(0);
      } else {
        if (restIter.hasNext()) {
          currentScanElem = restIter.next();
        } else {
          // no more elements available
          return null;
        }
      }

      if (currentScanElem instanceof EmptyBindingSet) {
        // the empty bindingset should be merged with all bindingset in
        // the hash table
        hashTableValues = new ArrayList<BindingSet>();
        for (BindingSet key : hashTable.keySet()) {
          hashTableValues.addAll(hashTable.get(key));
        }
      } else {
        BindingSet key = calcKey(currentScanElem, joinAttributes);

        if (hashTable.containsKey(key)) {
          hashTableValues = new ArrayList<BindingSet>(hashTable.get(key));
        } else {
          currentScanElem = null;
          hashTableValues = null;
        }
      }
    }

    BindingSet nextHashTableValue = hashTableValues.remove(0);

    QueryBindingSet result = new QueryBindingSet(currentScanElem);

    for (String name : nextHashTableValue.getBindingNames()) {
      Binding b = nextHashTableValue.getBinding(name);
      if (!result.hasBinding(name)) {
        result.addBinding(b);
      }
    }

    if (hashTableValues.size() == 0) {
      // we've exhausted the current scanlist entry
      currentScanElem = null;
      hashTableValues = null;
    }

    return result;
  }
 private BindingSet calcKey(BindingSet bindings, Set<String> commonVars) {
   QueryBindingSet q = new QueryBindingSet();
   for (String varName : commonVars) {
     Binding b = bindings.getBinding(varName);
     if (b != null) {
       q.addBinding(b);
     }
   }
   return q;
 }