Example usage for java.util HashSet size

List of usage examples for java.util HashSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

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

Usage

From source file:fastcall.FArrayUtils.java

/**
 * Return sorted unique array of string//from w  w  w  . ja va  2 s .c  o  m
 * @param input
 * @return 
 */
public static String[] getUniqueStringArray(String[] input) {
    HashSet<String> t = new HashSet();
    for (int i = 0; i < input.length; i++) {
        t.add(input[i]);
    }
    String[] result = t.toArray(new String[t.size()]);
    Arrays.sort(result);
    return result;
}

From source file:edu.udel.ece.infolab.btc.Utils.java

/**
 * Flatten a list of triples to n-tuples containing many objects for the same
 * predicate. Generate one n-tuple per predicate.
 * //from  w  ww .  j  av  a  2  s.  co m
 * @param values
 *          The list of n-triples.
 * @return The n-tuples concatenated.
 */
private static void flattenNTriples(final String triples, final Map<String, HashSet<String>> map,
        final HashSet<String> types, final boolean isOut) {
    try {
        initParser();
        parser.parse(new StringReader(triples), "");
        for (Statement st : collector.getStatements()) {
            sb.setLength(0);
            final String subject = sb.append('<').append(st.getSubject().toString()).append('>').toString();
            sb.setLength(0);
            final String predicate = sb.append('<').append(st.getPredicate().toString()).append('>').toString();
            sb.setLength(0);
            final String object = (st.getObject() instanceof URI)
                    ? sb.append('<').append(st.getObject().toString()).append('>').toString()
                    : st.getObject().toString();
            if (types != null && predicate.equals(RDF_TYPE)) {
                types.add(object);
            } else {
                HashSet<String> hs = map.get(predicate);
                final String toAdd = isOut ? object : subject;
                if (hs == null) {
                    hs = new HashSet<String>();
                    map.put(predicate, hs);
                }
                if (hs.size() < 65535) // 2 ^ 16 - 1
                    hs.add(toAdd);
            }
        }
    } catch (RDFParseException e1) {
    } catch (RDFHandlerException e1) {
    } catch (IOException e1) {
    }
}

From source file:coq.DebugUnivInconst.java

/**
 * //from   w  w w  .  ja  v a 2 s.co  m
 * @param s1
 * @param s2
 * @return 
 */
static boolean nonDisjoint(HashSet<String> highlight, Set<String> scc) {
    if (highlight.isEmpty())
        return true;

    HashSet<String> highCopy = new HashSet<String>(highlight);
    highCopy.retainAll(scc);
    return (highCopy.size() > 0);
}

From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java

/**
 * Returns an array of full paths determined by parsing all paths arguments
 * found in the specified commandLine. Duplicates are ignored.
 * //from   w ww. java 2s  .  c om
 * @param padoShell
 *            PadoShell instance
 * @param commandLine
 *            Command line with path arguments.
 * @return null if paths are not found in the specified commandLine.
 */
@SuppressWarnings("unchecked")
public final static String[] getFullPaths(PadoShell padoShell, CommandLine commandLine) {
    List<String> argList = (List<String>) commandLine.getArgList();
    if (argList.size() <= 1) {
        return null;
    }
    HashSet<String> set = new HashSet<String>(argList.size());
    for (int i = 1; i < argList.size(); i++) {
        String path = argList.get(i);
        set.add(padoShell.getFullPath(path));
    }
    String fullPaths[] = set.toArray(new String[set.size()]);
    return fullPaths;
}

From source file:com.battlelancer.seriesguide.util.TraktTools.java

/**
 * Downloads and sets watched and collected flags from trakt on local episodes.
 *
 * @param clearExistingFlags If set, all watched and collected (and only those, e.g. skipped
 *                           flag is preserved) flags will be removed prior to getting the
 *                           actual flags from trakt (season by season).
 * @return Any of the {@link TraktTools} result codes.
 *//*  w  w  w  . jav  a  2 s . co  m*/
