Example usage for java.lang Float Float

List of usage examples for java.lang Float Float

Introduction

In this page you can find the example usage for java.lang Float Float.

Prototype

@Deprecated(since = "9")
public Float(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Float object that represents the floating-point value of type float represented by the string.

Usage

From source file:com.viewer.servlets.ViewDocument.java

public final String GetFileUrl(String path, boolean getPdf, boolean isPrintable, String fileDisplayName,

        String watermarkText, Integer watermarkColor, WatermarkPosition watermarkPosition, Float watermarkWidth,
        boolean ignoreDocumentAbsence, boolean useHtmlBasedEngine, boolean supportPageRotation) {
    Map<String, String> queryString = new LinkedHashMap<String, String>();
    String myUrl = "path=" + path;

    queryString.put("path", path);

    if (!isPrintable) {
        queryString.put("getPdf", String.valueOf(getPdf).toLowerCase());
        myUrl = myUrl + "&getPdf=" + String.valueOf(getPdf).toLowerCase();

        if (fileDisplayName != null) {
            queryString.put("displayName", fileDisplayName);
        }//  w  ww  .ja  va  2s.  c  om
    }

    if (watermarkText != null) {
        queryString.put("watermarkText", watermarkText);
        queryString.put("watermarkColor", watermarkColor.toString());

        if (watermarkPosition != null) {
            queryString.put("watermarkPosition", watermarkPosition.toString());
        }

        if (watermarkWidth != null) {
            queryString.put("watermarkWidth", (new Float((float) watermarkWidth)).toString());
        }
    }

    if (ignoreDocumentAbsence) {
        queryString.put("ignoreDocumentAbsence", String.valueOf(ignoreDocumentAbsence).toLowerCase());
    }

    queryString.put("useHtmlBasedEngine", String.valueOf(useHtmlBasedEngine).toLowerCase());
    myUrl = myUrl + "&useHtmlBasedEngine=" + String.valueOf(useHtmlBasedEngine).toLowerCase();
    queryString.put("supportPageRotation", String.valueOf(supportPageRotation).toLowerCase());
    myUrl = myUrl + "&supportPageRotation=" + String.valueOf(supportPageRotation).toLowerCase();
    String handlerName = isPrintable ? "GetPdfWithPrintDialog" : "GetFile";
    String baseUrl = "http://localhost:8080/" + handlerName + "?" + myUrl;
    String fileUrl = baseUrl + handlerName + queryString;
    return baseUrl;
}

From source file:ar.com.fdvs.dj.domain.chart.builder.DJScatterChartBuilder.java

/**
 * Sets the line width.//from  www.j av  a2  s  .c  o  m
 *
 * @param lineWidth the line width
 **/
public DJScatterChartBuilder setLineWidth(float lineWidth) {
    this.chart.getOptions().setLineWidth(new Float(lineWidth));
    return this;
}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testFloat() throws Exception {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();
    final Random random = new Random();
    final float val1 = random.nextFloat();
    final Float val2 = random.nextFloat();

    assertThat(config.getProperty(key), nullValue());

    config.setProperty(key, val1);
    assertEquals(val1, config.getFloat(key), 10e-6);
    assertEquals(new Float(val1), config.getFloat(key, val2));

    config.setProperty(key, val2);
    assertEquals(val2, config.getFloat(key), 10e-6);
    assertEquals(val2, config.getFloat(key, Float.valueOf(val1)));

}

From source file:ar.com.fdvs.dj.domain.chart.builder.DJTimeSeriesChartBuilder.java

/**
 * Sets the line width.//from   w ww .j ava 2s  . co m
 *
 * @param lineWidth the line width
 **/
public DJTimeSeriesChartBuilder setLineWidth(float lineWidth) {
    this.chart.getOptions().setLineWidth(new Float(lineWidth));
    return this;
}

From source file:it.geosolutions.geobatch.destination.ingestion.GateIngestionProcess.java

/**
 * Imports the gate data from the exported file to database.
 * //from w  w w. j  a  v a 2  s. com
 * @param ignorePks Flag to indicates that should ignore pks in the xml file and
 *        create a new one with a sequence manager
 * @throws IOException
 * 
 * @return resume of the operation in a map
 */
public Map<String, Object> doProcess(boolean ignorePks, boolean copyFileAtEnd, String successPath,
        String failPath) throws IOException {

    Map<String, Object> result = new HashMap<String, Object>();
    List<Long> ids = new ArrayList<Long>();
    reset();
    this.ignorePks = ignorePks;
    if (isValid()) {

        int process = -1;
        int trace = -1;
        int errors = 0;
        int total = 0;
        int processed = 0;
        float percent = 0;

        try {

            process = createProcess();

            // write log for the imported file
            trace = logFile(process, DEFAULT_GATE_TYPE, PARTNER, PARTNER_CODE, date, false);

            // Read xml file
            ExportData exportData = null;
            try {
                exportData = JAXB.unmarshal(file, ExportData.class);
            } catch (Exception e) {
                String msg = "Unknown file format for gate ingestion";
                updateProgress(90, msg);
                metadataHandler.logError(trace, errors, msg, getError(e), 0);
                throw new IOException(msg);
            }

            if (exportData != null && exportData.getTransits().size() == 1) {
                Transits transits = exportData.getTransits().get(0);
                total = transits.getTransit().size();
                float ftot = new Float(total);

                // Insert one by one
                for (Transit transit : transits.getTransit()) {
                    Long id = null;
                    try {

                        // Update status
                        inputCount++;
                        float fproc = new Float(++processed);
                        String msg = "Importing data in transit table: " + (processed) + "/" + total;
                        percent = (fproc++ / ftot);
                        if (processed % 100 == 0) {
                            updateProgress(percent * 100, msg);
                            if (LOGGER.isInfoEnabled()) {
                                LOGGER.info(msg);
                            }
                        }

                        // insert
                        id = createTransit(transit);

                        // add to result
                        if (id != null) {
                            // Trace insert
                            if (LOGGER.isTraceEnabled()) {
                                LOGGER.trace("Correctly insert id " + id);
                            }
                            ids.add(id);
                        } else {
                            if (LOGGER.isTraceEnabled()) {
                                LOGGER.trace("Error on gate ingestion for element " + inputCount);
                            }
                        }

                    } catch (Exception e) {
                        errors++;
                        if (id != null) {
                            metadataHandler.logError(trace, errors, "Error on gate ingestion", getError(e),
                                    id.intValue());
                            /*String msg = "Error on gate ingestion for id "
                            + id.intValue();
                            updateProgress(percent * 100, msg);
                            LOGGER.error(msg);*/
                        } else {
                            metadataHandler.logError(trace, errors, "Error importing element " + inputCount,
                                    getError(e), 0);
                            /*String msg = "Error on gate ingestion for element "
                            + inputCount;
                            updateProgress(percent * 100, msg);
                            LOGGER.error(msg);*/
                        }
                    }
                }
            } else {
                LOGGER.error("Incorrect format for ingestion");
            }

            // all complete
            importFinished(total, errors, "Data imported in transit table");
            metadataHandler.updateLogFile(trace, total, errors, true);

        } catch (IOException e) {
            errors++;
            metadataHandler.logError(trace, errors, "Error importing data", getError(e), 0);

            // close current process phase
            process = closeProcess(process);

            throw e;
        } finally {
            if (process != -1) {
                // close current process phase
                metadataHandler.closeProcessPhase(process, "A");
            }

        }

        // save counts
        result.put(ERROR_COUNT, errors);
        result.put(PROCESSED_COUNT, processed);
        result.put(TOTAL_COUNT, total);

        if (copyFileAtEnd) {
            if (errors > 0) {
                copyFile(file, failPath);
            } else {
                copyFile(file, successPath);
            }
        }

        // close current process phase
        process = closeProcess(process);
    }

    // save ids
    result.put(IDS, ids);

    return result;
}

From source file:easyJ.common.validate.GenericTypeValidator.java

/**
 * Checks if the value can safely be converted to a float primitive.
 * /*  ww  w  . j  ava2s  .c  o  m*/
 * @param value
 *                The value validation is being performed on.
 * @param locale
 *                The locale to use to parse the number (system default if
 *                null)
 * @return the converted Float value.
 */
public static Float formatFloat(String value, Locale locale) {
    Float result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getInstance(locale);
        } else {
            formatter = NumberFormat.getInstance(Locale.getDefault());
        }
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= (Float.MAX_VALUE * -1) && num.doubleValue() <= Float.MAX_VALUE) {
                result = new Float(num.floatValue());
            }
        }
    }

    return result;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Convert a Double to an Object of a given class
 * @param value Double value to convert/*ww  w .  j  a  v a  2s .  c  o m*/
 * @param clazz Class the class to convert to
 * @return new object of the given class
 * @throws IllegalArgumentException if the value is not convertible to the class
 */
