Example usage for java.lang Object equals

List of usage examples for java.lang Object equals

Introduction

In this page you can find the example usage for java.lang Object equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.slc.sli.dashboard.unit.client.SDKAPIClientTest.java

private static List<Entity> fromFileWithValue(String filename, String value, String key) {
    List<Entity> allEntities = fromFile(filename);
    List<Entity> matchingEntities = new ArrayList<Entity>();
    for (Entity e : allEntities) {
        Object entity = ((GenericEntity) e).get(key);
        // entity can be a single value or an ArrayList of values
        if (entity instanceof ArrayList) {
            if (((ArrayList<?>) entity).contains(value)) {
                matchingEntities.add(e);
            }//  w  w w .  j  a v  a2s .  co m
        } else if (entity.equals(value)) {
            matchingEntities.add(e);
        }
    }
    return matchingEntities;
}

From source file:org.openmrs.module.metadatasharing.merger.ComparisonEngine.java

private boolean nullSafeEqual(Object o1, Object o2) {
    if (o1 == o2) {
        return true;
    } else if (o1 != null) {
        return o1.equals(o2);
    } else {//from  w  w  w.j a  v a  2  s  . c  o  m
        return false;
    }
}

From source file:it.unibas.spicygui.controllo.spicy.ActionLoadComaCorrespondences.java

@Override
public void update(Observable o, Object stato) {
    if (stato.equals(LastActionBean.CLOSE)) {
        this.setEnabled(false);
    } else {/*w ww  . j a  v  a  2  s  .  co  m*/
        this.setEnabled(true);
    }

}

From source file:com.mb.framework.util.property.PropertyUtilExt.java