public static int syncToSeriesGuide(Context context, Trakt trakt, HashSet<Integer> localShows,
        boolean clearExistingFlags) {
    if (localShows.size() == 0) {
        return SUCCESS_NOWORK;
    }

    final UserService userService = trakt.userService();
    final String username = TraktCredentials.get(context).getUsername();
    List<TvShow> remoteShows;

    // watched episodes
    try {
        // get watched episodes from trakt
        remoteShows = userService.libraryShowsWatched(username, Extended.MIN);
    } catch (RetrofitError e) {
        Timber.e(e, "Downloading watched shows failed");
        return FAILED_API;
    }
    if (remoteShows == null) {
        return FAILED_API;
    }
    if (!remoteShows.isEmpty()) {
        applyEpisodeFlagChanges(context, remoteShows, localShows, SeriesGuideContract.Episodes.WATCHED,
                clearExistingFlags);
    }

    // collected episodes
    try {
        // get watched episodes from trakt
        remoteShows = userService.libraryShowsCollection(username, Extended.MIN);
    } catch (RetrofitError e) {
        Timber.e(e, "Downloading collected shows failed");
        return FAILED_API;
    }
    if (remoteShows == null) {
        return FAILED_API;
    }
    if (!remoteShows.isEmpty()) {
        applyEpisodeFlagChanges(context, remoteShows, localShows, SeriesGuideContract.Episodes.COLLECTED,
                clearExistingFlags);
    }

    return SUCCESS;
}

From source file:com.alibaba.jstorm.utils.LoadConf.java

public static InputStream getConfigFileInputStream(String configFilePath, boolean canMultiple)
        throws IOException {
    if (null == configFilePath) {
        throw new IOException("Could not find config file, name not specified");
    }/*from  w  w w . ja v  a  2s .co m*/

    HashSet<URL> resources = new HashSet<>(findResources(configFilePath));
    if (resources.isEmpty()) {
        File configFile = new File(configFilePath);
        if (configFile.exists()) {
            return new FileInputStream(configFile);
        }
    } else if (resources.size() > 1 && !canMultiple) {
        throw new IOException("Found multiple " + configFilePath + " resources. "
                + "You're probably bundling storm jars with your topology jar. " + resources);
    } else {
        LOG.debug("Using " + configFilePath + " from resources");
        URL resource = resources.iterator().next();
        return resource.openStream();
    }
    return null;
}

From source file:org.jamocha.dn.memory.javaimpl.MemoryHandlerMain.java

public static org.jamocha.dn.memory.MemoryHandlerMainAndCounterColumnMatcher newMemoryHandlerMain(
        final PathNodeFilterSet filterSet, final Map<Edge, Set<Path>> edgesAndPaths) {
    final ArrayList<Template> template = new ArrayList<>();
    final ArrayList<FactAddress> addresses = new ArrayList<>();
    final HashMap<FactAddress, FactAddress> newAddressesCache = new HashMap<>();
    if (!edgesAndPaths.isEmpty()) {
        final Edge[] incomingEdges = edgesAndPaths.entrySet().iterator().next().getKey().getTargetNode()
                .getIncomingEdges();/*from   w w w .  ja v a  2  s.  co m*/
        for (final Edge edge : incomingEdges) {
            final MemoryHandlerMain memoryHandlerMain = (MemoryHandlerMain) edge.getSourceNode().getMemory();
            for (final Template t : memoryHandlerMain.getTemplate()) {
                template.add(t);
            }
            final HashMap<FactAddress, FactAddress> addressMap = new HashMap<>();
            for (final FactAddress oldFactAddress : memoryHandlerMain.addresses) {
                final FactAddress newFactAddress = new FactAddress(addresses.size());
                addressMap.put(oldFactAddress, newFactAddress);
                newAddressesCache.put(oldFactAddress, newFactAddress);
                addresses.add(newFactAddress);
            }
            edge.setAddressMap(addressMap);
        }
    }
    final Template[] templArray = toArray(template, Template[]::new);
    final FactAddress[] addrArray = toArray(addresses, FactAddress[]::new);

    final PathFilterToCounterColumn pathFilterToCounterColumn = new PathFilterToCounterColumn();

    if (filterSet.getPositiveExistentialPaths().isEmpty()
            && filterSet.getNegativeExistentialPaths().isEmpty()) {
        return new MemoryHandlerMainAndCounterColumnMatcher(new MemoryHandlerMain(templArray,
                Counter.newCounter(filterSet, pathFilterToCounterColumn), addrArray),
                pathFilterToCounterColumn);
    }
    final boolean[] existential = new boolean[templArray.length];
    // gather existential paths
    final HashSet<Path> existentialPaths = new HashSet<>();
    existentialPaths.addAll(filterSet.getPositiveExistentialPaths());
    existentialPaths.addAll(filterSet.getNegativeExistentialPaths());

    int index = 0;
    for (final PathFilter pathFilter : filterSet.getFilters()) {
        final HashSet<Path> paths = PathCollector.newHashSet().collect(pathFilter).getPaths();
        paths.retainAll(existentialPaths);
        if (0 == paths.size())
            continue;
        for (final Path path : paths) {
            existential[newAddressesCache.get(path.getFactAddressInCurrentlyLowestNode()).index] = true;
        }
        pathFilterToCounterColumn.putFilterElementToCounterColumn(pathFilter, new CounterColumn(index++));
    }
    return new MemoryHandlerMainAndCounterColumnMatcher(
            new MemoryHandlerMainWithExistentials(templArray,
                    Counter.newCounter(filterSet, pathFilterToCounterColumn), addrArray, existential),
            pathFilterToCounterColumn);
}

