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:gov.nih.nci.caarray.application.translation.magetab.TermSourceTranslator.java

/**
 * @param name//from  w  w  w  .j a  v a  2 s.  c  o m
 * @return
 */
private TermSource lookupSourceByNameOnly(String name) {
    Set<TermSource> matches = vocabularyService.getSources(name);
    if (!matches.isEmpty()) {
        return getBestMatch(matches);
    } else {
        TermSource newSource = new TermSource();
        newSource.setName(name);
        return newSource;
    }
}

From source file:net.minecraftforge.common.crafting.CraftingHelper.java

public static ShapedPrimer parseShaped(Object... recipe) {
    ShapedPrimer ret = new ShapedPrimer();
    String shape = "";
    int idx = 0;//from   w  w  w  . j  a  v  a  2  s.  c o  m

    if (recipe[idx] instanceof Boolean) {
        ret.mirrored = (Boolean) recipe[idx];
        if (recipe[idx + 1] instanceof Object[])
            recipe = (Object[]) recipe[idx + 1];
        else
            idx = 1;
    }

    if (recipe[idx] instanceof String[]) {
        String[] parts = ((String[]) recipe[idx++]);

        for (String s : parts) {
            ret.width = s.length();
            shape += s;
        }

        ret.height = parts.length;
    } else {
        while (recipe[idx] instanceof String) {
            String s = (String) recipe[idx++];
            shape += s;
            ret.width = s.length();
            ret.height++;
        }
    }

    if (ret.width * ret.height != shape.length() || shape.length() == 0) {
        String err = "Invalid shaped recipe: ";
        for (Object tmp : recipe) {
            err += tmp + ", ";
        }
        throw new RuntimeException(err);
    }

    HashMap<Character, Ingredient> itemMap = Maps.newHashMap();
    itemMap.put(' ', Ingredient.EMPTY);

    for (; idx < recipe.length; idx += 2) {
        Character chr = (Character) recipe[idx];
        Object in = recipe[idx + 1];
        Ingredient ing = CraftingHelper.getIngredient(in);

        if (' ' == chr.charValue())
            throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");

        if (ing != null) {
            itemMap.put(chr, ing);
        } else {
            String err = "Invalid shaped ore recipe: ";
            for (Object tmp : recipe) {
                err += tmp + ", ";
            }
            throw new RuntimeException(err);
        }
    }

    ret.input = NonNullList.withSize(ret.width * ret.height, Ingredient.EMPTY);

    Set<Character> keys = Sets.newHashSet(itemMap.keySet());
    keys.remove(' ');

    int x = 0;
    for (char chr : shape.toCharArray()) {
        Ingredient ing = itemMap.get(chr);
        if (ing == null)
            throw new IllegalArgumentException(
                    "Pattern references symbol '" + chr + "' but it's not defined in the key");
        ret.input.set(x++, ing);
        keys.remove(chr);
    }

    if (!keys.isEmpty())
        throw new IllegalArgumentException("Key defines symbols that aren't used in pattern: " + keys);

    return ret;
}

From source file:com.github.jrrdev.mantisbtsync.core.jobs.projects.decider.ProjectFlowDecider.java

/**
 * {@inheritDoc}/*from w  ww.j a v  a2s. co  m*/
 *
 * @see org.springframework.batch.core.job.flow.JobExecutionDecider#decide(org.springframework.batch.core.JobExecution, org.springframework.batch.core.StepExecution)
 */
@Override
public FlowExecutionStatus decide(final JobExecution jobExecution, final StepExecution stepExecution) {

    final Set<BigInteger> projectsId = (Set<BigInteger>) jobExecution.getExecutionContext()
            .get("mantis.loop.projects_to_process");

    if (projectsId != null && !projectsId.isEmpty()) {
        return new FlowExecutionStatus("LOOP");
    } else {
        return new FlowExecutionStatus("END_LOOP");
    }
}

From source file:com.rsone.util.JobLauncherSynchronizer.java

@Before("execution(* org.springframework.batch..JobLauncher+.*(..)) && args(job,..)")
public void checkJobBeforeLaunch(Job job) throws JobExecutionAlreadyRunningException {
    String jobName = job.getName();
    logger.debug("Checking for synchronization on Job: " + jobName);
    if (!jobNames.contains(jobName)) {
        logger.debug("Not synchronizing Job: " + jobName);
        return;//from   ww  w  .  ja v  a 2  s .com
    }
    Set<JobExecution> running = jobExplorer.findRunningJobExecutions(jobName);
    if (!running.isEmpty()) {
        throw new JobExecutionAlreadyRunningException("An instance of this job is already active: " + jobName);
    }
    logger.debug("Job checked and no duplicates detected: " + jobName);
}

From source file:com.smhdemo.common.report.service.ChartService.java

