Example usage for java.util Set size

List of usage examples for java.util Set size

Introduction

In this page you can find the example usage for java.util Set size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:com.alta189.bukkit.script.event.EventScanner.java

public static void scanPlugin(Plugin plugin) {
    if (pluginEvents.containsKey(plugin)) {
        return;//from w ww  .  j ava2  s  .  c o m
    }
    BScript.getInstance().debug("Scanning plugin " + plugin.getName());
    if (plugin instanceof JavaPlugin) {
        ClassLoader loader = ReflectionUtil.getFieldValue(JavaPlugin.class, plugin, "classLoader");
        Reflections reflections = new Reflections(new ConfigurationBuilder()
                .filterInputsBy(new FilterBuilder().exclude(FilterBuilder.prefix("org.bukkit")))
                .setUrls(ClasspathHelper.forClassLoader(loader)));

        Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class);

        BScript.getInstance().info("Found " + classes.size() + " classes extending "
                + Event.class.getCanonicalName() + " in " + plugin.getName());
        for (Class<? extends Event> clazz : classes) {
            if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
                continue;
            }
            BScript.getInstance().debug(clazz.getCanonicalName());

            String className = clazz.getCanonicalName();
            if (className == null) {
                className = clazz.getName();
            }
            BScript.getInstance().debug(className);
            events.put(className, clazz);
            String simpleName = clazz.getSimpleName();
            if (simpleNameEvents.get(simpleName) != null) {
                simpleNameEvents.remove(simpleName);
            } else {
                simpleNameEvents.put(simpleName, clazz);
            }
        }
        if (classes.size() > 0) {
            pluginEvents.put(plugin, classes);
        }
    } else {
        BScript.getInstance().debug("Plugin is not JavaPlugin " + plugin.getName());
    }
}

From source file:spring.osgi.utils.OsgiResourceUtils.java

public static Resource[] convertURLEnumerationToResourceArray(Enumeration enm) {
    Set<Resource> resources = new LinkedHashSet<>(4);
    while (enm != null && enm.hasMoreElements()) {
        resources.add(new UrlResource((URL) enm.nextElement()));
    }/*ww  w .java2 s  .  com*/
    return resources.toArray(new Resource[resources.size()]);
}

From source file:com.diversityarrays.util.ClassPathExtender.java

public static void addDirectoryJarsToClassPath(Log logger, Consumer<File> jarChecker, File... dirs) {
    if (dirs == null || dirs.length <= 0) {
        if (logger != null) {
            logger.info("No directories provided for class path");
        }// w  w  w.  j a v  a 2  s .  co m
        return;
    }

    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    if (ccl instanceof java.net.URLClassLoader) {
        try {
            Method m = java.net.URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            m.setAccessible(true);

            Set<URL> currentUrls = new HashSet<URL>(Arrays.asList(((URLClassLoader) ccl).getURLs()));
            if (VERBOSE) {
                info(logger, "=== Current URLS in ClassLoader: " + currentUrls.size());
                for (URL u : currentUrls) {
                    info(logger, "\t" + u.toString());
                }
            }

            for (File dir : dirs) {
                if (dir.isDirectory()) {
                    for (File f : dir.listFiles(JAR_OR_PROPERTIES)) {
                        try {
                            URL u = f.toURI().toURL();
                            if (!currentUrls.contains(u)) {
                                m.invoke(ccl, u);
                                if (VERBOSE) {
                                    info(logger, "[Added " + u + "] to CLASSPATH");
                                }
                                if (jarChecker != null) {
                                    jarChecker.accept(f);
                                }
                            }
                        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
                                | MalformedURLException e) {
                            warn(logger,
                                    "%Unable to add " + f.getPath() + " to CLASSPATH (" + e.getMessage() + ")");
                        }
                    }
                }
            }
        } catch (NoSuchMethodException e) {
            warn(logger, "%No method: " + java.net.URLClassLoader.class.getName() + ".addURL(URL)");
        }

    } else {
        warn(logger, "%currentThread.contextClassLoader is not an instance of "
                + java.net.URLClassLoader.class.getName());
    }
}

From source file:net.sf.json.AbstractJSON.java

/**
 * Removes a reference for cycle detection check.
 *///w  ww. jav a2  s.c om
