ToStringBuilder
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package org.jackhuang.hmcl.game;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -52,4 +53,8 @@ public final class AssetIndex {
|
||||
return Collections.unmodifiableMap(objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).append("virtual", virtual).append("objects", objects).toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.Immutable;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
import org.jackhuang.hmcl.util.Validation;
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,11 @@ public class DownloadInfo implements Validation {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).append("url", url).append("sha1", sha1).append("size", size).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws JsonParseException {
|
||||
if (StringUtils.isBlank(url))
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class ExtractRules {
|
||||
private final List<String> exclude;
|
||||
|
||||
public ExtractRules() {
|
||||
this.exclude = Collections.EMPTY_LIST;
|
||||
this.exclude = Collections.emptyList();
|
||||
}
|
||||
|
||||
public ExtractRules(List<String> exclude) {
|
||||
@@ -44,7 +44,7 @@ public final class ExtractRules {
|
||||
}
|
||||
|
||||
public boolean shouldExtract(String path) {
|
||||
return exclude.stream().noneMatch(it -> path.startsWith(it));
|
||||
return exclude.stream().noneMatch(path::startsWith);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gson.reflect.TypeToken;
|
||||
import org.jackhuang.hmcl.util.Constants;
|
||||
import org.jackhuang.hmcl.util.OperatingSystem;
|
||||
import org.jackhuang.hmcl.util.Platform;
|
||||
import org.jackhuang.hmcl.util.ToStringBuilder;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
@@ -142,7 +143,7 @@ public class Library implements Comparable<Library> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Library[" + getName() + "]";
|
||||
return new ToStringBuilder(this).append("name", getName()).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
public class ToStringBuilder {
|
||||
|
||||
private final StringBuilder stringBuilder;
|
||||
private boolean first = true;
|
||||
|
||||
public ToStringBuilder(Object object) {
|
||||
stringBuilder = new StringBuilder(object.getClass().getSimpleName()).append(" [");
|
||||
}
|
||||
|
||||
public ToStringBuilder append(String name, Object content) {
|
||||
if (!first)
|
||||
stringBuilder.append(", ");
|
||||
stringBuilder.append(name).append('=').append(content.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringBuilder.toString() + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user