use of java.util.AbstractMap.SimpleEntry in project chassis by Kixeye.
the class ConfigurationBuilderTest method zookeeperOverridesApplicationProperties.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void zookeeperOverridesApplicationProperties() throws Exception {
String key1 = UUID.randomUUID().toString();
String value1 = UUID.randomUUID().toString();
String key2 = UUID.randomUUID().toString();
String value2 = UUID.randomUUID().toString();
TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(key1, value1), new SimpleEntry(key2, value2));
curatorFramework.create().creatingParentsIfNeeded().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + key1, "zookeepervalue".getBytes());
configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
configurationBuilder.withApplicationProperties(TEST_APP_CONFIG_PROPERTIES_SPRING_PATH);
Configuration configuration = configurationBuilder.build();
//assert that the zookeeper config overrode the app properties config
Assert.assertEquals("zookeepervalue", configuration.getString(key1));
//assert that the proper which exists in app properties but not in zookeeper is found.
Assert.assertEquals(value2, configuration.getString(key2));
}
use of java.util.AbstractMap.SimpleEntry in project lucene-solr by apache.
the class TestInputIterator method testTerms.
public void testTerms() throws Exception {
Random random = random();
int num = atLeast(10000);
TreeMap<BytesRef, SimpleEntry<Long, BytesRef>> sorted = new TreeMap<>();
TreeMap<BytesRef, Long> sortedWithoutPayload = new TreeMap<>();
TreeMap<BytesRef, SimpleEntry<Long, Set<BytesRef>>> sortedWithContext = new TreeMap<>();
TreeMap<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>> sortedWithPayloadAndContext = new TreeMap<>();
Input[] unsorted = new Input[num];
Input[] unsortedWithoutPayload = new Input[num];
Input[] unsortedWithContexts = new Input[num];
Input[] unsortedWithPayloadAndContext = new Input[num];
Set<BytesRef> ctxs;
for (int i = 0; i < num; i++) {
BytesRef key;
BytesRef payload;
ctxs = new HashSet<>();
do {
key = new BytesRef(TestUtil.randomUnicodeString(random));
payload = new BytesRef(TestUtil.randomUnicodeString(random));
for (int j = 0; j < atLeast(2); j++) {
ctxs.add(new BytesRef(TestUtil.randomUnicodeString(random)));
}
} while (sorted.containsKey(key));
long value = random.nextLong();
sortedWithoutPayload.put(key, value);
sorted.put(key, new SimpleEntry<>(value, payload));
sortedWithContext.put(key, new SimpleEntry<>(value, ctxs));
sortedWithPayloadAndContext.put(key, new SimpleEntry<>(value, new SimpleEntry<>(payload, ctxs)));
unsorted[i] = new Input(key, value, payload);
unsortedWithoutPayload[i] = new Input(key, value);
unsortedWithContexts[i] = new Input(key, value, ctxs);
unsortedWithPayloadAndContext[i] = new Input(key, value, payload, ctxs);
}
// test the sorted iterator wrapper with payloads
try (Directory tempDir = getDirectory()) {
InputIterator wrapper = new SortedInputIterator(tempDir, "sorted", new InputArrayIterator(unsorted));
Iterator<Map.Entry<BytesRef, SimpleEntry<Long, BytesRef>>> expected = sorted.entrySet().iterator();
while (expected.hasNext()) {
Map.Entry<BytesRef, SimpleEntry<Long, BytesRef>> entry = expected.next();
assertEquals(entry.getKey(), wrapper.next());
assertEquals(entry.getValue().getKey().longValue(), wrapper.weight());
assertEquals(entry.getValue().getValue(), wrapper.payload());
}
assertNull(wrapper.next());
}
// test the sorted iterator wrapper with contexts
try (Directory tempDir = getDirectory()) {
InputIterator wrapper = new SortedInputIterator(tempDir, "sorted", new InputArrayIterator(unsortedWithContexts));
Iterator<Map.Entry<BytesRef, SimpleEntry<Long, Set<BytesRef>>>> actualEntries = sortedWithContext.entrySet().iterator();
while (actualEntries.hasNext()) {
Map.Entry<BytesRef, SimpleEntry<Long, Set<BytesRef>>> entry = actualEntries.next();
assertEquals(entry.getKey(), wrapper.next());
assertEquals(entry.getValue().getKey().longValue(), wrapper.weight());
Set<BytesRef> actualCtxs = entry.getValue().getValue();
assertEquals(actualCtxs, wrapper.contexts());
}
assertNull(wrapper.next());
}
// test the sorted iterator wrapper with contexts and payload
try (Directory tempDir = getDirectory()) {
InputIterator wrapper = new SortedInputIterator(tempDir, "sorter", new InputArrayIterator(unsortedWithPayloadAndContext));
Iterator<Map.Entry<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>>> expectedPayloadContextEntries = sortedWithPayloadAndContext.entrySet().iterator();
while (expectedPayloadContextEntries.hasNext()) {
Map.Entry<BytesRef, SimpleEntry<Long, SimpleEntry<BytesRef, Set<BytesRef>>>> entry = expectedPayloadContextEntries.next();
assertEquals(entry.getKey(), wrapper.next());
assertEquals(entry.getValue().getKey().longValue(), wrapper.weight());
Set<BytesRef> actualCtxs = entry.getValue().getValue().getValue();
assertEquals(actualCtxs, wrapper.contexts());
BytesRef actualPayload = entry.getValue().getValue().getKey();
assertEquals(actualPayload, wrapper.payload());
}
assertNull(wrapper.next());
}
// test the unsorted iterator wrapper with payloads
InputIterator wrapper = new UnsortedInputIterator(new InputArrayIterator(unsorted));
TreeMap<BytesRef, SimpleEntry<Long, BytesRef>> actual = new TreeMap<>();
BytesRef key;
while ((key = wrapper.next()) != null) {
long value = wrapper.weight();
BytesRef payload = wrapper.payload();
actual.put(BytesRef.deepCopyOf(key), new SimpleEntry<>(value, BytesRef.deepCopyOf(payload)));
}
assertEquals(sorted, actual);
// test the sorted iterator wrapper without payloads
try (Directory tempDir = getDirectory()) {
InputIterator wrapperWithoutPayload = new SortedInputIterator(tempDir, "sorted", new InputArrayIterator(unsortedWithoutPayload));
Iterator<Map.Entry<BytesRef, Long>> expectedWithoutPayload = sortedWithoutPayload.entrySet().iterator();
while (expectedWithoutPayload.hasNext()) {
Map.Entry<BytesRef, Long> entry = expectedWithoutPayload.next();
assertEquals(entry.getKey(), wrapperWithoutPayload.next());
assertEquals(entry.getValue().longValue(), wrapperWithoutPayload.weight());
assertNull(wrapperWithoutPayload.payload());
}
assertNull(wrapperWithoutPayload.next());
}
// test the unsorted iterator wrapper without payloads
InputIterator wrapperWithoutPayload = new UnsortedInputIterator(new InputArrayIterator(unsortedWithoutPayload));
TreeMap<BytesRef, Long> actualWithoutPayload = new TreeMap<>();
while ((key = wrapperWithoutPayload.next()) != null) {
long value = wrapperWithoutPayload.weight();
assertNull(wrapperWithoutPayload.payload());
actualWithoutPayload.put(BytesRef.deepCopyOf(key), value);
}
assertEquals(sortedWithoutPayload, actualWithoutPayload);
}
use of java.util.AbstractMap.SimpleEntry in project BKCommonLib by bergerhealer.
the class CommonTag method nbtToCommon.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected static Object nbtToCommon(Object data, boolean wrapData) {
if (NMSNBT.Base.T.isInstance(data)) {
return create(data);
} else if (data instanceof CommonTag || data == null) {
return data;
} else if (data instanceof Entry) {
Entry old = (Entry) data;
// Replace
Object newKey = nbtToCommon(old.getKey(), wrapData);
Object newValue = nbtToCommon(old.getValue(), wrapData);
// If changed, return new type
if (newKey != old.getKey() || newValue != old.getValue()) {
return new SimpleEntry(newKey, newValue);
} else {
return data;
}
} else if (data instanceof Set) {
Set<Object> elems = (Set<Object>) data;
HashSet<Object> tags = new HashSet<Object>(elems.size());
// Replace
for (Object value : elems) {
tags.add(nbtToCommon(value, wrapData));
}
return tags;
} else if (data instanceof Map) {
Map<String, Object> elems = (Map<String, Object>) data;
HashMap<String, Object> tags = new HashMap<String, Object>(elems.size());
// Replace
for (Entry<String, Object> entry : elems.entrySet()) {
tags.put(entry.getKey(), nbtToCommon(entry.getValue(), wrapData));
}
return tags;
} else if (data instanceof Collection) {
Collection<Object> elems = (Collection<Object>) data;
ArrayList<Object> tags = new ArrayList<Object>(elems.size());
// Replace
for (Object value : elems) {
tags.add(nbtToCommon(value, wrapData));
}
return tags;
} else if (wrapData) {
return createForData(data);
} else {
return data;
}
}
use of java.util.AbstractMap.SimpleEntry in project BKCommonLib by bergerhealer.
the class CommonTag method commonToNbt.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected static Object commonToNbt(Object data) {
if (data instanceof CommonTag) {
return ((CommonTag) data).getRawHandle();
} else if (NMSNBT.Base.T.isInstance(data) || data == null) {
return data;
} else if (data instanceof Entry) {
Entry old = (Entry) data;
// Replace
Object newKey = commonToNbt(old.getKey());
Object newValue = commonToNbt(old.getValue());
// If changed, return new type
if (newKey != old.getKey() || newValue != old.getValue()) {
return new SimpleEntry(newKey, newValue);
} else {
return data;
}
} else if (data instanceof Set) {
Set<Object> elems = (Set<Object>) data;
HashSet<Object> tags = new HashSet<Object>(elems.size());
// Replace
for (Object value : elems) {
tags.add(commonToNbt(value));
}
return tags;
} else if (data instanceof Map) {
Map<String, Object> elems = (Map<String, Object>) data;
HashMap<String, Object> tags = new HashMap<String, Object>(elems.size());
// Replace
for (Entry<String, Object> entry : elems.entrySet()) {
Object value = commonToNbt(entry.getValue());
tags.put(entry.getKey(), value);
}
return tags;
} else if (data instanceof Collection) {
Collection<Object> elems = (Collection<Object>) data;
ArrayList<Object> tags = new ArrayList<Object>(elems.size());
// Replace
for (Object value : elems) {
tags.add(commonToNbt(value));
}
return tags;
} else {
return NMSNBT.createHandle(data);
}
}
use of java.util.AbstractMap.SimpleEntry in project ddf by codice.
the class SeedCommand method executeWithSubject.
@Override
protected Object executeWithSubject() throws Exception {
if (resourceLimit <= 0) {
printErrorMessage("A limit of " + resourceLimit + " was supplied. The limit must be greater than 0.");
return null;
}
final long start = System.currentTimeMillis();
int resourceDownloads = 0;
int downloadErrors = 0;
int pageCount = 0;
while (resourceDownloads < resourceLimit) {
final QueryImpl query = new QueryImpl(getFilter());
query.setPageSize(resourceLimit);
query.setStartIndex(pageCount * resourceLimit + 1);
++pageCount;
final QueryRequestImpl queryRequest;
if (isNotEmpty(sources)) {
queryRequest = new QueryRequestImpl(query, sources);
} else {
queryRequest = new QueryRequestImpl(query, true);
}
queryRequest.setProperties(new HashMap<>(CACHE_UPDATE_PROPERTIES));
final QueryResponse queryResponse = catalogFramework.query(queryRequest);
if (queryResponse.getResults().isEmpty()) {
break;
}
final List<Entry<? extends ResourceRequest, String>> resourceRequests = queryResponse.getResults().stream().map(Result::getMetacard).filter(isNonCachedResource).map(metacard -> new SimpleEntry<>(new ResourceRequestById(metacard.getId()), metacard.getSourceId())).collect(toList());
for (Entry<? extends ResourceRequest, String> requestAndSourceId : resourceRequests) {
final ResourceRequest request = requestAndSourceId.getKey();
try {
ResourceResponse response = catalogFramework.getResource(request, requestAndSourceId.getValue());
++resourceDownloads;
EXECUTOR.execute(new ResourceCloseHandler(response));
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
++downloadErrors;
LOGGER.debug("Could not download resource for metacard [id={}]", request.getAttributeValue(), e);
}
printProgressAndFlush(start, resourceLimit, resourceDownloads);
if (resourceDownloads == resourceLimit) {
break;
}
}
}
printProgressAndFlush(start, resourceDownloads, resourceDownloads);
console.println();
if (downloadErrors > 0) {
printErrorMessage(downloadErrors + " resource download(s) had errors. Check the logs for details.");
}
printSuccessMessage("Done seeding. " + resourceDownloads + " resource download(s) started.");
return null;
}
Aggregations