Example usage for java.util List indexOf

List of usage examples for java.util List indexOf

Introduction

In this page you can find the example usage for java.util List indexOf.

Prototype

int indexOf(Object o);

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:com.twinsoft.convertigo.beans.core.TransactionWithVariables.java

/**
 * Get representation of order for quick sort of a given database object.
 *///from w  ww  .  j  av a  2 s. com
@Override
public Object getOrder(Object object) throws EngineException {
    if (object instanceof Variable) {
        List<Long> ordered = orderedVariables.get(0);
        long time = ((Variable) object).priority;
        if (ordered.contains(time))
            return (long) ordered.indexOf(time);
        else
            throw new EngineException("Corrupted variable for transaction \"" + getName() + "\". Variable \""
                    + ((Variable) object).getName() + "\" with priority \"" + time
                    + "\" isn't referenced anymore.");
    } else
        return super.getOrder(object);
}

From source file:de.tudarmstadt.ukp.dkpro.core.clearnlp.ClearNlpSemanticRoleLabeler.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    predicateFinder.configure(aJCas.getCas());
    roleSetClassifier.configure(aJCas.getCas());
    roleLabeller.configure(aJCas.getCas());

    // Iterate over all sentences
    for (Sentence sentence : select(aJCas, Sentence.class)) {
        List<Token> tokens = selectCovered(aJCas, Token.class, sentence);
        DEPTree tree = new DEPTree();

        // Generate:
        // - DEPNode
        // - pos tags
        // - lemma
        for (int i = 0; i < tokens.size(); i++) {
            Token t = tokens.get(i);/*from  w  ww  .  ja v a  2s  .co  m*/
            DEPNode node = new DEPNode(i + 1, tokens.get(i).getCoveredText());
            node.pos = t.getPos().getPosValue();
            node.lemma = t.getLemma().getValue();
            tree.add(node);
        }

        // Generate:
        // Dependency relations
        for (Dependency dep : selectCovered(Dependency.class, sentence)) {
            int headIndex = tokens.indexOf(dep.getGovernor());
            int tokenIndex = tokens.indexOf(dep.getDependent());

            DEPNode token = tree.get(tokenIndex + 1);
            DEPNode head = tree.get(headIndex + 1);

            token.setHead(head, dep.getDependencyType());
        }

        // For the root node
        for (int i = 0; i < tokens.size(); i++) {
            DEPNode parserNode = tree.get(i + 1);
            if (parserNode.getLabel() == null) {
                int headIndex = tokens.indexOf(null);
                DEPNode head = tree.get(headIndex + 1);
                parserNode.setHead(head, "root");
            }
        }

        // Do the SRL
        predicateFinder.getResource().process(tree);
        roleSetClassifier.getResource().process(tree);
        roleLabeller.getResource().process(tree);

        // Convert the results into UIMA annotations
        Map<Token, SemanticPredicate> predicates = new HashMap<Token, SemanticPredicate>();
        Map<SemanticPredicate, List<SemanticArgument>> predArgs = new HashMap<SemanticPredicate, List<SemanticArgument>>();

        for (int i = 0; i < tokens.size(); i++) {
            DEPNode parserNode = tree.get(i + 1);
            Token argumentToken = tokens.get(i);

            for (DEPArc argPredArc : parserNode.getSHeads()) {
                Token predToken = tokens.get(argPredArc.getNode().id - 1);

                // Instantiate the semantic predicate annotation if it hasn't been done yet
                SemanticPredicate pred = predicates.get(predToken);
                if (pred == null) {
                    // Create the semantic predicate annotation itself
                    pred = new SemanticPredicate(aJCas, predToken.getBegin(), predToken.getEnd());
                    pred.setCategory(argPredArc.getNode().getFeat(DEPLib.FEAT_PB));
                    pred.addToIndexes();
                    predicates.put(predToken, pred);

                    // Prepare a list to store its arguments
                    predArgs.put(pred, new ArrayList<SemanticArgument>());
                }

                // Instantiate the semantic argument annotation
                SemanticArgument arg = new SemanticArgument(aJCas, argumentToken.getBegin(),
                        argumentToken.getEnd());
                arg.setRole(argPredArc.getLabel());
                arg.addToIndexes();

                // Remember to which predicate this argument belongs
                predArgs.get(pred).add(arg);
            }
        }

        for (Entry<SemanticPredicate, List<SemanticArgument>> e : predArgs.entrySet()) {
            e.getKey().setArguments(FSCollectionFactory.createFSArray(aJCas, e.getValue()));
        }
    }
}

