Java 类java.util.AbstractMap.SimpleImmutableEntry 实例源码

项目:bskyblock    文件:YamlResourceBundle.java   
/**
 * Flatten yaml tree structure.
 *
 * @param entry {@link Entry} of yaml tree.
 * @return {@link Stream} of entries
 */
private static Stream<Entry<String, Object>> flattenYamlTree(Entry<?, ?> entry) {
    String key = entry.getKey().toString();
    Object value = entry.getValue();
    if (value instanceof Map) {
        Map<?, ?> valueAsMap = (Map<?, ?>) value;
        return valueAsMap.entrySet().stream()
                .flatMap(YamlResourceBundle::flattenYamlTree)
                .map(e -> new SimpleImmutableEntry<>(key + "." + e.getKey(), e.getValue()));
    } else if (value instanceof List) {
        List<?> valueAsList = (List<?>) value;
        value = valueAsList.stream().toArray(String[]::new);
        AtomicInteger index = new AtomicInteger();
        return Stream.concat(
                Stream.of(new SimpleImmutableEntry<>(key, value)),
                valueAsList.stream()
                        .map(v -> new SimpleImmutableEntry<>(key + "[" + index.getAndIncrement() + "]", v))
        );
    }
    return Stream.of(new SimpleImmutableEntry<>(key, value));
}
项目:datapipelines-java    文件:DataPipeline.java   
@SuppressWarnings({"unchecked", "rawtypes"}) // Can't get specific generic types for new SinkHandler
private Entry<Set<SinkHandler<?, ?>>, Set<SinkHandler<?, ?>>> createSinkHandlers(final Class<?> before, final ChainTransform<?, ?> transform,
    final Class<?> after, final Set<DataSink> targets) {
    final Set<SinkHandler<?, ?>> beforeTransform = new HashSet<>();
    final Set<SinkHandler<?, ?>> afterTransform = new HashSet<>();
    for(final DataSink sink : targets) {
        final ChainTransform<?, ?> fromBefore = getBestTransform(before, sink.accepts());
        final ChainTransform<?, ?> fromAfter = getBestTransform(after, sink.accepts());

        if(fromBefore != null && fromAfter != null) {
            if(fromBefore.cost() < fromAfter.cost()) {
                beforeTransform.add(new SinkHandler(sink, fromBefore, fromBefore.from(), fromBefore.to()));
            } else {
                afterTransform.add(new SinkHandler(sink, fromAfter, fromAfter.from(), fromAfter.to()));
            }
        } else if(fromBefore != null) {
            beforeTransform.add(new SinkHandler(sink, fromBefore, fromBefore.from(), fromBefore.to()));
        } else if(fromAfter != null) {
            afterTransform.add(new SinkHandler(sink, fromAfter, fromAfter.from(), fromAfter.to()));
        }
    }
    return new SimpleImmutableEntry<>(beforeTransform, afterTransform);
}
项目:MicroServiceProject    文件:Recommender.java   
/**
 * 产生类似电影推荐
 * @throws Exception
 */
public List<String> getSimilarMovies(String movieId)throws Exception{
    int numTopNRanks = numRecs < 0 ? 10 : numRecs;
    int itemIdx = rateDao.getItemId(movieId);
    List<String> recommendationList = new ArrayList<String>();
    for (int u = 0,um = trainMatrix.numColumns();u<um;u++){
        if(u!=itemIdx){
            double score = Sims.pcc(trainMatrix.getColumns(u),trainMatrix.getColumns(itemIdx));
            List<Map.Entry<Integer, Double>> itemScores = new ArrayList<>();
            itemScores.add(new SimpleImmutableEntry<Integer,Double>(itemIdx,score));
            itemScores = Lists.sortListTopK(itemScores, true, numTopNRanks);
            List<Integer> rankedItems = new ArrayList<>(itemScores.size());
            for (Map.Entry<Integer, Double> kv : itemScores) {
                Integer item = kv.getKey();
                rankedItems.add(item);
            }
            for (int i = 0; i < rankedItems.size()&&i<10; i++) {
                recommendationList.add(rateDao.getItemId(rankedItems.get(i)));
            }
        }
    }
    return recommendationList;
}
项目:OpenJSharp    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:monarch    文件:MemoryIndexStore.java   
/**
 * Find the old key by traversing the forward map in case of in-place update modification If not
 * found it means the value object was modified with same value. So oldKey is same as newKey.
 * 
 * @return oldKey
 */
