You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2014/09/04 10:07:06 UTC
svn commit: r1622414 -
/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
Author: cziegeler
Date: Thu Sep 4 08:07:06 2014
New Revision: 1622414
URL: http://svn.apache.org/r1622414
Log:
FELIX-4632 : [RFC212] Make properties map passed to event methods comparable
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java?rev=1622414&r1=1622413&r2=1622414&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java Thu Sep 4 08:07:06 2014
@@ -35,11 +35,13 @@ import org.osgi.framework.ServiceReferen
* a <code>Map</code> whose modificaiton methods (like {@link #put(Object, Object)},
* {@link #remove(Object)}, etc.) have no effect.
*/
-public class ReadOnlyDictionary<S, T> extends Dictionary<S, T> implements Map<S, T>
+public class ReadOnlyDictionary<S, T> extends Dictionary<S, T>
+ implements Map<S, T>, Comparable<ReadOnlyDictionary<S, T>>
{
private final Hashtable<S, T> m_delegate;
+ private final ServiceReference<?> m_serviceReference;
/**
* Creates a wrapper for the given delegate dictionary providing read
@@ -59,6 +61,7 @@ public class ReadOnlyDictionary<S, T> ex
this.m_delegate.put( entry.getKey(), entry.getValue() );
}
}
+ m_serviceReference = null;
}
@@ -79,28 +82,33 @@ public class ReadOnlyDictionary<S, T> ex
}
}
m_delegate = properties;
+ m_serviceReference = serviceReference;
}
//---------- Dictionary API
+ @Override
public Enumeration<T> elements()
{
return m_delegate.elements();
}
+ @Override
public T get( final Object key )
{
return m_delegate.get( key );
}
+ @Override
public boolean isEmpty()
{
return m_delegate.isEmpty();
}
+ @Override
public Enumeration<S> keys()
{
return m_delegate.keys();
@@ -111,6 +119,7 @@ public class ReadOnlyDictionary<S, T> ex
* This method has no effect and always returns <code>null</code> as this
* instance is read-only and cannot modify and properties.
*/
+ @Override
public T put( final S key, final T value )
{
return null;
@@ -121,18 +130,21 @@ public class ReadOnlyDictionary<S, T> ex
* This method has no effect and always returns <code>null</code> as this
* instance is read-only and cannot modify and properties.
*/
+ @Override
public T remove( final Object key )
{
return null;
}
+ @Override
public int size()
{
return m_delegate.size();
}
+ @Override
public String toString()
{
return m_delegate.toString();
@@ -181,4 +193,23 @@ public class ReadOnlyDictionary<S, T> ex
{
return Collections.unmodifiableCollection( m_delegate.values() );
}
+
+
+ public int compareTo(ReadOnlyDictionary<S, T> o)
+ {
+ if ( m_serviceReference == null )
+ {
+ if ( o.m_serviceReference == null )
+ {
+ return 0;
+ }
+ return 1;
+ }
+ else if ( o.m_serviceReference == null )
+ {
+ return -1;
+ }
+ return m_serviceReference.compareTo(o.m_serviceReference);
+ }
+
}