List of usage examples for java.util HashMap size
int size
To view the source code for java.util HashMap size.
Click Source Link
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void BogusWithdrawCost() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION) .withMinDuration(TimeService.DAY * 5).withEarlyWithdrawPayment(1e20) .addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff);/*from w w w . j a v a 2 s .c o m*/ ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for bob", new Integer(10000), calls.get(jimTariff)); }
From source file:com.clustercontrol.accesscontrol.util.UserRoleCache.java
/** * ?/*from w ww. j a v a 2 s . c om*/ */ public static void refresh() { m_log.info("refreshing cache : " + UserRoleCache.class.getSimpleName()); try { _lock.writeLock(); long startTime = System.currentTimeMillis(); new JpaTransactionManager().getEntityManager().clear(); // ??? HashMap<String, ArrayList<String>> roleUserMap = new HashMap<String, ArrayList<String>>(); List<RoleInfo> roleEntities = QueryUtil.getAllRole_NONE(); for (RoleInfo roleEntity : roleEntities) { ArrayList<String> userIdList = new ArrayList<String>(); if (roleEntity.getUserInfoList() != null) { for (UserInfo userEntity : roleEntity.getUserInfoList()) { userIdList.add(userEntity.getUserId()); } } roleUserMap.put(roleEntity.getRoleId(), userIdList); } // ????? HashMap<String, ArrayList<SystemPrivilegeInfo>> roleSystemPrivilegeMap = new HashMap<String, ArrayList<SystemPrivilegeInfo>>(); for (RoleInfo roleEntity : roleEntities) { roleSystemPrivilegeMap.put(roleEntity.getRoleId(), roleEntity.getSystemPrivilegeList() != null ? new ArrayList<SystemPrivilegeInfo>(roleEntity.getSystemPrivilegeList()) : new ArrayList<SystemPrivilegeInfo>()); } // ??? HashMap<String, ArrayList<String>> userRoleMap = new HashMap<String, ArrayList<String>>(); List<UserInfo> userEntities = QueryUtil.getAllUser_NONE(); for (UserInfo userEntity : userEntities) { ArrayList<String> roleIdList = new ArrayList<String>(); if (userEntity.getRoleList() != null) { for (RoleInfo roleEntity : userEntity.getRoleList()) { roleIdList.add(roleEntity.getRoleId()); } } userRoleMap.put(userEntity.getUserId(), roleIdList); } storeRoleUserCache(roleUserMap); storeRoleSystemPrivilegeCache(roleSystemPrivilegeMap); storeUserRoleCache(userRoleMap); m_log.info("refresh UserRoleCache " + (System.currentTimeMillis() - startTime) + "ms. roleUserMap size=" + roleUserMap.size() + " roleSystemPrivilegeMap size=" + roleSystemPrivilegeMap.size() + " userRoleMap size=" + userRoleMap.size()); } finally { _lock.writeUnlock(); } }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void signupBonus() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);/*from w w w . j av a2 s. co m*/ TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION).withSignupPayment(200.0) .addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for jim", new Integer(10000), calls.get(jimTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void signupCharge() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);//from ww w . j ava 2s .com TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION).withSignupPayment(-200.0) .addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for bob", new Integer(10000), calls.get(bobTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void signupCharge2() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);//from w w w .jav a 2s . c o m TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION).withSignupPayment(-15.0) .addRate(new Rate().withValue(-0.2)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 10.0, 20.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for bob", new Integer(10000), calls.get(bobTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void signupCharge3() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);/*www.ja v a 2 s . co m*/ TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION).withSignupPayment(-15.0) .addRate(new Rate().withValue(-0.2)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 2.0, 4.0, 2.0, 4.0, 2.0, 4.0, 2.0, 4.0, 2.0, 4.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for bob", new Integer(10000), calls.get(bobTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void withdrawCost() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);// w w w. ja v a2 s . co m TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION) .withMinDuration(TimeService.DAY * 5).withEarlyWithdrawPayment(-500.0) .addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for bob", new Integer(10000), calls.get(bobTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void singleNewTariffConsumption() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification newTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.59)); Tariff newTariff = new Tariff(newTS); initTariff(newTariff);/*from w w w .ja v a 2s . co m*/ ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(newTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(5000); // just two chunks evaluator.evaluateTariffs(); assertEquals("two tariffs", 2, calls.size()); assertEquals("-5000 for default", new Integer(-5000), calls.get(defaultConsumption)); assertEquals("+5000 for new", new Integer(5000), calls.get(newTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void twoTariffSplit() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);/*from ww w .ja va 2 s.c o m*/ TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION) .withMinDuration(TimeService.DAY * 5).addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("three tariffs", 3, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+5000 for bob", new Integer(5000), calls.get(bobTariff)); assertEquals("+5000 for jim", new Integer(5000), calls.get(jimTariff)); }
From source file:org.powertac.common.TariffEvaluatorTest.java
@Test public void minDurationTest() { subscribeTo(defaultConsumption, customer.getPopulation()); TariffSpecification bobTS = new TariffSpecification(bob, PowerType.CONSUMPTION) .addRate(new Rate().withValue(-0.4)); Tariff bobTariff = new Tariff(bobTS); initTariff(bobTariff);//from www. jav a2 s .c o m TariffSpecification jimTS = new TariffSpecification(jim, PowerType.CONSUMPTION) .withMinDuration(TimeService.DAY * 2).withEarlyWithdrawPayment(-50.0).withSignupPayment(50.0) .addRate(new Rate().withValue(-0.4)); Tariff jimTariff = new Tariff(jimTS); initTariff(jimTariff); TariffSpecification jimLong = new TariffSpecification(jim, PowerType.CONSUMPTION) .withMinDuration(TimeService.DAY * 4).withEarlyWithdrawPayment(-50.0).withSignupPayment(50.0) .addRate(new Rate().withValue(-0.4)); Tariff jimTariffL = new Tariff(jimLong); initTariff(jimTariffL); ArrayList<Tariff> tariffs = new ArrayList<Tariff>(); tariffs.add(defaultConsumption); tariffs.add(bobTariff); tariffs.add(jimTariff); tariffs.add(jimTariffL); when(tariffRepo.findRecentActiveTariffs(anyInt(), any(PowerType.class))).thenReturn(tariffs); double[] profile = { 1.0, 2.0 }; cma.capacityProfile = profile; cma.setChoiceSamples(0.4, 0.6); // capture calls to tariffMarket final HashMap<Tariff, Integer> calls = new HashMap<Tariff, Integer>(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); assertEquals("correct customer", customer, args[1]); calls.put((Tariff) args[0], (Integer) args[2]); return null; } }).when(tariffMarket).subscribeToTariff(any(Tariff.class), any(CustomerInfo.class), anyInt()); evaluator.withChunkSize(50); // 200 chunks evaluator.evaluateTariffs(); assertEquals("two changes", 2, calls.size()); assertEquals("-10000 for default", new Integer(-10000), calls.get(defaultConsumption)); assertEquals("+10000 for jim-long", new Integer(10000), calls.get(jimTariff)); }