public static Object doubleToObject(Double value, Class clazz) {
    if (clazz == Boolean.class)
        return new Boolean(value.doubleValue() != 0.0);
    else if (clazz == Byte.class)
        return new Byte(value.byteValue());
    else if (clazz == Short.class)
        return new Short(value.shortValue());
    else if (clazz == Integer.class)
        return new Integer(value.intValue());
    else if (clazz == Long.class)
        return new Long(value.longValue());
    else if (clazz == Float.class)
        return new Float(value.floatValue());
    else if (clazz == Double.class)
        return value;
    else if (clazz == Money.class)
        return Money.getInstance(value.doubleValue());
    else if (clazz == Duration.class)
        return Duration.getInstanceFromDouble(value);
    else if (clazz == Work.class)
        return Work.getWorkInstanceFromDouble(value);

    throw new IllegalArgumentException("Class " + clazz + " cannot be converted from a Double");
}

From source file:io.druid.segment.realtime.firehose.WikipediaIrcDecoder.java

@Override
public InputRow decodeMessage(final DateTime timestamp, String channel, String msg) {
    final Map<String, String> dimensions = Maps.newHashMap();
    final Map<String, Float> metrics = Maps.newHashMap();

    Matcher m = pattern.matcher(msg);
    if (!m.matches()) {
        throw new IllegalArgumentException("Invalid input format");
    }//  w  ww .  j  a v  a  2s.  co  m

    Matcher shortname = shortnamePattern.matcher(channel);
    if (shortname.matches()) {
        dimensions.put("language", shortname.group(1));
    }

    String page = m.group(1);
    String pageUrl = page.replaceAll("\\s", "_");

    dimensions.put("page", pageUrl);

    String user = m.group(4);
    Matcher ipMatch = ipPattern.matcher(user);
    boolean anonymous = ipMatch.matches();
    if (anonymous) {
        try {
            final InetAddress ip = InetAddress.getByName(ipMatch.group());
            final Omni lookup = geoLookup.omni(ip);

            dimensions.put("continent", lookup.getContinent().getName());
            dimensions.put("country", lookup.getCountry().getName());
            dimensions.put("region", lookup.getMostSpecificSubdivision().getName());
            dimensions.put("city", lookup.getCity().getName());
        } catch (UnknownHostException e) {
            log.error(e, "invalid ip [%s]", ipMatch.group());
        } catch (IOException e) {
            log.error(e, "error looking up geo ip");
        } catch (GeoIp2Exception e) {
            log.error(e, "error looking up geo ip");
        }
    }
    dimensions.put("user", user);

    final String flags = m.group(2);
    dimensions.put("unpatrolled", Boolean.toString(flags.contains("!")));
    dimensions.put("newPage", Boolean.toString(flags.contains("N")));
    dimensions.put("robot", Boolean.toString(flags.contains("B")));

    dimensions.put("anonymous", Boolean.toString(anonymous));

    String[] parts = page.split(":");
    if (parts.length > 1 && !parts[1].startsWith(" ")) {
        Map<String, String> channelNamespaces = namespaces.get(channel);
        if (channelNamespaces != null && channelNamespaces.containsKey(parts[0])) {
            dimensions.put("namespace", channelNamespaces.get(parts[0]));
        } else {
            dimensions.put("namespace", "wikipedia");
        }
    } else {
        dimensions.put("namespace", "article");
    }

    float delta = m.group(6) != null ? Float.parseFloat(m.group(6)) : 0;
    metrics.put("delta", delta);
    metrics.put("added", Math.max(delta, 0));
    metrics.put("deleted", Math.min(delta, 0));

    return new InputRow() {
        @Override
        public List<String> getDimensions() {
            return dimensionList;
        }

        @Override
        public long getTimestampFromEpoch() {
            return timestamp.getMillis();
        }

        @Override
        public DateTime getTimestamp() {
            return timestamp;
        }

        @Override
        public List<String> getDimension(String dimension) {
            final String value = dimensions.get(dimension);
            if (value != null) {
                return ImmutableList.of(value);
            } else {
                return ImmutableList.of();
            }
        }

        @Override
        public Object getRaw(String dimension) {
            return dimensions.get(dimension);
        }

        @Override
        public float getFloatMetric(String metric) {
            return metrics.get(metric);
        }

        @Override
        public long getLongMetric(String metric) {
            return new Float(metrics.get(metric)).longValue();
        }

        @Override
        public int compareTo(Row o) {
            return timestamp.compareTo(o.getTimestamp());
        }

        @Override
        public String toString() {
            return "WikipediaRow{" + "timestamp=" + timestamp + ", dimensions=" + dimensions + ", metrics="
                    + metrics + '}';
        }
    };
}

