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.rockhoppertech.music.scale.Scale.java

public int pitchToDegree(final String key, final String pitch) {
    // Pitch kp = PitchFactory.getPitch(key);
    final Pitch p = PitchFactory.getPitch(pitch);
    final List<Pitch> pits = this.getDegreesAsPitches(key);
    String msg = null;//from   ww w  .  j  av a 2  s  . c o m
    int degree = 0;

    if (pits.contains(p)) {
        degree = pits.indexOf(p);
        degree++; // music is not zero based
        msg = String.format("contains at index/degree=%d", degree);
        Scale.logger.debug(msg);
        return degree;
    }

    for (int i = 0; i < pits.size(); i++) {
        final Pitch cp = pits.get(i);
        if (cp.getMidiNumber() == p.getMidiNumber() + 1) {
            msg = String.format("raised at index=%d", i);
            Scale.logger.debug(msg);
            return i;
        }
    }

    // for (int i = 0; i < this.degrees.length; i++) {
    // if(this.degrees[i] + kp.getMidiNumber() == p.getMidiNumber()) {
    // degree = 0;
    // break;
    // }
    // }
    return degree;
}

From source file:org.guzz.builder.GuzzConfigFileBuilder.java

protected Document loadFullConfigFile(Resource resource, String encoding)
        throws DocumentException, IOException, SAXException {
    SAXReader reader = null;//from  www . ja  v a  2s .c o  m
    Document document = null;

    reader = new SAXReader();
    reader.setValidation(false);
    // http://apache.org/xml/features/nonvalidating/load-external-dtd"  
    reader.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false);

    InputStreamReader isr = new InputStreamReader(resource.getInputStream(), encoding);

    document = reader.read(isr);
    final Element root = document.getRootElement();

    List list = document.selectNodes("//import");

    for (int i = 0; i < list.size(); i++) {
        Element n = (Element) list.get(i);

        String file = n.attribute("resource").getValue();

        //load included xml file.
        FileResource fr = new FileResource(resource, file);
        Document includedDoc = null;

        try {
            includedDoc = loadFullConfigFile(fr, encoding);
        } finally {
            CloseUtil.close(fr);
        }

        List content = root.content();
        int indexOfPos = content.indexOf(n);

        content.remove(indexOfPos);

        //appends included docs
        Element ie = includedDoc.getRootElement();
        List ie_children = ie.content();

        for (int k = ie_children.size() - 1; k >= 0; k--) {
            content.add(indexOfPos, ie_children.get(k));
        }
    }

    return document;
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * Adds the dropoff location to the map route.
 *//*from w w  w .j av a  2 s .co m*/
private void setDropOffLocation() {
    // Defines the AutoCompleteTextView with the dropoff address
    acDropoff = (AutoCompleteTextView) findViewById(R.id.dropoffText);
    //Controls if the user has entered an address
    if (!acDropoff.getText().toString().equals("")) {
        // Gets the GeoPoint of the given address
        GeoPoint dropoffGeo = GeoHelper.getGeoPoint(acDropoff.getText().toString());
        // Gets the MapLocation from the given GeoPoint
        MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(dropoffGeo);
        // Finds the dropoff location on the route closest to the given address
        Location temp = findClosestLocationOnRoute(mapLocation);

        // Controls if the user has entered a NEW address
        if (dropoffPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayDropoffThumb != null) {
                mapView.getOverlays().remove(overlayDropoffThumb);
                overlayDropoffThumb = null;
            }
            mapView.invalidate();

            // If no pickup point is specified, we add the dropoff point to the map.
            if (pickupPoint == null) {
                dropoffPoint = temp;
                overlayDropoffThumb = drawThumb(dropoffPoint, false);
            } else { // If a pickup point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the dropoff point is after the pickup point.
                if (l.indexOf(temp) > l.indexOf(pickupPoint)) {
                    //makeToast("The droppoff point has to be after the pickup point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The droppoff point has to be after the pickup point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the dropoff point to the map by drawing a cross
                    dropoffPoint = temp;
                    overlayDropoffThumb = drawThumb(dropoffPoint, false);
                }
            }
        }
    } else {
        //makeToast("Please add a dropoff address");
        AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
        ad.setMessage("Please add a dropoff address");
        ad.setTitle("Unable to send request");
        ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

            }
        });
        ad.show();
    }
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * Adds the pickup location to the map route.
 *//* www. ja  va2 s.  co  m*/
