Example usage for java.util Set toString

List of usage examples for java.util Set toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest.java

@Test
public void deleteCount() throws Exception {
    Set<String> ids = createArtifacts();

    long count = store.countDeleteChunks(Lists.newArrayList(ids), 0);

    Iterator<String> iter = store.getAllChunkIds(0);
    Set<String> ret = Sets.newHashSet();
    while (iter.hasNext()) {
        ret.add(iter.next());/*from  ww  w . j ava2 s.  com*/
    }

    assertTrue(ret.toString(), ret.isEmpty());
    assertEquals(ids.size(), count);
}

From source file:org.apache.james.postage.PostageRunner.java

/**
 * This method makes sure the test accounts exist in the target James Server.
 * If the account does not already exist then the account is created; 
 * if the account does exist, the method checks configuration 
 * to see if the account should be re-used or removed and re-added.
 * /*from  w ww .  j a va 2s  .  c  om*/
 * @throws StartupException
 */
private void setupInternalUserAccounts() throws StartupException {

    try {

        String host = this.postageConfiguration.getTestserverHost();
        int jmxPort = this.postageConfiguration.getTestserverPortJMXRemoting();
        int internalUserCount = this.postageConfiguration.getInternalUsers().getCount();
        String internalUsernamePrefix = this.postageConfiguration.getInternalUsers().getNamePrefix();
        String internalDomain = this.postageConfiguration.getInternalUsers().getDomain();
        String internalPassword = this.postageConfiguration.getInternalUsers().getPassword();

        // Make connection to the James server via JMX
        log.info("Connecting to host: " + host + ":" + jmxPort);
        ServerProbe serverManager = new JmxServerProbe(host, jmxPort);

        if (!serverManager.containsDomain(internalDomain)) {
            serverManager.addDomain(internalDomain);
        }

        // Collect the set of users already provisioned
        Set<String> existingUsers = new LinkedHashSet<String>(Arrays.asList(serverManager.listUsers()));
        log.info("Existing users: " + existingUsers.toString());

        // Check all the test accounts we need; if they don't exist then
        // create them; if they do exist then check if we should reuse or recreate
        ArrayList<String> internalUsers = new ArrayList<String>();
        for (int i = 1; i <= internalUserCount; i++) {
            String username = internalUsernamePrefix + i;
            String useremail = username + "@" + internalDomain;
            if (existingUsers.contains(useremail)) {
                log.info("user already exists: " + useremail);
                if (!this.postageConfiguration.isInternalReuseExisting()) {
                    serverManager.removeUser(useremail);
                    serverManager.addUser(useremail, internalPassword);
                    log.info("user deleted and re-created: " + useremail);
                }
                serverManager.setPassword(useremail, internalPassword);
            } else {
                log.info("Adding user: " + useremail);
                serverManager.addUser(useremail, internalPassword);
            }
            internalUsers.add(username);
        }

        this.postageConfiguration.getInternalUsers().setExistingUsers(internalUsers);

    } catch (Exception e) {
        throw new StartupException("error setting up internal user accounts", e);
    }

}

From source file:org.apache.kylin.cube.model.validation.rule.AggregationGroupRule.java

