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);
}
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;
}
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;
}
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);
}
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());
}
Aggregations