org.elasticsearch.client.common.ProtocolUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-rest-high-level-client Show documentation
Show all versions of elasticsearch-rest-high-level-client Show documentation
Elasticsearch subproject :client:rest-high-level
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.client.common;
import java.util.Arrays;
import java.util.Map;
/**
* Common utilities used for XPack protocol classes
*/
public final class ProtocolUtils {
/**
* Implements equals for a map of string arrays
*
* The map of string arrays is used in some XPack protocol classes but does't work with equal.
*/
public static boolean equals(Map a, Map b) {
if (a == null) {
return b == null;
}
if (b == null) {
return false;
}
if (a.size() != b.size()) {
return false;
}
for (Map.Entry entry : a.entrySet()) {
String[] val = entry.getValue();
String key = entry.getKey();
if (val == null) {
if (b.get(key) != null || b.containsKey(key) == false) {
return false;
}
} else {
if (Arrays.equals(val, b.get(key)) == false) {
return false;
}
}
}
return true;
}
/**
* Implements hashCode for map of string arrays
*
* The map of string arrays does't work with hashCode.
*/
public static int hashCode(Map a) {
int hash = 0;
for (Map.Entry entry : a.entrySet())
hash += Arrays.hashCode(entry.getValue());
return hash;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy