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:com.redhat.lightblue.rest.metadata.hystrix.GetEntityNamesCommand.java

@Override
protected String run() {
    LOGGER.debug("run:");
    Error.reset();/*w w  w.j a va2 s.c om*/
    Error.push(getClass().getSimpleName());
    try {
        HashSet<MetadataStatus> statusSet = new HashSet<>();
        for (String x : statuses) {
            statusSet.add(MetadataParser.statusFromString(x));
        }
        String[] names = getMetadata().getEntityNames(statusSet.toArray(new MetadataStatus[statusSet.size()]));
        ObjectNode node = NODE_FACTORY.objectNode();
        ArrayNode arr = NODE_FACTORY.arrayNode();
        node.put("entities", arr);
        for (String x : names) {
            arr.add(NODE_FACTORY.textNode(x));
        }
        return node.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:org.apache.solr.analytics.legacy.LegacyAbstractAnalyticsTest.java

public <T extends Comparable<T>> Object calculateStat(ArrayList<T> list, String stat) {
    Object result;//from  w  w w .  j  a v  a  2s  .  co  m
    if (stat.contains("perc_")) {
        ArrayList<Integer> percs = new ArrayList<>(1);
        int ord = (int) Math.ceil(Double.parseDouble(stat.substring(5)) / 100 * list.size()) - 1;
        percs.add(ord);
        OrdinalCalculator.putOrdinalsInPosition(list, percs);
        result = list.get(percs.get(0));
    } else if (stat.equals("count")) {
        result = Long.valueOf(list.size());
    } else if (stat.equals("unique")) {
        HashSet<T> set = new HashSet<>();
        set.addAll(list);
        result = Long.valueOf((long) set.size());
    } else if (stat.equals("max")) {
        Collections.sort(list);
        result = list.get(list.size() - 1);
    } else if (stat.equals("min")) {
        Collections.sort(list);
        result = list.get(0);
    } else {
        result = null;
    }
    return result;
}

From source file:com.github.pjungermann.config.specification.constraint.url.UrlConstraint.java

@NotNull
@SuppressWarnings("unchecked")
protected String[] configureAllowedSchemes() {
    final Collection<String> schemesConfig = (Collection<String>) config.get(SCHEMES_KEY);
    if (schemesConfig == null || schemesConfig.isEmpty()) {
        return new String[0];
    }/*from www . jav a  2  s .co  m*/

    final HashSet<String> schemes = new HashSet<>();
    final Set<String> checked = checkedSet(schemes, String.class);
    checked.addAll(schemesConfig);

    return schemes.toArray(new String[schemes.size()]);
}

From source file:com.sec.ose.osi.sdk.protexsdk.discovery.AbstractDiscoveryController.java

public static int curPendingFileCount(String projectName) {
    HashSet<String> fileSet = new HashSet<String>();
    UIResponseObserver observer = null;/*from w w w  .j  a v a2  s  . c o  m*/
    ArrayList<String> files = new ArrayList<String>();

    ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, observer);

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    files = ProjectDiscoveryControllerMap
            .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE)
            .getPendingFileList();
    for (String file : files) {
        fileSet.add(file);
    }

    return fileSet.size();
}

From source file:org.oscarehr.hospitalReportManager.SFTPConnector.java

protected static void notifyHrmError(LoggedInInfo loggedInInfo, String errorMsg) {
    HashSet<String> sendToProviderList = new HashSet<String>();

    String providerNoTemp = "999998";
    if (!doNotSentMsgForOuttage.contains(providerNoTemp))
        sendToProviderList.add(providerNoTemp);

    if (loggedInInfo != null && loggedInInfo.getLoggedInProvider() != null) {
        // manual prompts always send to admin
        sendToProviderList.add(providerNoTemp);

        providerNoTemp = loggedInInfo.getLoggedInProviderNo();
        if (!doNotSentMsgForOuttage.contains(providerNoTemp))
            sendToProviderList.add(providerNoTemp);
    }/*from   w w w. j  a  v a2s. co m*/

    // no one wants to hear about the problem
    if (sendToProviderList.size() == 0)
        return;

    String message = "OSCAR attempted to perform a fetch of HRM data at " + new Date()
            + " but there was an error during the task.\n\nSee below for the error message:\n" + errorMsg;

    oscar.oscarMessenger.data.MsgMessageData messageData = new oscar.oscarMessenger.data.MsgMessageData();

    ArrayList<MsgProviderData> sendToProviderListData = new ArrayList<MsgProviderData>();
    for (String providerNo : sendToProviderList) {
        MsgProviderData mpd = new MsgProviderData();
        mpd.providerNo = providerNo;
        mpd.locationId = "145";
        sendToProviderListData.add(mpd);
    }

    String sentToString = messageData.createSentToString(sendToProviderListData);
    messageData.sendMessage2(message, "HRM Retrieval Error", "System", sentToString, "-1",
            sendToProviderListData, null, null);
}

