Example #1
0
 @Override
 /**
  * Applies <code>doValueMap</code> to each object in <code>objects</code>. Keeps track of the
  * object with the largest value, and returns it at the end of the stream.s
  */
 protected Iterable<T> doMap(Iterable<T> objects) {
   T max = null;
   S maxVal = null;
   for (T object : objects) {
     S val = doValueMap(object);
     if (maxVal == null || val.compareTo(maxVal) == 1) {
       max = object;
       maxVal = val;
     }
   }
   ArrayList<T> result = new ArrayList<T>(1);
   if (max != null) {
     result.add(max);
   }
   return result;
 }
Example #2
0
  public void add(S value) {
    Node<S> novy = new Node<S>(value);
    if (first == null) first = novy;
    else {
      Node<S> act, pred;

      for (act = pred = first; act != null; pred = act, act = act.getNext()) {
        int res = value.compareTo(act.getValue());
        if (res > 0) continue;
        if (res == 0) return;
        if (res < 0) {
          if (act.equals(first)) {
            first = novy;
            novy.setNext(act);
            return;
          }
          pred.setNext(novy);
          novy.setNext(act);
          return;
        }
      }
      pred.setNext(novy);
    }
  }