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:license.regist.ReadProjectInfo.java

private static boolean checkMac(Map<Integer, String> infoMap) throws SocketException {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    Base64 base64 = new Base64();
    int i = 12;/*from   www  .  ja v  a  2 s  . c  om*/
    for (NetworkInterface ni : Collections.list(interfaces)) {
        if (ni.getName().substring(0, 1).equalsIgnoreCase("e")) {
            if (!((String) infoMap.get(Integer.valueOf(i))).equalsIgnoreCase(ni.getName()))
                return false;
            i++;
            byte[] mac = ni.getHardwareAddress();

            if (!((String) infoMap.get(Integer.valueOf(i))).equalsIgnoreCase(base64.encodeAsString(mac))) {
                return false;
            }
            i++;
        }
    }
    return true;
}

From source file:org.fourthline.cling.osgi.test.integration.BaseIntegration.java

public void dumpUPnPDevice(UPnPDevice device) {
    System.out.printf("%s\n", device);
    for (Object key : Collections.list(device.getDescriptions(null).keys())) {
        System.out.printf("\t %s: %s\n", key, device.getDescriptions(null).get(key));
    }//  w ww. j a  v a2 s .c  o  m
}

From source file:com.googlecode.l10nmavenplugin.model.BundlePropertiesFamily.java

/**
 * {@inheritDoc}/*w  w  w  .j  a  v  a 2s  .c  om*/
 */
public Set<String> getKeys() {
    Set<String> keys = new HashSet<String>();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        keys.addAll(new HashSet<String>(
                Collections.list((Enumeration<String>) propertiesFile.getProperties().propertyNames())));
    }
    return keys;
}

From source file:org.artifactory.ui.rest.service.admin.security.auth.login.HttpLoginArtifactoryRequest.java

@Override
public boolean isRecursive() {
    Enumeration<String> origins = getOrigins();
    if (origins != null && origins.hasMoreElements()) {
        ArrayList<String> originsList = Collections.list(origins);
        String currentHostId = ContextHelper.get().beanForType(AddonsManager.class)
                .addonByType(HaCommonAddon.class).getHostId();
        int numOfOrigins = originsList.size();
        for (String origin : originsList) {
            if (numOfOrigins > 1 && currentHostId.equals(origin)) {
                return true;
            }/*  w  ww .ja v  a 2 s  . c o m*/
        }
    }

    return false;
}

From source file:org.apache.asterix.external.provider.ParserFactoryProvider.java

protected static Map<String, Class> initFactories() throws AsterixException {
    Map<String, Class> factories = new HashMap<>();
    ClassLoader cl = ParserFactoryProvider.class.getClassLoader();
    try {/* ww w  . j  ava2  s. co m*/
        Enumeration<URL> urls = cl.getResources(RESOURCE);
        for (URL url : Collections.list(urls)) {
            List<String> classNames;
            try (InputStream is = url.openStream()) {
                classNames = IOUtils.readLines(is, StandardCharsets.UTF_8);
            }
            for (String className : classNames) {
                if (className.startsWith("#")) {
                    continue;
                }
                final Class<?> clazz = Class.forName(className);
                String[] formats = ((IDataParserFactory) clazz.newInstance()).getFormats();
                for (String format : formats) {
                    if (factories.containsKey(format)) {
                        throw new AsterixException("Duplicate format " + format);
                    }
                    factories.put(format, clazz);
                }
            }
        }
    } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new AsterixException(e);
    }
    return factories;
}

From source file:org.trafodion.rest.util.NetworkConfiguration.java

public NetworkConfiguration(Configuration conf) throws Exception {

    this.conf = conf;
    ia = InetAddress.getLocalHost();

    String dnsInterface = conf.get(Constants.REST_DNS_INTERFACE, Constants.DEFAULT_REST_DNS_INTERFACE);
    if (dnsInterface.equalsIgnoreCase("default")) {
        intHostAddress = extHostAddress = ia.getHostAddress();
        canonicalHostName = ia.getCanonicalHostName();
        LOG.info("Using local host [" + canonicalHostName + "," + extHostAddress + "]");
    } else {//from ww w .  j  a va  2s. c  o  m
        // For all nics get all hostnames and addresses   
        // and try to match against rest.dns.interface property 
        Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
        while (nics.hasMoreElements() && !matchedInterface) {
            InetAddress inet = null;
            NetworkInterface ni = nics.nextElement();
            LOG.info("Found interface [" + ni.getDisplayName() + "]");
            if (dnsInterface.equalsIgnoreCase(ni.getDisplayName())) {
                LOG.info("Matched specified interface [" + ni.getName() + "]");
                inet = getInetAddress(ni);
                getCanonicalHostName(ni, inet);
            } else {
                Enumeration<NetworkInterface> subIfs = ni.getSubInterfaces();
                for (NetworkInterface subIf : Collections.list(subIfs)) {
                    LOG.debug("Sub Interface Display name [" + subIf.getDisplayName() + "]");
                    if (dnsInterface.equalsIgnoreCase(subIf.getDisplayName())) {
                        LOG.info("Matched subIf [" + subIf.getName() + "]");
                        inet = getInetAddress(subIf);
                        getCanonicalHostName(subIf, inet);
                        break;
                    }
                }
            }
        }
    }

    if (!matchedInterface)
        checkCloud();
}

