Example usage for java.math BigInteger doubleValue

List of usage examples for java.math BigInteger doubleValue

Introduction

In this page you can find the example usage for java.math BigInteger doubleValue.

Prototype

public double doubleValue() 

Source Link

Document

Converts this BigInteger to a double .

Usage

From source file:com.mothsoft.alexis.engine.numeric.TopicActivityDataSetImporter.java

private void recordAggregateTopicActivity(final Long userId, final Date startDate, final BigInteger total) {

    logger.debug("Recording aggregate topic activity for user: " + userId + "; (" + startDate.toString() + ", "
            + total + ")");

    this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from w ww .  ja v a  2s  .c  o  m*/
        protected void doInTransactionWithoutResult(TransactionStatus txStatus) {
            DataSet dataSet = TopicActivityDataSetImporter.this.dataSetDao
                    .findAggregateTopicActivityDataSet(userId);

            if (dataSet == null) {
                final DataSetType type = TopicActivityDataSetImporter.this.dataSetTypeDao
                        .findSystemDataSetType(DataSetType.TOPIC_ACTIVITY);
                dataSet = new DataSet(userId, "*All Topics*", type, true);
                TopicActivityDataSetImporter.this.dataSetDao.add(dataSet);
            }

            final DataSetPoint totalPoint = new DataSetPoint(dataSet, startDate, total.doubleValue());
            TopicActivityDataSetImporter.this.dataSetPointDao.add(totalPoint);
        }
    });
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.graph.EntityGraphJGraphT.java

/**
 * Computes the depth of the graph, i.e. the maximum path length starting with the root node (if
 * a single root exists)/*from  www  .  j a v  a 2 s.  co m*/
 *
 * @return The depth of the hierarchy.
 * @throws UnsupportedOperationException
 * @throws LexicalSemanticResourceException
 */
private double computeDepth() throws LexicalSemanticResourceException {
    List<Entity> roots = new Stack<Entity>();
    roots.addAll(getRoots());
    if (roots.size() == 0) {
        logger.error("There is no root for this lexical semantic resource.");
        return Double.NaN;
    } else if (roots.size() > 1) {
        logger.warn("There are " + roots.size() + " roots for this lexical semantic resource.");
        logger.info("Trying to get root from underlying lexical semantic resource.");

        Entity root = lexSemRes.getRoot();
        if (root == null) {
            EntityGraph lcc = getLargestConnectedComponent();
            int nrOfLccNodes = lcc.getNumberOfNodes();
            int nrOfGraphNodes = this.getNumberOfNodes();

            double ratio = (double) nrOfLccNodes / (double) nrOfGraphNodes;

            logger.info("Falling back to the depth of the LCC.");

            if (ratio < 0.7) {
                logger.warn("The largest connected component contains only " + ratio * 100
                        + "% of all nodes. Depth might not be meaningful.");
            }

            return lcc.getDepth();
        } else {
            roots.clear(); // we know the real root, so remove the others
            roots.add(root);
        }
    }

    Entity root = roots.get(0);
    BigInteger bigMaxPathLength = BigInteger.valueOf(0);
    BigInteger[] returnValues = computeShortestPathLengths(root, BigInteger.ZERO, bigMaxPathLength,
            new HashSet<Entity>());
    bigMaxPathLength = returnValues[1];
    return bigMaxPathLength.doubleValue();

}

From source file:com.mothsoft.alexis.engine.numeric.TopicActivityDataSetImporter.java