private void setPickupLocation() {
    // Defines the AutoCompleteTextView pickupText
    acPickup = (AutoCompleteTextView) findViewById(R.id.pickupText);
    // Controls if the user has entered an address
    if (!acPickup.getText().toString().equals("")) {
        // Gets the GeoPoint of the written address
        GeoPoint pickupGeo = GeoHelper.getGeoPoint(acPickup.getText().toString());
        // Gets the MapLocation of the GeoPoint
        MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(pickupGeo);
        // Finds the pickup location on the route closest to the given address
        Location temp = findClosestLocationOnRoute(mapLocation);

        //Controls if the user has entered a NEW address
        if (pickupPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayPickupThumb != null) {
                mapView.getOverlays().remove(overlayPickupThumb);
                overlayPickupThumb = null;
            }
            mapView.invalidate();

            // If no dropoff point is specified, we add the pickup point to the map.
            if (dropoffPoint == null) {
                pickupPoint = temp;
                overlayPickupThumb = drawThumb(pickupPoint, true);
            } else { // If a dropoff point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the pickup point is before the dropoff point.
                if (l.indexOf(temp) < l.indexOf(dropoffPoint)) {
                    //makeToast("The pickup point has to be before the dropoff point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The pickup point has to be before the dropoff point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the pickup point to the map by drawing a cross
                    pickupPoint = temp;
                    overlayPickupThumb = drawThumb(pickupPoint, true);
                }
            }
        }
    } else {
        //makeToast("Please add a pickup address");
        AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
        ad.setMessage("Please add a pickup address");
        ad.setTitle("Unable to send request");
        ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

            }
        });
        ad.show();
    }
}

From source file:edu.cmu.tetrad.data.DataUtils.java

/**
 * Returns the submatrix of m with variables in the order of the x variables.
 *///from   w  w w .j  a  v a 2s.co  m
public static TetradMatrix subMatrix(ICovarianceMatrix m, Node x, Node y, List<Node> z) {
    if (x == null) {
        throw new NullPointerException();
    }

    if (y == null) {
        throw new NullPointerException();
    }

    if (z == null) {
        throw new NullPointerException();
    }

    for (Node node : z) {
        if (node == null) {
            throw new NullPointerException();
        }
    }

    List<Node> variables = m.getVariables();
    //        TetradMatrix _covMatrix = m.getMatrix();

    // Create index array for the given variables.
    int[] indices = new int[2 + z.size()];

    indices[0] = variables.indexOf(x);
    indices[1] = variables.indexOf(y);

    for (int i = 0; i < z.size(); i++) {
        indices[i + 2] = variables.indexOf(z.get(i));
    }

    // Extract submatrix of correlation matrix using this index array.
    TetradMatrix submatrix = m.getSelection(indices, indices);

    if (containsMissingValue(submatrix)) {
        throw new IllegalArgumentException("Please remove or impute missing values first.");
    }

    return submatrix;
}

From source file:eu.opensourceprojects.mondo.benchmarks.transformationzoo.instantiator.SpecimenGenerator.java

@SuppressWarnings("unused")
private void createResource(ResourceSet resourceSet, Map<EClass, Integer> resourcesSize,
        TreeIterator<EObject> eAllContents, EObject eObject, List<EObject> ret) {
    TreeIterator<EObject> properContents = EcoreUtil.getAllProperContents(eObject, true);
    int allProperContentsSize = Iterators.size(properContents);
    EClass eClass = eObject.eClass();/*  w  ww.j a  va  2 s.  co m*/
    Integer integer = resourcesSize.get(eClass);
    if (integer != null && allProperContentsSize <= integer.intValue()) {
        createResource(resourceSet, eObject);
        setNextResourceSizeForType(resourcesSize, eClass);
        eAllContents.prune();
    } else if (eObject.eContainer() == null) {
        List<EObject> precedingSibling = ret.subList(0, ret.indexOf(eObject));
        TreeIterator<Object> allPrecedingSiblingContents = EcoreUtil.getAllProperContents(precedingSibling,
                true);
        int allPrecedingSiblingContentsSize = Iterators.size(allPrecedingSiblingContents);
        if (integer != null && allPrecedingSiblingContentsSize >= integer.intValue()) {
            createResource(resourceSet, eObject);
            setNextResourceSizeForType(resourcesSize, eClass);
            eAllContents.prune();
        }
    }
}

From source file:com.splicemachine.mrio.api.core.SMSQLUtil.java

public int[] getRowDecodingMap(List<NameType> nameTypes, List<PKColumnNamePosition> primaryKeys,
        List<String> columnNames) {
    if (LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG, "getRowDecodingMap nameTypes=%s, primaryKeys=%s, columnNames=%s", nameTypes,
                primaryKeys, columnNames);

    int[] rowDecodingMap = IntArrays.count(nameTypes.size());
    for (int i = 0; i < nameTypes.size(); i++) {
        NameType nameType = nameTypes.get(i);
        if (!isPrimaryKeyColumn(primaryKeys, nameType.getName()) && (columnNames.contains(nameType.getName())))
            rowDecodingMap[i] = columnNames.indexOf(nameType.getName());
        else/*from w  ww.  jav a 2  s. c o  m*/
            rowDecodingMap[i] = -1;
    }
    if (LOG.isTraceEnabled())
        SpliceLogUtils.trace(LOG, "getRowDecodingMap returns=%s", Arrays.toString(rowDecodingMap));
    return rowDecodingMap;
}

