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:de.hs.mannheim.modUro.controller.diagram.SimulationDiagramController.java

/**
 * Initializes Choicebox Content./*  www  . j a v  a2  s  . c o  m*/
 */
private void initializeChoiceboxContent() {
    List<String> name = choiceBoxMetrictypeNames();

    int left = 0;
    int right = 0;

    for (String val : name) {
        if (val.equals(FitnessName.ARRANGEMENT_FITNESS.getName())) {
            left = name.indexOf(FitnessName.ARRANGEMENT_FITNESS.getName());
        }

        if (val.equals(FitnessName.VOLUME_FITNESS.getName())) {
            right = name.indexOf(FitnessName.VOLUME_FITNESS.getName());
        }
    }

    leftMetricType.setItems(FXCollections.observableArrayList(name));
    rightMetricType.setItems(FXCollections.observableArrayList(name));

    leftMetricType.getSelectionModel().select(left);
    rightMetricType.getSelectionModel().select(right);

    leftLastSelectedIndex = left;
    rightLastSelectedIndex = right;

    leftLastSelectedMetrictypename = name.get(leftLastSelectedIndex);
    rightLastSelectedMetrictypename = name.get(rightLastSelectedIndex);

    setLeftChartContent(left);
    setRightChartContent(right);
}

From source file:net.sf.jdmf.data.output.RuleElement.java

/**
 * Determines whether a new rule element should be appended to conditions
 * or consequences.//from w  ww  . j av  a2 s .  c om
 */
protected RuleElement classifyRuleElement(Rule parentRule) {
    List<RuleElement> conditions = parentRule.getConditions();
    List<RuleElement> consequences = parentRule.getConsequences();

    RuleElement ruleElement = new RuleElement();

    if (conditions.contains(this) && (conditions.indexOf(this) == conditions.size() - 1)) {
        conditions.add(ruleElement);
    } else if (consequences.contains(this) && (consequences.indexOf(this) == consequences.size() - 1)) {
        consequences.add(ruleElement);
    } else {
        throw new RuleDefinitionException(
                "Could not define rule - " + "the previous rule element is not defined");
    }

    return ruleElement;
}

From source file:com.cronutils.model.time.TimeNode.java

/**
 * We return same reference value if matches or previous one if does not match.
 * Then we start applying shifts.//w w  w .j av a  2 s.c  o m
 * This way we ensure same value is returned if no shift is requested.
 * @param reference - reference value
 * @param shiftsToApply - shifts to apply
 * @return NearestValue instance, never null. Holds information on nearest (backward) value and shifts performed.
 */
@VisibleForTesting
NearestValue getNearestBackwardValue(int reference, int shiftsToApply) {
    List<Integer> values = new ArrayList<Integer>(this.values);
    Collections.reverse(values);
    int index = 0;
    boolean foundSmaller = false;
    AtomicInteger shift = new AtomicInteger(0);
    if (!values.contains(reference)) {
        for (Integer value : values) {
            if (value < reference) {
                index = values.indexOf(value);
                shiftsToApply--;//we just moved a position!
                foundSmaller = true;
                break;
            }
        }
        if (!foundSmaller) {
            shift.incrementAndGet();
        }
    } else {
        index = values.indexOf(reference);
    }
    int value = values.get(index);
    for (int j = 0; j < shiftsToApply; j++) {
        value = getValueFromList(values, index + 1, shift);
        index = values.indexOf(value);
    }
    return new NearestValue(value, shift.get());
}

From source file:com.capgemini.b2bassets.cockpits.cmscockpit.session.impl.DefaultCmsPageBrowserModel.java

