下面列出了怎么用com.google.common.collect.LinkedListMultimap的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testCopyCredentialToHeaders() throws IOException {
ListMultimap<String, String> values = LinkedListMultimap.create();
values.put("Authorization", "token1");
values.put("Authorization", "token2");
values.put("Extra-Authorization", "token3");
values.put("Extra-Authorization", "token4");
when(credentials.getRequestMetadata(any(URI.class))).thenReturn(Multimaps.asMap(values));
ClientCall<String, Integer> interceptedCall =
interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata headers = new Metadata();
interceptedCall.start(listener, headers);
assertEquals(listener, call.responseListener);
assertEquals(headers, call.headers);
Iterable<String> authorization = headers.getAll(AUTHORIZATION);
Assert.assertArrayEquals(new String[]{"token1", "token2"},
Iterables.toArray(authorization, String.class));
Iterable<String> extraAuthorization = headers.getAll(EXTRA_AUTHORIZATION);
Assert.assertArrayEquals(new String[]{"token3", "token4"},
Iterables.toArray(extraAuthorization, String.class));
}
public static boolean checkDateTime(LinkedListMultimap<String, String> headers) {
long timestamp = getDateTime(headers);
if (timestamp > 0) {
long currentTime = System.currentTimeMillis();
if (timestamp + HttpKeys.REQUEST_TIME_LIMIT >= currentTime) {
return true;
} else {
LOG.warn("Request time is too skewed, requestTime=" + timestamp +
", currentTime=" + currentTime + ", skewed=" +
(currentTime - timestamp));
}
} else {
LOG.warn("Request time is not specified");
}
return false;
}
@Test
public void oauthClassesNotInClassPath() throws Exception {
ListMultimap<String, String> values = LinkedListMultimap.create();
values.put("Authorization", "token1");
when(credentials.getRequestMetadata(eq(expectedUri))).thenReturn(Multimaps.asMap(values));
assertNull(GoogleAuthLibraryCallCredentials.createJwtHelperOrNull(null));
GoogleAuthLibraryCallCredentials callCredentials =
new GoogleAuthLibraryCallCredentials(credentials, null);
callCredentials.applyRequestMetadata(new RequestInfoImpl(), executor, applier);
verify(credentials).getRequestMetadata(eq(expectedUri));
verify(applier).apply(headersCaptor.capture());
Metadata headers = headersCaptor.getValue();
Iterable<String> authorization = headers.getAll(AUTHORIZATION);
assertArrayEquals(new String[]{"token1"},
Iterables.toArray(authorization, String.class));
}
@Test
public void apply_fromConfiguration_unmappedColumnsAppend() {
Properties config = new Properties();
config.setProperty("contentTemplate.myTemplate.title", "TField");
config.setProperty("contentTemplate.myTemplate.unmappedColumnsMode", "APPEND");
setupConfig.initConfig(config);
ContentTemplate template = ContentTemplate.fromConfiguration("myTemplate");
Multimap<String, Object> keyVals = LinkedListMultimap.create();
keyVals.put("TField", "My Title");
keyVals.put("AField1", "A1Value");
StringBuilder target = new StringBuilder();
target.append("<!DOCTYPE html>\n<html lang='en'>\n<head>\n")
.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>\n")
.append("<title>My Title</title>\n</head>\n<body>\n")
.append("<div id='TField'>\n <p>TField:</p>\n <h1>My Title</h1>\n</div>\n")
.append("<div id='AField1'>\n <p>AField1:</p>\n <p><small>A1Value</small></p>\n</div>\n")
.append("</body>\n</html>\n");
assertEquals(target.toString(), template.apply(keyVals));
}
@BeforeClass
public static void beforeClass() {
Multimap<String,String> multimap = LinkedListMultimap.create();
multimap.clear();
multimap.put("MAKE_COLOR", "MAKE");
multimap.put("MAKE_COLOR", "COLOR");
multimap.put("COLOR_WHEELS", "COLOR");
multimap.put("COLOR_WHEELS", "WHEELS");
multimap.put("TEAM_NAME_POINTS", "TEAM");
multimap.put("TEAM_NAME_POINTS", "NAME");
multimap.put("TEAM_NAME_POINTS", "POINTS");
multimap.put("TEAM_POINTS", "TEAM");
multimap.put("TEAM_POINTS", "POINTS");
compositeToFieldMap = Multimaps.unmodifiableMultimap(multimap);
Map<String,String> sepMap = new HashMap<>();
sepMap.put("MAKE_COLOR", ",");
sepMap.put("COLOR_WHEELS", ",");
sepMap.put("TEAM_NAME_POINTS", ",");
sepMap.put("TEAM_POINTS", ",");
compositeFieldSeparators = Collections.unmodifiableMap(sepMap);
}
@Test
public void test12() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO", "GEO");
compositeToFieldMap.put("GEO", "WKT_BYTE_LENGTH");
conf.setCompositeToFieldMap(compositeToFieldMap);
Map<String,String> compositeToSeparatorMap = new HashMap<>();
compositeToSeparatorMap.put("GEO", ",");
conf.setCompositeFieldSeparators(compositeToSeparatorMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "((GEO >= '1f0155640000000000' && GEO <= '1f01556bffffffffff') || GEO == '00' || (GEO >= '0100' && GEO <= '0103')) && (WKT_BYTE_LENGTH >= '"
+ Normalizer.NUMBER_NORMALIZER.normalize("0") + "' && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "')";
String expected = "(((GEO >= '1f0155640000000000,+AE0' && GEO <= '1f01556bffffffffff,+eE1.2345') && ((ASTEvaluationOnly = true) && ((GEO >= '1f0155640000000000' && GEO <= '1f01556bffffffffff') && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))) || ((GEO >= '00,+AE0' && GEO <= '00,+eE1.2345') && ((ASTEvaluationOnly = true) && (GEO == '00' && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))) || ((GEO >= '0100,+AE0' && GEO <= '0103,+eE1.2345') && ((ASTEvaluationOnly = true) && ((GEO >= '0100' && GEO <= '0103') && (WKT_BYTE_LENGTH >= '+AE0' && WKT_BYTE_LENGTH <= '+eE1.2345')))))";
runTestQuery(query, expected, indexedFields, conf);
}
@Test
public void test14() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO", "GEO");
compositeToFieldMap.put("GEO", "WKT_BYTE_LENGTH");
conf.setCompositeToFieldMap(compositeToFieldMap);
Map<String,String> compositeToSeparatorMap = new HashMap<>();
compositeToSeparatorMap.put("GEO", ",");
conf.setCompositeFieldSeparators(compositeToSeparatorMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "(GEO >= '0100' && GEO <= '0103') && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "'";
String expected = "(GEO >= '0100' && GEO <= '0103,+eE1.2345') && ((ASTEvaluationOnly = true) && ((GEO >= '0100' && GEO <= '0103') && WKT_BYTE_LENGTH <= '+eE1.2345'))";
runTestQuery(query, expected, indexedFields, conf);
}
@Test
public void test15() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO", "GEO");
compositeToFieldMap.put("GEO", "WKT_BYTE_LENGTH");
conf.setCompositeToFieldMap(compositeToFieldMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "GEO >= '0100' && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "'";
String expected = "GEO >= '0100' && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "'";
runTestQuery(query, expected, indexedFields, conf);
}
/**
* Populate internal map to translate between incoming message event type and saga type.
*/
private Multimap<Class, SagaType> initializeMessageMappings(final Map<Class<? extends Saga>, SagaHandlersMap> handlersMap) {
Multimap<Class, SagaType> scannedTypes = LinkedListMultimap.create();
for (Map.Entry<Class<? extends Saga>, SagaHandlersMap> entry : handlersMap.entrySet()) {
Class<? extends Saga> sagaClass = entry.getKey();
Collection<MessageHandler> sagaHandlers = entry.getValue().messageHandlers();
for (MessageHandler handler : sagaHandlers) {
// remember all message types where a completely new saga needs to be started.
if (handler.getStartsSaga()) {
scannedTypes.put(handler.getMessageType(), SagaType.startsNewSaga(sagaClass));
} else {
scannedTypes.put(handler.getMessageType(), SagaType.continueSaga(sagaClass));
}
}
}
return scannedTypes;
}
@Test
public void testCopyCredentialToHeaders() throws IOException {
ListMultimap<String, String> values = LinkedListMultimap.create();
values.put("Authorization", "token1");
values.put("Authorization", "token2");
values.put("Extra-Authorization", "token3");
values.put("Extra-Authorization", "token4");
when(credentials.getRequestMetadata(any(URI.class))).thenReturn(Multimaps.asMap(values));
ClientCall<String, Integer> interceptedCall =
interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
Metadata headers = new Metadata();
interceptedCall.start(listener, headers);
assertEquals(listener, call.responseListener);
assertEquals(headers, call.headers);
Iterable<String> authorization = headers.getAll(AUTHORIZATION);
Assert.assertArrayEquals(new String[]{"token1", "token2"},
Iterables.toArray(authorization, String.class));
Iterable<String> extraAuthorization = headers.getAll(EXTRA_AUTHORIZATION);
Assert.assertArrayEquals(new String[]{"token3", "token4"},
Iterables.toArray(extraAuthorization, String.class));
}
@Test
public void test23() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO_WKT", "GEO");
compositeToFieldMap.put("GEO_WKT", "WKT");
conf.setCompositeToFieldMap(compositeToFieldMap);
Map<String,String> compositeToSeparatorMap = new HashMap<>();
compositeToSeparatorMap.put("GEO_WKT", ",");
conf.setCompositeFieldSeparators(compositeToSeparatorMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "((((GEO >= '0202' && GEO <= '020d'))) || (((GEO >= '030a' && GEO <= '0335'))) || (((GEO >= '0428' && GEO <= '0483'))) || (((GEO >= '0500aa' && GEO <= '050355'))) || (((GEO >= '1f0aaaaaaaaaaaaaaa' && GEO <= '1f36c71c71c71c71c7')))) && ((WKT >= '+AE0' && WKT < '+bE4'))";
String expected = "(((((GEO_WKT >= '0202,+AE0' && GEO_WKT < '020d,+bE4') && ((ASTEvaluationOnly = true) && ((GEO >= '0202' && GEO <= '020d') && (WKT >= '+AE0' && WKT < '+bE4')))))) || ((((GEO_WKT >= '030a,+AE0' && GEO_WKT < '0335,+bE4') && ((ASTEvaluationOnly = true) && ((GEO >= '030a' && GEO <= '0335') && (WKT >= '+AE0' && WKT < '+bE4')))))) || ((((GEO_WKT >= '0428,+AE0' && GEO_WKT < '0483,+bE4') && ((ASTEvaluationOnly = true) && ((GEO >= '0428' && GEO <= '0483') && (WKT >= '+AE0' && WKT < '+bE4')))))) || ((((GEO_WKT >= '0500aa,+AE0' && GEO_WKT < '050355,+bE4') && ((ASTEvaluationOnly = true) && ((GEO >= '0500aa' && GEO <= '050355') && (WKT >= '+AE0' && WKT < '+bE4')))))) || ((((GEO_WKT >= '1f0aaaaaaaaaaaaaaa,+AE0' && GEO_WKT < '1f36c71c71c71c71c7,+bE4') && ((ASTEvaluationOnly = true) && ((GEO >= '1f0aaaaaaaaaaaaaaa' && GEO <= '1f36c71c71c71c71c7') && (WKT >= '+AE0' && WKT < '+bE4')))))))";
runTestQuery(query, expected, indexedFields, conf);
}
@Test
public void test24() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO_WKT", "GEO");
compositeToFieldMap.put("GEO_WKT", "WKT");
conf.setCompositeToFieldMap(compositeToFieldMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "((((GEO >= '0202' && GEO <= '020d'))) || (((GEO >= '030a' && GEO <= '0335'))) || (((GEO >= '0428' && GEO <= '0483'))) || (((GEO >= '0500aa' && GEO <= '050355'))) || (((GEO >= '1f0aaaaaaaaaaaaaaa' && GEO <= '1f36c71c71c71c71c7'))))";
String expected = "((((GEO >= '0202' && GEO <= '020d'))) || (((GEO >= '030a' && GEO <= '0335'))) || (((GEO >= '0428' && GEO <= '0483'))) || (((GEO >= '0500aa' && GEO <= '050355'))) || (((GEO >= '1f0aaaaaaaaaaaaaaa' && GEO <= '1f36c71c71c71c71c7'))))";
runTestQuery(query, expected, indexedFields, conf);
}
@Test
public void test27() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO", "GEO");
compositeToFieldMap.put("GEO", "WKT");
conf.setCompositeToFieldMap(compositeToFieldMap);
Map<String,String> compositeToSeparatorMap = new HashMap<>();
compositeToSeparatorMap.put("GEO", ",");
conf.setCompositeFieldSeparators(compositeToSeparatorMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String normNum = Normalizer.NUMBER_NORMALIZER.normalize("55");
String query = "(GEO == '0202' || ((GEO >= '030a' && GEO <= '0335'))) && WKT == '" + normNum + "'";
String expected = "(GEO == '0202,+bE5.5' || (((GEO >= '030a,+bE5.5' && GEO <= '0335,+bE5.5') && ((ASTEvaluationOnly = true) && ((GEO >= '030a' && GEO <= '0335') && WKT == '+bE5.5')))))";
runTestQuery(query, expected, indexedFields, conf);
}
@Test
public void test29() throws Exception {
ShardQueryConfiguration conf = new ShardQueryConfiguration();
Multimap<String,String> compositeToFieldMap = LinkedListMultimap.create();
compositeToFieldMap.put("GEO", "GEO");
compositeToFieldMap.put("GEO", "WKT");
conf.setCompositeToFieldMap(compositeToFieldMap);
Map<String,String> compositeToSeparatorMap = new HashMap<>();
compositeToSeparatorMap.put("GEO", ",");
conf.setCompositeFieldSeparators(compositeToSeparatorMap);
Set<String> indexedFields = new HashSet<>();
indexedFields.add("GEO");
conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
String query = "(GEO == '0202' || GEO >= '030a') && WKT == '+bE5.5'";
String expected = "((WKT == '+bE5.5' && GEO >= '030a') || GEO == '0202,+bE5.5')";
runTestQuery(query, expected, indexedFields, conf);
}
/**
* Clone this payload
*/
@Override
public IBaseDataObject clone() throws CloneNotSupportedException {
final BaseDataObject c = (BaseDataObject) super.clone();
if ((this.theData != null) && (this.theData.length > 0)) {
c.setData(this.theData, 0, this.theData.length);
}
c.currentForm = new ArrayList<>(this.currentForm);
c.history = new ArrayList<>(this.history);
c.multipartAlternative = new HashMap<>(this.multipartAlternative);
c.priority = this.priority;
c.creationTimestamp = this.creationTimestamp;
if ((this.extractedRecords != null) && !this.extractedRecords.isEmpty()) {
c.clearExtractedRecords(); // remove super.clone copy
for (final IBaseDataObject r : this.extractedRecords) {
c.addExtractedRecord(r.clone());
}
}
// This creates a deep copy Guava style
c.parameters = LinkedListMultimap.create(this.parameters);
return c;
}
/**
* Find clashes by name.
*
* @param myPolyMember
* current validated Polyfill
* @param pivotPolyMember
* other polyfill in same project
* @return pairs of contrandicting or same polyfills.
*/
private ListMultimap<TMember, TMember> findClashingMembersByName(EList<TMember> myPolyMember,
EList<TMember> pivotPolyMember) {
ListMultimap<TMember, TMember> ret = LinkedListMultimap.create();
for (TMember my : myPolyMember) {
String myName = my.getName();
if (myName == null)
continue; // broken AST
for (TMember other : pivotPolyMember) {
String otherName = other.getName();
if (myName.equals(otherName)) {
ret.put(my, other);
}
}
}
return ret;
}
@Override
public ImmutableMultimap<Attribute, Label> computeAspectDependencies(
Target target, DependencyFilter dependencyFilter) throws InterruptedException {
if (!(target instanceof Rule)) {
return ImmutableMultimap.of();
}
Rule rule = (Rule) target;
if (!rule.hasAspects()) {
return ImmutableMultimap.of();
}
Multimap<Attribute, Label> result = LinkedListMultimap.create();
Multimap<Attribute, Label> transitions =
rule.getTransitions(DependencyFilter.NO_NODEP_ATTRIBUTES);
for (Attribute attribute : transitions.keySet()) {
for (Aspect aspect : attribute.getAspects(rule)) {
if (hasDepThatSatisfies(aspect, transitions.get(attribute))) {
AspectDefinition.forEachLabelDepFromAllAttributesOfAspect(
rule, aspect, dependencyFilter, result::put);
}
}
}
return ImmutableMultimap.copyOf(result);
}
public void register(BeanFactory beanFactory, String key, SpringValue springValue) {
if (!registry.containsKey(beanFactory)) {
synchronized (LOCK) {
if (!registry.containsKey(beanFactory)) {
registry.put(beanFactory, Multimaps.synchronizedListMultimap(LinkedListMultimap.<String, SpringValue>create()));
}
}
}
registry.get(beanFactory).put(key, springValue);
// lazy initialize
if (initialized.compareAndSet(false, true)) {
initialize();
}
}
/**
* Verifies that a traversal of a well-formed DAG proceeds as expected.
*
* <pre>
* A
* / \
* B C
* / \ /
* D E
* \ /
* F
* </pre>
*/
@Test
public void testExpectedTraversal() throws CycleException {
Multimap<Node, Node> graph = LinkedListMultimap.create();
graph.put(Node.A, Node.B);
graph.put(Node.A, Node.C);
graph.put(Node.B, Node.D);
graph.put(Node.B, Node.E);
graph.put(Node.C, Node.E);
graph.put(Node.D, Node.F);
graph.put(Node.E, Node.F);
TestDagDepthFirstSearch dfs = new TestDagDepthFirstSearch(graph);
dfs.traverse(ImmutableList.of(Node.A));
ImmutableList<Node> expectedExploredNodes =
ImmutableList.of(Node.F, Node.D, Node.E, Node.B, Node.C, Node.A);
assertEquals(expectedExploredNodes, dfs.exploredNodes);
assertEquals(expectedExploredNodes.size(), dfs.numFindChildrenCalls);
}
private void checkQuotaLimitNamesAreUnique(Quota quota) {
ListMultimap<String, QuotaLimit> limitNameCounts = LinkedListMultimap.create();
for (QuotaLimit limit : quota.getLimitsList()) {
limitNameCounts.put(limit.getName(), limit);
}
for (String limitName : limitNameCounts.keySet()) {
List<QuotaLimit> limits = limitNameCounts.get(limitName);
if (limits.size() > 1) {
error(
MessageLocationContext.create(Iterables.getLast(limits), "name"),
"There are %d quota limits with name '%s'.",
limits.size(),
limitName);
}
}
}
@Test
public void builderPutAllMultimap() {
Multimap<String, Integer> toPut = LinkedListMultimap.create();
toPut.put("foo", 1);
toPut.put("bar", 4);
toPut.put("foo", 2);
toPut.put("foo", 3);
Multimap<String, Integer> moreToPut = LinkedListMultimap.create();
moreToPut.put("foo", 6);
moreToPut.put("bar", 5);
moreToPut.put("foo", 7);
ImmutableSortedKeyListMultimap.Builder<String, Integer> builder
= ImmutableSortedKeyListMultimap.builder();
builder.putAll(toPut);
builder.putAll(moreToPut);
Multimap<String, Integer> multimap = builder.build();
assertThat(multimap).valuesForKey("foo").containsExactly(1, 2, 3, 6, 7).inOrder();
assertThat(multimap).valuesForKey("bar").containsExactly(4, 5).inOrder();
assertThat(multimap).hasSize(7);
}
/**
* Create a mapping of rules based on rule type and family.
*/
private void createRuleMapping(Iterable<RuleDocumentation> docEntries,
Map<String, ListMultimap<RuleType, RuleDocumentation>> ruleMapping)
throws BuildEncyclopediaDocException {
for (RuleDocumentation ruleDoc : docEntries) {
RuleClass ruleClass = ruleClassProvider.getRuleClassMap().get(ruleDoc.getRuleName());
if (ruleClass != null) {
String ruleFamily = ruleDoc.getRuleFamily();
if (!ruleMapping.containsKey(ruleFamily)) {
ruleMapping.put(ruleFamily, LinkedListMultimap.<RuleType, RuleDocumentation>create());
}
if (ruleClass.isDocumented()) {
ruleMapping.get(ruleFamily).put(ruleDoc.getRuleType(), ruleDoc);
}
} else {
throw ruleDoc.createException("Can't find RuleClass for " + ruleDoc.getRuleName());
}
}
}
/**
* Verifies that the reported cycle mentions only A, B, and D, but not C or E.
*
* <pre>
* A <---|
* / |
* B |
* / | \ |
* C D E |
* | |
* ==========|
* </pre>
*/
@Test
public void testCycleExceptionDoesNotContainUnrelatedNodes() {
Multimap<Node, Node> graph = LinkedListMultimap.create();
graph.put(Node.A, Node.B);
graph.put(Node.B, Node.C);
graph.put(Node.B, Node.D);
graph.put(Node.B, Node.E);
graph.put(Node.D, Node.A);
TestDagDepthFirstSearch dfs = new TestDagDepthFirstSearch(graph);
try {
dfs.traverse(ImmutableList.of(Node.A));
} catch (CycleException e) {
assertThat(
e.getMessage(),
Matchers.containsString(
linesToText(
"The following circular dependency has been found:", "A -> B -> D -> A")));
assertEquals(ImmutableList.of(Node.A, Node.B, Node.D, Node.A), e.getCycle());
}
}
/**
* Sign the specified http request.
*
* @param httpMethod The http request method
* @param uri The uri string
* @param httpHeaders The http request headers
* @param secretAccessKeyId The user's secret access key
* @param algorithm The sign algorithm
* @return Byte buffer of the signed result
* @throws java.security.NoSuchAlgorithmException
* @throws java.security.InvalidKeyException
*/
public static byte[] sign(HttpMethod httpMethod, URI uri,
LinkedListMultimap<String, String> httpHeaders, String secretAccessKeyId,
SignAlgorithm algorithm) throws NoSuchAlgorithmException,
InvalidKeyException {
Preconditions.checkNotNull(httpMethod, "Http method");
Preconditions.checkNotNull(uri, "uri");
Preconditions.checkNotNull(secretAccessKeyId, "secret access key");
Preconditions.checkNotNull(algorithm, "algorithm");
String stringToSign = constructStringToSign(httpMethod,
uri, httpHeaders);
Mac mac = Mac.getInstance(algorithm.name());
mac.init(new SecretKeySpec(secretAccessKeyId.getBytes(), algorithm.name()));
return mac.doFinal(stringToSign.getBytes());
}
public StateChangeNotifier(DAG dag) {
this.dag = dag;
this.vertexListeners = Multimaps.synchronizedSetMultimap(
HashMultimap.<TezVertexID, ListenerContainer>create());
this.lastKnowStatesMap = LinkedListMultimap.create();
startThread();
}
static String constructStringToSign(HttpMethod httpMethod, URI uri,
LinkedListMultimap<String, String> httpHeaders) {
StringBuilder builder = new StringBuilder();
builder.append(httpMethod.name()).append("\n");
builder.append(checkAndGet(httpHeaders,
HttpKeys.CONTENT_MD5).get(0)).append("\n");
builder.append(checkAndGet(httpHeaders,
HttpKeys.CONTENT_TYPE).get(0)).append("\n");
long expires;
if ((expires = getExpires(uri)) > 0) {
// For pre-signed URI
builder.append(expires).append("\n");
} else {
String xiaomiDate = checkAndGet(httpHeaders, XIAOMI_DATE).get(0);
String date = "";
if ("".equals(xiaomiDate)) {
date = checkAndGet(httpHeaders, HttpKeys.DATE).get(0);
}
builder.append(checkAndGet(date)).append("\n");
}
builder.append(canonicalizeXiaomiHeaders(httpHeaders));
builder.append(canonicalizeResource(uri));
return builder.toString();
}
@Test
public void testTemplateApplyWithAppends() {
// build template
String title = "TField";
List<String> high = new ArrayList<>(Arrays.asList("HField1", "HField2"));
List<String> med = new ArrayList<>(Arrays.asList("MField1"));
List<String> low = new ArrayList<>(Arrays.asList("LField3", "LField2", "LField1"));
ContentTemplate template = new Builder().setTitle(title)
.setUnmappedColumnMode(UnmappedColumnsMode.APPEND)
.setHighContent(high).setMediumContent(med).setLowContent(low).build();
// apply map key/values
Multimap<String, Object> keyVals = LinkedListMultimap.create();
keyVals.put("TField", "My Title");
keyVals.put("HField1", "H1Value");
keyVals.put("HField2", "H2Value");
keyVals.put("MField1", "M1Value");
keyVals.put("LField1", "L1Value");
keyVals.put("LField2", "L2Value");
keyVals.put("LField3", "L3Value");
keyVals.put("AField1", "A1Value");
keyVals.put("AField2", "A2Value");
// build target
StringBuilder target = new StringBuilder();
target.append("<!DOCTYPE html>\n<html lang='en'>\n<head>\n")
.append("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>\n")
.append("<title>My Title</title>\n</head>\n<body>\n")
.append("<div id='TField'>\n <p>TField:</p>\n <h1>My Title</h1>\n</div>\n")
.append("<div id='HField1'>\n <p>HField1:</p>\n <h1>H1Value</h1>\n</div>\n")
.append("<div id='HField2'>\n <p>HField2:</p>\n <h1>H2Value</h1>\n</div>\n")
.append("<div id='MField1'>\n <p>MField1:</p>\n <p>M1Value</p>\n</div>\n")
.append("<div id='LField3'>\n <p>LField3:</p>\n <p><small>L3Value</small></p>\n</div>\n")
.append("<div id='LField2'>\n <p>LField2:</p>\n <p><small>L2Value</small></p>\n</div>\n")
.append("<div id='LField1'>\n <p>LField1:</p>\n <p><small>L1Value</small></p>\n</div>\n")
.append("<div id='AField1'>\n <p>AField1:</p>\n <p><small>A1Value</small></p>\n</div>\n")
.append("<div id='AField2'>\n <p>AField2:</p>\n <p><small>A2Value</small></p>\n</div>\n")
.append("</body>\n</html>\n");
assertEquals(target.toString(), template.apply(keyVals));
}
@Override
public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world)
{
Multimap<String, Ticket> persistentPlayerTickets = HashMultimap.create();
LinkedListMultimap<String, Ticket> claimedTickets = LinkedListMultimap.create();
//int i = 0;
for (String player : tickets.keys())
{
//System.out.println("playerTicketsLoaded(): looping outer start: " + i);
for (Ticket ticket : tickets.get(player))
{
if (ticket != null)
{
/*if (ticket.world != null && ticket.world.provider != null) { System.out.println("playerTicketsLoaded(): looping: " + i + " world: " + world + " dim: " + ticket.world.provider.getDimensionId()); }
else { System.out.println("playerTicketsLoaded(): looping: " + i + " world: " + world); }
++i;*/
NBTTagCompound nbt = ticket.getModData();
// Only claim tickets that are used for persistent chunk loading
if (nbt != null && nbt.getBoolean("Persistent"))
{
//System.out.println("playerTicketsLoaded(): found persistent ticket");
persistentPlayerTickets.put(player, ticket);
}
}
}
}
claimedTickets.putAll(persistentPlayerTickets);
return claimedTickets;
}
@Test
public void builderPutNullValue() {
Multimap<String, Integer> toPut = LinkedListMultimap.create();
toPut.put(null, 1);
ImmutableSortedKeyListMultimap.Builder<String, Integer> builder
= ImmutableSortedKeyListMultimap.builder();
assertThrows(NullPointerException.class, () -> builder.put("foo", null));
assertThrows(
NullPointerException.class, () -> builder.putAll("foo", Arrays.asList(1, null, 3)));
assertThrows(NullPointerException.class, () -> builder.putAll("foo", 1, null, 3));
assertThrows(NullPointerException.class, () -> builder.putAll(toPut));
}
/**
* Constructor
*
* @param serializationClassName serialization class to be used
* @param key key class name
* @param val value class name
* @param comparator to be used
* @param correctComparator (real comparator to be used for correct results)
* @param testResult expected result
* @throws IOException
*/
public TestValuesIterator(String serializationClassName, Class key, Class val,
TestWithComparator comparator, TestWithComparator correctComparator, boolean testResult)
throws IOException {
this.keyClass = key;
this.valClass = val;
this.comparator = getComparator(comparator);
this.correctComparator =
(correctComparator == null) ? this.comparator : getComparator(correctComparator);
this.expectedTestResult = testResult;
originalData = LinkedListMultimap.create();
setupConf(serializationClassName);
}