Exemple #1
0
  /**
   * Removes the given value from the Sequence set, splitting a contained sequence if necessary.
   *
   * @param value The value that should be removed from the SequenceSet.
   * @return true if the value was removed from the set, false if there was no sequence in the set
   *     that contained the given value.
   */
  public boolean remove(long value) {
    Sequence sequence = getHead();
    while (sequence != null) {
      if (sequence.contains(value)) {
        if (sequence.range() == 1) {
          sequence.unlink();
          return true;
        } else if (sequence.getFirst() == value) {
          sequence.setFirst(value + 1);
          return true;
        } else if (sequence.getLast() == value) {
          sequence.setLast(value - 1);
          return true;
        } else {
          sequence.linkBefore(new Sequence(sequence.first, value - 1));
          sequence.linkAfter(new Sequence(value + 1, sequence.last));
          sequence.unlink();
          return true;
        }
      }

      sequence = sequence.getNext();
    }

    return false;
  }
Exemple #2
0
 @TypeParameters(@TypeParameter(value = "Value", satisfies = "ceylon.language.Summable<Value>"))
 @TypeInfo("Value")
 public static <Value extends Summable<Value>> Value sum(
     @Name("values") @TypeInfo("ceylon.language.Sequence<Value>")
         final Sequence<? extends Value> values) {
   Value sum = values.getFirst();
   java.lang.Object $tmp;
   for (Iterator<? extends Value> $val$iter$0 = values.getRest().getIterator();
       !(($tmp = $val$iter$0.next()) instanceof Finished); ) {
     sum = sum.plus((Value) $tmp);
   }
   return sum;
 }