private BigInteger importTopicDataForTopic(final Long topicId, final Date startDate, final Date endDate) {
    logger.debug(String.format("Importing topic activity for topic: %d between %s and %s", topicId,
            startDate.toString(), endDate.toString()));

    final String queryString = "SELECT DATE_FORMAT(td.creation_date, '%Y-%m-%d %H:00:00') as the_hour, "
            + " COUNT(td.id) from topic_document td INNER JOIN topic on topic.id = td.topic_id "
            + " WHERE td.creation_date >= ? AND td.creation_date <= ? AND td.topic_id = ? "
            + " GROUP BY the_hour ORDER BY td.creation_date";

    final BigInteger count = this.transactionTemplate.execute(new TransactionCallback<BigInteger>() {
        @Override//from w  ww. j av a 2  s. co  m
        public BigInteger doInTransaction(TransactionStatus txStatus) {
            final Query query = TopicActivityDataSetImporter.this.em.createNativeQuery(queryString);
            query.setParameter(1, startDate);
            query.setParameter(2, endDate);
            query.setParameter(3, topicId);

            final List<?> results = query.getResultList();

            if (results == null || results.isEmpty()) {
                return BigInteger.ZERO;
            } else {
                final Object[] array = (Object[]) results.get(0);
                return (BigInteger) array[1];
            }
        }
    });

    logger.debug("Data set point: (" + startDate + ", " + count + ")");

    this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            TopicActivityDataSet dataSet = TopicActivityDataSetImporter.this.dataSetDao
                    .findTopicActivityDataSet(topicId);

            if (dataSet == null) {
                final DataSetType type = TopicActivityDataSetImporter.this.dataSetTypeDao
                        .findSystemDataSetType(DataSetType.TOPIC_ACTIVITY);
                final Topic topic = TopicActivityDataSetImporter.this.topicDao.get(topicId);
                dataSet = new TopicActivityDataSet(topic, type);
                TopicActivityDataSetImporter.this.em.persist(dataSet);
            }

            final DataSetPoint point = new DataSetPoint(dataSet, startDate, count.doubleValue());
            TopicActivityDataSetImporter.this.dataSetPointDao.add(point);
        }
    });

    return count;
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.graph.EntityGraphJGraphT.java

/**
 * Computes and sets the diameter, the average degree and the average shortest path length of
 * the graph. Do not call this in the constructor. May run a while. It is called in the getters,
 * if parameters are not yet initialized when retrieved.
 *///from  w  w  w  .j  av a 2s  .com
private void setGraphParameters() {

    logger.info("Setting graph parameters.");
    // The directed graph is treated as an undirected graph to compute these parameters.
    // UndirectedGraph<String, DefaultEdge> undirectedGraph = new AsUndirectedGraph<String,
    // DefaultEdge>(directedGraph);
    logger.info("Treating the graph as undirected.");

    // Diameter is the maximum of all shortest path lengths
    // Average shortest path length is (as the name says) the average of the shortest path
    // length between all node pairs

    BigInteger bigMaxPathLength = BigInteger.valueOf(0);
    BigInteger bigShortestPathLengthSum = BigInteger.valueOf(0);
    double degreeSum = 0.0;
    double clusterCoefficientSum = 0.0;

    // iterate over all node pairs
    Set<Entity> nodes = undirectedGraph.vertexSet();

    // a hashset of the nodes which have been the start node of the computation process
    // for such nodes all path lengths have been already computed
    Set<Entity> wasSource = new HashSet<Entity>();

    int progress = 0;
    double percent = 0.0;
    for (Entity node : nodes) {

        progress++;
        percent = (double) progress / nodes.size() * 100;

        if (percent % 10 == 0) {
            logger.info("Progress: " + percent);
        }
        LoggingUtils.printProgressInfo(progress, nodes.size(), 100, LoggingUtils.ProgressInfoMode.TEXT,
                "Getting graph parameters");

        int nodeDegree = undirectedGraph.degreeOf(node);
        degreeSum += nodeDegree;

        // logger.info("Updating degree distribution.");
        updateDegreeDistribution(nodeDegree);

        // cluster coefficient C_v of a node v is the fraction of the connections that exist
        // between the
        // neighbor nodes (k_v) of this node and all allowable connections between the neighbors
        // (k_v(k_v -1)/2)
        // for degrees 0 or 1 there is no cluster coefficient, as there can be no connections
        // between neighbors
        if (nodeDegree > 1) {
            double numberOfNeighborConnections = getNumberOfNeighborConnections(node);
            clusterCoefficientSum += (numberOfNeighborConnections / (nodeDegree * (nodeDegree - 1)));
        }

        // Returns the new shortestPathLengthSum and the new maxPathLength.
        // They are returned as an double array for performance reasons.
        // I do not want to create an object, as this function is called *very* often
        // logger.info("Computing shortest path lengths.");
        BigInteger[] returnValues = computeShortestPathLengths(node, bigShortestPathLengthSum, bigMaxPathLength,
                wasSource);
        bigShortestPathLengthSum = returnValues[0];
        bigMaxPathLength = returnValues[1];

        // save the info that the node was already used as the source of path computation
        wasSource.add(node);
    }

    if (nodes.size() > 1) {
        long denominator = nodes.size() * (nodes.size() - 1) / 2;
        this.averageShortestPathLength = bigShortestPathLengthSum.divide(BigInteger.valueOf(denominator))
                .doubleValue();
        // sum of path lengths / (number of node pairs)
    } else {
        this.averageShortestPathLength = 0; // there is only one node
    }
    this.diameter = bigMaxPathLength.doubleValue();
    this.clusterCoefficient = clusterCoefficientSum / nodes.size();
}