@Override
public void delChart(Long pk) {
    Chart chartReport = chartDao.get(pk);
    Assert.notNull(chartReport);//w  w  w .  j  a v  a  2 s  . c  o  m
    List<Category> categories = chartDao.findCategoryReportByChartReportId(pk);
    if (categories != null && !categories.isEmpty()) {
        for (Category category : categories) {
            Set<Chart> charts = category.getChartReports();
            if (charts.isEmpty())
                continue;
            charts.remove(chartReport);
            category.setChartReports(charts);
            categoryDao.merge(category);
        }
    }
    //      List<EwcmsJobReport> ewcmsJobReports = chartDao.findEwcmsJobReportByChartReportId(chartReportId);
    //      if (ewcmsJobReports != null && !ewcmsJobReports.isEmpty()){
    //         for (EwcmsJobReport ewcmsJobReport : ewcmsJobReports){
    //            if (ewcmsJobReport.getTextReport() == null) {
    //               ewcmsJobReportDAO.remove(ewcmsJobReport);
    //            }else{
    //               ewcmsJobReport.setChartReport(null);
    //               ewcmsJobReportDAO.merge(ewcmsJobReport);
    //            }
    //         }
    //      }
    chartDao.removeByPK(pk);
}

From source file:de.ingrid.server.security.IngridRealm.java

@Override
public Principal authenticate(final String userName, final Object password, final Request request) {

    Principal principal = null;//from   www .  j  av a 2s .  c o m
    try {
        final RequestCallbackHandler handler = new RequestCallbackHandler(request);
        final LoginContext loginContext = new LoginContext("IngridLogin", handler);
        loginContext.login();
        final Subject subject = loginContext.getSubject();
        final Set<Principal> principals = subject.getPrincipals();
        final Principal tmpPrincipal = principals.isEmpty() ? principal : principals.iterator().next();
        if (tmpPrincipal instanceof KnownPrincipal) {
            final KnownPrincipal knownPrincipal = (KnownPrincipal) tmpPrincipal;
            knownPrincipal.setLoginContext(loginContext);
            principal = knownPrincipal;
            LOG.info("principal has logged in: " + principal);
        }
    } catch (final LoginException e) {
        LOG.error("login error for user: " + userName);
    }
    if (principal == null) {
        LOG.info("login failed for userName: " + userName);
    }
    return principal;
}

From source file:de.micromata.genome.gwiki.plugin.blog_1_0.GWikiBlogBaseActionBean.java

public void renderBlogCatHeader() {
    Set<String> cats = getBlogCategories();
    if (cats.isEmpty() == false) {
        String thisPl = wikiContext.localUrl(this.blogPageId);
        wikiContext.append("<div class=\"blogNavCats\">");
        wikiContext.append("<a href=\"" + thisPl + "?blogCategory=\">")
                .append(esc(translate("gwiki.blog.page.allCats"))).append("</a>");
        for (String cat : cats) {
            wikiContext.append("&nbsp;|&nbsp;");
            wikiContext.append("<a href=\"" + thisPl + "?blogCategory=" + Converter.encodeUrlParam(cat) + "\">"
                    + WebUtils.escapeHtml(cat) + "</a>");
        }//  w ww .j a v  a  2  s.com
        wikiContext.append("</div>\n");
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.executionCourse.EvaluationMethodDA.java

public ActionForward prepareEditEvaluationMethod(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    final ExecutionCourse executionCourse = (ExecutionCourse) request.getAttribute("executionCourse");
    EvaluationMethod evaluationMethod = executionCourse.getEvaluationMethod();
    MultiLanguageString evaluationElements = evaluationMethod == null ? null
            : evaluationMethod.getEvaluationElements();
    if (evaluationMethod == null || evaluationElements == null || evaluationElements.isEmpty()
            || StringUtils.isEmpty(evaluationElements.getContent())) {
        MultiLanguageString evaluationMethodMls = new MultiLanguageString();
        final Set<CompetenceCourse> competenceCourses = executionCourse.getCompetenceCourses();
        if (!competenceCourses.isEmpty()) {
            final CompetenceCourse competenceCourse = competenceCourses.iterator().next();
            final String pt = competenceCourse.getEvaluationMethod();
            final String en = competenceCourse.getEvaluationMethodEn();
            evaluationMethodMls = evaluationMethodMls.with(MultiLanguageString.pt, pt == null ? "" : pt)
                    .with(MultiLanguageString.en, en == null ? "" : en);
        }//www  .ja  v a 2  s . c om
        EditEvaluation.runEditEvaluation(executionCourse, evaluationMethodMls);
        evaluationMethod = executionCourse.getEvaluationMethod();
    }
    return forward(request, "/teacher/executionCourse/editEvaluationMethod.jsp");
}

From source file:com.khartec.waltz.service.orgunit.OrganisationalUnitService.java

private Node<OrganisationalUnit, Long> buildHierarchyTree(long orgUnitId,
        Collection<OrganisationalUnit> allInvolvedUnits) {
    List<FlatNode<OrganisationalUnit, Long>> allInvolvedAsFlatNodes = toFlatNodes(allInvolvedUnits);

    Forest<OrganisationalUnit, Long> unitForest = HierarchyUtilities.toForest(allInvolvedAsFlatNodes);

    Set<Node<OrganisationalUnit, Long>> rootNodes = unitForest.getRootNodes();
    checkFalse(rootNodes.isEmpty(), "Calculating tree for ouId: " + orgUnitId + " gave no root!?");
    checkTrue(rootNodes.size() == 1, "Calculating tree for ouId:" + orgUnitId + " gave more than one root!");
    return rootNodes.iterator().next();
}