コード例 #1
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testOf() {
   assertMapEquals(ImmutableBiMap.of("one", 1), "one", 1);
   assertMapEquals(ImmutableBiMap.of("one", 1).inverse(), 1, "one");
   assertMapEquals(ImmutableBiMap.of("one", 1, "two", 2), "one", 1, "two", 2);
   assertMapEquals(ImmutableBiMap.of("one", 1, "two", 2).inverse(), 1, "one", 2, "two");
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3), "one", 1, "two", 2, "three", 3);
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3).inverse(),
       1,
       "one",
       2,
       "two",
       3,
       "three");
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3, "four", 4),
       "one",
       1,
       "two",
       2,
       "three",
       3,
       "four",
       4);
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3, "four", 4).inverse(),
       1,
       "one",
       2,
       "two",
       3,
       "three",
       4,
       "four");
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3, "four", 4, "five", 5),
       "one",
       1,
       "two",
       2,
       "three",
       3,
       "four",
       4,
       "five",
       5);
   assertMapEquals(
       ImmutableBiMap.of("one", 1, "two", 2, "three", 3, "four", 4, "five", 5).inverse(),
       1,
       "one",
       2,
       "two",
       3,
       "three",
       4,
       "four",
       5,
       "five");
 }
コード例 #2
0
 public void setupLoadOnly(String deobfFileName, boolean loadAll) {
   try {
     File mapData = new File(deobfFileName);
     LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
     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) && loadAll) {
         parseMethod(parts);
       } else if ("FD".equals(typ) && loadAll) {
         parseField(parts);
       }
     }
     classNameBiMap = builder.build();
     mcpNameBiMap = mcpBuilder.build();
   } catch (IOException ioe) {
     FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
   }
   methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
   fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
 }
コード例 #3
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testValues() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<Integer> values = bimap.values();
   assertEquals(Sets.newHashSet(1, 2, 3, 4), values);
   assertThat(values).containsExactly(1, 2, 3, 4).inOrder();
 }
コード例 #4
0
ファイル: MetricsHandler.java プロジェクト: domarps/cdap
  static {
    ImmutableBiMap<String, String> mapping =
        ImmutableBiMap.<String, String>builder()
            .put(Constants.Metrics.Tag.NAMESPACE, "namespace")
            .put(Constants.Metrics.Tag.RUN_ID, "run")
            .put(Constants.Metrics.Tag.INSTANCE_ID, "instance")
            .put(Constants.Metrics.Tag.COMPONENT, "component")
            .put(Constants.Metrics.Tag.HANDLER, "handler")
            .put(Constants.Metrics.Tag.METHOD, "method")
            .put(Constants.Metrics.Tag.STREAM, "stream")
            .put(Constants.Metrics.Tag.DATASET, "dataset")
            .put(Constants.Metrics.Tag.APP, "app")
            .put(Constants.Metrics.Tag.ADAPTER, "adapter")
            .put(Constants.Metrics.Tag.SERVICE, "service")
            // SERVICE_HANDLER is the same HANDLER

            .put(Constants.Metrics.Tag.WORKER, "worker")
            .put(Constants.Metrics.Tag.FLOW, "flow")
            .put(Constants.Metrics.Tag.FLOWLET, "flowlet")
            .put(Constants.Metrics.Tag.FLOWLET_QUEUE, "queue")
            .put(Constants.Metrics.Tag.PRODUCER, "producer")
            .put(Constants.Metrics.Tag.CONSUMER, "consumer")
            .put(Constants.Metrics.Tag.MAPREDUCE, "mapreduce")
            .put(Constants.Metrics.Tag.MR_TASK_TYPE, "tasktype")
            .put(Constants.Metrics.Tag.WORKFLOW, "workflow")
            .put(Constants.Metrics.Tag.SPARK, "spark")
            .build();

    tagNameToHuman = mapping;
    humanToTagName = mapping.inverse();
  }
