private void addServerIPAndHostEntries() { String hostName = serverConfigurationInformation.getHostName(); String ipAddress = serverConfigurationInformation.getIpAddress(); if (hostName != null && !"".equals(hostName)) { Entry entry = new Entry(SynapseConstants.SERVER_HOST); entry.setValue(hostName); synapseConfiguration.addEntry(SynapseConstants.SERVER_HOST, entry); } if (ipAddress != null && !"".equals(ipAddress)) { Entry entry = new Entry(SynapseConstants.SERVER_IP); entry.setValue(ipAddress); if (synapseConfiguration.getAxisConfiguration().getTransportsIn() != null) { Map<String, TransportInDescription> transportInConfigMap = synapseConfiguration.getAxisConfiguration().getTransportsIn(); if (transportInConfigMap != null) { TransportInDescription transportInDescription = transportInConfigMap.get("http"); if (transportInDescription != null) { Parameter bindAddressParam = transportInDescription.getParameter("bind-address"); if (bindAddressParam != null) { entry.setValue(bindAddressParam.getValue()); } } } } synapseConfiguration.addEntry(SynapseConstants.SERVER_IP, entry); } }
@Override public V put(final K key, final V value) { final Entry<K, V>[] table = this.table; final int hash = key.hashCode(); final int index = HashUtil.indexFor(hash, table.length, shift, mask); for (Entry<K, V> e = table[index]; e != null; e = e.hashNext) { final K entryKey; if (e.keyHash == hash && ((entryKey = e.key) == key || entryKey.equals(key))) { moveToTop(e); return e.setValue(value); } } final Entry<K, V> e = new Entry<K, V>(key, value); e.hashNext = table[index]; table[index] = e; final Entry<K, V> top = this.top; e.next = top; if (top != null) { top.previous = e; } else { back = e; } this.top = e; size = size + 1; if (removeEldestEntry(back)) { remove(back.key); } else if (size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; }
/** * increments every value in the sequence by (what?).. <br> * you can decrement if you want to. But values below 0 will be REJECTED. As will values above 255 * * @param byWhat this much! * @throws if you give a bogus value */ public void increment(int byWhat) throws Exception { for (Entry e : compressedSequence) { e.setValue(e.getValue() + byWhat); if (e.getValue() > 255 || e.getValue() < 0) { throw new Exception("too big value"); } } }
private Map<String, String> sanitizeMap() { Map<String, String> sanitized = new HashMap<String, String>(map); for (Entry<String, String> entry : sanitized.entrySet()) { if (entry.getKey().startsWith(SENSITIVE_PREFIX)) { entry.setValue(SENSITIVE_MASK); } } return sanitized; }
@Override public List<Entry> marshal(Map<String, ? extends Set<String>> map) throws Exception { List<Entry> entryList = new ArrayList<StringSetMapAdapter.Entry>(); for (Map.Entry<String, ? extends Set<String>> mapEntry : map.entrySet()) { for (String value : mapEntry.getValue()) { Entry entry = new Entry(); entry.setKey(mapEntry.getKey()); entry.setValue(value); entryList.add(entry); } } return entryList; }
@Override public V put(K key, V value) { int index = index(key); Entry<K, V> e = find(index, key); if (e != null) { return e.setValue(value); } e = new Entry<K, V>(key, value); if (table[index] == null) { table[index] = e; } else { e.next = table[index]; table[index] = e; } size++; return null; }
public V put(final int key, final V value) { final Entry<V>[] table = this.table; final int index = HashUtil.indexFor(key, table.length, mask); for (Entry<V> e = table[index]; e != null; e = e.hashNext) { if (e.key == key) { return e.setValue(value); } } final Entry<V> e = new Entry<>(key, value); e.hashNext = table[index]; table[index] = e; size += 1; if (size > capacity) { rehash(HashUtil.nextCapacity(capacity)); } return null; }
public Object put(Comparator comparator, Object key, Object val) { Object oldVal; int search = binarySearch(this, 0, size, key, comparator); if (search > -1) { Entry entry = get(search); oldVal = entry.getValue(); entry.setValue(val); } else if (size < capacity) { oldVal = null; search = -(search + 1); insert(search, key, val); } else { Leaf next = Leaf.newInstance(capacity); int halfSize = size / 2; shallowCopy(this, halfSize, next, 0, halfSize); clear(halfSize, size); size = halfSize; next.size = halfSize; if (compare(comparator, key, next.firstKey()) < 0) { put(comparator, key, val); } else { next.put(comparator, key, val); } next.next = this.next; this.next = next; oldVal = Node.Sentinal.SPLIT; } return oldVal; }
/** * This method adds or replaces a Key,Value. * * @param key The key of an Entry object. * @param value The value of the Entry object. * @return Returns the old value of the key. */ public V put(K key, V value) { System.nanoTime(); int index = theHasher(key); if (array[index] == null) { array[index] = new LinkedList<Entry<K, V>>(); size++; } for (Entry<K, V> nextItem : array[index]) { if (nextItem.getKey().equals(key)) { V temp = nextItem.getValue(); nextItem.setValue(value); return temp; // Previous value is returned. } } array[index].addFirst(new Entry<K, V>(key, value)); // addFirst method from Java LinkedList numElements++; long sysTime = System.nanoTime(); if (printTimes == true) { System.out.print("This put process took " + sysTime + " nanoseconds." + "\n"); } return null; // No previous value to return. }
public void put(K key, V value) { int index = key.hashCode(); // Wir können uns an dieser Stelle sicher sein, dass das Objekt eine // LinkedList mit entsprechendem Entry ist, // da wir keinen Zugriff von außen auf das Array erlauben @SuppressWarnings("unchecked") LinkedList<Entry<K, V>> list = (LinkedList<Entry<K, V>>) this.values[index]; // Wenn die Liste noch nicht existiert if (list == null) { list = new LinkedList<Entry<K, V>>(); this.values[index] = list; n--; } // Wenn das Element mit dem gegeben Schlüssel existiert, dann überschreiben den Wert boolean containsKey = false; for (Entry<K, V> e : list) { if (e.getKey().equals(key)) { e.setValue(value); containsKey = true; break; } } // füge an das Ende der Liste ein Entry Element bestehend aus Wert und Punkt ein, wenn // das Element noch nicht existiert. if (containsKey == false) { Entry<K, V> item = new Entry<K, V>(key, value); list.add(item); entrySet.add(item); n++; } size++; }
/** * priavate! Why is this method so long? Because it has to deal with a lot of checking and * recompression to make sure that everything is compressed correctly and in the right place. * * @param entryIndex see step 1 * @param indexWithinEntry see step1 * @param val the value, just like step 1 which you should have looked at * @throws Exception same as step 1 */ private void setStepTwo(int entryIndex, int indexWithinEntry, int val) throws Exception { Entry previousEntry = null; Entry currentEntry = compressedSequence.get(entryIndex); if (entryIndex > 0) { previousEntry = compressedSequence.get(entryIndex - 1); } Entry nextEntry = null; if (entryIndex < compressedSequence.size() - 1) { nextEntry = compressedSequence.get(entryIndex + 1); } // case 1 if (currentEntry.getNumber() == 1) { currentEntry.setValue(val); Entry firstCompare = compareTwo(previousEntry, currentEntry); Entry secondCompare = compareTwo(currentEntry, nextEntry); if (firstCompare != null && secondCompare != null) { Entry thirdCompare = compareTwo(firstCompare, secondCompare); compressedSequence.set(entryIndex, thirdCompare); compressedSequence.remove(entryIndex - 1); // since we've shifted one to the left compressedSequence.remove(entryIndex); } else if (secondCompare != null) { compressedSequence.set(entryIndex, secondCompare); compressedSequence.remove(entryIndex + 1); } else if (firstCompare != null) { compressedSequence.set(entryIndex, firstCompare); compressedSequence.remove(entryIndex - 1); } } // case 2 else { // these are sub-entries Entry previousStuff = null; Entry nextStuff = null; Entry userInsertedEntry = null; for (int i = 0; i < currentEntry.getNumber(); i++) { if (i == indexWithinEntry) { if (i != 0) { previousStuff = new Entry(i, currentEntry.getValue()); } if (i < currentEntry.getNumber() - 1) { nextStuff = new Entry(currentEntry.getNumber() - i - 1, currentEntry.getValue()); } userInsertedEntry = new Entry(1, val); } } if (previousStuff != null && nextStuff != null) { compressedSequence.set(entryIndex, userInsertedEntry); compressedSequence.add(entryIndex + 1, nextStuff); compressedSequence.add(entryIndex, previousStuff); } else if (previousStuff != null) { Entry one = compareTwo(nextEntry, userInsertedEntry); if (one != null) { compressedSequence.set(entryIndex + 1, one); currentEntry.setNumber(currentEntry.getNumber() - 1); } else { compressedSequence.set(entryIndex, userInsertedEntry); compressedSequence.add(entryIndex, previousStuff); } } else if (nextStuff != null) { Entry two = compareTwo(previousEntry, userInsertedEntry); if (two != null) { compressedSequence.set(entryIndex - 1, two); currentEntry.setNumber(currentEntry.getNumber() - 1); } else { compressedSequence.set(entryIndex, userInsertedEntry); compressedSequence.add(entryIndex + 1, nextStuff); } } else { // this is mathematically impossible because // it is handled above, in case 1 } } }
@Override public V setValue(V value) { return ent.setValue(value); }
public V remove(Object key) { Entry<K, V>[] tab = this.table; if (key != null) { int hash = key.hashCode(); int index = (hash & 0x7fffffff) % tab.length; for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) { V entryValue = e.get(); if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } this.count--; } else if (e.hash == hash && key.equals(e.key)) { this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } this.count--; e.setValue(null); return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } else { for (Entry<K, V> e = tab[0], prev = null; e != null; e = e.next) { V entryValue = e.get(); if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[0] = e.next; } this.count--; } else if (e.key == null) { this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[0] = e.next; } this.count--; e.setValue(null); return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } return null; }
public V put(K key, V value) { if (value == null) { value = (V) KeyFactory.NULL; } // Makes sure the key is not already in the HashMap. Entry<K, V>[] tab = this.table; int hash; int index; if (key != null) { hash = key.hashCode(); index = (hash & 0x7fffffff) % tab.length; for (Entry<K, V> e = tab[index], prev = null; e != null; e = e.next) { V entryValue = e.get(); if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[index] = e.next; } this.count--; } else if (e.hash == hash && key.equals(e.key)) { e.setValue(value); return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } else { hash = 0; index = 0; for (Entry<K, V> e = tab[0], prev = null; e != null; e = e.next) { V entryValue = e.get(); if (entryValue == null) { // Clean up after a cleared Reference. this.modCount++; if (prev != null) { prev.next = e.next; } else { tab[0] = e.next; } this.count--; } else if (e.key == null) { e.setValue(value); return (entryValue == KeyFactory.NULL) ? null : entryValue; } else { prev = e; } } } this.modCount++; if (this.count >= this.threshold) { // Cleanup the table if the threshold is exceeded. cleanup(); } if (this.count >= this.threshold) { // Rehash the table if the threshold is still exceeded. rehash(); tab = this.table; index = (hash & 0x7fffffff) % tab.length; } // Creates the new entry. Entry<K, V> e = newEntry(hash, key, (V) value, tab[index]); tab[index] = e; this.count++; return null; }
/** * Sets the value of the entry, and returns the former value. The value is {@link #validateValue * validated}. * * @param entry the entry. * @param value the value. * @return the former value, or <code>null</code>. */ protected V putEntry(Entry<K, V> entry, V value) { return entry.setValue(value); }