From source file:org.egov.pgr.dashboard.service.DashboardService.java

private List<Map<String, Object>> performanceProjection(List<Object[]> wardwisePerformanceData) {
    DecimalFormat df = new DecimalFormat("####0.00");
    List<Map<String, Object>> compAggrData = new ArrayList<>();
    for (Object[] compData : wardwisePerformanceData) {
        Map<String, Object> complaintData = new HashMap<>();
        complaintData.put("name", compData[0]);
        BigInteger compData1 = (BigInteger) compData[1];
        BigInteger compData3 = (BigInteger) compData[3];
        BigInteger compData4 = (BigInteger) compData[4];
        double noOfCompAsOnDate = compData1.doubleValue();
        double noOfCompReceivedBtw = compData3.doubleValue();
        double noOfCompPenAsonDate = compData4.doubleValue();
        Double yValue = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (yValue.isNaN() || yValue.isInfinite())
            complaintData.put("y", BigDecimal.ZERO);
        else//  w w  w  . j a  v a2 s  .  c o m
            complaintData.put("y", new BigDecimal(df.format(yValue)));
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "y");
    Collections.reverse(compAggrData);
    return compAggrData;
}

From source file:org.egov.pgr.dashboard.service.DashboardService.java

private List<Map<String, Object>> performanceAnalysis(List<Object[]> wardwisePerformanceData,
        DateTime currentDate) {//  ww  w . j a  v a 2s  .c om
    List<Map<String, Object>> compAggrData = new ArrayList<>();
    String formattedFrm = endOfGivenDate(currentDate.minusDays(14)).toString(defaultDateFormatter());
    String formattedDayAfterFrm = startOfGivenDate(currentDate.minusDays(13)).toString(defaultDateFormatter());
    String formattedTo = currentDate.toString(defaultDateFormatter());
    DecimalFormat df = new DecimalFormat("####0.00");
    for (Object[] compData : wardwisePerformanceData) {
        Map<String, Object> complaintData = new HashMap<>();
        complaintData.put("zone", compData[0]);
        BigInteger compData1 = (BigInteger) compData[1];
        BigInteger compData3 = (BigInteger) compData[3];
        BigInteger compData4 = (BigInteger) compData[4];
        double noOfCompAsOnDate = compData1.doubleValue();
        double noOfCompReceivedBtw = compData3.doubleValue();
        double noOfCompPenAsonDate = compData4.doubleValue();
        complaintData.put("dateAsOn2WeekBack", formattedFrm);
        complaintData.put("noOfCompAsOnDate", noOfCompAsOnDate);
        complaintData.put("dateAsOnDayAfter", formattedDayAfterFrm);
        complaintData.put("noOfCompReceivedBtw", noOfCompReceivedBtw);
        complaintData.put("dateAsOn", formattedTo);
        complaintData.put("noOfCompPenAsonDate", noOfCompPenAsonDate);
        Double disposalPerc = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (disposalPerc.isNaN() || disposalPerc.isInfinite())
            complaintData.put(DISPOSALPERC, "0.00");
        else
            complaintData.put(DISPOSALPERC, df.format(disposalPerc));
        complaintData.put("lat", compData[6]);
        complaintData.put("lng", compData[7]);
        complaintData.put("zoneId", compData[8]);
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, DISPOSALPERC);
    Collections.reverse(compAggrData);
    // ASSIGN A RANK BASED ON ORDER
    assignRank(compAggrData, "rank");
    return compAggrData;
}

From source file:org.egov.pgr.service.dashboard.DashboardService.java

private List<Map<String, Object>> performanceProjection(final List<Object[]> wardwisePerformanceData,
        final DateTime currentDate) {
    final DecimalFormat df = new DecimalFormat("####0.00");
    final List<Map<String, Object>> compAggrData = new ArrayList<Map<String, Object>>();
    for (final Object[] compData : wardwisePerformanceData) {
        final Map<String, Object> complaintData = new HashMap<String, Object>();
        complaintData.put("name", compData[0]);
        final BigInteger compData1 = (BigInteger) compData[1];
        final BigInteger compData3 = (BigInteger) compData[3];
        final BigInteger compData4 = (BigInteger) compData[4];
        final double noOfCompAsOnDate = compData1.doubleValue();
        final double noOfCompReceivedBtw = compData3.doubleValue();
        final double noOfCompPenAsonDate = compData4.doubleValue();
        final Double yValue = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (yValue.isNaN() || yValue.isInfinite())
            complaintData.put("y", BigDecimal.ZERO);
        else/*w w  w  .  ja va2s  . c o m*/
            complaintData.put("y", new BigDecimal(df.format(yValue)));
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "y");
    Collections.reverse(compAggrData);
    return compAggrData;
}