private void inner(CubeDesc cube, ValidateContext context) {

    if (cube.getAggregationGroups() == null || cube.getAggregationGroups().size() == 0) {
        context.addResult(ResultLevel.ERROR, "Cube should have at least one Aggregation group.");
        return;// www.j a va  2s .c om
    }

    int index = 0;
    for (AggregationGroup agg : cube.getAggregationGroups()) {
        if (agg.getIncludes() == null) {
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index + " 'includes' field not set");
            continue;
        }

        if (agg.getSelectRule() == null) {
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index + " 'select rule' field not set");
            continue;
        }

        Set<String> includeDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getIncludes() != null) {
            for (String include : agg.getIncludes()) {
                includeDims.add(include);
            }
        }

        Set<String> mandatoryDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().mandatoryDims != null) {
            for (String m : agg.getSelectRule().mandatoryDims) {
                mandatoryDims.add(m);
            }
        }

        Set<String> hierarchyDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().hierarchyDims != null) {
            for (String[] ss : agg.getSelectRule().hierarchyDims) {
                for (String s : ss) {
                    hierarchyDims.add(s);
                }
            }
        }

        Set<String> jointDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().jointDims != null) {
            for (String[] ss : agg.getSelectRule().jointDims) {
                for (String s : ss) {
                    jointDims.add(s);
                }
            }
        }

        if (!includeDims.containsAll(mandatoryDims) || !includeDims.containsAll(hierarchyDims)
                || !includeDims.containsAll(jointDims)) {
            List<String> notIncluded = Lists.newArrayList();
            final Iterable<String> all = Iterables
                    .unmodifiableIterable(Iterables.concat(mandatoryDims, hierarchyDims, jointDims));
            for (String dim : all) {
                if (includeDims.contains(dim) == false) {
                    notIncluded.add(dim);
                }
            }
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " 'includes' dimensions not include all the dimensions:" + notIncluded.toString());
            continue;
        }

        if (CollectionUtils.containsAny(mandatoryDims, hierarchyDims)) {
            Set<String> intersection = new HashSet<>(mandatoryDims);
            intersection.retainAll(hierarchyDims);
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " mandatory dimension has overlap with hierarchy dimension: " + intersection.toString());
            continue;
        }
        if (CollectionUtils.containsAny(mandatoryDims, jointDims)) {
            Set<String> intersection = new HashSet<>(mandatoryDims);
            intersection.retainAll(jointDims);
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " mandatory dimension has overlap with joint dimension: " + intersection.toString());
            continue;
        }

        int jointDimNum = 0;
        if (agg.getSelectRule().jointDims != null) {
            for (String[] joints : agg.getSelectRule().jointDims) {

                Set<String> oneJoint = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                for (String s : joints) {
                    oneJoint.add(s);
                }

                if (oneJoint.size() < 2) {
                    context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                            + " require at least 2 dimensions in a joint: " + oneJoint.toString());
                    continue;
                }
                jointDimNum += oneJoint.size();

                int overlapHierarchies = 0;
                if (agg.getSelectRule().hierarchyDims != null) {
                    for (String[] oneHierarchy : agg.getSelectRule().hierarchyDims) {
                        Set<String> share = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                        share.addAll(CollectionUtils.intersection(oneJoint, Arrays.asList(oneHierarchy)));

                        if (!share.isEmpty()) {
                            overlapHierarchies++;
                        }
                        if (share.size() > 1) {
                            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                                    + " joint dimensions has overlap with more than 1 dimensions in same hierarchy: "
                                    + share.toString());
                            continue;
                        }
                    }

                    if (overlapHierarchies > 1) {
                        context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                                + " joint dimensions has overlap with more than 1 hierarchies");
                        continue;
                    }
                }
            }

            if (jointDimNum != jointDims.size()) {

                Set<String> existing = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                Set<String> overlap = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                for (String[] joints : agg.getSelectRule().jointDims) {
                    Set<String> oneJoint = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                    for (String s : joints) {
                        oneJoint.add(s);
                    }
                    if (CollectionUtils.containsAny(existing, oneJoint)) {
                        overlap.addAll(CollectionUtils.intersection(existing, oneJoint));
                    }
                    existing.addAll(oneJoint);
                }
                context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                        + " a dimension exists in more than one joint: " + overlap.toString());
                continue;
            }
        }
        long combination = 0;
        try {
            combination = agg.calculateCuboidCombination();
        } catch (Exception ex) {
            combination = getMaxCombinations(cube) + 1;
        } finally {
            if (combination > getMaxCombinations(cube)) {
                String msg = "Aggregation group " + index
                        + " has too many combinations, current combination is " + combination
                        + ", max allowed combination is " + getMaxCombinations(cube)
                        + "; use 'mandatory'/'hierarchy'/'joint' to optimize; or update 'kylin.cube.aggrgroup.max-combination' to a bigger value.";
                context.addResult(ResultLevel.ERROR, msg);
                continue;
            }
        }

        index++;
    }
}

From source file:com.kelveden.rastajax.core.ResourceClassLoader.java

