Example usage for java.util Collections list

List of usage examples for java.util Collections list

Introduction

In this page you can find the example usage for java.util Collections list.

Prototype

public static <T> ArrayList<T> list(Enumeration<T> e) 

Source Link

Document

Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.

Usage

From source file:org.pentaho.osgi.i18n.webservice.ResourceBundleMessageBodyWriter.java

@Override
public void writeTo(ResourceBundle resourceBundle, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {
    if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
        JSONObject resourceBundleJsonObject = new JSONObject();
        for (String key : Collections.list(resourceBundle.getKeys())) {
            resourceBundleJsonObject.put(key, resourceBundle.getString(key));
        }/* w ww. j  a  va2  s .c  o m*/
        OutputStreamWriter outputStreamWriter = null;
        try {
            outputStreamWriter = new OutputStreamWriter(entityStream);
            resourceBundleJsonObject.writeJSONString(outputStreamWriter);
        } finally {
            if (outputStreamWriter != null) {
                outputStreamWriter.flush();
            }
        }
    } else if (MediaType.APPLICATION_XML_TYPE.equals(mediaType)) {
        try {
            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            Node propertiesNode = document.createElement("properties");
            document.appendChild(propertiesNode);
            for (String key : Collections.list(resourceBundle.getKeys())) {
                Node propertyNode = document.createElement("property");
                propertiesNode.appendChild(propertyNode);

                Node keyNode = document.createElement("key");
                keyNode.setTextContent(key);
                propertyNode.appendChild(keyNode);

                Node valueNode = document.createElement("value");
                valueNode.setTextContent(resourceBundle.getString(key));
                propertyNode.appendChild(valueNode);
            }
            Result output = new StreamResult(entityStream);
            Source input = new DOMSource(document);
            try {
                Transformer transformer = TransformerFactory.newInstance().newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                transformer.transform(input, output);
            } catch (TransformerException e) {
                throw new IOException(e);
            }
        } catch (ParserConfigurationException e) {
            throw new WebApplicationException(e);
        }
    }
}

From source file:org.docear.plugin.core.listeners.WorkspaceChangeListener.java

private void setSystemNodes() {
    try {/*  ww  w .j  a  v a  2  s  .co m*/
        File libPath = WorkspaceUtils.resolveURI(DocearController.getController().getLibraryPath());
        URI _tempFile = Compat.fileToUrl(new File(libPath, "temp.mm")).toURI();
        URI _trashFile = Compat.fileToUrl(new File(libPath, "trash.mm")).toURI();

        AWorkspaceTreeNode parent = WorkspaceUtils
                .getNodeForPath(((WorkspaceRoot) WorkspaceUtils.getModel().getRoot()).getName() + "/Library");
        for (AWorkspaceTreeNode node : Collections.list(parent.children())) {
            if (node.getType().equals(LinkTypeIncomingCreator.LINK_TYPE_INCOMING)
                    || node.getType()
                            .equals(LinkTypeLiteratureAnnotationsCreator.LINK_TYPE_LITERATUREANNOTATIONS)
                    || node.getType().equals(LinkTypeMyPublicationsCreator.LINK_TYPE_MYPUBLICATIONS)) {
                node.setSystem(true);
            }
            if (node.getType().equals(ALinkNode.LINK_TYPE_FILE)) {
                URI linkPath = WorkspaceUtils.absoluteURI(((ALinkNode) node).getLinkPath());
                if (linkPath.equals(_trashFile) || linkPath.equals(_tempFile)) {
                    node.setSystem(true);
                }
            }
        }
    } catch (MalformedURLException e) {
        LogUtils.warn(e);
    } catch (URISyntaxException e) {
        LogUtils.warn(e);
    }
}

From source file:org.jasig.portlet.test.mvc.tests.GetExpectedUserAttributesTest.java

