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:fr.inria.atlanmod.neoemf.data.blueprints.util.BlueprintsURI.java

public static URI createURI(URI uri) {
    URI returnValue;//from  w w  w .j  a  v  a  2s  .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 NeoGraphURI from the URI scheme {0}", uri.scheme()));
    }
    return returnValue;
}

From source file:Main.java

/**
 * Removes value from given array if present, providing set-like behavior.
 *///from  w w  w  . java2 s . c om
public static String[] removeString(String[] cur, String val) {
    if (cur == null) {
        return null;
    }
    final int N = cur.length;
    for (int i = 0; i < N; i++) {
        if (Objects.equals(cur[i], val)) {
            String[] ret = new String[N - 1];
            if (i > 0) {
                System.arraycopy(cur, 0, ret, 0, i);
            }
            if (i < (N - 1)) {
                System.arraycopy(cur, i + 1, ret, i, N - i - 1);
            }
            return ret;
        }
    }
    return cur;
}

From source file:Main.java

/**
 * Returns true if list has equal items as array in same order.
 * @param <T>/*from w  ww  .  ja va2  s.  c om*/
 * @param list
 * @param array
 * @return 
 */
public static <T> boolean equals(List<T> list, T... array) {
    if (list.size() != array.length) {
        return false;
    }
    int len = array.length;
    for (int ii = 0; ii < len; ii++) {
        if (!Objects.equals(list.get(ii), array[ii])) {
            return false;
        }
    }
    return true;
}

From source file:com.quartercode.eventbridge.test.ExtraAssert.java

public static void assertListEquals(String message, List<?> actualList, Object... expectedElements) {

    assertTrue(message, actualList.size() == expectedElements.length);

    for (int index = 0; index < actualList.size(); index++) {
        assertTrue(message, Objects.equals(expectedElements[index], actualList.get(index)));
    }//www  .j a  v  a2s  . c  om
}

From source file:com.norconex.commons.lang.EqualsUtil.java

/**
 * Whether a source object equals ANY of the target objects.
 * @param source object being tested for equality with targets
 * @param targets one or more objects to be tested with source for equality
 * @return <code>true</code> if any of the target objects are equal
 *///from  w  w  w  .ja  va 2s .co m
public static boolean equalsAny(Object source, Object... targets) {
    if (targets == null) {
        return source == null;
    }
    for (Object object : targets) {
        if (Objects.equals(source, object)) {
            return true;
        }
    }
    return false;
}

From source file:com.milaboratory.test.TestUtil.java

public static boolean lt() {
    return Objects.equals(System.getProperty("longTests"), "")
            || Objects.equals(System.getProperty("longTests"), "true");
}

From source file:com.vmware.identity.openidconnect.common.State.java

private static boolean htmlFriendly(String value) {
    return Objects.equals(value, StringEscapeUtils.escapeHtml4(value));
}

From source file:Main.java

/**
 * INTERNAL: Compares two collections to see if they contain the same
 * elements./* ww  w.  j  a va2  s  . co  m*/
 *
 * @since 1.4.1
 */
public static <T> boolean equalsUnorderedSet(Collection<T> coll1, Collection<T> coll2) {

    // Take care of nulls
    if (coll1 == null)
        if (coll2 == null)
            // 1: null 2: null
            return true;
        else
            // 1: null 2: not null
            return false;
    else if (coll2 == null)
        // 1: not null 2: null
        return false;

    // Compare set size
    int size1 = coll1.size();
    int size2 = coll2.size();
    if (size1 != size2)
        return false;

    // If both have 1 element compare first element
    if (size1 == 1) {
        return Objects.equals(coll1.iterator().next(), coll2.iterator().next());
    }

    // Compare collections as sets
    if (coll1 instanceof Set)
        if (coll2 instanceof Set)
            return coll1.equals(coll2);
        else
            return coll1.equals(new HashSet<T>(coll2));
    else if (coll2 instanceof Set)
        return coll2.equals(new HashSet<T>(coll1));
    else
        return new HashSet<T>(coll2).equals(new HashSet<T>(coll1));
}

From source file:com.quartercode.eventbridge.test.ExtraAssert.java

public static void assertMapEquals(String message, Map<?, ?> map, Pair<?, ?>... entries) {

    assertTrue(message, map.size() == entries.length);

    Map<?, ?> mapClone = new HashMap<>(map);
    for (Pair<?, ?> expectedEntry : entries) {
        Object actualValue = mapClone.get(expectedEntry.getKey());
        assertTrue(message, Objects.equals(expectedEntry.getValue(), actualValue));

        mapClone.remove(expectedEntry.getKey());
    }//from  w  w w .jav  a 2  s . com
}

From source file:org.kitodo.data.elasticsearch.index.IndexRestClient.java

/**
 * Return singleton variable of type IndexRestClient.
 *
 * @return unique instance of IndexRestClient
 *//*from w w  w . j a  va2  s  .  co  m*/
public static IndexRestClient getInstance() {
    if (Objects.equals(instance, null)) {
        synchronized (IndexRestClient.class) {
            if (Objects.equals(instance, null)) {
                instance = new IndexRestClient();
                instance.initiateClient();
            }
        }
    }
    return instance;
}