Example usage for java.util HashSet isEmpty

List of usage examples for java.util HashSet isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:com.vaadin.tests.server.LicenseInJavaFiles.java

public void testJavaFilesContainsLicense() throws IOException {
    File srcDir = new File(SRC_DIR);
    System.out.println(new File(".").getAbsolutePath());
    HashSet<String> missing = new HashSet<String>();
    checkForLicense(srcDir, missing);/*from  w  ww . j  a  v a2s .c  o m*/
    if (!missing.isEmpty()) {
        throw new RuntimeException(
                "The following files are missing license information:\n" + missing.toString());
    }
}

From source file:edu.cens.loci.classes.LociWifiFingerprint.java

/**
 * Calculated Tanimoto score between to Wifi fingerprints
 * @param sig1 is a Wifi fingerprint//from   ww w.jav  a2 s. c  o m
 * @param sig2 is a Wifi fingerprint
 * @param repAP1 
 * @param repAP2
 * @param rrThreshold is used to filter low response rate APs
 * @param isDebugOn
 * @return
 */
public static double tanimotoScore(LociWifiFingerprint sig1, LociWifiFingerprint sig2, HashSet<String> repAP1,
        HashSet<String> repAP2, double rrThreshold, boolean isDebugOn) {

    if (repAP1 == null)
        MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use all.");
    else
        MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use rep.");

    // use every beacon when repAP is empty
    if (repAP1 == null || repAP1.isEmpty())
        repAP1 = sig1.getBssids();
    if (repAP2 == null || repAP2.isEmpty())
        repAP2 = sig2.getBssids();

    // use only the union of both representative set
    HashSet<String> union = new HashSet<String>(repAP1);
    union.addAll(repAP2);

    // two arrays to save RSS values 
    double a[] = new double[union.size()];
    double b[] = new double[union.size()];

    // fill in the arrays with RSS values
    Iterator<String> iterator = union.iterator();
    int cnt = 0;

    String debugSsids = "   ";
    String debugRssA = "rss (a) : ";
    String debugRssB = "rss (b) : ";
    String debugNorA = "nor (a) : ";
    String debugNorB = "nor (b) : ";
    String debugCntA = "cnt (a) : ";
    String debugCntB = "cnt (b) : ";
    String debugRRA = "rr  (a) : ";
    String debugRRB = "rr  (b) : ";

    while (iterator.hasNext()) {
        String bssid = iterator.next();

        int aIntVal = sig1.getAvgRss(bssid);
        int bIntVal = sig2.getAvgRss(bssid);
        double rr1 = sig1.getResponseRate(bssid);
        double rr2 = sig2.getResponseRate(bssid);

        if (rr1 >= rrThreshold)
            a[cnt] = raw2normal(aIntVal, pMinRss, pMaxRss);
        else
            a[cnt] = raw2normal(0, pMinRss, pMaxRss);

        if (rr2 >= rrThreshold)
            b[cnt] = raw2normal(bIntVal, pMinRss, pMaxRss);
        else
            b[cnt] = raw2normal(0, pMinRss, pMaxRss);

        cnt++;

        if (isDebugOn) {
            String ssid = sig1.getSsid(bssid);
            if (ssid == null)
                ssid = sig2.getSsid(bssid);
            if (ssid == null)
                ssid = "unknown";

            int count1 = sig1.getCount(bssid);
            int count2 = sig2.getCount(bssid);

            debugSsids = debugSsids + String.format("%10s", ssid.substring(0, Math.min(ssid.length(), 9)));
            debugRssA = debugRssA + String.format("%10d", aIntVal);
            debugRssB = debugRssB + String.format("%10d", bIntVal);
            debugNorA = debugNorA + String.format("%10.2f", a[cnt - 1]);
            debugNorB = debugNorB + String.format("%10.2f", b[cnt - 1]);
            debugCntA = debugCntA + String.format("%10d", count1);
            debugCntB = debugCntB + String.format("%10d", count2);
            debugRRA = debugRRA + String.format("%10.2f", rr1);
            debugRRB = debugRRB + String.format("%10.2f", rr2);
        }
    }

    MyLog.d(isDebugOn, TAG, debugSsids);
    MyLog.d(isDebugOn, TAG, debugRssA);
    MyLog.d(isDebugOn, TAG, debugRssB);
    MyLog.d(isDebugOn, TAG, debugNorA);
    MyLog.d(isDebugOn, TAG, debugNorB);
    MyLog.d(isDebugOn, TAG, debugCntA);
    MyLog.d(isDebugOn, TAG, debugCntB);
    MyLog.d(isDebugOn, TAG, debugRRA);
    MyLog.d(isDebugOn, TAG, debugRRB);

    return tanimotoSimilarity(a, b);
}

From source file:org.gcaldaemon.core.GCalUtilities.java

