Skip to content

Commit

Permalink
Cleanup unused code in org.opensearch.common
Browse files Browse the repository at this point in the history
Signed-off-by: Rabi Panda <adnapibar@gmail.com>
  • Loading branch information
adnapibar committed Nov 17, 2022
1 parent 9d4aac2 commit a816b2b
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 256 deletions.
19 changes: 0 additions & 19 deletions server/src/main/java/org/opensearch/common/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@
*/
public class Classes {

/**
* The package separator character '.'
*/
private static final char PACKAGE_SEPARATOR = '.';

/**
* Determine the name of the package of the given class:
* e.g. "java.lang" for the <code>java.lang.String</code> class.
*
* @param clazz the class
* @return the package name, or the empty String if the class
* is defined in the default package
*/
public static String getPackageName(Class<?> clazz) {
String className = clazz.getName();
int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
return (lastDotIndex != -1 ? className.substring(0, lastDotIndex) : "");
}

public static boolean isInnerClass(Class<?> clazz) {
return !Modifier.isStatic(clazz.getModifiers()) && clazz.getEnclosingClass() != null;
}
Expand Down

This file was deleted.

32 changes: 0 additions & 32 deletions server/src/main/java/org/opensearch/common/Numbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,6 @@ public static long bytesToLong(BytesRef bytes) {
return (((long) high) << 32) | (low & 0x0ffffffffL);
}

public static byte[] intToBytes(int val) {
byte[] arr = new byte[4];
arr[0] = (byte) (val >>> 24);
arr[1] = (byte) (val >>> 16);
arr[2] = (byte) (val >>> 8);
arr[3] = (byte) (val);
return arr;
}

/**
* Converts an int to a byte array.
*
* @param val The int to convert to a byte array
* @return The byte array converted
*/
public static byte[] shortToBytes(int val) {
byte[] arr = new byte[2];
arr[0] = (byte) (val >>> 8);
arr[1] = (byte) (val);
return arr;
}

/**
* Converts a long to a byte array.
*
Expand All @@ -98,16 +76,6 @@ public static byte[] longToBytes(long val) {
return arr;
}

/**
* Converts a double to a byte array.
*
* @param val The double to convert to a byte array
* @return The byte array converted
*/
public static byte[] doubleToBytes(double val) {
return longToBytes(Double.doubleToRawLongBits(val));
}

/** Returns true if value is neither NaN nor infinite. */
public static boolean isValidDouble(double value) {
if (Double.isNaN(value) || Double.isInfinite(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@

package org.opensearch.common;

import org.opensearch.common.settings.SecureString;

import java.util.Arrays;
import java.util.Base64;
import java.util.Random;

Expand All @@ -54,27 +51,6 @@ public String getBase64UUID() {
return getBase64UUID(SecureRandomHolder.INSTANCE);
}

/**
* Returns a Base64 encoded {@link SecureString} of a Version 4.0 compatible UUID
* as defined here: http://www.ietf.org/rfc/rfc4122.txt
*/
public SecureString getBase64UUIDSecureString() {
byte[] uuidBytes = null;
byte[] encodedBytes = null;
try {
uuidBytes = getUUIDBytes(SecureRandomHolder.INSTANCE);
encodedBytes = Base64.getUrlEncoder().withoutPadding().encode(uuidBytes);
return new SecureString(CharArrays.utf8BytesToChars(encodedBytes));
} finally {
if (uuidBytes != null) {
Arrays.fill(uuidBytes, (byte) 0);
}
if (encodedBytes != null) {
Arrays.fill(encodedBytes, (byte) 0);
}
}
}

/**
* Returns a Base64 encoded version of a Version 4.0 compatible UUID
* randomly initialized by the given {@link java.util.Random} instance
Expand Down
67 changes: 1 addition & 66 deletions server/src/main/java/org/opensearch/common/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,67 +80,6 @@ public static void spaceify(int spaces, String from, StringBuilder to) throws Ex
}
}

/**
* Splits a backslash escaped string on the separator.
* <p>
* Current backslash escaping supported:
* <br> \n \t \r \b \f are escaped the same as a Java String
* <br> Other characters following a backslash are produced verbatim (\c =&gt; c)
*
* @param s the string to split
* @param separator the separator to split on
* @param decode decode backslash escaping
*/
public static List<String> splitSmart(String s, String separator, boolean decode) {
ArrayList<String> lst = new ArrayList<>(2);
StringBuilder sb = new StringBuilder();
int pos = 0, end = s.length();
while (pos < end) {
if (s.startsWith(separator, pos)) {
if (sb.length() > 0) {
lst.add(sb.toString());
sb = new StringBuilder();
}
pos += separator.length();
continue;
}

char ch = s.charAt(pos++);
if (ch == '\\') {
if (!decode) sb.append(ch);
if (pos >= end) break; // ERROR, or let it go?
ch = s.charAt(pos++);
if (decode) {
switch (ch) {
case 'n':
ch = '\n';
break;
case 't':
ch = '\t';
break;
case 'r':
ch = '\r';
break;
case 'b':
ch = '\b';
break;
case 'f':
ch = '\f';
break;
}
}
}

sb.append(ch);
}

if (sb.length() > 0) {
lst.add(sb.toString());
}

return lst;
}

// ---------------------------------------------------------------------
// General convenience methods for working with Strings
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -303,7 +242,7 @@ public static String replace(String inString, String oldPattern, String newPatte
// the index of an occurrence we've found, or -1
int patLen = oldPattern.length();
while (index >= 0) {
sb.append(inString.substring(pos, index));
sb.append(inString, pos, index);
sb.append(newPattern);
pos = index + patLen;
index = inString.indexOf(oldPattern, pos);
Expand Down Expand Up @@ -875,10 +814,6 @@ public static boolean isNullOrEmpty(@Nullable String s) {
return s == null || s.isEmpty();
}

public static String coalesceToEmpty(@Nullable String s) {
return s == null ? "" : s;
}

public static String padStart(String s, int minimumLength, char c) {
if (s == null) {
throw new NullPointerException("s");
Expand Down
13 changes: 0 additions & 13 deletions server/src/main/java/org/opensearch/common/UUIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.opensearch.common;

import org.opensearch.common.settings.SecureString;

import java.util.Random;

/**
Expand All @@ -44,7 +42,6 @@
public class UUIDs {

private static final RandomBasedUUIDGenerator RANDOM_UUID_GENERATOR = new RandomBasedUUIDGenerator();
private static final UUIDGenerator LEGACY_TIME_UUID_GENERATOR = new LegacyTimeBasedUUIDGenerator();
private static final UUIDGenerator TIME_UUID_GENERATOR = new TimeBasedUUIDGenerator();

/** Generates a time-based UUID (similar to Flake IDs), which is preferred when generating an ID to be indexed into a Lucene index as
Expand All @@ -53,11 +50,6 @@ public static String base64UUID() {
return TIME_UUID_GENERATOR.getBase64UUID();
}

/** Legacy implementation of {@link #base64UUID()}, for pre 6.0 indices. */
public static String legacyBase64UUID() {
return LEGACY_TIME_UUID_GENERATOR.getBase64UUID();
}

/** Returns a Base64 encoded version of a Version 4.0 compatible UUID as defined here: http://www.ietf.org/rfc/rfc4122.txt, using the
* provided {@code Random} instance */
public static String randomBase64UUID(Random random) {
Expand All @@ -70,9 +62,4 @@ public static String randomBase64UUID() {
return RANDOM_UUID_GENERATOR.getBase64UUID();
}

/** Returns a Base64 encoded {@link SecureString} of a Version 4.0 compatible UUID as defined here: http://www.ietf.org/rfc/rfc4122.txt,
* using a private {@code SecureRandom} instance */
public static SecureString randomBase64UUIDSecureString() {
return RANDOM_UUID_GENERATOR.getBase64UUIDSecureString();
}
}

0 comments on commit a816b2b

Please sign in to comment.