コード例 #5
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testKeySet() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<String> keys = bimap.keySet();
   assertEquals(Sets.newHashSet("one", "two", "three", "four"), keys);
   assertThat(keys).containsExactly("one", "two", "three", "four").inOrder();
 }
コード例 #6
0
ファイル: ImmutableBiMapTest.java プロジェクト: hinike/opera
 public void testKeySet() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<String> keys = bimap.keySet();
   assertEquals(Sets.newHashSet("one", "two", "three", "four"), keys);
   ASSERT.that(keys).hasContentsInOrder("one", "two", "three", "four");
 }
コード例 #7
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testCopyOfEmptyMap() {
   ImmutableBiMap<String, Integer> copy =
       ImmutableBiMap.copyOf(Collections.<String, Integer>emptyMap());
   assertEquals(Collections.<String, Integer>emptyMap(), copy);
   assertSame(copy, ImmutableBiMap.copyOf(copy));
   assertSame(ImmutableBiMap.of(), copy);
 }
コード例 #8
0
  @Override
  public byte[] toBinary() {
    int byteBufferLength = 20 + (2 * orderedSfcIndexToTierId.size());
    final List<byte[]> orderedSfcBinaries = new ArrayList<byte[]>(orderedSfcs.length);
    final List<byte[]> dimensionBinaries = new ArrayList<byte[]>(baseDefinitions.length);
    for (final SpaceFillingCurve sfc : orderedSfcs) {
      final byte[] sfcBinary = PersistenceUtils.toBinary(sfc);
      byteBufferLength += (4 + sfcBinary.length);
      orderedSfcBinaries.add(sfcBinary);
    }
    for (final NumericDimensionDefinition dimension : baseDefinitions) {
      final byte[] dimensionBinary = PersistenceUtils.toBinary(dimension);
      byteBufferLength += (4 + dimensionBinary.length);
      dimensionBinaries.add(dimensionBinary);
    }
    final ByteBuffer buf = ByteBuffer.allocate(byteBufferLength);
    buf.putInt(orderedSfcs.length);
    buf.putInt(baseDefinitions.length);
    buf.putInt(orderedSfcIndexToTierId.size());
    buf.putLong(maxEstimatedDuplicateIds);
    for (final byte[] sfcBinary : orderedSfcBinaries) {
      buf.putInt(sfcBinary.length);
      buf.put(sfcBinary);
    }
    for (final byte[] dimensionBinary : dimensionBinaries) {
      buf.putInt(dimensionBinary.length);
      buf.put(dimensionBinary);
    }
    for (final Entry<Integer, Byte> entry : orderedSfcIndexToTierId.entrySet()) {
      buf.put(entry.getKey().byteValue());
      buf.put(entry.getValue());
    }

    return buf.array();
  }
コード例 #9
0
ファイル: ImmutableBiMapTest.java プロジェクト: hinike/opera
 public void testValues() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4));
   Set<Integer> values = bimap.values();
   assertEquals(Sets.newHashSet(1, 2, 3, 4), values);
   ASSERT.that(values).hasContentsInOrder(1, 2, 3, 4);
 }
コード例 #10
0
 @Override
 public Set<ByteArrayId> getNaturalSplits() {
   final Set<ByteArrayId> retVal = new HashSet<ByteArrayId>(orderedSfcIndexToTierId.size());
   for (final Byte tier : orderedSfcIndexToTierId.values()) {
     retVal.add(new ByteArrayId(new byte[] {tier}));
   }
   return retVal;
 }
コード例 #11
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testFromHashMap() {
   Map<String, Integer> hashMap = Maps.newLinkedHashMap();
   hashMap.put("one", 1);
   hashMap.put("two", 2);
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2));
   assertMapEquals(bimap, "one", 1, "two", 2);
   assertMapEquals(bimap.inverse(), 1, "one", 2, "two");
 }
