Example usage for java.util Map map

List of usage examples for java.util Map map

Introduction

In this page you can find the example usage for java.util Map map.

Prototype

map

Source Link

Usage

From source file:edu.umd.cs.marmoset.utilities.MarmosetUtilities.java

public static <T> Map<T, Boolean> setAsMap(final Set<T> set) {
    return new Map<T, Boolean>() {

        @Override/*from ww  w  .  j  a  va  2 s . co m*/
        public void clear() {
            set.clear();

        }

        @Override
        public boolean containsKey(Object arg0) {
            return set.contains(arg0);
        }

        @Override
        public boolean containsValue(Object arg0) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<java.util.Map.Entry<T, Boolean>> entrySet() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Boolean get(Object arg0) {
            return set.contains(arg0);
        }

        @Override
        public boolean isEmpty() {
            return set.isEmpty();
        }

        @Override
        public Set<T> keySet() {
            return set;
        }

        @Override
        public Boolean put(T arg0, Boolean arg1) {
            Boolean result = set.contains(arg0);
            if (arg1)
                set.add(arg0);
            else
                set.remove(arg0);
            return result;
        }

        @Override
        public void putAll(Map<? extends T, ? extends Boolean> arg0) {
            throw new UnsupportedOperationException();

        }

        @Override
        public Boolean remove(Object arg0) {
            Boolean result = set.contains(arg0);
            set.remove(arg0);
            return result;
        }

        @Override
        public int size() {
            return set.size();
        }

        @Override
        public Collection<Boolean> values() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:carstore.CarBean.java

/**
 * <p>Initialize our components <code>Map</code> as described in the
 * class documentation.</p>/*from   w w  w . j  ava  2  s  .  c o m*/
 *
 * <p>Create a wrapper <code>Map</code> around the components
 * <code>Map</code> that exposes the String converted value of each
 * component.</p>
 */

private void init(String bundleName) {
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle data = null;
    Enumeration keys = null;
    components = new HashMap();

    // load the labels
    resources = ResourceBundle.getBundle(CarStore.CARSTORE_PREFIX + ".bundles.Resources",
            context.getViewRoot().getLocale());

    // load the prices
    priceData = ResourceBundle.getBundle(CarStore.CARSTORE_PREFIX + ".bundles.OptionPrices");

    // populate the locale-specific information
    if (log.isDebugEnabled()) {
        log.debug("Loading bundle: " + bundleName + ".");
    }
    data = ResourceBundle.getBundle(bundleName, context.getViewRoot().getLocale());
    if (log.isDebugEnabled()) {
        log.debug("Bundle " + bundleName + " loaded. Reading properties...");
    }
    initComponentsFromProperties(context, data);
    if (log.isDebugEnabled()) {
        log.debug("done.");
    }

    // populate the non-locale-specific information common to all cars
    if (log.isDebugEnabled()) {
        log.debug("Loading bundle: Common_options.");
    }
    data = ResourceBundle.getBundle(CarStore.CARSTORE_PREFIX + ".bundles.Common_options");
    if (log.isDebugEnabled()) {
        log.debug("Bundle Common_options loaded. Reading properties...");
    }
    initComponentsFromProperties(context, data);
    if (log.isDebugEnabled()) {
        log.debug("done.");
    }

    // populate the non-locale-specific information specific to each car
    if (log.isDebugEnabled()) {
        log.debug("Loading bundle: " + bundleName + "_options.");
    }
    data = ResourceBundle.getBundle(bundleName + "_options");
    if (log.isDebugEnabled()) {
        log.debug("Bundle " + bundleName + "_options loaded. Reading properties...");
    }
    initComponentsFromProperties(context, data);
    if (log.isDebugEnabled()) {
        log.debug("done.");
    }

    // create a read-only Map exposing the values of all of our
    // components.
    attributes = new Map() {
        public void clear() {
            CarBean.this.components.clear();
        }

        public boolean containsKey(Object key) {
            return CarBean.this.components.containsKey(key);
        }

        public boolean containsValue(Object value) {
            throw new UnsupportedOperationException();
        }

        public java.util.Set entrySet() {
            throw new UnsupportedOperationException();
        }

        public boolean equals(Object o) {
            throw new UnsupportedOperationException();
        }

        public Object get(Object key) {
            UIComponent component = null;
            Converter converter = null;
            Object result = null;
            if (null == key) {
                return null;
            }
            if (null != (component = (UIComponent) CarBean.this.components.get(key))) {
                // if this component can have a Converter
                if (component instanceof ValueHolder) {
                    // try to get it
                    converter = ((ValueHolder) component).getConverter();
                    result = ((ValueHolder) component).getValue();
                }

                // if we do have a value
                if (null != result) {
                    // and we do have a converter
                    if (null != converter) {
                        // convert the value to String
                        result = converter.getAsString(FacesContext.getCurrentInstance(), component, result);
                    }
                }
            }
            return result;
        }

        public int hashCode() {
            return CarBean.this.components.hashCode();
        }

        public boolean isEmpty() {
            return CarBean.this.components.isEmpty();
        }

        public java.util.Set keySet() {
            return CarBean.this.components.keySet();
        }

        public Object put(Object k, Object v) {
            throw new UnsupportedOperationException();
        }

        public void putAll(Map t) {
            throw new UnsupportedOperationException();
        }

        public Object remove(Object k) {
            throw new UnsupportedOperationException();
        }

        public int size() {
            return CarBean.this.components.size();
        }

        public java.util.Collection values() {
            ArrayList result = new ArrayList();
            Iterator keys = keySet().iterator();
            while (keys.hasNext()) {
                result.add(get(keys.next()));
            }
            return result;
        }
    };

}

From source file:org.onosproject.sse.SseTopologyViewMessages.java

protected Map<Link, Set<LambdaResource>> getAvaliableLambda() {
    Map<Link, Set<LambdaResource>> avaliableLambda = new Map<Link, Set<LambdaResource>>() {

        @Override/* www  . j a v  a2s .co  m*/
        public void clear() {
            // TODO Auto-generated method stub

        }

        @Override
        public boolean containsKey(Object arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean containsValue(Object arg0) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public Set<java.util.Map.Entry<Link, Set<LambdaResource>>> entrySet() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Set<LambdaResource> get(Object arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isEmpty() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public Set<Link> keySet() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public Set<LambdaResource> put(Link arg0, Set<LambdaResource> arg1) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void putAll(Map<? extends Link, ? extends Set<LambdaResource>> arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public Set<LambdaResource> remove(Object arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public int size() {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public Collection<Set<LambdaResource>> values() {
            // TODO Auto-generated method stub
            return null;
        }
    };

    Iterator<Link> activeLinks = linkService.getActiveLinks().iterator();
    while (activeLinks.hasNext()) {
        Link link = activeLinks.next();
        //         Set<Lambda> lambdas = linkResourceService.getAvailableLambdas(link);
        avaliableLambda.put(link, linkResourceService.getAvailableLambdas(link));
    }
    return avaliableLambda;
}

From source file:org.jivesoftware.openfire.clearspace.ClearspaceManager.java

/**
 * Constructs a new ClearspaceManager instance. Typically, {@link #getInstance()} should be
 * called instead of this method. ClearspaceManager instances should only be created directly
 * for testing purposes./*from  w w w .ja  v a2  s  .co  m*/
 */
public ClearspaceManager() {
    super("Clearspace integration module");
    // Create a special Map implementation to wrap XMLProperties. We only implement
    // the get, put, and remove operations, since those are the only ones used. Using a Map
    // makes it easier to perform LdapManager testing.
    this.properties = new Map<String, String>() {

        public String get(Object key) {
            return JiveGlobals.getProperty((String) key);
        }

        public String put(String key, String value) {
            JiveGlobals.setProperty(key, value);
            // Always return null since XMLProperties doesn't support the normal semantics.
            return null;
        }

        public String remove(Object key) {
            JiveGlobals.deleteProperty((String) key);
            // Always return null since XMLProperties doesn't support the normal semantics.
            return null;
        }

        public int size() {
            return 0;
        }

        public boolean isEmpty() {
            return false;
        }

        public boolean containsKey(Object key) {
            return false;
        }

        public boolean containsValue(Object value) {
            return false;
        }

        public void putAll(Map<? extends String, ? extends String> t) {
        }

        public void clear() {
        }

        public Set<String> keySet() {
            return null;
        }

        public Collection<String> values() {
            return null;
        }

        public Set<Entry<String, String>> entrySet() {
            return null;
        }
    };

    init();
    instance = this;
}