public static boolean equalsSimpleProperties(Object mainObject, Object otherObject)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(mainObject);
    for (int i = 0; i < origDescriptors.length; i++) {
        String name = origDescriptors[i].getName();

        if (PropertyUtils.getPropertyDescriptor(otherObject, name) != null) {
            Object origValue = PropertyUtils.getSimpleProperty(mainObject, name);
            Object otherValue = PropertyUtils.getSimpleProperty(otherObject, name);

            if (origValue != null && otherValue == null) {
                return false;
            }/*from   www  .  j a v a  2  s.  c om*/

            if (origValue == null && otherValue != null) {
                return false;
            }

            if (origValue != null && otherValue != null) {
                /*
                 * to walk around timestamp and date equals behavior Date d
                 * = new Date(); Timestamp t = new Timestamp(d.getTime());
                 * d.equals(t) > == true; t.equals(d) > == false;
                 */
                if (origValue instanceof java.sql.Timestamp
                        && (otherValue instanceof java.sql.Date || otherValue instanceof java.util.Date)) {
                    if (!otherValue.equals(origValue)) {
                        return false;
                    }
                } else {
                    if (!origValue.equals(otherValue)) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.diversityarrays.dalclient.util.Pair.java

@Override
public boolean equals(Object o) {
    if (o == this)
        return true;
    if (!(o instanceof Pair))
        return false;

    Pair<?, ?> other = (Pair<?, ?>) o;
    Object oa = other.a;
    Object ob = other.b;/*from  ww w.  j a  v  a2s  .c o m*/

    return (oa == null ? a == null : oa.equals(a)) && (ob == null ? b == null : ob.equals(b));
}

From source file:com.xie.javacase.json.XML.java

/**
 * Scan the content following the named tag, attaching it to the context.
 * @param x       The XMLTokener containing the source string.
 * @param context The JSONObject that will include the new material.
 * @param name    The tag name./*from   ww  w.java 2 s .c  o m*/
 * @return true if the close tag is processed.
 * @throws org.json.JSONException
 */
private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
    char c;
    int i;
    String n;
    JSONObject o = null;
    String s;
    Object t;

    // Test for and skip past these forms:
    //      <!-- ... -->
    //      <!   ...   >
    //      <![  ... ]]>
    //      <?   ...  ?>
    // Report errors for these forms:
    //      <>
    //      <=
    //      <<

    t = x.nextToken();

    // <!

    if (t == BANG) {
        c = x.next();
        if (c == '-') {
            if (x.next() == '-') {
                x.skipPast("-->");
                return false;
            }
            x.back();
        } else if (c == '[') {
            t = x.nextToken();
            if (t.equals("CDATA")) {
                if (x.next() == '[') {
                    s = x.nextCDATA();
                    if (s.length() > 0) {
                        context.accumulate("content", s);
                    }
                    return false;
                }
            }
            throw x.syntaxError("Expected 'CDATA['");
        }
        i = 1;
        do {
            t = x.nextMeta();
            if (t == null) {
                throw x.syntaxError("Missing '>' after '<!'.");
            } else if (t == LT) {
                i += 1;
            } else if (t == GT) {
                i -= 1;
            }
        } while (i > 0);
        return false;
    } else if (t == QUEST) {

        // <?

        x.skipPast("?>");
        return false;
    } else if (t == SLASH) {

        // Close tag </

        t = x.nextToken();
        if (name == null) {
            throw x.syntaxError("Mismatched close tag" + t);
        }
        if (!t.equals(name)) {
            throw x.syntaxError("Mismatched " + name + " and " + t);
        }
        if (x.nextToken() != GT) {
            throw x.syntaxError("Misshaped close tag");
        }
        return true;

    } else if (t instanceof Character) {
        throw x.syntaxError("Misshaped tag");

        // Open tag <

    } else {
        n = (String) t;
        t = null;
        o = new JSONObject();
        for (;;) {
            if (t == null) {
                t = x.nextToken();
            }

            // attribute = value

            if (t instanceof String) {
                s = (String) t;
                t = x.nextToken();
                if (t == EQ) {
                    t = x.nextToken();
                    if (!(t instanceof String)) {
                        throw x.syntaxError("Missing value");
                    }
                    o.accumulate(s, JSONObject.stringToValue((String) t));
                    t = null;
                } else {
                    o.accumulate(s, "");
                }

                // Empty tag <.../>

            } else if (t == SLASH) {
                if (x.nextToken() != GT) {
                    throw x.syntaxError("Misshaped tag");
                }
                context.accumulate(n, o);
                return false;

                // Content, between <...> and </...>

            } else if (t == GT) {
                for (;;) {
                    t = x.nextContent();
                    if (t == null) {
                        if (n != null) {
                            throw x.syntaxError("Unclosed tag " + n);
                        }
                        return false;
                    } else if (t instanceof String) {
                        s = (String) t;
                        if (s.length() > 0) {
                            o.accumulate("content", JSONObject.stringToValue(s));
                        }

                        // Nested element

                    } else if (t == LT) {
                        if (parse(x, o, n)) {
                            if (o.length() == 0) {
                                context.accumulate(n, "");
                            } else if (o.length() == 1 && o.opt("content") != null) {
                                context.accumulate(n, o.opt("content"));
                            } else {
                                context.accumulate(n, o);
                            }
                            return false;
                        }
                    }
                }
            } else {
                throw x.syntaxError("Misshaped tag");
            }
        }
    }
}

From source file:de.thm.arsnova.security.ApplicationPermissionEvaluator.java

private boolean checkSessionPermission(final String username, final Serializable targetId,
        final Object permission) {
    if (permission instanceof String && (permission.equals("owner") || permission.equals("write"))) {
        return dao.getSessionFromKeyword(targetId.toString()).getCreator().equals(username);
    } else if (permission instanceof String && permission.equals("read")) {
        return dao.getSessionFromKeyword(targetId.toString()).isActive();
    }/*  w w w.  j a  v  a 2 s.c  o  m*/
    return false;
}

From source file:com.asual.lesscss.compiler.RhinoCompiler.java

private boolean hasProperty(Scriptable value, String name) {
    Object property = ScriptableObject.getProperty(value, name);
    return property != null && !property.equals(UniqueTag.NOT_FOUND);
}

From source file:edu.umass.cs.gigapaxos.PaxosConfig.java

@SuppressWarnings({ "javadoc", "unchecked", "rawtypes" })
public static void sanityCheck(NodeConfig nodeConfig) throws IOException {
    for (Object n : nodeConfig.getNodeIDs()) {
        for (Object m : nodeConfig.getNodeIDs())
            if (!n.equals(m) && nodeConfig.getNodeAddress(n).equals(nodeConfig.getNodeAddress(m))
                    && (nodeConfig.getNodePort(n) == nodeConfig.getNodePort(m)
                            || nodeConfig.getNodePort(n)
                                    + Config.getGlobalInt(PC.CLIENT_PORT_OFFSET) == nodeConfig.getNodePort(m)
                            || nodeConfig.getNodePort(n)
                                    + Config.getGlobalInt(PC.CLIENT_PORT_SSL_OFFSET) == nodeConfig
                                            .getNodePort(m)

                    ))//  www  . j a va2 s .  c  om
                throw new IOException("Clash in nodeConfig between " + n + " and " + m
                        + ": node socket addresses should not be identical or " + "be exactly "
                        + "CLIENT_PORT_OFFSET=" + Config.getGlobalInt(PC.CLIENT_PORT_OFFSET) + " or "
                        + "CLIENT_PORT_SSL_OFFSET=" + Config.getGlobalInt(PC.CLIENT_PORT_SSL_OFFSET)
                        + " apart.");
    }
}

From source file:gov.nih.nci.caarray.util.URIUserType.java

/**
 * {@inheritDoc}/*  w  w w. ja va 2 s.c  o  m*/
 */
@Override
public boolean equals(Object x, Object y) {
    return (x == y) || (x != null && y != null && (x.equals(y))); // NOPMD - on purpose == comparison
}