Skip to content

Commit

Permalink
Delete all unused private methods (elastic#98111)
Browse files Browse the repository at this point in the history
Pretty straight forward dead-code cleanup I think. Just delete all
private methods or methods in private classes that aren't used.
  • Loading branch information
original-brownbear authored Nov 25, 2023
1 parent fdf51ac commit 1b84ea7
Show file tree
Hide file tree
Showing 51 changed files with 0 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,12 @@ private static void assertLinesInFile(Path path, List<String> expectedLines) {
}
}

private static boolean toolExists(Project project) {
if (project.getName().contains("tar")) {
return tarExists();
} else {
assert project.getName().contains("zip");
return zipExists();
}
}

private static void assertNoClassFile(File file) {
if (file.getName().endsWith(".class")) {
throw new GradleException("Detected class file in distribution ('" + file.getName() + "')");
}
}

private static boolean zipExists() {
return new File("/bin/unzip").exists() || new File("/usr/bin/unzip").exists() || new File("/usr/local/bin/unzip").exists();
}

private static boolean tarExists() {
return new File("/bin/tar").exists() || new File("/usr/bin/tar").exists() || new File("/usr/local/bin/tar").exists();
}

private Object distTaskOutput(TaskProvider<Task> buildDistTask) {
return new Callable<File>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ private void logForbiddenAPIsOutput(String forbiddenApisOutput) {
getLogger().error("Forbidden APIs output:\n{}==end of forbidden APIs==", forbiddenApisOutput);
}

private void throwNotConfiguredCorrectlyException() {
throw new IllegalArgumentException("Audit of third party dependencies is not configured correctly");
}

/**
* Ideally we would do unpacking already via artifact transform and keep unpacked jars across builds.
* At the moment transform target folder is not configurable and forbidden CLI only takes one common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -1591,15 +1590,6 @@ public void testGetSemanticVersion() {
assertThat(InstallPluginAction.getSemanticVersion("foo-1.2.3"), nullValue());
}

private Map<String, Map<String, String>> namedComponentsMap() {
Map<String, Map<String, String>> result = new LinkedHashMap<>();
Map<String, String> extensibles = new LinkedHashMap<>();
extensibles.put("a_component", "p.A");
extensibles.put("b_component", "p.B");
result.put("org.elasticsearch.plugins.cli.test_model.ExtensibleInterface", extensibles);
return result;
}

private static String namedComponentsJSON() {
return """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ public void testRemoveMultiple() throws Exception {
assertRemoveCleaned(env);
}

private static Version minimumCompatibleVersion(Version v) {
return Version.fromString((v.major - 1) + ".0.0");
}

public void testBin() throws Exception {
createPlugin("fake");
Path binDir = env.binFile().resolve("fake");
Expand Down
76 changes: 0 additions & 76 deletions libs/lz4/src/test/java/org/elasticsearch/lz4/ESLZ4Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1898,80 +1898,4 @@ public void testRoundtripIssue12() {
testRoundTrip(data, 9, data.length - 9);
}

private static void assertCompressedArrayEquals(String message, byte[] expected, byte[] actual) {
int off = 0;
int decompressedOff = 0;
while (true) {
if (off == expected.length) {
break;
}
final Sequence sequence1 = readSequence(expected, off);
final Sequence sequence2 = readSequence(actual, off);
assertEquals(message + ", off=" + off + ", decompressedOff=" + decompressedOff, sequence1, sequence2);
off += sequence1.length;
decompressedOff += sequence1.literalLen + sequence1.matchLen;
}
}

private static Sequence readSequence(byte[] buf, int off) {
final int start = off;
final int token = buf[off++] & 0xFF;
int literalLen = token >>> 4;
if (literalLen >= 0x0F) {
int len;
while ((len = buf[off++] & 0xFF) == 0xFF) {
literalLen += 0xFF;
}
literalLen += len;
}
off += literalLen;
if (off == buf.length) {
return new Sequence(literalLen, -1, -1, off - start);
}
int matchDec = (buf[off++] & 0xFF) | ((buf[off++] & 0xFF) << 8);
int matchLen = token & 0x0F;
if (matchLen >= 0x0F) {
int len;
while ((len = buf[off++] & 0xFF) == 0xFF) {
matchLen += 0xFF;
}
matchLen += len;
}
matchLen += 4;
return new Sequence(literalLen, matchDec, matchLen, off - start);
}

private static class Sequence {
final int literalLen, matchDec, matchLen, length;

private Sequence(int literalLen, int matchDec, int matchLen, int length) {
this.literalLen = literalLen;
this.matchDec = matchDec;
this.matchLen = matchLen;
this.length = length;
}

@Override
public String toString() {
return "Sequence [literalLen=" + literalLen + ", matchDec=" + matchDec + ", matchLen=" + matchLen + "]";
}

@Override
public int hashCode() {
return 42;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Sequence other = (Sequence) obj;
if (literalLen != other.literalLen) return false;
if (matchDec != other.matchDec) return false;
if (matchLen != other.matchLen) return false;
return true;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ private Location location(ParserRuleContext ctx) {
return new Location(sourceName, ctx.getStart().getStartIndex());
}

private Location location(TerminalNode tn) {
return new Location(sourceName, tn.getSymbol().getStartIndex());
}

@Override
public ANode visitSource(SourceContext ctx) {
List<SFunction> functions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ public static class PrefixTrees {
public static final String GEOHASH = "geohash";
}

@Deprecated
public static class DeprecatedParameters {

private static void checkPrefixTreeSupport(String fieldName) {
if (ShapesAvailability.JTS_AVAILABLE == false || ShapesAvailability.SPATIAL4J_AVAILABLE == false) {
throw new ElasticsearchParseException("Field parameter [{}] is not supported for [{}] field type", fieldName, CONTENT_TYPE);
}

}
}

private static Builder builder(FieldMapper in) {
return ((LegacyGeoShapeFieldMapper) in).builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,38 +759,4 @@ public int read() throws IOException {
}
}

private static final class PrivilegedWriteChannelStream extends OutputStream {

private final OutputStream stream;

PrivilegedWriteChannelStream(WritableByteChannel channel) {
stream = Channels.newOutputStream(channel);
}

@Override
public void write(int b) throws IOException {
SocketAccess.doPrivilegedVoidIOException(() -> stream.write(b));
}

@Override
public void write(byte[] b) throws IOException {
SocketAccess.doPrivilegedVoidIOException(() -> stream.write(b));
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
SocketAccess.doPrivilegedVoidIOException(() -> stream.write(b, off, len));
}

@Override
public void flush() throws IOException {
SocketAccess.doPrivilegedVoidIOException(stream::flush);
}

@Override
public void close() throws IOException {
SocketAccess.doPrivilegedVoidIOException(stream::close);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,6 @@ private static void assertSameIndices(IndicesRequest originalRequest, String...
assertSameIndices(originalRequest, false, actions);
}

private static void assertSameIndicesOptionalRequests(IndicesRequest originalRequest, String... actions) {
assertSameIndices(originalRequest, true, actions);
}

private static void assertSameIndices(IndicesRequest originalRequest, boolean optional, String... actions) {
for (String action : actions) {
List<TransportRequest> requests = consumeTransportRequests(action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,6 @@ private class NodeTasksResponse extends TransportResponse {
this.exceptions = exceptions;
}

public String getNodeId() {
return nodeId;
}

public List<TaskOperationFailure> getExceptions() {
return exceptions;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(nodeId);
Expand Down
4 changes: 0 additions & 4 deletions server/src/main/java/org/elasticsearch/env/NodeMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ public void setNodeVersionId(int nodeVersionId) {
this.nodeVersion = Version.fromId(nodeVersionId);
}

public void setPreviousNodeVersionId(int previousNodeVersionId) {
this.previousNodeVersion = Version.fromId(previousNodeVersionId);
}

public void setOldestIndexVersion(int oldestIndexVersion) {
this.oldestIndexVersion = IndexVersion.fromId(oldestIndexVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public static class Builder {
private Disk disk;
private ShardLimits shardLimits;

private Builder() {}

private Builder(HealthMetadata healthMetadata) {
this.disk = healthMetadata.diskMetadata;
this.shardLimits = healthMetadata.shardLimitsMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ private static class Defaults {
public static final int DEPTH_LIMIT = 20;
}

private static FlattenedFieldMapper toType(FieldMapper in) {
return (FlattenedFieldMapper) in;
}

private static Builder builder(Mapper in) {
return ((FlattenedFieldMapper) in).builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ private KeyValue(final String key, final String value) {
this(value, new Prefix(key), new Suffix(key));
}

public Prefix prefix() {
return this.prefix;
}

public Suffix suffix() {
return this.suffix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.util.CollectionUtils;

import java.io.IOException;
import java.util.Locale;
Expand Down Expand Up @@ -48,9 +47,4 @@ public static Operator fromString(String op) {
return valueOf(op.toUpperCase(Locale.ROOT));
}

private static IllegalArgumentException newOperatorException(String op) {
return new IllegalArgumentException(
"operator needs to be either " + CollectionUtils.arrayAsArrayList(values()) + ", but not [" + op + "]"
);
}
}
4 changes: 0 additions & 4 deletions server/src/main/java/org/elasticsearch/tasks/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,6 @@ private void notifyListeners(List<Runnable> listeners) {
ExceptionsHelper.reThrowIfNotNull(rootException);
}

public boolean hasParent(TaskId parentTaskId) {
return task.getParentTaskId().equals(parentTaskId);
}

public CancellableTask getTask() {
return task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,4 @@ private static TimeSeries randomTimeSeries() {
}
}

private IngestStats.Stats getPipelineStats(List<IngestStats.PipelineStat> pipelineStats, String id) {
return pipelineStats.stream().filter(p1 -> p1.pipelineId().equals(id)).findFirst().map(p2 -> p2.stats()).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,4 @@ protected TestNodeResponse(StreamInput in) throws IOException {
}
}

private static class OtherNodeResponse extends BaseNodeResponse {
OtherNodeResponse() {
super(mock(DiscoveryNode.class));
}

protected OtherNodeResponse(StreamInput in) throws IOException {
super(in);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1557,14 +1557,6 @@ public void testDedupConcreteIndices() {
}
}

private static Metadata metadataBuilder(String... indices) {
Metadata.Builder mdBuilder = Metadata.builder();
for (String concreteIndex : indices) {
mdBuilder.put(indexBuilder(concreteIndex));
}
return mdBuilder.build();
}

public void testFilterClosedIndicesOnAliases() {
Metadata.Builder mdBuilder = Metadata.builder()
.put(indexBuilder("test-0").state(State.OPEN).putAlias(AliasMetadata.builder("alias-0")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3435,17 +3435,6 @@ public void testSkipTranslogReplay() throws IOException {
}
}

private Path[] filterExtraFSFiles(Path[] files) {
List<Path> paths = new ArrayList<>();
for (Path p : files) {
if (p.getFileName().toString().startsWith("extra")) {
continue;
}
paths.add(p);
}
return paths.toArray(new Path[0]);
}

public void testTranslogReplay() throws IOException {
final LongSupplier inSyncGlobalCheckpointSupplier = () -> this.engine.getProcessedLocalCheckpoint();
final int numDocs = randomIntBetween(1, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;

import java.io.IOException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Collections;
Expand Down Expand Up @@ -333,10 +332,6 @@ public void testDateNanoDocValues() throws IOException {
dir.close();
}

private Instant instant(String str) {
return DateFormatters.from(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parse(str)).toInstant();
}

private static DateFieldType fieldType(Resolution resolution, String format, String nullValue) {
DateFormatter formatter = DateFormatter.forPattern(format);
return new DateFieldType("field", true, false, true, formatter, resolution, nullValue, null, Collections.emptyMap());
Expand Down
Loading

0 comments on commit 1b84ea7

Please sign in to comment.