From source file:com.china317.gmmp.gmmp_report_analysis.App.java

private static void analysisBanche(String yyyyMMdd, ApplicationContext context) {
    try {/*from w w w. ja  v  a2  s . com*/
        String businessType = "2";

        // System.out.println("[classpath]"+System.getProperty("java.class.path"));//classpaht
        // System.out.println("[path]"+System.getProperty("user.dir"));//?

        log.info("[get baseVehicle begin---------]");
        VehicleDao vehicleDao = (VehicleDao) context.getBean("vehicleDao");
        List<Vehicle> vehs = vehicleDao.getBaseVehicleByDate(yyyyMMdd, businessType);

        List<List<Vehicle>> list_tm = ListUtil.splitList(vehs, 400);
        log.info("[get baseVehicle end1---------],vehicle total:" + vehs.size());
        log.info("[get baseVehicle end2---------],list_tm total:" + list_tm.size());
        for (List<Vehicle> vls : list_tm) {
            Map<String, Vehicle> vehMap = new HashMap<String, Vehicle>();

            log.info("[code set init------]");
            HashSet<String> codes = new HashSet<String>();
            for (Vehicle v : vls) {
                codes.add(v.getCode());
                vehMap.put(v.getCode(), v);
            }

            log.info("[code set end------]" + "setSize:" + vehMap.size());
            List<VehicleLocate> list = new ArrayList<VehicleLocate>();
            if (codes.size() > 0) {
                VehicleLocateDao vehicleLocateDao_gmmpraw = (VehicleLocateDao) context
                        .getBean("vehicleLocateDaoGmmpRaw");
                list = vehicleLocateDao_gmmpraw.findHistoryByParams(yyyyMMdd, codes);
                log.info("[this time total Points Size]:" + list.size());
            }

            Map<String, List<VehicleLocate>> map = new HashMap<String, List<VehicleLocate>>();
            for (VehicleLocate entity : list) {
                if (entity.getGpsSpeed() < 160) {
                    // businessType
                    Vehicle tmpV = vehMap.get(entity.getCode());
                    entity.setBusinessType(tmpV.getBusinessType());
                    List<VehicleLocate> records = map.get(entity.getCode());
                    if (records == null) {
                        records = new ArrayList<VehicleLocate>();
                    }
                    long lastlong = DateTime.accountTime3(entity.getGpsTime(), entity.getGetTime());
                    if (lastlong <= 10 * 60) {
                        records.add(entity);
                    }
                    map.put(entity.getCode(), records);
                }

            }

            log.info("analysis begin ,total:" + map.size());

            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                List<VehicleLocate> tmps = map.get(key);
                log.info("analysis vehicle code:" + key + "sort list begin, list size:" + tmps.size());
                Collections.sort(tmps, new Comparator<VehicleLocate>() {
                    public int compare(VehicleLocate o1, VehicleLocate o2) {
                        Date d1 = o1.getGpsTime();
                        Date d2 = o2.getGpsTime();
                        if (d1.after(d2)) {
                            return 1;
                        } else if (d1.before(d2)) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                });
                log.info("analysis vehicle code:" + key + "sort list end");

                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS begin");
                for (int i = 0; i < tmps.size(); i++) {
                    VehicleLocate e = tmps.get(i);
                    AreaAddProcessor.addAreaRuleInfo(e);
                    /*
                     * log.info("[vehcilelocate properties]" + e.getCode() +
                     * "; gpstime:" + e.getGpsTime() + "; gpsSpeed:" +
                     * e.getGpsSpeed() + "; businessType:" +
                     * e.getBusinessType() + "; lon:" + e.getLon() +
                     * "; lat:" + e.getLat() + "; acc:" + e.getACCState());
                     */
                    PtmAnalysisImp.getInstance().overSpeedAnalysis(e);
                    // PtmAnalysisImp.getInstance().offlineAnalysis(e,
                    // yyyyMMdd);

                    // ?
                    PtmAnalysisImp.getInstance().putLastRecord(e);
                }

                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS end");

                log.info("result: overspeed:" + PtmAnalysisImp.getInstance().getOverSpeedRecordsSize()
                        + "; offline:" + PtmAnalysisImp.getInstance().getOfflineRecordsSize());
                // PtmAnalysisImp.getInstance().clear();
            }
            // OverSpeedRecordsStoreIntoDB(PtmAnalysisImp.getInstance()
            // .getOverSpeedRecords(), context);
            PtmOverSpeedRecordsStoreIntoDB(PtmAnalysisImp.getInstance().getOverSpeedRecords(), context);
        }

        log.info("analysis end");

        log.info("[Ptm ended]");
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:mobac.program.model.Atlas.java

public boolean checkData() {
    if (name == null) // name set?
        return true;
    // Check for duplicate layer names
    HashSet<String> names = new HashSet<String>(layers.size());
    for (LayerInterface layer : layers)
        names.add(layer.getName());/*from  www . j  ava  2  s  . c  o m*/
    if (names.size() < layers.size())
        return true; // at least one duplicate name found
    return false;
}

From source file:org.osiam.resources.helper.AttributesRemovalHelper.java

private ObjectWriter getObjectWriter(ObjectMapper mapper, String[] fieldsToReturn) {

    if (fieldsToReturn.length != 0) {
        mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);

        HashSet<String> givenFields = new HashSet<>();
        givenFields.add("schemas");
        Collections.addAll(givenFields, fieldsToReturn);
        String[] finalFieldsToReturn = givenFields.toArray(new String[givenFields.size()]);

        FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name",
                SimpleBeanPropertyFilter.filterOutAllExcept(finalFieldsToReturn));
        return mapper.writer(filters);
    }/*  ww  w.  ja v  a  2s  .  co m*/
    return mapper.writer();
}

