Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

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

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this set.

Usage

From source file:edu.uiowa.icts.bluebutton.json.Encounter.java

public String getFindings() {
    if (this.findings.size() == 0) {
        return null;
    } else {//from w  ww  .j  a  v  a 2s. com
        Set<String> findingNameSet = new LinkedHashSet<String>();
        for (Entry f : this.findings) {
            findingNameSet.add(f.getName());
        }
        return StringUtils.join(findingNameSet.toArray(), ", ");
    }
}

From source file:edu.umass.cs.gigapaxos.paxosutil.PaxosMessenger.java

private GenericMessagingTask<NodeIDType, ?> toGeneric(MessagingTask mtask) throws JSONException {
    Set<NodeIDType> nodes = this.nodeMap.getIntArrayAsNodeSet(mtask.recipients);
    return (new GenericMessagingTask<NodeIDType, String>(nodes.toArray(),
            // Util.intToIntegerArray(mtask.recipients)
            toObjects(mtask.msgs)));// w  ww. ja v  a2s . com
}

From source file:com.zte.ums.zenap.itm.agent.plugin.linux.util.Calculator.java

public String calculateItem(Map variables, String formula) throws MonitorException {

    Set vKeySet = variables.keySet();
    Object[] keys = vKeySet.toArray();
    Arrays.sort(keys);/*from w  ww  .java  2s . c o  m*/
    JexlContext jexlContext = new MapContext();
    for (int i = keys.length - 1; i >= 0; i--) {
        String s = keys[i].toString();
        String s1 = s.replace('.', 'a');
        formula = formula.replaceAll(s, s1);
        jexlContext.set(s1, variables.get(s));
    }

    try {
        while (true) {
            int eIndex = formula.indexOf("E");
            if (eIndex == -1) {
                break;
            }
            int startIndex = getBackwardNumIndex(formula, eIndex);
            int endIndex = getForwardNumIndex(formula, eIndex);
            String eNum = formula.substring(eIndex + 1, endIndex);
            String tenNumString = null;
            int num = Integer.parseInt(eNum);
            if (num > 5) {
                int tenNum = 1;
                for (int i = 0; i < (num - 5); i++) {
                    tenNum = tenNum * 10;
                }
                tenNumString = "100000.0 * " + Integer.toString(tenNum);
            } else if (num > 0) {
                int tenNum = 1;
                for (int i = 0; i < num; i++) {
                    tenNum = tenNum * 10;
                }
                tenNumString = Integer.toString(tenNum);
            } else if (num < 0) {
                double tenNum = 1;
                for (int i = 0; i > num; i--) {
                    tenNum = tenNum * 0.1;
                }
                tenNumString = Double.toString(tenNum);
            }
            String variable = formula.substring(startIndex, endIndex);
            String headVariable = formula.substring(startIndex, eIndex);
            formula = formula.replaceFirst(variable, "(" + headVariable + " * " + tenNumString + ")");
        }
        JexlEngine jexlEngine = new JexlEngine();
        Expression expression = jexlEngine.createExpression(formula);
        Object result = expression.evaluate(jexlContext);
        if (result instanceof Double) {
            Double dd = (Double) result;

            NumberFormat formater = new DecimalFormat("#.00");
            formater.setRoundingMode(RoundingMode.HALF_UP);
            return formater.format(dd);
        }
        return result.toString();
    } catch (Exception e) {
        throw new MonitorException("Error!Something wrong happened! ", e);
    }
}

From source file:edu.cmu.lti.oaqa.extractors.ExtractorHelper.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    try {/* www  .  j  a v a 2  s . c o  m*/
        String quiid = null;
        FSIterator<Annotation> it = aJCas.getAnnotationIndex(InputElement.type).iterator();
        if (it.hasNext()) {
            InputElement elem = (InputElement) it.next();
            quiid = elem.getQuuid();
        } else {
            throw new Exception("Cannot find the docUri!");
        }

        FSIterator<Annotation> sentenceIterator = AnnotUtils.getIterator(aJCas, Sentence.typeIndexID);

        ArrayList<ArrayList<String>> resList = new ArrayList<ArrayList<String>>();

        for (int j = 0; j < extrList.size(); j++) {
            resList.add(new ArrayList<String>());
        }

        String FileName = new File(quiid).getName();

        String FileNameParts[] = FileName.split("\\.");
        String CountryName = FileNameParts[0].replace('_', ' ');

        TreeSet<String> exceptions = new TreeSet<String>();
        exceptions.add(CountryName);

        getContext().getLogger().log(Level.INFO, "DOCUMENT: " + FileName + " Country: " + CountryName);

        for (int counter = 1; sentenceIterator.isValid(); counter++, sentenceIterator.moveToNext()) {
            Annotation sentence = sentenceIterator.get();
            /*
            getContext().getLogger().log(Level.INFO, "SENTENCE " + counter + 
                    " begin: " + sentence.getBegin() + " end: " + sentence.getEnd());
            */
            for (int i = 0; i < extrList.size(); ++i) {
                Extractor e = extrList.get(i);
                ArrayList<String> res = resList.get(i);

                e.process(aJCas, sentence, res);
            }
        }

        for (int i = 0; i < extrList.size(); ++i) {
            Extractor e = extrList.get(i);
            ArrayList<String> res = resList.get(i);
            Set<String> setRes = e.aggregate(res, exceptions);

            getContext().getLogger().log(Level.INFO,
                    FileName + "#" + e.getClass().getName() + " : " + StringUtils.join(setRes.toArray(), ';'));
        }

    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    }

}

From source file:org.openplans.delayfeeder.RouteStatus.java

