Example usage for java.util Map equals

List of usage examples for java.util Map equals

Introduction

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

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this map for equality.

Usage

From source file:nl.hnogames.domoticzapi.Utils.RequestUtil.java

/**
 * Method to get json object request where json response starts with {
 *//* www  .ja  v a 2  s  . c om*/
public static void makeJsonGetResultRequest(@Nullable final JSONParserInterface parser, final String username,
        final String password, final String url, final SessionUtil sessionUtil,
        final boolean usePreviousSession, final int retryCounter, final RequestQueue queue) {

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {

                    String jsonString;

                    try {
                        jsonString = response.getString(DomoticzValues.Json.Field.RESULT);
                        if (parser != null)
                            parser.parseResult(jsonString);
                    } catch (JSONException e) {
                        jsonErrorHandling(response, e, parser);
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    int counter = retryCounter - 1;
                    if (counter <= 0) {
                        errorHandling(volleyError);
                        if (parser != null)
                            parser.onError(volleyError);
                    } else {
                        //try again without session id
                        Log.d(TAG, "Trying again without session ID. Retries left: " + String.valueOf(counter));
                        makeJsonGetResultRequest(parser, username, password, url, sessionUtil, false, counter,
                                queue);
                    }
                }
            }) {

        @Override
        // HTTP basic authentication
        // Taken from: http://blog.lemberg.co.uk/volley-part-1-quickstart
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = super.getHeaders();

            if (headers == null || headers.equals(Collections.emptyMap())) {
                headers = new HashMap<>();
            }

            if (usePreviousSession)
                sessionUtil.addSessionCookie(headers);
            return createBasicAuthHeader(username, password, headers);
        }

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            // since we don't know which of the two underlying network vehicles
            // will Volley use, we have to handle and store session cookies manually
            sessionUtil.checkSessionCookie(response.headers);
            return super.parseNetworkResponse(response);
        }
    };

    // Adding request to request queue
    addToRequestQueue(jsonObjReq, queue);
}

From source file:nl.hnogames.domoticzapi.Utils.RequestUtil.java

/**
 * Method to put a JSON object to a url//from  w w  w . j a  v a2 s  .  c  om
 */
public static void makeJsonPutRequest(@Nullable final JSONParserInterface parser, final String username,
        final String password, final String url, final SessionUtil sessionUtil,
        final boolean usePreviousSession, final int retryCounter, final RequestQueue queue) {

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.PUT, url, null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {

                    String jsonString;

                    try {
                        jsonString = response.getString(DomoticzValues.Json.Field.STATUS);
                        if (jsonString.equals(DomoticzValues.Json.Field.ERROR)) {
                            jsonErrorHandling(response, null, parser);
                        } else {
                            if (parser != null)
                                parser.parseResult(jsonString);
                        }
                    } catch (JSONException e) {

                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    int counter = retryCounter - 1;
                    if (counter <= 0) {
                        errorHandling(volleyError);
                        if (parser != null)
                            parser.onError(volleyError);
                    } else {
                        //try again without session id
                        Log.d(TAG, "Trying again without session ID. Retries left: " + String.valueOf(counter));
                        makeJsonPutRequest(parser, username, password, url, sessionUtil, false, counter, queue);
                    }
                }
            }) {

        @Override
        // HTTP basic authentication
        // Taken from: http://blog.lemberg.co.uk/volley-part-1-quickstart
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = super.getHeaders();

            if (headers == null || headers.equals(Collections.emptyMap())) {
                headers = new HashMap<>();
            }

            if (usePreviousSession)
                sessionUtil.addSessionCookie(headers);
            return createBasicAuthHeader(username, password, headers);
        }

        @Override
        protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
            // since we don't know which of the two underlying network vehicles
            // will Volley use, we have to handle and store session cookies manually
            sessionUtil.checkSessionCookie(response.headers);
            return super.parseNetworkResponse(response);
        }
    };

    // Adding request to request queue
    addToRequestQueue(jsonObjReq, queue);
}

From source file:org.apache.hadoop.tools.util.DistCpUtils.java

/**
 * Preserve attribute on file matching that of the file status being sent
 * as argument. Barring the block size, all the other attributes are preserved
 * by this function/*w  ww .  ja  va 2  s . c  o  m*/
 *
 * @param targetFS - File system
 * @param path - Path that needs to preserve original file status
 * @param srcFileStatus - Original file status
 * @param attributes - Attribute set that needs to be preserved
 * @param preserveRawXattrs if true, raw.* xattrs should be preserved
 * @throws IOException - Exception if any (particularly relating to group/owner
 *                       change or any transient error)
 */
