Ejemplo n.º 1
0
  @Test
  public <T> void testRemoveDuplicates() {

    ArrayList<String> testArrayList = new ArrayList<String>();
    MiscUtil.removeDuplicates(testArrayList);
    assertTrue(testArrayList.equals(new ArrayList<String>()));

    testArrayList = new ArrayList<String>(Arrays.asList("b", "a"));
    MiscUtil.removeDuplicates(testArrayList);
    assertTrue(testArrayList.equals(new ArrayList<String>(Arrays.asList("b", "a"))));

    testArrayList = new ArrayList<String>(Arrays.asList("b", "a", "b"));
    MiscUtil.removeDuplicates(testArrayList);
    assertTrue(testArrayList.equals(new ArrayList<String>(Arrays.asList("b", "a"))));

    testArrayList = new ArrayList<String>(Arrays.asList("b", "a", "b", "b"));
    MiscUtil.removeDuplicates(testArrayList);
    assertTrue(testArrayList.equals(new ArrayList<String>(Arrays.asList("b", "a"))));

    testArrayList = new ArrayList<String>(Arrays.asList("a", "b", "b", "b", "b"));
    MiscUtil.removeDuplicates(testArrayList);
    assertTrue(testArrayList.equals(new ArrayList<String>(Arrays.asList("a", "b"))));

    LinkedList<String> testLinkedList = new LinkedList<String>(Arrays.asList("b", "a", "b"));
    MiscUtil.removeDuplicates(testLinkedList);
    assertTrue(testLinkedList.equals(new LinkedList<String>(Arrays.asList("b", "a"))));

    testLinkedList = new LinkedList<String>(Arrays.asList("b", "a", "b", "b"));
    MiscUtil.removeDuplicates(testLinkedList);
    assertTrue(testLinkedList.equals(new LinkedList<String>(Arrays.asList("b", "a"))));

    testLinkedList = new LinkedList<String>(Arrays.asList("a", "b", "b", "b", "b"));
    MiscUtil.removeDuplicates(testLinkedList);
    assertTrue(testLinkedList.equals(new LinkedList<String>(Arrays.asList("a", "b"))));
  }
Ejemplo n.º 2
0
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Path path1 = (Path) o;

    if (!path.equals(path1.path)) return false;

    return true;
  }
Ejemplo n.º 3
0
 @Test
 public void testLinkedListSerialization() {
   SerializationService ss = new DefaultSerializationServiceBuilder().build();
   LinkedList<Person> linkedList = new LinkedList<Person>();
   linkedList.add(new Person(35, 180, 100, "Orhan", null));
   linkedList.add(new Person(12, 120, 60, "Osman", null));
   Data data = ss.toData(linkedList);
   LinkedList deserialized = ss.toObject(data);
   assertTrue("Objects are not identical!", linkedList.equals(deserialized));
 }
