Package org.jtester.hamcrest.matcher.property.difference

Examples of org.jtester.hamcrest.matcher.property.difference.CollectionDifference


      ReflectionComparator reflectionComparator) {
    List leftList = ListHelper.toList(left);
    List rightList = ListHelper.toList(right);

    int elementIndex = -1;
    CollectionDifference difference = new CollectionDifference("Different elements", left, right, leftList,
        rightList);

    Iterator<?> leftIterator = leftList.iterator();
    Iterator<?> rightIterator = rightList.iterator();
    while (leftIterator.hasNext() && rightIterator.hasNext()) {
      elementIndex++;

      Difference elementDifference = reflectionComparator.getDifference(leftIterator.next(),
          rightIterator.next(), onlyFirstDifference);
      if (elementDifference != null) {
        difference.addElementDifference(elementIndex, elementDifference);
        if (onlyFirstDifference) {
          return difference;
        }
      }
    }

    // check for missing elements
    int leftElementIndex = elementIndex;
    while (leftIterator.hasNext()) {
      leftIterator.next();
      difference.addLeftMissingIndex(++leftElementIndex);
    }
    int rightElementIndex = elementIndex;
    while (rightIterator.hasNext()) {
      rightIterator.next();
      difference.addRightMissingIndex(++rightElementIndex);
    }

    if (difference.getElementDifferences().isEmpty() && difference.getLeftMissingIndexes().isEmpty()
        && difference.getRightMissingIndexes().isEmpty()) {
      return null;
    }
    return difference;
  }
View Full Code Here

TOP

Related Classes of org.jtester.hamcrest.matcher.property.difference.CollectionDifference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.