Example usage for java.util Set isEmpty

List of usage examples for java.util Set isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:net.antidot.semantic.rdf.rdb2rdf.r2rml.core.R2RMLMappingFactory.java

private static ReferencingObjectMap extractReferencingObjectMap(SesameDataSet r2rmlMappingGraph,
        Resource object, Set<GraphMap> graphMaps, Map<Resource, TriplesMap> triplesMapResources)
        throws InvalidR2RMLStructureException, InvalidR2RMLSyntaxException {
    log.debug("[R2RMLMappingFactory:extractReferencingObjectMap] Extract referencing object map..");
    URI parentTriplesMap = (URI) extractValueFromTermMap(r2rmlMappingGraph, object,
            R2RMLTerm.PARENT_TRIPLES_MAP);
    Set<JoinCondition> joinConditions = extractJoinConditions(r2rmlMappingGraph, object);
    if (parentTriplesMap == null && !joinConditions.isEmpty())
        throw new InvalidR2RMLStructureException(
                "[R2RMLMappingFactory:extractReferencingObjectMap] " + object.stringValue()
                        + " has no parentTriplesMap map defined whereas one or more joinConditions exist"
                        + " : exactly one parentTripleMap is required.");
    if (parentTriplesMap == null && joinConditions.isEmpty()) {
        log.debug(/*from w ww . j  av  a  2  s .  c om*/
                "[R2RMLMappingFactory:extractReferencingObjectMap] This object map is not a referencing object map.");
        return null;
    }
    // Extract parent
    boolean contains = false;
    TriplesMap parent = null;
    for (Resource triplesMapResource : triplesMapResources.keySet()) {
        if (triplesMapResource.stringValue().equals(parentTriplesMap.stringValue())) {
            contains = true;
            parent = triplesMapResources.get(triplesMapResource);
            log.debug("[R2RMLMappingFactory:extractReferencingObjectMap] Parent triples map found : "
                    + triplesMapResource.stringValue());
            break;
        }
    }
    if (!contains) {
        throw new InvalidR2RMLStructureException("[R2RMLMappingFactory:extractReferencingObjectMap] "
                + object.stringValue() + " reference to parent triples maps is broken : "
                + parentTriplesMap.stringValue() + " not found.");
    }
    // Link between this reerencing object and its triplesMap parent will be
    // performed
    // at the end f treatment.
    ReferencingObjectMap refObjectMap = new StdReferencingObjectMap(null, parent, joinConditions);
    log.debug("[R2RMLMappingFactory:extractReferencingObjectMap] Extract referencing object map done.");
    return refObjectMap;
}

From source file:com.genentech.application.calcProps.SDFCalcProps.java

/**Generated a string of piped commands based on a set of calculators
 * Need to figure out dependencies,/*from   ww  w  .j  a v a2  s.c  o m*/
 */
