Exemple #1
0
    public void testBuilderReuse() {
      Builder<String, Integer> builder = new Builder<String, Integer>();
      ImmutableBiMap<String, Integer> mapOne = builder.put("one", 1).put("two", 2).build();
      ImmutableBiMap<String, Integer> mapTwo = builder.put("three", 3).put("four", 4).build();

      assertMapEquals(mapOne, "one", 1, "two", 2);
      assertMapEquals(mapOne.inverse(), 1, "one", 2, "two");
      assertMapEquals(mapTwo, "one", 1, "two", 2, "three", 3, "four", 4);
      assertMapEquals(mapTwo.inverse(), 1, "one", 2, "two", 3, "three", 4, "four");
    }
 @Override
 public void fromBinary(final byte[] bytes) {
   final ByteBuffer buf = ByteBuffer.wrap(bytes);
   final int numSfcs = buf.getInt();
   final int numDimensions = buf.getInt();
   final int mappingSize = buf.getInt();
   maxEstimatedDuplicateIds = buf.getLong();
   maxEstimatedDuplicateIdsBigInteger = BigInteger.valueOf(maxEstimatedDuplicateIds);
   orderedSfcs = new SpaceFillingCurve[numSfcs];
   baseDefinitions = new NumericDimensionDefinition[numDimensions];
   for (int i = 0; i < numSfcs; i++) {
     final byte[] sfc = new byte[buf.getInt()];
     buf.get(sfc);
     orderedSfcs[i] = PersistenceUtils.fromBinary(sfc, SpaceFillingCurve.class);
   }
   for (int i = 0; i < numDimensions; i++) {
     final byte[] dim = new byte[buf.getInt()];
     buf.get(dim);
     baseDefinitions[i] = PersistenceUtils.fromBinary(dim, NumericDimensionDefinition.class);
   }
   final Builder<Integer, Byte> bimapBuilder = ImmutableBiMap.builder();
   for (int i = 0; i < mappingSize; i++) {
     bimapBuilder.put(Byte.valueOf(buf.get()).intValue(), buf.get());
   }
   orderedSfcIndexToTierId = bimapBuilder.build();
 }
Exemple #3
0
 public void testBuilderPutNullValue() {
   Builder<String, Integer> builder = new Builder<String, Integer>();
   try {
     builder.put("one", null);
     fail();
   } catch (NullPointerException expected) {
   }
 }
 public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) {
   this.classLoader = classLoader;
   try {
     InputStream classData = getClass().getResourceAsStream(deobfFileName);
     LZMAInputSupplier zis = new LZMAInputSupplier(classData);
     InputSupplier<InputStreamReader> srgSupplier =
         CharStreams.newReaderSupplier(zis, Charsets.UTF_8);
     List<String> srgList = CharStreams.readLines(srgSupplier);
     rawMethodMaps = Maps.newHashMap();
     rawFieldMaps = Maps.newHashMap();
     Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
     Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>builder();
     Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
     for (String line : srgList) {
       String[] parts = Iterables.toArray(splitter.split(line), String.class);
       String typ = parts[0];
       if ("CL".equals(typ)) {
         parseClass(builder, parts);
         parseMCPClass(mcpBuilder, parts);
       } else if ("MD".equals(typ)) {
         parseMethod(parts);
       } else if ("FD".equals(typ)) {
         parseField(parts);
       }
     }
     classNameBiMap = builder.build();
     // Special case some mappings for modloader mods
     mcpBuilder.put("BaseMod", "net/minecraft/src/BaseMod");
     mcpBuilder.put("ModLoader", "net/minecraft/src/ModLoader");
     mcpBuilder.put("EntityRendererProxy", "net/minecraft/src/EntityRendererProxy");
     mcpBuilder.put("MLProp", "net/minecraft/src/MLProp");
     mcpBuilder.put("TradeEntry", "net/minecraft/src/TradeEntry");
     mcpNameBiMap = mcpBuilder.build();
   } catch (IOException ioe) {
     FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data");
   }
   methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
   fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
 }
 private void parseMCPClass(Builder<String, String> builder, String[] parts) {
   int clIdx = parts[2].lastIndexOf('/');
   builder.put("net/minecraft/src/" + parts[2].substring(clIdx + 1), parts[2]);
 }
 private void parseClass(Builder<String, String> builder, String[] parts) {
   builder.put(parts[1], parts[2]);
 }