@RenderMapping
public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response)
        throws Exception {
    final List<String> attributesNames = Collections.list(request.getAttributeNames());
    final Map<String, String> userInfo = (Map<String, String>) request.getAttribute(PortletRequest.USER_INFO);
    final Map<String, List<Object>> multivaluedUserInfo = (Map<String, List<Object>>) request
            .getAttribute(USER_INFO_MULTIVALUED);

    final Map<String, String> model = new LinkedHashMap<String, String>();
    model.put("ACTION_AttributeNames", request.getParameter("AttributeNames"));
    model.put("ACTION_USER_INFO", request.getParameter(PortletRequest.USER_INFO));
    model.put("ACTION_USER_INFO_MULTIVALUED", request.getParameter(USER_INFO_MULTIVALUED));

    model.put("RENDER_AttributeNames", String.valueOf(attributesNames));
    model.put("RENDER_USER_INFO", String.valueOf(userInfo));
    model.put("RENDER_USER_INFO_MULTIVALUED", String.valueOf(multivaluedUserInfo));

    return new ModelAndView("getExpectedUserAttributesTest", model);
}

From source file:org.vosao.i18n.Messages.java

/**
 * Generate JavaScript JSON message bundle for JavaScript messages 
 * localization./*  ww w  . j a  v a2  s.c o m*/
 * @return JS file.
 */
public static String getJSMessages() {
    VosaoContext ctx = VosaoContext.getInstance();
    String cached = (String) getBusiness().getSystemService().getCache()
            .get(I18N_CACHE_KEY + ctx.getLanguage());

    logger.debug("checking is i18n_" + ctx.getLanguage() + " in cache: " + (cached != null ? "yes" : "no"));

    if (cached != null)
        return cached;
    Map<String, String> messages = new HashMap<String, String>();
    VosaoResourceBundle defaultBundle = getDefaultBundle();
    for (String key : Collections.list(defaultBundle.getKeys())) {
        try {
            messages.put(key, defaultBundle.getString(key));
        } catch (MissingResourceException e) {
        }
    }
    VosaoResourceBundle bundle = getBundle(ctx.getRequest());
    for (String key : Collections.list(bundle.getKeys())) {
        try {
            messages.put(key, bundle.getString(key));
        } catch (MissingResourceException e) {
        }
    }
    ConfigEntity config = VosaoContext.getInstance().getConfig();
    StringBuffer result = new StringBuffer();
    result.append("var locale = '").append(ctx.getLocale().toString()).append("';\n");
    result.append("var locale_language = '").append(ctx.getLocale().getLanguage()).append("';\n");
    result.append("var default_language = '").append(getBusiness().getDefaultLanguage()).append("';\n");
    result.append("function messages(key) {\n" + "  if (_messages[key] == 'undefined') {\n"
            + "    return '__' + key + '__';\n" + "  } else {\n" + "    return _messages[key];\n" + "  }\n"
            + "}\n");
    result.append("var _messages = {\n");
    int i = 0;
    for (String key : messages.keySet()) {
        if (i++ > 0) {
            result.append(",");
        }
        result.append(" '").append(key).append("' : '").append(filterForJS(messages.get(key))).append("'\n");
    }
    result.append("};");

    cached = result.toString();
    getBusiness().getSystemService().getCache().put(I18N_CACHE_KEY + ctx.getLanguage(), cached);

    logger.debug("put i18n_" + ctx.getLanguage() + " to cache");

    return cached;
}

From source file:org.commonjava.aprox.util.AcceptInfoParser.java

public List<AcceptInfo> parse(final Enumeration<String> accepts) {
    return parse(Collections.list(accepts));
}

From source file:com.steeleforge.aem.ironsites.i18n.I18nResourceBundle.java

@SuppressWarnings("unchecked")
public <AdapterType> AdapterType adaptTo(Class<AdapterType> clazz) {
    if (clazz == ValueMap.class) {
        ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>());
        for (String key : Collections.list(getKeys())) {
            vm.put(key, getString(key));
        }/* w ww . j  a  va  2  s.  c om*/
        return (AdapterType) vm;
    }
    return null;
}

From source file:newcontroller.handler.impl.DefaultRequest.java

@Override
public Map<String, ?> model() {
    return Collections.list(this.request.getAttributeNames()).stream()
            .collect(Collectors.toMap(Function.identity(), this.request::getAttribute));
}