コード例 #12
0
ファイル: ImmutableBiMapTest.java プロジェクト: hinike/opera
 public void testForcePut() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of("one", 1, "two", 2));
   try {
     bimap.forcePut("three", 3);
     fail();
   } catch (UnsupportedOperationException expected) {
   }
 }
コード例 #13
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 @GwtIncompatible // SerializableTester
 public void testInverseSerialization() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of(1, "one", 2, "two")).inverse();
   ImmutableBiMap<String, Integer> copy = SerializableTester.reserializeAndAssert(bimap);
   assertEquals(Integer.valueOf(1), copy.get("one"));
   assertEquals("one", copy.inverse().get(1));
   assertSame(copy, copy.inverse().inverse());
 }
コード例 #14
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    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");
    }
コード例 #15
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    public void testCopyOf() {
      Map<String, Integer> original = new LinkedHashMap<String, Integer>();
      original.put("one", 1);
      original.put("two", 2);
      original.put("three", 3);

      ImmutableBiMap<String, Integer> copy = ImmutableBiMap.copyOf(original);
      assertMapEquals(copy, "one", 1, "two", 2, "three", 3);
      assertSame(copy, ImmutableBiMap.copyOf(copy));
    }
コード例 #16
0
 /**
  * Returns an immutable bimap containing the same entries as {@code map}. If {@code map} somehow
  * contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose
  * comparator is not <i>consistent with equals</i>), the results of this method are undefined.
  *
  * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
  * safe to do so. The exact circumstances under which a copy will or will not be performed are
  * undocumented and subject to change.
  *
  * @throws IllegalArgumentException if two keys have the same value
  * @throws NullPointerException if any key or value in {@code map} is null
  */
 public static <K, V> ImmutableBiMap<K, V> copyOf(Map<? extends K, ? extends V> map) {
   if (map instanceof ImmutableBiMap) {
     @SuppressWarnings("unchecked") // safe since map is not writable
     ImmutableBiMap<K, V> bimap = (ImmutableBiMap<K, V>) map;
     // TODO(lowasser): if we need to make a copy of a BiMap because the
     // forward map is a view, don't make a copy of the non-view delegate map
     if (!bimap.isPartialView()) {
       return bimap;
     }
   }
   return copyOf(map.entrySet());
 }
