Search in sources :

Example 21 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project Gargoyle by callakrsos.

the class CachedMapTest method simple.

@Test
public void simple() throws InterruptedException {
    CachedMap<Object, Object> cachedMap = new CachedMap<>(1000);
    cachedMap.put("sample", "zz");
    cachedMap.put("sample22", "zz");
    System.out.println(cachedMap.get("sample"));
    Thread.sleep(1500);
    System.out.println(cachedMap.get("sample"));
    System.out.println(cachedMap.get("sample22"));
    HashedMap hashedMap = new HashedMap();
    hashedMap.put("sample", "zz");
    hashedMap.put("sample22", "zz");
    cachedMap.putAll(hashedMap);
    System.out.println(cachedMap);
    Thread.sleep(1500);
    System.out.println(cachedMap);
}
Also used : HashedMap(org.apache.commons.collections.map.HashedMap) Test(org.junit.Test)

Example 22 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project gocd by gocd.

the class AuthorizationMessageConverterV1 method getAuthConfigs.

private List<Map<String, Object>> getAuthConfigs(List<SecurityAuthConfig> authConfigs) {
    List<Map<String, Object>> configs = new ArrayList<>();
    if (authConfigs == null) {
        return configs;
    }
    for (SecurityAuthConfig securityAuthConfig : authConfigs) {
        Map<String, Object> authConfig = new HashedMap();
        authConfig.put("id", securityAuthConfig.getId());
        authConfig.put("configuration", securityAuthConfig.getConfigurationAsMap(true));
        configs.add(authConfig);
    }
    return configs;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HashedMap(org.apache.commons.collections.map.HashedMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 23 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project opennms by OpenNMS.

the class PathOutageStatusProvider method getStatusForVertices.

@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
    final List<Integer> nodeIds = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (PathOutageVertex) v).map(v -> v.getNodeID()).collect(Collectors.toList());
    if (nodeIds.isEmpty()) {
        return new HashMap<>();
    }
    // Preparing database request
    final StringBuilder hql = new StringBuilder();
    hql.append("SELECT node.id, max(event.eventSeverity) ");
    hql.append("FROM OnmsOutage as outage ");
    hql.append("LEFT JOIN outage.monitoredService as ifservice ");
    hql.append("LEFT JOIN ifservice.ipInterface as ipinterface ");
    hql.append("LEFT JOIN ipinterface.node as node ");
    hql.append("LEFT JOIN outage.serviceLostEvent as event ");
    hql.append("WHERE node.id in (:nodeIds) ");
    hql.append("AND outage.serviceRegainedEvent is null ");
    hql.append("GROUP BY node.id");
    final List<String> paramNames = Lists.newArrayList("nodeIds");
    final List<Object> paramValues = new ArrayList();
    paramValues.add(Lists.newArrayList(nodeIds));
    final List<Object[]> retvals = this.persistenceAccessor.findUsingNamedParameters(hql.toString(), paramNames.toArray(new String[paramNames.size()]), paramValues.toArray());
    // Generating alarms map
    final Map<Integer, OnmsSeverity> mappedAlarms = new HashedMap();
    for (int i = 0; i < retvals.size(); i++) {
        final Integer nodeId = (Integer) retvals.get(i)[0];
        final Integer severity = Optional.ofNullable((Integer) retvals.get(i)[1]).orElse(OnmsSeverity.NORMAL.ordinal());
        mappedAlarms.put(nodeId, OnmsSeverity.get(severity));
    }
    final Map<VertexRef, Status> status = vertices.stream().map(v -> (PathOutageVertex) v).collect(Collectors.toMap(v -> v, v -> {
        if (!mappedAlarms.containsKey(v.getNodeID())) {
            return new DefaultStatus(OnmsSeverity.NORMAL.getLabel(), 0);
        } else {
            return new DefaultStatus(mappedAlarms.get(v.getNodeID()).getLabel(), 0);
        }
    }));
    return status;
}
Also used : Collection(java.util.Collection) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) HashedMap(org.apache.commons.collections.map.HashedMap) ArrayList(java.util.ArrayList) Objects(java.util.Objects) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) List(java.util.List) StatusProvider(org.opennms.features.topology.api.topo.StatusProvider) Lists(com.google.common.collect.Lists) VertexProvider(org.opennms.features.topology.api.topo.VertexProvider) GenericPersistenceAccessor(org.opennms.netmgt.dao.api.GenericPersistenceAccessor) Map(java.util.Map) Criteria(org.opennms.features.topology.api.topo.Criteria) Optional(java.util.Optional) Status(org.opennms.features.topology.api.topo.Status) VertexRef(org.opennms.features.topology.api.topo.VertexRef) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) Status(org.opennms.features.topology.api.topo.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultStatus(org.opennms.features.topology.api.topo.DefaultStatus) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) HashedMap(org.apache.commons.collections.map.HashedMap) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 24 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project beakerx by twosigma.

the class GroovyCompleteHandlerTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    GroovyEvaluator groovyEvaluator = new GroovyEvaluator("id", "sid", cellExecutor(), EvaluatorTest.getTestTempFolderFactory(), new EvaluatorParameters(new HashedMap()));
    groovyKernel = new GroovyKernelMock("sid", groovyEvaluator);
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) GroovyKernelMock(com.twosigma.beakerx.groovy.kernel.GroovyKernelMock) GroovyEvaluator(com.twosigma.beakerx.groovy.evaluator.GroovyEvaluator) HashedMap(org.apache.commons.collections.map.HashedMap) BeforeClass(org.junit.BeforeClass)

