Esempio n. 1
0
  /**
   * Perform an intersection of the 2 results
   *
   * @param results
   */
  public void and(Results results) {
    getEntitiesMap();
    results.getEntitiesMap();

    if ((entitiesMap != null) && (results.entitiesMap != null)) {
      Map<UUID, Entity> newMap = new LinkedHashMap<UUID, Entity>();
      for (Map.Entry<UUID, Entity> e : entitiesMap.entrySet()) {
        if (results.entitiesMap.containsKey(e.getKey())) {
          newMap.put(e.getKey(), e.getValue());
        }
      }
      entitiesMap = newMap;
      entities = new ArrayList<Entity>(entitiesMap.values());
      level = Level.ALL_PROPERTIES;
      return;
    }

    getRefsMap();
    results.getRefsMap();
    if ((refsMap != null) && (results.refsMap != null)) {
      Map<UUID, EntityRef> newMap = new LinkedHashMap<UUID, EntityRef>();
      for (Map.Entry<UUID, EntityRef> e : refsMap.entrySet()) {
        if (results.refsMap.containsKey(e.getKey())) {
          newMap.put(e.getKey(), e.getValue());
        }
      }
      refsMap = newMap;
      refs = new ArrayList<EntityRef>(refsMap.values());
      level = Level.REFS;
      ids = null;
      return;
    }

    getIdSet();
    results.getIdSet();
    if ((idSet != null) && (results.idSet != null)) {
      Set<UUID> newSet = new LinkedHashSet<UUID>();
      for (UUID uuid : idSet) {
        if (results.idSet.contains(uuid)) {
          newSet.add(uuid);
        }
      }
      idSet = newSet;
      ids = new ArrayList<UUID>(idSet);
      level = Level.IDS;
      return;
    }

    // should be empty
    init();
  }
Esempio n. 2
0
  public void merge(Results results) {
    getEntitiesMap();
    results.getEntitiesMap();
    if (entitiesMap != null || results.entitiesMap != null) {

      level = Level.ALL_PROPERTIES;

      // do nothing, nothing to union
      if (entitiesMap != null && results.entitiesMap == null) {
        return;
        // other side has the results, assign and return
      } else if (entitiesMap == null && results.entitiesMap != null) {
        entities = results.entities;
        return;
      }

      entitiesMap.putAll(results.entitiesMap);
      entities = new ArrayList<Entity>(entitiesMap.values());

      return;
    }

    getRefsMap();
    results.getRefsMap();
    if ((refsMap != null) || (results.refsMap != null)) {

      level = Level.REFS;

      // do nothing, nothing to union
      if (refsMap != null && results.refsMap == null) {
        return;
        // other side has the results, assign and return
      } else if (refsMap == null && results.refsMap != null) {
        refs = results.refs;
        return;
      }

      refsMap.putAll(results.refsMap);
      refs = new ArrayList<EntityRef>(refsMap.values());

      return;
    }

    getIdSet();
    results.getIdSet();
    if ((idSet != null) && (results.idSet != null)) {

      level = Level.IDS;

      // do nothing, nothing to union
      if (idSet != null && results.idSet == null) {
        return;
        // other side has the results, assign and return
      } else if (idSet == null && results.idSet != null) {
        ids = results.ids;
        return;
      }

      idSet.addAll(results.idSet);
      ids = new ArrayList<UUID>(idSet);

      return;
    }
  }