コード例 #17
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testBuilder() {
   ImmutableBiMap<String, Integer> map =
       ImmutableBiMap.<String, Integer>builder()
           .put("one", 1)
           .put("two", 2)
           .put("three", 3)
           .put("four", 4)
           .put("five", 5)
           .build();
   assertMapEquals(map, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5);
   assertMapEquals(map.inverse(), 1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
 }
コード例 #18
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    public void testOfNullKey() {
      try {
        ImmutableBiMap.of(null, 1);
        fail();
      } catch (NullPointerException expected) {
      }

      try {
        ImmutableBiMap.of("one", 1, null, 2);
        fail();
      } catch (NullPointerException expected) {
      }
    }
コード例 #19
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testFromImmutableMap() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(
           new ImmutableMap.Builder<String, Integer>()
               .put("one", 1)
               .put("two", 2)
               .put("three", 3)
               .put("four", 4)
               .put("five", 5)
               .build());
   assertMapEquals(bimap, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5);
   assertMapEquals(bimap.inverse(), 1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
 }
コード例 #20
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    public void testOfNullValue() {
      try {
        ImmutableBiMap.of("one", null);
        fail();
      } catch (NullPointerException expected) {
      }

      try {
        ImmutableBiMap.of("one", 1, "two", null);
        fail();
      } catch (NullPointerException expected) {
      }
    }
コード例 #21
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
    public void testBuilderPutAll() {
      Map<String, Integer> toPut = new LinkedHashMap<String, Integer>();
      toPut.put("one", 1);
      toPut.put("two", 2);
      toPut.put("three", 3);
      Map<String, Integer> moreToPut = new LinkedHashMap<String, Integer>();
      moreToPut.put("four", 4);
      moreToPut.put("five", 5);

      ImmutableBiMap<String, Integer> map =
          new Builder<String, Integer>().putAll(toPut).putAll(moreToPut).build();
      assertMapEquals(map, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5);
      assertMapEquals(map.inverse(), 1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
    }
コード例 #22
0
ファイル: RuleNames.java プロジェクト: iloveeclipse/xtext
  public RuleNames(Grammar grammar, boolean installAdapter) {
    this.contextGrammar = grammar;
    Adapter adapter = new Adapter(this);
    if (installAdapter) {
      installAdapterIfMissing(adapter, grammar);
    }
    List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
    ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder =
        ImmutableListMultimap.builder();
    ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder();

    Map<String, AbstractRule> names = Maps.newHashMap();
    Set<String> usedAntlrNames = Sets.newHashSet();
    Set<String> usedUniqueNames = Sets.newHashSet();
    for (AbstractRule rule : allRules) {
      String name = rule.getName();
      simpleNameToRulesBuilder.put(name, rule);
      String qualifiedName = getQualifiedName(rule);
      qualifiedNameToRuleBuilder.put(qualifiedName, rule);
      String uniqueName = name;
      String antlrRuleName;
      if (names.containsKey(name)) {
        name = qualifiedName;
        uniqueName = getInheritedUniqueName(rule, usedUniqueNames);
        antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames);
      } else {
        antlrRuleName = getDefaultAntlrRuleName(rule);
      }
      names.put(name, rule);
      if (!usedUniqueNames.add(uniqueName)) {
        throw new IllegalStateException(uniqueName);
      }
      uniqueNameToRuleBuilder.put(uniqueName, rule);
      if (!usedAntlrNames.add(antlrRuleName)) {
        throw new IllegalStateException(antlrRuleName);
      }
      antlrNameToRuleBuilder.put(antlrRuleName, rule);
      if (installAdapter) {
        installAdapterIfMissing(adapter, rule);
      }
    }
    simpleNameToRules = simpleNameToRulesBuilder.build();
    qualifiedNameToRule = qualifiedNameToRuleBuilder.build();
    nameToRule = ImmutableBiMap.copyOf(names);
    uniqueNameToRule = uniqueNameToRuleBuilder.build();
    antlrNameToRule = antlrNameToRuleBuilder.build();
    this.allRules = ImmutableList.copyOf(allRules);
  }
コード例 #23
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testToImmutableBiMap() {
   Collector<Entry<String, Integer>, ?, ImmutableBiMap<String, Integer>> collector =
       ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue);
   Equivalence<ImmutableBiMap<String, Integer>> equivalence =
       Equivalence.equals()
           .<Entry<String, Integer>>pairwise()
           .onResultOf(ImmutableBiMap::entrySet);
   CollectorTester.of(collector, equivalence)
       .expectCollects(
           ImmutableBiMap.of("one", 1, "two", 2, "three", 3),
           mapEntry("one", 1),
           mapEntry("two", 2),
           mapEntry("three", 3));
 }