private ResourceClassMethod loadMethod(final Class<?> candidateResourceClass, final Method method) {

    final String logPrefix = " |-";

    LOGGER.debug("{} Attempting to load method {} as a JAX-RS resource method...", logPrefix, method.getName());

    String requestMethodDesignator = null;
    String uriTemplate = null;//from   w w  w.  j  a v a 2s.  c  o  m
    String[] produces = null;
    String[] consumes = null;
    Class<?> returnType = method.getReturnType();

    final Set<Annotation> methodAnnotations = JaxRsAnnotationScraper
            .scrapeJaxRsAnnotationsFrom(candidateResourceClass, method);
    LOGGER.debug("{} Found method annotations {}.", logPrefix, methodAnnotations.toString());

    if (returnType != null) {
        LOGGER.debug("{} Method return type is {}.", logPrefix, returnType.getName());
    }

    for (Annotation annotation : methodAnnotations) {

        final HttpMethod httpMethodAnnotation = annotation.annotationType().getAnnotation(HttpMethod.class);

        if (httpMethodAnnotation != null) {
            requestMethodDesignator = httpMethodAnnotation.value();

            LOGGER.debug("{} Method request method designator is '{}'.", logPrefix, requestMethodDesignator);

        } else if (annotation.annotationType() == Path.class) {
            uriTemplate = ((Path) annotation).value();

            LOGGER.debug("{} Method URI template '{}'.", logPrefix, uriTemplate);

        } else if (annotation.annotationType() == Produces.class) {
            produces = ((Produces) annotation).value();

            LOGGER.debug("{} Method produces: {}.", logPrefix, StringUtils.join(produces, ","));

        } else if (annotation.annotationType() == Consumes.class) {
            consumes = ((Consumes) annotation).value();

            LOGGER.debug("{} Method consumes: {}.", logPrefix, StringUtils.join(consumes, ","));
        }
    }

    if ((uriTemplate == null) && (requestMethodDesignator == null)) {
        LOGGER.debug("{} Method is NOT a resource method.", logPrefix);
        return null;
    }

    LOGGER.debug("{} Method is a resource method.", logPrefix);
    LOGGER.debug("{} Finding method parameters...", logPrefix);

    final List<Parameter> parameters = loadMethodParameters(candidateResourceClass, method);

    return createResourceClassMethod(method, uriTemplate, requestMethodDesignator, arrayAsList(consumes),
            arrayAsList(produces), parameters);
}

From source file:org.cloudgraph.hbase.graph.ParallelSubgraphTask.java

@Override
protected void assemble(PlasmaDataObject target, long targetSequence, EdgeReader sourceCollection,
        PlasmaDataObject source, PlasmaProperty sourceProperty, RowReader rowReader, int level)
        throws IOException {

    Set<Property> props = this.getProperties(target, source, sourceProperty, level);
    if (props.size() == 0)
        return;//from  w w  w  . ja  va2s  .c om
    if (log.isDebugEnabled())
        log.debug("assembling(" + level + "): " + target.toString() + ": " + props.toString());

    // synchronize on row-reader here rather than target because row-reader
    // uses shared column key factory
    synchronized (rowReader) {
        assembleData(target, targetSequence, props, rowReader);
    }

    TableReader tableReader = rowReader.getTableReader();
    TableMapping tableConfig = tableReader.getTableConfig();

    traversals.clear();

    // reference props
    for (Property p : props) {
        PlasmaProperty prop = (PlasmaProperty) p;
        if (prop.getType().isDataType())
            continue;

        EdgeReader edgeReader = null;
        if (rowReader.edgeExists((PlasmaType) target.getType(), prop, targetSequence)) {
            edgeReader = rowReader.getEdgeReader((PlasmaType) target.getType(), prop, targetSequence);
        } else
            continue; // edge not found in data

        if (!edgeReader.isExternal()) {
            assembleEdges(target, targetSequence, prop, edgeReader, rowReader, tableReader, rowReader, level);
        } else {
            TableReader externalTableReader = distributedReader.getTableReader(edgeReader.getTable());
            if (externalTableReader == null)
                throw new OperationException("no table reader found for type, " + edgeReader.getBaseType());
            assembleExternalEdges(target, targetSequence, prop, edgeReader, rowReader, externalTableReader,
                    level);
        }
    }

    traverse(level);
}

From source file:com.adobe.cq.wcm.core.components.internal.models.v1.PageListItemImpl.java

private Page getRedirectTarget(@Nonnull Page page) {
    Page result = page;//from  ww  w.  j ava2  s  .c om
    String redirectTarget;
    PageManager pageManager = page.getPageManager();
    Set<String> redirectCandidates = new LinkedHashSet<>();
    redirectCandidates.add(page.getPath());
    while (result != null && StringUtils.isNotEmpty(
            (redirectTarget = result.getProperties().get(PageImpl.PN_REDIRECT_TARGET, String.class)))) {
        result = pageManager.getPage(redirectTarget);
        if (result != null) {
            if (!redirectCandidates.add(result.getPath())) {
                LOGGER.warn("Detected redirect loop for the following pages: {}.",
                        redirectCandidates.toString());
                break;
            }
        }
    }
    return result;
}

From source file:com.sun.socialsite.web.rest.opensocial.service.ActivityServiceImpl.java

