You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2015/09/10 08:59:30 UTC
svn commit: r1702174 [4/5] - in
/river/jtsk/skunk/qa-refactor-namespace/trunk: ./
qa/src/org/apache/river/test/impl/outrigger/javaspace05/ src/manifest/
src/net/jini/core/entry/ src/net/jini/core/lookup/ src/net/jini/entry/
src/net/jini/loader/ src/net...
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftEqualityReference.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftEqualityReference.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftEqualityReference.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftEqualityReference.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,81 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+/**
+ * Implemented as per Ref.SOFT
+ *
+ * @see Ref#SOFT
+ * @author Peter Firmstone.
+ */
+class SoftEqualityReference<T> extends SoftReference<T> implements Referrer<T>, Serializable{
+ private static final long serialVersionUID = 1L;
+ private final int hash; // Once the object is garbage collected, hash is the only identifier.
+
+ SoftEqualityReference(T k, ReferenceQueue<? super T> q) {
+ super(k,q);
+ int hash = 7;
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ this.hash = hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true; // Same reference.
+ if (!(o instanceof Referrer)) return false;
+ Object k1 = get();
+ Object k2 = ((Referrer) o).get();
+ if ( k1 != null && k1.equals(k2)) return true;
+ return ( k1 == null && k2 == null && hashCode() == o.hashCode());
+ }
+
+ @Override
+ public int hashCode() {
+ Object k = get();
+ int hash = 7;
+ if (k != null) {
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ } else {
+ hash = this.hash;
+ }
+ return hash;
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ final Object writeReplace() throws ObjectStreamException {
+ return ReferenceSerializationFactory.create(get());
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException{
+ throw new InvalidObjectException("Builder required");
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftIdentityReference.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftIdentityReference.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftIdentityReference.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/SoftIdentityReference.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,74 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+/**
+ * Implementation as per Ref.SOFT_IDENTITY
+ *
+ * @see Ref#SOFT_IDENTITY
+ * @author Peter Firmstone.
+ */
+class SoftIdentityReference<T> extends SoftReference<T> implements Referrer<T>, Serializable{
+ private static final long serialVersionUID = 1L;
+ private final int hash;
+
+ SoftIdentityReference(T k, ReferenceQueue<? super T> q) {
+ super(k,q);
+ int hash = 7;
+ hash = 29 * hash + System.identityHashCode(k);
+ hash = 29 * hash + k.getClass().hashCode();
+ this.hash = hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Referrer)) return false;
+ Object k1 = get();
+ Object k2 = ((Referrer) o).get();
+ if ( k1 != null && k1 == k2 ) return true;
+ return ( k1 == null && k2 == null && hashCode() == o.hashCode());
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ private Object writeReplace() {
+ // returns a Builder instead of this class.
+ return ReferenceSerializationFactory.create(get());
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException{
+ throw new InvalidObjectException("Factory required");
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/StrongReference.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/StrongReference.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/StrongReference.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/StrongReference.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,117 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+
+/**
+ * Implemented as per Ref.STRONG
+ *
+ * @see Ref#STRONG
+ * @author Peter Firmstone
+ */
+class StrongReference<T> implements Referrer<T>, Serializable{
+ private static final long serialVersionUID = 1L;
+ private T referent;
+ private final int hash;
+
+ /**
+ * Creates a new strong reference that refers to the given object. The new
+ * reference is not registered with any queue.
+ *
+ * @param referent object the new weak reference will refer to
+ */
+ StrongReference(T referent){
+ this.referent = referent ;
+ int hash = 7;
+ hash = 29 * hash + referent.hashCode();
+ hash = 29 * hash + referent.getClass().hashCode();
+ this.hash = hash;
+ }
+
+ /**
+ * Creates a new strong reference that refers to the given object. The
+ * reference queue is silently ignored.
+ *
+ * @param referent object the new weak reference will refer to
+ * @param q queue is never used.
+ */
+ StrongReference(T referent, ReferenceQueue<? super T> q) {
+ this(referent);
+ }
+
+ @Override
+ public int hashCode() {
+ Object k = get();
+ int hash = 7;
+ if (k != null) {
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ } else {
+ hash = this.hash;
+ }
+ return hash;
+ }
+
+ public boolean equals(Object o){
+ if (this == o) return true; // Same reference.
+ if (!(o instanceof Referrer)) return false;
+ Object k1 = get();
+ Object k2 = ((Referrer) o).get();
+ if ( k1 != null && k1.equals(k2)) return true;
+ return ( k1 == null && k2 == null && hashCode() == o.hashCode());
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ @Override
+ public void clear() {
+ this.referent = null;
+ }
+
+ final Object writeReplace() throws ObjectStreamException {
+ return ReferenceSerializationFactory.create(get());
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException{
+ throw new InvalidObjectException("Builder required");
+ }
+
+ @Override
+ public T get() {
+ return referent;
+ }
+
+ @Override
+ public boolean isEnqueued() {
+ return false;
+ }
+
+ @Override
+ public boolean enqueue() {
+ return false;
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempComparableReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempComparableReferrer.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempComparableReferrer.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempComparableReferrer.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,49 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @author peter
+ */
+class TempComparableReferrer<T> extends TempEqualReferrer<T>
+ implements Comparable<Referrer<T>>{
+
+ TempComparableReferrer(T t){
+ super(t);
+ }
+
+ public int compareTo(Referrer<T> o) {
+ T t = lookDontTouch();
+ T r = null;
+ if (o instanceof UntouchableReferrer){
+ r = ((UntouchableReferrer<T>)o).lookDontTouch();
+ }else{
+ r = o.get();
+ }
+ if ( t != null && r != null) {
+ if ( t instanceof Comparable){
+ int result = ((Comparable) t).compareTo(r);
+ if ( result == 0 ){
+ o.get();
+ }
+ }
+ }
+ if ( hashCode() < o.hashCode()) return -1;
+ if ( hashCode() == o.hashCode()) return 0;
+ return 1;
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempEqualReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempEqualReferrer.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempEqualReferrer.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempEqualReferrer.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,47 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @param <T>
+ * @author peter
+ */
+class TempEqualReferrer<T> extends TempIdentityReferrer<T> {
+
+ TempEqualReferrer(T t){
+ super(t);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ } else if (!(o instanceof Referrer)) {
+ return false;
+ }
+ Object t2 = ((Referrer) o).get();
+ return ( get().equals(t2) );
+ }
+
+ public int hashCode(){
+ Object k = get();
+ int hash = 7;
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ return hash;
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempIdentityReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempIdentityReferrer.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempIdentityReferrer.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TempIdentityReferrer.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,73 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @author peter
+ */
+class TempIdentityReferrer<T> implements UntouchableReferrer<T> {
+
+ private final T t;
+
+ TempIdentityReferrer(T t){
+ if ( t == null ) throw new NullPointerException("Null prohibited");
+ this.t = t;
+ }
+
+ @Override
+ public T get() {
+ return t;
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public boolean isEnqueued() {
+ return false;
+ }
+
+ @Override
+ public boolean enqueue() {
+ return false;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ } else if (!(o instanceof Referrer)) {
+ return false;
+ }
+ Object t2 = ((Referrer) o).get();
+ return( t == t2 );
+ }
+
+ public int hashCode(){
+ int hash = 7;
+ hash = 29 * hash + System.identityHashCode(t);
+ hash = 29 * hash + t.getClass().hashCode();
+ return hash;
+ }
+
+ public T lookDontTouch() {
+ return t;
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimeBomb.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimeBomb.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimeBomb.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimeBomb.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2012 peter.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @author peter
+ */
+interface TimeBomb {
+
+ void updateClock(long time);
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedComparableReferrerDecorator.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedComparableReferrerDecorator.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedComparableReferrerDecorator.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedComparableReferrerDecorator.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @param <T>
+ * @author peter
+ */
+class TimedComparableReferrerDecorator<T> extends TimedReferrerDecorator<T>
+ implements Comparable<Referrer<T>> {
+ private static final long serialVersionUID = 1L;
+
+ TimedComparableReferrerDecorator(Referrer<T> r){
+ super(r);
+ }
+
+ public int compareTo(Referrer<T> o) {
+ T t = null;
+ Referrer<T> ref = getReference();
+ if (ref instanceof UntouchableReferrer){
+ t = ((UntouchableReferrer<T>)ref).lookDontTouch();
+ } else {
+ t = ref.get();
+ }
+ T r = null;
+ if (o instanceof UntouchableReferrer){
+ r = ((UntouchableReferrer<T>)o).lookDontTouch();
+ } else {
+ o.get();
+ }
+ if ( t != null && r != null) {
+ if ( t instanceof Comparable){
+ int c = ((Comparable) t).compareTo(r);
+ if (c == 0){ // If they were untouchable, this is a hit.
+ ref.get();
+ o.get();
+ }
+ return c;
+ }
+ }
+ if ( hashCode() < o.hashCode()) return -1;
+ if ( hashCode() == o.hashCode()) return 0;
+ return 1;
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedRefQueue.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedRefQueue.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedRefQueue.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedRefQueue.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012 peter.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ *
+ * @author peter
+ */
+class TimedRefQueue extends ConcurrentLinkedQueue implements RefQueue{
+ private static final long serialVersionUID = 1L;
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrer.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrer.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrer.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+import java.util.concurrent.Future;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+class TimedReferrer<T> implements UntouchableReferrer<T>, TimeBomb {
+
+ private volatile long clock;
+ private volatile long read;
+ private final TimedRefQueue queue;
+ private final T referent;
+ private volatile boolean enqued;
+ private final Object lock;
+
+ TimedReferrer(T k, TimedRefQueue q){
+ long time = System.nanoTime();
+ clock = time;
+ read = time;
+ referent = k;
+ queue = q;
+ enqued = false;
+ lock = new Object();
+ }
+
+ public T get() {
+ // Doesn't need to be atomic.
+ if (read < clock) read = clock; //Avoid unnecessary volatile write.
+ return referent;
+ }
+
+ public void clear() {
+ // Does nothing.
+// referent = null;
+ }
+
+ public boolean isEnqueued() {
+ return enqued;
+ }
+
+ public boolean enqueue() {
+ if (enqued) return false;
+// if (referent == null) return false;
+ if (queue == null) return false;
+ synchronized (lock){ // Sync for atomic write of enqued.
+ if (enqued) return false;
+ enqued = queue.offer(this);
+ }
+ return enqued;
+ }
+
+ @Override
+ public void updateClock(long time){
+ if (read < clock) { // only write volatile if necessary.
+ if (referent instanceof Future) ((Future)referent).cancel(false);
+ enqueue();
+ // Don't clear, it will be removed soon anyway, prevents
+ // non empty Queue.poll() returning null.
+ //clear();
+ } else {
+ clock = time;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true; // Same reference.
+ if (!(o instanceof Referrer)) return false;
+ Object k1 = get(); //call get(), so equals updates clock for key's in a hash map.
+ Object k2 =((Referrer) o).get();
+ if ( k1 != null && k1.equals(k2)) return true;
+ return ( k1 == null && k2 == null && hashCode() == o.hashCode()); // Both objects were collected.
+ }
+
+ @Override
+ public int hashCode() {
+ Object k = referent; //don't call get(), avoid read update.
+ int hash = 7;
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ return hash;
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ public T lookDontTouch() {
+ return referent;
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrerDecorator.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrerDecorator.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrerDecorator.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/TimedReferrerDecorator.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 peter.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @param <T>
+ * @author peter
+ */
+class TimedReferrerDecorator<T> extends ReferrerDecorator<T> implements TimeBomb {
+ private static final long serialVersionUID = 1L;
+
+ TimedReferrerDecorator(Referrer<T> r){
+ super(r);
+ if (!(r instanceof TimeBomb)) throw new IllegalStateException("Must be instance of TimeBomb");
+ }
+
+ public void updateClock(long time) {
+ Referrer<T> r = getReference();
+ ((TimeBomb)r).updateClock(time);
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/UntouchableReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/UntouchableReferrer.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/UntouchableReferrer.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/UntouchableReferrer.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2012 Zeus Project Services Pty Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.concurrent;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+interface UntouchableReferrer<T> extends Referrer<T> {
+ T lookDontTouch();
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakEqualityReference.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakEqualityReference.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakEqualityReference.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakEqualityReference.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,86 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * Implemented as per Ref.WEAK
+ *
+ * @see Ref#WEAK
+ * @author Peter Firmstone
+ */
+class WeakEqualityReference<T> extends WeakReference<T> implements Referrer<T>, Serializable {
+ private static final long serialVersionUID = 1L;
+ private final int hash; // Only used after referent has been garbage collected.
+
+ WeakEqualityReference(T k, ReferenceQueue<? super T> q) {
+ super(k,q);
+ int hash = 7;
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ this.hash = hash;
+ }
+
+ /* ReferenceQueue is not compared, because a lookup key is used to locate
+ * an existing key and ReferenceQueue is null in lookup key's.
+ *
+ * ReferenceQueue is not part of hashCode or equals.
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true; // Same reference.
+ if (!(o instanceof Referrer)) return false;
+ Object k1 = get();
+ Object k2 = ((Referrer) o).get();
+ if ( k1 != null && k1.equals(k2)) return true;
+ return ( k1 == null && k2 == null && hashCode() == o.hashCode()); // Both objects were collected.
+ }
+
+ @Override
+ public int hashCode() {
+ Object k = get();
+ int hash = 7;
+ if (k != null) {
+ hash = 29 * hash + k.hashCode();
+ hash = 29 * hash + k.getClass().hashCode();
+ } else {
+ hash = this.hash;
+ }
+ return hash;
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ final Object writeReplace() throws ObjectStreamException {
+ return ReferenceSerializationFactory.create(get());
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException{
+ throw new InvalidObjectException("Builder required");
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakIdentityReference.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakIdentityReference.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakIdentityReference.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/WeakIdentityReference.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,77 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * Implemented as per Ref.WEAK_IDENTITY
+ *
+ * @see Ref#WEAK_IDENTITY
+ * @author Peter Firmstone.
+ */
+class WeakIdentityReference<T> extends WeakReference<T> implements Referrer<T>, Serializable {
+ private static final long serialVersionUID = 1L;
+ private final int hash;
+
+ WeakIdentityReference(T k, ReferenceQueue<? super T> q) {
+ super(k,q);
+ int hash = 7;
+ hash = 29 * hash + System.identityHashCode(k);
+ hash = 29 * hash + k.getClass().hashCode();
+ this.hash = hash;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ } else if (!(o instanceof Referrer)) {
+ return false;
+ }
+ Object k1 = get();
+ Object k2 = ((Referrer) o).get();
+ if ( k1 != null && k1 == k2 ) return true;
+ return ( k1 == null && k2 == null && hash == o.hashCode());
+ }
+
+ @Override
+ public int hashCode() {
+ return hash;
+ }
+
+ @Override
+ public String toString(){
+ Object s = get();
+ if (s != null) return s.toString();
+ return super.toString();
+ }
+
+ final Object writeReplace() throws ObjectStreamException {
+ return ReferenceSerializationFactory.create(get());
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException{
+ throw new InvalidObjectException("Builder required");
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/package.html
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/package.html?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/package.html (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/concurrent/package.html Thu Sep 10 06:59:28 2015
@@ -0,0 +1,81 @@
+<!--
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Custard-apple</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <div>
+ <p>Custard-apple is a utility that enables weak, soft, strong
+ or time references to be used in any collection implementing standard
+ Java Framework Interfaces</p>
+ <p>Expected behaviour of reference types may vary between platforms
+ and should not be depended upon other than; weak references will
+ be collected when no further strong references remain and soft
+ references may be collected at any time the JVM's available memory
+ is under pressure and the referent is softly reachable. Time
+ references should exhibit identical behaviour on all platforms and
+ will be collected after a period of inactivity, even while strong
+ references to those objects remain.</p>
+ <p>Due to the multi threaded nature of Custard-apple the
+ garbage collection thread may not see timestamp updates on soft
+ references when reading objects from collections, possibly causing those
+ soft references to be collected earlier than expected.</p>
+ <p>Large memory heaps cause issues with soft references in the Oracle
+ jvm, in this case use -XX:SoftRefLRUPolicyMSPerMB=1 to minimise
+ GC issues. At least until bug 6912889 is fixed.</p>
+ <p>Cliff Click's highly scalable hash map has been tested with
+ Custard-apple, also designed with scalability in mind.
+ Cleaning of garbage collected objects from collections is performed
+ by a background executor periodically. Internal implementations
+ produce significant quantities of short lived objects during
+ read operations that die young. These objects only ever live in
+ CPU cache, are not written back to shared memory and are never
+ shared between threads.</p>
+ <p>Although Custard-apple is intended to be scalable it
+ has not been tested on highly scalable hardware, if you have
+ access to such hardware, feel free to write tests and
+ contribute back performance improvements.</p>
+ <p>Timed references are provided for caching purposes and also
+ support cancellation of Future's, for example timed references can
+ be used in Queue's as a throttling mechanism, similar to a
+ network dropping packets. Referent Future tasks will be cancelled by the
+ cleaning thread when enqueued.</p>
+ <p>Serialization support for Map's will be implemented in a future
+ release. Serialization of other collection types is supported,
+ provided the underlying collection also supports Serialization.</p>
+ <p>Serialized form has been implemented as a separate concern
+ using the
+ <link><i><a href="http://wiki.apache.org/river/Serialization">
+ Serialization Builder Pattern</a></i>
+ with the readResolve() workaround.
+ </p>
+ <p>Package private implementation classes are not tied to
+ serial form. These classes are not published by implementing
+ Serializable. Future versions of this library, may
+ utilise a completely different class or classes upon deserialisation.
+ The serial form may also change between releases in ways that would
+ normally break compatibility, multiple serial forms may exist for
+ one class in multiple versions of it, without ever breaking
+ compatibility. Currently all classes that implement Collection
+ share an identical serial form.</p>
+ <p>Serialization compatibility is guaranteed between different releases.</p>
+ </div>
+ </body>
+</html>
Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/impl/lease/AbstractLeaseMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/impl/lease/AbstractLeaseMap.java?rev=1702174&r1=1702173&r2=1702174&view=diff
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/impl/lease/AbstractLeaseMap.java (original)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/impl/lease/AbstractLeaseMap.java Thu Sep 10 06:59:28 2015
@@ -18,9 +18,9 @@
package org.apache.river.impl.lease;
-import au.net.zeus.collection.RC;
-import au.net.zeus.collection.Ref;
-import au.net.zeus.collection.Referrer;
+import org.apache.river.concurrent.RC;
+import org.apache.river.concurrent.Ref;
+import org.apache.river.concurrent.Referrer;
import java.util.AbstractMap;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/outrigger/OutriggerServerImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/outrigger/OutriggerServerImpl.java?rev=1702174&r1=1702173&r2=1702174&view=diff
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/outrigger/OutriggerServerImpl.java (original)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/outrigger/OutriggerServerImpl.java Thu Sep 10 06:59:28 2015
@@ -17,9 +17,9 @@
*/
package org.apache.river.outrigger;
-import au.net.zeus.collection.RC;
-import au.net.zeus.collection.Ref;
-import au.net.zeus.collection.Referrer;
+import org.apache.river.concurrent.RC;
+import org.apache.river.concurrent.Ref;
+import org.apache.river.concurrent.Referrer;
import org.apache.river.config.Config;
import org.apache.river.constants.TimeConstants;
import org.apache.river.landlord.Landlord;
Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/reggie/RegistrarEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/reggie/RegistrarEvent.java?rev=1702174&r1=1702173&r2=1702174&view=diff
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/reggie/RegistrarEvent.java (original)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/reggie/RegistrarEvent.java Thu Sep 10 06:59:28 2015
@@ -80,6 +80,9 @@ class RegistrarEvent extends ServiceEven
* from the lookup service.
*/
public ServiceItem getServiceItem() {
+ if (serviceItem instanceof ServiceItem){
+ return ((ServiceItem) serviceItem).clone();
+ }
return (ServiceItem)serviceItem;
}
Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/AggregatePolicyProvider.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/AggregatePolicyProvider.java?rev=1702174&r1=1702173&r2=1702174&view=diff
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/AggregatePolicyProvider.java (original)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/AggregatePolicyProvider.java Thu Sep 10 06:59:28 2015
@@ -18,9 +18,9 @@
package org.apache.river.start;
-import au.net.zeus.collection.RC;
-import au.net.zeus.collection.Ref;
-import au.net.zeus.collection.Referrer;
+import org.apache.river.concurrent.RC;
+import org.apache.river.concurrent.Ref;
+import org.apache.river.concurrent.Referrer;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.AccessController;
Modified: river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/LoaderSplitPolicyProvider.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/LoaderSplitPolicyProvider.java?rev=1702174&r1=1702173&r2=1702174&view=diff
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/LoaderSplitPolicyProvider.java (original)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/src/org/apache/river/start/LoaderSplitPolicyProvider.java Thu Sep 10 06:59:28 2015
@@ -33,9 +33,9 @@ import java.util.concurrent.ConcurrentHa
import java.util.concurrent.ConcurrentMap;
import org.apache.river.api.security.ScalableNestedPolicy;
import org.apache.river.api.security.PermissionGrant;
-import au.net.zeus.collection.RC;
-import au.net.zeus.collection.Ref;
-import au.net.zeus.collection.Referrer;
+import org.apache.river.concurrent.RC;
+import org.apache.river.concurrent.Ref;
+import org.apache.river.concurrent.Referrer;
/**
* Security policy provider which handles permission queries and grants by
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/MutableMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/MutableMap.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/MutableMap.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/MutableMap.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,79 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.util.AbstractMap;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+public class MutableMap<K,V> extends AbstractMap<K,V> {
+ private Set<Entry<K,V>> entrySet;
+ public MutableMap(){
+ entrySet = new TreeSet<Entry<K,V>>(new Compare<K,V>());
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return entrySet;
+ }
+
+ public V put(K key, V value) {
+ Entry<K,V> e = new SimpleEntry<K,V>(key, value);
+ V oldVal = null;
+ Iterator<Entry<K,V>> i = entrySet.iterator();
+ while (i.hasNext()){
+ Entry<K,V> en = i.next();
+ if ( e.getKey().equals(key)){
+ i.remove();
+ oldVal = e.getValue();
+ break;
+ }
+ }
+ entrySet.add(e);
+ return oldVal;
+ }
+
+ /**
+ * This class prevents duplicate keys from being added to the underlying
+ * set.
+ * @param <K>
+ * @param <V>
+ */
+ private static class Compare<K,V> implements Comparator<Entry<K,V>> {
+
+ @Override
+ public int compare(Entry<K, V> o1, Entry<K, V> o2) {
+ K key1 = o1.getKey();
+ K key2 = o2.getKey();
+ if (key1 instanceof Comparable && key2 instanceof Comparable){
+ return ((Comparable) key1).compareTo(key2);
+ }
+ if ( key1.hashCode() < key2.hashCode()) return -1;
+ if ( key1.hashCode() == key2.hashCode()) return 0;
+ return 1;
+ }
+
+
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceBlockingQueueTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceBlockingQueueTest.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceBlockingQueueTest.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceBlockingQueueTest.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,187 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.Executor;
+import java.lang.ref.Reference;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.Collection;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceBlockingQueueTest {
+ private BlockingQueue<String> instance;
+ public ReferenceBlockingQueueTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = RC.blockingQueue(new ArrayBlockingQueue<Referrer<String>>(30), Ref.SOFT, 10000L);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of put method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testPut() throws Exception {
+ System.out.println("put");
+ String e = "put";
+ instance.put(e);
+ String r = instance.take();
+ assertEquals(e, r);
+ }
+
+ /**
+ * Test of offer method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testOffer() throws Exception {
+ System.out.println("offer");
+ String e = "offer";
+ long timeout = 2L;
+ TimeUnit unit = TimeUnit.MILLISECONDS;
+ boolean expResult = true;
+ boolean result = instance.offer(e, timeout, unit);
+ assertEquals(expResult, result);
+ result = instance.remove(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of take method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testTake() throws Exception {
+ System.out.println("take");
+ String expResult = "take";
+ instance.add(expResult);
+ Object result = instance.take();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of poll method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testPoll() throws Exception {
+ System.out.println("poll");
+ long timeout = 10L;
+ TimeUnit unit = TimeUnit.MILLISECONDS;
+ String expResult = "poll";
+ instance.add(expResult);
+ Object result = instance.poll(timeout, unit);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of remainingCapacity method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testRemainingCapacity() {
+ System.out.println("remainingCapacity");
+ int expResult = 30;
+ int result = instance.remainingCapacity();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of drainTo method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testDrainTo_Collection() {
+ System.out.println("drainTo");
+ Collection<String> c = new ArrayList<String>();
+ instance.add("drain");
+ instance.add("two");
+ int expResult = 2;
+ int result = instance.drainTo(c);
+ assertEquals(expResult, result);
+ assertTrue(c.contains("drain"));
+ assertTrue(c.contains("two"));
+ }
+
+ /**
+ * Test of drainTo method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testDrainTo_Collection_int() {
+ System.out.println("drainTo");
+ Collection<String> c = new ArrayList<String>();
+ instance.add("drain");
+ instance.add("too");
+ int maxElements = 1;
+ int expResult = 1;
+ int result = instance.drainTo(c, maxElements);
+ assertEquals(expResult, result);
+ }
+
+
+ /**
+ * Test serialization
+ */
+ @Test
+ @SuppressWarnings("unchecked")
+ public void serialization() {
+ System.out.println("Serialization Test");
+ Object result = null;
+ ObjectOutputStream out = null;
+ ObjectInputStream in = null;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ out = new ObjectOutputStream(baos);
+ out.writeObject(instance);
+ // Unmarshall it
+ in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+ result = in.readObject();
+ } catch (IOException ex) {
+ ex.printStackTrace(System.out);
+ } catch (ClassNotFoundException ex){
+ ex.printStackTrace(System.out);
+ }
+ assertTrue(result instanceof BlockingQueue);
+ assertTrue(instance.containsAll((BlockingQueue<String>)result));
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceCollectionTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceCollectionTest.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceCollectionTest.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceCollectionTest.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,247 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * This test also validates ReferenceSet and most of ReferenceList.
+ *
+ * @author peter
+ */
+public class ReferenceCollectionTest {
+
+ private ReferenceCollection<String> instance;
+ private String truck = "truck";
+ private String shovel = "shovel";
+ private String grader = "grader";
+ private String waterTruck = "water truck";
+ private String roller = "roller";
+
+ public ReferenceCollectionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = new ReferenceCollection<String>(new ArrayList<Referrer<String>>(), Ref.WEAK_IDENTITY, false, 10000L);
+ instance.add(truck);
+ instance.add(shovel);
+ instance.add(grader);
+ instance.add(waterTruck);
+ instance.add(roller);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of size method, of class ReferenceCollection.
+ */
+ @Test
+ public void testSize() {
+ System.out.println("size");
+ int expResult = 5;
+ int result = instance.size();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of isEmpty method, of class ReferenceCollection.
+ */
+ @Test
+ public void testIsEmpty() {
+ System.out.println("isEmpty");
+ boolean expResult = false;
+ boolean result = instance.isEmpty();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of contains method, of class ReferenceCollection.
+ */
+ @Test
+ public void testContains() {
+ System.out.println("contains");
+ String o = "truck";
+ boolean expResult = true;
+ boolean result = instance.contains(o);
+ // This only passes because String uses object pooling.
+ // For other objects this would fail when identity and equality
+ // are not the same.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of iterator method, of class ReferenceCollection.
+ */
+ @Test
+ public void testIterator() {
+ System.out.println("iterator");
+ Collection<String> expResult = new ArrayList<String>(5);
+ expResult.add(truck);
+ expResult.add(shovel);
+ expResult.add(waterTruck);
+ expResult.add(grader);
+ expResult.add(roller);
+ Collection<String> result = new ArrayList<String>(5);
+ Iterator<String> it = instance.iterator();
+ while (it.hasNext()){
+ result.add(it.next());
+ }
+ assertTrue(expResult.containsAll(result));
+ }
+
+ /**
+ * Test of toArray method, of class ReferenceCollection.
+ */
+ @Test
+ public void testToArray_0args() {
+ System.out.println("toArray");
+ Object[] expResult = {truck, shovel, waterTruck, grader, roller};
+ Object[] result = instance.toArray();
+ assertTrue(expResult.length == result.length);
+ Collection res = Arrays.asList(result);
+ Collection exp = Arrays.asList(expResult);
+ assertTrue(exp.containsAll(res));
+ }
+
+ /**
+ * Test of toArray method, of class ReferenceCollection.
+ */
+ @Test
+ public void testToArray_GenericType() {
+ System.out.println("toArray");
+ String[] a = new String [5];
+ String[] expResult = {truck, shovel, waterTruck, grader, roller};
+ String[] result = instance.toArray(a);
+ assertTrue(expResult.length == result.length);
+ Collection<String> res = Arrays.asList(result);
+ Collection<String> exp = Arrays.asList(expResult);
+ assertTrue(exp.containsAll(res));
+ }
+
+ /**
+ * Test of add method, of class ReferenceCollection.
+ */
+ @Test
+ public void testAdd() {
+ System.out.println("add");
+ truck = "cat797";
+ boolean expResult = true;
+ boolean result = instance.add(truck);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of remove method, of class ReferenceCollection.
+ */
+ @Test
+ public void testRemove() {
+ System.out.println("remove");
+ boolean expResult = true;
+ boolean result = instance.remove(shovel);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of containsAll method, of class ReferenceCollection.
+ */
+ @Test
+ public void testContainsAll() {
+ System.out.println("containsAll");
+ Collection<String> c = new ArrayList<String>(4);
+ c.add(truck);
+ c.add(grader);
+ c.add(waterTruck);
+ c.add(roller);
+ boolean expResult = true;
+ boolean result = instance.containsAll(c);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of addAll method, of class ReferenceCollection.
+ */
+ @Test
+ public void testAddAll() {
+ System.out.println("addAll");
+ Collection<String> c = new ArrayList<String>(2);
+ c.add("Kress");
+ c.add("Bucyrus");
+ boolean expResult = true;
+ boolean result = instance.addAll(c);
+ assertEquals(expResult, result);
+ assertTrue(instance.containsAll(c));
+ }
+
+ /**
+ * Test of removeAll method, of class ReferenceCollection.
+ */
+ @Test
+ public void testRemoveAll() {
+ System.out.println("removeAll");
+ Collection<String> c = new ArrayList<String>(2);
+ c.add(grader);
+ c.add(roller);
+ boolean expResult = true;
+ boolean result = instance.removeAll(c);
+ assertEquals(expResult, result);
+ assertFalse(instance.containsAll(c));
+ }
+
+ /**
+ * Test of retainAll method, of class ReferenceCollection.
+ */
+ @Test
+ public void testRetainAll() {
+ System.out.println("retainAll");
+ Collection<String> c = new ArrayList<String>(2);
+ c.add(truck);
+ c.add(waterTruck);
+ boolean expResult = true;
+ boolean result = instance.retainAll(c);
+ assertEquals(expResult, result);
+ assertTrue( instance.size() == 2);
+ }
+
+ /**
+ * Test of clear method, of class ReferenceCollection.
+ */
+ @Test
+ public void testClear() {
+ System.out.println("clear");
+ instance.clear();
+ assertTrue( instance.isEmpty() );
+ }
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentMapConcurrencyTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentMapConcurrencyTest.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentMapConcurrencyTest.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentMapConcurrencyTest.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,165 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import edu.illinois.imunit.Schedules;
+import edu.illinois.imunit.Schedule;
+import org.junit.Test;
+import java.util.concurrent.ConcurrentHashMap;
+import org.junit.Before;
+import java.util.concurrent.ConcurrentMap;
+import edu.illinois.imunit.IMUnitRunner;
+import org.junit.runner.RunWith;
+import static edu.illinois.imunit.IMUnit.fireEvent;
+import static edu.illinois.imunit.IMUnit.schAssertEquals;
+import static edu.illinois.imunit.IMUnit.schAssertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+@RunWith(IMUnitRunner.class)
+public class ReferenceConcurrentMapConcurrencyTest {
+ private ConcurrentMap<Integer,String> map;
+ private ConcurrentMap<Referrer<Integer>,Referrer<String>> internal;
+ private String t1, t2, t3, t4;
+ @Before
+ public void setup() {
+ internal = new ConcurrentHashMap<Referrer<Integer>, Referrer<String>>();
+ map = RC.concurrentMap( internal, Ref.STRONG, Ref.STRONG, 0L, 0L);
+ t1 = null;
+ t2 = null;
+ t3 = null;
+ t4 = null;
+ }
+
+ @Test
+ @Schedule("startingPutIfAbsent1->finishPutIfAbsent1,finishPutIfAbsent1->startingPutIfAbsent2,finishPutIfAbsent1->startingPutIfAbsent3")
+ public void testPut() throws InterruptedException {
+ System.out.println("test putIfAbsent");
+ performParallelPutIfAbsent();
+ assertEquals("Forty-two", map.get(42));
+ }
+
+ @Test
+ @Schedule("startingPut1->finishPut1,finishPut1->startingClear1,startingClear1->finishClear1,finishClear1->startingPut2,finishClear1->startingPut3,finishClear1->startingPut4")
+ public void testPutClearPut() throws InterruptedException {
+ String exp = "Forty-seven";
+ System.out.println("test put Clear put");
+ putClearMultiPut();
+ assertEquals(exp, map.get(new Integer(42)));
+ assertNull(t1);
+ boolean success = t2 == null? t3.equals(exp) && t4.equals(exp) :
+ t3 == null ? t2.equals(exp) && t4.equals(exp):
+ t4 == null ? t2.equals(t3) && t3.equals(exp): false;
+ assertTrue(success);
+ }
+
+ private void performParallelPutIfAbsent() throws InterruptedException {
+ Thread putIfAbsentThread1 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPutIfAbsent1");
+ map.putIfAbsent(42, "Forty-two");
+ fireEvent("finishPutIfAbsent1");
+ }
+ });
+ Thread putIfAbsentThread2 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPutIfAbsent2");
+ map.putIfAbsent(42, "Forty-seven");
+ fireEvent("finishPutIfAbsent2");
+ }
+ });
+ Thread putIfAbsentThread3 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPutIfAbsent3");
+ map.putIfAbsent(42, "Fifty-one");
+ fireEvent("finishPutIfAbsent3");
+ }
+ });
+ putIfAbsentThread1.start();
+ putIfAbsentThread2.start();
+ putIfAbsentThread3.start();
+ putIfAbsentThread1.join();
+ putIfAbsentThread2.join();
+ putIfAbsentThread3.join();
+ }
+
+ private void putClearMultiPut() throws InterruptedException {
+ Thread thread1 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPut1");
+ t1 = map.putIfAbsent(new Integer(42), "Forty-two");
+ fireEvent("finishPut1");
+ }
+ });
+ Thread thread2 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPut2");
+ t2 = map.putIfAbsent(new Integer(42), "Forty-seven");
+ fireEvent("finishPut2");
+ }
+ });
+ Thread thread3 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPut3");
+ t3 = map.putIfAbsent(new Integer(42), "Forty-seven");
+ fireEvent("finishPut3");
+ }
+ });
+ Thread thread4 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingPut4");
+ t4 = map.putIfAbsent(new Integer(42), "Forty-seven");
+ fireEvent("finishPut4");
+ }
+ });
+ Thread thread5 = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ fireEvent("startingClear1");
+ System.out.println("staring clear");
+ Referrer<String> ref = internal.get(ReferenceFactory.singleUseForLookup(new Integer(42), Ref.STRONG));
+ assertNotNull( ref);
+ ref.clear();
+ assertNull( ref.get());
+ fireEvent("finishClear1");
+ }
+ });
+ thread1.start();
+ thread2.start();
+ thread3.start();
+ thread4.start();
+ thread5.start();
+ thread1.join();
+ thread2.join();
+ thread3.join();
+ thread4.join();
+ thread5.join();
+ }
+
+}
Added: river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentNavigableMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentNavigableMapTest.java?rev=1702174&view=auto
==============================================================================
--- river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentNavigableMapTest.java (added)
+++ river/jtsk/skunk/qa-refactor-namespace/trunk/test/src/org/apache/river/concurrent/ReferenceConcurrentNavigableMapTest.java Thu Sep 10 06:59:28 2015
@@ -0,0 +1,358 @@
+/* Copyright (c) 2010-2012 Zeus Project Services Pty Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.concurrent;
+
+import java.util.TreeSet;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.lang.ref.Reference;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.Comparator;
+import java.util.Map.Entry;
+import java.util.NavigableSet;
+import java.util.concurrent.ConcurrentNavigableMap;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceConcurrentNavigableMapTest {
+ private ConcurrentNavigableMap<Integer, String> instance;
+ // strong references
+ private Integer i1, i2, i3, i4, i5;
+ private Comparator<Integer> comparator;
+ public ReferenceConcurrentNavigableMapTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ comparator = new Comparator<Integer>(){
+
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o1.compareTo(o2);
+ }
+
+ };
+ Comparator<Referrer<Integer>> ci = RC.comparator(comparator);
+ ConcurrentNavigableMap<Referrer<Integer>, Referrer<String>> internal
+ = new ConcurrentSkipListMap<Referrer<Integer>, Referrer<String>>(ci);
+ instance = RC.concurrentNavigableMap(internal, Ref.WEAK, Ref.STRONG, 10000L, 10000L);
+ i1 = 1;
+ i2 = 2;
+ i3 = 3;
+ i4 = 4;
+ i5 = 5;
+ instance.put(i1, "1");
+ instance.put(i2, "2");
+ instance.put(i3, "3");
+ instance.put(i4, "4");
+ instance.put(i5, "5");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of comparator method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testComparator() {
+ System.out.println("comparator");
+ Comparator<Integer> expResult = comparator;
+ Comparator<? super Integer> result = instance.comparator();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of subMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testSubMap() {
+ System.out.println("subMap");
+ Integer fromKey = 2;
+ Integer toKey = 4;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(2, "2");
+ expResult.put(3, "3");
+ SortedMap<Integer, String> result = instance.subMap(fromKey, toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testHeadMap() {
+ System.out.println("headMap");
+ Integer toKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(1, "1");
+ expResult.put(2, "2");
+ SortedMap<Integer, String> result = instance.headMap(toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testTailMap() {
+ System.out.println("tailMap");
+ Integer fromKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(3, "3");
+ expResult.put(4, "4");
+ expResult.put(5, "5");
+ SortedMap<Integer, String> result = instance.tailMap(fromKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testFirstKey() {
+ System.out.println("firstKey");
+ Object expResult = 1;
+ Object result = instance.firstKey();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testLastKey() {
+ System.out.println("lastKey");
+ Object expResult = 5;
+ Object result = instance.lastKey();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lowerEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerEntry() {
+ System.out.println("lowerEntry");
+ Integer key = 2;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lowerEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lowerKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerKey() {
+ System.out.println("lowerKey");
+ Integer key = 3;
+ Object expResult = 2;
+ Object result = instance.lowerKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorEntry() {
+ System.out.println("floorEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(4, "4");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.floorEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorKey() {
+ System.out.println("floorKey");
+ Integer key = 3;
+ Object expResult = 3;
+ Object result = instance.floorKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingEntry() {
+ System.out.println("ceilingEntry");
+ Integer key = 3;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(3, "3");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.ceilingEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingKey() {
+ System.out.println("ceilingKey");
+ Integer key = 2;
+ Object expResult = 2;
+ Object result = instance.ceilingKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherEntry() {
+ System.out.println("higherEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.higherEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherKey() {
+ System.out.println("higherKey");
+ Integer key = 3;
+ Object expResult = 4;
+ Object result = instance.higherKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFirstEntry() {
+ System.out.println("firstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.firstEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLastEntry() {
+ System.out.println("lastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lastEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollFirstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollFirstEntry() {
+ System.out.println("pollFirstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollFirstEntry();
+ instance.put(1, "1"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollLastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollLastEntry() {
+ System.out.println("pollLastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollLastEntry();
+ instance.put(5, "5"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingMap() {
+ System.out.println("descendingMap");
+ NavigableMap<Integer, String> result = instance.descendingMap();
+ assertTrue(result.firstKey().equals(5));
+ assertTrue(result.lastKey().equals(1));
+ }
+
+ /**
+ * Test of navigableKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testNavigableKeySet() {
+ System.out.println("navigableKeySet");
+ NavigableSet<Integer> expResult = new TreeSet<Integer>();
+ expResult.add(1);
+ expResult.add(2);
+ expResult.add(3);
+ expResult.add(4);
+ expResult.add(5);
+ NavigableSet<Integer> result = instance.navigableKeySet();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingKeySet() {
+ System.out.println("descendingKeySet");
+ NavigableSet<Integer> result = instance.descendingKeySet();
+ assertTrue(result.first().equals(5));
+ assertTrue(result.last().equals(1));
+ }
+
+}