public final int[] getIntArray(int argLength) { if (!aints.containsKey(argLength)) { aints.put(argLength, new int[argLength]); } assert (aints.get(argLength).length == argLength) : "Array not built with correct length"; return aints.get(argLength); }
private void mapKey(int orikey, int key) throws Exception { int orivalue = map.get(orikey); int value = map.get(key); ArrayList<Integer> oriKeyList = mapList.get(orivalue); ArrayList<Integer> keyList = mapList.get(value); for (Integer temp : oriKeyList) { map.put(temp, value); keyList.add(temp); } mapList.remove(orivalue); }
public static <V> HashMap<V, Integer> multi_set(List<V> list) { HashMap<V, Integer> rtn = new HashMap<>(); for (V v : list) { int cnt = 1; if (rtn.containsKey(v)) { cnt += rtn.get(v); } rtn.put(v, cnt); } return rtn; }
private HashMap<String/* brokerName */, Set<MessageQueue>> buildProcessQueueTableByBrokerName() { HashMap<String, Set<MessageQueue>> result = new HashMap<String, Set<MessageQueue>>(); for (MessageQueue mq : this.processQueueTable.keySet()) { Set<MessageQueue> mqs = result.get(mq.getBrokerName()); if (null == mqs) { mqs = new HashSet<MessageQueue>(); result.put(mq.getBrokerName(), mqs); } mqs.add(mq); } return result; }
@Test public void testGenericMapWithKeyType() { GenericBean<?> gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); Map<String, String> input = new HashMap<>(); input.put("4", "5"); input.put("6", "7"); bw.setPropertyValue("longMap", input); assertEquals("5", gb.getLongMap().get(new Long("4"))); assertEquals("7", gb.getLongMap().get(new Long("6"))); }
public FindBrokerResult findBrokerAddressInSubscribe( final String brokerName, final long brokerId, final boolean onlyThisBroker ) { String brokerAddr = null; boolean slave = false; boolean found = false; HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName); if (map != null && !map.isEmpty()) { brokerAddr = map.get(brokerId); slave = brokerId != MixAll.MASTER_ID; found = brokerAddr != null; if (!found && !onlyThisBroker) { Entry<Long, String> entry = map.entrySet().iterator().next(); brokerAddr = entry.getValue(); slave = entry.getKey() != MixAll.MASTER_ID; found = true; } } if (found) { return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr)); } return null; }
public void add(HashMap<String, ArrayList<TaskMessage>> workerTupleSetMap) { for (String key : workerTupleSetMap.keySet()) { ArrayList<ArrayList<TaskMessage>> bundle = bundles.get(key); if (null == bundle) { bundle = new ArrayList<>(); bundles.put(key, bundle); } ArrayList tupleSet = workerTupleSetMap.get(key); if (null != tupleSet && tupleSet.size() > 0) { bundle.add(tupleSet); } } }
public static <V> HashMap<V, Integer> multi_set(List<V> list) { HashMap<V, Integer> rtn = new HashMap<V, Integer>(); for (V v : list) { int cnt = 1; if (rtn.containsKey(v)) { cnt += rtn.get(v); } rtn.put(v, cnt); } return rtn; }
private void calcAV() { System.out.println("count: "+left.size()); Iterator<String> it = left.keySet().iterator(); while(it.hasNext()){ String key = it.next(); Double l = Math.log(left.get(key).size()); Double r = Math.log(right.get(key).size()); av.put(key, (int)Math.min(l, r)); } System.out.println("av count: "+av.size()); }
/** * <code><pre> * type ::= string * ::= int * </code></pre> */ private void writeType(String type) throws IOException { flushIfFull(); int len = type.length(); if (len == 0) { throw new IllegalArgumentException("empty type is not allowed"); } if (_typeRefs == null) _typeRefs = new HashMap(); Integer typeRefV = (Integer) _typeRefs.get(type); if (typeRefV != null) { int typeRef = typeRefV.intValue(); writeInt(typeRef); } else { _typeRefs.put(type, Integer.valueOf(_typeRefs.size())); writeString(type); } }
private void mapKey(int orikey, int key) throws Exception { int orivalue = map.get(orikey); int value = map.get(key); ArrayList<Integer> oriKeyList = mapList.get(orivalue); ArrayList<Integer> keyList = mapList.get(value); for (Integer temp : oriKeyList) { map.put(temp, value); keyList.add(temp); } mapList.remove(orivalue); }
@Test public void testGenericMapWithKeyTypeConstructor() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class); Map<String, String> input = new HashMap<>(); input.put("4", "5"); input.put("6", "7"); rbd.getConstructorArgumentValues().addGenericArgumentValue(input); bf.registerBeanDefinition("genericBean", rbd); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); assertEquals("5", gb.getLongMap().get(new Long("4"))); assertEquals("7", gb.getLongMap().get(new Long("6"))); }
public final float[] getFloatArray(int argLength) { if (!afloats.containsKey(argLength)) { afloats.put(argLength, new float[argLength]); } assert (afloats.get(argLength).length == argLength) : "Array not built with correct length"; return afloats.get(argLength); }