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:com.bibisco.manager.SceneTagsManager.java

/**
 * @return a Map as/*from w w w .j a  va2 s .c o  m*/
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - character.1 -     X         X
 * - character.2 -               X
 * - character.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getCharactersChaptersPresence() {

    Map<String, List<Boolean>> lMapCharacterChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getCharactersChaptersDistribution()");

    List<com.bibisco.bean.CharacterDTO> lListCharacterDTO = CharacterManager.loadAll();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    if (CollectionUtils.isEmpty(lListCharacterDTO) || CollectionUtils.isEmpty(lListChapters)) {
        mLog.debug("End getStrandsChaptersDistribution()");
        return lMapCharacterChapterPresence;
    }

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, id_character");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<Integer>> lMapCharactersChaptersDistribution = new HashMap<Integer, Set<Integer>>();
            int lIntLastChapter = -1;
            Set<Integer> lSetChapterCharacters = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterCharacters = new HashSet<Integer>();
                    lMapCharactersChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterCharacters);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getIdCharacter() != null) {
                    lSetChapterCharacters.add(lVSceneTags.getIdCharacter().intValue());
                }
            }

            // populate result map
            for (CharacterDTO lCharacterDTO : lListCharacterDTO) {
                List<Boolean> lListCharacterChapterPresence = new ArrayList<Boolean>();
                lMapCharacterChapterPresence.put(lCharacterDTO.getIdCharacter().toString(),
                        lListCharacterChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<Integer> lSetCharacters = lMapCharactersChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetCharacters != null && !lSetCharacters.isEmpty()
                            && lSetCharacters.contains(lCharacterDTO.getIdCharacter())) {
                        lListCharacterChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListCharacterChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getCharactersChaptersDistribution()");

    return lMapCharacterChapterPresence;
}

From source file:com.bibisco.manager.SceneTagsManager.java

/**
 * @return a Map as/*from   www  .j  a  v  a  2s .  c o  m*/
 * 
 *                 Chapter.1 Chapter.2 Chapter.3
 * - pointOfView.1 -     X         X
 * - pointOfView.2 -               X
 * - pointOfView.3 -     X         X          
 * 
 */
public static Map<String, List<Boolean>> getPointOfViewsChaptersPresence() {

    Map<String, List<Boolean>> lMapPointOfViewChapterPresence = new HashMap<String, List<Boolean>>();

    mLog.debug("Start getPointOfViewsChaptersDistribution()");

    List<PointOfView4AnalysisDTO> lListPointOfViewDTO = getPointOfView4AnalysisList();
    List<ChapterDTO> lListChapters = ChapterManager.loadAll();

    SqlSessionFactory lSqlSessionFactory = SqlSessionFactoryManager.getInstance().getSqlSessionFactoryProject();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {

        VSceneTagsMapper lVSceneTagsMapper = lSqlSession.getMapper(VSceneTagsMapper.class);
        VSceneTagsExample lVSceneTagsExample = new VSceneTagsExample();
        lVSceneTagsExample.setOrderByClause("chapter_position, point_of_view, point_of_view_id_character");
        List<VSceneTags> lListVSceneTags = lVSceneTagsMapper.selectByExample(lVSceneTagsExample);

        if (lListVSceneTags != null && lListVSceneTags.size() > 0) {

            Map<Integer, Set<String>> lMapPointOfViewsChaptersDistribution = new HashMap<Integer, Set<String>>();
            int lIntLastChapter = -1;
            Set<String> lSetChapterPointOfViews = null;

            // filter duplicate items using a set
            for (VSceneTags lVSceneTags : lListVSceneTags) {
                if (lVSceneTags.getChapterPosition().intValue() != lIntLastChapter) {
                    lSetChapterPointOfViews = new HashSet<String>();
                    lMapPointOfViewsChaptersDistribution.put(lVSceneTags.getChapterPosition(),
                            lSetChapterPointOfViews);
                    lIntLastChapter = lVSceneTags.getChapterPosition();
                }
                if (lVSceneTags.getPointOfView() != null) {
                    lSetChapterPointOfViews.add(lVSceneTags.getIdPointOfView4Analysis());
                }
            }

            // populate result map
            for (PointOfView4AnalysisDTO lPointOfView4AnalysisDTO : lListPointOfViewDTO) {
                List<Boolean> lListPointOfViewChapterPresence = new ArrayList<Boolean>();
                lMapPointOfViewChapterPresence.put(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis(),
                        lListPointOfViewChapterPresence);
                for (ChapterDTO lChapterDTO : lListChapters) {
                    Set<String> lSetPointOfViews = lMapPointOfViewsChaptersDistribution
                            .get(lChapterDTO.getPosition());
                    if (lSetPointOfViews != null && !lSetPointOfViews.isEmpty() && lSetPointOfViews
                            .contains(lPointOfView4AnalysisDTO.getIdPointOfView4Analysis())) {
                        lListPointOfViewChapterPresence.add(Boolean.TRUE);
                    } else {
                        lListPointOfViewChapterPresence.add(Boolean.FALSE);
                    }
                }
            }
        }

    } catch (Throwable t) {
        mLog.error(t);
        throw new BibiscoException(t, BibiscoException.SQL_EXCEPTION);
    } finally {
        lSqlSession.close();
    }

    mLog.debug("End getPointOfViewsChaptersDistribution()");

    return lMapPointOfViewChapterPresence;
}

From source file:ch.algotrader.esper.EsperTestBase.java

protected static void deployModule(final EPServiceProvider epServiceProvider, final URL resource,
        final String... includedStatements) throws IOException, ParseException {

    Set<String> statementNames = new LinkedHashSet<>();
    for (String includedStatement : includedStatements) {
        statementNames.add(includedStatement);
    }//  w  ww  .  j  av a 2s. co m
    Module module = load(resource, "unit-test");
    EPAdministrator epAdministrator = epServiceProvider.getEPAdministrator();
    for (ModuleItem moduleItem : module.getItems()) {
        String expression = moduleItem.getExpression();
        EPStatementObjectModel compiledStatement = epAdministrator.compileEPL(expression);
        boolean included = true;
        if (!statementNames.isEmpty()) {
            for (AnnotationPart annotationPart : compiledStatement.getAnnotations()) {
                if (annotationPart.getName().equals("Name")) {
                    for (AnnotationAttribute attribute : annotationPart.getAttributes()) {
                        if (attribute.getName().equals("value")) {
                            Object name = attribute.getValue();
                            included = statementNames.contains(name);
                            break;
                        }
                    }
                    break;
                }
            }
        }
        if (included) {
            epAdministrator.create(compiledStatement);
        }
    }
}

From source file:org.eclipse.cft.server.core.internal.CloudUtil.java

/**
 * Creates a partial war file containing only the resources listed in the
 * list to filter in. Note that at least one content must be present in the
 * list to filter in, otherwise null is returned.
 * @param resources/* w w  w .ja  va2 s .  c om*/
 * @param module
 * @param server
 * @param monitor
 * @return partial war file with resources specified in the filter in list,
 * or null if filter list is empty or null
 * @throws CoreException
 */
public static File createWarFile(List<IModuleResource> allResources, IModule module,
        Set<IModuleResource> filterInResources, IProgressMonitor monitor) throws CoreException {
    if (allResources == null || allResources.isEmpty() || filterInResources == null
            || filterInResources.isEmpty()) {
        return null;
    }
    List<IStatus> result = new ArrayList<IStatus>();
    try {
        File tempDirectory = getTempFolder(module);
        // tempFile needs to be in the same location as the war file
        // otherwise PublishHelper will fail
        String fileName = module.getName() + ".war"; //$NON-NLS-1$

        File warFile = new File(tempDirectory, fileName);
        warFile.createNewFile();
        warFile.deleteOnExit();
        List<IModuleResource> newResources = new ArrayList<IModuleResource>();
        for (IModuleResource mr : allResources) {
            newResources.add(processModuleResource(mr));
        }

        IStatus[] status = publishZip(allResources, warFile, filterInResources, monitor);
        merge(result, status);
        throwException(result, "Publishing of : " + module.getName() + " failed"); //$NON-NLS-1$ //$NON-NLS-2$

        return warFile;
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, CloudFoundryPlugin.PLUGIN_ID,
                "Failed to create war file: " + e.getMessage(), e)); //$NON-NLS-1$
    }
}