protected void processEventTypeChanged(final CockpitEvent event, final ItemChangedEvent changedEvent) {
    for (final BrowserSectionModel sectionModel : getBrowserSectionModels()) {
        if (sectionModel.equals(event.getSource())) {
            continue;
        }//from  ww w  .  jav  a 2 s .c om
        final List<TypedObject> sectionItems = sectionModel.getItems();
        final TypedObject changedItem = changedEvent.getItem();
        if (sectionItems.contains(changedItem)) {
            final TypedObject typedObject = sectionItems.get(sectionItems.indexOf(changedItem));
            modelService.refresh(typedObject.getObject());
            sectionModel.update();
        }
        if (sectionModel.getRootItem() != null && sectionModel.getRootItem().equals(changedItem)) {
            final TypedObject rootItem = (TypedObject) sectionModel.getRootItem();
            final ItemModel itemModel = (ItemModel) rootItem.getObject();
            modelService.refresh(itemModel);
            if (sectionModel instanceof Lockable) {
                getContentEditorSection().setReadOnly(((Lockable) sectionModel).isLocked());
            }
            sectionModel.update();
        }
    }
}

From source file:org.openlmis.fulfillment.service.OrderCsvHelper.java

private void writeHeader(List<OrderFileColumn> orderFileColumns, Writer writer) throws IOException {
    for (OrderFileColumn column : orderFileColumns) {
        String columnLabel = column.getColumnLabel();
        if (columnLabel == null) {
            columnLabel = "";
        }//  w  w w  .  jav  a  2s .  c  o  m
        writer.write(columnLabel);
        if (orderFileColumns.indexOf(column) == (orderFileColumns.size() - 1)) {
            writer.write(LINE_SEPARATOR);
            break;
        }
        writer.write(",");
    }
}

From source file:com.jstar.eclipse.services.JStar.java

@SuppressWarnings("static-access")
// in io 2.0 FileUtils.listFiles should return Collection<File> instead of Collection
public List<File> convertToJimple(final JavaFile fileToConvert) {
    String fileDirectory = fileToConvert.getOutputDirectory().getLocation().toOSString();
    String javaFile = fileToConvert.getNameWithPackage();

    final String sootOutput = fileDirectory + File.separator + SootOutput + File.separator + javaFile;

    final String[] args = { "-cp",
            PreferenceConstants.getSootClassPath() + File.pathSeparator + fileToConvert.getProjectClasspath(),
            "-f", "J", "-output-dir", sootOutput, "-src-prec", "java",
            //"-v",
            "-print-tags", javaFile };

    soot.G.v().reset();//from w  w w. j a v a  2  s.  c  o m
    soot.Main.main(args);

    final List<String> types = fileToConvert.getTypes();
    final List<File> jimpleFiles = new LinkedList<File>();

    for (Object file : (FileUtils.listFiles(new File(sootOutput), new WildcardFileFilter("*.jimple"), null))) {
        final String fileName = ((File) file).getName();

        if (types.indexOf(new Path(fileName).removeFileExtension().toOSString()) != -1) {
            jimpleFiles.add((File) file);
        }
    }

    if (jimpleFiles == null || jimpleFiles.size() == 0) {
        ConsoleService.getInstance()
                .printErrorMessage("An error occurred while converting java file to jimple format.");
        throw new NullPointerException();
    }

    return jimpleFiles;
}

From source file:io.pravega.controller.eventProcessor.impl.SerializedRequestHandlerTest.java

