Example usage for java.lang Number equals

List of usage examples for java.lang Number equals

Introduction

In this page you can find the example usage for java.lang Number 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.jfree.data.general.junit.TestIntervalCategoryDataset.java

/**
 * Tests this dataset for equality with an arbitrary object.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean./*from   w  w w.j  a v a 2s.com*/
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof TestIntervalCategoryDataset)) {
        return false;
    }
    TestIntervalCategoryDataset that = (TestIntervalCategoryDataset) obj;
    if (!getRowKeys().equals(that.getRowKeys())) {
        return false;
    }
    if (!getColumnKeys().equals(that.getColumnKeys())) {
        return false;
    }
    int rowCount = getRowCount();
    int colCount = getColumnCount();
    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colCount; c++) {
            Number v1 = getValue(r, c);
            Number v2 = that.getValue(r, c);
            if (v1 == null) {
                if (v2 != null) {
                    return false;
                }
            } else if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}

From source file:com.gst.infrastructure.core.api.JsonCommand.java

private boolean differenceExists(final Number baseValue, final Number workingCopyValue) {
    boolean differenceExists = false;

    if (baseValue != null) {
        if (workingCopyValue != null) {
            differenceExists = !baseValue.equals(workingCopyValue);
        } else {/*from w  ww  .  jav a  2  s  .  c o  m*/
            differenceExists = true;
        }
    } else {
        differenceExists = workingCopyValue != null;
    }

    return differenceExists;
}

From source file:org.opengroupware.logic.authz.OGoAuthzFetchContext.java

/**
 * Checks whether login-ctx has authenticated the given id. It could be a
 * team id or a person(/account) id. If you just need to check person ids
 * (eg 'ownerId' like fields) use the contextHasAccountId() method. 
 * /*from   w  w w .  j  a  v  a2s  .c  o  m*/
 * @param  _id - the primary key to be checked
 * @return true if this ID is authenticated, false otherwise
 */
public boolean contextHasPrincipalId(final Number _id) {
    if (_id == null || this.authIds == null)
        return false;

    for (final Number p : this.authIds) {
        if (p != null && p.equals(_id))
            return true;
    }
    return false;
}

From source file:org.opengroupware.logic.authz.OGoAuthzFetchContext.java

/**
 * Checks whether login-ctx has authenticated the given account id.
 * /*from  www  .ja  va  2s .c om*/
 * @param  _id - the person contact's primary key to be checked
 * @return true if this ID is authenticated, false otherwise
 */
public boolean contextHasAccountId(final Number _id) {
    if (_id == null || this.personAuthIds == null)
        return false;

    for (final Number p : this.personAuthIds) {
        if (p != null && p.equals(_id))
            return true;
    }
    return false;
}

From source file:org.jfree.data.DefaultKeyedValues2D.java

/**
 * Tests if this object is equal to another.
 *
 * @param o  the other object (<code>null</code> permitted).
 *
 * @return A boolean.//www.  j a  v  a2 s  .com
 */