From source file:com.etsy.arbiter.workflow.WorkflowGraphBuilder.java

/**
 * Recursively insert fork/joins for connected subcomponents of a graph
 *
 * @param vertices The set of vertices to process
 * @param parentGraph The parentGraph graph of these vertices
 * @return DirectedAcyclicGraph A new graph containing all the given vertices with appropriate fork/join pairs inserted
 * @throws WorkflowGraphException/*  w  w w.j av  a2  s  .c  o  m*/
 * @throws DirectedAcyclicGraph.CycleFoundException
 */
private static DirectedAcyclicGraph<Action, DefaultEdge> buildComponentGraph(Set<Action> vertices,
        DirectedAcyclicGraph<Action, DefaultEdge> parentGraph)
        throws WorkflowGraphException, DirectedAcyclicGraph.CycleFoundException {
    DirectedAcyclicGraph<Action, DefaultEdge> subgraph = buildSubgraph(parentGraph, vertices);

    // Start by pulling out the vertices with no incoming edges
    // These can run in parallel in a fork-join
    Set<Action> initialNodes = new HashSet<>();
    for (Action vertex : subgraph.vertexSet()) {
        if (subgraph.inDegreeOf(vertex) == 0) {
            initialNodes.add(vertex);
        }
    }

    DirectedAcyclicGraph<Action, DefaultEdge> result = new DirectedAcyclicGraph<>(DefaultEdge.class);

    if (initialNodes.isEmpty()) {
        // This is a very odd case, but just in case we'll fail if it happens
        throw new WorkflowGraphException("No nodes with inDegree = 0 found.  This shouldn't happen.");
    } else if (initialNodes.size() == 1) {
        // If there is only one node, we can't put it in a fork/join
        // In this case we'll add just that vertex to the resulting graph
        Action vertex = initialNodes.iterator().next();
        result.addVertex(vertex);
        // Remove the processed vertex so that we have new unprocessed subcomponents
        subgraph.removeVertex(vertex);
    } else {
        // If there are multiple nodes, insert a fork/join pair to run them in parallel
        Pair<Action, Action> forkJoin = addForkJoin(result);
        Action fork = forkJoin.getLeft();
        Action join = forkJoin.getRight();
        for (Action vertex : initialNodes) {
            result.addVertex(vertex);
            result.addDagEdge(fork, vertex);
            result.addDagEdge(vertex, join);
            // Remove the processed vertex so that we have new unprocessed subcomponents
            subgraph.removeVertex(vertex);
        }
    }

    // Now recursively process the graph with the processed nodes removed
    Triple<DirectedAcyclicGraph<Action, DefaultEdge>, Action, Action> subComponentGraphTriple = processSubcomponents(
            subgraph);
    DirectedAcyclicGraph<Action, DefaultEdge> subComponentGraph = subComponentGraphTriple.getLeft();

    // Having processed the subcomponents, we attach the "last" node of the graph created here to
    // the "first" node of the subcomponent graph
    Action noIncoming = subComponentGraphTriple.getMiddle();
    Action noOutgoing = null;

    for (Action vertex : result.vertexSet()) {
        if (noOutgoing == null && result.outDegreeOf(vertex) == 0) {
            noOutgoing = vertex;
        }
    }

    Graphs.addGraph(result, subComponentGraph);
    if (noOutgoing != null && noIncoming != null && !noOutgoing.equals(noIncoming)) {
        result.addDagEdge(noOutgoing, noIncoming);
    }
    return result;
}