/**
 * Deletes the activity for the passed in user and group that corresponds to
 * the activityId.//from w  w  w . j  av a2 s  .c o m
 *
 * @param userId     The user.
 * @param groupId    The group.
 * @param appId      The app id.
 * @param activityId The id of the activity to delete.
 * @param token      A valid SecurityToken.
 * @return a response item containing any errors
 */
private Void deleteActivityInternal(UserId userId, GroupId groupId, String appId, Set<String> activityIds,
        SecurityToken token) throws SocialSpiException {

    String uid = userId.getUserId(token);
    log.trace(String.format("deleteActivity(%s, %s)", uid, activityIds.toString()));

    try {
        SocialSiteActivityManager amgr = Factory.getSocialSite().getSocialSiteActivityManager();
        String viewerId = token.getViewerId();
        for (Iterator<String> it = activityIds.iterator(); it.hasNext();) {
            String aid = it.next();
            SocialSiteActivity acontent = amgr.getActivity(aid);
            if (acontent == null) {
                throw new SocialSpiException(ResponseError.BAD_REQUEST, "No such activity: " + aid);
            }

            // Ensure that only owning user can delete his own activities
            Profile ownerProfile = acontent.getProfile();
            if (ownerProfile.getUserId().equals(token.getViewerId())) {
                amgr.removeActivity(acontent);
            } else {
                throw new SocialSpiException(ResponseError.BAD_REQUEST, String
                        .format("Activity(%s) does not belong to User(%s): ", aid, ownerProfile.getUserId()));
            }
        }
        Factory.getSocialSite().flush();

    } catch (SocialSiteException e) {
        log.debug("ERROR deleting activities", e);
        throw new SocialSpiException(ResponseError.INTERNAL_ERROR, "Problem deleting activities", e);
    }

    return null;
}

From source file:org.openremote.controller.service.impl.StatusPollingServiceImpl.java

/**
 * This operation is :<br />//from   ww  w  . j a v a2  s .  co m
 * 1) Query changed status record from changedStatusTable. if not found insert a new record with polling request, <br /> 
 * if found check whether the statuses of polling ids had changed.
 * 2) Check whether the statuses of polling ids had changed. if changed return the changed statuses, if not wait the changeStatusRecord.
 * 3) Waiting the status change until status changed or timeout. if had waited the chanted status then return changed status and <br />
 * changedSensorIds column of ChangedStatusRecord. if timeout throws 504 exception.
 */
@Override
public String queryChangedState(String deviceID, String unParsedSensorIDs) {
    if (deployer.isPaused()) {
        throw new ControllerXMLChangedException("The content of controller.xml had changed.");
    }

    logger.info("Querying changed state from ChangedStatus table...");
    String skipState = "";
    String[] sensorIDs = (unParsedSensorIDs == null || "".equals(unParsedSensorIDs)) ? new String[] {}
            : unParsedSensorIDs.split(Constants.STATUS_POLLING_SENSOR_IDS_SEPARATOR);

    Set<Integer> pollingSensorIDs = new TreeSet<Integer>();
    for (String pollingSensorID : sensorIDs) {
        try {
            pollingSensorIDs.add(Integer.parseInt(pollingSensorID));
        } catch (NumberFormatException e) {
            throw new NoSuchComponentException("The sensor id '" + pollingSensorID + "' should be digit", e);
        }
    }
    String orderedSensorIDs = pollingSensorIDs.toString();
    String changedStatusRecordKey = deviceID + "-" + orderedSensorIDs;

    ChangedStatusRecord changedStateRecord = changedStatusTable.query(changedStatusRecordKey);
    String tempInfo = "Found: [device => " + deviceID + ", sensorIDs => " + orderedSensorIDs
            + "] in ChangedStatus table.";
    logger.info(changedStateRecord == null ? "Not " + tempInfo : tempInfo);

    if (changedStateRecord == null) {
        changedStateRecord = new ChangedStatusRecord(changedStatusRecordKey, pollingSensorIDs);
        changedStatusTable.insert(changedStateRecord);
    }
    if (changedStateRecord.getStatusChangedSensorIDs() != null
            && changedStateRecord.getStatusChangedSensorIDs().size() > 0) {
        logger.info("Got the skipped sensor ids of statuses in " + changedStateRecord);
    }

    synchronized (changedStateRecord) {
        boolean willTimeout = false;
        while (changedStateRecord.getStatusChangedSensorIDs() == null
                || changedStateRecord.getStatusChangedSensorIDs().size() == 0) {
            if (willTimeout) {
                logger.info("Had timeout for waiting status change.");
                return Constants.SERVER_RESPONSE_TIME_OUT;
            }
            try {
                logger.info(changedStateRecord + "Waiting...");
                changedStateRecord.wait(50000);

                if (deployer.isPaused()) {
                    throw new ControllerXMLChangedException("The content of controller.xml had changed.");
                }

                willTimeout = true;
            } catch (InterruptedException e) {
                e.printStackTrace();
                return Constants.SERVER_RESPONSE_TIME_OUT;
            }
        }
        if (willTimeout) {
            logger.info("Had waited the skipped sensor ids of statuses in " + changedStateRecord);
        }
        skipState = queryChangedStatusesFromCachedStatusTable(changedStateRecord.getStatusChangedSensorIDs());
        changedStatusTable.resetChangedStatusIDs(changedStatusRecordKey);
    }

    return skipState;
}