From source file:com.jonbanjo.cupsprint.CertificateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_certificate);
    host = (EditText) findViewById(R.id.cert_host_edit);
    port = (EditText) findViewById(R.id.cert_port_edit);
    certList = (ListView) findViewById(R.id.cert_list);
    importButton = (Button) findViewById(R.id.cert_import);

    Intent intent = getIntent();// w ww.j  a  va 2 s . com
    String ip = intent.getStringExtra("host");
    if (ip != null) {
        host.setText(ip);
    }
    String pt = intent.getStringExtra("port");
    if (pt != null) {
        port.setText(pt);
    }

    trustStore = loadTrustStore();
    if (trustStore == null) {
        return;
    }

    ArrayList<String> certArray;
    try {
        certArray = Collections.list(trustStore.aliases());
    } catch (Exception e) {
        return;
    }

    certListAdaptor = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, certArray);
    certList.setAdapter(certListAdaptor);
    certList.setClickable(true);
    certList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            displayCert(certListAdaptor.getItem(position));

        }
    });

}

From source file:com.android.builder.testing.MockableJarGenerator.java

public void createMockableJar(File input, File output) throws IOException {
    Preconditions.checkState(output.createNewFile(), "Output file [%s] already exists.",
            output.getAbsolutePath());/*from   w  w w  . ja  va 2s.com*/

    JarFile androidJar = null;
    JarOutputStream outputStream = null;
    try {
        androidJar = new JarFile(input);
        outputStream = new JarOutputStream(new FileOutputStream(output));

        for (JarEntry entry : Collections.list(androidJar.entries())) {
            InputStream inputStream = androidJar.getInputStream(entry);

            if (entry.getName().endsWith(".class")) {
                if (!skipClass(entry.getName().replace("/", "."))) {
                    rewriteClass(entry, inputStream, outputStream);
                }
            } else {
                outputStream.putNextEntry(entry);
                ByteStreams.copy(inputStream, outputStream);
            }

            inputStream.close();
        }
    } finally {
        if (androidJar != null) {
            androidJar.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
    }
}

From source file:org.openhab.binding.russound.internal.discovery.RioSystemDiscovery.java

/**
 * Starts the scan. For each network interface (that is up and not a loopback), all addresses will be iterated
 * and checked for something open on port 9621. If that port is open, a russound controller "type" command will be
 * issued. If the response is a correct pattern, we assume it's a rio system device and will emit a
 * {{@link #thingDiscovered(DiscoveryResult)}
 */// w ww .ja va 2  s  . com
@Override
protected void startScan() {
    final List<NetworkInterface> interfaces;
    try {
        interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
    } catch (SocketException e1) {
        logger.debug("Exception getting network interfaces: {}", e1.getMessage(), e1);
        return;
    }

    nbrNetworkInterfacesScanning = interfaces.size();
    executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 10);

    for (final NetworkInterface networkInterface : interfaces) {
        try {
            if (networkInterface.isLoopback() || !networkInterface.isUp()) {
                continue;
            }
        } catch (SocketException e) {
            continue;
        }

        for (Iterator<InterfaceAddress> it = networkInterface.getInterfaceAddresses().iterator(); it
                .hasNext();) {
            final InterfaceAddress interfaceAddress = it.next();

            // don't bother with ipv6 addresses (russound doesn't support)
            if (interfaceAddress.getAddress() instanceof Inet6Address) {
                continue;
            }

            final String subnetRange = interfaceAddress.getAddress().getHostAddress() + "/"
                    + interfaceAddress.getNetworkPrefixLength();

            logger.debug("Scanning subnet: {}", subnetRange);
            final SubnetUtils utils = new SubnetUtils(subnetRange);

            final String[] addresses = utils.getInfo().getAllAddresses();

            for (final String address : addresses) {
                executorService.execute(new Runnable() {
                    @Override
                    public void run() {
                        scanAddress(address);
                    }
                });
            }
        }
    }

    // Finishes the scan and cleans up
    stopScan();
}