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:jease.cms.web.content.ContentTableModel.java

private void visibilityChangePerformed(Content content, Checkbox checkbox) {
    // Change visibility for actual selected item
    content.setVisible(checkbox.isChecked());
    nodes.save(content);/*from  ww w. ja  va  2 s.  com*/

    // Change visibility for multiple selected items
    Listcell listcell = (Listcell) checkbox.getParent();
    Listbox listbox = (Listbox) listcell.getListbox();
    Set<Listitem> selectedItems = listbox.getSelectedItems();
    if (!selectedItems.isEmpty()) {
        for (Listitem item : listbox.getSelectedItems()) {
            Content node = item.getValue();
            node.setVisible(checkbox.isChecked());
            nodes.save(node);
        }
        listbox.clearSelection();
        ((ContainerTable) listbox.getParent()).refresh();
    }
}

From source file:com.migratebird.config.FactoryContext.java

public ScriptRepository createScriptRepository() {
    Set<String> scriptLocationIndicators = config.getScriptLocations();
    if (scriptLocationIndicators.isEmpty()) {
        throw new MigrateBirdException("Unable to find scripts. No script locations specified.");
    }//  w w w . j  a  v  a2 s.  c o m
    Set<ScriptLocation> scriptLocations = new HashSet<ScriptLocation>();
    for (String scriptLocationIndicator : scriptLocationIndicators) {
        scriptLocations.add(createScriptLocation(scriptLocationIndicator));
    }
    QualifierEvaluator qualifierEvaluator = createQualifierEvaluator(scriptLocations);
    return new ScriptRepository(scriptLocations, qualifierEvaluator);
}

From source file:io.seldon.recommendation.baseline.jdo.SqlStaticRecommendationsProvider.java

@Override
public Map<Long, Double> getStaticRecommendations(long userId, Set<Integer> dimensions, int max) {
    Collection<Object[]> results;
    Query query;/*  ww  w.  j  a  v  a 2s  . co  m*/
    if (dimensions.isEmpty()
            || (dimensions.size() == 1 && dimensions.iterator().next() == Constants.DEFAULT_DIMENSION)) {
        String sql = "select item_id,score from recommendations where user_id=? order by score desc";
        if (max > 0)
            sql = sql + " limit " + max;
        query = getPM().newQuery("javax.jdo.query.SQL", sql);
        ArrayList<Object> args = new ArrayList<>();
        args.add(userId);
        results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    } else {
        String dimensionsStr = StringUtils.join(dimensions, ",");
        String sql = "select recs.item_id,score from recommendations recs join item_map_enum ime on (recs.item_id=ime.item_id) join dimension d on (ime.attr_id=d.attr_id and ime.value_id=d.value_id) where dim_id in ("
                + dimensionsStr + ") and recs.user_id=? order by score desc";
        if (max > 0)
            sql = sql + " limit " + max;
        query = getPM().newQuery("javax.jdo.query.SQL", sql);
        ArrayList<Object> args = new ArrayList<>();
        args.add(userId);
        results = (Collection<Object[]>) query.executeWithArray(args.toArray());
    }
    Map<Long, Double> map = new HashMap<>();
    for (Object[] res : results) {
        Long item = (Long) res[0];
        Double score = (Double) res[1];
        map.put(item, score);
    }
    query.closeAll();
    return map;
}

From source file:edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.JoinedOntModelCache.java

public JoinedOntModelCache(OntModelCache primary, OntModelCache secondary) {
    this.primary = primary;
    this.secondary = secondary;

    Set<String> duplicateNames = new HashSet<>(primary.getModelNames());
    duplicateNames.retainAll(secondary.getModelNames());
    if (!duplicateNames.isEmpty()) {
        log.warn("These model names appear in both caches: " + duplicateNames);
    }/*from   w ww . j av  a2  s. c o m*/
}

From source file:org.elasticsearch.xpack.security.authc.saml.SamlRealm.java