private static String assembleCommands(Set<Calculator> calculators, boolean verbose, boolean debug,
        String counterTag, Set<String> outputTags) {
    if (calculators.isEmpty()) {
        return null;
    }

    //generate a string of SD tags that are separated by | character
    StringBuilder tagsToKeep = assembleTags(outputTags);

    if (debug) { //extra info debugging
        System.err.println("++++++++++Calculators for sorting ++++++++++++++++");
        for (Calculator c : calculators) {
            Set<String> deps = c.getRequiredCalculators();
            System.err.print(c.getName() + ", " + c.getProgName() + " " + c.getProgOps()
                    + ", number of required calculators: " + deps.size() + "(");
            for (String d : deps)
                System.err.print(d + " ");
            System.err.println(")");
        }
    }

    //sort calculators by dependencies
    //cHLM required cLogD7.4, cLogD7.4 should be calculated prior to cHLM
    List<Calculator> sortedCalculators = sortByDependencies(new ArrayList<Calculator>(calculators), 0);

    if (debug) { //extra info for debugging
        System.err.println("++++++++++sorted Calculators++++++++++++++++");
        for (Calculator c : sortedCalculators) {
            Set<String> reqCalculators = c.getRequiredCalculators();
            System.err.print(c.getName() + ", " + c.getProgName() + " " + c.getProgOps()
                    + ", number of required calculators: " + reqCalculators.size() + "(");
            for (String d : reqCalculators)
                System.err.print(d + " ");
            System.err.println(")");
        }
    }

    if (debug) {//extra info for debugging
        System.err.println("++++++++++aggregated Calculators++++++++++++++++");
        for (Calculator c : sortedCalculators) {
            Set<String> reqCalculators = c.getRequiredCalculators();
            System.err.print(c.getProgName() + " " + c.getProgOps() + ", number of required calculators: "
                    + reqCalculators.size() + "(");
            for (String d : reqCalculators)
                System.err.print(d + " ");
            System.err.println(")");
        }
    }

    //chain together the calculators to produce a single command line
    String calcCommands = getCommands(sortedCalculators) + " | sdf2Tab.csh -in .sdf -tags \"" + counterTag + "|"
            + tagsToKeep + "\"";
    return calcCommands;
}

From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaApplicationSpecs.java

/**
 * Get a specification using the specified parameters.
 *
 * @param name     The name of the application
 * @param user     The name of the user who created the application
 * @param statuses The status of the application
 * @param tags     The set of tags to search with
 * @param type     The type of applications to fine
 * @return A specification object used for querying
 *///from w  ww.  jav a  2  s .  c  o m
public static Specification<ApplicationEntity> find(@Nullable final String name, @Nullable final String user,
        @Nullable final Set<ApplicationStatus> statuses, @Nullable final Set<TagEntity> tags,
        @Nullable final String type) {
    return (final Root<ApplicationEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> {
        final List<Predicate> predicates = new ArrayList<>();
        if (StringUtils.isNotBlank(name)) {
            predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb,
                    root.get(ApplicationEntity_.name), name));
        }
        if (StringUtils.isNotBlank(user)) {
            predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb,
                    root.get(ApplicationEntity_.user), user));
        }
        if (statuses != null && !statuses.isEmpty()) {
            predicates.add(
                    cb.or(statuses.stream().map(status -> cb.equal(root.get(ApplicationEntity_.status), status))
                            .toArray(Predicate[]::new)));
        }
        if (tags != null && !tags.isEmpty()) {
            final Join<ApplicationEntity, TagEntity> tagEntityJoin = root.join(ApplicationEntity_.tags);
            predicates.add(tagEntityJoin.in(tags));
            cq.groupBy(root.get(ApplicationEntity_.id));
            cq.having(cb.equal(cb.count(root.get(ApplicationEntity_.id)), tags.size()));
        }
        if (StringUtils.isNotBlank(type)) {
            predicates.add(JpaSpecificationUtils.getStringLikeOrEqualPredicate(cb,
                    root.get(ApplicationEntity_.type), type));
        }
        return cb.and(predicates.toArray(new Predicate[predicates.size()]));
    };
}

From source file:mj.ocraptor.extraction.tika.parser.pkg.ZipContainerDetector.java

@SuppressWarnings("unchecked")
private static MediaType detectIpa(ZipFile zip) {
    // Note - consider generalising this logic, if another format needs many regexp matching
    Set<Pattern> tmpPatterns = (Set<Pattern>) ipaEntryPatterns.clone();

    Enumeration<ZipArchiveEntry> entries = zip.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        String name = entry.getName();

        Iterator<Pattern> ip = tmpPatterns.iterator();
        while (ip.hasNext()) {
            if (ip.next().matcher(name).matches()) {
                ip.remove();/*from  w w w.j  a v a  2 s  .c  o m*/
            }
        }
        if (tmpPatterns.isEmpty()) {
            // We've found everything we need to find
            return MediaType.application("x-itunes-ipa");
        }
    }

    // If we get here, not all required entries were found
    return null;
}

