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