Example usage for java.util Dictionary get

List of usage examples for java.util Dictionary get

Introduction

In this page you can find the example usage for java.util Dictionary get.

Prototype

public abstract V get(Object key);

Source Link

Document

Returns the value to which the key is mapped in this dictionary.

Usage

From source file:org.openhab.binding.insteonhub.internal.InsteonHubProxyFactory.java

public static Map<String, InsteonHubProxy> createInstances(Dictionary<String, ?> config) {
    Map<String, InsteonHubProxy> proxies = new HashMap<String, InsteonHubProxy>();
    // parse all configured receivers
    // ( insteonhub:<hubid>.host=10.0.0.2 )
    Enumeration<String> keys = config.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (key.endsWith(CONFIG_KEY_HOST)) {
            // parse host
            String host = (String) config.get(key);
            int separatorIdx = key.indexOf('.');
            String hubId, keyPrefix;
            if (separatorIdx == -1) {
                // no prefix/hubid => one hub => use default hub ID
                hubId = InsteonHubBinding.DEFAULT_HUB_ID;
                keyPrefix = "";
            } else {
                // prefix => use it as the hub ID
                hubId = key.substring(0, separatorIdx);
                keyPrefix = hubId + ".";
            }/*w w w. j  a  v a 2  s .c o  m*/
            String portStr = (String) config.get(keyPrefix + CONFIG_KEY_PORT);
            int port = StringUtils.isBlank(portStr) ? InsteonHubSerialProxy.DEFAULT_PORT
                    : Integer.parseInt(config.get(keyPrefix + CONFIG_KEY_PORT).toString());
            // Create proxy, and add it to map
            InsteonHubProxy proxy = new InsteonHubSerialProxy(host, port);
            proxies.put(hubId, proxy);
        }
    }
    return proxies;
}

From source file:org.eclipse.gemini.blueprint.util.DebugUtils.java

/**
 * Get the version of a package import from a bundle.
 * //  w  w  w.j ava2  s .  c o  m
 * @param bundle
 * @param packageName
 * @return
 */
private static Version hasImport(Bundle bundle, String packageName) {
    Dictionary dict = bundle.getHeaders();
    // Check imports
    String imports = (String) dict.get(Constants.IMPORT_PACKAGE);
    Version v = getVersion(imports, packageName);
    if (v != null) {
        return v;
    }
    // Check for dynamic imports
    String dynimports = (String) dict.get(Constants.DYNAMICIMPORT_PACKAGE);
    if (dynimports != null) {
        for (StringTokenizer strok = new StringTokenizer(dynimports, COMMA); strok.hasMoreTokens();) {
            StringTokenizer parts = new StringTokenizer(strok.nextToken(), SEMI_COLON);
            String pkg = parts.nextToken().trim();
            if (pkg.endsWith(".*") && packageName.startsWith(pkg.substring(0, pkg.length() - 2))
                    || pkg.equals("*")) {
                Version version = Version.emptyVersion;
                for (; parts.hasMoreTokens();) {
                    String modifier = parts.nextToken().trim();
                    if (modifier.startsWith("version")) {
                        version = Version.parseVersion(modifier.substring(modifier.indexOf(EQUALS) + 1).trim());
                    }
                }
                return version;
            }
        }
    }
    return null;
}

From source file:org.openengsb.itests.util.AbstractExamTestHelper.java

@SuppressWarnings("rawtypes")
private static String explode(Dictionary dictionary) {
    Enumeration keys = dictionary.keys();
    StringBuffer result = new StringBuffer();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        result.append(String.format("%s=%s", key, dictionary.get(key)));
        if (keys.hasMoreElements()) {
            result.append(", ");
        }//from  w ww  . j  a v  a2s  .c om
    }
    return result.toString();
}

From source file:org.opentaps.notes.repository.impl.NoteRepositoryImpl.java

private static BasicDBObject noteToDbObject(Note note) {
    if (note == null) {
        return null;
    }/*from ww w  .  jav a  2  s.  co m*/
    BasicDBObject noteDoc = (BasicDBObject) BasicDBObjectBuilder.start()
            .add(Note.Fields.noteId.getName(), note.getNoteId())
            .add(Note.Fields.noteText.getName(), note.getNoteText())
            .add(Note.Fields.clientDomain.getName(), note.getClientDomain()).get();

    User user = note.getCreatedByUser();
    if (user != null) {
        BasicDBObject userDoc = (BasicDBObject) BasicDBObjectBuilder.start().get();
        @SuppressWarnings("unchecked")
        Dictionary<String, Object> props = user.getProperties();
        if (props != null && !props.isEmpty()) {
            Enumeration<String> keys = props.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                userDoc.append(key, props.get(key));
            }
        }
        noteDoc.append(Note.Fields.createdByUser.getName(), userDoc);
    }

    // look for custom fields
    for (String field : note.getAttributeNames()) {
        noteDoc.put(field, note.getAttribute(field));
    }

    return noteDoc;
}

From source file:Main.java

/**
 * Return a Dictionary object which is a subset of the given Dictionary,
 * where the tags all <b>begin</b> with the given tag.
 * //w ww .j a  v  a  2  s .  co m
 * Hastables and Properties can be used as they are Dictionaries.
 * 
 * @param superset
 *            .
 * 
 * 
 * @param tag
 *            String
 * @param result
 *            Dictionary<String,Object>
 */
