List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.eiichiro.bootleg.AbstractRequest.java
/** * Returns the Web endpoint method parameter from HTTP session. * //from w ww .j a v a2s .c o m * @param type The parameter type. * @param name The parameter name. * @return The Web endpoint method parameter from HTTP session. */ protected Object session(Type type, String name) { return parameter(type, name, new Function<String, Object>() { public Object apply(String name) { return context.session().getAttribute(name); } }, new Function<String, Collection<Object>>() { @SuppressWarnings("unchecked") public Collection<Object> apply(String name) { HttpSession session = context.session(); Object attribute = session.getAttribute(name); if (attribute instanceof Collection<?>) { return (Collection<Object>) attribute; } Map<String, Object> map = new TreeMap<String, Object>(); for (Object object : Collections.list(session.getAttributeNames())) { String key = (String) object; if (key.startsWith(name + "[")) { map.put(key, session.getAttribute(key)); } } return (map.isEmpty()) ? null : map.values(); } }); }
From source file:ca.simplegames.micro.utils.StringUtils.java
/** * Copy the given Enumeration into a String array. * The Enumeration must contain String elements only. * * @param enumeration the Enumeration to copy * @return the String array (<code>null</code> if the passed-in * Enumeration was <code>null</code>) *//*from w ww . j ava2 s. c o m*/ public static String[] toStringArray(Enumeration enumeration) { if (enumeration == null) { return null; } List list = Collections.list(enumeration); return (String[]) list.toArray(new String[list.size()]); }
From source file:org.sonar.classloader.ClassloaderBuilderTest.java
@Test public void getResources_multiple_versions_with_parent_first_strategy() throws Exception { Map<String, ClassLoader> newClassloaders = sut.newClassloader("the-parent") .addURL("the-parent", new File("tester/a.jar").toURL()) .newClassloader("the-child").addURL("the-child", new File("tester/a_v2.jar").toURL()) .setParent("the-child", "the-parent", Mask.ALL).build(); ClassLoader parent = newClassloaders.get("the-parent"); assertThat(Collections.list(parent.getResources("a.txt"))).hasSize(1); ClassLoader child = newClassloaders.get("the-child"); List<URL> childResources = Collections.list(child.getResources("a.txt")); assertThat(childResources).hasSize(2); assertThat(IOUtils.toString(childResources.get(0))).startsWith("version 1 of a.txt"); assertThat(IOUtils.toString(childResources.get(1))).startsWith("version 2 of a.txt"); }
From source file:jp.terasoluna.fw.batch.util.BatchUtil.java
/** * .properties???? ?????????? ?????//from w ww . ja va 2 s . c o m * @param propertyName .properties????.properties???? * @param grpKey * @return propertyName??grpKeyPrefix */ public static List<String> getProperties(String propertyName, String grpKey) { Properties properties = PropertyUtil.loadProperties(propertyName); Enumeration<String> propNames = PropertyUtil.getPropertyNames(properties, grpKey); List<String> propNamesList = Collections.list(propNames); Collections.sort(propNamesList); List<String> resultList = new ArrayList<String>(); for (String key : propNamesList) { resultList.add(PropertyUtil.getProperty(key)); } return resultList; }
From source file:net.sf.jabref.JabRef.java
private void setLookAndFeel() { try {/*from www . j a va2s .c o m*/ String lookFeel; String systemLnF = UIManager.getSystemLookAndFeelClassName(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) { // Use system Look & Feel by default lookFeel = systemLnF; } else { lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL); } // At all cost, avoid ending up with the Metal look and feel: if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(lookFeel)) { Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel(); Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer()); com.jgoodies.looks.Options.setPopupDropShadowEnabled(true); UIManager.setLookAndFeel(lnf); } else { try { UIManager.setLookAndFeel(lookFeel); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // specified look and feel does not exist on the classpath, so use system l&f UIManager.setLookAndFeel(systemLnF); // also set system l&f as default Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLnF); // notify the user JOptionPane.showMessageDialog(JabRef.jrf, Localization.lang( "Unable to find the requested Look & Feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); } } } catch (Exception e) { LOGGER.warn("Look and feel could not be set", e); } // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS); if (overrideDefaultFonts) { int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE); UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); Double zoomLevel = null; for (Object key : Collections.list(keys)) { if ((key instanceof String) && ((String) key).endsWith(".font")) { FontUIResource font = (FontUIResource) UIManager.get(key); if (zoomLevel == null) { // zoomLevel not yet set, calculate it based on the first found font zoomLevel = (double) fontSize / (double) font.getSize(); } font = new FontUIResource(font.getName(), font.getStyle(), fontSize); defaults.put(key, font); } } if (zoomLevel != null) { GUIGlobals.zoomLevel = zoomLevel; } } }
From source file:org.eiichiro.bootleg.AbstractRequest.java
/** * Returns the Web endpoint method parameter from Web application * ({@code ServletContext}).//from w w w . j a v a 2s . co m * * @param type The parameter type. * @param name The parameter name. * @return The Web endpoint method parameter from Web application * ({@code ServletContext}). */ protected Object application(Type type, String name) { return parameter(type, name, new Function<String, Object>() { public Object apply(String name) { return context.application().getAttribute(name); } }, new Function<String, Collection<Object>>() { @SuppressWarnings("unchecked") public Collection<Object> apply(String name) { ServletContext servletContext = context.application(); Object attribute = servletContext.getAttribute(name); if (attribute instanceof Collection<?>) { return (Collection<Object>) attribute; } Map<String, Object> map = new TreeMap<String, Object>(); for (Object object : Collections.list(servletContext.getAttributeNames())) { String key = (String) object; if (key.startsWith(name + "[")) { map.put(key, servletContext.getAttribute(key)); } } return (map.isEmpty()) ? null : map.values(); } }); }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java
private HikariConfig createDataSourceConfig(HikariPoolConfigBean hikariConfigBean, boolean autoCommit, boolean readOnly) throws StageException { HikariConfig config = new HikariConfig(); // Log all registered drivers LOG.info("Registered JDBC drivers:"); Collections.list(DriverManager.getDrivers()).forEach(driver -> { LOG.info("Driver class {} (version {}.{})", driver.getClass().getName(), driver.getMajorVersion(), driver.getMinorVersion()); });/* w w w . j a v a2 s. c om*/ config.setJdbcUrl(hikariConfigBean.getConnectionString()); if (hikariConfigBean.useCredentials) { config.setUsername(hikariConfigBean.username.get()); config.setPassword(hikariConfigBean.password.get()); } config.setAutoCommit(autoCommit); config.setReadOnly(readOnly); config.setMaximumPoolSize(hikariConfigBean.maximumPoolSize); config.setMinimumIdle(hikariConfigBean.minIdle); config.setConnectionTimeout(hikariConfigBean.connectionTimeout * MILLISECONDS); config.setIdleTimeout(hikariConfigBean.idleTimeout * MILLISECONDS); config.setMaxLifetime(hikariConfigBean.maxLifetime * MILLISECONDS); if (!StringUtils.isEmpty(hikariConfigBean.driverClassName)) { config.setDriverClassName(hikariConfigBean.driverClassName); } if (!StringUtils.isEmpty(hikariConfigBean.connectionTestQuery)) { config.setConnectionTestQuery(hikariConfigBean.connectionTestQuery); } if (hikariConfigBean.transactionIsolation != TransactionIsolationLevel.DEFAULT) { config.setTransactionIsolation(hikariConfigBean.transactionIsolation.name()); } if (StringUtils.isNotEmpty(hikariConfigBean.initialQuery)) { config.setConnectionInitSql(hikariConfigBean.initialQuery); } config.setDataSourceProperties(hikariConfigBean.getDriverProperties()); return config; }
From source file:com.landenlabs.all_devtool.NetFragment.java
public static String getMacAddr() { try {/*from w w w .java 2 s .com*/ List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress(); if (macBytes == null) { return ""; } StringBuilder res1 = new StringBuilder(); for (byte b : macBytes) { res1.append(Integer.toHexString(b & 0xFF)).append(":"); } if (res1.length() > 0) { res1.deleteCharAt(res1.length() - 1); } return res1.toString(); } } catch (Exception ex) { } return "02:00:00:00:00:00"; }
From source file:org.apache.nifi.web.server.JettyServer.java
private void configureConnectors(final Server server) throws ServerConfigurationException { // create the http configuration final HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setRequestHeaderSize(HEADER_BUFFER_SIZE); httpConfiguration.setResponseHeaderSize(HEADER_BUFFER_SIZE); if (props.getPort() != null) { final Integer port = props.getPort(); if (port < 0 || (int) Math.pow(2, 16) <= port) { throw new ServerConfigurationException("Invalid HTTP port: " + port); }// w ww. ja v a2s . com logger.info("Configuring Jetty for HTTP on port: " + port); final List<Connector> serverConnectors = Lists.newArrayList(); final Map<String, String> httpNetworkInterfaces = props.getHttpNetworkInterfaces(); if (httpNetworkInterfaces.isEmpty() || httpNetworkInterfaces.values().stream() .filter(value -> !Strings.isNullOrEmpty(value)).collect(Collectors.toList()).isEmpty()) { // create the connector final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration)); // set host and port if (StringUtils.isNotBlank(props.getProperty(NiFiProperties.WEB_HTTP_HOST))) { http.setHost(props.getProperty(NiFiProperties.WEB_HTTP_HOST)); } http.setPort(port); serverConnectors.add(http); } else { // add connectors for all IPs from http network interfaces serverConnectors .addAll(Lists.newArrayList(httpNetworkInterfaces.values().stream().map(ifaceName -> { NetworkInterface iface = null; try { iface = NetworkInterface.getByName(ifaceName); } catch (SocketException e) { logger.error("Unable to get network interface by name {}", ifaceName, e); } if (iface == null) { logger.warn("Unable to find network interface named {}", ifaceName); } return iface; }).filter(Objects::nonNull) .flatMap(iface -> Collections.list(iface.getInetAddresses()).stream()) .map(inetAddress -> { // create the connector final ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration)); // set host and port http.setHost(inetAddress.getHostAddress()); http.setPort(port); return http; }).collect(Collectors.toList()))); } // add all connectors serverConnectors.forEach(server::addConnector); } if (props.getSslPort() != null) { final Integer port = props.getSslPort(); if (port < 0 || (int) Math.pow(2, 16) <= port) { throw new ServerConfigurationException("Invalid HTTPs port: " + port); } logger.info("Configuring Jetty for HTTPs on port: " + port); final List<Connector> serverConnectors = Lists.newArrayList(); final Map<String, String> httpsNetworkInterfaces = props.getHttpsNetworkInterfaces(); if (httpsNetworkInterfaces.isEmpty() || httpsNetworkInterfaces.values().stream() .filter(value -> !Strings.isNullOrEmpty(value)).collect(Collectors.toList()).isEmpty()) { final ServerConnector https = createUnconfiguredSslServerConnector(server, httpConfiguration); // set host and port if (StringUtils.isNotBlank(props.getProperty(NiFiProperties.WEB_HTTPS_HOST))) { https.setHost(props.getProperty(NiFiProperties.WEB_HTTPS_HOST)); } https.setPort(port); serverConnectors.add(https); } else { // add connectors for all IPs from https network interfaces serverConnectors .addAll(Lists.newArrayList(httpsNetworkInterfaces.values().stream().map(ifaceName -> { NetworkInterface iface = null; try { iface = NetworkInterface.getByName(ifaceName); } catch (SocketException e) { logger.error("Unable to get network interface by name {}", ifaceName, e); } if (iface == null) { logger.warn("Unable to find network interface named {}", ifaceName); } return iface; }).filter(Objects::nonNull) .flatMap(iface -> Collections.list(iface.getInetAddresses()).stream()) .map(inetAddress -> { final ServerConnector https = createUnconfiguredSslServerConnector(server, httpConfiguration); // set host and port https.setHost(inetAddress.getHostAddress()); https.setPort(port); return https; }).collect(Collectors.toList()))); } // add all connectors serverConnectors.forEach(server::addConnector); } }
From source file:UnpackedJarFile.java
public Enumeration entries() { if (isClosed) { throw new IllegalStateException("NestedJarFile is closed"); }/*ww w . j av a2 s.c om*/ Collection baseEntries = Collections.list(baseJar.entries()); Collection entries = new LinkedList(); for (Iterator iterator = baseEntries.iterator(); iterator.hasNext();) { JarEntry baseEntry = (JarEntry) iterator.next(); String path = baseEntry.getName(); if (path.startsWith(basePath)) { entries.add(new NestedJarEntry(path.substring(basePath.length()), baseEntry, getManifestSafe())); } } return Collections.enumeration(entries); }