From source file:com.streamsets.datacollector.definition.StageDefinitionExtractor.java

public static List<String> getGroups(Class<? extends Stage> klass) {
    Set<String> set = new LinkedHashSet<>();
    addGroupsToList(klass, set);/* w ww . j  av a  2s.  c  o m*/
    List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass);
    for (Class<?> superClass : allSuperclasses) {
        if (!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) {
            addGroupsToList(superClass, set);
        }
    }
    if (set.isEmpty()) {
        set.add(""); // the default empty group
    }

    return new ArrayList<>(set);
}

From source file:com.baomidou.mybatisplus.toolkit.PackageHelper.java

/**
 * <p>/*from  w  w  w .  j a v  a2 s  .c om*/
 * ???
 * </p>
 * <p>
 * <property name="typeAliasesPackage" value="com.baomidou.*.entity"/>
 * </p>
 * 
 * @param typeAliasesPackage
 *            ??
 * @return
 */
public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
    ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
    String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
            + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";

    /*
     * ??Resource
     * ClassLoader.getResource("META-INF")?????????
     */
    try {
        Set<String> set = new HashSet<String>();
        Resource[] resources = resolver.getResources(pkg);
        if (resources != null && resources.length > 0) {
            MetadataReader metadataReader = null;
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    set.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage()
                            .getName());
                }
            }
        }
        if (!set.isEmpty()) {
            return set.toArray(new String[] {});
        } else {
            throw new MybatisPlusException("not find typeAliasesPackage:" + pkg);
        }
    } catch (Exception e) {
        throw new MybatisPlusException("not find typeAliasesPackage:" + pkg, e);
    }
}

