Search in sources :

Example 51 with SimpleEntry

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());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) Test(org.junit.Test)

Example 52 with SimpleEntry

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;
    }
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry)

Example 53 with SimpleEntry

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();
}
Also used : HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) SoftAssertions(org.assertj.core.api.SoftAssertions) Test(org.junit.Test)

Example 54 with SimpleEntry

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;
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) NumericalDist(desmoj.core.dist.NumericalDist) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) SimpleEntry(java.util.AbstractMap.SimpleEntry) TimeUnit(java.util.concurrent.TimeUnit) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance)

Example 55 with SimpleEntry

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);
    }
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry)

Aggregations

SimpleEntry (java.util.AbstractMap.SimpleEntry)59 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)19 Map (java.util.Map)13 Entry (java.util.Map.Entry)12 CucumberFeature (cucumber.runtime.model.CucumberFeature)10 Result (gherkin.formatter.model.Result)10 List (java.util.List)10 HashSet (java.util.HashSet)9 Metacard (ddf.catalog.data.Metacard)7 Serializable (java.io.Serializable)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)6 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 UpdateRequest (ddf.catalog.operation.UpdateRequest)5 Collections (java.util.Collections)5 Set (java.util.Set)5 Before (org.junit.Before)5 ZookeeperConfigurationProvider (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider)4