From source file:com.addthis.hydra.job.spawn.JobAlertUtil.java

/**
 * Count the total number of hits along a certain path in a tree object
 * @param jobId The job to query/*w  w  w  . jav  a  2  s  . co  m*/
 * @param checkPath The path to check, e.g.
 * @return The number of hits along the specified path
 */
public static long getQueryCount(String jobId, String checkPath) {

    HashSet<String> result = JSONFetcher.staticLoadSet(getQueryURL(jobId, checkPath, defaultOps, defaultOps),
            alertQueryTimeout, alertQueryRetries, null);
    if (result == null || result.isEmpty()) {
        log.warn("Found no data for job={} checkPath={}; returning zero", jobId, checkPath);
        return 0;
    } else if (result.size() > 1) {
        log.warn("Found multiple results for job={} checkPath={}; using first row", jobId, checkPath);
    }
    String raw = result.iterator().next();
    return Long.parseLong(QUERY_TRIM_PATTERN.matcher(raw).replaceAll("")); // Trim [] characters and parse as long

}

From source file:Main.java

public static void addTaintInformationToIntent(Intent i, HashSet<String> taintCategories) {
    boolean intentHasNoExtras = i.getExtras() == null ? true : false;

    Log.i("PEP", "in addTaintInformationToIntent(Intent i, HashSet<String> taintCategories)");

    //A bit of limitation here, because we do only care about the extras
    if (!intentHasNoExtras) {
        Bundle extras = i.getExtras();// w w  w .ja v a  2 s  . c  o m

        String taintKeyName = generateKeyNameForTaintInfo(extras.keySet());

        String taintInformation = null;

        if (taintCategories.size() > 1)
            taintInformation = taintCategories.toString().substring(1, taintCategories.toString().length() - 1);
        else
            taintInformation = taintCategories.iterator().next();

        i.putExtra(taintKeyName, taintInformation);
    }
}

From source file:SerialVersionUID.java

/**
 * Create a Map<String, ClassVersionInfo> for the jboss dist jars.
 * // w  ww  .j  av a 2  s.  co m
 * @param jbossHome -
 *          the jboss dist root directory
 * @return Map<String, ClassVersionInfo>
 * @throws IOException
 */
public static Map generateJBossSerialVersionUIDReport(File jbossHome) throws IOException {
    // Obtain the jars from the /lib, common/ and /server/all locations
    HashSet jarFiles = new HashSet();
    File lib = new File(jbossHome, "lib");
    buildJarSet(lib, jarFiles);
    File common = new File(jbossHome, "common");
    buildJarSet(common, jarFiles);
    File all = new File(jbossHome, "server/all");
    buildJarSet(all, jarFiles);
    URL[] cp = new URL[jarFiles.size()];
    jarFiles.toArray(cp);
    ClassLoader parent = Thread.currentThread().getContextClassLoader();
    URLClassLoader completeClasspath = new URLClassLoader(cp, parent);

    TreeMap classVersionMap = new TreeMap();
    Iterator jarIter = jarFiles.iterator();
    while (jarIter.hasNext()) {
        URL jar = (URL) jarIter.next();
        try {
            generateJarSerialVersionUIDs(jar, classVersionMap, completeClasspath, "");
        } catch (IOException e) {
            log.info("Failed to process jar: " + jar);
        }
    }

    return classVersionMap;
}