From source file:com.marcosanta.service.impl.KalturaServiceImpl.java

@Override
public ReporteGeneralGranulado reporteEntrysGranulado(Date fechaInicio, Date fechaFin, String valorUnitarioTam,
        String valorUnitarioMIN, String tipoReporte, String cuenta, String unidad, String fabrica,
        String programa, int novistos) {
    System.out.println(programa + " " + fabrica + " " + unidad + " " + cuenta + " ");
    ChartSeries chartStorage = new ChartSeries();
    ChartSeries chartTiempoVisto = new ChartSeries();
    ChartSeries chartProductividad = new ChartSeries();
    CartesianChartModel graficaStorage = new CartesianChartModel();
    CartesianChartModel graficaTiempoVisto = new CartesianChartModel();
    CartesianChartModel graficaProductividad = new CartesianChartModel();
    Map<Object, Number> mapaSerieTamanio = new HashMap<>();
    Map<Object, Number> mapaSerieTiempoVisto = new HashMap<>();
    Map<Object, Number> mapaSerieProductividad = new HashMap<>();
    List<SistemaReporte> listaTemporalReporte = new ArrayList<>();
    if (fechaInicio != null && fechaFin != null) {
        if (novistos == 0) {
            listaTemporalReporte = this.consultasBDService.findReportByFechaCorteNivelPrograma(fechaInicio,
                    fechaFin, unidad, fabrica, programa);
        } else {//w w  w .j av a  2 s.  co  m
            listaTemporalReporte = this.consultasBDService.findReportByFechaCorteNivelPrograma2(fechaInicio,
                    fechaFin, unidad, fabrica, programa);
        }
    } else {
        if (novistos == 0) {
            listaTemporalReporte = this.consultasBDService.findReportByNivelPrograma(unidad, fabrica, programa);
        } else {
            listaTemporalReporte = this.consultasBDService.findReportByNivelPrograma2(unidad, fabrica,
                    programa);
        }
    }
    List<CatReporteXls> reporteTemporal = new ArrayList<>();
    List<CatReporteXlsEntry> reporteTemporalGrafica = new ArrayList<>();
    for (SistemaReporte sr : listaTemporalReporte) {
        if (reporteTemporal.contains(new CatReporteXls(sr.getEntryId()))) {
            CatReporteXls caRepTmp2 = reporteTemporal
                    .get(reporteTemporal.indexOf(new CatReporteXls(sr.getEntryId())));
            caRepTmp2.setMinVistos(caRepTmp2.getMinVistos().add(new BigDecimal(sr.getTiempoVisto())));
            caRepTmp2.setTamanio((caRepTmp2.getTamanio()
                    .add(new BigDecimal((sr.getTamanio().doubleValue() / 1028) / 1028))));
            caRepTmp2.setTamUni(caRepTmp2.getTamUni().add(new BigDecimal(
                    ((sr.getTamanio().doubleValue() / 1028) / 1028) * Double.parseDouble(valorUnitarioTam))));
            caRepTmp2.setMinVisUni(caRepTmp2.getMinVisUni()
                    .add(new BigDecimal((sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)))));
            //                 caRepTmp2.setTotalEntrys(1L+caRepTmp2.getTotalEntrys());
            //                 System.out.println(caRepTmp2.getTotalEntrys());
            //                 System.out.println(caRepTmp2.getTamanio()+" "+caRepTmp2.getNombre());

        } else {
            reporteTemporal.add(new CatReporteXls(sr.getNombre(), sr.getEntryId(), sr.getNombreFabrica(),
                    sr.getNombrePrograma(), cuenta, sr.getNombre(), sr.getNombreUnidad(),
                    new BigDecimal(((sr.getTamanio().doubleValue() / 1028) / 1028)),
                    new BigDecimal(sr.getDuracion()), new BigDecimal(sr.getTiempoVisto()), sr.getFechaCorte(),
                    sr.getFechaCreacion(),
                    new BigDecimal(sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)),
                    new BigDecimal(((sr.getTamanio().doubleValue() / 1028) / 1028)
                            * Double.parseDouble(valorUnitarioTam)),
                    new BigDecimal(1L)));
        }
        if (reporteTemporalGrafica.contains(new CatReporteXlsEntry(sr.getFechaCorte()))) {
            CatReporteXlsEntry caRepTmp = reporteTemporalGrafica
                    .get(reporteTemporalGrafica.indexOf(new CatReporteXlsEntry(sr.getFechaCorte())));
            caRepTmp.setTotalEntrys(caRepTmp.getTotalEntrys() + 1L);
            caRepTmp.setTamanio(((sr.getTamanio().doubleValue() / 1028) / 1028) + caRepTmp.getTamanio());
            caRepTmp.setMinVistos(sr.getTiempoVisto() + caRepTmp.getMinVistos());
            caRepTmp.setMinVisUni(
                    (sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)) + caRepTmp.getMinVisUni());
            caRepTmp.setTamUni((sr.getTamanio() * Double.parseDouble(valorUnitarioTam)) + caRepTmp.getTamUni());
            mapaSerieTamanio.put(sr.getFechaCorte(), caRepTmp.getTamanio());
            mapaSerieTiempoVisto.put(sr.getFechaCorte(), caRepTmp.getMinVistos());
        } else {
            reporteTemporalGrafica.add(new CatReporteXlsEntry(sr.getEntryId(), sr.getNombreUnidad(),
                    sr.getNombreFabrica(), sr.getNombrePrograma(), cuenta, sr.getNombre(), sr.getTiempoVisto(),
                    ((sr.getTamanio().doubleValue() / 1028) / 1028), Long.parseLong(sr.getDuracion() + ""),
                    sr.getFechaCorte(), sr.getFechaCreacion(),
                    sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN),
                    sr.getTamanio() * Double.parseDouble(valorUnitarioTam), 1L));

            mapaSerieTamanio.put(sr.getFechaCorte(), ((sr.getTamanio().doubleValue() / 1028) / 1028));
            mapaSerieTiempoVisto.put(sr.getFechaCorte(), sr.getTiempoVisto());
        }

    }
    int cortes = 1;
    //        mapaSerieTamanio = new HashMap<>();
    if (fechaInicio != null && fechaFin != null) {
        cortes = consultasBDService.findCorteByFecha(fechaInicio, fechaFin).size();
    } else {
        cortes = consultasBDService.findCorteB().size();
    }

    for (CatReporteXlsEntry crtsxx : reporteTemporalGrafica) {
        BigDecimal prod;
        if (crtsxx.getTamUni() == 0) {
            prod = new BigDecimal(-1);
        } else {
            prod = new BigDecimal(crtsxx.getMinVisUni() - crtsxx.getTamUni());
            prod = prod.divide(new BigDecimal(crtsxx.getTamUni()), MathContext.DECIMAL128);
        }
        mapaSerieProductividad.put(crtsxx.getFechaCorte(), prod);
    }

    for (CatReporteXls crxls : reporteTemporal) {
        crxls.setTamanio(crxls.getTamanio().divide(new BigDecimal(cortes), MathContext.DECIMAL128));
        crxls.setTamUni(crxls.getTamUni().divide(new BigDecimal(cortes), MathContext.DECIMAL128));

    }
    //        for(CatReporteXlsEntry crxe:reporteTemporalGrafica){
    //            mapaSerieTamanio.put(crxe., cortes)
    //        }
    chartProductividad.setData(mapaSerieProductividad);
    chartStorage.setData(mapaSerieTamanio);
    chartTiempoVisto.setData(mapaSerieTiempoVisto);
    graficaProductividad.addSeries(chartProductividad);
    graficaStorage.addSeries(chartStorage);
    graficaTiempoVisto.addSeries(chartTiempoVisto);
    ReporteGeneralGranulado repGenGra = new ReporteGeneralGranulado(reporteTemporal, graficaStorage,
            graficaTiempoVisto, graficaProductividad);
    return repGenGra;
}

From source file:com.odoo.core.service.OSyncAdapter.java

/**
 * Removes non exist record from local database
 *
 * @param model/*from   ww w. ja v a 2s .  co m*/
 */
private void removeNonExistRecordFromLocal(OModel model) {
    List<Integer> ids = model.getServerIds();
    try {
        ODomain domain = new ODomain();
        domain.add("id", "in", new JSONArray(ids.toString()));
        JSONObject result = mOdoo.search_read(model.getModelName(), new JSONObject(), domain.get());
        JSONArray records = result.getJSONArray("records");
        if (records.length() > 0) {
            for (int i = 0; i < records.length(); i++) {
                JSONObject record = records.getJSONObject(i);
                ids.remove(ids.indexOf(record.getInt("id")));
            }
        }
        int removedCounter = 0;
        if (ids.size() > 0) {
            removedCounter = model.deleteRecords(ids, true);
        }
        Log.i(TAG, removedCounter + " Records removed from local database.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}