コード例 #24
0
 static {
   //noinspection ConstantConditions
   COAL_MAP =
       ImmutableBiMap.<CoalType, Integer>builder()
           .put(CoalTypes.COAL, 0)
           .put(CoalTypes.CHARCOAL, 1)
           .build();
   //noinspection ConstantConditions
   COOKED_FISH_MAP =
       ImmutableBiMap.<CookedFish, Integer>builder()
           .put(CookedFishes.COD, 0)
           .put(CookedFishes.SALMON, 1)
           .build();
   //noinspection deprecation, ConstantConditions
   DYE_MAP =
       ImmutableBiMap.<DyeColor, Integer>builder()
           .put(DyeColors.BLACK, (int) org.bukkit.DyeColor.BLACK.getDyeData())
           .put(DyeColors.RED, (int) org.bukkit.DyeColor.RED.getDyeData())
           .put(DyeColors.GREEN, (int) org.bukkit.DyeColor.GREEN.getDyeData())
           .put(DyeColors.BROWN, (int) org.bukkit.DyeColor.BROWN.getDyeData())
           .put(DyeColors.BLUE, (int) org.bukkit.DyeColor.BLUE.getDyeData())
           .put(DyeColors.PURPLE, (int) org.bukkit.DyeColor.PURPLE.getDyeData())
           .put(DyeColors.CYAN, (int) org.bukkit.DyeColor.CYAN.getDyeData())
           .put(DyeColors.SILVER, (int) org.bukkit.DyeColor.SILVER.getDyeData())
           .put(DyeColors.GRAY, (int) org.bukkit.DyeColor.GRAY.getDyeData())
           .put(DyeColors.PINK, (int) org.bukkit.DyeColor.PINK.getDyeData())
           .put(DyeColors.LIME, (int) org.bukkit.DyeColor.LIME.getDyeData())
           .put(DyeColors.YELLOW, (int) org.bukkit.DyeColor.YELLOW.getDyeData())
           .put(DyeColors.LIGHT_BLUE, (int) org.bukkit.DyeColor.LIGHT_BLUE.getDyeData())
           .put(DyeColors.MAGENTA, (int) org.bukkit.DyeColor.MAGENTA.getDyeData())
           .put(DyeColors.ORANGE, (int) org.bukkit.DyeColor.ORANGE.getDyeData())
           .put(DyeColors.WHITE, (int) org.bukkit.DyeColor.WHITE.getDyeData())
           .build();
   //noinspection ConstantConditions
   FISH_MAP =
       ImmutableBiMap.<Fish, Integer>builder()
           .put(Fishes.COD, 0)
           .put(Fishes.SALMON, 1)
           .put(Fishes.CLOWNFISH, 2)
           .put(Fishes.PUFFERFISH, 3)
           .build();
   //noinspection ConstantConditions
   GOLDEN_APPLE_MAP =
       ImmutableBiMap.<GoldenApple, Integer>builder()
           .put(GoldenApples.GOLDEN_APPLE, 0)
           .put(GoldenApples.ENCHANTED_GOLDEN_APPLE, 1)
           .build();
 }
コード例 #25
0
  public static void main(String[] args) {
    ArrayList<Integer> list = Lists.newArrayList(new Integer[] {1, 2, 3, 4});

    List<String> transform =
        Lists.transform(
            list,
            new Function<Integer, String>() {
              @Override
              public String apply(Integer integer) {
                return integer + "";
              }
            });

    List<Integer> reverseList = Lists.reverse(list);
    for (Object o : transform) {
      System.out.println(o.getClass().toString() + o);
    }
    for (Object o : reverseList) {
      System.out.println(o);
    }
    System.out.println("Hell o");
    // 不可变集合
    ImmutableList<Integer> immutableList = ImmutableList.of(1, 2, 3, 4);
    ImmutableBiMap<Integer, String> immutableBiMap = ImmutableBiMap.of(1, "1", 2, "2");
    ImmutableSet<Integer> immutableSet = ImmutableSet.of(1, 2, 3, 4);
    ImmutableCollection<Integer> immutableCollection = ImmutableList.of(1, 2, 3, 4);

    for (Integer i : immutableList) {
      System.out.print(i + "-");
    }
    System.out.println();
    for (Integer i : immutableBiMap.keySet()) {
      System.out.print(immutableBiMap.get(i) + "-");
    }
    System.out.println();
    for (Integer i : immutableList) {
      System.out.print(i + "-");
    }
    System.out.println();
    for (Integer i : immutableCollection) {
      System.out.print(i + "-");
    }
    // 新集合类型
    ArrayList arrayList = new ArrayList();
    arrayList.toArray();
    // 集合工具
    // 扩展工具类
  }
