FELIX-4632 : [RFC212] Make properties map passed to event methods comparable
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1622414 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
index e62d910..1baac09 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
@@ -35,11 +35,13 @@
* 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 @@
this.m_delegate.put( entry.getKey(), entry.getValue() );
}
}
+ m_serviceReference = null;
}
@@ -79,28 +82,33 @@
}
}
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 @@
* 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 @@
* 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 @@
{
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);
+ }
+
}