Example 25 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project xwiki-platform by xwiki.

the class DefaultPeriodicMimeMessageIteratorTest method test.

@Test
public void test() throws Exception {
    DocumentReference templateReference = new DocumentReference("xwiki", "XWiki", "Template");
    Map<String, Object> factoryParameters = new HashedMap();
    // Mocks
    NotificationUserIterator userIterator = mock(NotificationUserIterator.class);
    DocumentReference userA = new DocumentReference("xwiki", "XWiki", "UserA");
    DocumentReference userB = new DocumentReference("xwiki", "XWiki", "UserB");
    DocumentReference userC = new DocumentReference("xwiki", "XWiki", "UserC");
    when(userIterator.hasNext()).thenReturn(true, true, true, false);
    when(userIterator.next()).thenReturn(userA, userB, userC);
    DocumentReference userClass = new DocumentReference("xwiki", "XWiki", "XWikiUsers");
    when(documentAccessBridge.getProperty(userA, userClass, 0, "email")).thenReturn("userA@xwiki.org");
    when(documentAccessBridge.getProperty(userB, userClass, 0, "email")).thenReturn("bad email");
    when(documentAccessBridge.getProperty(userC, userClass, 0, "email")).thenReturn("userC@xwiki.org");
    when(serializer.serialize(userA)).thenReturn("xwiki:XWiki.UserA");
    when(serializer.serialize(userB)).thenReturn("xwiki:XWiki.UserA");
    when(serializer.serialize(userC)).thenReturn("xwiki:XWiki.UserC");
    CompositeEvent event1 = mock(CompositeEvent.class);
    CompositeEvent event2 = mock(CompositeEvent.class);
    when(notificationManager.getEvents("xwiki:XWiki.UserA", NotificationFormat.EMAIL, Integer.MAX_VALUE / 4, null, new Date(0L), Collections.emptyList())).thenReturn(Arrays.asList(event1));
    when(notificationManager.getEvents("xwiki:XWiki.UserC", NotificationFormat.EMAIL, Integer.MAX_VALUE / 4, null, new Date(0L), Collections.emptyList())).thenReturn(Arrays.asList(event2));
    MimeMessage message = mock(MimeMessage.class);
    when(factory.createMessage(templateReference, factoryParameters)).thenReturn(message, message);
    when(defaultNotificationEmailRenderer.renderHTML(eq(event1), anyString())).thenReturn("eventHTML1");
    when(defaultNotificationEmailRenderer.renderPlainText(eq(event1), anyString())).thenReturn("event1");
    when(defaultNotificationEmailRenderer.renderHTML(eq(event2), anyString())).thenReturn("eventHTML2");
    when(defaultNotificationEmailRenderer.renderPlainText(eq(event2), anyString())).thenReturn("event2");
    // Test
    PeriodicMimeMessageIterator iterator = mocker.getComponentUnderTest();
    iterator.initialize(userIterator, factoryParameters, new Date(0L), templateReference);
    // First iteration
    assertTrue(iterator.hasNext());
    assertEquals(message, iterator.next());
    assertEquals(new InternetAddress("xwiki@xwiki.org"), factoryParameters.get("from"));
    assertEquals(new InternetAddress("userA@xwiki.org"), factoryParameters.get("to"));
    Map<String, Object> velocityVariables = (Map<String, Object>) factoryParameters.get("velocityVariables");
    assertNotNull(velocityVariables);
    assertEquals(Arrays.asList(event1), velocityVariables.get("events"));
    assertEquals(Arrays.asList("eventHTML1"), velocityVariables.get("htmlEvents"));
    assertEquals(Arrays.asList("event1"), velocityVariables.get("plainTextEvents"));
    // Second iteration
    assertTrue(iterator.hasNext());
    assertEquals(message, iterator.next());
    assertEquals(new InternetAddress("xwiki@xwiki.org"), factoryParameters.get("from"));
    assertEquals(new InternetAddress("userC@xwiki.org"), factoryParameters.get("to"));
    velocityVariables = (Map<String, Object>) factoryParameters.get("velocityVariables");
    assertNotNull(velocityVariables);
    assertEquals(Arrays.asList(event2), velocityVariables.get("events"));
    assertEquals(Arrays.asList("eventHTML2"), velocityVariables.get("htmlEvents"));
    assertEquals(Arrays.asList("event2"), velocityVariables.get("plainTextEvents"));
    // End
    assertFalse(iterator.hasNext());
    // Verify
    verify(serializer, never()).serialize(userB);
    assertEquals(iterator, iterator.iterator());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashedMap(org.apache.commons.collections.map.HashedMap) CompositeEvent(org.xwiki.notifications.CompositeEvent) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date) Test(org.junit.Test)

Aggregations

HashedMap (org.apache.commons.collections.map.HashedMap)34 Test (org.junit.Test)14 Map (java.util.Map)13 HashMap (java.util.HashMap)10 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 File (java.io.File)3 LogDetail (com.bc.pmpheep.annotation.LogDetail)2 ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)2 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)2 EmailPool (com.bonree.brfs.email.EmailPool)2 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)2 Date (java.util.Date)2 List (java.util.List)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 OrgVO (com.bc.pmpheep.back.vo.OrgVO)1 ProductType (com.bc.pmpheep.back.vo.ProductType)1 Service (com.bonree.brfs.common.service.Service)1