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 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 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); }
/** * Creates an empty CompoundMap which is initialised using the given values<br> <br> * * @param initial the initial values * @param sort elements are ordered in alphabetical ordering * @param reverse elements are ordered in reverse alphabetical ordering, when sort is true */ public CompoundMap(Iterable<Tag<?>> initial, boolean sort, boolean reverse) { if (reverse) { this.sort = true; } else { this.sort = sort; } this.reverse = reverse; if (!sort) { this.map = new LinkedHashMap<String, Tag<?>>(); } else { if (reverse) { this.map = new TreeMap<String, Tag<?>>(Collections.reverseOrder()); } else { this.map = new TreeMap<String, Tag<?>>(); } } if (initial != null) { for (Tag t : initial) { put(t); } } }
/** * Creates an empty CompoundMap which is initialised using the given values<br> <br> * * @param initial the initial values * @param sort elements are ordered in alphabetical ordering * @param reverse elements are ordered in reverse alphabetical ordering, when sort is true */ public CompoundMap(Iterable<Tag<?>> initial, boolean sort, boolean reverse) { if (reverse) { this.sort = true; } else { this.sort = sort; } this.reverse = reverse; if (!sort) { this.map = new LinkedHashMap<String, Tag<?>>(); } else { if (reverse) { this.map = new TreeMap<String, Tag<?>>(Collections.reverseOrder()); } else { this.map = new TreeMap<String, Tag<?>>(); } } if (initial != null) { for (Tag t : initial) { put(t); } } }
/** * Creates an empty CompoundMap which is initialised using the given values<br> <br> * * @param initial the initial values * @param sort elements are ordered in alphabetical ordering * @param reverse elements are ordered in reverse alphabetical ordering, when sort is true */ public CompoundMap(Iterable<Tag<?>> initial, boolean sort, boolean reverse) { if (reverse) { this.sort = true; } else { this.sort = sort; } this.reverse = reverse; if (!sort) { this.map = new LinkedHashMap<String, Tag<?>>(); } else { if (reverse) { this.map = new TreeMap<String, Tag<?>>(Collections.reverseOrder()); } else { this.map = new TreeMap<String, Tag<?>>(); } } if (initial != null) { for (Tag t : initial) { put(t); } } }
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; }
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(); } }
@Test public void preserveOrder() { CompoundMap tag = new CompoundMap(random, false, false); assertEquals("Tag setup", tag, random); tag = new CompoundMap(false, false); for (Tag t : random) { tag.put(t); } assertEquals("Tag setup", tag, random); }
@Test public void sorted() { CompoundMap tag = new CompoundMap(random, true, false); assertEquals("Tag setup", tag, sorted); tag = new CompoundMap(true, false); for (Tag t : random) { tag.put(t); } assertEquals("Tag setup", tag, sorted); }
@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); }
@Before public void setUp() { subject = new ExampleHolder(); CompoundMap map = new CompoundMap(); map.put(new StringTag("name", "helloworld")); CompoundTag mapTag = new CompoundTag("", map); subject.load(mapTag); }
break; } else { compoundTagList.put(tag);
break; } else { compoundTagList.put(tag);
break; } else { compoundTagList.put(tag);