From source file:net.nifheim.beelzebu.coins.common.utils.dependencies.DependencyManager.java

public static void loadAllDependencies() {
    Set<Dependency> dependencies = new LinkedHashSet<>();
    dependencies.addAll(Arrays.asList(Dependency.values()));
    if (classExists("org.sqlite.JDBC") || core.isBungee()) {
        dependencies.remove(Dependency.SQLITE_DRIVER);
    }/*from  w  ww .  j ava2 s. com*/
    if (classExists("com.mysql.jdbc.Driver")) {
        dependencies.remove(Dependency.MYSQL_DRIVER);
    }
    if (classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory")) {
        dependencies.remove(Dependency.SLF4J_API);
        dependencies.remove(Dependency.SLF4J_SIMPLE);
    }
    if (classExists("org.apache.commons.io.FileUtils")) {
        dependencies.remove(Dependency.COMMONS_IO);
    }
    if (!dependencies.isEmpty()) {
        loadDependencies(dependencies);
    }
}

From source file:net.lldp.checksims.ChecksimsCommandLine.java

/**
 * Parse flags which require submissions to be built.
 *
 * TODO unit tests/*from  w  w w  .  ja v  a 2  s.c  o  m*/
 *
 * @param cli Parse CLI options
 * @param baseConfig Base configuration to work off
 * @return Modified baseConfig with submissions (and possibly common code and archive submissions) changed
 * @throws ChecksimsException Thrown on bad argument
 * @throws IOException Thrown on error building submissions
 */
static ChecksimsConfig parseFileFlags(CommandLine cli, ChecksimsConfig baseConfig)
        throws ChecksimsException, IOException {
    checkNotNull(cli);
    checkNotNull(baseConfig);

    ChecksimsConfig toReturn = new ChecksimsConfig(baseConfig);

    // Get glob match pattern
    // Default to *
    String globPattern = cli.getOptionValue("g", "*");

    // Check if we are recursively building
    boolean recursive = cli.hasOption("r");

    // Check if we are retaining empty submissions
    boolean retainEmpty = cli.hasOption("e");

    // Get submission directories
    if (!cli.hasOption("s")) {
        throw new ChecksimsException("Must provide at least one submission directory!");
    }

    String[] submissionDirsString = cli.getOptionValues("s");

    // Make a Set<File> from those submission directories
    // Map to absolute file, to ensure no dups
    Set<File> submissionDirs = Arrays.stream(submissionDirsString).map(File::new).map(File::getAbsoluteFile)
            .collect(Collectors.toSet());

    if (submissionDirs.isEmpty()) {
        throw new ChecksimsException("Must provide at least one submission directory!");
    }

    // Generate submissions
    Set<Submission> submissions = getSubmissions(submissionDirs, globPattern, recursive, retainEmpty);

    logs.debug("Generated " + submissions.size() + " submissions to process.");

    if (submissions.isEmpty()) {
        throw new ChecksimsException("Could build any submissions to operate on!");
    }

    toReturn = toReturn.setSubmissions(submissions);

    // Check if we need to perform common code removal
    if (cli.hasOption("c")) {
        // Get the directory containing the common code
        String commonCodeDirString = cli.getOptionValue("c");

        List<SubmissionPreprocessor> procs = new ArrayList<>(toReturn.getPreprocessors());
        try {
            procs.add(getCommonCodeRemoval(commonCodeDirString, submissionDirs, globPattern));
        } catch (IOException | ChecksimsException e) {
            logs.debug(e.getMessage());
        }
        toReturn = toReturn.setPreprocessors(procs);
    }

    // Check if we need to add archive directories
    if (cli.hasOption("archive")) {
        String[] archiveDirsString = cli.getOptionValues("archive");

        // Convert them into a set of files, again using getAbsoluteFile
        Set<File> archiveDirs = Arrays.stream(archiveDirsString).map(File::new).map(File::getAbsoluteFile)
                .collect(Collectors.toSet());

        archiveDirs = extractTurninFiles(archiveDirs);

        // Ensure that none of them are also submission directories
        for (File archiveDir : archiveDirs) {
            if (submissionDirs.contains(archiveDir)) {
                throw new ChecksimsException("Directory is both an archive directory and submission directory: "
                        + archiveDir.getAbsolutePath());
            }
        }

        // Get set of archive submissions
        Set<Submission> archiveSubmissions = getSubmissions(archiveDirs, globPattern, recursive, retainEmpty);

        logs.debug("Generated " + archiveSubmissions.size() + " archive submissions to process");

        if (archiveSubmissions.isEmpty()) {
            logs.warn("Did not find any archive submissions to test with!");
        }

        toReturn = toReturn.setArchiveSubmissions(archiveSubmissions);
    }

    return toReturn;
}