From source file:com.autentia.intra.bean.activity.GlobalHoursReportBean.java

public List<GlobalHourReport> getAll() {

    // Retrieve activities for every User during that period of time
    ActivitySearch search = new ActivitySearch();

    Calendar init = Calendar.getInstance();
    init.setTime(startDate);// ww  w  .  j a  va 2  s . c  om
    Calendar last = Calendar.getInstance();
    last.setTime(endDate);

    init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
    init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
    init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
    init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));

    last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
    last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
    last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
    last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));

    search.setStartStartDate(init.getTime());
    search.setEndStartDate(last.getTime());

    List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>();

    if (billable)
        search.setBillable(true);

    // Search activities during indicated dates
    List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));

    // Search for projects in activities and create the global list.

    for (Activity act : activities) {
        Project proj = act.getRole().getProject();
        GlobalHourReport unit = new GlobalHourReport();
        unit.setProject(proj);

        // an entry in the list represents a project
        if (!listGlobal.contains(unit))
            listGlobal.add(unit);

        // Retrieve the stored unit and save hours
        GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit));
        float horas = act.getDuration() / 60.0f;

        storedUnit.setUserHours(act.getUser(), horas);
        storedUnit.setIterator(usuarios.iterator());

    }

    return listGlobal;

}

From source file:eg.nileu.cis.nilestore.monitor.server.NsMonitorServer.java

/**
 * Dump whole viewto json.//from   www  . ja va  2 s .c o m
 * 
 * @return the string
 */
@SuppressWarnings("unchecked")
private synchronized String dumpWholeViewtoJSON() {

    List<String> serversList = new ArrayList<String>();
    List<String> filesList = new ArrayList<String>();
    List<Map<String, Object>> links = new ArrayList<Map<String, Object>>();
    Map<String, String> sslinks = new HashMap<String, String>();

    for (NilestoreAddress peer : view.keySet()) {

        StorageStatusView peerstatus = view.get(peer);
        Map<String, SIStatusItem> statusperSI = peerstatus.getStatusPerSI();
        if (statusperSI.size() == 0)
            continue;

        String peerkey = peer.getNickname();

        String peerurl = String.format("http://%s:%s", peer.getPeerAddress().getIp(), peer.getWebPort());
        sslinks.put(peerkey, peerurl);

        serversList.add(peerkey);
        int serverIndex = serversList.indexOf(peerkey);
        int siIndex = 0;

        for (String si : statusperSI.keySet()) {

            if (!filesList.contains(si))
                filesList.add(si);
            siIndex = filesList.indexOf(si);

            SIStatusItem item = statusperSI.get(si);
            Map<String, Object> elem = new HashMap<String, Object>();

            elem.put("ss", serverIndex);
            elem.put("si", siIndex);
            Object val = item.getCount();

            if (val.equals(deadval)) {
                val = "dead";
            }

            elem.put("val", val);

            if (!links.contains(elem))
                links.add(elem);
        }
    }

    JSONObject obj = new JSONObject();
    obj.put("ss", serversList);
    obj.put("si", filesList);
    obj.put("links", links);
    obj.put("sslinks", sslinks);

    return obj.toJSONString();
}