private static List<X509Credential> buildCredential(RealmConfig config, X509KeyPairSettings keyPairSettings,
        Setting<String> aliasSetting, final boolean allowMultiple) {
    final X509KeyManager keyManager = CertParsingUtils.getKeyManager(keyPairSettings, config.settings(), null,
            config.env());/*from   www.java  2  s. co m*/

    if (keyManager == null) {
        return null;
    }

    final Set<String> aliases = new HashSet<>();
    final String configuredAlias = aliasSetting.get(config.settings());
    if (Strings.isNullOrEmpty(configuredAlias)) {

        final String[] serverAliases = keyManager.getServerAliases("RSA", null);
        if (serverAliases != null) {
            aliases.addAll(Arrays.asList(serverAliases));
        }

        if (aliases.isEmpty()) {
            throw new IllegalArgumentException("The configured key store for "
                    + RealmSettings.getFullSettingKey(config, keyPairSettings.getPrefix())
                    + " does not contain any RSA key pairs");
        } else if (allowMultiple == false && aliases.size() > 1) {
            throw new IllegalArgumentException("The configured key store for "
                    + RealmSettings.getFullSettingKey(config, keyPairSettings.getPrefix())
                    + " has multiple keys but no alias has been specified (from setting "
                    + RealmSettings.getFullSettingKey(config, aliasSetting) + ")");
        }
    } else {
        aliases.add(configuredAlias);
    }

    final List<X509Credential> credentials = new ArrayList<>();
    for (String alias : aliases) {
        if (keyManager.getPrivateKey(alias) == null) {
            throw new IllegalArgumentException("The configured key store for "
                    + RealmSettings.getFullSettingKey(config, keyPairSettings.getPrefix())
                    + " does not have a key associated with alias [" + alias + "] "
                    + ((Strings.isNullOrEmpty(configuredAlias) == false)
                            ? "(from setting " + RealmSettings.getFullSettingKey(config, aliasSetting) + ")"
                            : ""));
        }

        final String keyType = keyManager.getPrivateKey(alias).getAlgorithm();
        if (keyType.equals("RSA") == false) {
            throw new IllegalArgumentException("The key associated with alias [" + alias + "] "
                    + "(from setting " + RealmSettings.getFullSettingKey(config, aliasSetting)
                    + ") uses unsupported key algorithm type [" + keyType + "], only RSA is supported");
        }
        credentials.add(new X509KeyManagerX509CredentialAdapter(keyManager, alias));
    }

    return credentials;
}

From source file:com.nike.cerberus.validation.IamPrincipalPermissionsValidator.java

public boolean isValid(Set<IamPrincipalPermission> iamRolePermissionSet, ConstraintValidatorContext context) {
    if (iamRolePermissionSet == null || iamRolePermissionSet.isEmpty()) {
        return true;
    }//from   w w w.  j  av  a2  s  .  c  o  m

    boolean isValid = true;
    Set<String> iamRoles = new HashSet<>();

    for (IamPrincipalPermission iamRolePermission : iamRolePermissionSet) {
        final String key = buildKey(iamRolePermission);
        if (iamRoles.contains(key)) {
            isValid = false;
            break;
        } else {
            iamRoles.add(key);
        }
    }

    return isValid;
}

From source file:ru.mystamps.web.dao.impl.JdbcStampsCatalogDao.java

public void addToSeries(Integer seriesId, Set<String> catalogNumbers) {
    Validate.validState(seriesId != null, "Series id must be non null");
    Validate.validState(!catalogNumbers.isEmpty(), "Catalog numbers must be non empty");
    Validate.validState(!"".equals(addCatalogNumbersToSeriesSql), "Query must be non empty");

    Map<String, Object> params = new HashMap<>();
    params.put("series_id", seriesId);
    params.put("numbers", catalogNumbers);

    jdbcTemplate.update(addCatalogNumbersToSeriesSql, params);
}

From source file:com.edduarte.vokter.job.MatchingJob.java

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {

    JobKey key = context.getJobDetail().getKey();
    String responseUrl = key.getName();
    JobDataMap dataMap = context.getJobDetail().getJobDataMap();

    String managerName = dataMap.getString(PARENT_JOB_MANAGER);
    JobManager manager = JobManager.get(managerName);
    if (manager == null) {
        return;//from  w w  w  .  ja v a2s.com
    }

    String requestUrl = dataMap.getString(REQUEST_URL);

    try {
        ObjectMapper mapper = new ObjectMapper();
        List<String> keywords = mapper.readValue(dataMap.getString(KEYWORDS), ArrayList.class);
        boolean hasNewDifferences = dataMap.getBoolean(HAS_NEW_DIFFS);
        boolean ignoreAdded = dataMap.getBoolean(IGNORE_ADDED);
        boolean ignoreRemoved = dataMap.getBoolean(IGNORE_REMOVED);

        if (hasNewDifferences) {
            dataMap.put(HAS_NEW_DIFFS, false);

            // build keywords
            List<Keyword> kws = keywords.stream().map(manager::callBuildKeyword).collect(Collectors.toList());

            // match them
            List<Difference> diffs = manager.callGetDiffsImpl(requestUrl);
            DifferenceMatcher matcher = new DifferenceMatcher(kws, diffs, ignoreAdded, ignoreRemoved);
            Set<DifferenceMatcher.Result> results = matcher.call();
            if (!results.isEmpty()) {
                manager.responseOk(requestUrl, responseUrl, results);
            }
        }
    } catch (IOException ex) {
        logger.error(ex.getMessage(), ex);
    }
}

