diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java deleted file mode 100644 index 9181f4f0c0bbd..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/ProtocolUtils.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java deleted file mode 100644 index c3f26be56075e..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/TimeUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.client.common; - -import org.elasticsearch.common.time.DateFormatters; -import org.elasticsearch.common.xcontent.XContentParser; - -import java.io.IOException; -import java.time.Instant; -import java.time.format.DateTimeFormatter; -import java.util.Date; - -public final class TimeUtil { - - /** - * Parse out a Date object given the current parser and field name. - * - * @param parser current XContentParser - * @param fieldName the field's preferred name (utilized in exception) - * @return parsed Date object - * @throws IOException from XContentParser - */ - public static Date parseTimeField(XContentParser parser, String fieldName) throws IOException { - if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return new Date(parser.longValue()); - } else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) { - return new Date(DateFormatters.from(DateTimeFormatter.ISO_INSTANT.parse(parser.text())).toInstant().toEpochMilli()); - } - throw new IllegalArgumentException( - "unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]"); - } - - /** - * Parse out an Instant object given the current parser and field name. - * - * @param parser current XContentParser - * @param fieldName the field's preferred name (utilized in exception) - * @return parsed Instant object - * @throws IOException from XContentParser - */ - public static Instant parseTimeFieldToInstant(XContentParser parser, String fieldName) throws IOException { - if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) { - return Instant.ofEpochMilli(parser.longValue()); - } else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) { - return DateFormatters.from(DateTimeFormatter.ISO_INSTANT.parse(parser.text())).toInstant(); - } - throw new IllegalArgumentException( - "unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]"); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java deleted file mode 100644 index 689f82f18b9a6..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.common; - -import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentUtils; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -/** - * Encapsulates the xcontent source - */ -public class XContentSource { - - private final Object data; - - /** - * Constructs a new XContentSource out of the given parser - */ - public XContentSource(XContentParser parser) throws IOException { - this.data = XContentUtils.readValue(parser, parser.nextToken()); - } - - /** - * @return true if the top level value of the source is a map - */ - public boolean isMap() { - return data instanceof Map; - } - - /** - * @return The source as a map - */ - @SuppressWarnings("unchecked") - public Map getAsMap() { - return (Map) data; - } - - /** - * @return true if the top level value of the source is a list - */ - public boolean isList() { - return data instanceof List; - } - - /** - * @return The source as a list - */ - @SuppressWarnings("unchecked") - public List getAsList() { - return (List) data; - } - - /** - * Extracts a value identified by the given path in the source. - * - * @param path a dot notation path to the requested value - * @return The extracted value or {@code null} if no value is associated with the given path - */ - @SuppressWarnings("unchecked") - public T getValue(String path) { - return (T) ObjectPath.eval(path, data); - } - -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/common/ProtocolUtilsTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/common/ProtocolUtilsTests.java deleted file mode 100644 index 8402367390263..0000000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/common/ProtocolUtilsTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.common; - -import org.elasticsearch.test.ESTestCase; - -import java.util.HashMap; -import java.util.Map; - -public class ProtocolUtilsTests extends ESTestCase { - - public void testMapStringEqualsAndHash() { - assertTrue(ProtocolUtils.equals(null, null)); - assertFalse(ProtocolUtils.equals(null, new HashMap<>())); - assertFalse(ProtocolUtils.equals(new HashMap<>(), null)); - - Map a = new HashMap<>(); - a.put("foo", new String[] { "a", "b" }); - a.put("bar", new String[] { "b", "c" }); - - Map b = new HashMap<>(); - b.put("foo", new String[] { "a", "b" }); - - assertFalse(ProtocolUtils.equals(a, b)); - assertFalse(ProtocolUtils.equals(b, a)); - - b.put("bar", new String[] { "c", "b" }); - - assertFalse(ProtocolUtils.equals(a, b)); - assertFalse(ProtocolUtils.equals(b, a)); - - b.put("bar", new String[] { "b", "c" }); - - assertTrue(ProtocolUtils.equals(a, b)); - assertTrue(ProtocolUtils.equals(b, a)); - assertEquals(ProtocolUtils.hashCode(a), ProtocolUtils.hashCode(b)); - - b.put("baz", new String[] { "b", "c" }); - - assertFalse(ProtocolUtils.equals(a, b)); - assertFalse(ProtocolUtils.equals(b, a)); - - a.put("non", null); - - assertFalse(ProtocolUtils.equals(a, b)); - assertFalse(ProtocolUtils.equals(b, a)); - - b.put("non", null); - b.remove("baz"); - - assertTrue(ProtocolUtils.equals(a, b)); - assertTrue(ProtocolUtils.equals(b, a)); - assertEquals(ProtocolUtils.hashCode(a), ProtocolUtils.hashCode(b)); - } -}