private RouteFeedItem getLatestItem(String agency, String route, Session session) {
    RouteFeed feed = getFeed(agency, route, session);
    if (feed == null) {
        return null;
    }/* www . j av  a 2 s. c  o m*/

    GregorianCalendar now = new GregorianCalendar();
    if (feed.lastFetched == null
            || now.getTimeInMillis() - feed.lastFetched.getTimeInMillis() > FEED_UPDATE_FREQUENCY) {

        try {
            refreshFeed(feed, session);
        } catch (Exception e) {
            e.printStackTrace();
            logger.warn(e.fillInStackTrace());
        }
    }

    Set<RouteFeedItem> list = feed.items;

    if (list.size() == 0) {
        return null;
    }
    RouteFeedItem item = (RouteFeedItem) list.toArray()[0];
    return item;
}

From source file:com.capitalone.dashboard.collector.DefaultNexusIQClientTest.java

private LibraryPolicyResult.Threat getThreat(Set<LibraryPolicyResult.Threat> threats,
        LibraryPolicyThreatLevel level) {
    for (Object o : threats.toArray()) {
        LibraryPolicyResult.Threat t = (LibraryPolicyResult.Threat) o;
        if (t.getLevel().equals(level)) {
            return t;
        }/* ww  w.  ja  v  a  2 s .c o  m*/
    }
    return null;
}

From source file:com.gst.infrastructure.accountnumberformat.data.AccountNumberFormatDataValidator.java

public void validateForCreate(final String json) {

    if (StringUtils.isBlank(json)) {
        throw new InvalidJsonException();
    }/*from   w w  w. j  a  va  2 s .c o m*/
    final Type typeOfMap = new TypeToken<Map<String, Object>>() {
    }.getType();
    this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,
            AccountNumberFormatConstants.ACCOUNT_NUMBER_FORMAT_CREATE_REQUEST_DATA_PARAMETERS);
    final JsonElement element = this.fromApiJsonHelper.parse(json);
    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();

    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(AccountNumberFormatConstants.ENTITY_NAME);

    final Integer accountType = this.fromApiJsonHelper
            .extractIntegerSansLocaleNamed(AccountNumberFormatConstants.accountTypeParamName, element);
    baseDataValidator.reset().parameter(AccountNumberFormatConstants.accountTypeParamName).value(accountType)
            .notNull().integerGreaterThanZero()
            .inMinMaxRange(EntityAccountType.getMinValue(), EntityAccountType.getMaxValue());

    if (this.fromApiJsonHelper.parameterExists(AccountNumberFormatConstants.prefixTypeParamName, element)) {
        final Integer prefixType = this.fromApiJsonHelper
                .extractIntegerSansLocaleNamed(AccountNumberFormatConstants.prefixTypeParamName, element);
        DataValidatorBuilder dataValidatorForValidatingPrefixType = baseDataValidator.reset()
                .parameter(AccountNumberFormatConstants.prefixTypeParamName).value(prefixType).notNull()
                .integerGreaterThanZero();

        /**
         * Permitted values for prefix type vary based on the actual
         * selected accountType, carry out this validation only if data
         * validation errors do not exist for both entity type and prefix
         * type
         **/
        boolean areAccountTypeAndPrefixTypeValid = true;
        for (ApiParameterError apiParameterError : dataValidationErrors) {
            if (apiParameterError.getParameterName()
                    .equalsIgnoreCase(AccountNumberFormatConstants.accountTypeParamName)
                    || apiParameterError.getParameterName()
                            .equalsIgnoreCase(AccountNumberFormatConstants.prefixTypeParamName)) {
                areAccountTypeAndPrefixTypeValid = false;
            }
        }

        if (areAccountTypeAndPrefixTypeValid) {
            EntityAccountType entityAccountType = EntityAccountType.fromInt(accountType);
            Set<Integer> validAccountNumberPrefixes = determineValidAccountNumberPrefixes(entityAccountType);
            dataValidatorForValidatingPrefixType.isOneOfTheseValues(validAccountNumberPrefixes.toArray());
        }
    }

    throwExceptionIfValidationWarningsExist(dataValidationErrors);

}

From source file:helma.swarm.SwarmSessionManager.java

void broadcastIds(int operation, Set idSet) {
    try {/*  w w  w .  j a v  a  2 s . c  om*/
        if (!idSet.isEmpty()) {
            Object[] ids = idSet.toArray();
            for (int i = 0; i < ids.length; i++)
                idSet.remove(ids[i]);
            Serializable idlist = new SessionIdList(operation, ids);
            adapter.send(new Message(null, address, idlist));
        }
    } catch (Exception x) {
        log.error("Error broadcasting session list", x);
    }
}

From source file:com.swordlord.gozer.session.SecuredWebSession.java

/**
 * @return Get the roles that this session can play
 *//*ww  w . j a  va 2  s .  com*/
@Override
public org.apache.wicket.authroles.authorization.strategies.role.Roles getRoles() {
    if (_ai == null) {
        return null;
    }

    Set<String> setRoles = _ai.getRoles();
    final String[] arrRoles = (String[]) setRoles.toArray();

    return new org.apache.wicket.authroles.authorization.strategies.role.Roles(arrRoles);
}

From source file:jef.tools.ArrayUtils.java

/**
 * ????? ? //w ww . j a  v a 2s  .c  o m
 * 
 * @param ls
 * @param ls2
 * @return
 */
public static Object[] xor(Object[] ls, Object[] ls2) {
    // 
    Set<Object> setAll = new HashSet<Object>(Arrays.asList(ls));
    for (Object o : ls2) {
        setAll.add(o);
    }
    // 
    HashSet<Object> setInter = new HashSet<Object>(Arrays.asList(ls));
    setInter.retainAll(Arrays.asList(ls2));
    // ?
    setAll.removeAll(setInter);
    return setAll.toArray();
}