private Object getOldKey(Object newKey, RegionEntry entry) throws TypeMismatchException {
  for (Object mapEntry : valueToEntriesMap.entrySet()) {
    Object regionEntries = ((SimpleImmutableEntry) mapEntry).getValue();
    Object indexKey = ((SimpleImmutableEntry) mapEntry).getKey();
    // if more than one index key maps to the same RegionEntry that
    // means there has been an in-place modification
    if (TypeUtils.compare(indexKey, newKey, CompiledComparison.TOK_NE).equals(Boolean.TRUE)) {
      if (regionEntries instanceof RegionEntry && regionEntries.equals(entry)) {
        return indexKey;
      } else if (regionEntries instanceof Collection) {
        Collection coll = (Collection) regionEntries;
        if (coll.contains(entry)) {
          return indexKey;
        }
      }
    }
  }
  return newKey;
}
项目:jdk8u-jdk    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:aws-sdk-java-v2    文件:TypeConverter.java   
/**
 * Null-safely convert between two maps by applying a function to each key and value. A predicate is also specified to filter
 * the results, in case the mapping function were to generate duplicate keys, etc.
 */
public static <T1, T2, U1, U2> Map<U1, U2> convert(Map<T1, T2> toConvert,
                                                   Function<? super T1, ? extends U1> keyConverter,
                                                   Function<? super T2, ? extends U2> valueConverter,
                                                   BiPredicate<U1, U2> resultFilter) {
    if (toConvert == null) {
        return null;
    }

    Map<U1, U2> result = toConvert.entrySet().stream()
                                  .map(e -> new SimpleImmutableEntry<>(keyConverter.apply(e.getKey()),
                                                                       valueConverter.apply(e.getValue())))
                                  .filter(p -> resultFilter.test(p.getKey(), p.getValue()))
                                  .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
    return Collections.unmodifiableMap(result);
}
项目:openjdk-jdk10    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:PACE    文件:EntrySignerTest.java   
@Test
public void signVerifyInValueTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));

  MutableEntry signed;
  Entry<Key,Value> verified;

  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  signed = new MutableEntry(signer.sign(entry.toEntry(), true));
  assertThat("row should not have changed", signed.row, is(entry.row));
  assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
  assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
  assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
  assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
  assertThat("delete should not have changed", signed.delete, is(entry.delete));
  assertThat("value should have changed", signed.value, is(not(entry.value)));

  verified = verifier.verify(signed.toEntry());
  assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
项目:PACE    文件:EntrySignerTest.java   
@Test
public void signVerifyInSeparateTableTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));

  MutableEntry signed;
  Entry<Key,Value> verified;

  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  signed = new MutableEntry(signer.sign(entry.toEntry(), true));
  assertThat("row should not have changed", signed.row, is(entry.row));
  assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
  assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
  assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
  assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
  assertThat("delete should not have changed", signed.delete, is(entry.delete));
  assertThat("value should have changed", signed.value, is(not(entry.value)));

  verified = verifier.verify(entry.toEntry(), signed.toEntry());
  assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
