Example usage for java.util Objects equals

List of usage examples for java.util Objects equals

Introduction

In this page you can find the example usage for java.util Objects equals.

Prototype

public static boolean equals(Object a, Object b) 

Source Link

Document

Returns true if the arguments are equal to each other and false otherwise.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<String> liste = Arrays.asList("CSS", "HTML", "Davut", null);

    liste.parallelStream()// Parallel stuff uses Fork-Join
            .filter(e -> (!Objects.equals(e, null))) // lazy & parallel
            .filter(e -> (e.length() > 3)) // lazy & parallel
            .forEach(e -> { // sequential & eagerly
                System.out.println("Bigger length than 3 in List: " + e);
            });/*from w  w w  .  j av  a 2s . c om*/
}

From source file:Main.java

public static void main(String[] args) {
    List<String> liste = Arrays.asList("XML", "HTML", "CSS", null);

    liste.parallelStream()// Parallel stuff uses Fork-Join
            .filter(e -> (!Objects.equals(e, null))) // lazy & parallel
            .filter(e -> (e.length() > 3)) // lazy & parallel
            .forEach(e -> { // sequential & eagerly
                System.out.println("Bigger length than 3 in List: " + e);
            });/*from   w  ww.jav  a  2  s .c o m*/

}

From source file:Main.java

public static void main(String[] args) {
    My p1 = produce(() -> new My());
    My p2 = produce(() -> new My());

    System.out.println("Check the same object? " + Objects.equals(p1, p2));

}

From source file:Main.java

public static void main(String[] args) {
    SunPower power = new SunPower();

    SunPower p1 = produce(() -> power);
    SunPower p2 = produce(() -> power);

    System.out.println("Check the same object? " + Objects.equals(p1, p2));
}

From source file:Main.java

public static <K, V> K getKeyByValue(Map<K, V> map, V value) {
    K result = null;/*w ww .j a va 2 s.  c  om*/
    for (Map.Entry<K, V> entry : map.entrySet()) {
        if (Objects.equals(entry.getValue(), value)) {
            result = entry.getKey();
            break;
        }
    }

    return result;
}

From source file:Main.java

/**
 * Compare if two iterable objects are equal by element.
 * @param i1 sequence 1./*from w  w  w. j a  va  2 s  . co  m*/
 * @param i2 sequence 2.
 * @param <T> type.
 * @return true if all elements at the same index are equal.
 */
public static <T> boolean iterableEquals(Iterable<T> i1, Iterable<T> i2) {

    if (Objects.equals(i1, i2))
        return true;

    if (i1 == null || i2 == null)
        return false;

    Iterator<T> iterator1 = i1.iterator();
    Iterator<T> iterator2 = i2.iterator();

    while (iterator1.hasNext()) {

        if (!iterator2.hasNext())
            return false;

        T obj1 = iterator1.next();
        T obj2 = iterator2.next();

        if (!Objects.equals(obj1, obj2)) {
            return false;
        }
    }

    return !iterator2.hasNext();
}

From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseURI.java

public static URI createURI(URI uri) {
    if (Objects.equals(PersistenceURI.FILE_SCHEME, uri.scheme())) {
        return createFileURI(FileUtils.getFile(uri.toFileString()));
    } else if (Objects.equals(SCHEME, uri.scheme())) {
        return PersistenceURI.createURI(uri);
    } else {/*ww  w  .ja  va2  s .  c  o m*/
        throw new IllegalArgumentException(
                MessageFormat.format("Can not create HBaseURI from the URI scheme {0}", uri.scheme()));
    }
}

From source file:fr.inria.atlanmod.neoemf.data.mapdb.util.MapDbURI.java

public static URI createURI(URI uri) {
    URI returnValue;//from  w  w  w.j a  va  2  s.c  o  m
    if (Objects.equals(PersistenceURI.FILE_SCHEME, uri.scheme())) {
        returnValue = createFileURI(FileUtils.getFile(uri.toFileString()));
    } else if (Objects.equals(SCHEME, uri.scheme())) {
        returnValue = PersistenceURI.createURI(uri);
    } else {
        throw new IllegalArgumentException(
                MessageFormat.format("Can not create MapDbURI from the URI scheme {0}", uri.scheme()));
    }
    return returnValue;
}

From source file:Main.java

/**
 * Return first index of {@code value} in {@code array}, or {@code -1} if
 * not found./*from  www. j a va 2s  .c  om*/
 */
public static <T> int indexOf(T[] array, T value) {
    if (array == null)
        return -1;
    for (int i = 0; i < array.length; i++) {
        if (Objects.equals(array[i], value))
            return i;
    }
    return -1;
}

From source file:fr.inria.atlanmod.neoemf.data.berkeleydb.util.BerkeleyDBURI.java

public static URI createURI(URI uri) {
    URI returnValue;//  w  w w  . j a  v  a2  s. c om
    if (Objects.equals(PersistenceURI.FILE_SCHEME, uri.scheme())) {
        returnValue = createFileURI(FileUtils.getFile(uri.toFileString()));
    } else if (Objects.equals(SCHEME, uri.scheme())) {
        returnValue = PersistenceURI.createURI(uri);
    } else {
        throw new IllegalArgumentException(
                MessageFormat.format("Can not create BerkeleyDBURI from the URI scheme {0}", uri.scheme()));
    }
    return returnValue;
}