コード例 #26
0
 @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();
 }
コード例 #27
0
  public ResponseLinking copyWithFilteredResponses(final Predicate<Response> toKeepCondition) {
    final Set<Response> newIncompletes = Sets.filter(incompleteResponses(), toKeepCondition);
    final ImmutableSet.Builder<ResponseSet> newResponseSetsB = ImmutableSet.builder();
    final ImmutableBiMap.Builder<String, ResponseSet> responseSetsIdB = ImmutableBiMap.builder();
    // to account for ResponseSets merging due to lost annotation
    final Set<ResponseSet> alreadyAdded = Sets.newHashSet();
    for (final ResponseSet responseSet : responseSets()) {
      final ImmutableSet<Response> okResponses =
          FluentIterable.from(responseSet.asSet()).filter(toKeepCondition).toSet();
      if (!okResponses.isEmpty()) {
        final ResponseSet newResponseSet = ResponseSet.from(okResponses);
        if (alreadyAdded.contains(newResponseSet)) {
          continue;
        }
        alreadyAdded.add(newResponseSet);
        newResponseSetsB.add(newResponseSet);
        if (responseSetIds().isPresent()) {
          responseSetsIdB.put(responseSetIds().get().inverse().get(responseSet), newResponseSet);
        }
      }
    }

    final ImmutableSet<ResponseSet> newResponseSets = newResponseSetsB.build();
    final ResponseLinking.Builder ret =
        ResponseLinking.builder()
            .docID(docID())
            .responseSets(newResponseSets)
            .incompleteResponses(newIncompletes);
    if (responseSetIds().isPresent()) {
      ret.responseSetIds(responseSetsIdB.build());
    }
    return ret.build();
  }
コード例 #28
0
  @Override
  public Expression visitTableScan(TableScanNode node, Void context) {
    if (!node.getGeneratedPartitions().isPresent()) {
      return BooleanLiteral.TRUE_LITERAL;
    }

    // The effective predicate can be computed from the intersection of the aggregate partition
    // TupleDomain summary (generated from Partitions)
    // and the TupleDomain that was initially used to generate those Partitions. We do this because
    // we need to select the more restrictive of the two.
    // Note: the TupleDomain used to generate the partitions may contain columns/predicates that are
    // unknown to the partition TupleDomain summary,
    // but those are guaranteed to be part of a FilterNode directly above this table scan, so it's
    // ok to include.
    TupleDomain tupleDomain =
        node.getPartitionsDomainSummary()
            .intersect(node.getGeneratedPartitions().get().getTupleDomainInput());

    // A TupleDomain that has too many disjunctions will produce an Expression that will be very
    // expensive to evaluate at runtime.
    // For the time being, we will just summarize the TupleDomain by the span over each of its
    // columns (which is ok since we only need to generate
    // an effective predicate here).
    // In the future, we can do further optimizations here that will simplify the TupleDomain, but
    // still improve the specificity compared to just a simple span (e.g. range clustering).
    tupleDomain = spanTupleDomain(tupleDomain);

    Expression partitionPredicate =
        DomainTranslator.toPredicate(
            tupleDomain, ImmutableBiMap.copyOf(node.getAssignments()).inverse());
    return pullExpressionThroughSymbols(partitionPredicate, node.getOutputSymbols());
  }
コード例 #29
0
ファイル: ImmutableBiMapTest.java プロジェクト: hinike/opera
 public void testOfWithDuplicateKey() {
   try {
     ImmutableBiMap.of("one", 1, "one", 1);
     fail();
   } catch (IllegalArgumentException expected) {
     assertEquals("duplicate key: one", expected.getMessage());
   }
 }
コード例 #30
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 public void testOfWithDuplicateKey() {
   try {
     ImmutableBiMap.of("one", 1, "one", 1);
     fail();
   } catch (IllegalArgumentException expected) {
     assertThat(expected.getMessage()).contains("one");
   }
 }