项目:PACE    文件:EntrySignerTest.java   
@Test
public void hasNoTimestampTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
  MutableEntry signed;

  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  try {
    signed = new MutableEntry(signer.sign(entry.toEntry(), true));
    signed.timestamp = 1000L;
    verifier.verify(signed.toEntry());
    fail("changing the timestamp should cause the signature to fail");
  } catch (SignatureException e) { /* expected */}

  signed = new MutableEntry(signer.sign(entry.toEntry(), false));
  signed.timestamp = 1000L;
  verifier.verify(signed.toEntry());
}
项目:PACE    文件:EntrySignerTest.java   
@Test
public void badSignatureTest() throws Exception {
  MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
  Entry<Key,Value> signed;

  // Sign to value;
  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  signed = signer.sign(entry.toEntry(), true);
  entry.value = new byte[] {7};

  try {
    verifier.verify(entry.toEntry(), signed);
    fail("bad signature should thrown an exception");
  } catch (SignatureException e) { /* expected */}
}
项目:PACE    文件:SignedIteratorTest.java   
@Test
public void internalUnprocessedTest() throws Exception {
  EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
  EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));

  List<Entry<Key,Value>> entries = new ArrayList<>();
  byte[] row = new byte[] {1};
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
      false), new Value(new byte[] {4}));

  entries.add(signer.sign(entry, true));
  SignedInlineScannerIterator iterator = new SignedInlineScannerIterator(entries.iterator(), verifier);

  iterator.next();
  assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
项目:PACE    文件:SignedIteratorTest.java   
@Test
public void externalUnprocessedTest() throws Exception {
  EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
  EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));

  List<Entry<Key,Value>> entries = new ArrayList<>();
  List<Entry<Key,Value>> signedEntries = new ArrayList<>();

  byte[] row = new byte[] {1};
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
      false), new Value(new byte[] {4}));

  entries.add(entry);
  signedEntries.add(signer.sign(entry, true));

  SignedExternalScannerIterator iterator = new SignedExternalScannerIterator(entries.iterator(), signedEntries.iterator(), verifier, true);

  iterator.next();
  assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