From source file:fr.treeptik.cloudunit.service.impl.ApplicationServiceImpl.java

/**
 * Remove an application/* w ww . j  a  va  2  s  . c  o m*/
 *
 * @param application
 * @param user
 * @return
 * @throws ServiceException
 */
@Override
@Transactional
public Application remove(Application application, User user) throws ServiceException, CheckException {

    try {
        logger.info("Starting removing application " + application.getName());

        // Delete all modules
        List<Module> listModules = application.getModules();
        for (Module module : listModules) {
            try {
                moduleService.remove(application, user, module, false, application.getStatus());
            } catch (ServiceException | CheckException e) {
                application.setStatus(Status.FAIL);
                logger.error("ApplicationService Error : failed to remove module " + module.getName()
                        + " for application " + application.getName() + " : " + e);
                e.printStackTrace();
            }
        }

        // Delete all alias
        List<String> aliases = new ArrayList<>();
        aliases.addAll(application.getAliases());
        for (String alias : aliases) {
            removeAlias(application, alias);
        }

        // Delete all servers
        List<Server> listServers = application.getServers();
        for (Server server : listServers) {
            serverService.remove(server.getName());
            if (listServers.indexOf(server) == listServers.size() - 1) {
                hipacheRedisUtils.removeRedisAppKey(application);
                applicationDAO.delete(server.getApplication());
                portUtils.releaseProxyPorts(application);
            }
        }

        logger.info("ApplicationService : Application successfully removed ");

    } catch (PersistenceException e) {
        setStatus(application, Status.FAIL);
        logger.error("ApplicationService Error : failed to remove " + application.getName() + " : " + e);

        throw new ServiceException(e.getLocalizedMessage(), e);
    } catch (ServiceException e) {
        setStatus(application, Status.FAIL);
        logger.error(
                "ApplicationService Error : failed to remove application " + application.getName() + " : " + e);
    }
    return application;
}

From source file:eionet.cr.web.action.TypeSearchActionBean.java

/**
 *
 * @param map/*from   w ww  . ja  va 2 s . co m*/
 * @return
 */
private Map<String, String> sortByValueIgnoreCase(Map<String, String> map) {

    LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
    if (map != null && !map.isEmpty()) {

        List<String> keys = new ArrayList<String>(map.keySet());
        List<String> values = new ArrayList<String>(map.values());

        List<String> sortedValues = new ArrayList<String>(map.values());
        Collections.sort(sortedValues, new CaseInsensitiveStringComparator());
        for (int i = 0; i < sortedValues.size(); i++) {
            result.put(keys.get(values.indexOf(sortedValues.get(i))), sortedValues.get(i));
        }
    }

    return result;
}

From source file:com.linkedin.cubert.analyzer.physical.AggregateRewriter.java

protected ObjectNode getFactTimeSpecNode(ObjectNode factNode, ObjectNode cubeNode)
        throws AggregateRewriteException {
    List<String> paths = lineage.getPaths(factNode.get("path"));
    for (JsonNode timeSpecNode : (ArrayNode) (cubeNode.get("timeColumnSpec"))) {
        String elementPath = ((ObjectNode) timeSpecNode).get("factPath").getTextValue();
        if (paths.indexOf(elementPath) != -1) {
            tNode = (ObjectNode) timeSpecNode;
            return tNode;
        }/*from w w  w. j a  va2 s .  c o m*/
    }
    throw new AggregateRewriteException(
            "No matching time column specification found for FACT load at " + factNode.toString());
}

From source file:au.gov.ansto.bragg.kakadu.ui.plot.MultiPlotDataManager.java

/**
 * Manages plot the item visible state and visualization widget update.
 *  //from   www. jav a  2 s. c  o m
 * @param plotDataItem an item
 * @param isVisible true if visible or false otherwise
 */