@Test(timeout = 10000)
public void testProcessEvent() throws InterruptedException, ExecutionException {
    final ConcurrentHashMap<String, List<Integer>> orderOfProcessing = new ConcurrentHashMap<>();

    SerializedRequestHandler<TestEvent> requestHandler = new SerializedRequestHandler<TestEvent>(
            executorService()) {/*from   w  w w  .j  ava  2s  .  c  o  m*/
        @Override
        public CompletableFuture<Void> processEvent(TestEvent event) {
            orderOfProcessing.compute(event.getKey(), (x, y) -> {
                if (y == null) {
                    y = new ArrayList<>();
                }
                y.add(event.getNumber());
                return y;
            });
            return event.getFuture();
        }
    };

    List<Pair<TestEvent, CompletableFuture<Void>>> stream1Queue = requestHandler
            .getEventQueueForKey(getKeyForStream("scope", "stream1"));
    assertNull(stream1Queue);
    // post 3 work for stream1
    TestEvent s1e1 = new TestEvent("scope", "stream1", 1);
    CompletableFuture<Void> s1p1 = requestHandler.process(s1e1);
    TestEvent s1e2 = new TestEvent("scope", "stream1", 2);
    CompletableFuture<Void> s1p2 = requestHandler.process(s1e2);
    TestEvent s1e3 = new TestEvent("scope", "stream1", 3);
    CompletableFuture<Void> s1p3 = requestHandler.process(s1e3);

    stream1Queue = requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream1"));
    assertTrue(stream1Queue.size() >= 2);
    assertTrue(stream1Queue.stream().noneMatch(x -> x.getRight().isDone()));
    List<Integer> collect = stream1Queue.stream().map(x -> x.getLeft().getNumber())
            .collect(Collectors.toList());
    assertTrue(collect.indexOf(2) < collect.indexOf(3));

    s1e3.complete();

    stream1Queue = requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream1"));

    // verify that no processing is complete
    assertTrue(stream1Queue.size() >= 2);
    assertTrue(stream1Queue.stream().noneMatch(x -> x.getRight().isDone()));
    collect = stream1Queue.stream().map(x -> x.getLeft().getNumber()).collect(Collectors.toList());
    assertTrue(collect.indexOf(2) < collect.indexOf(3));

    // post 3 work for stream2
    TestEvent s2e1 = new TestEvent("scope", "stream2", 1);
    CompletableFuture<Void> s2p1 = requestHandler.process(s2e1);
    TestEvent s2e2 = new TestEvent("scope", "stream2", 2);
    CompletableFuture<Void> s2p2 = requestHandler.process(s2e2);
    TestEvent s2e3 = new TestEvent("scope", "stream2", 3);
    CompletableFuture<Void> s2p3 = requestHandler.process(s2e3);

    List<Pair<TestEvent, CompletableFuture<Void>>> stream2Queue = requestHandler
            .getEventQueueForKey(getKeyForStream("scope", "stream1"));
    assertTrue(stream2Queue.size() >= 2);
    assertTrue(stream2Queue.stream().noneMatch(x -> x.getRight().isDone()));
    collect = stream2Queue.stream().map(x -> x.getLeft().getNumber()).collect(Collectors.toList());
    assertTrue(collect.indexOf(2) < collect.indexOf(3));

    s1e1.complete();
    Futures.await(s1p1);

    stream1Queue = requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream1"));
    assertTrue(stream1Queue.size() >= 1);
    assertTrue(stream1Queue.stream().noneMatch(x -> x.getRight().isDone()));
    collect = stream1Queue.stream().map(x -> x.getLeft().getNumber()).collect(Collectors.toList());
    assertTrue(collect.contains(3));

    // now make sure that we have concurrently run for two streams
    s2e1.complete();
    Futures.await(s2p1);

    stream2Queue = requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream2"));
    assertTrue(stream2Queue.size() >= 1);
    assertTrue(stream2Queue.stream().noneMatch(x -> x.getRight().isDone()));
    collect = stream2Queue.stream().map(x -> x.getLeft().getNumber()).collect(Collectors.toList());
    assertTrue(collect.contains(3));

    // now complete all processing
    s2e2.complete();
    Futures.await(s2p2);

    s2e3.complete();

    s1e2.complete();
    Futures.await(s1p2);

    Futures.await(s1p3);
    Futures.await(s2p3);

    assertTrue(
            orderOfProcessing.get(s1e1.getKey()).get(0) == 1 && orderOfProcessing.get(s1e1.getKey()).get(1) == 2
                    && orderOfProcessing.get(s1e1.getKey()).get(2) == 3);
    assertTrue(
            orderOfProcessing.get(s2e1.getKey()).get(0) == 1 && orderOfProcessing.get(s2e1.getKey()).get(1) == 2
                    && orderOfProcessing.get(s2e1.getKey()).get(2) == 3);

    Futures.loop(() -> requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream1")) == null,
            () -> CompletableFuture.completedFuture(null), executorService());
    Futures.loop(() -> requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream2")) == null,
            () -> CompletableFuture.completedFuture(null), executorService());

    // now that we have drained all the work from the processor.
    // let's post new work for stream 1
    TestEvent s1e4 = new TestEvent("scope", "stream1", 4);
    CompletableFuture<Void> s1p4 = requestHandler.process(s1e4);

    stream1Queue = requestHandler.getEventQueueForKey(getKeyForStream("scope", "stream1"));
    assertNotNull(stream1Queue);

    s1e4.complete();
    Futures.await(s1p4);

    assertTrue(orderOfProcessing.get(s1e1.getKey()).get(3) == 4);
}

