Skip to content

Commit

Permalink
Cleanup dead code in org.elasticsearch.common (#87820)
Browse files Browse the repository at this point in the history
Just some obvious static cleanup of this package. Should be trivial
to review since it's deletes only and still compiles/tests fine.
  • Loading branch information
original-brownbear committed Jun 19, 2022
1 parent 0db8965 commit faae31c
Show file tree
Hide file tree
Showing 45 changed files with 3 additions and 504 deletions.
19 changes: 0 additions & 19 deletions server/src/main/java/org/elasticsearch/common/Classes.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,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()) == false && clazz.getEnclosingClass() != null;
}
Expand Down
13 changes: 0 additions & 13 deletions server/src/main/java/org/elasticsearch/common/StopWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.elasticsearch.common;

import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.TimeValue;

import java.text.NumberFormat;
Expand Down Expand Up @@ -131,18 +130,6 @@ public StopWatch stop() throws IllegalStateException {
return this;
}

public Releasable timing(String taskName) {
start(taskName);
return this::stop;
}

/**
* Return whether the stop watch is currently running.
*/
public boolean isRunning() {
return this.running;
}

/**
* Return the time taken by the last task.
*/
Expand Down
22 changes: 0 additions & 22 deletions server/src/main/java/org/elasticsearch/common/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ public static String replace(String inString, String oldPattern, String newPatte
return sb.toString();
}

/**
* Delete all occurrences of the given substring.
*
* @param inString the original String
* @param pattern the pattern to delete all occurrences of
* @return the resulting String
*/
public static String delete(String inString, String pattern) {
return replace(inString, pattern, "");
}

/**
* Delete any character in a given String.
*
Expand All @@ -316,17 +305,6 @@ public static String deleteAny(String inString, String charsToDelete) {
// Convenience methods for working with formatted Strings
// ---------------------------------------------------------------------

/**
* Quote the given String with single quotes.
*
* @param str the input String (e.g. "myString")
* @return the quoted String (e.g. "'myString'"),
* or <code>null</code> if the input was <code>null</code>
*/
public static String quote(String str) {
return (str != null ? "'" + str + "'" : null);
}

/**
* Capitalize a <code>String</code>, changing the first letter to
* upper case as per {@link Character#toUpperCase(char)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,6 @@ public void putAll(Builder<KType, VType> builder) {
}
}

/**
* Remove that can be used in the fluent pattern.
*/
public Builder<KType, VType> fRemove(KType key) {
maybeCloneMap();
mutableMap.remove(key);
return this;
}

