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:logica.EstacionMet.java

/**
 * Encargado de actualizar y guardar la informacion de un sensor en los 
 * resumenes XML//from  w  ww. ja  va 2s.c o m
 * 
 * @param registro El manejador de XML
 * @param sensorID El id del sensor cuyo resumen hay que actualizar
 * @param tipo El tipo de sensor cuyo resumen hay que actualizar
 * @param medicionS La medicion del sensor
 */
private void resumenSave(XMLConfiguration registro, Integer sensorID, String tipo, String medicionS) {
    try {
        // Busco si ya hay algun registro del sensor.
        List<String> idsRegistro = registro.getList(String.format("estacion%d.sensor.id", ID));
        int index = -1;

        for (String id : idsRegistro) {
            if (Integer.valueOf(id).equals(sensorID)) {
                index = idsRegistro.indexOf(String.valueOf(sensorID));
                break;
            }
        }
        // Si ya hay, actualizo
        if (index != -1) {
            float medicion; // Medicion actual en float
            String nMedicionesS; // Numero de mediciones
            int nMediciones;
            String maximoS; // Valor maximo de las mediciones
            float maximo;
            String minimoS; // Valor minimo de las mediciones
            float minimo;
            String medioS; // Valor medio de las mediciones
            float medio;

            // Cargo los valores
            nMedicionesS = registro.getString(String.format("estacion%d.sensor(%d).mediciones", ID, index));
            maximoS = registro.getString(String.format("estacion%d.sensor(%d).maximo", ID, index));
            minimoS = registro.getString(String.format("estacion%d.sensor(%d).minimo", ID, index));
            medioS = registro.getString(String.format("estacion%d.sensor(%d).medio", ID, index));

            // Aumento en uno la cantidad de mediciones
            nMediciones = Integer.valueOf(nMedicionesS) + 1;
            registro.setProperty(String.format("estacion%d.sensor(%d).mediciones", ID, index),
                    String.valueOf(nMediciones));

            // Recalculo maximo y minimo
            medicion = Float.valueOf(medicionS.split(" ")[0]);
            maximo = Float.valueOf(maximoS.split(" ")[0]);
            minimo = Float.valueOf(minimoS.split(" ")[0]);

            if (medicion > maximo)
                registro.setProperty(String.format("estacion%d.sensor(%d).maximo", ID, index), medicionS);
            if (medicion < minimo)
                registro.setProperty(String.format("estacion%d.sensor(%d).minimo", ID, index), medicionS);

            // Recalculo el valor medio
            medio = Float.valueOf(medioS.split(" ")[0]);

            medio = (medio + medicion) / 2;
            registro.setProperty(String.format("estacion%d.sensor(%d).medio", ID, index),
                    String.valueOf(medio));
        } else { // Si no, creo y cargo los valores como iniciales
            index = idsRegistro.size();
            registro.addProperty(String.format("estacion%d.sensor(%d).id", ID, index), sensorID.toString());
            registro.addProperty(String.format("estacion%d.sensor(%d).tipo", ID, index), tipo);
            registro.addProperty(String.format("estacion%d.sensor(%d).maximo", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).minimo", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).medio", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).mediciones", ID, index), "1");
        }

        registro.save();
    } catch (ConfigurationException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }
}

From source file:com.openshift.internal.restclient.model.ReplicationController.java