From source file:org.springframework.vault.authentication.MacAddressUserId.java

@Override
public String createUserId() {

    try {/*ww  w  . j a va2 s  . co m*/

        NetworkInterface networkInterface = null;
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());

        if (StringUtils.hasText(networkInterfaceHint)) {

            try {
                networkInterface = getNetworkInterface(Integer.parseInt(networkInterfaceHint), interfaces);
            } catch (NumberFormatException e) {
                networkInterface = getNetworkInterface((networkInterfaceHint), interfaces);
            }
        }

        if (networkInterface == null) {

            if (StringUtils.hasText(networkInterfaceHint)) {
                log.warn(String.format("Did not find a NetworkInterface applying hint %s",
                        networkInterfaceHint));
            }

            InetAddress localHost = InetAddress.getLocalHost();
            networkInterface = NetworkInterface.getByInetAddress(localHost);

            if (networkInterface == null) {
                throw new IllegalStateException(
                        String.format("Cannot determine NetworkInterface for %s", localHost));
            }
        }

        byte[] mac = networkInterface.getHardwareAddress();
        if (mac == null) {
            throw new IllegalStateException(
                    String.format("Network interface %s has no hardware address", networkInterface.getName()));
        }

        return Sha256.toSha256(Sha256.toHexString(mac));
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:psiprobe.tools.logging.jdk.Jdk14ManagerAccessor.java

/**
 * Gets the handlers.//from   w ww . j a  v a  2 s .  c om
 *
 * @return the handlers
 */
public List<LogDestination> getHandlers() {
    List<LogDestination> allHandlers = new ArrayList<>();
    try {
        for (String name : Collections
                .list((Enumeration<String>) MethodUtils.invokeMethod(getTarget(), "getLoggerNames", null))) {
            Jdk14LoggerAccessor accessor = getLogger(name);
            if (accessor != null) {
                allHandlers.addAll(accessor.getHandlers());
            }
        }
    } catch (Exception e) {
        logger.error("{}#getLoggerNames() failed", getTarget().getClass().getName(), e);
    }
    return allHandlers;
}

From source file:org.paxle.core.io.impl.ResourceBundleTool.java

@SuppressWarnings("unchecked")
public List<URL> getLocaleURL(Bundle osgiBundle, String resourceBundleBase) {
    if (osgiBundle == null)
        throw new NullPointerException("The osgi-bundle was null");
    else if (resourceBundleBase == null)
        throw new NullPointerException("The resource-bundle base-name was null");

    // calculating the resource-bundle location
    String localizationLocation = IResourceBundleTool.LOCALIZATION_LOCATION_DEFAULT;
    if (resourceBundleBase.contains("/")) {
        localizationLocation = resourceBundleBase.substring(0, resourceBundleBase.lastIndexOf('/'));
        resourceBundleBase = resourceBundleBase.substring(resourceBundleBase.lastIndexOf('/') + 1);
    }//from  w  w w. ja v a2  s  .  c om

    // find all resource-bundle files for the given base-name
    final Enumeration<URL> e = osgiBundle.findEntries(localizationLocation, resourceBundleBase + "*.properties",
            false);
    final List<URL> resourceBundleURLs = (e == null) ? Collections.EMPTY_LIST : Collections.list(e);
    return resourceBundleURLs;
}

From source file:com.github.promeg.configchecker.Main.java

/**
 * Tries to open an input file as a Zip archive (jar/apk) with a
 * "classes.dex" inside./*w ww  .j  a va2 s  . c o  m*/
 */
void openInputFileAsZip(String fileName, List<String> dexFiles) throws IOException {
    ZipFile zipFile;

    // Try it as a zip file.
    try {
        zipFile = new ZipFile(fileName);
    } catch (FileNotFoundException fnfe) {
        // not found, no point in retrying as non-zip.
        System.err.println("Unable to open '" + fileName + "': " + fnfe.getMessage());
        throw fnfe;
    } catch (ZipException ze) {
        // not a zip
        return;
    }

    // Open and add all files matching "classes.*\.dex" in the zip file.
    for (ZipEntry entry : Collections.list(zipFile.entries())) {
        if (entry.getName().matches("classes.*\\.dex")) {
            dexFiles.add(openDexFile(zipFile, entry).getAbsolutePath());
        }
    }

    zipFile.close();
}