Ejemplo n.º 1
0
  /**
   * call {@link Esi4JEntityResolver#replaceEntity(Object)} for each task. At the same time, we
   * create a map of {@link ObjectKey}s.
   */
  private ListMap<ObjectKey, Integer> replaceEntities(final Esi4JEntityTask[] tasks) {
    final ListMap<ObjectKey, Integer> map = new ObjectKeyListMap(tasks.length);

    for (int i = 0; i < tasks.length; i++) {
      final Esi4JEntityTask task = tasks[i];
      if (task != null) {
        task.replaceEntity(_entityResolver);
        map.add(task.toObjectKey(_entityResolver), i);
      }
    }
    return map;
  }
Ejemplo n.º 2
0
  /**
   * reduce number of operations by replacing duplicates. If a task isn't an update, we ignore
   * everything before it.
   */
  static void resolveDuplicates(
      final Esi4JEntityTask[] tasks, final ListMap<ObjectKey, Integer> map) {
    for (final Map.Entry<ObjectKey, List<Integer>> e : map.entrySet()) {

      final List<Integer> taskIndices = e.getValue();
      if (taskIndices.size() > 1) {
        // resolving duplicates

        final ListIterator<Integer> iter = taskIndices.listIterator(taskIndices.size());
        boolean overwritePrevious = false;
        while (iter.hasPrevious()) {
          final int taskIndex = iter.previous();

          if (overwritePrevious) {
            tasks[taskIndex] = null;
            iter.remove();
          } else if (!tasks[taskIndex].isUpdate()) {
            overwritePrevious = true;
          }
        }
      }
    }
  }