From source file:com.aurel.track.admin.customize.lists.systemOption.IssueTypeBL.java

/**
 * Load all possible item types which can be created by the user
 * @param personID/*from  w ww. j  ava  2 s.  c o m*/
 * @param locale
 * @return
 */
public static List<TListTypeBean> loadAllByPerson(Integer personID, Locale locale) {
    //get all create item role assignments for person
    List<TAccessControlListBean> accessControlListBeans = AccessBeans.loadByPersonAndRight(personID,
            new int[] { AccessFlagIndexes.CREATETASK, AccessFlagIndexes.PROJECTADMIN }, true);
    Map<Integer, Set<Integer>> projectsToRolesMap = new HashMap<Integer, Set<Integer>>();
    Set<Integer> allPersonRolesSet = new HashSet<Integer>();
    if (accessControlListBeans != null) {
        for (TAccessControlListBean accessControlListBean : accessControlListBeans) {
            Integer projectID = accessControlListBean.getProjectID();
            Integer roleID = accessControlListBean.getRoleID();
            allPersonRolesSet.add(roleID);
            Set<Integer> rolesInProject = projectsToRolesMap.get(projectID);
            if (rolesInProject == null) {
                rolesInProject = new HashSet<Integer>();
                projectsToRolesMap.put(projectID, rolesInProject);
            }
            rolesInProject.add(roleID);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(accessControlListBeans.size() + " assignments found for person " + personID + ": "
                    + allPersonRolesSet.size() + " roles " + " in " + projectsToRolesMap.size() + " projects ");
        }
    } else {
        return new LinkedList<TListTypeBean>();
    }
    //gets the itemType assignments for the assigned roles 
    Map<Integer, Set<Integer>> roleToItemTypesMap = new HashMap<Integer, Set<Integer>>();
    List<TRoleListTypeBean> itemTypesInRoles = RoleBL
            .loadByRoles(GeneralUtils.createIntegerListFromCollection(allPersonRolesSet));
    if (itemTypesInRoles != null) {
        for (TRoleListTypeBean roleListTypeBean : itemTypesInRoles) {
            Integer roleID = roleListTypeBean.getRole();
            Integer itemTypeID = roleListTypeBean.getListType();
            Set<Integer> itemTypesInRoleSet = roleToItemTypesMap.get(roleID);
            if (itemTypesInRoleSet == null) {
                itemTypesInRoleSet = new HashSet<Integer>();
                roleToItemTypesMap.put(roleID, itemTypesInRoleSet);
            }
            itemTypesInRoleSet.add(itemTypeID);
        }
    }
    Set<Integer> projectSet = projectsToRolesMap.keySet();
    if (projectSet.isEmpty()) {
        LOGGER.info("No project assignment for person " + personID);
        return new LinkedList<TListTypeBean>();
    }
    //gets the project to projectType map
    List<TProjectBean> projectList = ProjectBL
            .loadByProjectIDs(GeneralUtils.createIntegerListFromCollection(projectSet));
    Map<Integer, Integer> projectToProjectTypeMap = new HashMap<Integer, Integer>();
    Set<Integer> projectTypesSet = new HashSet<Integer>();
    for (TProjectBean projectBean : projectList) {
        Integer projectTypeID = projectBean.getProjectType();
        projectToProjectTypeMap.put(projectBean.getObjectID(), projectTypeID);
        projectTypesSet.add(projectTypeID);
    }
    //gets the item type assignments for project types
    List<TPlistTypeBean> plistTypes = loadByProjectTypes(projectTypesSet.toArray());
    Map<Integer, Set<Integer>> projectTypeToItemTypesMap = new HashMap<Integer, Set<Integer>>();
    if (plistTypes != null) {
        for (TPlistTypeBean plistTypeBean : plistTypes) {
            Integer projectTypeID = plistTypeBean.getProjectType();
            Integer itemTypeID = plistTypeBean.getCategory();
            Set<Integer> itemTypesSet = projectTypeToItemTypesMap.get(projectTypeID);
            if (itemTypesSet == null) {
                itemTypesSet = new HashSet<Integer>();
                projectTypeToItemTypesMap.put(projectTypeID, itemTypesSet);
            }
            itemTypesSet.add(itemTypeID);
        }
    }
    Set<Integer> allowedItemTypeIDs = new HashSet<Integer>();
    List<TListTypeBean> allSelectableitemTypeBeans = IssueTypeBL.loadAllSelectable(locale);
    Set<Integer> allSelectableItemTypeIDs = GeneralUtils
            .createIntegerSetFromBeanList(allSelectableitemTypeBeans);
    for (Map.Entry<Integer, Set<Integer>> rolesInProjectEntry : projectsToRolesMap.entrySet()) {
        Integer projectID = rolesInProjectEntry.getKey();
        Set<Integer> roleIDs = rolesInProjectEntry.getValue();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(roleIDs.size() + " roles found in project " + projectID);
        }
        Integer projectTypeID = projectToProjectTypeMap.get(projectID);
        Set<Integer> projectTypeLimitedItemTypes = projectTypeToItemTypesMap.get(projectTypeID);
        Set<Integer> rolesLimitedItemTypes = new HashSet<Integer>();
        //get the item types limited in all roles
        for (Integer roleID : roleIDs) {
            Set<Integer> roleLimitedItemTypes = roleToItemTypesMap.get(roleID);
            if (roleLimitedItemTypes != null) {
                rolesLimitedItemTypes.addAll(roleLimitedItemTypes);
            } else {
                //at least one role has no item type limitations
                rolesLimitedItemTypes.clear();
                break;
            }
        }
        if ((projectTypeLimitedItemTypes == null || projectTypeLimitedItemTypes.isEmpty())
                && rolesLimitedItemTypes.isEmpty()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No roles or project type specific limitation found for project " + projectID);
            }
            return allSelectableitemTypeBeans;
        } else {
            if (projectTypeLimitedItemTypes == null || projectTypeLimitedItemTypes.isEmpty()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Add role specific item type limitations for project " + projectID);
                }
                allowedItemTypeIDs.addAll(rolesLimitedItemTypes);
            } else {
                if (rolesLimitedItemTypes.isEmpty()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(
                                "Add project type specific item type limitations for project " + projectID);
                    }
                    allowedItemTypeIDs.addAll(projectTypeLimitedItemTypes);
                } else {
                    Collection<Integer> intersection = CollectionUtils.intersection(projectTypeLimitedItemTypes,
                            rolesLimitedItemTypes);
                    if (intersection != null) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(
                                    "Add project type specific and role specific item type limitations for project "
                                            + projectID);
                        }
                        allowedItemTypeIDs.addAll(intersection);
                    }
                }
            }
        }
    }
    allowedItemTypeIDs.retainAll(allSelectableItemTypeIDs);
    if (allowedItemTypeIDs.isEmpty()) {
        return new LinkedList<TListTypeBean>();
    } else {
        return LocalizeUtil.localizeDropDownList(
                loadByIssueTypeIDs(GeneralUtils.createIntegerListFromCollection(allowedItemTypeIDs)), locale);
    }
}