From source file:com.acc.conv.Oauth2AccessTokenConverter.java

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writerOrig,
        final MarshallingContext context) {
    final OAuth2AccessToken token = (OAuth2AccessToken) source;
    final ExtendedHierarchicalStreamWriter writer = (ExtendedHierarchicalStreamWriter) writerOrig
            .underlyingWriter();/*from w  w w  .j a v  a2s.  c o  m*/

    writer.startNode(OAuth2AccessToken.ACCESS_TOKEN, String.class);
    writer.setValue(formattedValue(token.getValue()));
    writer.endNode();

    writer.startNode(OAuth2AccessToken.TOKEN_TYPE, String.class);
    writer.setValue(formattedValue(token.getTokenType()));
    writer.endNode();

    final OAuth2RefreshToken refreshToken = token.getRefreshToken();
    if (refreshToken != null) {
        writer.startNode(OAuth2AccessToken.REFRESH_TOKEN, String.class);
        writer.setValue(formattedValue(refreshToken.getValue()));
        writer.endNode();

    }
    final Date expiration = token.getExpiration();
    if (expiration != null) {
        final long now = System.currentTimeMillis();
        writer.startNode(OAuth2AccessToken.EXPIRES_IN, Integer.class);
        writer.setValue(String.valueOf((expiration.getTime() - now) / 1000));
        writer.endNode();
    }
    final Set<String> scope = token.getScope();
    if (scope != null && !scope.isEmpty()) {
        final StringBuffer scopes = new StringBuffer();
        for (final String s : scope) {
            Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope);
            scopes.append(s);
            scopes.append(' ');
        }

        writer.startNode(OAuth2AccessToken.SCOPE, String.class);
        writer.setValue(formattedValue(scopes.substring(0, scopes.length() - 1)));
        writer.endNode();
    }
    final Map<String, Object> additionalInformation = token.getAdditionalInformation();
    for (final String key : additionalInformation.keySet()) {
        writer.startNode(key, String.class);
        writer.setValue(formattedValue(String.valueOf(additionalInformation.get(key))));
        writer.endNode();
    }
}

From source file:com.bstek.dorado.view.TopViewOutputter.java

@Override
public void output(Object object, OutputContext context) throws Exception {
    View view = (View) object;
    if (StringUtils.isEmpty(view.getId())) {
        view.setId("viewMain");
    }/*  w w  w.  j  a va 2 s.  c o m*/

    context.addDependsPackage("widget");

    DoradoContext doradoContext = DoradoContext.getCurrent();
    int currentClientType = VariantUtils.toInt(doradoContext.getAttribute(ClientType.CURRENT_CLIENT_TYPE_KEY));
    if ((currentClientType == 0 || ClientType.supports(currentClientType, ClientType.DESKTOP))
            && WebConfigure.getBoolean("view.debugEnabled")) {
        context.addDependsPackage("debugger");
    }

    Writer writer = context.getWriter();
    writer.append("dorado.onInit(function(){\n");
    writer.append("try{\n");

    ViewOutputter outputter = (ViewOutputter) clientOutputHelper.getOutputter(view.getClass());
    outputter.outputView(view, context);

    writer.append("view.set(\"renderOn\",\"#doradoView\");\n");

    ViewRenderMode renderMode = view.getRenderMode();
    if (renderMode == ViewRenderMode.onCreate) {
        writer.append("view.render();\n");
    } else if (renderMode == ViewRenderMode.onDataLoaded) {
        writer.append("view.loadData();\n");
    }

    writer.append("}\n").append("catch(e){").append("dorado.Exception.processException(e);}\n");
    writer.append("});\n");

    context.addDependsPackage("common");

    Set<String> dependsPackages = context.getDependsPackages();
    if (dependsPackages != null && !dependsPackages.isEmpty()) {
        writer.append("$import(\"").append(StringUtils.join(dependsPackages, ',')).append("\");\n");
    }
}