public void testMap() { MapJoiner j = Joiner.on(';').withKeyValueSeparator(':'); assertEquals("", j.join(ImmutableMap.of())); assertEquals(":", j.join(ImmutableMap.of("", ""))); Map<String, String> mapWithNulls = Maps.newLinkedHashMap(); mapWithNulls.put("a", null); mapWithNulls.put(null, "b"); try { j.join(mapWithNulls); fail(); } catch (NullPointerException expected) { } assertEquals("a:00;00:b", j.useForNull("00").join(mapWithNulls)); StringBuilder sb = new StringBuilder(); j.appendTo(sb, ImmutableMap.of(1, 2, 3, 4, 5, 6)); assertEquals("1:2;3:4;5:6", sb.toString()); }
public void testMap() { MapJoiner j = Joiner.on(";").withKeyValueSeparator(":"); assertEquals("", j.join(ImmutableMap.of())); assertEquals(":", j.join(ImmutableMap.of("", ""))); Map<String, String> mapWithNulls = Maps.newLinkedHashMap(); mapWithNulls.put("a", null); mapWithNulls.put(null, "b"); try { j.join(mapWithNulls); fail(); } catch (NullPointerException expected) { } assertEquals("a:00;00:b", j.useForNull("00").join(mapWithNulls)); StringBuilder sb = new StringBuilder(); j.appendTo(sb, ImmutableMap.of(1, 2, 3, 4, 5, 6)); assertEquals("1:2;3:4;5:6", sb.toString()); }
protected void appendContent(/* @Nullable */ Map<?, ?> map, String prefix, StringBuilder result, String indentation) { if (map != null) { MapJoiner joiner = Joiner.on("\n " + indentation).withKeyValueSeparator(" -> "); result.append("\n").append(indentation).append(prefix).append(":\n").append(indentation).append(" "); joiner.appendTo(result, map); } }
public static void dumpRegistry(File minecraftDir) { if (customItemStacks == null) { return; } if (Boolean.valueOf(System.getProperty("fml.dumpRegistry", "false")).booleanValue()) { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (String modId : customItemStacks.rowKeySet()) { builder.putAll(modId, customItemStacks.row(modId).keySet()); } File f = new File(minecraftDir, "itemStackRegistry.csv"); MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator(","); try { Files.write(mapJoiner.join(builder.build().entries()), f, Charsets.UTF_8); FMLLog.log(Level.INFO, "Dumped item registry data to %s", f.getAbsolutePath()); } catch (IOException e) { FMLLog.log(Level.ERROR, e, "Failed to write registry data to %s", f.getAbsolutePath()); } } }
public static void dumpRegistry(File minecraftDir) { if (customItemStacks == null) { return; } if (Boolean.valueOf(System.getProperty("fml.dumpRegistry", "false")).booleanValue()) { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (String modId : customItemStacks.rowKeySet()) { builder.putAll(modId, customItemStacks.row(modId).keySet()); } File f = new File(minecraftDir, "itemStackRegistry.csv"); MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator(","); try { Files.write(mapJoiner.join(builder.build().entries()), f, Charsets.UTF_8); FMLLog.log(Level.INFO, "Dumped item registry data to %s", f.getAbsolutePath()); } catch (IOException e) { FMLLog.log(Level.SEVERE, e, "Failed to write registry data to %s", f.getAbsolutePath()); } } }
public static Renderer<Map<?, ?>> fromMapJoiner(Function<? super Locale, ? extends MapJoiner> joinerFunction) { return new MapJoinerRenderer(joinerFunction); }
public MapJoinerRenderer(Function<? super Locale, ? extends MapJoiner> joinerFunction) { super(); this.joinerFunction = checkNotNull(joinerFunction); }
@Override public String render(Map<?, ?> value, Locale locale) { checkNotNull(locale); MapJoiner joiner = joinerFunction.apply(locale); return joiner.join(value); }