public boolean equals(Object o) {

    if (o == null) {
        return false;
    }
    if (o == this) {
        return true;
    }

    if (!(o instanceof KeyedValues2D)) {
        return false;
    }
    KeyedValues2D kv2D = (KeyedValues2D) o;
    if (!getRowKeys().equals(kv2D.getRowKeys())) {
        return false;
    }
    if (!getColumnKeys().equals(kv2D.getColumnKeys())) {
        return false;
    }
    int rowCount = getRowCount();
    if (rowCount != kv2D.getRowCount()) {
        return false;
    }

    int colCount = getColumnCount();
    if (colCount != kv2D.getColumnCount()) {
        return false;
    }

    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colCount; c++) {
            Number v1 = getValue(r, c);
            Number v2 = kv2D.getValue(r, c);
            if (v1 == null) {
                if (v2 != null) {
                    return false;
                }
            } else {
                if (!v1.equals(v2)) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:org.jfree.data.DefaultKeyedValues2D.java

/**
 * Tests if this object is equal to another.
 *
 * @param o  the other object (<code>null</code> permitted).
 *
 * @return A boolean.//from  w ww .  j  a v a 2  s  .  co m
 */
@Override
public boolean equals(Object o) {

    if (o == null) {
        return false;
    }
    if (o == this) {
        return true;
    }

    if (!(o instanceof KeyedValues2D)) {
        return false;
    }
    KeyedValues2D kv2D = (KeyedValues2D) o;
    if (!getRowKeys().equals(kv2D.getRowKeys())) {
        return false;
    }
    if (!getColumnKeys().equals(kv2D.getColumnKeys())) {
        return false;
    }
    int rowCount = getRowCount();
    if (rowCount != kv2D.getRowCount()) {
        return false;
    }

    int colCount = getColumnCount();
    if (colCount != kv2D.getColumnCount()) {
        return false;
    }

    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colCount; c++) {
            Number v1 = getValue(r, c);
            Number v2 = kv2D.getValue(r, c);
            if (v1 == null) {
                if (v2 != null) {
                    return false;
                }
            } else {
                if (!v1.equals(v2)) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:edu.ku.brc.specify.datamodel.SpQueryField.java

/**
 * @param val//w  w  w  . j  a  v a  2  s.c  o m
 * @return
 */
protected Number nullIfZero(Number val) {
    if (val != null && val.equals(0)) {
        return null;
    }
    return val;
}

From source file:com.datatorrent.apps.logstream.DimensionOperator.java

/**
 * Does dimensional computations for each incoming tuple and populates the cache with the computations
 *
 * @param tuple//from  w  ww.  j  a va2 s  .c  om
 */
protected void processTuple(Map<String, Object> tuple) {
    long time;
    if (timeKeyName != null) {
        time = (Long) tuple.get(timeKeyName);
    } else {
        time = LogstreamUtil.extractTime(currentWindowId, windowWidth);
    }
    List<String> timeBucketList = getTimeBucketList(time);

    if (firstTuple) {
        // populate record type
        extractType(tuple);
        outTimeBuckets = new ArrayList<String>(timeBucketList);

        // create all dimension combinations if not specified by user
        if (!dimensionCombinationList.containsKey(recordType.get(LogstreamUtil.LOG_TYPE))) {
            createAllDimensionCombinations();
        }

        dimensionCombinations = dimensionCombinationList.get(recordType.get(LogstreamUtil.LOG_TYPE));
        valueOperationTypes = valueOperations.get(recordType.get(LogstreamUtil.LOG_TYPE));
        firstTuple = false;
    }

    // temporary validation to ensure that unexpected records do not appear in any partition
    Number receivedLogType = (Number) tuple.get(LogstreamUtil.LOG_TYPE);
    Number receivedFilter = (Number) tuple.get(LogstreamUtil.FILTER);

    Number expectedLogType = recordType.get(LogstreamUtil.LOG_TYPE);
    Number expectedFilter = recordType.get(LogstreamUtil.FILTER);

    if (!receivedLogType.equals(expectedLogType) || !receivedFilter.equals(expectedFilter)) {
        logger.error("Unexpected tuple");
        logger.error("expected log type = {} received = {}", expectedLogType, receivedLogType);
        logger.error("expected filter = {} received = {}", expectedFilter, receivedFilter);
    } else {
        for (String timeBucket : timeBucketList) {
            for (Integer dimensionCombinationId : dimensionCombinations) {
                String dimensionCombination = registry.lookupValue(dimensionCombinationId);
                String[] dimensions = dimensionCombination.split(":");

                String dimValueName = new String();
                boolean isBadTuple = false;
                if (dimensions != null) {
                    for (String dimension : dimensions) {
                        Object dimVal = tuple.get(dimension);
                        if (dimVal == null) {
                            logger.error("dimension \"{}\" not found in tuple", dimension);
                            isBadTuple = true;
                            continue;
                        }
                        if (!dimValueName.isEmpty()) {
                            dimValueName += ",";
                        }
                        dimValueName += tuple.get(dimension).toString();
                    }
                }

                if (!isBadTuple) {
                    for (Entry<String, HashSet<AggregateOperation>> entry : valueOperationTypes.entrySet()) {
                        String valueKeyName = entry.getKey();
                        Object value = tuple.get(valueKeyName);
                        Number numberValue = LogstreamUtil.extractNumber(value);
                        doComputations(timeBucket, dimensionCombinationId, dimValueName, valueKeyName,
                                numberValue);
                    }
                }
            }
        }
    }
}

From source file:org.opengroupware.logic.auth.OGoLoginTokenManager.java

/**
 * Creates a new token for the given subject / environment.
 * //from w  ww  .  jav  a 2 s  . com
 * @param _subject - the JAAS subject which contains the principals
 * @param _env     - an optional environment
 * @return the token String as inserted in the database
 */
public String createToken(Subject _subject, Object _env) {
    // TBD: createToken must take a *Subject* (or LoginContext), and not do the
    //      auth
    if (_subject == null)
        return null;

    String envext = _env != null ? NSPropertyListSerialization.stringFromPropertyList(_env) : null;

    Date now = new Date();
    Number uid = null;

    /* generate token */

    StringBuilder msg = new StringBuilder(1024);
    for (Principal p : _subject.getPrincipals()) {
        msg.append(p.getName());
        if (p instanceof IOGoPrincipal) {
            // TBD: check DB identifier
            Number pid = ((IOGoPrincipal) p).id();
            msg.append(pid);
            if (p instanceof OGoAccountPrincipal) {
                if (uid == null)
                    uid = pid;
                else if (!uid.equals(pid))
                    log.error("multiple account principals!");
            }
        }
    }
    if (uid == null) {
        log.error("did not find a primary principal in subject!");
        return null;
    }
    msg.append(now.getTime());
    if (envext != null)
        msg.append(envext);

    String token = UString.md5HashForString(msg.toString());
    msg = null;

    /* insert token into database */

    Map<String, Object> record = new HashMap<String, Object>(16);
    record.put("token", token);
    record.put("account_id", uid);
    record.put("creation_date", now);
    record.put("touch_date", now);
    if (envext != null)
        record.put("environment", envext);

    if (!this.db.adaptor().insertRow("login_token", record)) {
        log.error("could not insert login token into database: " + _subject);
        return null;
    }

    /* token is inserted, we are done */

    return token;
}

From source file:eu.dasish.annotation.backend.rest.NotebookResource.java

/**
 * // w  ww. j a  va  2s  .c om
 * @param externalIdentifier the external UUID identifier of a notebook.
 * @param notebookInfo the fresh {@link NotebookInfo} object.
 * @return a {@link ResponseBody} element containing the just updated {@link Notebook} element
 * and the list of actions (which are not yet specified for the notebooks).
 * @throws IOException if sending an error fails.
 */
@PUT
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
@Path("{notebookid: " + BackendConstants.regExpIdentifier + "}")
public JAXBElement<ResponseBody> updateNotebookInfo(@PathParam("notebookid") String externalIdentifier,
        NotebookInfo notebookInfo) throws IOException {
    Number remotePrincipalID = this.getPrincipalID();
    if (remotePrincipalID == null) {
        return new ObjectFactory().createResponseBody(new ResponseBody());
    }
    String path = this.getRelativeServiceURI();
    String notebookURI = notebookInfo.getHref();
    if (!(path + "/notebooks/" + externalIdentifier).equals(notebookURI)) {
        httpServletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return new ObjectFactory().createResponseBody(new ResponseBody());
    }
    ;
    try {
        final Number notebookID = dbDispatcher
                .getResourceInternalIdentifier(UUID.fromString(externalIdentifier), Resource.NOTEBOOK);
        try {
            if (remotePrincipalID.equals(dbDispatcher.getNotebookOwner(notebookID))
                    || dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID).equals(admin)) {
                boolean success = dbDispatcher.updateNotebookMetadata(notebookID, notebookInfo);
                if (success) {
                    return new ObjectFactory()
                            .createResponseBody(dbDispatcher.makeNotebookResponseEnvelope(notebookID));
                } else {
                    httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    return new ObjectFactory().createResponseBody(new ResponseBody());
                }
            } else {
                loggerServer.debug(
                        " Ownership changing is the part of the full update of the notebook metadadata.");
                httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
                return new ObjectFactory().createResponseBody(new ResponseBody());
            }
        } catch (NotInDataBaseException e1) {
            loggerServer.debug(e1.toString());
            httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
            return new ObjectFactory().createResponseBody(new ResponseBody());
        }
    } catch (NotInDataBaseException e) {
        loggerServer.debug(e.toString());
        httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.toString());
        return new ObjectFactory().createResponseBody(new ResponseBody());
    }
}