From source file:com.stb.async.ParallelExecutionProcess.java

/**
 *
 * @param processList/*from  ww  w.ja v  a2s .c o m*/
 */
public void initiateDecode(List processList) {

    Date startTime = new java.util.Date();
    System.out.println("Start Work" + startTime);
    ExecutorService es = Executors.newFixedThreadPool(10);
    Collections.sort(processList, new ProcessCompare());

    List<Future> futures = new ArrayList<>();

    for (Iterator it = processList.iterator(); it.hasNext();) {
        Process e = (Process) it.next();
        workerId = processList.indexOf(e);
        System.out.println("* Start Decode process " + processList.indexOf(e));
        futures.add(es.submit(() -> {
            new DecodedSTBProcesses((Process) processList.get(ParallelExecutionProcess.workerId)).doWork();
            return null;
        }));
    }

    es.shutdown();

    System.out.println(
            "... The Process is under execution! Using CPU core which are available, wait while work is being done....");
    int ctr = 0;
    for (Future future : futures) {
        try {
            future.get(); // blocking call, explicitly waiting for the response from a specific task, not necessarily the first task that is completed
            System.out.println("** Response of process " + ++ctr + " is in.");
        } catch (InterruptedException | ExecutionException e) {
        }
    }

    Date endTime = new java.util.Date();
    System.out.println("End work at " + endTime);
    System.out.println("Total decoding took " + new Double(0.001 * (endTime.getTime() - startTime.getTime()))
            + " seconds");
    System.exit(0);
}

From source file:cc.kave.commons.pointsto.evaluation.ProjectTrainValidateEvaluation.java

private void printSummary(List<String> names) {
    double[][] grid = new double[names.size()][names.size()];

    for (Map.Entry<ICoReTypeName, List<EvaluationResult>> resultEntry : results.entrySet()) {
        for (EvaluationResult result : resultEntry.getValue()) {
            grid[names.indexOf(result.training)][names.indexOf(result.validation)] += result.score;
        }//from  w w w. ja va 2  s.com
    }

    PrintStream printer = System.out;
    double numTypes = results.size();
    for (int i = 0; i < names.size(); ++i) {
        printer.print(names.get(i));

        for (int j = 0; j < names.size(); ++j) {
            printer.print(' ');
            printer.printf(Locale.US, "%.3f", grid[i][j] / numTypes);
        }
        printer.println();
    }
}

From source file:org.wallerlab.yoink.regionizer.partitioner.CubePartitioner.java

private void checkEveryGridPoint(Map<Region.Name, Region> regions, Region.Name cubeRegionName,
        List<GridPoint> gridPoints, List<Coord> coordinates) {
    coordinates.parallelStream().forEach(currentCoord -> {
        Map<String, Object> properties = gridPointAssigner.assign(currentCoord, regions, cubeRegionName);
        if (!properties.isEmpty()) {
            SimpleGridPoint gridPoint = new SimpleGridPoint();
            gridPoint.setCoordinate(currentCoord);
            gridPoint.setIndexInCube(coordinates.indexOf(currentCoord));
            gridPoint.setProperties(properties);
            gridPoints.add(gridPoint);/*from  w w w .ja  va2 s .  c  om*/
        }
    });
}