项目:PACE    文件:EncryptedScannerIteratorTest.java   
@Test
public void hasNextTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  entries.add(encryptor.encrypt(entry));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()),
      new TreeSet<Column>());

  assertThat("has next item", iterator.hasNext(), is(true));
  assertThat("has next item", iterator.hasNext(), is(true));
  iterator.next();
  assertThat("does not have a next item", iterator.hasNext(), is(false));
}
项目:PACE    文件:EncryptedScannerIteratorTest.java   
@Test
public void nextTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  entries.add(encryptor.encrypt(entry));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()),
      new TreeSet<Column>());
  assertThat("next item is correct", iterator.next(), Matchers.equalTo(entry));

  try {
    iterator.next();
    fail("no items should be left");
  } catch (NoSuchElementException e) { /* expected */}
}
项目:PACE    文件:EncryptedScannerIteratorTest.java   
@Test
public void matchRangeTest() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0,
      false, false), new Value(new byte[] {4}));
  Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7}, "secret".getBytes(Utils.VISIBILITY_CHARSET),
      0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), new EntryEncryptor(getConfig("config.ini"), KEYS),
      Collections.singletonList(new Range()), new TreeSet<>());
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = new EncryptedScannerIterator(entries.iterator(), new EntryEncryptor(getConfig("config.ini"), KEYS), new ArrayList<Range>(),
      new TreeSet<Column>());
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = getIteratorForRange(entries, (byte) 1);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(1));

  iterator = getIteratorForRange(entries, (byte) 3);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(0));
}
项目:PACE    文件:EncryptedScannerIteratorTest.java   
@Test
public void matchColumnFilters() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0,
      false, false), new Value(new byte[] {4}));
  Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {2}, new byte[] {7}, "secret".getBytes(Utils.VISIBILITY_CHARSET),
      0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), new EntryEncryptor(getConfig("config.ini"), KEYS),
      Collections.singletonList(new Range()), new TreeSet<>());
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = getIteratorForColumn(entries, new byte[] {2}, null);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(2));

  iterator = getIteratorForColumn(entries, new byte[] {3}, null);
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(0));

  iterator = getIteratorForColumn(entries, new byte[] {2}, new byte[] {7});
  assertThat("correct number of items", Lists.newArrayList(iterator), hasSize(1));
}
项目:PACE    文件:EncryptedScannerIteratorTest.java   
@Test
public void removeException() throws Exception {
  EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);

  List<Entry<Key,Value>> entries = new ArrayList<>();
  Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  entries.add(encryptor.encrypt(entry));

  EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()), new TreeSet<>());

  try {
    iterator.remove();
    fail("remove not supported");
  } catch (UnsupportedOperationException e) { /* expected */}
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void setRangesSearchableTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("searchable-row.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("searchable-row.ini"), KEYS);
  scanner.setRanges(Collections.singletonList(new Range(new Text(new byte[] {1}))));
  assertThat("has correct number of elements", scanner, iterableWithSize(2));

  verify(mockScanner).setRanges(captor.capture());
  assertThat("correct number of ranges", captor.getValue(), hasSize(2));
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void fetchColumnFamilySemanticEncryptionTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("encrypt-key.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("encrypt-key.ini"), KEYS);
  assertThat("has correct number of elements", scanner, iterableWithSize(2));

  scanner.fetchColumnFamily(new Text(new byte[] {2}));
  assertThat("has correct number of elements", scanner, iterableWithSize(1));

  scanner.fetchColumnFamily(new Text(new byte[] {6}));
  assertThat("has correct number of elements", scanner, iterableWithSize(2));

  // Should not have been handled server side.
  verify(mockScanner, never()).fetchColumn(any());
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void fetchColumnFamilySearchableTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("searchable.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("searchable.ini"), KEYS);
  scanner.fetchColumnFamily(new Text(new byte[] {2}));
  assertThat("filtering is not happening client-side", scanner, iterableWithSize(2));
  verify(mockScanner, times(2)).fetchColumnFamily(any());
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void fetchColumnSemanticEncryptionTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("encrypt-key.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("encrypt-key.ini"), KEYS);
  assertThat("has correct number of elements", scanner, iterableWithSize(2));

  scanner.fetchColumn(new IteratorSetting.Column(new Text(new byte[] {2}), new Text(new byte[] {3})));
  assertThat("has correct number of elements", scanner, iterableWithSize(1));

  scanner.fetchColumn(new IteratorSetting.Column(new Text(new byte[] {6}), new Text(new byte[] {7})));
  assertThat("has correct number of elements", scanner, iterableWithSize(2));

  // Should not have been handled server side.
  verify(mockScanner, never()).fetchColumn(any());
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void fetchColumnSearchableTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("searchable.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("searchable.ini"), KEYS);
  scanner.fetchColumn(new Text(new byte[] {2}), new Text(new byte[] {3}));
  assertThat("filtering is not happening client-side", scanner, iterableWithSize(2));
  verify(mockScanner, times(4)).fetchColumn(any(), any());
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void fetchColumnPartiallySearchableTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("partially-searchable.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("partially-searchable.ini"), KEYS);
  scanner.fetchColumn(new Text(new byte[] {2}), new Text(new byte[] {3}));
  assertThat("filtering is partially happening client-side", scanner, iterableWithSize(1));
  verify(mockScanner, times(2)).fetchColumnFamily(any());
}
项目:PACE    文件:EncryptedBatchScannerTest.java   
@Test
public void clearColumnsTest() throws Exception {
  when(mockConnector.createBatchScanner(TEST_TABLE, authorizations, 1)).thenReturn(mockScanner);

  EntryEncryptor encryptor = new EntryEncryptor(getConfig("encrypt-key.ini"), KEYS);
  List<Map.Entry<Key,Value>> entries = new ArrayList<>();
  Map.Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
  Map.Entry<Key,Value> entry2 = new SimpleImmutableEntry<>(new Key(new byte[] {5}, new byte[] {6}, new byte[] {7},
      "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {8}));
  entries.add(encryptor.encrypt(entry));
  entries.add(encryptor.encrypt(entry2));
  when(mockScanner.iterator()).thenReturn(entries.iterator()).thenReturn(entries.iterator());

  BatchScanner scanner = new EncryptedBatchScanner(mockConnector, TEST_TABLE, authorizations, 1, getConfig("encrypt-key.ini"), KEYS);
  scanner.fetchColumn(new Text(new byte[] {2}), new Text(new byte[] {2}));
  assertThat("has correct number of elements", scanner, iterableWithSize(0));

  scanner.clearColumns();
  assertThat("has correct number of elements", scanner, iterableWithSize(2));
}
项目:openjdk9    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:redjob    文件:ExecutionResultUpdateListener.java   
/**
 * On job start register for updates.
 *
 * @param event
 *           Job start event.
 */
@EventListener(condition = "#event.worker instanceof T(com.s24.redjob.queue.QueueWorker)")
public void onJobStart(JobStart event) {
   Assert.notNull(event, "Pre-condition violated: event != null.");
   if (ignoreJob(event)) {
      return;
   }

   QueueWorker worker = event.getWorker();
   Execution execution = event.getExecution();

   handleJobStart(event);
   // Register execution for updates.
   executions.put(execution.getId(), new SimpleImmutableEntry<>(worker, execution));
   handleUpdate(execution);
}
项目:Java8CN    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:jdk8u_jdk    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:lookaside_java-1.8.0-openjdk    文件:DateTimeFormatterBuilder.java   
protected PrefixTree getTree(DateTimeParseContext context) {
    // prepare parse tree
    Set<String> regionIds = ZoneRulesProvider.getAvailableZoneIds();
    final int regionIdsSize = regionIds.size();
    Entry<Integer, PrefixTree> cached = context.isCaseSensitive()
                                        ? cachedPrefixTree : cachedPrefixTreeCI;
    if (cached == null || cached.getKey() != regionIdsSize) {
        synchronized (this) {
            cached = context.isCaseSensitive() ? cachedPrefixTree : cachedPrefixTreeCI;
            if (cached == null || cached.getKey() != regionIdsSize) {
                cached = new SimpleImmutableEntry<>(regionIdsSize, PrefixTree.newTree(regionIds, context));
                if (context.isCaseSensitive()) {
                    cachedPrefixTree = cached;
                } else {
                    cachedPrefixTreeCI = cached;
                }
            }
        }
    }
    return cached.getValue();
}
项目:solrplugins    文件:BidirectionalFacetResponseBuilder.java   
@Override
public void addEntry(LimitMinder<T, SimpleTermIndexKey> limitMinder, SimpleTermIndexKey facetKey, Deque<Entry<String, Object>> entryBuilder) throws IOException {
  ShardFacetCount sfc = counts[facetKey.index];
  TermDocEntry val = (TermDocEntry)sfc.val;
  String currentTerm = val.term;
  String docIdStr = val.docId;
  SolrDocument doc = val.doc;
  if (!limitMinder.updateEntry(currentTerm, docIdStr, doc, entryBuilder)) {
    Deque<Entry<String, SolrDocument>> docDeque = new ArrayDeque<>(4);
    docDeque.add(new SimpleImmutableEntry<>(docIdStr, doc));
    NamedList<Object> termEntry = new NamedList<>(2);
    if (val.termMetadata != null) {
      termEntry.add("termMetadata", val.termMetadata);
    }
    termEntry.add("docs", docDeque);
    Entry<String, Object> entry = new SimpleImmutableEntry<>(currentTerm, termEntry);
    limitMinder.addEntry(entry, entryBuilder);
  }
}
项目:openshift-elasticsearch-plugin    文件:ProjectRolesMappingSyncStrategy.java   
@Override
protected  void syncFromImpl(UserProjectCache cache, RolesMappingBuilder builder) {
    for (Entry<SimpleImmutableEntry<String, String>, Set<String>> userProjects : cache.getUserProjects()
            .entrySet()) {
        String username = userProjects.getKey().getKey();
        String token = userProjects.getKey().getValue();

        for (String project : userProjects.getValue()) {
            String projectRoleName = String.format("%s_%s", PROJECT_PREFIX, project.replace('.', '_'));

            builder.addUser(projectRoleName, username);
        }

        if (cache.isOperationsUser(username, token)) {
            builder.addUser(SearchGuardRolesMapping.ADMIN_ROLE, username);
            builder.addUser(SearchGuardRolesMapping.KIBANA_SHARED_ROLE, username);
        } else {
            //role mapping for user's kibana index
            String kibanaRoleName = SearchGuardRoles.formatUniqueKibanaRoleName(username);
            builder.addUser(kibanaRoleName, username);
        }
    }
}
项目:openshift-elasticsearch-plugin    文件:UserRolesMappingSyncStrategy.java   
@Override
protected void syncFromImpl(UserProjectCache cache, RolesMappingBuilder builder) {
    Set<String> opsUsers = new HashSet<>();
    for (Entry<SimpleImmutableEntry<String, String>, Set<String>> userProjects : cache.getUserProjects()
            .entrySet()) {
        String username = userProjects.getKey().getKey();
        String token = userProjects.getKey().getValue();

        if (cache.isOperationsUser(username, token)) {
            opsUsers.add(username);
        } else {
            String roleName = BaseRolesSyncStrategy.formatUserRoleName(username);
            builder.addUser(roleName, username);
        }
    }
    for (String user : opsUsers) {
        builder.addUser(SearchGuardRolesMapping.ADMIN_ROLE, user);
        builder.addUser(SearchGuardRolesMapping.KIBANA_SHARED_ROLE, user);
    }
}
项目:FMTech    文件:CronetUrlRequest.java   
private final UrlResponseInfo a(int paramInt, String[] paramArrayOfString)
{
  long l1;
  CronetUrlRequest.HeadersList localHeadersList;
  synchronized (this.d)
  {
    if (this.a == 0L) {
      return null;
    }
    l1 = this.a;
    localHeadersList = new CronetUrlRequest.HeadersList();
    int i1 = 0;
    if (i1 < paramArrayOfString.length)
    {
      localHeadersList.add(new AbstractMap.SimpleImmutableEntry(paramArrayOfString[i1], paramArrayOfString[(i1 + 1)]));
      i1 += 2;
    }
  }
  return new UrlResponseInfo(new ArrayList(this.l), paramInt, nativeGetHttpStatusText(l1), localHeadersList, nativeGetWasCached(l1), nativeGetNegotiatedProtocol(l1), nativeGetProxyServer(l1));
}
项目:hazelcast-jet    文件:ReadHdfsP.java   
@Override
@Nonnull
public List<Processor> get(int count) {
    Map<Integer, List<IndexedInputSplit>> processorToSplits =
            range(0, assignedSplits.size()).mapToObj(i -> new SimpleImmutableEntry<>(i, assignedSplits.get(i)))
                    .collect(groupingBy(e -> e.getKey() % count,
                            mapping(Entry::getValue, toList())));
    range(0, count)
            .forEach(processor -> processorToSplits.computeIfAbsent(processor, x -> emptyList()));
    InputFormat inputFormat = jobConf.getInputFormat();

    return processorToSplits
            .values().stream()
            .map(splits -> splits.isEmpty()
                    ? Processors.noopP().get()
                    : new ReadHdfsP<>(splits.stream()
                    .map(IndexedInputSplit::getSplit)
                    .map(split -> uncheckCall(() ->
                            inputFormat.getRecordReader(split, jobConf, NULL)))
                    .collect(toList()), mapper)
            ).collect(toList());
}
项目:InflatableDonkey    文件:AssetPool.java   
ItemElements<Asset, ByteString>
        assetChunks(List<Voodoo> voodoos, Map<ByteString, Asset> fileSignatureToAsset) {
    Map<Asset, List<ByteString>> map = voodoos.stream()
            .map(Voodoo::fileSignatureToChunkChecksumList)
            .map(Map::entrySet)
            .flatMap(Collection::stream)
            .filter(e -> {
                if (fileSignatureToAsset.containsKey(e.getKey())) {
                    return true;
                }
                logger.warn("-- assetChunks() - unreferenced signature: {}", e.getKey());
                return false;
            })
            .map(e -> new SimpleImmutableEntry<>(fileSignatureToAsset.get(e.getKey()), e.getValue()))
            .collect(toMap(Map.Entry::getKey,
                    Map.Entry::getValue,
                    (u, v) -> {
                        if (!u.equals(v)) {
                            logger.warn("-- assetChunks() - collision: {} {}", u, v);
                        }
                        return u;
                    }));
    return new ItemElements<>(map);
}
项目:InflatableDonkey    文件:VoodooChunkEncryptionKeyMapper.java   
Map<Integer, Set<Integer>>
        resolveChunkReferences(Map<Integer, StorageHostChunkList> containers, List<ChunkReference> references) {
    return references
            .stream()
            .map(cr -> {
                int containerIndex = (int) cr.getContainerIndex();
                if (!containers.containsKey(containerIndex)) {
                    logger.warn("-- containerChunkList() - bad container index: {}", containerIndex);
                    return null;
                }
                int chunkIndex = (int) cr.getChunkIndex();
                if (containers.get(containerIndex).getChunkInfoCount() < chunkIndex) {
                    logger.warn("-- containerChunkList() - bad chunk index: {}", chunkIndex);
                    return null;
                }
                return new SimpleImmutableEntry<>(containerIndex, chunkIndex);
            })
            .filter(Objects::nonNull)
            .collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())));
}
项目:InflatableDonkey    文件:BiMapSet.java   
public static <K, V> BiMapSet<K, V> from(Map<K, ? extends Collection<V>> map) {
    map.forEach((k, v) -> {
        if (k == null || v == null || v.contains(null)) {
            throw new NullPointerException("BiMapSet, null values not permitted");
        }
    });

    Map<K, Set<V>> kToVSet = map.entrySet()
            .stream()
            .flatMap(e -> e.getValue()
                    .stream()
                    .map(v -> new SimpleImmutableEntry<>(e.getKey(), v)))
            .collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())));

    Map<V, Set<K>> vToKSet = map.entrySet()
            .stream()
            .flatMap(e -> e.getValue()
                    .stream()
                    .map(v -> new SimpleImmutableEntry<>(v, e.getKey())))
            .collect(groupingBy(Map.Entry::getKey, mapping(Map.Entry::getValue, toSet())));

    return new BiMapSet(kToVSet, vToKSet);
}
项目:InflatableDonkey    文件:ServiceKeySetAssistant.java   
public static Map<Integer, Key<ECPrivateKey>>
        incongruentServiceKeys(Collection<Key<ECPrivateKey>> keys, Map<Integer, Set<KeyID>> serviceKeyIDs) {
    Map<KeyID, Key<ECPrivateKey>> map = keys.stream()
            .collect(toMap(Key::keyID, Function.identity()));
    return serviceKeyIDs.entrySet()
            .stream()
            .flatMap(e -> e
                    .getValue()
                    .stream()
                    .map(v -> new SimpleImmutableEntry<>(e.getKey(), v)))
            .filter(e -> map.containsKey(e.getValue()))
            .filter(e -> map
                    .get(e.getValue())
                    .publicKeyInfo()
                    .map(PublicKeyInfo::service)
                    .map(u -> !e.getKey().equals(u))
                    .orElse(false))
            .collect(toMap(Map.Entry::getKey, e -> map.get(e.getValue())));
}