Оптимизация хранения ClientProfile

This commit is contained in:
Gravit 2018-11-14 19:55:53 +07:00
parent 4c4ff840d4
commit 2bff9a4e18
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -66,15 +66,15 @@ public String toString() {
private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher(
new String[0], new String[]{"indexes", "objects"}, new String[0]);
// Version
private final StringConfigEntry version;
private String version;
private final StringConfigEntry assetIndex;
private final String assetIndex;
// Client
private final IntegerConfigEntry sortIndex;
private final StringConfigEntry title;
private final StringConfigEntry serverAddress;
private final int sortIndex;
private String title;
private final String serverAddress;
private final IntegerConfigEntry serverPort;
private final int serverPort;
public static class MarkedString {
@LauncherAPI
@ -112,30 +112,30 @@ public int hashCode() {
private final List<String> updateShared = new ArrayList<>();
private final List<String> updateVerify = new ArrayList<>();
private final Set<MarkedString> updateOptional = new HashSet<>();
private final BooleanConfigEntry updateFastCheck;
private final boolean updateFastCheck;
private final BooleanConfigEntry useWhitelist;
private final boolean useWhitelist;
// Client launcher
private final StringConfigEntry mainClass;
private final List<String> jvmArgs= new ArrayList<>();
private final ListConfigEntry classPath;
private final ListConfigEntry clientArgs;
private final String mainClass;
private final List<String> jvmArgs = new ArrayList<>();
private final List<String> classPath = new ArrayList<>();
private final List<String> clientArgs = new ArrayList<>();
private final ListConfigEntry whitelist;
private final List<String> whitelist = new ArrayList<>();
@LauncherAPI
public ClientProfile(BlockConfigEntry block) {
super(block);
// Version
version = block.getEntry("version", StringConfigEntry.class);
assetIndex = block.getEntry("assetIndex", StringConfigEntry.class);
version = block.getEntryValue("version", StringConfigEntry.class);
assetIndex = block.getEntryValue("assetIndex", StringConfigEntry.class);
// Client
sortIndex = block.getEntry("sortIndex", IntegerConfigEntry.class);
title = block.getEntry("title", StringConfigEntry.class);
serverAddress = block.getEntry("serverAddress", StringConfigEntry.class);
serverPort = block.getEntry("serverPort", IntegerConfigEntry.class);
sortIndex = block.getEntryValue("sortIndex", IntegerConfigEntry.class);
title = block.getEntryValue("title", StringConfigEntry.class);
serverAddress = block.getEntryValue("serverAddress", StringConfigEntry.class);
serverPort = block.getEntryValue("serverPort", IntegerConfigEntry.class);
// Updater and client watch service
block.getEntry("update", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(update::add);
@ -144,15 +144,15 @@ public ClientProfile(BlockConfigEntry block) {
block.getEntry("updateOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.add(new MarkedString(e)));
block.getEntry("updateExclusions", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(updateExclusions::add);
block.getEntry("enabledOptional", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(e -> updateOptional.stream().anyMatch(e1 -> e.equals(e1.string) && (e1.mark = true)));
updateFastCheck = block.getEntry("updateFastCheck", BooleanConfigEntry.class);
useWhitelist = block.getEntry("useWhitelist", BooleanConfigEntry.class);
updateFastCheck = block.getEntryValue("updateFastCheck", BooleanConfigEntry.class);
useWhitelist = block.getEntryValue("useWhitelist", BooleanConfigEntry.class);
// Client launcher
mainClass = block.getEntry("mainClass", StringConfigEntry.class);
classPath = block.getEntry("classPath", ListConfigEntry.class);
mainClass = block.getEntryValue("mainClass", StringConfigEntry.class);
block.getEntry("classPath", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(classPath::add);
block.getEntry("jvmArgs", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(jvmArgs::add);
clientArgs = block.getEntry("clientArgs", ListConfigEntry.class);
whitelist = block.getEntry("whitelist", ListConfigEntry.class);
block.getEntry("clientArgs", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(clientArgs::add);
block.getEntry("whitelist", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(whitelist::add);
}
@LauncherAPI
@ -167,7 +167,7 @@ public int compareTo(ClientProfile o) {
@LauncherAPI
public String getAssetIndex() {
return assetIndex.getValue();
return assetIndex;
}
@LauncherAPI
@ -177,12 +177,12 @@ public FileNameMatcher getAssetUpdateMatcher() {
@LauncherAPI
public String[] getClassPath() {
return classPath.stream(StringConfigEntry.class).toArray(String[]::new);
return classPath.toArray(new String[0]);
}
@LauncherAPI
public String[] getClientArgs() {
return clientArgs.stream(StringConfigEntry.class).toArray(String[]::new);
return clientArgs.toArray(new String[0]);
}
@LauncherAPI
@ -209,12 +209,12 @@ public String[] getJvmArgs() {
@LauncherAPI
public String getMainClass() {
return mainClass.getValue();
return mainClass;
}
@LauncherAPI
public String getServerAddress() {
return serverAddress.getValue();
return serverAddress;
}
@LauncherAPI
@ -248,7 +248,7 @@ public void pushOptional(HashedDir dir, boolean digest) throws IOException {
@LauncherAPI
public int getServerPort() {
return serverPort.getValue();
return serverPort;
}
@LauncherAPI
@ -258,43 +258,43 @@ public InetSocketAddress getServerSocketAddress() {
@LauncherAPI
public int getSortIndex() {
return sortIndex.getValue();
return sortIndex;
}
@LauncherAPI
public String getTitle() {
return title.getValue();
return title;
}
@LauncherAPI
public Version getVersion() {
return Version.byName(version.getValue());
return Version.byName(version);
}
@LauncherAPI
public boolean isUpdateFastCheck() {
return updateFastCheck.getValue();
return updateFastCheck;
}
@LauncherAPI
public boolean isWhitelistContains(String username) {
if (!useWhitelist.getValue()) return true;
return whitelist.stream(StringConfigEntry.class).anyMatch(e -> e.equals(username));
if (!useWhitelist) return true;
return whitelist.stream().anyMatch(e -> e.equals(username));
}
@LauncherAPI
public void setTitle(String title) {
this.title.setValue(title);
this.title = title;
}
@LauncherAPI
public void setVersion(Version version) {
this.version.setValue(version.name);
this.version = version.name;
}
@Override
public String toString() {
return title.getValue();
return title;
}
@LauncherAPI
@ -309,8 +309,6 @@ public void verify() {
VerifyHelper.verifyInt(getServerPort(), VerifyHelper.range(0, 65535), "Illegal server port: " + getServerPort());
// Client launcher
classPath.verifyOfType(ConfigEntry.Type.STRING);
clientArgs.verifyOfType(ConfigEntry.Type.STRING);
VerifyHelper.verify(getTitle(), VerifyHelper.NOT_EMPTY, "Main class can't be empty");
}
}