public void setPlotDataItemVisible(PlotDataItem plotDataItem, final boolean isVisible) {
    plotDataItem.setVisible(isVisible);
    //      final AbstractDataSource dataSourceWrapper = plot.getCurrentPlotWidget().getMultiPlotManager().
    //               getDataSourceWrapper(plotDataItem.getKurandaPlotDataId());
    //      if (dataSourceWrapper != null) {
    //         dataSourceWrapper.setVisible(isVisible);
    //         try {
    //            plot.getCurrentPlotWidget().repaint();
    //         } catch (Exception e) {
    //            plot.handleException(e);
    //         }
    //      }
    PlotType type = plot.getCurrentPlotType();
    switch (type) {
    case OffsetPlot:
    case OverlayPlot:
        IXYErrorDataset dataset1D = (IXYErrorDataset) plot.getCurrentPlotWidget().getDataset();
        List<IXYErrorSeries> seriesList = dataset1D.getSeries();
        for (IXYErrorSeries series : seriesList) {
            if (series == plotDataItem.getPlotData()) {
                XYItemRenderer renderer = plot.getCurrentPlotWidget().getXYPlot().getRenderer();
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(seriesList.indexOf(series),
                        isVisible);
            }
        }
        break;
    case IntensityPlot:
        IGroup group = plotDataItem.getData();
        Hist2DDataset dataset2D = (Hist2DDataset) plot.getCurrentPlotWidget().getDataset();
        if (group.getShortName().equals(dataset2D.getTitle())) {
            plot.getCurrentPlotWidget().setVisible(isVisible);
        }
        break;
    default:
        break;
    }
    if ((plotDataItem.getDataType() == DataType.Map || plotDataItem.getDataType() == DataType.MapSet)
            && plot.getCurrentPlotType() == PlotType.IntensityPlot) {
        plot.getViewPlotPropertiesComposite().updateUI();
    }
    fireItemUpdatedEvent(plotDataItem);
}

From source file:com.autentia.tnt.bean.activity.GlobalHoursReportBean.java

public List<GlobalHourReport> getAll() {

    // Retrieve activities for every User during that period of time            
    ActivitySearch search = new ActivitySearch();

    Calendar init = Calendar.getInstance();
    init.setTime(startDate);/*from  w w w.j a v  a  2 s .c  om*/
    Calendar last = Calendar.getInstance();
    last.setTime(endDate);

    init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
    init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
    init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
    init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));

    last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
    last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
    last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
    last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));

    search.setStartStartDate(init.getTime());
    search.setEndStartDate(last.getTime());

    List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>();

    if (billable)
        search.setBillable(true);

    // Search activities during indicated dates
    List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));

    // Search for projects in activities and create the global list.      

    for (Activity act : activities) {
        Project proj = act.getRole().getProject();
        GlobalHourReport unit = new GlobalHourReport();
        unit.setProject(proj);

        // an entry in the list represents a project
        if (!listGlobal.contains(unit))
            listGlobal.add(unit);

        // Retrieve the stored unit and save hours
        GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit));
        float horas = act.getDuration() / 60.0f;

        storedUnit.setUserHours(act.getUser(), horas);
        storedUnit.setIterator(usuarios.iterator());

    }

    return listGlobal;

}

From source file:com.twinsoft.convertigo.beans.core.RequestableStep.java

private void decreaseOrder(DatabaseObject databaseObject, Long after) throws EngineException {
    List<Long> ordered = null;
    long value = databaseObject.priority;

    if (databaseObject instanceof Variable)
        ordered = orderedVariables.get(0);

    if (!ordered.contains(value))
        return;/*from   ww w . ja  v a  2  s  .  c  om*/
    int pos = ordered.indexOf(value);
    if (pos + 1 == ordered.size())
        return;

    if (after == null)
        after = ordered.get(pos + 1);
    int pos1 = ordered.indexOf(after);

    ordered.add(pos1 + 1, value);
    ordered.remove(pos);
    hasChanged = true;
}