org.ebay.datameta.dom.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dom-core Show documentation
Show all versions of dom-core Show documentation
Classes needed for DataMeta DOM functionality in JVM; with Java, Scala, Clojure, JRuby and other platforms running on a JVM.
package org.ebay.datameta.dom;
import java.util.function.Consumer;
/**
* @author Michael Bergens
*/
public class Util {
public static final Object[] NO_XTRAS = new Object[0];
private Util() {
}
/* attempt to generalize the list function; but Java generics are just not powerful enough for this
public static boolean areListsSame(List one, List another, DataMetaSame dataMetaSame) {
if(one == another) return true;
if(one == null || another == null ) return false; // one of them is null but not both -- not equal short-circuit
java.util.ListIterator> it1 = one.listIterator();
java.util.ListIterator> it2 = another.listIterator();
while(it1.hasNext() && it2.hasNext()) {
final T o1 = it1.next(), o2 = it2.next();
if(!(o1 == null ? o2 == null : dataMetaSame.isSame(o1, o2))) return false; // shortcircuit to false
}
return !(it1.hasNext() || it2.hasNext());
}
*/
public static Consumer consumerReRte(ThrowingConsumer consumer) {
return t -> {
try {
consumer.accept(t);
}
catch (Exception x) {
reAsRte(x);
}
};
}
@SuppressWarnings("unchecked") private static void reAsRte(E x) {
throw new RuntimeException(x);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy