コード例 #1
0
ファイル: SetGenerators.java プロジェクト: hinike/opera
 protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) {
   List<Integer> elements = newArrayList(elementsSet);
   /*
    * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it
    * doesn't need one, or it should be suppressed for ContiguousSet.
    */
   for (int i = 0; i < elements.size() - 1; i++) {
     assertEquals(elements.get(i) + 1, (int) elements.get(i + 1));
   }
   Range<Integer> range =
       (elements.isEmpty()) ? Ranges.closedOpen(0, 0) : Ranges.encloseAll(elements);
   return range.asSet(DiscreteDomains.integers());
 }
コード例 #2
0
ファイル: SetGenerators.java プロジェクト: hinike/opera
 @Override
 protected SortedSet<Integer> create(Integer[] elements) {
   SortedSet<Integer> set = nullCheckedTreeSet(elements);
   if (set.isEmpty()) {
     /*
      * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
      * greater than tooHigh.
      */
     return Ranges.openClosed(0, 1).asSet(DiscreteDomains.integers()).subSet(0, 1);
   }
   int tooHigh = set.last() + 1;
   int tooLow = set.first() - 1;
   set.add(tooHigh);
   set.add(tooLow);
   return checkedCreate(set).subSet(tooLow + 1, tooHigh);
 }
コード例 #3
0
 private List<ScheduledCommand> createMoveCommands(final double length) {
   if (Math.abs(length) < 1) {
     return ImmutableList.<ScheduledCommand>of();
   }
   final double currentAngle = workspace.getCurrentAngle();
   final ScheduledCommand command =
       new ScheduledCommand() {
         @Override
         public void execute() {
           workspace.updatePosition(length > 0 ? 1.0 : -1.0, currentAngle);
         }
       };
   final Function<Integer, ScheduledCommand> function =
       new Function<Integer, ScheduledCommand>() {
         @Override
         public ScheduledCommand apply(Integer input) {
           return command;
         }
       };
   final List<Integer> range =
       Ranges.closed(1, (int) length).asSet(DiscreteDomains.integers()).asList();
   return transform(range, function);
 }
コード例 #4
0
 private void printAllElements(Range<Integer> range) {
   for (int i : range.asSet(DiscreteDomains.integers())) System.out.print(i + " ");
   System.out.println();
 }