public VType remove(KType key) {
maybeCloneMap();
return mutableMap.remove(key);
Expand Down Expand Up @@ -509,11 +500,6 @@ public Set<KType> keys() {
return new KeySet<>(mutableMap.keys());
}

@SuppressWarnings("unchecked")
public <K, V> Builder<K, V> cast() {
return (Builder) this;
}

public int removeAll(BiPredicate<? super KType, ? super VType> predicate) {
maybeCloneMap();
return mutableMap.removeAll(predicate::test);
Expand All @@ -524,11 +510,6 @@ public int indexOf(KType key) {
return mutableMap.indexOf(key);
}

public boolean indexExists(int index) {
maybeCloneMap();
return mutableMap.indexExists(index);
}

public void release() {
maybeCloneMap();
mutableMap.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,6 @@ public MapBuilder<K, V> remove(K key) {
return this;
}

public MapBuilder<K, V> clear() {
this.map.clear();
return this;
}

public V get(K key) {
return map.get(key);
}

public boolean containsKey(K key) {
return map.containsKey(key);
}

public boolean isEmpty() {
return map.isEmpty();
}

public Map<K, V> map() {
return this.map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public void addLifecycleListener(LifecycleListener listener) {
listeners.add(listener);
}

@Override
public void removeLifecycleListener(LifecycleListener listener) {
listeners.remove(listener);
}

@Override
public void start() {
synchronized (lifecycle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface LifecycleComponent extends Releasable {

void addLifecycleListener(LifecycleListener listener);

void removeLifecycleListener(LifecycleListener listener);

void start();

void stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public interface Compressor {

boolean isCompressed(BytesReference bytes);

int headerLength();

/**
* Creates a new input stream that decompresses the contents read from the provided input stream.
* Closing the returned {@link InputStream} will close the provided stream input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ public boolean isCompressed(BytesReference bytes) {
return true;
}

@Override
public int headerLength() {
return HEADER.length;
}

// Reusable inflater reference for streaming decompression
private static final ThreadLocal<ReleasableReference<Inflater>> inflaterForStreamRef = ThreadLocal.withInitial(() -> {
final Inflater inflater = new Inflater(true);
Expand Down
17 changes: 0 additions & 17 deletions server/src/main/java/org/elasticsearch/common/geo/GeoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ public class GeoUtils {
/** Minimum valid longitude in degrees. */
public static final double MIN_LON = -180.0;

public static final String LATITUDE = "lat";
public static final String LONGITUDE = "lon";
public static final String GEOHASH = "geohash";
public static final String COORDINATES = "coordinates";
public static final String TYPE = "type";

/** Earth ellipsoid major axis defined by WGS 84 in meters */
public static final double EARTH_SEMI_MAJOR_AXIS = 6378137.0; // meters (WGS 84)

Expand All @@ -52,9 +46,6 @@ public class GeoUtils {
/** Earth mean radius defined by WGS 84 in meters */
public static final double EARTH_MEAN_RADIUS = 6371008.7714D; // meters (WGS 84)

/** Earth axis ratio defined by WGS 84 (0.996647189335) */
public static final double EARTH_AXIS_RATIO = EARTH_SEMI_MINOR_AXIS / EARTH_SEMI_MAJOR_AXIS;

/** Earth ellipsoid equator length in meters */
public static final double EARTH_EQUATOR = 2 * Math.PI * EARTH_SEMI_MAJOR_AXIS;

Expand Down Expand Up @@ -508,14 +499,6 @@ public static int checkPrecisionRange(int precision) {
return precision;
}

/** Returns the maximum distance/radius (in meters) from the point 'center' before overlapping */
public static double maxRadialDistanceMeters(final double centerLat, final double centerLon) {
if (Math.abs(centerLat) == MAX_LAT) {
return SloppyMath.haversinMeters(centerLat, centerLon, 0, centerLon);
}
return SloppyMath.haversinMeters(centerLat, centerLon, centerLat, (MAX_LON + centerLon) % 360);
}

/** Return the distance (in meters) between 2 lat,lon geo points using the haversine method implemented by lucene */
public static double arcDistance(double lat1, double lon1, double lat2, double lon2) {
return SloppyMath.haversinMeters(lat1, lon1, lat2, lon2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ static class IntermediateResult {
private static long C1 = 0x87c37b91114253d5L;
private static long C2 = 0x4cf5ad432745937fL;

protected static long getblock(byte[] key, int offset, int index) {
int i_8 = index << 3;
int blockOffset = offset + i_8;
return ByteUtils.readLongLE(key, blockOffset);
}

protected static long fmix(long k) {
k ^= k >>> 33;
k *= 0xff51afd7ed558ccdL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ public interface Binder {
*/
void addError(String message, Object... arguments);

/**
* Records an exception, the full details of which will be logged, and the
* message of which will be presented to the user at a later
* time. If your Module calls something that you worry may fail, you should
* catch the exception and pass it into this.
*/
void addError(Throwable t);

/**
* Records an error message to be presented to the user at a later time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.elasticsearch.common.inject.internal.Errors;
import org.elasticsearch.common.inject.spi.Element;
import org.elasticsearch.common.inject.spi.ProviderLookup;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -45,11 +44,4 @@ public void initialize(Errors errors) {
new LookupProcessor(errors).process(injector, lookups);
}

@Override
public <T> Provider<T> getProvider(Key<T> key) {
ProviderLookup<T> lookup = new ProviderLookup<>(key, key);
lookups.add(lookup);
return lookup.getProvider();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public interface Injector {
*/
<T> Provider<T> getProvider(Key<T> key);

/**
* Returns the provider used to obtain instances for the given type. When feasible, avoid
* using this method, in favor of having Guice inject your dependencies ahead of time.
*
* @throws ConfigurationException if this injector cannot find or create the provider.
*/
<T> Provider<T> getProvider(Class<T> type);

/**
* Returns the appropriate instance for the given injection key; equivalent to {@code
* getProvider(key).get()}. When feasible, avoid using this method, in favor of having Guice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ interface MethodInvoker {
*/
MembersInjectorStore membersInjectorStore;

@Override
public <T> Provider<T> getProvider(Class<T> type) {
private <T> Provider<T> getProvider(Class<T> type) {
return getProvider(Key.get(type));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@
*/
interface Lookups {

<T> Provider<T> getProvider(Key<T> key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public void addError(String message, Object... arguments) {
elements.add(new Message(getSource(), Errors.format(message, arguments)));
}

@Override
public void addError(Throwable t) {
private void addError(Throwable t) {
String message = "An exception was caught and reported. Message: " + t.getMessage();
elements.add(new Message(Collections.singletonList(getSource()), message, t));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

/**
* An error message and the context in which it occurred. Messages are usually created internally by
* Guice and its extensions. Messages can be created explicitly in a module using {@link
* org.elasticsearch.common.inject.Binder#addError(Throwable) addError()} statements:
* Guice and its extensions.
* <pre>
* try {
* bindPropertiesFromFile();
Expand Down
16 changes: 0 additions & 16 deletions server/src/main/java/org/elasticsearch/common/io/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,6 @@ public static String copyToString(Reader in) throws IOException {
return out.toString();
}

public static int readFully(Reader reader, char[] dest) throws IOException {
return readFully(reader, dest, 0, dest.length);
}

public static int readFully(Reader reader, char[] dest, int offset, int len) throws IOException {
int read = 0;
while (read < len) {
final int r = reader.read(dest, offset + read, len - read);
if (r == -1) {
break;
}
read += r;
}
return read;
}

public static int readFully(InputStream reader, byte[] dest) throws IOException {
return readFully(reader, dest, 0, dest.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,6 @@ public void write(String str, int off, int len) throws IOException {
}
}

/**
* Writes the specified character sequence.
*
* @param csq the character sequence.
* @throws IOException if an I/O error occurs
*/
public void write(CharSequence csq) throws IOException {
final int length = csq.length();
for (int i = 0; i < length;) {
char c = csq.charAt(i++);
if (c < 0x80) {
_bytes[_index] = (byte) c;
if (++_index >= _bytes.length) {
flushBuffer();
}
} else {
write(c);
}
}
}

/**
* Flushes the stream. If the stream has saved any characters from the
* various write() methods in a buffer, write them immediately to their
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public void reset(byte[] bytes, int offset, int len) {
limit = offset + len;
}

public int length() {
return limit;
}

public void skipBytes(long count) {
pos += count;
}
Expand Down

0 comments on commit faae31c

Please sign in to comment.