[jboss-cvs] jboss-portal/common/src/main/org/jboss/portal/common/util ...
Julien Viet
julien at jboss.com
Tue Aug 22 10:08:51 EDT 2006
User: julien
Date: 06/08/22 10:08:51
Modified: common/src/main/org/jboss/portal/common/util
ParameterMap.java
Added: common/src/main/org/jboss/portal/common/util TypedMap.java
Log:
- refactored the ValueMap to PropertyMap and moved it in org.jboss.portal.portlet.state package
- introduced TypedMap that is super type of ParameterMap and is reused for the PropertyMap
Revision Changes Path
1.4 +7 -221 jboss-portal/common/src/main/org/jboss/portal/common/util/ParameterMap.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ParameterMap.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/common/src/main/org/jboss/portal/common/util/ParameterMap.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ParameterMap.java 31 Jul 2006 00:05:39 -0000 1.3
+++ ParameterMap.java 22 Aug 2006 14:08:51 -0000 1.4
@@ -21,23 +21,16 @@
*/
package org.jboss.portal.common.util;
-import java.util.Map;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
/**
* A decorator that enforce the map content to be <String,String[]>
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public abstract class ParameterMap implements Map
+public abstract class ParameterMap extends TypedMap
{
- protected abstract Map getDelegate();
-
- protected void assertKey(Object value)
+ protected void assertKeyValidity(Object value)
{
if (!(value instanceof String))
{
@@ -45,7 +38,7 @@
}
}
- protected void assertValue(Object value)
+ protected Object getInternalValue(Object value)
{
if (!(value instanceof String[]))
{
@@ -63,218 +56,11 @@
throw new IllegalArgumentException("No null entries allowed in String[]");
}
}
+ return strings;
}
- public int size()
- {
- return getDelegate().size();
- }
-
- public void clear()
- {
- getDelegate().clear();
- }
-
- public boolean isEmpty()
- {
- return getDelegate().isEmpty();
- }
-
- public boolean containsKey(Object key)
- {
- return getDelegate().containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return getDelegate().containsValue(value);
- }
-
- public Collection values()
- {
- return getDelegate().values();
- }
-
- public void putAll(Map t)
- {
- for (Iterator i = t.entrySet().iterator(); i.hasNext();)
- {
- Entry entry = (Entry)i.next();
- assertKey(entry.getKey());
- assertValue(entry.getValue());
- }
- getDelegate().putAll(t);
- }
-
- public Set entrySet()
- {
- return new ParameterEntrySet(getDelegate().entrySet());
- }
-
- public Set keySet()
- {
- return getDelegate().keySet();
- }
-
- public Object get(Object key)
- {
- return getDelegate().get(key);
- }
-
- public Object remove(Object key)
- {
- return getDelegate().remove(key);
- }
-
- public Object put(Object key, Object value)
- {
- assertKey(key);
- assertValue(value);
- return getDelegate().put(key, value);
- }
-
- public class ParameterEntrySet implements Set
- {
-
- private Set delegate;
-
- public ParameterEntrySet(Set delegate)
- {
- this.delegate = delegate;
- }
-
- public int size()
- {
- return delegate.size();
- }
-
- public void clear()
- {
- delegate.clear();
- }
-
- public boolean isEmpty()
- {
- return delegate.isEmpty();
- }
-
- public Object[] toArray()
- {
- return delegate.toArray();
- }
-
- public boolean add(Object o)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean contains(Object o)
- {
- return delegate.contains(o);
- }
-
- public boolean remove(Object o)
- {
- return delegate.remove(o);
- }
-
- public boolean addAll(Collection c)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean containsAll(Collection c)
- {
- return delegate.containsAll(c);
- }
-
- public boolean removeAll(Collection c)
- {
- return delegate.removeAll(c);
- }
-
- public boolean retainAll(Collection c)
- {
- return delegate.retainAll(c);
- }
-
- public Iterator iterator()
- {
- return new ParameterEntryIterator(delegate.iterator());
- }
-
- public Object[] toArray(Object a[])
- {
- return delegate.toArray(a);
- }
- }
-
- public class ParameterEntryIterator implements Iterator
- {
-
- private Iterator delegate;
-
- public ParameterEntryIterator(Iterator delegate)
- {
- this.delegate = delegate;
- }
-
- public void remove()
- {
- delegate.remove();
- }
-
- public boolean hasNext()
- {
- return delegate.hasNext();
- }
-
- public Object next()
- {
- Entry entry = (Entry)delegate.next();
- return new ParameterEntry(entry);
- }
- }
-
- public class ParameterEntry implements Entry
- {
-
- private Entry delegate;
-
- public ParameterEntry(Entry delegate)
- {
- this.delegate = delegate;
- }
-
- public int hashCode()
+ protected Object getExternalValue(Object value)
{
- return delegate.hashCode();
- }
-
- public boolean equals(Object obj)
- {
- return delegate.equals(obj);
- }
-
- public String toString()
- {
- return delegate.toString();
- }
-
- public Object getKey()
- {
- return delegate.getKey();
- }
-
- public Object getValue()
- {
- return delegate.getValue();
- }
-
- public Object setValue(Object value)
- {
- assertValue(value);
- return delegate.setValue(value);
- }
+ return value;
}
}
1.1 date: 2006/08/22 14:08:51; author: julien; state: Exp;jboss-portal/common/src/main/org/jboss/portal/common/util/TypedMap.java
Index: TypedMap.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.common.util;
import java.util.Map;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.HashMap;
/**
* A decorator that enforce the map content to be checked against a type.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public abstract class TypedMap implements Map
{
protected abstract Map getDelegate();
/**
* Throw an IllegalArgumentException if the key is not valid.
*/
protected abstract void assertKeyValidity(Object key) throws IllegalArgumentException;
/**
* Unwrap the value to the the internal value.
*
* @param value the value to unwrap
* @return the unwrapped value
* @throws IllegalArgumentException if the type is not correct.
*/
protected abstract Object getInternalValue(Object value) throws IllegalArgumentException;
/**
* Wrap the internal value to its external representation.
*/
protected abstract Object getExternalValue(Object value);
public int size()
{
return getDelegate().size();
}
public void clear()
{
getDelegate().clear();
}
public boolean isEmpty()
{
return getDelegate().isEmpty();
}
public boolean containsKey(Object key)
{
assertKeyValidity(key);
return getDelegate().containsKey(key);
}
public boolean containsValue(Object value)
{
value = getInternalValue(value);
return getDelegate().containsValue(value);
}
public Collection values()
{
throw new UnsupportedOperationException("NYI");
}
public void putAll(Map t)
{
Map tmp = new HashMap(t);
for (Iterator i = tmp.entrySet().iterator(); i.hasNext();)
{
Entry entry = (Entry)i.next();
assertKeyValidity(entry.getKey());
Object value = getInternalValue(entry.getValue());
entry.setValue(value);
}
getDelegate().putAll(tmp);
}
public Set entrySet()
{
return new TypedMap.TypedEntrySet(getDelegate().entrySet());
}
public Set keySet()
{
return getDelegate().keySet();
}
public Object get(Object key)
{
Object value = getDelegate().get(key);
return getExternalValue(value);
}
public Object remove(Object key)
{
assertKeyValidity(key);
Object value = getDelegate().remove(key);
value = getExternalValue(value);
return value;
}
public Object put(Object key, Object value)
{
assertKeyValidity(key);
value = getInternalValue(value);
value = getDelegate().put(key, value);
value = getExternalValue(value);
return value;
}
public class TypedEntrySet implements Set
{
/** . */
private final Set delegate;
public TypedEntrySet(Set delegate)
{
this.delegate = delegate;
}
public int size()
{
return delegate.size();
}
public void clear()
{
delegate.clear();
}
public boolean isEmpty()
{
return delegate.isEmpty();
}
public Object[] toArray()
{
throw new UnsupportedOperationException();
}
public boolean add(Object o)
{
throw new UnsupportedOperationException();
}
public boolean contains(Object o)
{
throw new UnsupportedOperationException();
}
public boolean remove(Object o)
{
throw new UnsupportedOperationException();
}
public boolean addAll(Collection c)
{
throw new UnsupportedOperationException();
}
public boolean containsAll(Collection c)
{
throw new UnsupportedOperationException();
}
public boolean removeAll(Collection c)
{
throw new UnsupportedOperationException();
}
public boolean retainAll(Collection c)
{
throw new UnsupportedOperationException();
}
public Iterator iterator()
{
return new TypedMap.TypedEntryIterator(delegate.iterator());
}
public Object[] toArray(Object a[])
{
throw new UnsupportedOperationException();
}
}
public class TypedEntryIterator implements Iterator
{
/** . */
private final Iterator delegate;
public TypedEntryIterator(Iterator delegate)
{
this.delegate = delegate;
}
public void remove()
{
delegate.remove();
}
public boolean hasNext()
{
return delegate.hasNext();
}
public Object next()
{
Entry entry = (Entry)delegate.next();
return new TypedMap.TypedEntry(entry);
}
}
public class TypedEntry implements Entry
{
/** . */
private final Entry delegate;
public TypedEntry(Entry delegate)
{
this.delegate = delegate;
}
public int hashCode()
{
return delegate.hashCode();
}
public boolean equals(Object obj)
{
return delegate.equals(obj);
}
public String toString()
{
return delegate.toString();
}
public Object getKey()
{
return delegate.getKey();
}
public Object getValue()
{
Object value = delegate.getValue();
value = getExternalValue(value);
return value;
}
public Object setValue(Object value)
{
value = getInternalValue(value);
return delegate.setValue(value);
}
}
}
More information about the jboss-cvs-commits
mailing list