0

what are the changes that I need to make if I am using jdk 7 and want to use lambda expression? I am comparing 2 xml files and want to ignore specific nodes hence using this expression

final Diff documentDiff = DiffBuilder
            .compare(expectedSource)
            .withTest(actualSource)
            .withNodeFilter(node -> !node.getNodeName().equals(someName))
            .build();

error: Syntax error on token '-',-- expected

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Fraction
  • 3
  • 2
  • 10

2 Answers2

1

Try this.

    final Diff documentDiff = DiffBuilder
        .compare(expectedSource)
        .withTest(actualSource)
        .withNodeFilter(new Predicate<Node>() {
            @Override
            public boolean test(Node node) {
                return !node.getNodeName().equals(someName);
            } 
        })
        .build();

This is redundant, but JDK7 will accept it. I don't know if you can realize what you want to do with this.

  • error:The method compare(String) is undefined for the type DiffBuilder; added commons-codec1.9 jar as well for diffbuilder – Fraction Jun 13 '17 at 06:13
  • any other jars to be added or modifications? @saka1029 – Fraction Jun 13 '17 at 06:22
  • See [this](http://www.xmlunit.org/api/java/2.0.0/org/xmlunit/builder/DiffBuilder.html#compare-java.lang.Object-). –  Jun 13 '17 at 06:33
0

lambda expression can not be used in java 7. The syntax itself is only allowed in java8. However the functionality you can achieve by writing more code or with out using lamda expression. You need to write a filter method which checks the name of node with someName if it returns true then proceed with building document Difference. You will need to write multiple statement and if case to check name equality.

You can also achieve this using xslt. which is very fast for long xml files but then you will need to write a lot of code as xslt is declarative and based upon functional programming.

Pradeep Singh
  • 1,094
  • 1
  • 9
  • 24