public CompoundMap save() { CompoundMap map = new CompoundMap(); for (FieldValue<?> field : fields) { field.save(map); } return map; }
public void save(CompoundMap tag) { T value = this.value; if (value == null) { if ((value = defaultValue) == null) { return; } } Tag t = field.getValue(key, value); tag.put(t); }
private static ServerInfo createServerFromTag(CompoundMap compound){ String ipString, ip, name, icon = null; int port; ipString = compound.get("ip").getValue().toString(); name = compound.get("name").getValue().toString(); if(ipString.contains(":")){ ip = ipString.split(":")[0]; port = Integer.parseInt(ipString.split(":")[1]); } else { ip = ipString; port = DEFAULT_PORT; } if(compound.containsKey("icon")){ icon = ((StringTag)compound.get("icon")).getValue(); } return new ServerInfo(ip, name, icon,port); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
private CompoundMap createCompoundFromServer(ServerInfo server){ CompoundMap result = new CompoundMap(); result.put("name", new StringTag("name", server.getName())); String ipString = server.getIP(); if(server.getPort() != DEFAULT_PORT) ipString = ipString.concat(":".concat(Integer.toString(server.getPort()))); result.put("ip", new StringTag("ip", ipString)); if(server.hasIcon()) result.put("icon", new StringTag("icon", server.getIcon())); return result; }
/** * Creates a CompoundMap using the same element ordering rules as in the given CompoundMap.<br> <br> The map is initialised using the values given in the CompoundMap. * * @param initial the initial values for the CompoundMap */ public CompoundMap(CompoundMap initial) { this(initial.values(), initial.sort, initial.reverse); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }
public void saveServers(ServerInfo[] servers) throws IOException { if(file.exists()) if(!file.delete()) throw new IOException("Could not overwrite '".concat(file.getAbsolutePath()).concat("'")); final FileOutputStream fos = new FileOutputStream(file); NBTOutputStream nbtOutputStream = new NBTOutputStream(fos, false); ArrayList<CompoundTag> serversList = new ArrayList<CompoundTag>(); for(ServerInfo server : servers){ serversList.add(new CompoundTag("", createCompoundFromServer(server))); } ListTag<CompoundTag> listTag = new ListTag<CompoundTag>("servers", CompoundTag.class, serversList); CompoundTag root = new CompoundTag("", new CompoundMap()); root.getValue().put("servers", listTag); nbtOutputStream.writeTag(root); nbtOutputStream.flush(); fos.flush(); nbtOutputStream.close(); fos.close(); } }
/** * Creates a CompoundMap using the same element ordering rules as in the given CompoundMap.<br> <br> The map is initialised using the values given in the CompoundMap. * * @param initial the initial values for the CompoundMap */ public CompoundMap(CompoundMap initial) { this(initial.values(), initial.sort, initial.reverse); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }
@Test public void reverseSorted() { CompoundMap tag = new CompoundMap(random, true, true); assertEquals("Tag setup", tag, reverse); tag = new CompoundMap(true, true); for (Tag t : random) { tag.put(t); } assertEquals("Tag setup", tag, reverse); }
public void save(CompoundMap tag) { T value = this.value; if (value == null) { if ((value = defaultValue) == null) { return; } } Tag t = field.getValue(key, value); tag.put(t); }
public CompoundMap save() { CompoundMap map = new CompoundMap(); for (FieldValue<?> field : fields) { field.save(map); } return map; }
/** * Creates a CompoundMap using the same element ordering rules as in the given CompoundMap.<br> <br> The map is initialised using the values given in the CompoundMap. * * @param initial the initial values for the CompoundMap */ public CompoundMap(CompoundMap initial) { this(initial.values(), initial.sort, initial.reverse); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }