Example usage for org.apache.commons.lang ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

Usage

From source file:org.jlucrum.realtime.generators.RsiGenerator.java

public void update(EventBean[] ebs, EventBean[] ebs1) {
    for (int i = 0; i < ebs.length; i++) {
        StockTick tick = (StockTick) ebs[i].getUnderlying();
        Double[] data = stockIndx.get(tick.getStockName());
        if (data == null) {
            data = new Double[0];
        }//w w w .j  av  a 2 s. c  o  m

        data = storeValue(data, tick.getLatestPrice());
        stockIndx.put(tick.getStockName(), data);

        if (data.length < 60)
            return;
        double input[] = ArrayUtils.toPrimitive(data);
        if (data.length > config.rsiPeriod + 1) {
            MInteger outBegIdx = new MInteger();
            MInteger outNbElement = new MInteger();
            double[] output = indicators.RSI(input, outBegIdx, outNbElement,
                    //config.rsiPeriod);
                    //                        data.length - 2); //FIXME: Which is better, calculate over all available data or tested period ????
                    50 - 2); //FIXME: Which is better, calculate over all available data or tested period ????
            if (output != null) {
                sendEvent(tick.getStockName(), output[output.length - 1]);
            }
        }
    }
}

From source file:org.jlucrum.realtime.listeners.ListenerRsiIndicator.java

public void update(EventBean[] ebs, EventBean[] ebs1) {

    //Update list of the price
    for (EventBean eb : ebs) {
        StockTick tick = (StockTick) eb.getUnderlying();
        ArrayList<Double> list = stockRsi.get(tick.getStockName());
        if (list == null) {
            list = new ArrayList<Double>();
            stockRsi.put(tick.getStockName(), list);
        }/*from www .  j  av  a 2  s .co  m*/
        list.add(tick.getLatestSell());

    }

    for (EventBean eb : ebs) {
        StockTick tick = (StockTick) eb.getUnderlying();
        ArrayList<Double> stockTicks = stockRsi.get(tick.getStockName());

        if (stockTicks.size() > getConfig(tick.getStockName()).inputRSIPeriod + 1) {
            double[] input = ArrayUtils.toPrimitive(stockTicks.toArray(new Double[0]));

            makeTest(tick.getStockName(), input);

            MInteger outBegIdx = new MInteger();
            MInteger outNbElement = new MInteger();

            double[] output = this.actionRSI(input, outBegIdx, outNbElement,
                    getConfig(tick.getStockName()).inputRSIPeriod);

            if (output[output.length - 1] < getConfig(tick.getStockName()).outputRSILowestThreshold) {
                //    System.err.printf("[%s] buy for: %f rsi:%d\n",tick.getStockName(), tick.getLatestSell(), getConfig(tick.getStockName()).outputRSILowestThreshold);
                getBudjetCounter(tick.getStockName()).buy(tick.getLatestSell(), -1);
            } else if (output[output.length - 1] > getConfig(tick.getStockName()).outputRSIHigestThreshold) {
                getBudjetCounter(tick.getStockName()).buy(tick.getLatestBuy(), -1);
            }
            //System.out.printf("Size of output:%d rsi:%d\n", output.length, getConfig(tick.getStockName()).inputRSIPeriod);

            EsperEventRsi rsiEvent = new EsperEventRsi();
            rsiEvent.setStockName(tick.getStockName());
            rsiEvent.setRsi(output[output.length - 1]);

            this.getEngine().sendEvent(rsiEvent);

            //Sending Indicator Data
            IndicatorData data = new IndicatorData();
            data.setStockName(tick.getStockName());
            data.setIndicatorValue(output[output.length - 1]);
            data.setIndicatorName("RSI");

            this.getEngine().sendEvent(data);

            getBudjetCounter(tick.getStockName()).dumpResults();
        }
    }
}

From source file:org.jtotus.database.LocalJDBC.java

public double[] fetchPeriod(String tableName, DateTime startDate, DateTime endDate, String type) {
    BigDecimal retValue = null;/* w w w .  j  a va2  s  .c  o m*/
    PreparedStatement pstm = null;
    java.sql.Date retDate = null;
    ResultSet results = null;
    ArrayList<Double> closingPrices = new ArrayList<Double>(600);
    Connection connection = null;

    try {
        String query = "SELECT " + type + ", DATE FROM " + this.normTableName(tableName)
                + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC";
        // this.createTable(connection, this.normTableName(tableName));

        connection = this.getConnection();
        pstm = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis());
        pstm.setDate(1, startSqlDate);

        java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis());
        pstm.setDate(2, endSqlDate);

        DateIterator dateIter = new DateIterator(startDate, endDate);

        results = pstm.executeQuery();
        DateTime dateCheck;

        if (debug) {
            System.out.printf("start data %s end date: %s\n", startSqlDate.toString(), endSqlDate.toString());
        }

        while (dateIter.hasNext()) {
            dateCheck = dateIter.nextInCalendar();

            if (results.next()) {
                retValue = results.getBigDecimal(1);
                retDate = results.getDate(2);

                DateTime compCal = new DateTime(retDate.getTime());
                if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth()
                        && compCal.getMonthOfYear() == dateCheck.getMonthOfYear()
                        && compCal.getYear() == dateCheck.getYear()) {
                    closingPrices.add(retValue.doubleValue());
                    continue;
                } else {
                    results.previous();
                }
            }

            BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, type);
            if (failOverValue != null) {
                closingPrices.add(failOverValue.doubleValue());
            }
        }

    } catch (SQLException ex) {
        System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n",
                "Cosing Price", tableName);
        ex.printStackTrace();
        SQLException xp = null;
        while ((xp = ex.getNextException()) != null) {
            xp.printStackTrace();
        }

    } finally {
        try {
            if (results != null)
                results.close();
            if (pstm != null)
                pstm.close();
            if (connection != null)
                connection.close();
            //                System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections());
            //                mainPool.dispose();

        } catch (SQLException ex) {
            Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return ArrayUtils.toPrimitive(closingPrices.toArray(new Double[0]));
}

From source file:org.jtotus.database.NetworkOP.java

private double[] fetchDataPeriod(String stockName, DateTime fromDate, DateTime toDate, int col) {
    List<Double> values = new ArrayList<Double>();
    URL url;/*from  www. ja  va 2  s. co m*/

    System.out.printf("NetworkOP fetchData(%s,hex:%s, date:%s-%s col:%d)\n", stockName,
            new StockType(stockName).getHexName(), fromDate.toString(), toDate.toString(), col);

    try {
        url = new URL(this.buildRequest(fromDate, toDate, stockName));

        Document doc = Jsoup.parse(url, 2 * 1000);

        Elements elems = doc.select("td");

        DateIterator dateIter = new DateIterator(fromDate, toDate);
        while (dateIter.hasNext()) {
            Iterator<Element> iter = elems.iterator();
            String datePattern = dateFormatter.print(dateIter.nextInCalendar());

            while (iter.hasNext()) {
                Element elem = iter.next();
                String data = elem.html();

                //System.out.printf("Fetching.. :%s\n", dateFormatter.print(dateIter.getCurrentAsCalendar()));
                //String formatHttp = "<div class=\"Ensimmainen\">\n" + datePattern + "\n</div>";
                if (data.indexOf(datePattern) != -1) {

                    for (int i = 0; i < col; i++) {
                        elem = iter.next();
                    }

                    data = elem.text();
                    String fdata = data.replace(',', '.');

                    if (debug) {
                        System.out.printf("Fetched value from OP bank ->:%s for date:%s\n", fdata, datePattern);
                    }

                    values.add(Double.valueOf(fdata));
                    break;
                }
            }
        }

    } catch (IOException ex) {
        System.out.printf("Failed in :%s\n", "NetworkOP");
        //Logger.getLogger(NetworkGoogle.class.getName()).log(Level.SEVERE, null, ex);
    }

    return ArrayUtils.toPrimitive(values.toArray(new Double[0]));
}

From source file:org.mrgeo.vector.mrsvector.VectorTile.java

protected void loadFalses() {
    final ArrayList<Integer> list = new ArrayList<Integer>();
    for (final String str : FALSE_KEYS) {
        final int ndx;
        if (mrsvectortile) {
            ndx = findString(str);//from  w ww.j a va2 s .c o  m
        } else {
            ndx = findStringUnsorted(str);
        }

        if (ndx >= 0) {
            list.add(ndx);
        }
    }

    falses = ArrayUtils.toPrimitive(list.toArray(new Integer[0]));
}

From source file:org.mrgeo.vector.mrsvector.VectorTile.java

protected void loadTrues() {
    final ArrayList<Integer> list = new ArrayList<Integer>();
    for (final String str : TRUE_KEYS) {
        final int ndx;
        if (mrsvectortile) {
            ndx = findString(str);//from ww  w  .  j a va2  s .  c  om
        } else {
            ndx = findStringUnsorted(str);
        }

        if (ndx >= 0) {
            list.add(ndx);
        }
    }

    trues = ArrayUtils.toPrimitive(list.toArray(new Integer[0]));

}

From source file:org.mrgeo.vector.mrsvector.VectorTileCleaner.java

private void loadPolygons() {
    final ArrayList<Integer> polys = new ArrayList<Integer>();
    final ArrayList<ArrayList<Integer>> incs = new ArrayList<ArrayList<Integer>>();
    final ArrayList<ArrayList<Integer>> excl = new ArrayList<ArrayList<Integer>>();
    for (final String str : POLYGONS) {
        final String[] split = str.split("\\|", 3);
        final String key = split[0];
        final String[] in = split[1].split(",");
        final String[] ex = split[2].split(",");

        int ndx = findString(key);
        if (ndx >= 0) {
            polys.add(findString(key));/*from ww w .  ja va  2s  .c o m*/

            ArrayList<Integer> list = new ArrayList<Integer>();
            boolean haveinclusion = false;
            for (final String s : in) {
                if (s.length() > 0) {
                    haveinclusion = true;
                    ndx = findString(s);
                    if (ndx >= 0) {
                        list.add(findString(s));
                    }
                }
            }
            // if we didn't find any keys matching the inclusion, we need to add a "dummy", so the 
            // searches still work
            if (haveinclusion && list.size() == 0) {
                list.add(Integer.MIN_VALUE);
            }
            incs.add(list);

            list = new ArrayList<Integer>();
            boolean haveexclusion = false;

            for (final String s : ex) {
                if (s.length() > 0) {
                    haveexclusion = true;
                    ndx = findString(s);
                    if (ndx >= 0) {
                        list.add(findString(s));
                    }
                }
            }

            // if we didn't find any keys matching the exclusion, we need to add a "dummy", so the 
            // searches still work
            if (haveexclusion && list.size() == 0) {
                list.add(Integer.MIN_VALUE);
            }

            excl.add(list);
        }
    }

    polygons = ArrayUtils.toPrimitive(polys.toArray(new Integer[0]));
    inclusions = new int[polygons.length][];
    exclusions = new int[polygons.length][];

    for (int i = 0; i < polygons.length; i++) {
        ArrayList<Integer> list = incs.get(i);
        if (list.size() > 0) {
            inclusions[i] = ArrayUtils.toPrimitive(list.toArray(new Integer[0]));
        } else {
            inclusions[i] = null;
        }
        list = excl.get(i);

        if (list.size() > 0) {
            exclusions[i] = ArrayUtils.toPrimitive(list.toArray(new Integer[0]));
        } else {
            exclusions[i] = null;
        }
    }
}

From source file:org.mskcc.cbio.portal.servlet.ProteinArraySignificanceTestJSON.java

static List<double[]> separateAbundance(Set<String> alteredCases, Map<String, Double> data) {
    List<Double> alteredList = new ArrayList<Double>();
    List<Double> unalteredList = new ArrayList<Double>();

    for (Map.Entry<String, Double> entry : data.entrySet()) {
        if (alteredCases.contains(entry.getKey())) {
            alteredList.add(entry.getValue());
        } else {//from ww w.ja  v  a 2  s . c  o m
            unalteredList.add(entry.getValue());
        }
    }

    double[] alteredArray = ArrayUtils.toPrimitive(alteredList.toArray(new Double[0]));
    double[] unalteredArray = ArrayUtils.toPrimitive(unalteredList.toArray(new Double[0]));

    return Arrays.asList(unalteredArray, alteredArray);
}

From source file:org.neo4j.gis.spatial.AbstractGeometryEncoder.java

public Envelope decodeEnvelope(PropertyContainer container) {
    double[] bbox = new double[] { 0, 0, 0, 0, };
    Object bboxProp = container.getProperty(PROP_BBOX);
    if (bboxProp instanceof Double[]) {
        bbox = ArrayUtils.toPrimitive((Double[]) bboxProp);
    } else if (bboxProp instanceof double[]) {
        bbox = (double[]) bboxProp;
    }//from   ww  w  .ja va2  s.  com
    // Envelope parameters: xmin, xmax, ymin, ymax
    return new Envelope(bbox[0], bbox[2], bbox[1], bbox[3]);
}

From source file:org.neo4j.gis.spatial.generic.GenericBoundingBox.java

private double[] decodeLeafNodeBounds(PropertyContainer container) {
    double[] bbox = new double[] { 0, 0, 0, 0 };
    Object bboxProp = container.getProperty(PROP_BBOX);
    if (bboxProp instanceof Double[]) {
        bbox = ArrayUtils.toPrimitive((Double[]) bboxProp);
    } else if (bboxProp instanceof double[]) {
        bbox = (double[]) bboxProp;
    }//from   ww w .  ja v  a  2s.  c om
    // Bounding Box parameters: xmin, xmax, ymin, ymax
    return bbox;
}