From source file:com.china317.gmmp.gmmp_report_analysis.App.java

private static void analysisBaoChe(String yyyyMMdd, ApplicationContext context) throws Exception {
    try {/*from w w w.  j a  va2 s.  c  o  m*/
        log.info("[Baoche App started]");
        String businessType = "3";
        // System.out.println("[classpath]"+System.getProperty("java.class.path"));//classpaht
        // System.out.println("[path]"+System.getProperty("user.dir"));//?

        log.info("[Baoche get baseVehicle begin---------]");
        VehicleDao vehicleDao = (VehicleDao) context.getBean("vehicleDao");
        List<Vehicle> vehs = vehicleDao.getBaseVehicleByDate(yyyyMMdd, businessType);

        List<List<Vehicle>> list_tm = ListUtil.splitList(vehs, 400);
        log.info("[Baoche get baseVehicle end1---------],vehicle total:" + vehs.size());
        log.info("[Baoche get baseVehicle end2---------],list_tm total:" + list_tm.size());
        for (List<Vehicle> vls : list_tm) {
            Map<String, Vehicle> vehMap = new HashMap<String, Vehicle>();

            log.info("[Baoche code set init------]");
            HashSet<String> codes = new HashSet<String>();
            for (Vehicle v : vls) {
                codes.add(v.getCode());
                vehMap.put(v.getCode(), v);
            }

            log.info("[Baoche code set end------]" + "setSize:" + vehMap.size());
            List<VehicleLocate> list = new ArrayList<VehicleLocate>();
            if (codes.size() > 0) {
                VehicleLocateDao vehicleLocateDao_gmmpraw = (VehicleLocateDao) context
                        .getBean("vehicleLocateDaoGmmpRaw");
                list = vehicleLocateDao_gmmpraw.findHistoryByParams(yyyyMMdd, codes);
                log.info("[Baoche this time total Points Size]:" + list.size());
            }

            Map<String, List<VehicleLocate>> map = new HashMap<String, List<VehicleLocate>>();
            for (VehicleLocate entity : list) {

                if (entity.getGpsSpeed() < 160) {
                    // businessType
                    Vehicle tmpV = vehMap.get(entity.getCode());
                    entity.setBusinessType(tmpV.getBusinessType());
                    List<VehicleLocate> records = map.get(entity.getCode());
                    if (records == null) {
                        records = new ArrayList<VehicleLocate>();
                    }
                    long lastlong = DateTime.accountTime3(entity.getGpsTime(), entity.getGetTime());
                    if (lastlong <= 10 * 60) {
                        records.add(entity);
                    }
                    map.put(entity.getCode(), records);
                }

            }

            log.info("analysis begin ,total:" + map.size());

            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                List<VehicleLocate> tmps = map.get(key);
                log.info("analysis vehicle code:" + key + "sort list begin, list size:" + tmps.size());
                Collections.sort(tmps, new Comparator<VehicleLocate>() {
                    public int compare(VehicleLocate o1, VehicleLocate o2) {
                        Date d1 = o1.getGpsTime();
                        Date d2 = o2.getGpsTime();
                        if (d1.after(d2)) {
                            return 1;
                        } else if (d1.before(d2)) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                });
                log.info("analysis vehicle code:" + key + "sort list end");

                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS begin");
                for (int i = 0; i < tmps.size(); i++) {
                    VehicleLocate e = tmps.get(i);
                    AreaAddProcessor.addAreaRuleInfo(e);
                    /*
                     * log.info("[Baoche vehcilelocate properties]" +
                     * e.getCode() + "; gpstime:" + e.getGpsTime() +
                     * "; gpsSpeed:" + e.getGpsSpeed() + "; businessType:" +
                     * e.getBusinessType() + "; lon:" + e.getLon() +
                     * "; lat:" + e.getLat() + "; acc:" + e.getACCState());
                     */
                    BaocheAnalysisImp.getInstance().overSpeedAnalysis(e);
                    // BaocheAnalysisImp.getInstance().offlineAnalysis(e,
                    // yyyyMMdd);

                    // ??
                    BaocheAnalysisImp.getInstance().xlpAlarmAnalysis(e);

                    // ?
                    BaocheAnalysisImp.getInstance().putLastRecord(e);
                }

                // BaocheAnalysisImp.getInstance().clear();
                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS end");

                log.info("result: overspeed:" + BaocheAnalysisImp.getInstance().getOverSpeedRecordsSize()
                        + "; offline:" + BaocheAnalysisImp.getInstance().getOfflineRecordsSize());

            }
            LybcOverSpeedRecordsStoreIntoDB(BaocheAnalysisImp.getInstance().getOverSpeedRecords(), context);
            // 
            IntOutNoneRecordsStoreIntoDB(BaocheAnalysisImp.getInstance().getIniOutNoneRecords(), context);

            // 
            InOutMoreRecordsStoreIntoDB(BaocheAnalysisImp.getInstance().getIniOutMoreRecords(), context);

        }

        log.info("analysis end");

        log.info("[Baoche ended]");
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:amie.keys.CombinationsExplorationNew.java

public static void discoverConditionalKeysForCondition(GraphNew newGraph, GraphNew graph,
        HashSet<Node> candidateKeys, Rule conditionRule) {
    HashSet<Node> newCandidateKeys = new HashSet<>();
    for (Node candidateKey : candidateKeys) {
        //  System.out.println("candidateKey:" + candidateKey);
        if (candidateKey.toExplore) {
            //   System.out.println("candidate:" + candidateKey);
            // if (candidateKey.toExplore) {
            List<String> properties = candidateKey.mapToString(id2Property);
            Rule amieRule = buildAMIERule(properties, conditionRule);
            boolean isConditionalKey = isConditionaKey(amieRule);

            if (amieRule.getSupport() >= support && !isConditionalKey) {
                //System.out.println("Case 0");
                if (!newGraph.graph.containsKey(candidateKey)) {
                    //System.out.println("Case 1");
                    Node newCandidateKey = candidateKey.clone();
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(newCandidateKey, children);
                    newGraph.nodes.put(newCandidateKey, newCandidateKey);
                    newCandidateKeys.add(newCandidateKey);
                } else {
                    //System.out.println("Case 2");
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(candidateKey, children);
                    newCandidateKeys.add(candidateKey);
                }/*from  w  w w.jav a 2 s.  c o m*/
            }

            // If the rule is a conditional above the support
            // and there is no a simpler key already discovered
            // then output it
            if (isConditionalKey && amieRule.getSupport() >= support
                    && !isSubsumedByKey(amieRule, conditionRule, conditions2Keys)) {
                //        System.out.println("KEY");
                if (!newGraph.graph.containsKey(candidateKey)) {
                    //       System.out.println("clone");
                    Node newCandidateKey = candidateKey.clone();
                    System.out.println(Utilities.formatKey(amieRule));
                    conditions2Keys.put(conditionRule, amieRule);
                    newCandidateKey.toExplore = false;
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(newCandidateKey, children);
                    newGraph.nodes.put(newCandidateKey, newCandidateKey);
                    newCandidateKeys.add(newCandidateKey);
                    //System.out.println("Case 3");
                } else {
                    System.out.println(Utilities.formatKey(amieRule));
                    conditions2Keys.put(conditionRule, amieRule);
                    candidateKey.toExplore = false;
                    HashSet<Node> children = new HashSet<>();
                    newGraph.graph.put(candidateKey, children);
                    newGraph.nodes.put(candidateKey, candidateKey);
                    newCandidateKeys.add(candidateKey);
                    //System.out.println("Case 4");
                }

                // System.out.println(Utilities.formatKey(amieRule));
                //conditions2Keys.put(conditionRule, amieRule);
                // candidateKey.toExplore = false;
            }
        } else {
            //System.out.println("Case 5");
            newCandidateKeys.add(candidateKey);
        }
    }
    //   System.out.println("newGraphBefore:" + newGraph);

    // createChildren
    HashSet<Node> allChildren = new HashSet<>();
    // System.out.println("newCandidateKeys:"+newCandidateKeys);
    for (Node parent1 : newCandidateKeys) {
        //    System.out.println("parent1:"+parent1);
        for (Node parent2 : newCandidateKeys) {
            if (parent1 != parent2 && parent1.toExplore != false && parent2.toExplore != false) {
                HashSet<Integer> newSet = new HashSet<>();
                newSet.addAll(parent1.set);
                newSet.addAll(parent2.set);
                HashSet<Integer> condProp_KeyProp = new HashSet<>();
                condProp_KeyProp.addAll(newSet);
                condProp_KeyProp.addAll(getRelations(conditionRule, property2Id));
                //     System.out.println("newSet:" + newSet);
                if ((newSet.size() == parent1.set.size() + 1) && (getSupport(newSet, conditionRule, support))
                        && GraphNew.containsASuperSetOf(CombinationsExplorationNew.nonKeysInt,
                                condProp_KeyProp) != -1) {
                    //      System.out.println("enters");
                    Node child = new Node(newSet);
                    if (hasFalseParent(newSet, newCandidateKeys)) {
                        //         System.out.println("falseParent");
                        child.toExplore = false;
                    }
                    HashSet<Node> children1 = newGraph.graph.get(parent1);
                    children1.add(child);
                    newGraph.graph.put(parent1, children1);
                    newGraph.nodes.put(child, child);
                    HashSet<Node> grandChildren = new HashSet<>();
                    newGraph.graph.put(child, grandChildren);
                    HashSet<Node> children2 = newGraph.graph.get(parent2);
                    children2.add(child);
                    newGraph.graph.put(parent2, children2);
                    allChildren.add(child);
                }
            }
        }
    }
    if (!allChildren.isEmpty()) {
        discoverConditionalKeysForCondition(newGraph, newGraph, allChildren, conditionRule);
    }
}