From source file:br.bookmark.db.util.ResultSetUtils.java

/**
 * Map JDBC objects to Java equivalents.
 * Used by getBean() and getBeans().// w  w  w .  j  av a2s  .  c  om
 * <p>
 * Some types not supported.
 * Many not work with all drivers.
 * <p>
 * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER,
 * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT.
 * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY,
 * VARBINARY.
 * <p>
 * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman.
 * Others not guaranteed.
 * @param classeDestino 
 * @throws NoSuchFieldException 
 * @throws SecurityException 
 */
private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i,
        Class classeDestino) throws Exception {

    /*
    In a perfect universe, this would be enough
    properties.put(
        metaData.getColumnName(i),
        resultSet.getObject(i));
    But only String, Timestamp, and Integer seem to get through that way.
    */

    String columnName = metaData.getColumnName(i);

    // Testa se  uma FK
    /*Field[] fields = classeDestino.getDeclaredFields();
    for (int j = 0; j < fields.length; j++) {
    if (fields[j].getAnnotation(DBFK.class) != null) {
        properties.put(columnName, resultSet.getString(i));
    }
    }*/
    //System.out.println(i+"-"+metaData.getColumnType(i));
    switch (metaData.getColumnType(i)) {

    // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html

    case Types.BIGINT:
        properties.put(columnName, new Long(resultSet.getLong(i)));
        break;

    case Types.DATE:
        properties.put(columnName, resultSet.getDate(i));
        break;

    case Types.DECIMAL:
    case Types.DOUBLE:
        properties.put(columnName, new Double(resultSet.getDouble(i)));
        break;

    case Types.FLOAT:
        properties.put(columnName, new Float(resultSet.getFloat(i)));
        break;

    case Types.INTEGER:
        int valor = 0;
        try { // Se o campo esta vazio d erro
            valor = resultSet.getInt(i);
        } catch (SQLException e) {
        }
        properties.put(columnName, new Integer(valor));
        break;

    case Types.REAL:
        properties.put(columnName, new Double(resultSet.getString(i)));
        break;

    case Types.SMALLINT:
        properties.put(columnName, new Short(resultSet.getShort(i)));
        break;

    case Types.TIME:
        properties.put(columnName, resultSet.getTime(i));
        break;

    case Types.TIMESTAMP:
        properties.put(columnName, resultSet.getTimestamp(i));
        break;

    // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer
    // :FIXME: with Poolman and MySQL unless use getString.
    case Types.TINYINT:
        properties.put(columnName, new Byte(resultSet.getString(i)));
        break;

    case Types.CHAR:
    case Types.CLOB:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        // :FIXME: Handle binaries differently?
    case Types.BLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
        properties.put(columnName, resultSet.getString(i));
        break;

    /*
        :FIXME: Add handlers for
        ARRAY
        BINARY
        BIT
        DISTINCT
        JAVA_OBJECT
        NULL
        NUMERIC
        OTHER
        REF
        STRUCT
    */

    // Otherwise, pass as *String property to be converted
    default:
        properties.put(columnName + "String", resultSet.getString(i));
        break;
    } // end switch

}