public static void preserve(FileSystem targetFS, Path path, CopyListingFileStatus srcFileStatus,
        EnumSet<FileAttribute> attributes, boolean preserveRawXattrs) throws IOException {

    // If not preserving anything from FileStatus, don't bother fetching it.
    FileStatus targetFileStatus = attributes.isEmpty() ? null : targetFS.getFileStatus(path);
    String group = targetFileStatus == null ? null : targetFileStatus.getGroup();
    String user = targetFileStatus == null ? null : targetFileStatus.getOwner();
    boolean chown = false;

    if (attributes.contains(FileAttribute.ACL)) {
        List<AclEntry> srcAcl = srcFileStatus.getAclEntries();
        List<AclEntry> targetAcl = getAcl(targetFS, targetFileStatus);
        if (!srcAcl.equals(targetAcl)) {
            targetFS.setAcl(path, srcAcl);
        }
        // setAcl doesn't preserve sticky bit, so also call setPermission if needed.
        if (srcFileStatus.getPermission().getStickyBit() != targetFileStatus.getPermission().getStickyBit()) {
            targetFS.setPermission(path, srcFileStatus.getPermission());
        }
    } else if (attributes.contains(FileAttribute.PERMISSION)
            && !srcFileStatus.getPermission().equals(targetFileStatus.getPermission())) {
        targetFS.setPermission(path, srcFileStatus.getPermission());
    }

    final boolean preserveXAttrs = attributes.contains(FileAttribute.XATTR);
    if (preserveXAttrs || preserveRawXattrs) {
        Map<String, byte[]> srcXAttrs = srcFileStatus.getXAttrs();
        Map<String, byte[]> targetXAttrs = getXAttrs(targetFS, path);
        if (srcXAttrs != null && !srcXAttrs.equals(targetXAttrs)) {
            for (Entry<String, byte[]> entry : srcXAttrs.entrySet()) {
                String xattrName = entry.getKey();
                if (preserveXAttrs) {
                    targetFS.setXAttr(path, xattrName, entry.getValue());
                }
            }
        }
    }

    if (attributes.contains(FileAttribute.REPLICATION) && !targetFileStatus.isDirectory()
            && (srcFileStatus.getReplication() != targetFileStatus.getReplication())) {
        targetFS.setReplication(path, srcFileStatus.getReplication());
    }

    if (attributes.contains(FileAttribute.GROUP) && !group.equals(srcFileStatus.getGroup())) {
        group = srcFileStatus.getGroup();
        chown = true;
    }

    if (attributes.contains(FileAttribute.USER) && !user.equals(srcFileStatus.getOwner())) {
        user = srcFileStatus.getOwner();
        chown = true;
    }

    if (chown) {
        targetFS.setOwner(path, user, group);
    }

    if (attributes.contains(FileAttribute.TIMES)) {
        targetFS.setTimes(path, srcFileStatus.getModificationTime(), srcFileStatus.getAccessTime());
    }
}

From source file:io.seldon.api.resource.service.UserService.java

private static UserBean mergeInUpdate(UserBean previous, UserBean update) {
    boolean activeDifferent = previous.isActive() != update.isActive();
    boolean typeDifferent = previous.getType() != update.getType();
    boolean usernameDifferent = !previous.getUsername().equals(update.getUsername());

    Map<Integer, Integer> previousAttributes = previous.getAttributes();
    Map<Integer, Integer> updateAttributes = update.getAttributes();
    boolean attrsDifferent;
    if (previousAttributes == null) {
        attrsDifferent = updateAttributes != null;
    } else {/*  www .j  ava2 s  . c  o  m*/
        attrsDifferent = !previousAttributes.equals(updateAttributes);
    }
    boolean attrsNameDifferent;

    Map<String, String> previousAttributesName = previous.getAttributesName();
    Map<String, String> updateAttributesName = update.getAttributesName();
    if (previousAttributesName == null) {
        attrsNameDifferent = updateAttributesName != null;
    } else {
        attrsNameDifferent = !previousAttributesName.equals(updateAttributesName);
    }
    if (activeDifferent || typeDifferent || usernameDifferent || attrsDifferent || attrsNameDifferent) {
        previous.setActive(update.isActive());
        previous.setType(update.getType());
        previous.setUsername(update.getUsername());
        previous.setAttributes(updateAttributes);
        previous.setAttributesName(updateAttributesName);
        return previous;
    } else
        return null;
}

From source file:com.linkedin.pinot.tools.perf.PerfBenchmarkDriver.java