From source file:com.ndemyanovskyi.backend.DataManager.java

/**
 * Loaded rate from any exist site./*  w  ww  .  j  ava2  s .c  o  m*/
 * @param <R> rate type
 * @param bank any bank, not null.
 * @param currency currency, supported by bank, not null.
 * @param date any date in bounds from minimum to today date, not null.
 * @return loaded rate, not null
 * @throws IOException for any io error.
 * @throws DocumentParseException if document from the last exist site can`t be parsed, or parsed elements count equals zero.
 */
public static <R extends Rate> R loadRate(Bank<R> bank, Currency currency, LocalDate date)
        throws IOException, DocumentParseException {
    if (bank.getSite() != null) {
        Set<InterbankSite> sites = Site.supported(InterbankSite.class, bank);
        BankSiteLoader<R> loader = BankSiteLoader.of(bank, date);

        try {
            R rate = loader.sync().get(currency);
            if (rate != null || sites.isEmpty())
                return rate;
        } catch (IOException ex) {
            if (sites.isEmpty())
                throw ex;
        }
    }

    InterbankSiteLoader<R> loader = InterbankSiteLoader.of(currency, date);
    R rate = loader.subscribe(bank);
    if (rate != null)
        return rate;

    String errorMessage = String.format(
            "Rate can`t be loaded on any exists sites (date = %s, bank = %s, currency = %s", date, bank,
            currency);
    LOG.log(Level.SEVERE, errorMessage);
    throw new IOException(errorMessage);
}

From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java

static Map<String, Integer> prepareBestMatchByLabel(Set<String> excelColumnNames,
        Map<String, Integer> previousMappings, Locale locale) {
    if (excelColumnNames == null) {
        return previousMappings;
    }//from w ww  .j  av  a 2s .c  o  m
    //do not match the previously matched columns
    excelColumnNames.removeAll(previousMappings.keySet());

    if (!excelColumnNames.isEmpty()) {
        //match by localized config labels
        addMatch(excelColumnNames, getLocalizedDefaultFieldConfigsMap(locale), previousMappings);
    }
    if (!excelColumnNames.isEmpty()) {
        //match by not localized config labels
        addMatch(excelColumnNames, getDefaultFieldConfigsMap(), previousMappings);
    }
    if (!excelColumnNames.isEmpty()) {
        //match by field names
        addMatch(excelColumnNames, getFieldNameBasedFieldConfigsMap(), previousMappings);
    }
    return previousMappings;
}

From source file:fr.paris.lutece.plugins.extend.modules.comment.web.CommentApp.java

/**
 * Builds the stop message./*from w w w. ja  va2s.c om*/
 * 
 * @param <A> the generic type
 * @param listErrors the list errors
 * @return the string
 */
private static <A> String buildStopMessage(Set<ConstraintViolation<A>> listErrors) {
    StringBuilder sbError = new StringBuilder();

    if ((listErrors != null) && !listErrors.isEmpty()) {
        for (ConstraintViolation<A> error : listErrors) {
            sbError.append(error.getMessage());
            sbError.append(HTML_BR);
        }
    }

    return sbError.toString();
}