@Override
public IContainer addContainer(String name, DockerImageURI tag, Set<IPort> containerPorts,
        Map<String, String> envVars, List<String> emptyDirVolumes) {

    IContainer container = addContainer(name);
    container.setImage(tag);//  w w  w . ja v a2  s .com

    if (!emptyDirVolumes.isEmpty()) {
        Set<IVolumeMount> volumes = new HashSet<>();
        for (String path : emptyDirVolumes) {
            VolumeMount volume = new VolumeMount(new ModelNode());
            volume.setMountPath(path);
            volume.setName(String.format("%s-%s", name, emptyDirVolumes.indexOf(path) + 1));
            volumes.add(volume);
            addEmptyDirVolumeToPodSpec(volume);
        }
        container.setVolumeMounts(volumes);
    }
    if (!containerPorts.isEmpty()) {
        Set<IPort> ports = new HashSet<>();
        for (IPort port : containerPorts) {
            ports.add(new Port(new ModelNode(), port));
        }
        container.setPorts(ports);
    }
    container.setEnvVars(envVars);
    return container;
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

public void setColor(String key, Color color) {
    Series<?> series = sampler.getSeries(key);
    Integer datasetIndex = datasetMapping.get(series.getUnit());

    List<String> l = seriesMapping.get(series.getUnit());
    int colIndex = l.indexOf(key);

    int seriesIndex = enabled.indexOf(key);

    chart.getXYPlot().getRenderer(datasetIndex).setSeriesPaint(colIndex, color);
    chart.getXYPlot().getRenderer(datasetIndex).setSeriesStroke(colIndex, DEFAULT_STROKE);
    int i = 0;/*from   w  w w  .  j  av a  2 s  .c o m*/
    for (Component c : legend.getComponents()) {
        if (c instanceof ColorButton) {
            i++;
            if (i == seriesIndex + 1) {
                ((ColorButton) c).setColor(color);
            }
        }
    }
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

protected void removeSeries(JFreeChart chart, int seriesIndex) {
    Color color = (Color) chart.getPlot().getLegendItems().get(seriesIndex).getLinePaint();
    palette.release(color);//from  w  ww  . ja  v  a  2s .  c  o m
    String key = enabled.remove(seriesIndex);
    XYPlot plot = chart.getXYPlot();
    Series<?> series = sampler.getSeries(key);
    Unit unit = series.getUnit();

    Integer datasetIndex = datasetMapping.get(unit);
    TimeSeriesCollection col = (TimeSeriesCollection) plot.getDataset(datasetIndex);

    List<String> colIndices = seriesMapping.get(unit);
    int colIndex = colIndices.indexOf(key);
    colIndices.remove(key);

    col.removeSeries(colIndex);
    if (col.getSeriesCount() == 0) {
        plot.setDataset(datasetIndex, null);
        plot.setRangeAxis(datasetIndex, null);
        seriesMapping.remove(unit);
        datasetMapping.remove(unit);
    }

    rebuildLegend();
    repaint();
    gp.saveLayout();
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

public void setExchangeRatio(Date date, String from, String to, double ratio) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from www . j a v  a 2  s . c om*/
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    date = calendar.getTime();

    List list = (ArrayList) historyMap.get(from + to);
    if (list == null)
        list = new ArrayList();
    History history = new History(date, new Double(ratio));
    int index = list.indexOf(history);
    if (index != -1) {
        History old = (History) list.get(index);
        if (!old.ratio.equals(history.ratio)) {
            list.set(index, history);
            setChanged();
        }
    } else {
        list.add(history);
        setChanged();
    }
    historyMap.put(from + to, list);
    notifyObservers();
}

From source file:gov.nih.nci.caarray.plugins.genepix.GprHandler.java

private void loadDesignElementList(DataSet dataSet, DelimitedFileReader reader, ArrayDesign design)
        throws IOException {
    final DesignElementBuilder builder = new DesignElementBuilder(dataSet, design, this.arrayDao,
            this.searchDao);
    final List<String> headers = getColumnHeaders(reader); // resets reader to start of data
    final int idIndex = headers.indexOf(ID_HEADER);
    while (reader.hasNextLine()) {
        final List<String> values = reader.nextLine();
        final String probeName = values.get(idIndex);
        builder.addProbe(probeName);//w  w  w  .  j av  a  2 s  . com
    }
    builder.finish();
}

From source file:com.appdynamics.monitors.hadoop.communicator.HadoopCommunicator.java

/**
 * Returns a metric Map with all node metrics in <code>node</code>. Metric names
 * are prefixed with <code>hierarchy</code>
 *
 * @param node//from w ww .j  a  v  a2s .c om
 * @param hierarchy
 * @return Map of node metrics
 */
private Map<String, Object> getNode(Map<String, Object> node, String hierarchy) {
    Map<String, Object> rtn = new HashMap<String, Object>();

    String id = (String) node.get("id");
    if (!xmlParser.isIncludeNodeid(id)) {
        return rtn;
    }

    if (node.get("healthStatus") != null && node.get("healthStatus").equals("Healthy")) {
        rtn.put(hierarchy + "|" + id + "|healthStatus", "1");
    } else {
        rtn.put(hierarchy + "|" + id + "|healthStatus", "0");
    }

    List<String> states = new ArrayList<String>();
    states.add("NEW");
    states.add("RUNNING");
    states.add("UNHEALTHY");
    states.add("DECOMMISSIONED");
    states.add("LOST");
    states.add("REBOOTED");
    rtn.put(hierarchy + "|" + id + "|state", states.indexOf(node.get("state")));

    rtn.put(hierarchy + "|" + id + "|usedMemoryMB", node.get("usedMemoryMB"));
    rtn.put(hierarchy + "|" + id + "|availMemoryMB", node.get("availMemoryMB"));
    rtn.put(hierarchy + "|" + id + "|numContainers", node.get("numContainers"));
    return rtn;
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceWithListsEStoreImpl.java

@Override
public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) {
    PersistentEObject PersistentEObject = NeoEObjectAdapterFactoryImpl.getAdapter(object,
            PersistentEObject.class);
    @SuppressWarnings("unchecked")
    List<Object> list = (List<Object>) getFromMap(PersistentEObject, feature);
    if (list == null) {
        return -1;
    }/*from w  w w.  java  2 s. c  o m*/
    if (feature instanceof EAttribute) {
        return list.indexOf(serializeToMapValue((EAttribute) feature, value));
    } else {
        PersistentEObject childEObject = NeoEObjectAdapterFactoryImpl.getAdapter(value,
                PersistentEObject.class);
        return list.indexOf(childEObject.id());
    }
}

From source file:eionet.gdem.conversion.odf.OdsReader.java

/**
 * Set mappings in case user has changed columns ordering.
 * @param listHeaderRow List of column names.
 * @param elements List of DD XML elements.
 * @param isMainTable true if DD main table, false if GIS table.
 *//* ww w  .  j  ava2  s.co m*/
private void setColumnMappings(List<String> listHeaderRow, List<DDXmlElement> elements, boolean isMainTable) {
    for (int j = 0; j < elements.size(); j++) {
        DDXmlElement elem = elements.get(j);
        String elemLocalName = elem.getLocalName();
        int k = listHeaderRow.indexOf(elemLocalName);

        if (k > -1) {
            elem.setColIndex(k);
            elem.setMainTable(isMainTable);
        }
    }
}

From source file:org.flite.cach3.test.KeyPrefixCacheTest.java

@Test
public void test() {
    final List<Long> allIds = new ArrayList<Long>();
    final long base = System.currentTimeMillis();
    for (int ix = 0; ix < 30; ix++) {
        allIds.add(base + (ix * 5));/*from w w  w .j a  v  a  2 s .com*/
    }
    final Long singleId = allIds.get(0);
    final List<Long> multiIds = new ArrayList<Long>();
    multiIds.add(allIds.get(1));
    multiIds.add(allIds.get(2));
    multiIds.add(allIds.get(3));
    Collections.shuffle(allIds);

    final Map<Long, Integer> positions = new HashMap<Long, Integer>();
    positions.put(singleId, allIds.indexOf(singleId));
    for (final Long id : allIds) {
        positions.put(id, allIds.indexOf(id));
    }

    final TestSvc test = (TestSvc) context.getBean("testSvc");
    final StubInvalidateSingleCacheListenerImpl listener = (StubInvalidateSingleCacheListenerImpl) context
            .getBean("stubIS");

    // Test the ReadThrough's
    final String sResult1 = test.getDwarf(singleId);
    final List<String> mResult1 = test.getDwarves(allIds);

    final int singleLoc = allIds.indexOf(singleId);
    assertEquals(sResult1, mResult1.get(singleLoc));

    // Testing the invalidations.
    final int previous = listener.getTriggers().size();
    test.invalidateDwarf(singleId);
    // Make sure the listener is getting triggered.
    // Testing that the listener got invoked as required.
    assertTrue("Doesn't look like the listener got called.", listener.getTriggers().size() == previous + 1);
    final String expected = StubInvalidateSingleCacheListenerImpl.formatTriggers(TestDAOImpl.PREFIX_NAMESPACE,
            TestDAOImpl.PREFIX_STRING, singleId.toString(), null, new Object[] { singleId });
    assertEquals(expected, listener.getTriggers().get(listener.getTriggers().size() - 1));

    final List<String> mResult2 = test.getDwarves(allIds);
    final int pos1 = positions.get(singleId);
    assertFalse(sResult1.equals(mResult2.get(pos1)));

    test.invalidateDwarves(multiIds);

    final List<String> mResult3 = test.getDwarves(allIds);
    for (final Long id : multiIds) {
        final int pos = positions.get(id);
        assertFalse(mResult2.get(pos).equals(mResult3.get(pos)));
    }

    // Now, test the updates.
    final String sResult2 = test.updateDwarf(singleId);
    final List<String> mResult4 = test.getDwarves(allIds);
    assertTrue(sResult2.equals(mResult4.get(pos1)));

    final List<String> uResult1 = test.updateDwarves(multiIds);
    final List<String> mResult5 = test.getDwarves(allIds);
    for (int ix = 0; ix < multiIds.size(); ix++) {
        final Long id = multiIds.get(ix);
        final int pos = positions.get(id);
        assertEquals(uResult1.get(ix), mResult5.get(pos));
    }
}