Fix some code smells

This commit is contained in:
Rsl1122 2019-03-31 14:20:10 +03:00
parent abd6b04b8d
commit 9b29edd16e
5 changed files with 70 additions and 7 deletions

View File

@ -30,10 +30,10 @@ import java.util.Optional;
*/
public class MethodAnnotations {
private final Map<Class, Map<Method, Annotation>> methodAnnotations;
private final Map<Class, Map<Method, Annotation>> byAnnotationType;
public MethodAnnotations() {
methodAnnotations = new HashMap<>();
byAnnotationType = new HashMap<>();
}
public static boolean hasAnyOf(Method method, Class... annotationClasses) {
@ -52,13 +52,13 @@ public class MethodAnnotations {
}
public <T extends Annotation> void put(Method method, Class<T> annotationClass, T annotation) {
Map<Method, Annotation> methods = methodAnnotations.getOrDefault(annotationClass, new HashMap<>());
Map<Method, Annotation> methods = byAnnotationType.getOrDefault(annotationClass, new HashMap<>());
methods.put(method, annotation);
methodAnnotations.put(annotationClass, methods);
byAnnotationType.put(annotationClass, methods);
}
public <T extends Annotation> Map<Method, T> getMethodAnnotations(Class<T> ofType) {
return (Map<Method, T>) methodAnnotations.getOrDefault(ofType, new HashMap<>());
return (Map<Method, T>) byAnnotationType.getOrDefault(ofType, new HashMap<>());
}
public <T extends Annotation> Collection<T> getAnnotations(Class<T> ofType) {
@ -66,11 +66,11 @@ public class MethodAnnotations {
}
public boolean isEmpty() {
return methodAnnotations.isEmpty();
return byAnnotationType.isEmpty();
}
@Override
public String toString() {
return "MethodAnnotations{" + methodAnnotations + '}';
return "MethodAnnotations{" + byAnnotationType + '}';
}
}

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.extension.implementation.results;
import com.djrapitops.plan.extension.icon.Icon;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
import java.util.Optional;
/**
@ -66,4 +67,21 @@ public class ExtensionDescriptive implements Comparable<ExtensionDescriptive> {
public int compareTo(ExtensionDescriptive other) {
return Integer.compare(other.priority, this.priority); // Higher is first
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExtensionDescriptive)) return false;
ExtensionDescriptive that = (ExtensionDescriptive) o;
return priority == that.priority &&
name.equals(that.name) &&
text.equals(that.text) &&
Objects.equals(description, that.description) &&
icon.equals(that.icon);
}
@Override
public int hashCode() {
return Objects.hash(name, text, description, icon, priority);
}
}

View File

@ -83,6 +83,20 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
return Integer.compare(this.tabInformation.getTabPriority(), other.tabInformation.getTabPriority()); // Lower is first
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExtensionTabData)) return false;
ExtensionTabData that = (ExtensionTabData) o;
return tabInformation.equals(that.tabInformation) &&
order.equals(that.order);
}
@Override
public int hashCode() {
return Objects.hash(tabInformation, order);
}
public void combine(ExtensionTabData other) {
this.booleanData.putAll(other.booleanData);
this.doubleData.putAll(other.doubleData);

View File

@ -22,6 +22,7 @@ import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Represents data of a single extension about a player.
@ -63,6 +64,21 @@ public class ExtensionPlayerData implements Comparable<ExtensionPlayerData> {
return String.CASE_INSENSITIVE_ORDER.compare(this.extensionInformation.getPluginName(), o.extensionInformation.getPluginName());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExtensionPlayerData)) return false;
ExtensionPlayerData that = (ExtensionPlayerData) o;
return pluginID == that.pluginID &&
extensionInformation.equals(that.extensionInformation) &&
tabs.equals(that.tabs);
}
@Override
public int hashCode() {
return Objects.hash(pluginID, extensionInformation, tabs);
}
public static class Factory {
private final ExtensionPlayerData data;

View File

@ -63,6 +63,21 @@ public class ExtensionServerData implements Comparable<ExtensionServerData> {
return String.CASE_INSENSITIVE_ORDER.compare(this.extensionInformation.getPluginName(), o.extensionInformation.getPluginName());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ExtensionServerData)) return false;
ExtensionServerData that = (ExtensionServerData) o;
return pluginID == that.pluginID &&
Objects.equals(extensionInformation, that.extensionInformation) &&
Objects.equals(tabs, that.tabs);
}
@Override
public int hashCode() {
return Objects.hash(pluginID, extensionInformation, tabs);
}
public static class Factory {
private final ExtensionServerData data;