/** * {@inheritDoc} */ @Override public synchronized String toString() { StringBuffer aLog = new StringBuffer(2000); aLog.append("\t---- cache ----"); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { aLog.append("\n\t\t"); aLog.append(entry.toString()); } return aLog.toString(); }
/** * {@inheritDoc} */ @Override public synchronized String toString() { StringBuffer aLog = new StringBuffer(2000); aLog.append("\t---- cache ----"); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { aLog.append("\n\t\t"); aLog.append(entry.toString()); } return aLog.toString(); }
/** * {@inheritDoc} */ @Override public synchronized String toString() { StringBuffer aLog = new StringBuffer(2000); aLog.append("\t---- cache ----"); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { aLog.append("\n\t\t"); aLog.append(entry.toString()); } return aLog.toString(); }
/** * @param key * @return map entry for the key */ protected Map.Entry<String, List<? extends DNSEntry>> getEntry(String key) { String stringKey = (key != null ? key.trim().toLowerCase() : null); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { if (stringKey != null) { if (stringKey.equals(entry.getKey())) { return entry; } } else { if (entry.getKey() == null) { return entry; } } } return null; }
/** * @param key * @return map entry for the key */ protected Map.Entry<String, List<? extends DNSEntry>> getEntry(String key) { String stringKey = (key != null ? key.trim().toLowerCase() : null); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { if (stringKey != null) { if (stringKey.equals(entry.getKey())) { return entry; } } else { if (entry.getKey() == null) { return entry; } } } return null; }
/** * @param key * @return map entry for the key */ protected Map.Entry<String, List<? extends DNSEntry>> getEntry(String key) { String stringKey = (key != null ? key.trim().toLowerCase() : null); for (Map.Entry<String, List<? extends DNSEntry>> entry : this.entrySet()) { if (stringKey != null) { if (stringKey.equals(entry.getKey())) { return entry; } } else { if (entry.getKey() == null) { return entry; } } } return null; }
/** * {@inheritDoc} */ @Override public synchronized String toString() { final StringBuilder sb = new StringBuilder(2000); sb.append("\n\t---- cache ----"); for(final Map.Entry<String, List<DNSEntry>> entry : this.entrySet()) { sb.append("\n\n\t\tname '").append(entry.getKey()).append('\''); final List<DNSEntry> entryList = entry.getValue(); if ((entryList != null) && (!entryList.isEmpty())) { synchronized (entryList) { for (DNSEntry dnsEntry : entryList) { sb.append("\n\t\t\t").append(dnsEntry.toString()); } } } else { sb.append(" : no entries"); } } return sb.toString(); }
/** * {@inheritDoc} */ @Override public List<? extends DNSEntry> put(String key, List<? extends DNSEntry> value) { synchronized (this) { List<? extends DNSEntry> oldValue = null; Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(key); if (oldEntry != null) { oldValue = oldEntry.setValue(value); } else { this.entrySet().add(new _CacheEntry(key, value)); } return oldValue; } }
/** * Removes a specific entry from the table. Returns true if the entry was found. * * @param dnsEntry * @return true if the entry was removed */ public synchronized boolean removeDNSEntry(DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> existingEntry = this.getEntry(dnsEntry.getKey()); if (existingEntry != null) { result = existingEntry.getValue().remove(dnsEntry); // If we just removed the last one we need to get rid of the entry if (existingEntry.getValue().isEmpty()) { this.entrySet().remove(existingEntry); } } } return result; }
/** * Removes a specific entry from the table. Returns true if the entry was found. * * @param dnsEntry * @return true if the entry was removed */ public synchronized boolean removeDNSEntry(DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> existingEntry = this.getEntry(dnsEntry.getKey()); if (existingEntry != null) { result = existingEntry.getValue().remove(dnsEntry); // If we just removed the last one we need to get rid of the entry if (existingEntry.getValue().isEmpty()) { this.entrySet().remove(existingEntry); } } } return result; }
/** * {@inheritDoc} */ @Override public List<? extends DNSEntry> put(String key, List<? extends DNSEntry> value) { synchronized (this) { List<? extends DNSEntry> oldValue = null; Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(key); if (oldEntry != null) { oldValue = oldEntry.setValue(value); } else { this.entrySet().add(new _CacheEntry(key, value)); } return oldValue; } }
/** * Removes a specific entry from the table. Returns true if the entry was found. * * @param dnsEntry * @return true if the entry was removed */ public synchronized boolean removeDNSEntry(DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> existingEntry = this.getEntry(dnsEntry.getKey()); if (existingEntry != null) { result = existingEntry.getValue().remove(dnsEntry); // If we just removed the last one we need to get rid of the entry if (existingEntry.getValue().isEmpty()) { this.entrySet().remove(existingEntry); } } } return result; }
/** * {@inheritDoc} */ @Override public List<? extends DNSEntry> put(String key, List<? extends DNSEntry> value) { synchronized (this) { List<? extends DNSEntry> oldValue = null; Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(key); if (oldEntry != null) { oldValue = oldEntry.setValue(value); } else { this.entrySet().add(new _CacheEntry(key, value)); } return oldValue; } }
/** * Adds an entry to the table. * * @param dnsEntry * @return true if the entry was added */ public synchronized boolean addDNSEntry(final DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(dnsEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.add(dnsEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(dnsEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }
/** * Adds an entry to the table. * * @param dnsEntry * @return true if the entry was added */ public synchronized boolean addDNSEntry(final DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(dnsEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.add(dnsEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(dnsEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }
/** * Adds an entry to the table. * * @param dnsEntry * @return true if the entry was added */ public synchronized boolean addDNSEntry(final DNSEntry dnsEntry) { boolean result = false; if (dnsEntry != null) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(dnsEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.add(dnsEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(dnsEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }
/** * Replace an existing entry by a new one.<br/> * <b>Note:</b> the 2 entries must have the same key. * * @param newDNSEntry * @param existingDNSEntry * @return <code>true</code> if the entry has been replace, <code>false</code> otherwise. */ public synchronized boolean replaceDNSEntry(DNSEntry newDNSEntry, DNSEntry existingDNSEntry) { boolean result = false; if ((newDNSEntry != null) && (existingDNSEntry != null) && (newDNSEntry.getKey().equals(existingDNSEntry.getKey()))) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(newDNSEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.remove(existingDNSEntry); aNewValue.add(newDNSEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(newDNSEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }
/** * Replace an existing entry by a new one.<br/> * <b>Note:</b> the 2 entries must have the same key. * * @param newDNSEntry * @param existingDNSEntry * @return <code>true</code> if the entry has been replace, <code>false</code> otherwise. */ public synchronized boolean replaceDNSEntry(DNSEntry newDNSEntry, DNSEntry existingDNSEntry) { boolean result = false; if ((newDNSEntry != null) && (existingDNSEntry != null) && (newDNSEntry.getKey().equals(existingDNSEntry.getKey()))) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(newDNSEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.remove(existingDNSEntry); aNewValue.add(newDNSEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(newDNSEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }
/** * Replace an existing entry by a new one.<br/> * <b>Note:</b> the 2 entries must have the same key. * * @param newDNSEntry * @param existingDNSEntry * @return <code>true</code> if the entry has been replace, <code>false</code> otherwise. */ public synchronized boolean replaceDNSEntry(DNSEntry newDNSEntry, DNSEntry existingDNSEntry) { boolean result = false; if ((newDNSEntry != null) && (existingDNSEntry != null) && (newDNSEntry.getKey().equals(existingDNSEntry.getKey()))) { Map.Entry<String, List<? extends DNSEntry>> oldEntry = this.getEntry(newDNSEntry.getKey()); List<DNSEntry> aNewValue = null; if (oldEntry != null) { aNewValue = new ArrayList<DNSEntry>(oldEntry.getValue()); } else { aNewValue = new ArrayList<DNSEntry>(); } aNewValue.remove(existingDNSEntry); aNewValue.add(newDNSEntry); if (oldEntry != null) { oldEntry.setValue(aNewValue); } else { this.entrySet().add(new _CacheEntry(newDNSEntry.getKey(), aNewValue)); } // This is probably not very informative result = true; } return result; }