mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-02 11:05:29 -04:00
New code style. No functional changes.
This commit is contained in:
parent
c60f80aacb
commit
ba4ff3dc45
@ -81,8 +81,7 @@ public final class SystemUtil {
|
||||
*
|
||||
* @return an input stream reading from the resource
|
||||
*/
|
||||
private static InputStream getResourceAsStream(ClassLoader pClassLoader, String pName,
|
||||
boolean pGuessSuffix) {
|
||||
private static InputStream getResourceAsStream(ClassLoader pClassLoader, String pName, boolean pGuessSuffix) {
|
||||
InputStream is;
|
||||
|
||||
if (!pGuessSuffix) {
|
||||
@ -122,8 +121,7 @@ public final class SystemUtil {
|
||||
*
|
||||
* @return an input stream reading from the resource
|
||||
*/
|
||||
private static InputStream getFileAsStream(String pName,
|
||||
boolean pGuessSuffix) {
|
||||
private static InputStream getFileAsStream(String pName, boolean pGuessSuffix) {
|
||||
InputStream is = null;
|
||||
File propertiesFile;
|
||||
|
||||
@ -206,8 +204,7 @@ public final class SystemUtil {
|
||||
* @todo Reconsider ever using the System ClassLoader: http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html
|
||||
* @todo Consider using Context Classloader instead?
|
||||
*/
|
||||
public static Properties loadProperties(Class pClass, String pName)
|
||||
throws IOException
|
||||
public static Properties loadProperties(Class pClass, String pName) throws IOException
|
||||
{
|
||||
// Convert to name the classloader understands
|
||||
String name = !StringUtil.isEmpty(pName) ? pName : pClass.getName().replace('.', '/');
|
||||
@ -219,8 +216,7 @@ public final class SystemUtil {
|
||||
|
||||
// TODO: WHAT IF MULTIPLE RESOURCES EXISTS?!
|
||||
// Try loading resource through the current class' classloader
|
||||
if (pClass != null
|
||||
&& (is = getResourceAsStream(pClass.getClassLoader(), name, guessSuffix)) != null) {
|
||||
if (pClass != null && (is = getResourceAsStream(pClass.getClassLoader(), name, guessSuffix)) != null) {
|
||||
//&& (is = getResourceAsStream(pClass, name, guessSuffix)) != null) {
|
||||
// Nothing to do
|
||||
//System.out.println(((is instanceof XMLPropertiesInputStream) ?
|
||||
@ -228,9 +224,8 @@ public final class SystemUtil {
|
||||
// + " from Class' ClassLoader");
|
||||
}
|
||||
// If that fails, try the system classloader
|
||||
else if ((is = getResourceAsStream(ClassLoader.getSystemClassLoader(),
|
||||
name, guessSuffix)) != null) {
|
||||
//else if ((is = getSystemResourceAsStream(name, guessSuffix)) != null) {
|
||||
else if ((is = getResourceAsStream(ClassLoader.getSystemClassLoader(), name, guessSuffix)) != null) {
|
||||
//else if ((is = getSystemResourceAsStream(name, guessSuffix)) != null) {
|
||||
// Nothing to do
|
||||
//System.out.println(((is instanceof XMLPropertiesInputStream) ?
|
||||
// "XML-properties" : "Normal .properties")
|
||||
|
@ -40,12 +40,12 @@ import java.io.Serializable;
|
||||
*/
|
||||
// TODO: The generics in this class looks suspicious..
|
||||
abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements Map<K, V>, Serializable, Cloneable {
|
||||
protected Map<K, Entry<K, V>> mEntries;
|
||||
protected transient volatile int mModCount;
|
||||
protected Map<K, Entry<K, V>> entries;
|
||||
protected transient volatile int modCount;
|
||||
|
||||
private transient volatile Set<Entry<K, V>> mEntrySet = null;
|
||||
private transient volatile Set<K> mKeySet = null;
|
||||
private transient volatile Collection<V> mValues = null;
|
||||
private transient volatile Set<Entry<K, V>> entrySet = null;
|
||||
private transient volatile Set<K> keySet = null;
|
||||
private transient volatile Collection<V> values = null;
|
||||
|
||||
/**
|
||||
* Creates a {@code Map} backed by a {@code HashMap}.
|
||||
@ -104,7 +104,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
throw new IllegalArgumentException("backing must be empty");
|
||||
}
|
||||
|
||||
mEntries = pBacking;
|
||||
this.entries = pBacking;
|
||||
init();
|
||||
|
||||
if (pContents != null) {
|
||||
@ -125,21 +125,21 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mEntries.size();
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mEntries.clear();
|
||||
mModCount++;
|
||||
entries.clear();
|
||||
modCount++;
|
||||
init();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mEntries.isEmpty();
|
||||
return entries.isEmpty();
|
||||
}
|
||||
|
||||
public boolean containsKey(Object pKey) {
|
||||
return mEntries.containsKey(pKey);
|
||||
return entries.containsKey(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,18 +166,18 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
}
|
||||
|
||||
public Collection<V> values() {
|
||||
Collection<V> values = mValues;
|
||||
return values != null ? values : (mValues = new Values());
|
||||
Collection<V> values = this.values;
|
||||
return values != null ? values : (this.values = new Values());
|
||||
}
|
||||
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
Set<Entry<K, V>> es = mEntrySet;
|
||||
return es != null ? es : (mEntrySet = new EntrySet());
|
||||
Set<Entry<K, V>> es = entrySet;
|
||||
return es != null ? es : (entrySet = new EntrySet());
|
||||
}
|
||||
|
||||
public Set<K> keySet() {
|
||||
Set<K> ks = mKeySet;
|
||||
return ks != null ? ks : (mKeySet = new KeySet());
|
||||
Set<K> ks = keySet;
|
||||
return ks != null ? ks : (keySet = new KeySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,9 +189,9 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
AbstractDecoratedMap map = (AbstractDecoratedMap) super.clone();
|
||||
|
||||
map.mValues = null;
|
||||
map.mEntrySet = null;
|
||||
map.mKeySet = null;
|
||||
map.values = null;
|
||||
map.entrySet = null;
|
||||
map.keySet = null;
|
||||
|
||||
// TODO: Implement: Need to clone the backing map...
|
||||
|
||||
@ -217,7 +217,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
}
|
||||
|
||||
/*protected*/ Entry<K, V> getEntry(K pKey) {
|
||||
return mEntries.get(pKey);
|
||||
return entries.get(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +271,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
Entry e = (Entry) o;
|
||||
|
||||
//noinspection SuspiciousMethodCalls
|
||||
Entry<K, V> candidate = mEntries.get(e.getKey());
|
||||
Entry<K, V> candidate = entries.get(e.getKey());
|
||||
return candidate != null && candidate.equals(e);
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ abstract class AbstractDecoratedMap<K, V> extends AbstractMap<K, V> implements M
|
||||
// NOTE: Extra cautions is taken, to only remove the entry if it
|
||||
// equals the entry in the map
|
||||
Object key = ((Entry) o).getKey();
|
||||
Entry entry = (Entry) mEntries.get(key);
|
||||
Entry entry = (Entry) entries.get(key);
|
||||
|
||||
// Same entry?
|
||||
if (entry != null && entry.equals(o)) {
|
||||
|
@ -36,8 +36,8 @@ package com.twelvemonkeys.util;
|
||||
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/AbstractResource.java#1 $
|
||||
*/
|
||||
abstract class AbstractResource implements Resource {
|
||||
protected final Object mResourceId;
|
||||
protected final Object mWrappedResource;
|
||||
protected final Object resourceId;
|
||||
protected final Object wrappedResource;
|
||||
|
||||
/**
|
||||
* Creates a {@code Resource}.
|
||||
@ -53,12 +53,12 @@ abstract class AbstractResource implements Resource {
|
||||
throw new IllegalArgumentException("resource == null");
|
||||
}
|
||||
|
||||
mResourceId = pResourceId;
|
||||
mWrappedResource = pWrappedResource;
|
||||
resourceId = pResourceId;
|
||||
wrappedResource = pWrappedResource;
|
||||
}
|
||||
|
||||
public final Object getId() {
|
||||
return mResourceId;
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ abstract class AbstractResource implements Resource {
|
||||
* @return {@code mWrapped.hashCode()}
|
||||
*/
|
||||
public int hashCode() {
|
||||
return mWrappedResource.hashCode();
|
||||
return wrappedResource.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,6 +87,6 @@ abstract class AbstractResource implements Resource {
|
||||
*/
|
||||
public boolean equals(Object pObject) {
|
||||
return pObject instanceof AbstractResource
|
||||
&& mWrappedResource.equals(((AbstractResource) pObject).mWrappedResource);
|
||||
&& wrappedResource.equals(((AbstractResource) pObject).wrappedResource);
|
||||
}
|
||||
}
|
||||
|
@ -44,16 +44,16 @@ import java.io.Serializable;
|
||||
* <a href="http://binkley.blogspot.com/2006/08/mapping-java-bean.html>Binkley's Blog</a>
|
||||
*/
|
||||
public final class BeanMap extends AbstractMap<String, Object> implements Serializable, Cloneable {
|
||||
private final Object mBean;
|
||||
private transient Set<PropertyDescriptor> mDescriptors;
|
||||
private final Object bean;
|
||||
private transient Set<PropertyDescriptor> descriptors;
|
||||
|
||||
public BeanMap(Object pBean) throws IntrospectionException {
|
||||
if (pBean == null) {
|
||||
throw new IllegalArgumentException("bean == null");
|
||||
}
|
||||
|
||||
mBean = pBean;
|
||||
mDescriptors = initDescriptors(pBean);
|
||||
bean = pBean;
|
||||
descriptors = initDescriptors(pBean);
|
||||
}
|
||||
|
||||
private static Set<PropertyDescriptor> initDescriptors(Object pBean) throws IntrospectionException {
|
||||
@ -100,7 +100,7 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mDescriptors.size();
|
||||
return descriptors.size();
|
||||
}
|
||||
|
||||
private String checkKey(final Object pKey) {
|
||||
@ -119,17 +119,17 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
|
||||
|
||||
private Object readResolve() throws IntrospectionException {
|
||||
// Initialize the property descriptors
|
||||
mDescriptors = initDescriptors(mBean);
|
||||
descriptors = initDescriptors(bean);
|
||||
return this;
|
||||
}
|
||||
|
||||
private class BeanSet extends AbstractSet<Entry<String, Object>> {
|
||||
public Iterator<Entry<String, Object>> iterator() {
|
||||
return new BeanIterator(mDescriptors.iterator());
|
||||
return new BeanIterator(descriptors.iterator());
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mDescriptors.size();
|
||||
return descriptors.size();
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
|
||||
throw new UnsupportedOperationException("No getter: " + mDescriptor.getName());
|
||||
}
|
||||
|
||||
return method.invoke(mBean);
|
||||
return method.invoke(bean);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -188,7 +188,7 @@ public final class BeanMap extends AbstractMap<String, Object> implements Serial
|
||||
}
|
||||
|
||||
final Object old = getValue();
|
||||
method.invoke(mBean, pValue);
|
||||
method.invoke(bean, pValue);
|
||||
return old;
|
||||
}
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ final class FileResource extends AbstractResource {
|
||||
}
|
||||
|
||||
private File getFile() {
|
||||
return (File) mWrappedResource;
|
||||
return (File) wrappedResource;
|
||||
}
|
||||
|
||||
public URL asURL() {
|
||||
|
@ -49,11 +49,11 @@ import java.util.NoSuchElementException;
|
||||
*/
|
||||
public class FilterIterator<E> implements Iterator<E> {
|
||||
|
||||
protected final Filter<E> mFilter;
|
||||
protected final Iterator<E> mIterator;
|
||||
protected final Filter<E> filter;
|
||||
protected final Iterator<E> iterator;
|
||||
|
||||
private E mNext = null;
|
||||
private E mCurrent = null;
|
||||
private E next = null;
|
||||
private E current = null;
|
||||
|
||||
/**
|
||||
* Creates a {@code FilterIterator} that wraps the {@code Iterator}. Each
|
||||
@ -72,8 +72,8 @@ public class FilterIterator<E> implements Iterator<E> {
|
||||
throw new IllegalArgumentException("filter == null");
|
||||
}
|
||||
|
||||
mIterator = pIterator;
|
||||
mFilter = pFilter;
|
||||
iterator = pIterator;
|
||||
filter = pFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,16 +85,16 @@ public class FilterIterator<E> implements Iterator<E> {
|
||||
* @see FilterIterator.Filter#accept
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
while (mNext == null && mIterator.hasNext()) {
|
||||
E element = mIterator.next();
|
||||
while (next == null && iterator.hasNext()) {
|
||||
E element = iterator.next();
|
||||
|
||||
if (mFilter.accept(element)) {
|
||||
mNext = element;
|
||||
if (filter.accept(element)) {
|
||||
next = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return mNext != null;
|
||||
return next != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,11 +105,11 @@ public class FilterIterator<E> implements Iterator<E> {
|
||||
*/
|
||||
public E next() {
|
||||
if (hasNext()) {
|
||||
mCurrent = mNext;
|
||||
current = next;
|
||||
|
||||
// Make sure we advance next time
|
||||
mNext = null;
|
||||
return mCurrent;
|
||||
next = null;
|
||||
return current;
|
||||
}
|
||||
else {
|
||||
throw new NoSuchElementException("Iteration has no more elements.");
|
||||
@ -124,8 +124,8 @@ public class FilterIterator<E> implements Iterator<E> {
|
||||
* progress in any way other than by calling this method.
|
||||
*/
|
||||
public void remove() {
|
||||
if (mCurrent != null) {
|
||||
mIterator.remove();
|
||||
if (current != null) {
|
||||
iterator.remove();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Iteration has no current element.");
|
||||
|
@ -107,7 +107,7 @@ public class IgnoreCaseMap<V> extends AbstractDecoratedMap<String, V> implements
|
||||
*/
|
||||
public V put(String pKey, V pValue) {
|
||||
String key = (String) toUpper(pKey);
|
||||
return unwrap(mEntries.put(key, new BasicEntry<String, V>(key, pValue)));
|
||||
return unwrap(entries.put(key, new BasicEntry<String, V>(key, pValue)));
|
||||
}
|
||||
|
||||
private V unwrap(Entry<String, V> pEntry) {
|
||||
@ -124,7 +124,7 @@ public class IgnoreCaseMap<V> extends AbstractDecoratedMap<String, V> implements
|
||||
* the key is not mapped to any value in this map.
|
||||
*/
|
||||
public V get(Object pKey) {
|
||||
return unwrap(mEntries.get(toUpper(pKey)));
|
||||
return unwrap(entries.get(toUpper(pKey)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +137,7 @@ public class IgnoreCaseMap<V> extends AbstractDecoratedMap<String, V> implements
|
||||
* or null if the key did not have a mapping.
|
||||
*/
|
||||
public V remove(Object pKey) {
|
||||
return unwrap(mEntries.remove(toUpper(pKey)));
|
||||
return unwrap(entries.remove(toUpper(pKey)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +149,7 @@ public class IgnoreCaseMap<V> extends AbstractDecoratedMap<String, V> implements
|
||||
* map, as determined by the equals method; false otherwise.
|
||||
*/
|
||||
public boolean containsKey(Object pKey) {
|
||||
return mEntries.containsKey(toUpper(pKey));
|
||||
return entries.containsKey(toUpper(pKey));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,14 +163,14 @@ public class IgnoreCaseMap<V> extends AbstractDecoratedMap<String, V> implements
|
||||
}
|
||||
|
||||
protected Iterator<Entry<String, V>> newEntryIterator() {
|
||||
return (Iterator) mEntries.entrySet().iterator();
|
||||
return (Iterator) entries.entrySet().iterator();
|
||||
}
|
||||
|
||||
protected Iterator<String> newKeyIterator() {
|
||||
return mEntries.keySet().iterator();
|
||||
return entries.keySet().iterator();
|
||||
}
|
||||
|
||||
protected Iterator<V> newValueIterator() {
|
||||
return (Iterator<V>) mEntries.values().iterator();
|
||||
return (Iterator<V>) entries.values().iterator();
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ import java.util.Iterator;
|
||||
*/
|
||||
public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap<K, V> {
|
||||
|
||||
private int mMaxSize = 1000;
|
||||
private float mTrimFactor = 0.01f;
|
||||
private int maxSize = 1000;
|
||||
private float trimFactor = 0.01f;
|
||||
|
||||
/**
|
||||
* Creates an LRUHashMap with default max size (1000 entries).
|
||||
@ -113,7 +113,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
* @return the size limit
|
||||
*/
|
||||
public int getMaxSize() {
|
||||
return mMaxSize;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,9 +131,9 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
throw new IllegalArgumentException("max size must be positive");
|
||||
}
|
||||
|
||||
mMaxSize = pMaxSize;
|
||||
maxSize = pMaxSize;
|
||||
|
||||
while(size() > mMaxSize) {
|
||||
while(size() > maxSize) {
|
||||
removeLRU();
|
||||
}
|
||||
}
|
||||
@ -148,7 +148,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
* @return the current trim factor
|
||||
*/
|
||||
public float getTrimFactor() {
|
||||
return mTrimFactor;
|
||||
return trimFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +168,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
throw new IllegalArgumentException("trim factor must be between 0 and 1");
|
||||
}
|
||||
|
||||
mTrimFactor = pTrimFactor;
|
||||
trimFactor = pTrimFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,7 +178,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
protected boolean removeEldestEntry(Map.Entry<K, V> pEldest) {
|
||||
// NOTE: As removeLRU() may remove more than one entry, this is better
|
||||
// than simply removing the eldest entry.
|
||||
if (size() >= mMaxSize) {
|
||||
if (size() >= maxSize) {
|
||||
removeLRU();
|
||||
}
|
||||
return false;
|
||||
@ -204,7 +204,7 @@ public class LRUHashMap<K, V> extends LinkedHashMap<K, V> implements ExpiringMap
|
||||
* @see #getTrimFactor()
|
||||
*/
|
||||
public void removeLRU() {
|
||||
int removeCount = (int) Math.max((size() * mTrimFactor), 1);
|
||||
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
||||
Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
|
||||
while ((removeCount--) > 0 && entries.hasNext()) {
|
||||
entries.next();
|
||||
|
@ -49,8 +49,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
|
||||
private int mMaxSize = 1000;
|
||||
private float mTrimFactor = 0.01f;
|
||||
private int maxSize = 1000;
|
||||
private float trimFactor = 0.01f;
|
||||
|
||||
/**
|
||||
* Creates an LRUMap with default max size (1000 entries).
|
||||
@ -124,7 +124,7 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
* @return the size limit
|
||||
*/
|
||||
public int getMaxSize() {
|
||||
return mMaxSize;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,9 +142,9 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
throw new IllegalArgumentException("max size must be positive");
|
||||
}
|
||||
|
||||
mMaxSize = pMaxSize;
|
||||
maxSize = pMaxSize;
|
||||
|
||||
while(size() > mMaxSize) {
|
||||
while(size() > maxSize) {
|
||||
removeLRU();
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
* @return the current trim factor
|
||||
*/
|
||||
public float getTrimFactor() {
|
||||
return mTrimFactor;
|
||||
return trimFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,7 +179,7 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
throw new IllegalArgumentException("trim factor must be between 0 and 1");
|
||||
}
|
||||
|
||||
mTrimFactor = pTrimFactor;
|
||||
trimFactor = pTrimFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +189,7 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
protected boolean removeEldestEntry(Entry pEldest) {
|
||||
// NOTE: As removeLRU() may remove more than one entry, this is better
|
||||
// than simply removing the eldest entry.
|
||||
if (size() >= mMaxSize) {
|
||||
if (size() >= maxSize) {
|
||||
removeLRU();
|
||||
}
|
||||
return false;
|
||||
@ -221,9 +221,9 @@ public class LRUMap<K, V> extends LinkedMap<K, V> implements ExpiringMap<K, V> {
|
||||
* @see #getTrimFactor()
|
||||
*/
|
||||
public void removeLRU() {
|
||||
int removeCount = (int) Math.max((size() * mTrimFactor), 1);
|
||||
int removeCount = (int) Math.max((size() * trimFactor), 1);
|
||||
while ((removeCount--) > 0) {
|
||||
removeEntry(mHead.mNext);
|
||||
removeEntry(head.mNext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Serializable {
|
||||
|
||||
transient LinkedEntry<K, V> mHead;
|
||||
protected final boolean mAccessOrder;
|
||||
transient LinkedEntry<K, V> head;
|
||||
protected final boolean accessOrder;
|
||||
|
||||
/**
|
||||
* Creates a {@code LinkedMap} backed by a {@code HashMap}, with default
|
||||
@ -118,7 +118,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
*/
|
||||
public LinkedMap(Map<? extends K, ? extends V> pContents, boolean pAccessOrder) {
|
||||
super(pContents);
|
||||
mAccessOrder = pAccessOrder;
|
||||
accessOrder = pAccessOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,11 +148,11 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
*/
|
||||
public LinkedMap(Map<K, Entry<K, V>> pBacking, Map<? extends K, ? extends V> pContents, boolean pAccessOrder) {
|
||||
super(pBacking, pContents);
|
||||
mAccessOrder = pAccessOrder;
|
||||
accessOrder = pAccessOrder;
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
mHead = new LinkedEntry<K, V>(null, null, null) {
|
||||
head = new LinkedEntry<K, V>(null, null, null) {
|
||||
void addBefore(LinkedEntry pExisting) {
|
||||
throw new Error();
|
||||
}
|
||||
@ -181,19 +181,19 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
return "head";
|
||||
}
|
||||
};
|
||||
mHead.mPrevious = mHead.mNext = mHead;
|
||||
head.mPrevious = head.mNext = head;
|
||||
}
|
||||
|
||||
public boolean containsValue(Object pValue) {
|
||||
// Overridden to take advantage of faster iterator
|
||||
if (pValue == null) {
|
||||
for (LinkedEntry e = mHead.mNext; e != mHead; e = e.mNext) {
|
||||
for (LinkedEntry e = head.mNext; e != head; e = e.mNext) {
|
||||
if (e.mValue == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (LinkedEntry e = mHead.mNext; e != mHead; e = e.mNext) {
|
||||
for (LinkedEntry e = head.mNext; e != head; e = e.mNext) {
|
||||
if (pValue.equals(e.mValue)) {
|
||||
return true;
|
||||
}
|
||||
@ -215,7 +215,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
}
|
||||
|
||||
private abstract class LinkedMapIterator<E> implements Iterator<E> {
|
||||
LinkedEntry<K, V> mNextEntry = mHead.mNext;
|
||||
LinkedEntry<K, V> mNextEntry = head.mNext;
|
||||
LinkedEntry<K, V> mLastReturned = null;
|
||||
|
||||
/**
|
||||
@ -223,10 +223,10 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
* List should have. If this expectation is violated, the iterator
|
||||
* has detected concurrent modification.
|
||||
*/
|
||||
int mExpectedModCount = mModCount;
|
||||
int mExpectedModCount = modCount;
|
||||
|
||||
public boolean hasNext() {
|
||||
return mNextEntry != mHead;
|
||||
return mNextEntry != head;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
@ -234,22 +234,22 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (mModCount != mExpectedModCount) {
|
||||
if (modCount != mExpectedModCount) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
LinkedMap.this.remove(mLastReturned.mKey);
|
||||
mLastReturned = null;
|
||||
|
||||
mExpectedModCount = mModCount;
|
||||
mExpectedModCount = modCount;
|
||||
}
|
||||
|
||||
LinkedEntry<K, V> nextEntry() {
|
||||
if (mModCount != mExpectedModCount) {
|
||||
if (modCount != mExpectedModCount) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
if (mNextEntry == mHead) {
|
||||
if (mNextEntry == head) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
}
|
||||
|
||||
public V get(Object pKey) {
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) mEntries.get(pKey);
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) entries.get(pKey);
|
||||
|
||||
if (entry != null) {
|
||||
entry.recordAccess(this);
|
||||
@ -290,11 +290,11 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
}
|
||||
|
||||
public V remove(Object pKey) {
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) mEntries.remove(pKey);
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) entries.remove(pKey);
|
||||
|
||||
if (entry != null) {
|
||||
entry.remove();
|
||||
mModCount++;
|
||||
modCount++;
|
||||
|
||||
return entry.mValue;
|
||||
}
|
||||
@ -302,22 +302,22 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
}
|
||||
|
||||
public V put(K pKey, V pValue) {
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) mEntries.get(pKey);
|
||||
LinkedEntry<K, V> entry = (LinkedEntry<K, V>) entries.get(pKey);
|
||||
V oldValue;
|
||||
|
||||
if (entry == null) {
|
||||
oldValue = null;
|
||||
|
||||
// Remove eldest entry if instructed, else grow capacity if appropriate
|
||||
LinkedEntry<K, V> eldest = mHead.mNext;
|
||||
LinkedEntry<K, V> eldest = head.mNext;
|
||||
if (removeEldestEntry(eldest)) {
|
||||
removeEntry(eldest);
|
||||
}
|
||||
|
||||
entry = createEntry(pKey, pValue);
|
||||
entry.addBefore(mHead);
|
||||
entry.addBefore(head);
|
||||
|
||||
mEntries.put(pKey, entry);
|
||||
entries.put(pKey, entry);
|
||||
}
|
||||
else {
|
||||
oldValue = entry.mValue;
|
||||
@ -326,7 +326,7 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
entry.recordAccess(this);
|
||||
}
|
||||
|
||||
mModCount++;
|
||||
modCount++;
|
||||
|
||||
return oldValue;
|
||||
}
|
||||
@ -446,10 +446,10 @@ public class LinkedMap<K, V> extends AbstractDecoratedMap<K, V> implements Seria
|
||||
*/
|
||||
protected void recordAccess(Map<K, V> pMap) {
|
||||
LinkedMap<K, V> linkedMap = (LinkedMap<K, V>) pMap;
|
||||
if (linkedMap.mAccessOrder) {
|
||||
linkedMap.mModCount++;
|
||||
if (linkedMap.accessOrder) {
|
||||
linkedMap.modCount++;
|
||||
remove();
|
||||
addBefore(linkedMap.mHead);
|
||||
addBefore(linkedMap.head);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ public class LinkedSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, S
|
||||
|
||||
private final static Object DUMMY = new Object();
|
||||
|
||||
private final Map<E, Object> mMap;
|
||||
private final Map<E, Object> map;
|
||||
|
||||
public LinkedSet() {
|
||||
mMap = new LinkedMap<E, Object>();
|
||||
map = new LinkedMap<E, Object>();
|
||||
}
|
||||
|
||||
public LinkedSet(Collection<E> pCollection) {
|
||||
@ -69,14 +69,14 @@ public class LinkedSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, S
|
||||
}
|
||||
|
||||
public boolean add(E pValue) {
|
||||
return mMap.put(pValue, DUMMY) == null;
|
||||
return map.put(pValue, DUMMY) == null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mMap.size();
|
||||
return map.size();
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return mMap.keySet().iterator();
|
||||
return map.keySet().iterator();
|
||||
}
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ public abstract class ResourceMonitor {
|
||||
|
||||
private static final ResourceMonitor INSTANCE = new ResourceMonitor() {};
|
||||
|
||||
private Timer mTimer;
|
||||
private Timer timer;
|
||||
|
||||
private Map mTimerEntries;
|
||||
private final Map<Object, ResourceMonitorTask> timerEntries;
|
||||
|
||||
public static ResourceMonitor getInstance() {
|
||||
return INSTANCE;
|
||||
@ -66,8 +66,8 @@ public abstract class ResourceMonitor {
|
||||
*/
|
||||
protected ResourceMonitor() {
|
||||
// Create timer, run timer thread as daemon...
|
||||
mTimer = new Timer(true);
|
||||
mTimerEntries = new HashMap();
|
||||
timer = new Timer(true);
|
||||
timerEntries = new HashMap<Object, ResourceMonitorTask>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,12 +95,12 @@ public abstract class ResourceMonitor {
|
||||
Object resourceId = getResourceId(pResourceId, pListener);
|
||||
|
||||
// Remove the old task for this Id, if any, and register the new one
|
||||
synchronized (mTimerEntries) {
|
||||
synchronized (timerEntries) {
|
||||
removeListenerInternal(resourceId);
|
||||
mTimerEntries.put(resourceId, task);
|
||||
timerEntries.put(resourceId, task);
|
||||
}
|
||||
|
||||
mTimer.schedule(task, pPeriod, pPeriod);
|
||||
timer.schedule(task, pPeriod, pPeriod);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,13 +110,13 @@ public abstract class ResourceMonitor {
|
||||
* @param pResourceId name of the resource to monitor.
|
||||
*/
|
||||
public void removeResourceChangeListener(ResourceChangeListener pListener, Object pResourceId) {
|
||||
synchronized (mTimerEntries) {
|
||||
synchronized (timerEntries) {
|
||||
removeListenerInternal(getResourceId(pResourceId, pListener));
|
||||
}
|
||||
}
|
||||
|
||||
private void removeListenerInternal(Object pResourceId) {
|
||||
ResourceMonitorTask task = (ResourceMonitorTask) mTimerEntries.remove(pResourceId);
|
||||
ResourceMonitorTask task = timerEntries.remove(pResourceId);
|
||||
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
|
@ -51,15 +51,15 @@ import java.util.NoSuchElementException;
|
||||
*/
|
||||
public class StringTokenIterator extends AbstractTokenIterator {
|
||||
|
||||
private final String mString;
|
||||
private final char[] mDelimiters;
|
||||
private int mPosition;
|
||||
private final int mMaxPosition;
|
||||
private String mNext;
|
||||
private String mNextDelimiter;
|
||||
private final boolean mIncludeDelimiters;
|
||||
private final boolean mIncludeEmpty;
|
||||
private final boolean mReverse;
|
||||
private final String string;
|
||||
private final char[] delimiters;
|
||||
private int position;
|
||||
private final int maxPosition;
|
||||
private String next;
|
||||
private String nextDelimiter;
|
||||
private final boolean includeDelimiters;
|
||||
private final boolean includeEmpty;
|
||||
private final boolean reverse;
|
||||
|
||||
public final static int FORWARD = 1;
|
||||
public final static int REVERSE = -1;
|
||||
@ -68,7 +68,7 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
* Stores the value of the delimiter character with the highest value.
|
||||
* It is used to optimize the detection of delimiter characters.
|
||||
*/
|
||||
private final char mMaxDelimiter;
|
||||
private final char maxDelimiter;
|
||||
|
||||
/**
|
||||
* Creates a StringTokenIterator
|
||||
@ -141,13 +141,13 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
throw new IllegalArgumentException("string == null");
|
||||
}
|
||||
|
||||
mString = pString;
|
||||
mMaxPosition = pString.length();
|
||||
mDelimiters = pDelimiters;
|
||||
mIncludeDelimiters = pIncludeDelimiters;
|
||||
mReverse = (pDirection == REVERSE);
|
||||
mIncludeEmpty = pIncludeEmpty;
|
||||
mMaxDelimiter = initMaxDelimiter(pDelimiters);
|
||||
string = pString;
|
||||
maxPosition = pString.length();
|
||||
delimiters = pDelimiters;
|
||||
includeDelimiters = pIncludeDelimiters;
|
||||
reverse = (pDirection == REVERSE);
|
||||
includeEmpty = pIncludeEmpty;
|
||||
maxDelimiter = initMaxDelimiter(pDelimiters);
|
||||
|
||||
reset();
|
||||
}
|
||||
@ -184,9 +184,9 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
*
|
||||
*/
|
||||
public void reset() {
|
||||
mPosition = 0;
|
||||
mNext = null;
|
||||
mNextDelimiter = null;
|
||||
position = 0;
|
||||
next = null;
|
||||
nextDelimiter = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,23 +197,23 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
* @return {@code true} if the iterator has more elements.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return (mNext != null || fetchNext() != null);
|
||||
return (next != null || fetchNext() != null);
|
||||
}
|
||||
|
||||
private String fetchNext() {
|
||||
// If next is delimiter, return fast
|
||||
if (mNextDelimiter != null) {
|
||||
mNext = mNextDelimiter;
|
||||
mNextDelimiter = null;
|
||||
return mNext;
|
||||
if (nextDelimiter != null) {
|
||||
next = nextDelimiter;
|
||||
nextDelimiter = null;
|
||||
return next;
|
||||
}
|
||||
|
||||
// If no more chars, return null
|
||||
if (mPosition >= mMaxPosition) {
|
||||
if (position >= maxPosition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mReverse ? fetchReverse() : fetchForward();
|
||||
return reverse ? fetchReverse() : fetchForward();
|
||||
|
||||
}
|
||||
|
||||
@ -222,20 +222,20 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
int prevPos = scanForPrev();
|
||||
|
||||
// Store next string
|
||||
mNext = mString.substring(prevPos + 1, mMaxPosition - mPosition);
|
||||
next = string.substring(prevPos + 1, maxPosition - position);
|
||||
|
||||
if (mIncludeDelimiters && prevPos >= 0 && prevPos < mMaxPosition) {
|
||||
mNextDelimiter = mString.substring(prevPos, prevPos + 1);
|
||||
if (includeDelimiters && prevPos >= 0 && prevPos < maxPosition) {
|
||||
nextDelimiter = string.substring(prevPos, prevPos + 1);
|
||||
}
|
||||
|
||||
mPosition = mMaxPosition - prevPos;
|
||||
position = maxPosition - prevPos;
|
||||
|
||||
// Skip empty
|
||||
if (mNext.length() == 0 && !mIncludeEmpty) {
|
||||
if (next.length() == 0 && !includeEmpty) {
|
||||
return fetchNext();
|
||||
}
|
||||
|
||||
return mNext;
|
||||
return next;
|
||||
}
|
||||
|
||||
private String fetchForward() {
|
||||
@ -243,33 +243,33 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
int nextPos = scanForNext();
|
||||
|
||||
// Store next string
|
||||
mNext = mString.substring(mPosition, nextPos);
|
||||
next = string.substring(position, nextPos);
|
||||
|
||||
if (mIncludeDelimiters && nextPos >= 0 && nextPos < mMaxPosition) {
|
||||
mNextDelimiter = mString.substring(nextPos, nextPos + 1);
|
||||
if (includeDelimiters && nextPos >= 0 && nextPos < maxPosition) {
|
||||
nextDelimiter = string.substring(nextPos, nextPos + 1);
|
||||
}
|
||||
|
||||
mPosition = ++nextPos;
|
||||
position = ++nextPos;
|
||||
|
||||
// Skip empty
|
||||
if (mNext.length() == 0 && !mIncludeEmpty) {
|
||||
if (next.length() == 0 && !includeEmpty) {
|
||||
return fetchNext();
|
||||
}
|
||||
|
||||
return mNext;
|
||||
return next;
|
||||
}
|
||||
|
||||
private int scanForNext() {
|
||||
int position = mPosition;
|
||||
int position = this.position;
|
||||
|
||||
while (position < mMaxPosition) {
|
||||
while (position < maxPosition) {
|
||||
// Find next match, using all delimiters
|
||||
char c = mString.charAt(position);
|
||||
char c = string.charAt(position);
|
||||
|
||||
if (c <= mMaxDelimiter) {
|
||||
if (c <= maxDelimiter) {
|
||||
|
||||
// Find first delimiter match
|
||||
for (char delimiter : mDelimiters) {
|
||||
for (char delimiter : delimiters) {
|
||||
if (c == delimiter) {
|
||||
return position;// Return if match
|
||||
}
|
||||
@ -285,16 +285,16 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
}
|
||||
|
||||
private int scanForPrev() {
|
||||
int position = (mMaxPosition - 1) - mPosition;
|
||||
int position = (maxPosition - 1) - this.position;
|
||||
|
||||
while (position >= 0) {
|
||||
// Find next match, using all delimiters
|
||||
char c = mString.charAt(position);
|
||||
char c = string.charAt(position);
|
||||
|
||||
if (c <= mMaxDelimiter) {
|
||||
if (c <= maxDelimiter) {
|
||||
|
||||
// Find first delimiter match
|
||||
for (char delimiter : mDelimiters) {
|
||||
for (char delimiter : delimiters) {
|
||||
if (c == delimiter) {
|
||||
return position;// Return if match
|
||||
}
|
||||
@ -320,8 +320,8 @@ public class StringTokenIterator extends AbstractTokenIterator {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
String next = mNext;
|
||||
mNext = fetchNext();
|
||||
String next = this.next;
|
||||
this.next = fetchNext();
|
||||
|
||||
return next;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ package com.twelvemonkeys.util;
|
||||
*/
|
||||
public class Time {
|
||||
|
||||
private int mTime = -1;
|
||||
private int time = -1;
|
||||
public final static int SECONDS_IN_MINUTE = 60;
|
||||
|
||||
/**
|
||||
@ -61,14 +61,14 @@ public class Time {
|
||||
if (pTime < 0) {
|
||||
throw new IllegalArgumentException("Time argument must be 0 or positive!");
|
||||
}
|
||||
mTime = pTime;
|
||||
time = pTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full time in seconds.
|
||||
*/
|
||||
public int getTime() {
|
||||
return mTime;
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +78,7 @@ public class Time {
|
||||
* @see java.util.Date#setTime(long)
|
||||
*/
|
||||
public long getTimeInMillis() {
|
||||
return (long) mTime * 1000L;
|
||||
return (long) time * 1000L;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ public class Time {
|
||||
* @param pSeconds an integer that should be between 0 and 59.
|
||||
*/
|
||||
public void setSeconds(int pSeconds) {
|
||||
mTime = getMinutes() * SECONDS_IN_MINUTE + pSeconds;
|
||||
time = getMinutes() * SECONDS_IN_MINUTE + pSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +97,7 @@ public class Time {
|
||||
* @return an integer between 0 and 59
|
||||
*/
|
||||
public int getSeconds() {
|
||||
return mTime % SECONDS_IN_MINUTE;
|
||||
return time % SECONDS_IN_MINUTE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ public class Time {
|
||||
* @param pMinutes an integer
|
||||
*/
|
||||
public void setMinutes(int pMinutes) {
|
||||
mTime = pMinutes * SECONDS_IN_MINUTE + getSeconds();
|
||||
time = pMinutes * SECONDS_IN_MINUTE + getSeconds();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ public class Time {
|
||||
* @return an integer
|
||||
*/
|
||||
public int getMinutes() {
|
||||
return mTime / SECONDS_IN_MINUTE;
|
||||
return time / SECONDS_IN_MINUTE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,10 @@
|
||||
|
||||
package com.twelvemonkeys.util;
|
||||
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
|
||||
import java.text.FieldPosition;
|
||||
import java.text.Format;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
@ -72,8 +75,7 @@ import java.util.Vector;
|
||||
*
|
||||
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
|
||||
*/
|
||||
|
||||
public class TimeFormat extends java.text.Format {
|
||||
public class TimeFormat extends Format {
|
||||
final static String MINUTE = "m";
|
||||
final static String SECOND = "s";
|
||||
final static String TIME = "S";
|
||||
@ -84,7 +86,7 @@ public class TimeFormat extends java.text.Format {
|
||||
*/
|
||||
|
||||
private final static TimeFormat DEFAULT_FORMAT = new TimeFormat("m:ss");
|
||||
protected String mFormatString = null;
|
||||
protected String formatString = null;
|
||||
|
||||
/**
|
||||
* Main method for testing ONLY
|
||||
@ -114,14 +116,14 @@ public class TimeFormat extends java.text.Format {
|
||||
|
||||
if (argv.length >= 1) {
|
||||
System.out.println("Parsing: \"" + argv[0] + "\" with format \""
|
||||
+ in.mFormatString + "\"");
|
||||
+ in.formatString + "\"");
|
||||
time = in.parse(argv[0]);
|
||||
}
|
||||
else
|
||||
time = new Time();
|
||||
|
||||
System.out.println("Time is \"" + out.format(time) +
|
||||
"\" according to format \"" + out.mFormatString + "\"");
|
||||
"\" according to format \"" + out.formatString + "\"");
|
||||
}
|
||||
|
||||
|
||||
@ -129,14 +131,14 @@ public class TimeFormat extends java.text.Format {
|
||||
* The formatter array.
|
||||
*/
|
||||
|
||||
protected TimeFormatter[] mFormatter;
|
||||
protected TimeFormatter[] formatter;
|
||||
|
||||
/**
|
||||
* Creates a new TimeFormat with the given formatString,
|
||||
*/
|
||||
|
||||
public TimeFormat(String pStr) {
|
||||
mFormatString = pStr;
|
||||
formatString = pStr;
|
||||
|
||||
Vector formatter = new Vector();
|
||||
StringTokenizer tok = new StringTokenizer(pStr, "\\msS", true);
|
||||
@ -195,10 +197,10 @@ public class TimeFormat extends java.text.Format {
|
||||
/*
|
||||
for (int i = 0; i < formatter.size(); i++) {
|
||||
System.out.println("Formatter " + formatter.get(i).getClass()
|
||||
+ ": length=" + ((TimeFormatter) formatter.get(i)).mDigits);
|
||||
+ ": length=" + ((TimeFormatter) formatter.get(i)).digits);
|
||||
}
|
||||
*/
|
||||
mFormatter = (TimeFormatter[])
|
||||
this.formatter = (TimeFormatter[])
|
||||
formatter.toArray(new TimeFormatter[formatter.size()]);
|
||||
|
||||
}
|
||||
@ -228,7 +230,7 @@ public class TimeFormat extends java.text.Format {
|
||||
|
||||
/** Gets the format string. */
|
||||
public String getFormatString() {
|
||||
return mFormatString;
|
||||
return formatString;
|
||||
}
|
||||
|
||||
/** DUMMY IMPLEMENTATION!! */
|
||||
@ -247,8 +249,8 @@ public class TimeFormat extends java.text.Format {
|
||||
|
||||
public String format(Time pTime) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < mFormatter.length; i++) {
|
||||
buf.append(mFormatter[i].format(pTime));
|
||||
for (int i = 0; i < formatter.length; i++) {
|
||||
buf.append(formatter[i].format(pTime));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
@ -279,45 +281,45 @@ public class TimeFormat extends java.text.Format {
|
||||
|
||||
boolean onlyUseSeconds = false;
|
||||
|
||||
for (int i = 0; (i < mFormatter.length)
|
||||
for (int i = 0; (i < formatter.length)
|
||||
&& (pos + skip < pStr.length()) ; i++) {
|
||||
// Go to next offset
|
||||
pos += skip;
|
||||
|
||||
if (mFormatter[i] instanceof MinutesFormatter) {
|
||||
if (formatter[i] instanceof MinutesFormatter) {
|
||||
// Parse MINUTES
|
||||
if ((i + 1) < mFormatter.length
|
||||
&& mFormatter[i + 1] instanceof TextFormatter) {
|
||||
if ((i + 1) < formatter.length
|
||||
&& formatter[i + 1] instanceof TextFormatter) {
|
||||
// Skip until next format element
|
||||
skip = pStr.indexOf(((TextFormatter) mFormatter[i + 1]).mText, pos);
|
||||
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
|
||||
// Error in format, try parsing to end
|
||||
if (skip < 0)
|
||||
skip = pStr.length();
|
||||
}
|
||||
else if ((i + 1) >= mFormatter.length) {
|
||||
else if ((i + 1) >= formatter.length) {
|
||||
// Skip until end of string
|
||||
skip = pStr.length();
|
||||
}
|
||||
else {
|
||||
// Hope this is correct...
|
||||
skip = mFormatter[i].mDigits;
|
||||
skip = formatter[i].digits;
|
||||
}
|
||||
|
||||
// May be first char
|
||||
if (skip > pos)
|
||||
min = Integer.parseInt(pStr.substring(pos, skip));
|
||||
}
|
||||
else if (mFormatter[i] instanceof SecondsFormatter) {
|
||||
else if (formatter[i] instanceof SecondsFormatter) {
|
||||
// Parse SECONDS
|
||||
if (mFormatter[i].mDigits == -1) {
|
||||
if (formatter[i].digits == -1) {
|
||||
// Only seconds (or full TIME)
|
||||
if ((i + 1) < mFormatter.length
|
||||
&& mFormatter[i + 1] instanceof TextFormatter) {
|
||||
if ((i + 1) < formatter.length
|
||||
&& formatter[i + 1] instanceof TextFormatter) {
|
||||
// Skip until next format element
|
||||
skip = pStr.indexOf(((TextFormatter) mFormatter[i + 1]).mText, pos);
|
||||
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
|
||||
|
||||
}
|
||||
else if ((i + 1) >= mFormatter.length) {
|
||||
else if ((i + 1) >= formatter.length) {
|
||||
// Skip until end of string
|
||||
skip = pStr.length();
|
||||
}
|
||||
@ -336,25 +338,25 @@ public class TimeFormat extends java.text.Format {
|
||||
}
|
||||
else {
|
||||
// Normal SECONDS
|
||||
if ((i + 1) < mFormatter.length
|
||||
&& mFormatter[i + 1] instanceof TextFormatter) {
|
||||
if ((i + 1) < formatter.length
|
||||
&& formatter[i + 1] instanceof TextFormatter) {
|
||||
// Skip until next format element
|
||||
skip = pStr.indexOf(((TextFormatter) mFormatter[i + 1]).mText, pos);
|
||||
skip = pStr.indexOf(((TextFormatter) formatter[i + 1]).text, pos);
|
||||
|
||||
}
|
||||
else if ((i + 1) >= mFormatter.length) {
|
||||
else if ((i + 1) >= formatter.length) {
|
||||
// Skip until end of string
|
||||
skip = pStr.length();
|
||||
}
|
||||
else {
|
||||
skip = mFormatter[i].mDigits;
|
||||
skip = formatter[i].digits;
|
||||
}
|
||||
// Get seconds
|
||||
sec = Integer.parseInt(pStr.substring(pos, skip));
|
||||
}
|
||||
}
|
||||
else if (mFormatter[i] instanceof TextFormatter) {
|
||||
skip = mFormatter[i].mDigits;
|
||||
else if (formatter[i] instanceof TextFormatter) {
|
||||
skip = formatter[i].digits;
|
||||
}
|
||||
|
||||
}
|
||||
@ -374,7 +376,7 @@ public class TimeFormat extends java.text.Format {
|
||||
* The base class of TimeFormatters
|
||||
*/
|
||||
abstract class TimeFormatter {
|
||||
int mDigits = 0;
|
||||
int digits = 0;
|
||||
|
||||
abstract String format(Time t);
|
||||
}
|
||||
@ -385,23 +387,23 @@ abstract class TimeFormatter {
|
||||
class SecondsFormatter extends TimeFormatter {
|
||||
|
||||
SecondsFormatter(int pDigits) {
|
||||
mDigits = pDigits;
|
||||
digits = pDigits;
|
||||
}
|
||||
|
||||
String format(Time t) {
|
||||
// Negative number of digits, means all seconds, no padding
|
||||
if (mDigits < 0) {
|
||||
if (digits < 0) {
|
||||
return Integer.toString(t.getTime());
|
||||
}
|
||||
|
||||
// If seconds is more than mDigits long, simply return it
|
||||
if (t.getSeconds() >= Math.pow(10, mDigits)) {
|
||||
// If seconds is more than digits long, simply return it
|
||||
if (t.getSeconds() >= Math.pow(10, digits)) {
|
||||
return Integer.toString(t.getSeconds());
|
||||
}
|
||||
|
||||
// Else return it with leading 0's
|
||||
//return StringUtil.formatNumber(t.getSeconds(), mDigits);
|
||||
return com.twelvemonkeys.lang.StringUtil.pad("" + t.getSeconds(), mDigits, "0", true);
|
||||
//return StringUtil.formatNumber(t.getSeconds(), digits);
|
||||
return StringUtil.pad("" + t.getSeconds(), digits, "0", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,18 +413,18 @@ class SecondsFormatter extends TimeFormatter {
|
||||
class MinutesFormatter extends TimeFormatter {
|
||||
|
||||
MinutesFormatter(int pDigits) {
|
||||
mDigits = pDigits;
|
||||
digits = pDigits;
|
||||
}
|
||||
|
||||
String format(Time t) {
|
||||
// If minutes is more than mDigits long, simply return it
|
||||
if (t.getMinutes() >= Math.pow(10, mDigits)) {
|
||||
// If minutes is more than digits long, simply return it
|
||||
if (t.getMinutes() >= Math.pow(10, digits)) {
|
||||
return Integer.toString(t.getMinutes());
|
||||
}
|
||||
|
||||
// Else return it with leading 0's
|
||||
//return StringUtil.formatNumber(t.getMinutes(), mDigits);
|
||||
return com.twelvemonkeys.lang.StringUtil.pad("" + t.getMinutes(), mDigits, "0", true);
|
||||
//return StringUtil.formatNumber(t.getMinutes(), digits);
|
||||
return StringUtil.pad("" + t.getMinutes(), digits, "0", true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,20 +432,20 @@ class MinutesFormatter extends TimeFormatter {
|
||||
* Formats text constant part of the Time
|
||||
*/
|
||||
class TextFormatter extends TimeFormatter {
|
||||
String mText = null;
|
||||
String text = null;
|
||||
|
||||
TextFormatter(String pText) {
|
||||
mText = pText;
|
||||
text = pText;
|
||||
|
||||
// Just to be able to skip over
|
||||
if (pText != null) {
|
||||
mDigits = pText.length();
|
||||
digits = pText.length();
|
||||
}
|
||||
}
|
||||
|
||||
String format(Time t) {
|
||||
// Simply return the text
|
||||
return mText;
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,10 +62,10 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
/**
|
||||
* Expiry time
|
||||
*/
|
||||
protected long mExpiryTime = 60000L; // 1 minute
|
||||
protected long expiryTime = 60000L; // 1 minute
|
||||
|
||||
//////////////////////
|
||||
private volatile long mNextExpiryTime;
|
||||
private volatile long nextExpiryTime;
|
||||
//////////////////////
|
||||
|
||||
/**
|
||||
@ -107,7 +107,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
*/
|
||||
public TimeoutMap(long pExpiryTime) {
|
||||
this();
|
||||
mExpiryTime = pExpiryTime;
|
||||
expiryTime = pExpiryTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +125,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
*/
|
||||
public TimeoutMap(Map<K, Map.Entry<K, V>> pBacking, Map<? extends K, ? extends V> pContents, long pExpiryTime) {
|
||||
super(pBacking, pContents);
|
||||
mExpiryTime = pExpiryTime;
|
||||
expiryTime = pExpiryTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +134,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* @return the expiry time
|
||||
*/
|
||||
public long getExpiryTime() {
|
||||
return mExpiryTime;
|
||||
return expiryTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,13 +144,13 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* @param pExpiryTime the expiry time (time to live) for elements in this map
|
||||
*/
|
||||
public void setExpiryTime(long pExpiryTime) {
|
||||
long oldEexpiryTime = mExpiryTime;
|
||||
long oldEexpiryTime = expiryTime;
|
||||
|
||||
mExpiryTime = pExpiryTime;
|
||||
expiryTime = pExpiryTime;
|
||||
|
||||
if (mExpiryTime < oldEexpiryTime) {
|
||||
if (expiryTime < oldEexpiryTime) {
|
||||
// Expire now
|
||||
mNextExpiryTime = 0;
|
||||
nextExpiryTime = 0;
|
||||
removeExpiredEntries();
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
*/
|
||||
public int size() {
|
||||
removeExpiredEntries();
|
||||
return mEntries.size();
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,7 +186,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
*/
|
||||
public boolean containsKey(Object pKey) {
|
||||
removeExpiredEntries();
|
||||
return mEntries.containsKey(pKey);
|
||||
return entries.containsKey(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,14 +203,14 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* @see #containsKey(java.lang.Object)
|
||||
*/
|
||||
public V get(Object pKey) {
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) mEntries.get(pKey);
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey);
|
||||
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
else if (entry.isExpired()) {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
mEntries.remove(pKey);
|
||||
entries.remove(pKey);
|
||||
processRemoved(entry);
|
||||
return null;
|
||||
}
|
||||
@ -231,7 +231,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* {@code null} values.
|
||||
*/
|
||||
public V put(K pKey, V pValue) {
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) mEntries.get(pKey);
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey);
|
||||
V oldValue;
|
||||
|
||||
if (entry == null) {
|
||||
@ -239,7 +239,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
|
||||
entry = createEntry(pKey, pValue);
|
||||
|
||||
mEntries.put(pKey, entry);
|
||||
entries.put(pKey, entry);
|
||||
}
|
||||
else {
|
||||
oldValue = entry.mValue;
|
||||
@ -250,7 +250,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
// Need to remove expired objects every now and then
|
||||
// We do it in the put method, to avoid resource leaks over time.
|
||||
removeExpiredEntries();
|
||||
mModCount++;
|
||||
modCount++;
|
||||
|
||||
return oldValue;
|
||||
}
|
||||
@ -267,7 +267,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* {@code null} values.
|
||||
*/
|
||||
public V remove(Object pKey) {
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) mEntries.remove(pKey);
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.remove(pKey);
|
||||
return (entry != null) ? entry.getValue() : null;
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* Removes all mappings from this map.
|
||||
*/
|
||||
public void clear() {
|
||||
mEntries.clear(); // Finally something straightforward.. :-)
|
||||
entries.clear(); // Finally something straightforward.. :-)
|
||||
init();
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
protected void removeExpiredEntries() {
|
||||
// Remove any expired elements
|
||||
long now = System.currentTimeMillis();
|
||||
if (now > mNextExpiryTime) {
|
||||
if (now > nextExpiryTime) {
|
||||
removeExpiredEntriesSynced(now);
|
||||
}
|
||||
}
|
||||
@ -303,10 +303,10 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* @param pTime now
|
||||
*/
|
||||
private synchronized void removeExpiredEntriesSynced(long pTime) {
|
||||
if (pTime > mNextExpiryTime) {
|
||||
if (pTime > nextExpiryTime) {
|
||||
////
|
||||
long next = Long.MAX_VALUE;
|
||||
mNextExpiryTime = next; // Avoid multiple runs...
|
||||
nextExpiryTime = next; // Avoid multiple runs...
|
||||
for (Iterator<Entry<K, V>> iterator = new EntryIterator(); iterator.hasNext();) {
|
||||
TimedEntry<K, V> entry = (TimedEntry<K, V>) iterator.next();
|
||||
////
|
||||
@ -317,7 +317,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
////
|
||||
}
|
||||
////
|
||||
mNextExpiryTime = next;
|
||||
nextExpiryTime = next;
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
* Note: Iterating through this iterator will remove any expired values.
|
||||
*/
|
||||
private abstract class TimeoutMapIterator<E> implements Iterator<E> {
|
||||
Iterator<Entry<K, Entry<K, V>>> mIterator = mEntries.entrySet().iterator();
|
||||
Iterator<Entry<K, Entry<K, V>>> mIterator = entries.entrySet().iterator();
|
||||
BasicEntry<K, V> mNext;
|
||||
long mNow = System.currentTimeMillis();
|
||||
|
||||
@ -443,7 +443,7 @@ public class TimeoutMap<K, V> extends AbstractDecoratedMap<K, V> implements Expi
|
||||
}
|
||||
|
||||
final long expires() {
|
||||
return mTimestamp + mExpiryTime;
|
||||
return mTimestamp + expiryTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,14 +49,14 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
/**
|
||||
* The wrapped map
|
||||
*/
|
||||
protected Map<K, V> mEntries;
|
||||
protected Map<K, V> entries;
|
||||
|
||||
/**
|
||||
* Creates a {@code TypedMap}.
|
||||
* This {@code TypedMap} will be backed by a new {@code HashMap} instance.
|
||||
*/
|
||||
public TypedMap() {
|
||||
mEntries = new HashMap<K, V>();
|
||||
entries = new HashMap<K, V>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,14 +104,14 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
|
||||
// This is safe, as we re-insert all values later
|
||||
//noinspection unchecked
|
||||
mEntries = (Map<K, V>) pBacking;
|
||||
entries = (Map<K, V>) pBacking;
|
||||
|
||||
// Re-insert all elements to avoid undeterministic ClassCastExceptions
|
||||
if (pUseElements) {
|
||||
putAll(pBacking);
|
||||
}
|
||||
else if (mEntries.size() > 0) {
|
||||
mEntries.clear();
|
||||
else if (entries.size() > 0) {
|
||||
entries.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* @return the number of key-value mappings in this map.
|
||||
*/
|
||||
public int size() {
|
||||
return mEntries.size();
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +132,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* @return {@code true} if this map contains no key-value mappings.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return mEntries.isEmpty();
|
||||
return entries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,7 +144,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* key.
|
||||
*/
|
||||
public boolean containsKey(Object pKey) {
|
||||
return mEntries.containsKey(pKey);
|
||||
return entries.containsKey(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,7 +160,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* specified value.
|
||||
*/
|
||||
public boolean containsValue(Object pValue) {
|
||||
return mEntries.containsValue(pValue);
|
||||
return entries.containsValue(pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,7 +177,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* @see #containsKey(java.lang.Object)
|
||||
*/
|
||||
public V get(Object pKey) {
|
||||
return mEntries.get(pKey);
|
||||
return entries.get(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -203,7 +203,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
if (!pKey.isCompatibleValue(pValue)) {
|
||||
throw new IllegalArgumentException("incompatible value for key");
|
||||
}
|
||||
return mEntries.put(pKey, pValue);
|
||||
return entries.put(pKey, pValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,7 +218,7 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* {@code null} values.
|
||||
*/
|
||||
public V remove(Object pKey) {
|
||||
return mEntries.remove(pKey);
|
||||
return entries.remove(pKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,19 +241,19 @@ public class TypedMap<K extends TypedMap.Key, V> implements Map<K, V>, Serializa
|
||||
* Removes all mappings from this map (optional operation).
|
||||
*/
|
||||
public void clear() {
|
||||
mEntries.clear();
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
public Collection<V> values() {
|
||||
return mEntries.values();
|
||||
return entries.values();
|
||||
}
|
||||
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return mEntries.entrySet();
|
||||
return entries.entrySet();
|
||||
}
|
||||
|
||||
public Set<K> keySet() {
|
||||
return mEntries.keySet();
|
||||
return entries.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@ final class URLResource extends AbstractResource {
|
||||
// NOTE: For the time being, we rely on the URL class (and helpers) to do
|
||||
// some smart caching and reuse of connections...
|
||||
// TODO: Change the implementation if this is a problem
|
||||
private long mLastModified = -1;
|
||||
private long lastModified = -1;
|
||||
|
||||
/**
|
||||
* Creates a {@code URLResource}.
|
||||
@ -58,7 +58,7 @@ final class URLResource extends AbstractResource {
|
||||
}
|
||||
|
||||
private URL getURL() {
|
||||
return (URL) mWrappedResource;
|
||||
return (URL) wrappedResource;
|
||||
}
|
||||
|
||||
public URL asURL() {
|
||||
@ -77,13 +77,13 @@ final class URLResource extends AbstractResource {
|
||||
URLConnection connection = getURL().openConnection();
|
||||
connection.setAllowUserInteraction(false);
|
||||
connection.setUseCaches(true);
|
||||
connection.setIfModifiedSince(mLastModified);
|
||||
connection.setIfModifiedSince(lastModified);
|
||||
|
||||
mLastModified = connection.getLastModified();
|
||||
lastModified = connection.getLastModified();
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
|
||||
return mLastModified;
|
||||
return lastModified;
|
||||
}
|
||||
}
|
||||
|
@ -135,46 +135,46 @@ public class WeakWeakMap<K, V> extends WeakHashMap<K, V> {
|
||||
public Iterator<Map.Entry<K, V>> iterator() {
|
||||
return new Iterator<Map.Entry<K, V>>() {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
final Iterator<Map.Entry<K, WeakReference<V>>> mIterator = (Iterator) WeakWeakMap.super.entrySet().iterator();
|
||||
final Iterator<Map.Entry<K, WeakReference<V>>> iterator = (Iterator) WeakWeakMap.super.entrySet().iterator();
|
||||
|
||||
public boolean hasNext() {
|
||||
return mIterator.hasNext();
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
public Map.Entry<K, V> next() {
|
||||
return new Map.Entry<K, V>() {
|
||||
final Map.Entry<K, WeakReference<V>> mEntry = mIterator.next();
|
||||
final Map.Entry<K, WeakReference<V>> entry = iterator.next();
|
||||
|
||||
public K getKey() {
|
||||
return mEntry.getKey();
|
||||
return entry.getKey();
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
WeakReference<V> ref = mEntry.getValue();
|
||||
WeakReference<V> ref = entry.getValue();
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
public V setValue(V pValue) {
|
||||
WeakReference<V> ref = mEntry.setValue(new WeakReference<V>(pValue));
|
||||
WeakReference<V> ref = entry.setValue(new WeakReference<V>(pValue));
|
||||
return ref != null ? ref.get() : null;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return mEntry.equals(obj);
|
||||
return entry.equals(obj);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return mEntry.hashCode();
|
||||
return entry.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return mEntry.toString();
|
||||
return entry.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
mIterator.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -191,19 +191,19 @@ public class WeakWeakMap<K, V> extends WeakHashMap<K, V> {
|
||||
public Iterator<V> iterator() {
|
||||
return new Iterator<V>() {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
Iterator<WeakReference<V>> mIterator = (Iterator<WeakReference<V>>) WeakWeakMap.super.values().iterator();
|
||||
Iterator<WeakReference<V>> iterator = (Iterator<WeakReference<V>>) WeakWeakMap.super.values().iterator();
|
||||
|
||||
public boolean hasNext() {
|
||||
return mIterator.hasNext();
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
public V next() {
|
||||
WeakReference<V> ref = mIterator.next();
|
||||
WeakReference<V> ref = iterator.next();
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
mIterator.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -183,12 +183,12 @@ public class WildcardStringParser {
|
||||
|
||||
WildcardStringParserState runnerState = pState;
|
||||
|
||||
while (runnerState.mPreviousState != null) {
|
||||
runnerState = runnerState.mPreviousState;
|
||||
if (isFreeRangeCharacter(runnerState.mChar)) {
|
||||
while (runnerState.previousState != null) {
|
||||
runnerState = runnerState.previousState;
|
||||
if (isFreeRangeCharacter(runnerState.character)) {
|
||||
return true;
|
||||
}
|
||||
if (!isFreePassCharacter(runnerState.mChar)) {
|
||||
if (!isFreePassCharacter(runnerState.character)) {
|
||||
return false;
|
||||
} // If free-pass char '?' - move on
|
||||
}
|
||||
@ -197,10 +197,10 @@ public class WildcardStringParser {
|
||||
|
||||
private boolean checkIfLastFreeRangeState(WildcardStringParserState pState) {
|
||||
|
||||
if (isFreeRangeCharacter(pState.mChar)) {
|
||||
if (isFreeRangeCharacter(pState.character)) {
|
||||
return true;
|
||||
}
|
||||
if (isFreePassCharacter(pState.mChar)) {
|
||||
if (isFreePassCharacter(pState.character)) {
|
||||
if (checkIfStateInWildcardRange(pState)) {
|
||||
return true;
|
||||
}
|
||||
@ -229,14 +229,14 @@ public class WildcardStringParser {
|
||||
// Create the initial state of the automaton
|
||||
if ((stringMask != null) && (stringMask.length() > 0)) {
|
||||
newState = new WildcardStringParserState(stringMask.charAt(0));
|
||||
newState.mAutomatonStateNumber = 0;
|
||||
newState.mPreviousState = null;
|
||||
newState.automatonStateNumber = 0;
|
||||
newState.previousState = null;
|
||||
if (checkIfLastFreeRangeState(newState)) {
|
||||
lastFreeRangeState = newState;
|
||||
}
|
||||
runnerState = newState;
|
||||
initialState = runnerState;
|
||||
initialState.mAutomatonStateNumber = 0;
|
||||
initialState.automatonStateNumber = 0;
|
||||
}
|
||||
else {
|
||||
System.err.println("string mask provided are null or empty - aborting!");
|
||||
@ -254,12 +254,12 @@ public class WildcardStringParser {
|
||||
}
|
||||
|
||||
// Set last free-range state before creating/checking the next state
|
||||
runnerState.mLastFreeRangeState = lastFreeRangeState;
|
||||
runnerState.lastFreeRangeState = lastFreeRangeState;
|
||||
|
||||
// Create next state, check if free-range state, set the state number and preceeding state
|
||||
newState = new WildcardStringParserState(activeChar);
|
||||
newState.mAutomatonStateNumber = i;
|
||||
newState.mPreviousState = runnerState;
|
||||
newState.automatonStateNumber = i;
|
||||
newState.previousState = runnerState;
|
||||
|
||||
// Special check if the state represents an '*' or '?' with only preceeding states representing '?' and '*'
|
||||
if (checkIfLastFreeRangeState(newState)) {
|
||||
@ -267,14 +267,14 @@ public class WildcardStringParser {
|
||||
}
|
||||
|
||||
// Set the succeding state before moving to the next state
|
||||
runnerState.mNextState = newState;
|
||||
runnerState.nextState = newState;
|
||||
|
||||
// Move to the next state
|
||||
runnerState = newState;
|
||||
|
||||
// Special setting of the last free-range state for the last element
|
||||
if (runnerState.mAutomatonStateNumber == stringMask.length() - 1) {
|
||||
runnerState.mLastFreeRangeState = lastFreeRangeState;
|
||||
if (runnerState.automatonStateNumber == stringMask.length() - 1) {
|
||||
runnerState.lastFreeRangeState = lastFreeRangeState;
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,9 +383,9 @@ public class WildcardStringParser {
|
||||
WildcardStringParserState runnerState = null;
|
||||
|
||||
// Accepted by the first state?
|
||||
if ((parsableString.mCharArray[0] == initialState.mChar) || isWildcardCharacter(initialState.mChar)) {
|
||||
if ((parsableString.charArray[0] == initialState.character) || isWildcardCharacter(initialState.character)) {
|
||||
runnerState = initialState;
|
||||
parsableString.mIndex = 0;
|
||||
parsableString.index = 0;
|
||||
}
|
||||
else {
|
||||
if (debugging) {
|
||||
@ -395,7 +395,7 @@ public class WildcardStringParser {
|
||||
}
|
||||
|
||||
// Initialize the free-pass character state visited count
|
||||
if (isFreePassCharacter(runnerState.mChar)) {
|
||||
if (isFreePassCharacter(runnerState.character)) {
|
||||
numberOfFreePassCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
|
||||
@ -406,23 +406,23 @@ public class WildcardStringParser {
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - index number " + i + ", active char: '"
|
||||
+ parsableString.getActiveChar() + "' char string index: " + parsableString.mIndex
|
||||
+ parsableString.getActiveChar() + "' char string index: " + parsableString.index
|
||||
+ " number of chars since last free-range state: " + numberOfParsedCharactersRead_SinceLastFreePassState);
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - state: " + runnerState.mAutomatonStateNumber + " '"
|
||||
+ runnerState.mChar + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
|
||||
out.println("parsing - state: " + runnerState.automatonStateNumber + " '"
|
||||
+ runnerState.character + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - hasPerformedFreeRangeMovement: " + hasPerformedFreeRangeMovement);
|
||||
}
|
||||
if (runnerState.mNextState == null) {
|
||||
if (runnerState.nextState == null) {
|
||||
if (debugging) {
|
||||
out.println("parsing - runnerState.mNextState == null");
|
||||
out.println("parsing - runnerState.nextState == null");
|
||||
}
|
||||
|
||||
// If there are no subsequent state (final state) and the state represents '*' - acceptance!
|
||||
if (isFreeRangeCharacter(runnerState.mChar)) {
|
||||
if (isFreeRangeCharacter(runnerState.character)) {
|
||||
|
||||
// Special free-range skipping check
|
||||
if (hasPerformedFreeRangeMovement) {
|
||||
@ -448,7 +448,7 @@ public class WildcardStringParser {
|
||||
out.println(
|
||||
"no subsequent state (final state) and the state represents '*' - not the end of parsing string and not enough characters read - read next character");
|
||||
}
|
||||
parsableString.mIndex++;
|
||||
parsableString.index++;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
else {
|
||||
@ -493,37 +493,37 @@ public class WildcardStringParser {
|
||||
}
|
||||
else {
|
||||
if (debugging) {
|
||||
out.println("parsing - runnerState.mNextState != null");
|
||||
out.println("parsing - runnerState.nextState != null");
|
||||
}
|
||||
|
||||
// Special Case:
|
||||
// If this state represents '*' - go to the rightmost state representing '?'.
|
||||
// This state will act as an '*' - except that you only can go to the next state or accept the string, if and only if the number of '?' read are equal or less than the number of character read from the parsing string.
|
||||
if (isFreeRangeCharacter(runnerState.mChar)) {
|
||||
if (isFreeRangeCharacter(runnerState.character)) {
|
||||
numberOfFreePassCharactersRead_SinceLastFreePassState = 0;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState = 0;
|
||||
WildcardStringParserState freeRangeRunnerState = runnerState.mNextState;
|
||||
WildcardStringParserState freeRangeRunnerState = runnerState.nextState;
|
||||
|
||||
while ((freeRangeRunnerState != null) && (isFreePassCharacter(freeRangeRunnerState.mChar))) {
|
||||
while ((freeRangeRunnerState != null) && (isFreePassCharacter(freeRangeRunnerState.character))) {
|
||||
runnerState = freeRangeRunnerState;
|
||||
hasPerformedFreeRangeMovement = true;
|
||||
numberOfFreePassCharactersRead_SinceLastFreePassState++;
|
||||
freeRangeRunnerState = freeRangeRunnerState.mNextState;
|
||||
freeRangeRunnerState = freeRangeRunnerState.nextState;
|
||||
}
|
||||
|
||||
// Special Case: if the mask is at the end
|
||||
if (runnerState.mNextState == null) {
|
||||
if (runnerState.nextState == null) {
|
||||
if (debugging) {
|
||||
out.println();
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - index number " + i + ", active char: '"
|
||||
+ parsableString.getActiveChar() + "' char string index: " + parsableString.mIndex
|
||||
+ parsableString.getActiveChar() + "' char string index: " + parsableString.index
|
||||
+ " number of chars since last free-range state: " + numberOfParsedCharactersRead_SinceLastFreePassState);
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - state: " + runnerState.mAutomatonStateNumber + " '"
|
||||
+ runnerState.mChar + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
|
||||
out.println("parsing - state: " + runnerState.automatonStateNumber + " '"
|
||||
+ runnerState.character + "' - no of free-pass chars read: " + numberOfFreePassCharactersRead_SinceLastFreePassState);
|
||||
}
|
||||
if (debugging) {
|
||||
out.println("parsing - hasPerformedFreeRangeMovement: "
|
||||
@ -540,31 +540,31 @@ public class WildcardStringParser {
|
||||
}
|
||||
|
||||
// If the next state represents '*' - go to this next state
|
||||
if (isFreeRangeCharacter(runnerState.mNextState.mChar)) {
|
||||
runnerState = runnerState.mNextState;
|
||||
parsableString.mIndex++;
|
||||
if (isFreeRangeCharacter(runnerState.nextState.character)) {
|
||||
runnerState = runnerState.nextState;
|
||||
parsableString.index++;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
|
||||
// If the next state represents '?' - go to this next state
|
||||
else if (isFreePassCharacter(runnerState.mNextState.mChar)) {
|
||||
runnerState = runnerState.mNextState;
|
||||
parsableString.mIndex++;
|
||||
else if (isFreePassCharacter(runnerState.nextState.character)) {
|
||||
runnerState = runnerState.nextState;
|
||||
parsableString.index++;
|
||||
numberOfFreePassCharactersRead_SinceLastFreePassState++;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
|
||||
// If the next state represents the same character as the next character in the string to test - go to this next state
|
||||
else if ((!parsableString.reachedEndOfString()) && (runnerState.mNextState.mChar == parsableString.getSubsequentChar())) {
|
||||
runnerState = runnerState.mNextState;
|
||||
parsableString.mIndex++;
|
||||
else if ((!parsableString.reachedEndOfString()) && (runnerState.nextState.character == parsableString.getSubsequentChar())) {
|
||||
runnerState = runnerState.nextState;
|
||||
parsableString.index++;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
|
||||
// If the next character in the string to test does not coincide with the next state - go to the last state representing '*'. If there are none - rejection!
|
||||
else if (runnerState.mLastFreeRangeState != null) {
|
||||
runnerState = runnerState.mLastFreeRangeState;
|
||||
parsableString.mIndex++;
|
||||
else if (runnerState.lastFreeRangeState != null) {
|
||||
runnerState = runnerState.lastFreeRangeState;
|
||||
parsableString.index++;
|
||||
numberOfParsedCharactersRead_SinceLastFreePassState++;
|
||||
}
|
||||
else {
|
||||
@ -610,21 +610,21 @@ public class WildcardStringParser {
|
||||
buffer.append("\n");
|
||||
buffer.append(" Automaton: ");
|
||||
while (runnerState != null) {
|
||||
buffer.append(runnerState.mAutomatonStateNumber);
|
||||
buffer.append(runnerState.automatonStateNumber);
|
||||
buffer.append(": ");
|
||||
buffer.append(runnerState.mChar);
|
||||
buffer.append(runnerState.character);
|
||||
buffer.append(" (");
|
||||
if (runnerState.mLastFreeRangeState != null) {
|
||||
buffer.append(runnerState.mLastFreeRangeState.mAutomatonStateNumber);
|
||||
if (runnerState.lastFreeRangeState != null) {
|
||||
buffer.append(runnerState.lastFreeRangeState.automatonStateNumber);
|
||||
}
|
||||
else {
|
||||
buffer.append("-");
|
||||
}
|
||||
buffer.append(")");
|
||||
if (runnerState.mNextState != null) {
|
||||
if (runnerState.nextState != null) {
|
||||
buffer.append(" --> ");
|
||||
}
|
||||
runnerState = runnerState.mNextState;
|
||||
runnerState = runnerState.nextState;
|
||||
}
|
||||
buffer.append("\n");
|
||||
buffer.append(" Format: <state index>: <character> (<last free state>)");
|
||||
@ -679,11 +679,11 @@ public class WildcardStringParser {
|
||||
|
||||
// Constants
|
||||
// Members
|
||||
int mAutomatonStateNumber;
|
||||
char mChar;
|
||||
WildcardStringParserState mPreviousState;
|
||||
WildcardStringParserState mNextState;
|
||||
WildcardStringParserState mLastFreeRangeState;
|
||||
int automatonStateNumber;
|
||||
char character;
|
||||
WildcardStringParserState previousState;
|
||||
WildcardStringParserState nextState;
|
||||
WildcardStringParserState lastFreeRangeState;
|
||||
|
||||
// Constructors
|
||||
|
||||
@ -693,7 +693,7 @@ public class WildcardStringParser {
|
||||
* @param pChar
|
||||
*/
|
||||
public WildcardStringParserState(final char pChar) {
|
||||
this.mChar = pChar;
|
||||
this.character = pChar;
|
||||
}
|
||||
|
||||
// Methods
|
||||
@ -705,34 +705,34 @@ public class WildcardStringParser {
|
||||
|
||||
// Constants
|
||||
// Members
|
||||
char[] mCharArray;
|
||||
int mIndex;
|
||||
char[] charArray;
|
||||
int index;
|
||||
|
||||
// Constructors
|
||||
ParsableString(final String pStringToParse) {
|
||||
|
||||
if (pStringToParse != null) {
|
||||
mCharArray = pStringToParse.toCharArray();
|
||||
charArray = pStringToParse.toCharArray();
|
||||
}
|
||||
mIndex = -1;
|
||||
index = -1;
|
||||
}
|
||||
|
||||
// Methods
|
||||
boolean reachedEndOfString() {
|
||||
|
||||
//System.out.println(DebugUtil.DEBUG + DebugUtil.getClassName(this) + ": mIndex :" + mIndex);
|
||||
//System.out.println(DebugUtil.DEBUG + DebugUtil.getClassName(this) + ": mCharArray.length :" + mCharArray.length);
|
||||
return mIndex == mCharArray.length - 1;
|
||||
//System.out.println(DebugUtil.DEBUG + DebugUtil.getClassName(this) + ": index :" + index);
|
||||
//System.out.println(DebugUtil.DEBUG + DebugUtil.getClassName(this) + ": charArray.length :" + charArray.length);
|
||||
return index == charArray.length - 1;
|
||||
}
|
||||
|
||||
int length() {
|
||||
return mCharArray.length;
|
||||
return charArray.length;
|
||||
}
|
||||
|
||||
char getActiveChar() {
|
||||
|
||||
if ((mIndex > -1) && (mIndex < mCharArray.length)) {
|
||||
return mCharArray[mIndex];
|
||||
if ((index > -1) && (index < charArray.length)) {
|
||||
return charArray[index];
|
||||
}
|
||||
System.err.println(getClass().getName() + ": trying to access character outside character array!");
|
||||
return ' ';
|
||||
@ -740,8 +740,8 @@ public class WildcardStringParser {
|
||||
|
||||
char getSubsequentChar() {
|
||||
|
||||
if ((mIndex > -1) && (mIndex + 1 < mCharArray.length)) {
|
||||
return mCharArray[mIndex + 1];
|
||||
if ((index > -1) && (index + 1 < charArray.length)) {
|
||||
return charArray[index + 1];
|
||||
}
|
||||
System.err.println(getClass().getName() + ": trying to access character outside character array!");
|
||||
return ' ';
|
||||
@ -752,8 +752,8 @@ public class WildcardStringParser {
|
||||
if (!isEmpty()) {
|
||||
|
||||
// Check if the string only contains chars that are elements in the alphabet
|
||||
for (int i = 0; i < mCharArray.length; i++) {
|
||||
if (!WildcardStringParser.isInAlphabet(mCharArray[i])) {
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
if (!WildcardStringParser.isInAlphabet(charArray[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -762,7 +762,7 @@ public class WildcardStringParser {
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return ((mCharArray == null) || (mCharArray.length == 0));
|
||||
return ((charArray == null) || (charArray.length == 0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -771,7 +771,7 @@ public class WildcardStringParser {
|
||||
* @return
|
||||
*/
|
||||
public String toString() {
|
||||
return new String(mCharArray);
|
||||
return new String(charArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.twelvemonkeys.lang;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -19,7 +20,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNoMehtod() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("noSuchMethod", "jaffa");
|
||||
|
||||
@ -34,7 +35,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNoMethodArgs() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("doubleValue", new Object()); // Should not be able to convert this
|
||||
|
||||
@ -52,7 +53,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureNullValue() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
map.put("stringValue", null);
|
||||
|
||||
@ -69,11 +70,11 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureSimple() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", "one");
|
||||
map.put("intValue", new Integer(2));
|
||||
map.put("doubleValue", new Double(.3));
|
||||
map.put("intValue", 2);
|
||||
map.put("doubleValue", .3);
|
||||
|
||||
try {
|
||||
BeanUtil.configure(bean, map);
|
||||
@ -84,15 +85,15 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertEquals("one", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(new Double(.3), bean.getDoubleValue());
|
||||
assertEquals(.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureConvert() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String,Serializable> map = new HashMap<String, Serializable>();
|
||||
|
||||
map.put("stringValue", new Integer(1));
|
||||
map.put("stringValue", 1);
|
||||
map.put("intValue", "2");
|
||||
map.put("doubleValue", NumberFormat.getNumberInstance().format(0.3)); // Note, format is locale specific...
|
||||
|
||||
@ -105,13 +106,13 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertEquals("1", bean.getStringValue());
|
||||
assertEquals(2, bean.getIntValue());
|
||||
assertEquals(new Double(.3), bean.getDoubleValue());
|
||||
assertEquals(.3, bean.getDoubleValue());
|
||||
}
|
||||
|
||||
public void testConfigureAmbigious1() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
String value = "one";
|
||||
map.put("ambigious", value);
|
||||
@ -133,9 +134,9 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureAmbigious2() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
Integer value = new Integer(2);
|
||||
Integer value = 2;
|
||||
map.put("ambigious", value);
|
||||
|
||||
try {
|
||||
@ -147,7 +148,7 @@ public class BeanUtilTestCase extends TestCase {
|
||||
|
||||
assertNotNull(bean.getAmbigious());
|
||||
assertEquals("Integer converted rather than invoking setAmbigiouos(Integer), ordering not predictable",
|
||||
new Integer(2), bean.getAmbigious());
|
||||
2, bean.getAmbigious());
|
||||
assertSame("Integer converted rather than invoking setAmbigiouos(Integer), ordering not predictable",
|
||||
value, bean.getAmbigious());
|
||||
}
|
||||
@ -155,9 +156,9 @@ public class BeanUtilTestCase extends TestCase {
|
||||
public void testConfigureAmbigious3() {
|
||||
TestBean bean = new TestBean();
|
||||
|
||||
Map map = new HashMap();
|
||||
Map<String, Double> map = new HashMap<String, Double>();
|
||||
|
||||
Double value = new Double(.3);
|
||||
Double value = .3;
|
||||
map.put("ambigious", value);
|
||||
|
||||
try {
|
||||
@ -175,54 +176,54 @@ public class BeanUtilTestCase extends TestCase {
|
||||
}
|
||||
|
||||
static class TestBean {
|
||||
private String mString;
|
||||
private int mInt;
|
||||
private Double mDouble;
|
||||
private String stringVal;
|
||||
private int intVal;
|
||||
private Double doubleVal;
|
||||
|
||||
private Object mAmbigious;
|
||||
private Object ambigious;
|
||||
|
||||
public Double getDoubleValue() {
|
||||
return mDouble;
|
||||
return doubleVal;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return mInt;
|
||||
return intVal;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return mString;
|
||||
return stringVal;
|
||||
}
|
||||
|
||||
public void setStringValue(String pString) {
|
||||
mString = pString;
|
||||
stringVal = pString;
|
||||
}
|
||||
|
||||
public void setIntValue(int pInt) {
|
||||
mInt = pInt;
|
||||
intVal = pInt;
|
||||
}
|
||||
|
||||
public void setDoubleValue(Double pDouble) {
|
||||
mDouble = pDouble;
|
||||
doubleVal = pDouble;
|
||||
}
|
||||
|
||||
public void setAmbigious(String pString) {
|
||||
mAmbigious = pString;
|
||||
ambigious = pString;
|
||||
}
|
||||
|
||||
public void setAmbigious(Object pObject) {
|
||||
mAmbigious = pObject;
|
||||
ambigious = pObject;
|
||||
}
|
||||
|
||||
public void setAmbigious(Integer pInteger) {
|
||||
mAmbigious = pInteger;
|
||||
ambigious = pInteger;
|
||||
}
|
||||
|
||||
public void setAmbigious(int pInt) {
|
||||
mAmbigious = new Long(pInt); // Just to differentiate...
|
||||
ambigious = (long) pInt; // Just to differentiate...
|
||||
}
|
||||
|
||||
public Object getAmbigious() {
|
||||
return mAmbigious;
|
||||
return ambigious;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public abstract class ObjectAbstractTestCase extends TestCase {
|
||||
clone.setAccessible(true);
|
||||
}
|
||||
|
||||
Object cloned = clone.invoke(obj, null);
|
||||
Object cloned = clone.invoke(obj);
|
||||
|
||||
assertNotNull("Cloned object should never be null", cloned);
|
||||
|
||||
|
@ -34,17 +34,16 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Map makeEmptyMap() {
|
||||
LRUMap map = new LRUMap();
|
||||
return map;
|
||||
return new LRUMap();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testRemoveLRU() {
|
||||
LRUMap map2 = new LRUMap(3);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"foo");
|
||||
map2.put(new Integer(3),"foo");
|
||||
map2.put(new Integer(4),"foo"); // removes 1 since max size exceeded
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"foo"); // removes 1 since max size exceeded
|
||||
map2.removeLRU(); // should be Integer(2)
|
||||
|
||||
assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo"));
|
||||
@ -52,11 +51,11 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
}
|
||||
|
||||
public void testMultiplePuts() {
|
||||
LRUMap map2 = new LRUMap(2);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"bar");
|
||||
map2.put(new Integer(3),"foo");
|
||||
map2.put(new Integer(4),"bar");
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(2);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"bar");
|
||||
map2.put(3,"foo");
|
||||
map2.put(4,"bar");
|
||||
|
||||
assertTrue("last value should exist",map2.get(new Integer(4)).equals("bar"));
|
||||
assertTrue("LRU should not exist", map2.get(new Integer(1)) == null);
|
||||
@ -67,13 +66,13 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* to exceed its maxiumum size.
|
||||
*/
|
||||
public void testPutAll() {
|
||||
LRUMap map2 = new LRUMap(3);
|
||||
map2.put(new Integer(1),"foo");
|
||||
map2.put(new Integer(2),"foo");
|
||||
map2.put(new Integer(3),"foo");
|
||||
LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3);
|
||||
map2.put(1,"foo");
|
||||
map2.put(2,"foo");
|
||||
map2.put(3,"foo");
|
||||
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(new Integer(4),"foo");
|
||||
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
|
||||
hashMap.put(4,"foo");
|
||||
|
||||
map2.putAll(hashMap);
|
||||
|
||||
@ -88,7 +87,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* when setMaximumSize(int) is called
|
||||
*/
|
||||
public void testSetMaximumSize() {
|
||||
LRUMap map = new LRUMap(6);
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(6);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
@ -102,7 +101,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
}
|
||||
|
||||
public void testGetPromotion() {
|
||||
LRUMap map = new LRUMap(3);
|
||||
LRUMap<String, String> map = new LRUMap<String, String>(3);
|
||||
map.put("1","1");
|
||||
map.put("2","2");
|
||||
map.put("3","3");
|
||||
@ -116,7 +115,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
// 2 should be evicted (then 3,1,4)
|
||||
map.put("4","4");
|
||||
|
||||
Iterator keyIterator = map.keySet().iterator();
|
||||
Iterator<String> keyIterator = map.keySet().iterator();
|
||||
Object[] keys = new Object[3];
|
||||
for (int i = 0; keyIterator.hasNext() ; ++i) {
|
||||
keys[i] = keyIterator.next();
|
||||
@ -134,7 +133,7 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
* by the LRU algorithm (the removeLRU() method).
|
||||
*/
|
||||
public void testLRUSubclass() {
|
||||
LRUCounter counter = new LRUCounter(3);
|
||||
LRUCounter<String, String> counter = new LRUCounter<String, String>(3);
|
||||
// oldest <--> newest
|
||||
// 1
|
||||
counter.put("1","foo");
|
||||
@ -165,9 +164,9 @@ public class LRUMapTestCase extends LinkedMapTestCase {
|
||||
//assertTrue("newest key is '2'",counter.get(1).equals("2"));
|
||||
}
|
||||
|
||||
private class LRUCounter extends LRUMap {
|
||||
private class LRUCounter<K, V> extends LRUMap<K, V> {
|
||||
int removedCount = 0;
|
||||
List list = new ArrayList(3);
|
||||
List<Object> list = new ArrayList<Object>(3);
|
||||
|
||||
LRUCounter(int i) {
|
||||
super(i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user