diff --git a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/SystemUtil.java b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/SystemUtil.java index a113752e68..c3d25a949e 100644 --- a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/SystemUtil.java +++ b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/SystemUtil.java @@ -23,9 +23,9 @@ import java.lang.management.ManagementFactory; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; + +import com.raytheon.uf.common.util.collections.BoundedMap; /** * System utilities such as hostname and pid lookup. @@ -44,30 +44,6 @@ import java.util.Map.Entry; * @version 1.0 */ public class SystemUtil { - /** - * Map that can be limited to a given number of entries. - */ - private static class BoundedMap extends LinkedHashMap { - private static final long serialVersionUID = 1L; - - private final int maxSize; - - public BoundedMap(int maxSize) { - super(16, 0.75f, true); - this.maxSize = maxSize; - } - - /* - * (non-Javadoc) - * - * @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry) - */ - @Override - protected boolean removeEldestEntry(Entry eldest) { - return size() > maxSize; - } - } - private static final Map hostNameCache = Collections .synchronizedMap(new BoundedMap(100)); diff --git a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/collections/BoundedMap.java b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/collections/BoundedMap.java new file mode 100644 index 0000000000..ad7b52006b --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/collections/BoundedMap.java @@ -0,0 +1,109 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.util.collections; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +/** + * Map implementation that limits the map to a specified number of entries. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 14, 2014 2726       rjpeter     Initial creation
+ * 
+ * 
+ * + * @author rjpeter + * @version 1.0 + * @param + * @param + */ +public class BoundedMap extends LinkedHashMap { + private static final long serialVersionUID = 1L; + + private static final int DEFAULT_INITIAL_SIZE = 16; + + private static final float DEFAULT_LOAD_FACTOR = 0.75f; + + private final int maxSize; + + /** + * BoundedMap with specified max size. Defaults to accessOrder elimination. + * + * @param maxSize + */ + public BoundedMap(int maxSize) { + this(maxSize, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR, true); + } + + /** + * BoundedMap with specified initial and max size. Defaults to accessOrder + * elimination. + * + * @param maxSize + * @param initialSize + */ + public BoundedMap(int maxSize, int initialSize) { + this(maxSize, initialSize, DEFAULT_LOAD_FACTOR, true); + } + + /** + * BoundedMap with specified initial size, max size, and loadFactor. + * Defaults to accessOrder elimination. + * + * @param maxSize + * @param initialSize + * @param loadFactor + */ + public BoundedMap(int maxSize, int initialSize, float loadFactor) { + this(maxSize, initialSize, loadFactor, true); + } + + /** + * BoundedMap with specified initial size, max size, loadFactor, and + * accessOrder elimination. If accessOrder is true, map is order by + * accessOrder, false is insertion order. + * + * @param maxSize + * @param initialSize + * @param loadFactor + * @param accessOrder + */ + public BoundedMap(int maxSize, int initialSize, float loadFactor, + boolean accessOrder) { + super(initialSize, loadFactor, accessOrder); + this.maxSize = maxSize; + } + + /* + * (non-Javadoc) + * + * @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry) + */ + @Override + protected boolean removeEldestEntry(Entry eldest) { + return size() > maxSize; + } +}