0

This program returns all the synonyms for a given input. But this code is for java 1.8. How to convert this code for Java 1.6.

model.listIndividuals().forEachRemaining(ind -> {

if(((Resource)ind).getLocalName().toString().equalsIgnoreCase(input)){              
System.out.println("Synonyms of " + ((Resource)ind).getLocalName().toString() + " are:");               
            ind.listPropertyValues(isSynonymOf).forEachRemaining(val -> {                   
   System.out.println(" * " + ((Resource) val).getLocalName().toString());

            });
        }
    });
Cœur
  • 37,241
  • 25
  • 195
  • 267
ALee
  • 53
  • 1
  • 8
  • Not trivially. First, Java 1.6 (and 1.7) are end of life; why must you use it? Second, [scala 2.11.1](http://www.scala-lang.org/news/2.11.1) runs on Java 6; and does have lambdas (but slightly different syntax). – Elliott Frisch Mar 15 '17 at 02:57
  • @Elliott Frisch actually it is contraint that i have to use Java 1.6. I do not know how to convert above code(rewrite) for Java 1.6 – ALee Mar 15 '17 at 03:04
  • 1
    [`Iterator.forEachRemaining(java.util.function.Consumer)`](https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html#forEachRemaining-java.util.function.Consumer-) Javadoc says (in part) *The default implementation behaves as if: `while (hasNext()) action.accept(next());`* (which you could implement in Java 1.6), or you could use scala. I'm not going to convert this for you because SO isn't a code writing service, I'm about to go to bed, and I can't test it. – Elliott Frisch Mar 15 '17 at 03:13
  • Also, telling me it's a "contraint" doesn't really tell me ***why*** you are so *constrained*. Is this for a class? Is this for your company? – Elliott Frisch Mar 15 '17 at 03:16

1 Answers1

3

Try this:

Iterator<Individual> iterInd = model.listIndividuals();
while (iterInd.hasNext()) {
    Individual ind = iterInd.next();
    if (ind.getLocalName().equalsIgnoreCase(input)) {
        System.out.println("Synonyms of " + ind.getLocalName() + " are:");
        NodeIterator iterVal = ind.listPropertyValues(isSynonymOf);
        while (iterVal.hasNext()) {
            System.out.println(" * " + iterVal.next().getLocalName());
        }
    }
}
shmosel
  • 49,289
  • 6
  • 73
  • 138