private static final void registerTimeZones(String content, byte[] bytes) {
    try {/*from  ww w.  ja  va2s .c o m*/
        StringTokenizer st = new StringTokenizer(content, "\r\n");
        HashSet timeZones = new HashSet();
        String line, timeZone;
        while (st.hasMoreTokens()) {
            line = st.nextToken();
            if (!line.startsWith("TZID:")) {
                continue;
            }
            timeZone = line.substring(5);
            if (timeZone.length() == 0) {
                continue;
            }
            if (registeredTimeZones.contains(timeZone)) {
                continue;
            }
            timeZones.add(timeZone);
        }
        if (timeZones.isEmpty()) {
            return;
        }
        Calendar calendar = ICalUtilities.parseCalendar(bytes);
        VTimeZone[] zones = ICalUtilities.getTimeZones(calendar);
        if (zones.length == 0) {
            return;
        }
        Component seasonalTime;
        TzOffsetTo offsetTo;
        String id, offset;
        VTimeZone zone;
        for (int i = 0; i < zones.length; i++) {
            zone = zones[i];
            seasonalTime = zone.getObservances().getComponent(Observance.STANDARD);
            if (seasonalTime == null) {
                seasonalTime = zone.getObservances().getComponent(Observance.DAYLIGHT);
            }
            id = zone.getTimeZoneId().getValue();
            if (registeredTimeZones.contains(id)) {
                continue;
            }
            if (seasonalTime == null) {
                continue;
            }
            offsetTo = (TzOffsetTo) seasonalTime.getProperty(Property.TZOFFSETTO);
            if (offsetTo == null) {
                continue;
            }
            registeredTimeZones.add(id);
            offset = offsetTo.getValue();
            log.debug("Set the offset of " + id + " to GMT" + offset + ".");
            if (!ICalUtilities.setTimeZone(id, offset)) {
                log.warn("Unknown time zone (" + id + ")!");
            }
        }
    } catch (Exception ignored) {
        log.debug(ignored);
    }
}

From source file:edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer.java

/**
  * Extracts the weak components from a graph.
  * @param graph the graph whose weak components are to be extracted
  * @return the list of weak components// w  w  w .j ava2 s .com
  */
public Set<Set<V>> transform(Graph<V, E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
        Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for (V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}

From source file:org.apache.sysml.hops.codegen.template.PlanSelectionFuseCostBased.java

private static Collection<HashSet<Long>> getConnectedSubGraphs(CPlanMemoTable memo, ArrayList<Hop> roots) {
    //build inverted index for 'referenced by' relationship 
    HashMap<Long, HashSet<Long>> refBy = new HashMap<Long, HashSet<Long>>();
    for (Entry<Long, List<MemoTableEntry>> e : memo._plans.entrySet())
        for (MemoTableEntry me : e.getValue())
            for (int i = 0; i < 3; i++)
                if (me.isPlanRef(i)) {
                    if (!refBy.containsKey(me.input(i)))
                        refBy.put(me.input(i), new HashSet<Long>());
                    refBy.get(me.input(i)).add(e.getKey());
                }/*from  ww w .j a v  a 2s  .co  m*/

    //create a single partition per root node, if reachable over refBy of 
    //other root node the resulting partition is empty and can be discarded
    ArrayList<HashSet<Long>> parts = new ArrayList<HashSet<Long>>();
    HashSet<Long> visited = new HashSet<Long>();
    for (Entry<Long, List<MemoTableEntry>> e : memo._plans.entrySet())
        if (!refBy.containsKey(e.getKey())) { //root node
            HashSet<Long> part = rGetConnectedSubGraphs(e.getKey(), memo, refBy, visited, new HashSet<Long>());
            if (!part.isEmpty())
                parts.add(part);
        }

    return parts;
}

From source file:com.goncalomb.bukkit.nbteditor.TestBosEntities.java

@Test
public void testBosEntities() {
    HashSet<EntityType> entityTypes = new HashSet<EntityType>();
    entityTypes.addAll(Arrays.asList(EntityType.values()));
    entityTypes.removeAll(EntityNBT.getValidEntityTypes());
    if (!entityTypes.isEmpty()) {
        System.out.print("Missing BoS entities: ");
        System.out.print(StringUtils.join(entityTypes, ", "));
        System.out.println(".");
    }/* w  w  w. j av a2  s .  c o  m*/
}

From source file:de.kaiserpfalzEdv.office.contacts.location.CountryBuilder.java

public void validate() {
    HashSet<String> reasons = new HashSet<>();

    generateValidationErrorList(reasons);

    if (!reasons.isEmpty()) {
        throw new BuilderValidationException("Can't build country information!", reasons);
    }/* w  w w.j  a  va 2s  .  c  o  m*/
}

From source file:de.kaiserpfalzEdv.office.contacts.address.phone.PhoneNumberBuilder.java

public void validate() {
    HashSet<String> reasons = new HashSet<>();

    generateValidationErrorList(reasons);

    if (!reasons.isEmpty()) {
        throw new BuilderValidationException("Can't build street address!", reasons);
    }/*from w w w.  j  a v a2s  .c om*/
}

From source file:de.kaiserpfalzEdv.office.contacts.location.CityBuilder.java

public void validate() {
    HashSet<String> reasons = new HashSet<>();

    generateValidationErrorList(reasons);

    if (!reasons.isEmpty()) {
        throw new BuilderValidationException("Can't build city information!", reasons);
    }/*from  w ww  . ja va  2 s .  co m*/
}

From source file:edu.anu.spice.SemanticConcept.java

/**
 * SemanticConcepts are similar if they share a synset or a concept
 *///from  w w  w . j  av a2 s.  c  om
public boolean similarTo(Object o) {
    if (o == null) {
        return false;
    }
    if (!(o instanceof SemanticConcept)) {
        return false;
    }
    SemanticConcept otherConcept = (SemanticConcept) o;
    HashSet<Integer> synset_intersection = new HashSet<Integer>(this.synsets);
    synset_intersection.retainAll(otherConcept.synsets);
    if (!synset_intersection.isEmpty()) {
        return true;
    }
    HashSet<String> concept_intersection = new HashSet<String>(this.concepts);
    concept_intersection.retainAll(otherConcept.concepts);
    return !concept_intersection.isEmpty();
}