From source file:org.egov.pgr.service.dashboard.DashboardService.java

private List<Map<String, Object>> performanceAnalysis(final List<Object[]> wardwisePerformanceData,
        final DateTime currentDate) {
    final List<Map<String, Object>> compAggrData = new ArrayList<Map<String, Object>>();
    final String formattedFrm = endOfGivenDate(currentDate.minusDays(14)).toString(DFLT_DATE_FRMTR);
    final String formattedDayAfterFrm = startOfGivenDate(currentDate.minusDays(13)).toString(DFLT_DATE_FRMTR);
    final String formattedTo = currentDate.toString(DFLT_DATE_FRMTR);
    final DecimalFormat df = new DecimalFormat("####0.00");
    for (final Object[] compData : wardwisePerformanceData) {
        final Map<String, Object> complaintData = new HashMap<String, Object>();
        complaintData.put("zone", compData[0]);
        final BigInteger compData1 = (BigInteger) compData[1];
        final BigInteger compData3 = (BigInteger) compData[3];
        final BigInteger compData4 = (BigInteger) compData[4];
        final double noOfCompAsOnDate = compData1.doubleValue();
        final double noOfCompReceivedBtw = compData3.doubleValue();
        final double noOfCompPenAsonDate = compData4.doubleValue();
        complaintData.put("dateAsOn2WeekBack", formattedFrm);
        complaintData.put("noOfCompAsOnDate", noOfCompAsOnDate);
        complaintData.put("dateAsOnDayAfter", formattedDayAfterFrm);
        complaintData.put("noOfCompReceivedBtw", noOfCompReceivedBtw);
        complaintData.put("dateAsOn", formattedTo);
        complaintData.put("noOfCompPenAsonDate", noOfCompPenAsonDate);
        final Double disposalPerc = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (disposalPerc.isNaN() || disposalPerc.isInfinite())
            complaintData.put("disposalPerc", "0.00");
        else/*from  ww  w  . j a v a2 s  .  c  o  m*/
            complaintData.put("disposalPerc", df.format(disposalPerc));
        complaintData.put("lat", compData[6]);
        complaintData.put("lng", compData[7]);
        complaintData.put("zoneId", compData[8]);
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "disposalPerc");
    Collections.reverse(compAggrData);
    // ASSIGN A RANK BASED ON ORDER
    assignRank(compAggrData, "rank");
    return compAggrData;
}

From source file:org.openvpms.component.system.common.jxpath.OpenVPMSTypeConverter.java

/**
 * Convert a {@link BigInteger} to another type
 * /*  w w  w.j  a  v  a2 s  .c  om*/
 * @param type
 *            the class to convert too
 * @param value
 *            the value to convert
 * @return Number
 *            the converted number of null.
 *            
 */
protected Number allocateNumber(Class type, BigInteger value) {
    if (type == Byte.class || type == byte.class) {
        return new Byte(value.byteValue());
    }
    if (type == Short.class || type == short.class) {
        return new Short(value.shortValue());
    }
    if (type == Integer.class || type == int.class) {
        return new Integer(value.intValue());
    }
    if (type == Long.class || type == long.class) {
        return new Long(value.longValue());
    }
    if (type == Float.class || type == float.class) {
        return new Float(value.floatValue());
    }
    if (type == Double.class || type == double.class) {
        return new Double(value.doubleValue());
    }
    if (type == BigDecimal.class) {
        return new BigDecimal(value);
    }
    if (type == BigInteger.class) {
        return value;
    }

    return null;
}

From source file:org.plasma.sdo.helper.DataConverter.java

public Object fromInteger(Type targetType, BigInteger value) {
    DataType targetDataType = DataType.valueOf(targetType.getName());
    switch (targetDataType) {
    case Integer:
        return value;
    case Double:
        return new Double(value.doubleValue());
    case Float:
        return new Float(value.floatValue());
    case Int://from w w  w.  j  a  v a2 s  . co  m
        return new Integer(value.intValue());
    case Long:
        return new Long(value.longValue());
    case Decimal:
        return new BigDecimal(value.doubleValue());
    case Bytes:
        return value.toByteArray();
    case String:
        //as per spec: ('+'|'-')? [0-9]+
        return value.toString();
    default:
        throw new InvalidDataConversionException(targetDataType, DataType.Integer, value);
    }
}