protected static void removeInstance(Object instance) {
    Set set = getCycleSet();
    set.remove(instance);
    if (set.size() == 0) {
        cycleSet.remove();
    }
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.ExportNameUtils.java

public static String getExportDescription(List<ImageInformation> scalingInformationList) {
    Set<String> importFileNames = new HashSet<String>();
    for (ImageInformation information : scalingInformationList) {
        importFileNames.add(information.getImageFile().getName());
    }/* w w  w  . ja v a  2 s.com*/
    StringBuilder builder = new StringBuilder("Import of ");
    // No multi import
    if (importFileNames.size() == 1) {
        builder.append(importFileNames.iterator().next());
        if (scalingInformationList.size() == 1) {
            builder.append(" in resolution ");
        } else {
            builder.append(" in resolutions ");
        }
        for (Iterator<ImageInformation> iterator = scalingInformationList.iterator(); iterator.hasNext();) {
            ImageInformation information = iterator.next();
            builder.append(information.getTargetResolution());
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
    } else {
        for (Iterator<String> iterator = importFileNames.iterator(); iterator.hasNext();) {
            String exportName = iterator.next();
            builder.append(exportName);
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
        builder.append(" as ").append(scalingInformationList.get(0).getExportName());
    }
    return builder.toString();
}

From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java

private static void setDefaultSize(int size) {
    Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
    Object[] keys = keySet.toArray(new Object[keySet.size()]);

    for (Object key : keys) {
        if (key != null && key.toString().toLowerCase().contains("font")) {
            Font font = UIManager.getDefaults().getFont(key);
            if (font != null) {
                font = font.deriveFont((float) size);
                UIManager.put(key, font);
            }//from  w w w  . ja va2s .com
        }
    }
}

From source file:it.unibz.instasearch.ui.InstaSearchPage.java

private static String getFieldFilterString(Field field, Set<String> values) {
    String filterString = null;/* w  w  w.j  av a2 s .  c  o m*/

    if (values.size() == 0)
        return "";

    for (String val : values) {
        if (filterString == null)
            filterString = "";
        else
            filterString += ",";
        filterString += val;
    }

    if (filterString.contains(" "))
        filterString = '"' + filterString + '"';

    return field.toString() + ':' + filterString;
}

From source file:com.infovity.iep.loader.util.SupplierLoaderUtil.java

public static Set<Integer> getUniqueNumbersSet(int numberOfUniquekeys) {
    Set<Integer> set = new HashSet<Integer>();
    while (set.size() < numberOfUniquekeys) {
        set.add(gen());//  w ww .  j  a  v  a2s.c o  m
    }
    return set;
}

From source file:co.cask.cdap.etl.tool.UpgradeTool.java

private static void printUpgraded(Set<Id.Application> pipelines) {
    if (pipelines.size() == 0) {
        LOG.info("Did not find any pipelines that needed upgrading.");
        return;/*from  www  .ja  v a  2s  . c  om*/
    }
    LOG.info("Successfully upgraded {} pipelines:", pipelines.size());
    for (Id.Application pipeline : pipelines) {
        LOG.info("  {}", pipeline);
    }
}

From source file:com.fengduo.bee.search.utils.PinyinParser.java

/**
 * ???(??)/* ww  w.  j a  v  a  2  s  .  c  o m*/
 * 
 * @param args
 */
private static Set<String> parseTheChineseByObject(List<Map<String, Integer>> list) {
    Map<String, Integer> first = null; // ?,???
    // ????
    for (int i = 0; i < list.size(); i++) {
        // ???Map
        Map<String, Integer> temp = new Hashtable<String, Integer>();
        // first
        if (first != null) {
            // ????
            for (String s : first.keySet()) {
                for (String s1 : list.get(i).keySet()) {
                    String str = s + s1;
                    temp.put(str, 1);
                }
            }
            // ???
            if (temp != null && temp.size() > 0) {
                first.clear();
            }
        } else {
            for (String s : list.get(i).keySet()) {
                String str = s;
                temp.put(str, 1);
            }
        }
        // ???
        if (temp != null && temp.size() > 0) {
            first = temp;
        }
    }
    Set<String> result = new HashSet<String>();
    if (first != null) {
        // ????
        for (String str : first.keySet()) {
            result.add(str);
            if (result.size() >= 5) {
                break;
            }
        }
    }
    return result;
}