From source file:com.hpe.application.automation.tools.octane.executor.UftTestDiscoveryDispatcher.java

private static Map<String, Entity> getTestsFromServer(MqmRestClient client, long workspaceId,
        long scmRepositoryId, Set<String> allTestNames) {
    List<String> conditions = new ArrayList<>();
    if (allTestNames != null && !allTestNames.isEmpty()) {
        String byNameCondition = QueryHelper.conditionIn(OctaneConstants.Tests.NAME_FIELD, allTestNames, false);
        int byNameConditionSizeThreshold = 3000;
        //Query string is part of UR, some servers limit request size by 4K,
        //Here we limit nameCondition by 3K, if it exceed, we will fetch all tests
        if (byNameCondition.length() < byNameConditionSizeThreshold) {
            conditions.add(byNameCondition);
        }//  w w  w .jav a 2s  .  c o  m
    }

    conditions.add(QueryHelper.conditionRef(OctaneConstants.Tests.SCM_REPOSITORY_FIELD, scmRepositoryId));
    Collection<String> fields = Arrays.asList(OctaneConstants.Tests.ID_FIELD, OctaneConstants.Tests.NAME_FIELD,
            OctaneConstants.Tests.PACKAGE_FIELD, OctaneConstants.Tests.EXECUTABLE_FIELD,
            OctaneConstants.Tests.DESCRIPTION_FIELD);
    List<Entity> octaneTests = client.getEntities(workspaceId, OctaneConstants.Tests.COLLECTION_NAME,
            conditions, fields);
    Map<String, Entity> octaneTestsMapByKey = new HashedMap();
    for (Entity octaneTest : octaneTests) {
        String key = createKey(octaneTest.getStringValue(OctaneConstants.Tests.PACKAGE_FIELD),
                octaneTest.getName());
        octaneTestsMapByKey.put(key, octaneTest);
    }
    return octaneTestsMapByKey;
}

