org.apache.commons.collections.keyvalue.MultiKey Java Examples
The following examples show how to use
org.apache.commons.collections.keyvalue.MultiKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public Object put(Object key1, Object key2, Object value) { int hashCode = hash(key1, key2); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry entry = map.data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) { Object oldValue = entry.getValue(); map.updateEntry(entry, value); return oldValue; } entry = entry.next; } map.addMapping(index, hashCode, new MultiKey(key1, key2), value); return null; }
Example #2
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public Object put(Object key1, Object key2, Object key3, Object value) { int hashCode = hash(key1, key2, key3); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry entry = map.data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) { Object oldValue = entry.getValue(); map.updateEntry(entry, value); return oldValue; } entry = entry.next; } map.addMapping(index, hashCode, new MultiKey(key1, key2, key3), value); return null; }
Example #3
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public Object put(Object key1, Object key2, Object key3, Object key4, Object value) { int hashCode = hash(key1, key2, key3, key4); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry entry = map.data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) { Object oldValue = entry.getValue(); map.updateEntry(entry, value); return oldValue; } entry = entry.next; } map.addMapping(index, hashCode, new MultiKey(key1, key2, key3, key4), value); return null; }
Example #4
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public Object put(Object key1, Object key2, Object key3, Object key4, Object key5, Object value) { int hashCode = hash(key1, key2, key3, key4, key5); int index = map.hashIndex(hashCode, map.data.length); AbstractHashedMap.HashEntry entry = map.data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) { Object oldValue = entry.getValue(); map.updateEntry(entry, value); return oldValue; } entry = entry.next; } map.addMapping(index, hashCode, new MultiKey(key1, key2, key3, key4, key5), value); return null; }
Example #5
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Removes all mappings where the first three keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has three or more keys, and the first three match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2, Object key3) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 3 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2)))) { it.remove(); modified = true; } } return modified; }
Example #6
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 6 votes |
/** * Removes all mappings where the first four keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has four or more keys, and the first four match those specified. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2, Object key3, Object key4) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 4 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3)))) { it.remove(); modified = true; } } return modified; }
Example #7
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 5 votes |
/** * Removes all mappings where the first key is that specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has one or more keys, and the first matches that specified. * * @param key1 the first key * @return true if any elements were removed */ public boolean removeAll(Object key1) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 1 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0)))) { it.remove(); modified = true; } } return modified; }
Example #8
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 5 votes |
/** * Removes all mappings where the first two keys are those specified. * <p> * This method removes all the mappings where the <code>MultiKey</code> * has two or more keys, and the first two match those specified. * * @param key1 the first key * @param key2 the second key * @return true if any elements were removed */ public boolean removeAll(Object key1, Object key2) { boolean modified = false; MapIterator it = mapIterator(); while (it.hasNext()) { MultiKey multi = (MultiKey) it.next(); if (multi.size() >= 2 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1)))) { it.remove(); modified = true; } } return modified; }
Example #9
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 5 votes |
/** * Check to ensure that input keys are valid MultiKey objects. * * @param key the key to check */ protected void checkKey(Object key) { if (key == null) { throw new NullPointerException("Key must not be null"); } if (key instanceof MultiKey == false) { throw new ClassCastException("Key must be a MultiKey"); } }
Example #10
Source File: ExpressionTypeIngredientSpace.java From astor with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void toJSON(String output) { JSONObject space = new JSONObject(); JSONArray list = new JSONArray(); space.put("nrall", this.allElementsFromSpace.size()); space.put("space", list); for (Object key : mkp.keySet()) { JSONObject keyjson = new JSONObject(); MultiKey mk = (MultiKey) key; keyjson.put("key", Arrays.toString(mk.getKeys())); list.add(keyjson); JSONArray ingredients = new JSONArray(); keyjson.put("ingredients", ingredients); List ings = (List) mkp.get(key); keyjson.put("nringredients", ings.size()); for (Object v : ings) { ingredients.add(v.toString()); } ; } String fileName = output + "ingredients.json"; try (FileWriter file = new FileWriter(fileName)) { file.write(space.toJSONString()); file.flush(); log.info("Storing ing JSON at " + fileName); } catch (IOException e) { e.printStackTrace(); log.error("Problem storing ing json file" + e.toString()); } }
Example #11
Source File: NFHttpClientFactory.java From ribbon with Apache License 2.0 | 5 votes |
public static NFHttpClient getNFHttpClient(String host, int port){ MultiKey mk = new MultiKey(host,port); NFHttpClient client = clientMap.get(mk); if (client == null){ client = new NFHttpClient(host, port); clientMap.put(mk,client); } return client; }
Example #12
Source File: ZKClusterCoordinator.java From Bats with Apache License 2.0 | 4 votes |
private synchronized void updateEndpoints() { try { // All active bits in the Zookeeper Collection<DrillbitEndpoint> newDrillbitSet = transform(discovery.queryForInstances(serviceName), new Function<ServiceInstance<DrillbitEndpoint>, DrillbitEndpoint>() { @Override public DrillbitEndpoint apply(ServiceInstance<DrillbitEndpoint> input) { return input.getPayload(); } }); // set of newly dead bits : original bits - new set of active bits. Set<DrillbitEndpoint> unregisteredBits = new HashSet<>(); // Set of newly live bits : new set of active bits - original bits. Set<DrillbitEndpoint> registeredBits = new HashSet<>(); // Updates the endpoints map if there is a change in state of the endpoint or with the addition // of new drillbit endpoints. Registered endpoints is set to newly live drillbit endpoints. for ( DrillbitEndpoint endpoint : newDrillbitSet) { String endpointAddress = endpoint.getAddress(); int endpointPort = endpoint.getUserPort(); if (! endpointsMap.containsKey(new MultiKey(endpointAddress, endpointPort))) { registeredBits.add(endpoint); } endpointsMap.put(new MultiKey(endpointAddress, endpointPort),endpoint); } // Remove all the endpoints that are newly dead for ( MultiKey key: endpointsMap.keySet()) { if(!newDrillbitSet.contains(endpointsMap.get(key))) { unregisteredBits.add(endpointsMap.get(key)); endpointsMap.remove(key); } } endpoints = endpointsMap.values(); if (logger.isDebugEnabled()) { StringBuilder builder = new StringBuilder(); builder.append("Active drillbit set changed. Now includes "); builder.append(newDrillbitSet.size()); builder.append(" total bits. New active drillbits:\n"); builder.append("Address | User Port | Control Port | Data Port | Version | State\n"); for (DrillbitEndpoint bit: newDrillbitSet) { builder.append(bit.getAddress()).append(" | "); builder.append(bit.getUserPort()).append(" | "); builder.append(bit.getControlPort()).append(" | "); builder.append(bit.getDataPort()).append(" | "); builder.append(bit.getVersion()).append(" |"); builder.append(bit.getState()).append(" | "); builder.append('\n'); } logger.debug(builder.toString()); } // Notify listeners of newly unregistered Drillbits. if (!unregisteredBits.isEmpty()) { drillbitUnregistered(unregisteredBits); } // Notify listeners of newly registered Drillbits. if (!registeredBits.isEmpty()) { drillbitRegistered(registeredBits); } } catch (Exception e) { logger.error("Failure while update Drillbit service location cache.", e); } }
Example #13
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 3 votes |
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @return true if the key matches */ protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2) { MultiKey multi = (MultiKey) entry.getKey(); return multi.size() == 2 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))); }
Example #14
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 3 votes |
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if the key matches */ protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3) { MultiKey multi = (MultiKey) entry.getKey(); return multi.size() == 3 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))); }
Example #15
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 3 votes |
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if the key matches */ protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4) { MultiKey multi = (MultiKey) entry.getKey(); return multi.size() == 4 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3))); }
Example #16
Source File: MultiKeyMap.java From Penetration_Testing_POC with Apache License 2.0 | 3 votes |
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @return true if the key matches */ protected boolean isEqualKey(AbstractHashedMap.HashEntry entry, Object key1, Object key2, Object key3, Object key4, Object key5) { MultiKey multi = (MultiKey) entry.getKey(); return multi.size() == 5 && (key1 == null ? multi.getKey(0) == null : key1.equals(multi.getKey(0))) && (key2 == null ? multi.getKey(1) == null : key2.equals(multi.getKey(1))) && (key3 == null ? multi.getKey(2) == null : key3.equals(multi.getKey(2))) && (key4 == null ? multi.getKey(3) == null : key4.equals(multi.getKey(3))) && (key5 == null ? multi.getKey(4) == null : key5.equals(multi.getKey(4))); }