fix indentation

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1377492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brent Worden 2012-08-26 19:35:45 +00:00
parent b10fa43d3e
commit 66261f908f
2 changed files with 604 additions and 641 deletions

View File

@ -55,32 +55,26 @@ import java.util.concurrent.TimeUnit;
* synchronization.
* </p>
*
* @param <K>
* the type of the keys in the map
*
* @param <V>
* the type of the values in the map
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since 4.0
* @version $Id: $
*/
public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
public class PassiveExpiringMap<K, V>
extends AbstractMapDecorator<K, V>
implements Serializable {
/**
* A {@link ExpirationPolicy} that returns a expiration time that is a
* constant about of time in the future from the current time.
*
* @param <K>
* the type of the keys in the map
* @param <V>
* the type of the values in the map
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since 4.0
* @version $Id: $
*/
public static class ConstantTimeToLiveExpirationPolicy<K, V> implements
ExpirationPolicy<K, V> {
public static class ConstantTimeToLiveExpirationPolicy<K, V>
implements ExpirationPolicy<K, V> {
/** Serialization version */
private static final long serialVersionUID = 1L;
@ -102,11 +96,10 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* expire. A zero time-to-live value indicates entries expire (nearly)
* immediately.
*
* @param timeToLiveMillis
* the constant amount of time (in milliseconds) an entry is
* available before it expires. A negative value results in
* entries that NEVER expire. A zero value results in entries
* that ALWAYS expire.
* @param timeToLiveMillis the constant amount of time (in milliseconds)
* an entry is available before it expires. A negative value
* results in entries that NEVER expire. A zero value results in
* entries that ALWAYS expire.
*/
public ConstantTimeToLiveExpirationPolicy(long timeToLiveMillis) {
super();
@ -117,16 +110,13 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* Construct a policy with the given time-to-live constant measured in
* the given time unit of measure.
*
* @param timeToLive
* the constant amount of time an entry is available before
* it expires. A negative value results in entries that NEVER
* expire. A zero value results in entries that ALWAYS
* @param timeToLive the constant amount of time an entry is available
* before it expires. A negative value results in entries that
* NEVER expire. A zero value results in entries that ALWAYS
* expire.
* @param timeUnit
* the unit of time for the <code>timeToLive</code>
* @param timeUnit the unit of time for the <code>timeToLive</code>
* parameter, must not be null.
* @throws IllegalArgumentException
* if the time unit is null.
* @throws IllegalArgumentException if the time unit is null.
*/
public ConstantTimeToLiveExpirationPolicy(long timeToLive,
TimeUnit timeUnit) {
@ -136,10 +126,8 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
/**
* Determine the expiration time for the given key-value entry.
*
* @param key
* the key for the entry (ignored).
* @param value
* the value for the entry (ignored).
* @param key the key for the entry (ignored).
* @param value the value for the entry (ignored).
* @return if {@link #timeToLiveMillis} &ge; 0, an expiration time of
* {@link #timeToLiveMillis} +
* {@link System#currentTimeMillis()} is returned. Otherwise, -1
@ -167,22 +155,19 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
/**
* A policy to determine the expiration time for key-value entries.
*
* @param <K>
* the key object type.
* @param <V>
* the value object type
*
* @param <K> the key object type.
* @param <V> the value object type
* @since 4.0
* @version $Id: $
*/
public static interface ExpirationPolicy<K, V> extends Serializable {
public static interface ExpirationPolicy<K, V>
extends Serializable {
/**
* Determine the expiration time for the given key-value entry.
*
* @param key
* the key for the entry.
* @param value
* the value for the entry.
* @param key the key for the entry.
* @param value the value for the entry.
* @return the expiration time value measured in milliseconds. A
* negative return value indicates the entry never expires.
*/
@ -198,15 +183,12 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* milliseconds. If the parameters are invalid, an
* {@link IllegalArgumentException} is thrown.
*
* @param timeToLive
* the constant amount of time an entry is available before it
* expires. A negative value results in entries that NEVER
* @param timeToLive the constant amount of time an entry is available
* before it expires. A negative value results in entries that NEVER
* expire. A zero value results in entries that ALWAYS expire.
* @param timeUnit
* the unit of time for the <code>timeToLive</code> parameter,
* must not be null.
* @throws IllegalArgumentException
* if the time unit is null.
* @param timeUnit the unit of time for the <code>timeToLive</code>
* parameter, must not be null.
* @throws IllegalArgumentException if the time unit is null.
*/
private static long validateAndConvertToMillis(long timeToLive,
TimeUnit timeUnit) {
@ -234,9 +216,8 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* Construct a map decorator using the given expiration policy to determine
* expiration times.
*
* @param expiringPolicy
* the policy used to determine expiration times of entries as
* they are added.
* @param expiringPolicy the policy used to determine expiration times of
* entries as they are added.
*/
public PassiveExpiringMap(ExpirationPolicy<K, V> expiringPolicy) {
this(expiringPolicy, new HashMap<K, V>());
@ -248,13 +229,10 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* elements already in the map being decorated, they will NEVER expire
* unless they are replaced.
*
* @param expiringPolicy
* the policy used to determine expiration times of entries as
* they are added.
* @param map
* the map to decorate, must not be null.
* @throws IllegalArgumentException
* if the map is null.
* @param expiringPolicy the policy used to determine expiration times of
* entries as they are added.
* @param map the map to decorate, must not be null.
* @throws IllegalArgumentException if the map is null.
*/
public PassiveExpiringMap(ExpirationPolicy<K, V> expiringPolicy,
Map<K, V> map) {
@ -270,11 +248,10 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* time-to-live value measured in milliseconds to create and use a
* {@link ConstantTimeToLiveExpirationPolicy} expiration policy.
*
* @param timeToLiveMillis
* the constant amount of time (in milliseconds) an entry is
* available before it expires. A negative value results in
* entries that NEVER expire. A zero value results in entries
* that ALWAYS expire.
* @param timeToLiveMillis the constant amount of time (in milliseconds) an
* entry is available before it expires. A negative value results in
* entries that NEVER expire. A zero value results in entries that
* ALWAYS expire.
*/
public PassiveExpiringMap(long timeToLiveMillis) {
this(new ConstantTimeToLiveExpirationPolicy<K, V>(timeToLiveMillis),
@ -288,15 +265,12 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* are any elements already in the map being decorated, they will NEVER
* expire unless they are replaced.
*
* @param timeToLiveMillis
* the constant amount of time (in milliseconds) an entry is
* available before it expires. A negative value results in
* entries that NEVER expire. A zero value results in entries
* that ALWAYS expire.
* @param map
* the map to decorate, must not be null.
* @throws IllegalArgumentException
* if the map is null.
* @param timeToLiveMillis the constant amount of time (in milliseconds) an
* entry is available before it expires. A negative value results in
* entries that NEVER expire. A zero value results in entries that
* ALWAYS expire.
* @param map the map to decorate, must not be null.
* @throws IllegalArgumentException if the map is null.
*/
public PassiveExpiringMap(long timeToLiveMillis, Map<K, V> map) {
this(new ConstantTimeToLiveExpirationPolicy<K, V>(timeToLiveMillis),
@ -308,15 +282,12 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* the given time units of measure to create and use a
* {@link ConstantTimeToLiveExpirationPolicy} expiration policy.
*
* @param timeToLive
* the constant amount of time an entry is available before it
* expires. A negative value results in entries that NEVER
* @param timeToLive the constant amount of time an entry is available
* before it expires. A negative value results in entries that NEVER
* expire. A zero value results in entries that ALWAYS expire.
* @param timeUnit
* the unit of time for the <code>timeToLive</code> parameter,
* must not be null.
* @throws IllegalArgumentException
* if the time unit is null.
* @param timeUnit the unit of time for the <code>timeToLive</code>
* parameter, must not be null.
* @throws IllegalArgumentException if the time unit is null.
*/
public PassiveExpiringMap(long timeToLive, TimeUnit timeUnit) {
this(validateAndConvertToMillis(timeToLive, timeUnit));
@ -330,19 +301,14 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* in the map being decorated, they will NEVER expire unless they are
* replaced.
*
* @param timeToLive
* the constant amount of time an entry is available before it
* expires. A negative value results in entries that NEVER
* @param timeToLive the constant amount of time an entry is available
* before it expires. A negative value results in entries that NEVER
* expire. A zero value results in entries that ALWAYS expire.
* @param timeUnit
* the unit of time for the <code>timeToLive</code> parameter,
* must not be null.
* @throws IllegalArgumentException
* if the time unit is null.
* @param map
* the map to decorate, must not be null.
* @throws IllegalArgumentException
* if the map is null.
* @param timeUnit the unit of time for the <code>timeToLive</code>
* parameter, must not be null.
* @throws IllegalArgumentException if the time unit is null.
* @param map the map to decorate, must not be null.
* @throws IllegalArgumentException if the map is null.
*/
public PassiveExpiringMap(long timeToLive, TimeUnit timeUnit, Map<K, V> map) {
this(validateAndConvertToMillis(timeToLive, timeUnit), map);
@ -353,10 +319,8 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
* entries NEVER expiring. If there are any elements already in the map
* being decorated, they also will NEVER expire.
*
* @param map
* the map to decorate, must not be null.
* @throws IllegalArgumentException
* if the map is null.
* @param map the map to decorate, must not be null.
* @throws IllegalArgumentException if the map is null.
*/
public PassiveExpiringMap(Map<K, V> map) {
this(-1L, map);
@ -425,11 +389,9 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
/**
* Determines if the given expiration time is less than <code>now</code>
*
* @param now
* the time in milliseconds used to compare against the
* @param now the time in milliseconds used to compare against the
* expiration time.
* @param expirationTimeObject
* the expiration time value retrieved from
* @param expirationTimeObject the expiration time value retrieved from
* {@link #expirationMap}, can be null.
* @return <code>true</code> if <code>expirationTimeObject</code> is &ge; 0
* and <code>expirationTimeObject</code> &lt; <code>now</code>.
@ -540,15 +502,14 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
/**
* Read the map in using a custom routine.
*
* @param in
* the input stream
* @param in the input stream
* @throws IOException
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
// (1) should only fail if input stream is incorrect
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
map = (Map<K, V>) in.readObject(); // (1)
}
@ -556,11 +517,11 @@ public class PassiveExpiringMap<K, V> extends AbstractMapDecorator<K, V>
/**
* Write the map out using a custom routine.
*
* @param out
* the output stream
* @param out the output stream
* @throws IOException
*/
private void writeObject(ObjectOutputStream out) throws IOException {
private void writeObject(ObjectOutputStream out)
throws IOException {
out.defaultWriteObject();
out.writeObject(map);
}

View File

@ -9,10 +9,11 @@ import junit.framework.Test;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.map.PassiveExpiringMap.ExpirationPolicy;
public class TestPassiveExpiringMap<K, V> extends AbstractTestMap<K, V> {
public class TestPassiveExpiringMap<K, V>
extends AbstractTestMap<K, V> {
private static class TestExpirationPolicy implements
ExpirationPolicy<Integer, String> {
private static class TestExpirationPolicy
implements ExpirationPolicy<Integer, String> {
private static final long serialVersionUID = 1L;
@ -60,7 +61,8 @@ public class TestPassiveExpiringMap<K, V> extends AbstractTestMap<K, V> {
m.put(Integer.valueOf(5), "five");
m.put(Integer.valueOf(6), "six");
return new PassiveExpiringMap<Integer, String>(
new TestExpirationPolicy(), m);
new TestExpirationPolicy(),
m);
}
@Override