Ejemplo n.º 4
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   TypeSet other = (TypeSet) obj;
   if (link != other.link) return false;
   if (typeDefinitions == null) {
     if (other.typeDefinitions != null) return false;
   } else if (!typeDefinitions.equals(other.typeDefinitions)) return false;
   return true;
 }
  /**
   * Test the ODBC driver
   *
   * @return String
   */
  public String test() {

    String shellPath = AcideProjectConfiguration.getInstance().getShellPath();

    // LinkedList<String> lines = null;
    LinkedList<String> lines = executeCommand("/tapi /test_tapi");
    /*
     * if (shellPath != null && (shellPath.endsWith("\\des.exe") ||
     * shellPath .endsWith("/des"))) { lines =
     * executeCommand("/tapi /test_tapi"); }
     */

    if (lines.equals("$success") || lines == null || lines.size() == 0) return "$success";

    return "$error";
  }
  /**
   * An equals method for ObjectWatcher that compares the HashMap and LinkedList. This will need to
   * be updated if more functionality is added.
   *
   * @param obj : the object for comparison
   * @return : a boolean value true or false
   */
  public boolean equals(Object obj) {
    if (this == obj) {
      return true; // The same object
    }
    if (!(obj instanceof ObjectWatcher)) {
      return false; // Not of the same type
    }

    ObjectWatcher other = (ObjectWatcher) obj;

    if (!(itemMap.equals(other.getItemMap()))) {
      // If the HashMaps aren't equal, return false
      return false;
    } else if (!(playerList.equals(other.getPlayerList()))) {
      // If the lists aren't equal, return false
      return false;
    } else {
      // If the hash maps and lists are equal, return true
      return true;
    }
  }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   PojoFoo other = (PojoFoo) obj;
   if (arrayBlockingQueue == null) {
     if (other.arrayBlockingQueue != null) return false;
   } else if (!arrayBlockingQueue.equals(other.arrayBlockingQueue)) return false;
   if (arrayDeque == null) {
     if (other.arrayDeque != null) return false;
   } else if (!arrayDeque.equals(other.arrayDeque)) return false;
   if (arrayList == null) {
     if (other.arrayList != null) return false;
   } else if (!arrayList.equals(other.arrayList)) return false;
   if (bar == null) {
     if (other.bar != null) return false;
   } else if (!bar.equals(other.bar)) return false;
   if (blockingDeque == null) {
     if (other.blockingDeque != null) return false;
   } else if (!blockingDeque.equals(other.blockingDeque)) return false;
   if (blockingQueue == null) {
     if (other.blockingQueue != null) return false;
   } else if (!blockingQueue.equals(other.blockingQueue)) return false;
   if (collection == null) {
     if (other.collection != null) return false;
   } else if (!collection.equals(other.collection)) return false;
   if (concurrentLinkedQueue == null) {
     if (other.concurrentLinkedQueue != null) return false;
   } else if (!concurrentLinkedQueue.equals(other.concurrentLinkedQueue)) return false;
   if (concurrentSkipListSet == null) {
     if (other.concurrentSkipListSet != null) return false;
   } else if (!concurrentSkipListSet.equals(other.concurrentSkipListSet)) return false;
   if (copyOnWriteArrayList == null) {
     if (other.copyOnWriteArrayList != null) return false;
   } else if (!copyOnWriteArrayList.equals(other.copyOnWriteArrayList)) return false;
   if (copyOnWriteArraySet == null) {
     if (other.copyOnWriteArraySet != null) return false;
   } else if (!copyOnWriteArraySet.equals(other.copyOnWriteArraySet)) return false;
   if (deque == null) {
     if (other.deque != null) return false;
   } else if (!deque.equals(other.deque)) return false;
   if (hashSet == null) {
     if (other.hashSet != null) return false;
   } else if (!hashSet.equals(other.hashSet)) return false;
   if (linkedBlockingDeque == null) {
     if (other.linkedBlockingDeque != null) return false;
   } else if (!linkedBlockingDeque.equals(other.linkedBlockingDeque)) return false;
   if (linkedBlockingQueue == null) {
     if (other.linkedBlockingQueue != null) return false;
   } else if (!linkedBlockingQueue.equals(other.linkedBlockingQueue)) return false;
   if (linkedHashSet == null) {
     if (other.linkedHashSet != null) return false;
   } else if (!linkedHashSet.equals(other.linkedHashSet)) return false;
   if (linkedList == null) {
     if (other.linkedList != null) return false;
   } else if (!linkedList.equals(other.linkedList)) return false;
   if (list == null) {
     if (other.list != null) return false;
   } else if (!list.equals(other.list)) return false;
   if (name == null) {
     if (other.name != null) return false;
   } else if (!name.equals(other.name)) return false;
   if (navigableSet == null) {
     if (other.navigableSet != null) return false;
   } else if (!navigableSet.equals(other.navigableSet)) return false;
   if (priorityBlockingQueue == null) {
     if (other.priorityBlockingQueue != null) return false;
   } else if (!priorityBlockingQueue.equals(other.priorityBlockingQueue)) return false;
   if (priorityQueue == null) {
     if (other.priorityQueue != null) return false;
   } else if (!priorityQueue.equals(other.priorityQueue)) return false;
   if (queue == null) {
     if (other.queue != null) return false;
   } else if (!queue.equals(other.queue)) return false;
   if (set == null) {
     if (other.set != null) return false;
   } else if (!set.equals(other.set)) return false;
   if (sortedSet == null) {
     if (other.sortedSet != null) return false;
   } else if (!sortedSet.equals(other.sortedSet)) return false;
   if (stack == null) {
     if (other.stack != null) return false;
   } else if (!stack.equals(other.stack)) return false;
   if (treeSet == null) {
     if (other.treeSet != null) return false;
   } else if (!treeSet.equals(other.treeSet)) return false;
   if (vector == null) {
     if (other.vector != null) return false;
   } else if (!vector.equals(other.vector)) return false;
   return true;
 }
  /**
   * This will consume two LinkedLists of Layers and return a combined List of Layers representing a
   * dualstrusion print, with all the appropriate toolchanges inserted.
   *
   * @param left
   * @param right
   */
  private LinkedList<Layer> doMerge(final LinkedList<Layer> left, final LinkedList<Layer> right) {
    /*
     *   Merging layers should look something like this:
     *   Queue<Layer> A, B;
     *   List<Layer> result
     *   A = layers from one file, sorted from least to greatest
     *   B = layers from other file, sorted from least to greatest
     *   last = null
     *   while A && B are not empty
     *     if A.peek.height < B.peek.height
     *       if last == B
     *         result.append(toolchange B to A)
     *       result.append(A.pop)
     *       last = A
     *     else if B.peek.height < A.peek.height
     *       if last == A
     *         result.append(toolchange A to B)
     *       result.append(B.pop)
     *       last = B
     *     else // they're of equal height
     *       if last != null
     *         if last == A
     *           result.append(A.pop)
     *         else if last == B
     *           result.append(B.pop)
     *       else
     *         result.append(A.pop)
     *   // at this point one of them is empty
     *   if A is not empty
     *     if last == B
     *       result.append(toolchange B to A)
     *     result.appendAll(A)
     *   if B is not empty
     *     if last == A
     *       result.append(toolchange A to B)
     *     result.appendAll(B)
     *
     *
     */
    // using a LinkedList means we can getLast()
    final LinkedList<Layer> result = new LinkedList<Layer>();

    // this is just a handy way to keep track of where our last layer came from
    Object lastLayer = null;

    final ToolheadAlias initialTool;
    // Start by selecting the correct toolhead
    // This mimics how the selection happens in the loop below
    if (right.peek().getHeight() < left.peek().getHeight()) initialTool = ToolheadAlias.RIGHT;
    else initialTool = ToolheadAlias.LEFT;

    // Prepend the switch to correct tool to the whole thing
    result.add(
        new Layer(
            0,
            new ArrayList<String>() {
              {
                add(initialTool.getRecallOffsetGcodeCommand());
                add("M108 " + initialTool.getTcode() + "(Set tool)");
              }
            }));

    // loop while we still have layers to merge
    while ((!left.isEmpty()) || (!right.isEmpty())) {
      // if we've used all of our right layers, keep grabbing from left
      if (right.isEmpty()) {
        // if last layer tool != next layer tool, add a toolchange
        if (right.equals(lastLayer))
          result.add(
              toolchange(ToolheadAlias.RIGHT, result.getLast(), ToolheadAlias.LEFT, left.peek()));
        result.add(left.pop());
        lastLayer = left;
      } else if (left.isEmpty()) // used all left layers, keep grabbing from right
      {
        // if last layer tool != next layer tool, add a toolchange
        if (left.equals(lastLayer))
          result.add(
              toolchange(ToolheadAlias.LEFT, result.getLast(), ToolheadAlias.RIGHT, right.peek()));
        result.add(right.pop());
        lastLayer = right;
      } else if (left.peek().getHeight()
          < right.peek().getHeight()) // left has a lower layer, grab it
      {
        // if last layer tool != next layer tool, add a toolchange
        if (right.equals(lastLayer))
          result.add(
              toolchange(ToolheadAlias.RIGHT, result.getLast(), ToolheadAlias.LEFT, left.peek()));
        result.add(left.pop());
        lastLayer = left;
      } else if (right.peek().getHeight() < left.peek().getHeight()) // right has lower layer
      {
        // if last layer tool != next layer tool, add a toolchange
        if (left.equals(lastLayer))
          result.add(
              toolchange(ToolheadAlias.LEFT, result.getLast(), ToolheadAlias.RIGHT, right.peek()));
        result.add(right.pop());
        lastLayer = right;
      } else // equal height
      {
        if (lastLayer == null) {
          // arbitrary
          result.add(left.pop());
          lastLayer = left;
        } else {
          if (lastLayer == left) result.add(left.pop());
          else // if(lastLayer == right)
          result.add(right.pop());
        }
      }
    }

    return result;
  }