/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.sling.event;

import java.io.Serializable;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.iterators.IteratorEnumeration;
import org.osgi.service.event.Event;

/**
 * An implementation of a map that helps in dealing with properties
 * of an OSGi event.
 * This map implements both, the map and the dictionary interfaces.
 */
public class EventPropertiesMap
    extends Dictionary<String, Object>
    implements Map<String, Object>, Serializable {

    private final Map<String, Object> delegatee;

    /**
     * Construct a new map out of an event object.
     * The resulting map is modifiable. But any modification has
     * no influence on the original properties of the event!
     * @param event The event object.
     */
    public EventPropertiesMap(final Event event) {
        // create a map out of the event properties
        final Map<String, Object> props = new HashMap<String, Object>();
        if ( event.getPropertyNames() != null ) {
            for(final String key : event.getPropertyNames() ) {
                props.put(key, event.getProperty(key));
            }
        }
        this.delegatee = props;
    }

    /**
     * Construct a new map out of another map.
     * @param props The properties map object.
     */
    public EventPropertiesMap(final Map<String, Object> props) {
        this.delegatee = props;
    }

    /**
     * Construct a new map.
     */
    public EventPropertiesMap() {
        this.delegatee = new HashMap<String, Object>();
    }

    /**
     * @see java.util.Map#clear()
     */
    public void clear() {
        delegatee.clear();
    }

    /**
     * @see java.util.Map#containsKey(java.lang.Object)
     */
    public boolean containsKey(Object key) {
        return delegatee.containsKey(key);
    }

    /**
     * @see java.util.Map#containsValue(java.lang.Object)
     */
    public boolean containsValue(Object value) {
        return delegatee.containsValue(value);
    }

    /**
     * @see java.util.Map#entrySet()
     */
    public Set<java.util.Map.Entry<String, Object>> entrySet() {
        return delegatee.entrySet();
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object o) {
        return delegatee.equals(o);
    }

    /**
     * @see java.util.Dictionary#get(java.lang.Object)
     */
    public Object get(Object key) {
        return delegatee.get(key);
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return delegatee.hashCode();
    }

    /**
     * @see java.util.Dictionary#isEmpty()
     */
    public boolean isEmpty() {
        return delegatee.isEmpty();
    }

    /**
     * @see java.util.Map#keySet()
     */
    public Set<String> keySet() {
        return delegatee.keySet();
    }

    /**
     * @see java.util.Dictionary#put(java.lang.Object, java.lang.Object)
     */
    public Object put(String key, Object value) {
        return delegatee.put(key, value);
    }

    /**
     * @see java.util.Map#putAll(java.util.Map)
     */
    public void putAll(Map<? extends String, ? extends Object> t) {
        delegatee.putAll(t);
    }

    /**
     * @see java.util.Dictionary#remove(java.lang.Object)
     */
    public Object remove(Object key) {
        return delegatee.remove(key);
    }

    /**
     * @see java.util.Dictionary#size()
     */
    public int size() {
        return delegatee.size();
    }

    /**
     * @see java.util.Map#values()
     */
    public Collection<Object> values() {
        return delegatee.values();
    }

    /**
     * @see java.util.Dictionary#elements()
     */
    @SuppressWarnings("unchecked")
    public Enumeration<Object> elements() {
        return new IteratorEnumeration(this.values().iterator());
    }

    /**
     * @see java.util.Dictionary#keys()
     */
    @SuppressWarnings("unchecked")
    public Enumeration<String> keys() {
        return new IteratorEnumeration(this.keySet().iterator());
    }

    /**
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return this.delegatee.toString();
    }
}

@@ -888,24 +888,54 @@
 Collection;%0A
+import java.util.Collections;%0A
 import java.
@@ -1056,77 +1056,8 @@
 t;%0A%0A
-import org.apache.commons.collections.iterators.IteratorEnumeration;%0A
 impo
@@ -4559,43 +4559,8 @@
  */%0A
-    @SuppressWarnings(%22unchecked%22)%0A
     
@@ -4610,37 +4610,37 @@
      return 
-new IteratorE
+Collections.e
 numeration(t
@@ -4651,27 +4651,16 @@
 values()
-.iterator()
 );%0A    %7D
@@ -4721,43 +4721,8 @@
  */%0A
-    @SuppressWarnings(%22unchecked%22)%0A
     
@@ -4776,21 +4776,21 @@
 urn 
-new IteratorE
+Collections.e
 nume
@@ -4813,19 +4813,8 @@
 et()
-.iterator()
 );%0A 

Use Java Runtime Collections class to get an Enumeration over a collection instead of Commons Collections.