From source file:org.cloudgraph.hbase.graph.ParallelSliceSubgraphTask.java

@Override
protected void assemble(PlasmaDataObject target, long targetSequence, EdgeReader sourceCollection,
        PlasmaDataObject source, PlasmaProperty sourceProperty, RowReader rowReader, int level)
        throws IOException {

    Set<Property> props = this.getProperties(target, source, sourceProperty, level);
    if (props.size() == 0)
        return;/* w w  w .  ja  va 2s .  c  o  m*/
    if (log.isDebugEnabled())
        log.debug("assembling(" + level + "): " + target.toString() + ": " + props.toString());

    // synchronize on row-reader here rather than target because row-reader
    // uses shared column key factory
    synchronized (rowReader) {
        assembleData(target, targetSequence, props, rowReader);
    }

    TableReader tableReader = rowReader.getTableReader();
    TableMapping tableConfig = tableReader.getTableConfig();

    traversals.clear();

    // reference props
    for (Property p : props) {
        PlasmaProperty prop = (PlasmaProperty) p;
        if (prop.getType().isDataType())
            continue;

        EdgeReader edgeReader = null;
        // if (level > 0) {
        if (rowReader.edgeExists((PlasmaType) target.getType(), prop, targetSequence)) {
            edgeReader = rowReader.getEdgeReader((PlasmaType) target.getType(), prop, targetSequence);
        } else
            continue; // edge not found in data

        PlasmaType childType = (PlasmaType) prop.getType();

        // NOTE: can we have predicates on singular props?
        Where where = this.selection.getPredicate(prop);

        if (!edgeReader.isExternal()) {
            Set<Long> sequences = null;
            if (prop.isMany() && where != null) {
                sequences = this.sliceSupport.fetchSequences((PlasmaType) prop.getType(), where, rowReader,
                        edgeReader);
                // preload properties for the NEXT level into the current
                // row so we have something to assemble
                Set<Property> childProperies = this.selection.getInheritedProperties(prop.getType(), level + 1);
                this.sliceSupport.loadBySequenceList(sequences, childProperies, childType, rowReader,
                        edgeReader);
            } else {
                // preload properties for the NEXT level into the current
                // row so we have something to assemble
                Set<Property> childProperies = this.selection.getInheritedProperties(prop.getType(), level + 1);
                this.sliceSupport.load(childProperies, childType, rowReader);
            }

            assembleEdges(target, targetSequence, prop, edgeReader, sequences, rowReader,
                    rowReader.getTableReader(), rowReader, level);
        } else {
            // String childTable =
            // rowReader.getGraphState().getRowKeyTable(edges[0].getUuid());
            // TableReader externalTableReader =
            // distributedReader.getTableReader(childTable);
            TableReader externalTableReader = distributedReader.getTableReader(edgeReader.getTable());
            if (log.isDebugEnabled())
                if (!tableConfig.getName().equals(externalTableReader.getTableConfig().getName()))
                    log.debug("switching row context from table: '" + tableConfig.getName() + "' to table: '"
                            + externalTableReader.getTableConfig().getName() + "'");
            List<CellValues> resultRows = null;
            if (prop.isMany() && where != null) {
                resultRows = this.sliceSupport.filter(childType, level, edgeReader, where, rowReader,
                        externalTableReader);
            }
            assembleExternalEdges(target, targetSequence, prop, edgeReader, rowReader, resultRows,
                    externalTableReader, level);
        }
    }

    traverse(level);
}

From source file:ml.shifu.shifu.core.Scorer.java

private String featureSetToString(Set<Integer> featureSet) {
    if (CollectionUtils.isEmpty(featureSet)) {
        return "EMPTY";
    } else {/*from   w  w w  .j  a  v a2s .  c  om*/
        return featureSet.toString();
    }
}