use of java.util.AbstractMap.SimpleEntry in project ddf by codice.
the class SolrProviderTest method testUpdateAlternativeAttribute.
/**
* Testing update operation of alternative attribute. Should return positive results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateAlternativeAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
final MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
create(metacard);
UpdateResponse response = provider.update(new UpdateRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<Entry<Serializable, Metacard>> getUpdates() {
MetacardImpl newMetacard = new MetacardImpl(metacard);
newMetacard.setContentTypeName("newContentName");
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
Update update = response.getUpdatedMetacards().get(0);
assertThat(update.getNewMetacard().getId(), is(equalTo(update.getOldMetacard().getId())));
assertEquals(1, response.getUpdatedMetacards().size());
}
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 spring-data-jdbc by spring-projects.
the class IterableOfEntryToMapConverterUnitTests method testConversions.
@Test
public void testConversions() {
Map<Object, Object> map = new HashMap<>();
map.put("key", "value");
List<Object[]> testValues = asList(//
new Object[] { emptySet(), emptyMap() }, //
new Object[] { emptyList(), emptyMap() }, //
new Object[] { "string", false }, //
new Object[] { asList(new SimpleEntry<>("key", "value")), map }, //
new Object[] { asList("string"), IllegalArgumentException.class });
SoftAssertions softly = new SoftAssertions();
testValues.forEach(array -> softly.assertThat(tryToConvert(array[0])).isEqualTo(array[1]));
softly.assertAll();
}
use of java.util.AbstractMap.SimpleEntry in project scylla by bptlab.
the class EventArrivalRateSchedulingPlugin method scheduleEvent.
/**
* Gets a sample of the arrival rate distribution for this event, if existing,
* and schedules the event displaced by this value.
*/
@Override
public boolean scheduleEvent(ScyllaEvent event, TimeSpan timeSpan) throws ScyllaRuntimeException {
ProcessSimulationComponents pSimComponents = event.getDesmojObjects();
Map<Integer, Object> arrivalRates = pSimComponents.getExtensionDistributions().get(getName());
@SuppressWarnings("unchecked") SimpleEntry<NumericalDist<?>, TimeUnit> arrivalRate = (SimpleEntry<NumericalDist<?>, TimeUnit>) arrivalRates.get(event.getNodeId());
if (arrivalRate != null) {
NumericalDist<?> distribution = arrivalRate.getKey();
TimeUnit timeUnit = arrivalRate.getValue();
ProcessInstance processInstance = event.getProcessInstance();
TimeSpan offset = new TimeSpan(distribution.sample().doubleValue(), timeUnit);
TimeSpan newTime = new TimeSpan(timeSpan.getTimeAsDouble() + offset.getTimeAsDouble());
event.schedule(processInstance, newTime);
return false;
}
return true;
}
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 if (NMSNBT.Type.canStore(data)) {
return NMSNBT.createHandle(data);
} else {
String dataAsString = Conversion.toString.convert(data);
if (dataAsString == null) {
throw new IllegalArgumentException("Value of type " + data.getClass() + " can not be serialized as a String");
}
return NMSNBT.createHandle(dataAsString);
}
}
Aggregations