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:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//from w  w w . ja  v  a2s. c  o m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    Map<Object, Object> objMap1 = new IdentityHashMap<Object, Object>();

    System.out.println(objMap1.equals(objMap));
}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Map<String, String> map2 = new HashMap<String, String>();
    map2.put("key2", "value2");
    map2.put("key1", "value1");
    map2.put("key3", "value3");
    System.out.println(map2.equals(map2));
}

From source file:AttributedStringUtilities.java

/**
 * Tests two attributed strings for equality.
 * //w  w w . ja  v a  2 s  .  co m
 * @param s1
 *          string 1 (<code>null</code> permitted).
 * @param s2
 *          string 2 (<code>null</code> permitted).
 * 
 * @return <code>true</code> if <code>s1</code> and <code>s2</code> are
 *         equal or both <code>null</code>, and <code>false</code>
 *         otherwise.
 */
public static boolean equal(AttributedString s1, AttributedString s2) {
    if (s1 == null) {
        return (s2 == null);
    }
    if (s2 == null) {
        return false;
    }
    AttributedCharacterIterator it1 = s1.getIterator();
    AttributedCharacterIterator it2 = s2.getIterator();
    char c1 = it1.first();
    char c2 = it2.first();
    int start = 0;
    while (c1 != CharacterIterator.DONE) {
        int limit1 = it1.getRunLimit();
        int limit2 = it2.getRunLimit();
        if (limit1 != limit2) {
            return false;
        }
        // if maps aren't equivalent, return false
        Map m1 = it1.getAttributes();
        Map m2 = it2.getAttributes();
        if (!m1.equals(m2)) {
            return false;
        }
        // now check characters in the run are the same
        for (int i = start; i < limit1; i++) {
            if (c1 != c2) {
                return false;
            }
            c1 = it1.next();
            c2 = it2.next();
        }
        start = limit1;
    }
    return c2 == CharacterIterator.DONE;
}

From source file:edu.cornell.mannlib.vitro.webapp.freemarker.config.FreemarkerConfiguration.java

private static boolean haveDeveloperSettingsChanged() {
    Map<String, Object> settingsMap = DeveloperSettings.getInstance().getRawSettingsMap();
    if (settingsMap.equals(previousSettingsMap)) {
        return false;
    } else {// w  w  w.  j  av a2  s  .  c om
        previousSettingsMap = settingsMap;
        return true;
    }
}

From source file:org.apache.falcon.entity.ClusterHelper.java

public static boolean matchProperties(final Cluster oldEntity, final Cluster newEntity) {
    Map<String, String> oldProps = getClusterProperties(oldEntity);
    Map<String, String> newProps = getClusterProperties(newEntity);
    return oldProps.equals(newProps);
}

From source file:com.ebay.myriad.scheduler.SchedulerUtils.java

public static boolean isMatchSlaveAttributes(Offer offer, Map<String, String> requestAttributes) {
    boolean match = true;

    Map<String, String> offerAttributes = new HashMap<String, String>();
    for (Attribute attribute : offer.getAttributesList()) {
        offerAttributes.put(attribute.getName(), attribute.getText().getValue());
    }/*from   w  ww.  j av a 2s.co m*/

    // Match with offer attributes only if request has attributes.
    if (!MapUtils.isEmpty(requestAttributes)) {
        match = offerAttributes.equals(requestAttributes);
    }

    LOGGER.info("Match status: {} for offer: {} and requestAttributes: {}", match, offer, requestAttributes);

    return match;
}

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

public static void makeJsonGetRequest(@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/* ww w  .  j  a va 2s  .  co  m*/
                public void onResponse(JSONObject response) {
                    if (parser != null)
                        parser.parseResult(response.toString());
                }
            }, 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));
                        makeJsonGetRequest(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

public static ImageLoader getImageLoader(final Domoticz domoticz, final SessionUtil sessionUtil,
        Context context) {// w  ww. java2 s  .com
    if (domoticz == null)
        return null;

    ImageLoader.ImageCache imageCache = new BitmapLruCache();
    return new ImageLoader(Volley.newRequestQueue(context), imageCache) {
        @SuppressWarnings("deprecation")
        @Override
        protected com.android.volley.Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth,
                int maxHeight, ImageView.ScaleType scaleType, final String cacheKey) {
            return new ImageRequest(requestUrl, new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    onGetImageSuccess(cacheKey, response);
                }
            }, maxWidth, maxHeight, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    onGetImageError(cacheKey, error);
                }
            }) {

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    Map<String, String> headers = super.getHeaders();

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

                    String credentials = domoticz.getUserCredentials(Domoticz.Authentication.USERNAME) + ":"
                            + domoticz.getUserCredentials(Domoticz.Authentication.PASSWORD);
                    String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(),
                            Base64.NO_WRAP);

                    headers.put("Authorization", "Basic " + base64EncodedCredentials);
                    headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                    headers.put("Accept-Language", "en-US,en;q=0.7,nl;q=0.3");
                    headers.put("Accept-Encoding", "gzip, deflate");

                    sessionUtil.addSessionCookie(headers);
                    return headers;
                }
            };
        }
    };
}

From source file:org.wso2.cdm.agent.utils.HTTPConnectorUtils.java

public static Map<String, String> postData(Context context, String url, Map<String, String> params) {
    Map<String, String> response = null;
    Map<String, String> responseFinal = null;
    for (int i = 1; i <= MAX_ATTEMPTS; i++) {
        Log.d(TAG, "Attempt #" + i + " to register " + url);
        try {/* ww w.  ja  v  a2  s .c om*/

            response = postToServer(context, url, params);
            if (response != null && !response.equals(null)) {
                responseFinal = response;
            }
            Log.d("Success", "Check Reg Success");

            return responseFinal;
        } catch (Exception e) {
            Log.e(TAG, "Failed to register on attempt " + i, e);
            if (i == MAX_ATTEMPTS) {
                break;
            }

            return responseFinal;
        }
    }

    return responseFinal;
}

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

public static void makeJsonVersionRequest(@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/* w  w w.  ja  v  a2 s  .  c o  m*/
                public void onResponse(JSONObject response) {

                    String jsonString;

                    try {
                        jsonString = response.getString(DomoticzValues.Json.Field.VERSION);
                        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);
                        Log.d(TAG, "No retries left");
                        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));
                        makeJsonVersionRequest(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) {
            sessionUtil.checkSessionCookie(response.headers); //save cookie
            return super.parseNetworkResponse(response);
        }
    };

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