public static void getSubset(Dictionary<String, Object> superset, String tag,
        Dictionary<String, Object> result) {
    if ((result == null) || (tag == null) || (superset == null)) {
        throw new IllegalArgumentException("Invalid arguments specified : superset = " + superset + " tag = "
                + tag + " result = " + result);
    }

    String key;
    Enumeration<String> enumKey = superset.keys();

    while (enumKey.hasMoreElements()) {
        key = enumKey.nextElement();

        if (key.startsWith(tag)) {
            result.put(key, superset.get(key));
        }
    }
}

From source file:com.basistech.yca.JsonNodeFlattener.java

public static JsonNode unflatten(Dictionary<String, ?> config) {
    Enumeration<String> keyEnum = config.keys();
    List<String> keys = new ArrayList<>();
    while (keyEnum.hasMoreElements()) {
        keys.add(keyEnum.nextElement());
    }//from w w  w  . jav a2  s .  co  m
    Collections.sort(keys);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    for (String key : keys) {
        Object value = config.get(key);
        addNode(root, key, value);
    }

    return root;
}

From source file:org.opencastproject.ingest.scanner.InboxScannerService.java

public static Map<String, String> getCfgAsMap(Dictionary<String, String> d, String key)
        throws ConfigurationException {
    HashMap<String, String> config = new HashMap<String, String>();
    for (Enumeration<String> e = d.keys(); e.hasMoreElements();) {
        String dKey = (String) e.nextElement();
        if (dKey.startsWith(key))
            config.put(dKey.substring(key.length() + 1), (String) d.get(dKey));
    }/* w w w.j  ava2 s  .  c o m*/
    return config;
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

public static void addPriceSeries(List trades, Dictionary<String, TimePeriodValues> positions,
        Dictionary originalValue) {
    for (Iterator iterator = trades.iterator(); iterator.hasNext();) {
        MakerTrade trade = (MakerTrade) iterator.next();
        TimePeriodValues values = positions.get(trade.getPos().getName());
        if (values == null) {
            continue;
        }//from   www. j  av a2s .  com
        if (originalValue.get(trade.getPos()) == null) {
            if (!trade.openValue().equals(trade.closeValue())) { // TODO This is only a transient, since opening prices weren't stored originally
                values.add(trade.openValue());
            }
            originalValue.put(trade.getPos(), trade);
        }
        values.add(trade.closeValue());
    }
}

From source file:org.apache.cxf.dosgi.dsw.OsgiUtils.java

@SuppressWarnings("unchecked")
public static List<Element> getAllDescriptionElements(Bundle b) {
    Object directory = null;//from w w  w. jav a2s  . co  m

    Dictionary headers = b.getHeaders();
    if (headers != null) {
        directory = headers.get(REMOTE_SERVICES_HEADER_NAME);
    }

    if (directory == null) {
        directory = REMOTE_SERVICES_DIRECTORY;
    }

    Enumeration urls = b.findEntries(directory.toString(), "*.xml", false);
    if (urls == null) {
        return Collections.emptyList();
    }

    List<Element> elements = new ArrayList<Element>();
    while (urls.hasMoreElements()) {
        URL resourceURL = (URL) urls.nextElement();
        try {
            Document d = new SAXBuilder().build(resourceURL.openStream());
            Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
            elements.addAll(d.getRootElement().getChildren(SERVICE_DESCRIPTION_ELEMENT, ns));
        } catch (Exception ex) {
            LOG.log(Level.WARNING, "Problem parsing: " + resourceURL, ex);
        }
    }
    return elements;
}

From source file:org.jtheque.modules.impl.ModuleLoader.java

/**
 * Read the manifest informations of the given module.
 *
 * @param container The module./*from ww w .j  a  v a2  s. c  om*/
 * @param bundle    The bundle.
 */
private static void readManifestInformations(Builder container, Bundle bundle) {
    @SuppressWarnings("unchecked") //We know that the bundle headers are a String<->String Map
    Dictionary<String, String> headers = bundle.getHeaders();

    container.setId(headers.get("Bundle-SymbolicName"));
    container.setVersion(Version.get(headers.get("Bundle-Version")));

    if (StringUtils.isNotEmpty(headers.get("Module-Core"))) {
        container.setCoreVersion(Version.get(headers.get("Module-Core")));
    } else {
        container.setCoreVersion(Core.VERSION);
    }

    container.setUrl(headers.get("Module-Url"));
    container.setUpdateUrl(headers.get("Module-UpdateUrl"));
    container.setMessagesUrl(headers.get("Module-MessagesUrl"));

    if (StringUtils.isNotEmpty(headers.get("Module-Collection"))) {
        container.setCollection(Boolean.parseBoolean(headers.get("Module-Collection")));
    }

    if (StringUtils.isNotEmpty(headers.get("Module-Dependencies"))) {
        container.setDependencies(COMMA_DELIMITER_PATTERN.split(headers.get("Module-Dependencies")));
    } else {
        container.setDependencies(EMPTY_ARRAY);
    }
}