From source file:com.doculibre.constellio.services.SkosServicesImpl.java

private static SkosConcept getFirstBroaderConcept(SkosConcept skosConcept) {
    SkosConcept firstBroaderConcept;//from   ww w.j a v  a2 s .com
    Set<SkosConcept> broader = skosConcept.getBroader();
    if (!broader.isEmpty()) {
        firstBroaderConcept = broader.iterator().next();
    } else {
        firstBroaderConcept = null;
    }
    return firstBroaderConcept;
}

From source file:org.jboss.as.test.integration.logging.formatters.JsonFormatterTestCase.java

private static void validateDefault(final JsonObject json, final Collection<String> expectedKeys,
        final String expectedMessage) {
    final Set<String> remainingKeys = new HashSet<>(json.keySet());

    // Check all the expected keys
    for (String key : expectedKeys) {
        checkNonNull(json, key);/*  w  ww.j a  v a  2 s.com*/
        Assert.assertTrue("Missing key " + key + " from JSON object: " + json, remainingKeys.remove(key));
    }

    // Should have no more remaining keys
    Assert.assertTrue("There are remaining keys that were not validated: " + remainingKeys,
            remainingKeys.isEmpty());

    Assert.assertEquals("org.jboss.logging.Logger", json.getString("loggerClassName"));
    Assert.assertEquals(LoggingServiceActivator.LOGGER.getName(), json.getString("loggerName"));
    Assert.assertTrue("Invalid level found in " + json.get("level"), isValidLevel(json.getString("level")));
    Assert.assertEquals(expectedMessage, json.getString("message"));
}