From source file:org.gephi.statistics.plugin.Hits.java

public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
    hgraph.readLock();/*from   w  ww. ja va  2  s  .  c o  m*/

    int N = hgraph.getNodeCount();
    authority = new double[N];
    hubs = new double[N];
    double[] temp_authority = new double[N];
    double[] temp_hubs = new double[N];

    hub_list = new LinkedList<Node>();
    auth_list = new LinkedList<Node>();

    Progress.start(progress);

    indicies = new HashMap<Node, Integer>();
    int index = 0;
    for (Node node : hgraph.getNodes()) {
        indicies.put(node, new Integer(index));
        index++;

        if (!useUndirected) {
            if (((HierarchicalDirectedGraph) hgraph).getTotalOutDegree(node) > 0) {
                hub_list.add(node);
            }
            if (((HierarchicalDirectedGraph) hgraph).getTotalInDegree(node) > 0) {
                auth_list.add(node);
            }
        } else {
            if (((HierarchicalUndirectedGraph) hgraph).getTotalDegree(node) > 0) {
                hub_list.add(node);
                auth_list.add(node);
            }
        }
    }

    for (Node node : hub_list) {
        int n_index = indicies.get(node);
        hubs[n_index] = 1.0f;
    }
    for (Node node : auth_list) {
        int n_index = indicies.get(node);
        authority[n_index] = 1.0f;
    }

    while (true) {

        boolean done = true;
        double auth_sum = 0;
        for (Node node : auth_list) {

            int n_index = indicies.get(node);
            temp_authority[n_index] = authority[n_index];
            EdgeIterable edge_iter;
            if (!useUndirected) {
                edge_iter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(node);
            } else {
                edge_iter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(node);
            }
            for (Edge edge : edge_iter) {
                Node target = hgraph.getOpposite(node, edge);
                int target_index = indicies.get(target);
                temp_authority[n_index] += hubs[target_index];
            }

            auth_sum += temp_authority[n_index];
            if (isCanceled) {
                break;
            }

        }

        double hub_sum = 0;
        for (Node node : hub_list) {

            int n_index = indicies.get(node);
            temp_hubs[n_index] = hubs[n_index];
            EdgeIterable edge_iter;
            if (!useUndirected) {
                edge_iter = ((HierarchicalDirectedGraph) hgraph).getInEdgesAndMetaInEdges(node);
            } else {
                edge_iter = ((HierarchicalUndirectedGraph) hgraph).getEdgesAndMetaEdges(node);
            }
            for (Edge edge : edge_iter) {
                Node target = hgraph.getOpposite(node, edge);
                int target_index = indicies.get(target);
                temp_hubs[n_index] += authority[target_index];
            }
            hub_sum += temp_hubs[n_index];
            if (isCanceled) {
                break;
            }
        }

        for (Node node : auth_list) {
            int n_index = indicies.get(node);
            temp_authority[n_index] /= auth_sum;
            if (((temp_authority[n_index] - authority[n_index]) / authority[n_index]) >= epsilon) {
                done = false;
            }
        }
        for (Node node : hub_list) {
            int n_index = indicies.get(node);
            temp_hubs[n_index] /= hub_sum;
            if (((temp_hubs[n_index] - hubs[n_index]) / hubs[n_index]) >= epsilon) {
                done = false;
            }
        }

        authority = temp_authority;
        hubs = temp_hubs;
        temp_authority = new double[N];
        temp_hubs = new double[N];

        if ((done) || (isCanceled)) {
            break;
        }
    }

    AttributeTable nodeTable = attributeModel.getNodeTable();
    AttributeColumn authorityCol = nodeTable.getColumn(AUTHORITY);
    AttributeColumn hubsCol = nodeTable.getColumn(HUB);
    if (authorityCol == null) {
        authorityCol = nodeTable.addColumn(AUTHORITY, "Authority", AttributeType.FLOAT,
                AttributeOrigin.COMPUTED, new Float(0));
    }
    if (hubsCol == null) {
        hubsCol = nodeTable.addColumn(HUB, "Hub", AttributeType.FLOAT, AttributeOrigin.COMPUTED, new Float(0));
    }

    for (Node s : hgraph.getNodes()) {
        int s_index = indicies.get(s);
        AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
        row.setValue(authorityCol, (float) authority[s_index]);
        row.setValue(hubsCol, (float) hubs[s_index]);
    }

    hgraph.readUnlockAll();
}