public static void waitForExternalViewUpdate(String zkAddress, final String clusterName,
        long timeoutInMilliseconds) {
    final ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkAddress);

    Verifier customVerifier = new Verifier() {

        @Override/*from  w  ww  .j a  v a  2 s .  c  o  m*/
        public boolean verify() {
            List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);
            LOGGER.info("Waiting for the cluster to be set up and indexes to be loaded on the servers"
                    + new Timestamp(System.currentTimeMillis()));
            for (String resourceName : resourcesInCluster) {
                IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
                ExternalView externalView = helixAdmin.getResourceExternalView(clusterName, resourceName);
                if (idealState == null || externalView == null) {
                    return false;
                }
                Set<String> partitionSet = idealState.getPartitionSet();
                for (String partition : partitionSet) {
                    Map<String, String> instanceStateMapIS = idealState.getInstanceStateMap(partition);
                    Map<String, String> instanceStateMapEV = externalView.getStateMap(partition);
                    if (instanceStateMapIS == null || instanceStateMapEV == null) {
                        return false;
                    }
                    if (!instanceStateMapIS.equals(instanceStateMapEV)) {
                        return false;
                    }
                }
            }
            LOGGER.info("Cluster is ready to serve queries");
            return true;
        }
    };

    ClusterStateVerifier.verifyByPolling(customVerifier, timeoutInMilliseconds);
}

From source file:org.onehippo.repository.documentworkflow.DocumentWorkflowTest.java

protected static void assertMatchingHints(Map<String, Serializable> hints, Map<String, Serializable> expected) {
    if (!hints.equals(expected)) {
        Assert.fail("Hints map does not match expected map.\n" + "Hint map: " + sortMap(hints) + "\n"
                + "expected: " + sortMap(expected));
    }/*  w w  w.ja v a2 s  . c  o  m*/
}

From source file:org.apache.ranger.plugin.client.HadoopConfigHolder.java

public static HadoopConfigHolder getInstance(String aDatasourceName, Map<String, String> connectionProperties,
        String defaultConfigFile) {
    HadoopConfigHolder ret = dataSource2HadoopConfigHolder.get(aDatasourceName);
    if (ret == null) {
        synchronized (HadoopConfigHolder.class) {
            HadoopConfigHolder temp = ret;
            if (temp == null) {
                ret = new HadoopConfigHolder(aDatasourceName, connectionProperties, defaultConfigFile);
                dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
            }/*from   w  ww .  j  a  v a2 s  .c  o  m*/
        }
    } else {
        if (connectionProperties != null && !connectionProperties.equals(ret.connectionProperties)) {
            ret = new HadoopConfigHolder(aDatasourceName, connectionProperties);
            dataSource2HadoopConfigHolder.remove(aDatasourceName);
            dataSource2HadoopConfigHolder.put(aDatasourceName, ret);
        }
    }

    return ret;
}

From source file:org.apache.axis2.context.externalize.ActivateUtils.java

/**
 * Compares the two collections to see if they are equivalent.
 * //from  w w  w .  j av  a2s  .com
 * @param m1  The first collection
 * @param m2  The second collection
 * @param strict  Indicates whether strict checking is required.  Strict
 *                checking means that the two collections must have the
 *                same mappings.  Non-strict checking means that the 
 *                two collections must have the same keys.  In both
 *                cases, the order is not significant.
 * @return TRUE if the two collections are equivalent
 *         FALSE, otherwise
 */
public static boolean isEquivalent(Map m1, Map m2, boolean strict) {
    if ((m1 != null) && (m2 != null)) {
        if (strict) {
            // This is a strict test.
            // Returns true if the given object is also a map and the two Maps 
            // represent the same mappings. 
            return (m1.equals(m2));
        } else {
            int size1 = m1.size();
            int size2 = m2.size();

            if (size1 != size2) {
                return false;
            }

            // check the keys, ordering is not important between the two maps
            Iterator it1 = m1.keySet().iterator();

            while (it1.hasNext()) {
                Object key1 = it1.next();

                if (m2.containsKey(key1) == false) {
                    return false;
                }
            }

            return true;
        }
    } else if ((m1 == null) && (m2 == null)) {
        return true;
    } else {
        // mismatch
        return false;
    }
}

From source file:com.cgrunge.ParameterValidator.java

public boolean isMapEmpty(Map<Object, Object> obj) {
    return obj.equals(Collections.<Object, Object>emptyMap());
}

From source file:com.hx.template.http.volley.BaseJsonObjectRequest.java

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String, String> headers = super.getHeaders();
    if (null == headers || headers.equals(Collections.emptyMap())) {
        headers = new HashMap<String, String>();
    }/* w ww  .  ja v  a2s  .  c  om*/
    if (additionalHeaders != null) {
        headers.putAll(additionalHeaders);
    }
    return headers;
}