Example usage for java.lang Float MAX_VALUE

List of usage examples for java.lang Float MAX_VALUE

Introduction

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

Prototype

float MAX_VALUE

To view the source code for java.lang Float MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type float , (2-2-23)·2127.

Usage

From source file:com.apm4all.tracy.TracyTest.java

@Test
public void testAnnotateRoot() throws InterruptedException {
    final String STRING_NAME = "stringName";
    final String stringValue = "stringValue";
    final String INT_NAME = "intName";
    final int intValue = Integer.MAX_VALUE;
    final String LONG_NAME = "longName";
    long longValue = Long.MAX_VALUE;
    final String FLOAT_NAME = "floatName";
    float floatValue = Float.MAX_VALUE;
    final String DOUBLE_NAME = "doubleName";
    double doubleValue = Double.MAX_VALUE;
    final String BOOLEAN_NAME = "booleanName";
    boolean booleanValue = true;

    Tracy.setContext(TASK_ID_VALUE, PARENT_OPT_ID_VALUE, COMPONENT_VALUE);
    Tracy.before(L1_LABEL_NAME);/*from   ww w. ja  v  a2 s . c o m*/
    Tracy.before(L11_LABEL_NAME);
    Tracy.annotateRoot(STRING_NAME, stringValue);
    Tracy.annotateRoot(INT_NAME, intValue);
    Tracy.annotateRoot(LONG_NAME, longValue);
    Tracy.annotateRoot(FLOAT_NAME, floatValue);
    Tracy.annotateRoot(DOUBLE_NAME, doubleValue);
    Tracy.annotateRoot(BOOLEAN_NAME, booleanValue);
    Tracy.after(L11_LABEL_NAME);
    Tracy.after(L1_LABEL_NAME);
    List<TracyEvent> events = Tracy.getEvents();
    assertEquals(2, events.size());
    for (TracyEvent event : events) {
        if (event.getLabel().equals(L1_LABEL_NAME)) {
            // Verify all annotations are present in root frame
            assertEquals(stringValue, event.getAnnotation(STRING_NAME));
            assertEquals(intValue, event.getAnnotation(INT_NAME));
            assertEquals(longValue, event.getAnnotation(LONG_NAME));
            assertEquals(floatValue, event.getAnnotation(FLOAT_NAME));
            assertEquals(doubleValue, event.getAnnotation(DOUBLE_NAME));
            assertEquals(booleanValue, event.getAnnotation(BOOLEAN_NAME));
        }
        if (event.getLabel().equals(L11_LABEL_NAME)) {
            // Verify all annotations are NOT present in root frame
            assertEquals(null, event.getAnnotation(STRING_NAME));
            assertEquals(null, event.getAnnotation(INT_NAME));
            assertEquals(null, event.getAnnotation(LONG_NAME));
            assertEquals(null, event.getAnnotation(FLOAT_NAME));
            assertEquals(null, event.getAnnotation(DOUBLE_NAME));
            assertEquals(null, event.getAnnotation(BOOLEAN_NAME));
        }
    }
    Tracy.clearContext();
}

From source file:org.knime.knip.suise.node.boundarymodel.contourdata.ContourDataFromCRF.java

private void showGrid(double[] grid, boolean newWindow) {
    System.arraycopy(grid, 0, m_debugArray, 0, grid.length);

    Img<FloatType> tmp = null;/*  w  w  w . ja va2s. c o m*/
    try {
        tmp = m_debugImg.factory().imgFactory(new FloatType()).create(m_debugImg, new FloatType());
    } catch (IncompatibleTypeException e) {
        // TODO Auto-generated catch block
    }
    new ImgConvert<DoubleType, FloatType>(m_debugImg.firstElement().createVariable(), new FloatType(),
            ImgConversionTypes.DIRECT).compute(m_debugImg, tmp);

    Pair<FloatType, FloatType> minmax = Operations.compute(new MinMax<FloatType>(), tmp);
    Operations.<FloatType, FloatType>map(new Normalize<FloatType>(minmax.getA().getRealDouble(),
            minmax.getB().getRealDouble(), -Float.MAX_VALUE, Float.MAX_VALUE)).compute(tmp, tmp);
    if (newWindow) {
        AWTImageTools.showInFrame(tmp, "debug");
    } else {
        m_show.show(tmp, 1.0);
    }

}

From source file:org.spout.engine.filesystem.WorldFiles.java

@SuppressWarnings("unchecked")
private static SpoutEntity loadEntityImpl(World w, CompoundTag tag, String name) {
    CompoundMap map = tag.getValue();/* w  ww.j a  v a  2 s . c  o  m*/

    @SuppressWarnings("unused")
    byte version = SafeCast.toByte(NBTMapper.toTagValue(map.get("version")), (byte) 0);
    boolean player = SafeCast.toByte(NBTMapper.toTagValue(map.get("player")), (byte) 0) == 1;

    //Read entity
    Float pX = SafeCast.toFloat(NBTMapper.toTagValue(map.get("posX")), Float.MAX_VALUE);
    Float pY = SafeCast.toFloat(NBTMapper.toTagValue(map.get("posY")), Float.MAX_VALUE);
    Float pZ = SafeCast.toFloat(NBTMapper.toTagValue(map.get("posZ")), Float.MAX_VALUE);

    if (pX == Float.MAX_VALUE || pY == Float.MAX_VALUE || pZ == Float.MAX_VALUE) {
        return null;
    }

    float sX = SafeCast.toFloat(NBTMapper.toTagValue(map.get("scaleX")), 1.0F);
    float sY = SafeCast.toFloat(NBTMapper.toTagValue(map.get("scaleY")), 1.0F);
    float sZ = SafeCast.toFloat(NBTMapper.toTagValue(map.get("scaleZ")), 1.0F);

    float qX = SafeCast.toFloat(NBTMapper.toTagValue(map.get("quatX")), 0.0F);
    float qY = SafeCast.toFloat(NBTMapper.toTagValue(map.get("quatY")), 0.0F);
    float qZ = SafeCast.toFloat(NBTMapper.toTagValue(map.get("quatZ")), 0.0F);
    float qW = SafeCast.toFloat(NBTMapper.toTagValue(map.get("quatW")), 1.0F);

    long msb = SafeCast.toLong(NBTMapper.toTagValue(map.get("UUID_msb")), new Random().nextLong());
    long lsb = SafeCast.toLong(NBTMapper.toTagValue(map.get("UUID_lsb")), new Random().nextLong());
    UUID uid = new UUID(msb, lsb);

    int view = SafeCast.toInt(NBTMapper.toTagValue(map.get("view")), 0);
    boolean observer = SafeCast
            .toGeneric(NBTMapper.toTagValue(map.get("observer")), new ByteTag("", (byte) 0), ByteTag.class)
            .getBooleanValue();

    //Setup data
    boolean controllerDataExists = SafeCast.toGeneric(NBTMapper.toTagValue(map.get("controller_data_exists")),
            new ByteTag("", (byte) 0), ByteTag.class).getBooleanValue();
    byte[] dataMap = null;
    if (controllerDataExists) {
        dataMap = SafeCast.toByteArray(NBTMapper.toTagValue(map.get("controller_data")), new byte[0]);
    }

    //Setup entity
    Region r = w.getRegionFromBlock(Math.round(pX), Math.round(pY), Math.round(pZ),
            player ? LoadOption.LOAD_GEN : LoadOption.NO_LOAD);
    if (r == null) {
        // TODO - this should never happen - entities should be located in the chunk that was just loaded
        Spout.getLogger().info("Attempted to load entity to unloaded region");
        Thread.dumpStack();
        return null;
    }
    final Transform t = new Transform(new Point(r.getWorld(), pX, pY, pZ),
            new Quaternion(qX, qY, qZ, qW, false), new Vector3(sX, sY, sZ));

    ListTag<StringTag> components = (ListTag<StringTag>) map.get("components");
    List<Class<? extends Component>> types = new ArrayList<Class<? extends Component>>(
            components.getValue().size());
    for (StringTag component : components.getValue()) {
        try {
            try {
                Class<? extends Component> clazz = (Class<? extends Component>) CommonClassLoader
                        .findPluginClass(component.getValue());
                types.add(clazz);
            } catch (ClassNotFoundException e) {
                Class<? extends Component> clazz = (Class<? extends Component>) Class
                        .forName(component.getValue());
                types.add(clazz);
            }
        } catch (ClassNotFoundException e) {
            Spout.getLogger().log(Level.SEVERE, "Unable to find component class " + component.getValue(), e);
        }
    }

    SpoutEntity e;
    if (!player) {
        e = new SpoutEntity(t, view, uid, false, dataMap, types.toArray(new Class[types.size()]));
        e.setObserver(observer);
    } else {
        e = new SpoutPlayer(name, t, view, uid, false, dataMap, types.toArray(new Class[types.size()]));
    }

    return e;
}

From source file:org.kaaproject.kaa.demo.powerplant.fragment.DashboardFragment.java

private void prepareLineChart(View rootView, List<DataReport> data) {
    lineChart = (LineChartView) rootView.findViewById(R.id.lineChart);

    TextView yAxisView = (TextView) rootView.findViewById(R.id.lineChartYAxisText);
    TextView xAxisView = (TextView) rootView.findViewById(R.id.lineChartXAxisText);

    // yAxisView.setBackgroundColor(CHART_BACKROUND_COLOR);
    yAxisView.setTextColor(LINE_CHART_AXIS_TEXT_COLOR);
    yAxisView.setTextSize(TypedValue.COMPLEX_UNIT_SP, LINE_CHART_AXIS_TEXT_SIZE);
    yAxisView.setText(Y_AXIS_LABEL);//  w w w . java  2  s  .c  o m

    // xAxisView.setBackgroundColor(CHART_BACKROUND_COLOR);
    xAxisView.setTextColor(LINE_CHART_AXIS_TEXT_COLOR);
    xAxisView.setTextSize(TypedValue.COMPLEX_UNIT_SP, LINE_CHART_AXIS_TEXT_SIZE);
    xAxisView.setText(X_AXIS_LABEL);

    // lineChart.setBackgroundColor(CHART_BACKROUND_COLOR);
    lineChart.getChartRenderer().setMinViewportXValue((float) 0);
    lineChart.getChartRenderer().setMaxViewportXValue((float) POINTS_COUNT);

    List<PointValue> values = new ArrayList<PointValue>();

    float maxValue = Float.MIN_VALUE;
    float minValue = Float.MAX_VALUE;
    int startPos = POINTS_COUNT - data.size() + 1;
    float latestValue = 0.0f;
    for (int i = 0; i < data.size(); i++) {
        if (i == 148) {
            System.out.println();
        }
        int pos = startPos + i;
        float value = 0.0f;
        for (DataPoint dp : data.get(i).getDataPoints()) {
            value += convertVoltage(dp.getVoltage());
        }
        values.add(new PointValue(pos, value));
        minValue = Math.min(minValue, value);
        maxValue = Math.max(maxValue, value);
        latestValue = value;
    }
    for (int i = 0; i < FUTURE_POINTS_COUNT; i++) {
        values.add(new PointValue(POINTS_COUNT + i + 1, latestValue));
    }

    lineChart.getChartRenderer().setMinViewportYValue(MIN_VOLTAGE);
    lineChart.getChartRenderer().setMaxViewportYValue((MAX_VOLTAGE * MAX_PANEL_PER_ZONE * NUM_ZONES) / 1000);

    // In most cased you can call data model methods in builder-pattern-like
    // manner.
    line = new Line(values).setColor(LINE_CHART_LINE_COLOR).setCubic(LINE_CHART_IS_CUBIC).setHasLabels(false)
            .setHasPoints(false).setFilled(true).setAreaTransparency(AREA_TRANSPARENCY);
    List<Line> lines = new ArrayList<Line>();
    lines.add(line);

    final LineChartData lineChartData = new LineChartData();
    lineChartData.setLines(lines);

    Axis axisX = new Axis();
    Axis axisY = new Axis().setHasLines(true);

    axisX.setTextSize(LINE_CHART_AXIS_SIZE);
    axisX.setTextColor(LINE_CHART_AXIS_COLOR);
    axisY.setTextSize(LINE_CHART_AXIS_SIZE);
    axisY.setTextColor(LINE_CHART_AXIS_COLOR);

    // This is the right way to show axis labels but has some issues with
    // layout
    final Calendar calendar = new GregorianCalendar();
    final SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss a ____________", Locale.US);

    axisX.setAutoGenerated(true);
    axisX.setFormatter(new AxisValueFormatter() {

        @Override
        public int formatValueForManualAxis(char[] formattedValue, AxisValue axisValue) {
            return format(calendar, ft, formattedValue, axisValue.getValue());
        }

        @Override
        public int formatValueForAutoGeneratedAxis(char[] formattedValue, float value, int autoDecimalDigits) {
            return format(calendar, ft, formattedValue, value);
        }

        private int format(final Calendar calendar, final SimpleDateFormat ft, char[] formattedValue,
                float value) {
            long time = System.currentTimeMillis();
            calendar.setTimeInMillis(time);
            String formatedValue = null;
            if ((int) value == POINTS_COUNT) {
                formatedValue = ft.format(calendar.getTime());
            } else {
                int delta = POINTS_COUNT - (int) value;
                if (delta % INTERVAL_FOR_HORIZONTAL_AXIS == 0 && delta > INTERVAL_FOR_HORIZONTAL_AXIS) {
                    formatedValue = "- " + (delta / 2);
                }
            }
            if (formatedValue == null) {
                return 0;
            } else {
                char[] data = formatedValue.toCharArray();
                for (int i = 0; i < data.length; i++) {
                    formattedValue[formattedValue.length - data.length + i] = data[i];
                }
                return data.length;
            }
        }
    });

    lineChartData.setAxisXBottom(axisX);
    lineChartData.setAxisYLeft(axisY);

    lineChart.setLineChartData(lineChartData);
}

From source file:org.apache.nutch.crawl.CrawlDbReader.java

private TreeMap<String, Writable> processStatJobHelper(String crawlDb, Configuration config, boolean sort)
        throws IOException, InterruptedException, ClassNotFoundException {
    Path tmpFolder = new Path(crawlDb, "stat_tmp" + System.currentTimeMillis());

    Job job = NutchJob.getInstance(config);
    config = job.getConfiguration();// ww  w .j av a2  s .c  o m
    job.setJobName("stats " + crawlDb);
    config.setBoolean("db.reader.stats.sort", sort);

    FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME));
    job.setInputFormatClass(SequenceFileInputFormat.class);

    job.setJarByClass(CrawlDbReader.class);
    job.setMapperClass(CrawlDbStatMapper.class);
    job.setCombinerClass(CrawlDbStatReducer.class);
    job.setReducerClass(CrawlDbStatReducer.class);

    FileOutputFormat.setOutputPath(job, tmpFolder);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(NutchWritable.class);

    // https://issues.apache.org/jira/browse/NUTCH-1029
    config.setBoolean("mapreduce.fileoutputcommitter.marksuccessfuljobs", false);
    FileSystem fileSystem = tmpFolder.getFileSystem(config);
    try {
        boolean success = job.waitForCompletion(true);
        if (!success) {
            String message = "CrawlDbReader job did not succeed, job status:" + job.getStatus().getState()
                    + ", reason: " + job.getStatus().getFailureInfo();
            LOG.error(message);
            fileSystem.delete(tmpFolder, true);
            throw new RuntimeException(message);
        }
    } catch (IOException | InterruptedException | ClassNotFoundException e) {
        LOG.error(StringUtils.stringifyException(e));
        fileSystem.delete(tmpFolder, true);
        throw e;
    }

    // reading the result
    SequenceFile.Reader[] readers = SegmentReaderUtil.getReaders(tmpFolder, config);

    Text key = new Text();
    NutchWritable value = new NutchWritable();

    TreeMap<String, Writable> stats = new TreeMap<>();
    for (int i = 0; i < readers.length; i++) {
        SequenceFile.Reader reader = readers[i];
        while (reader.next(key, value)) {
            String k = key.toString();
            Writable val = stats.get(k);
            if (val == null) {
                stats.put(k, value.get());
                continue;
            }
            if (k.equals("sc")) {
                float min = Float.MAX_VALUE;
                float max = Float.MIN_VALUE;
                if (stats.containsKey("scn")) {
                    min = ((FloatWritable) stats.get("scn")).get();
                } else {
                    min = ((FloatWritable) stats.get("sc")).get();
                }
                if (stats.containsKey("scx")) {
                    max = ((FloatWritable) stats.get("scx")).get();
                } else {
                    max = ((FloatWritable) stats.get("sc")).get();
                }
                float fvalue = ((FloatWritable) value.get()).get();
                if (min > fvalue) {
                    min = fvalue;
                }
                if (max < fvalue) {
                    max = fvalue;
                }
                stats.put("scn", new FloatWritable(min));
                stats.put("scx", new FloatWritable(max));
            } else if (k.equals("ft") || k.equals("fi")) {
                long min = Long.MAX_VALUE;
                long max = Long.MIN_VALUE;
                String minKey = k + "n";
                String maxKey = k + "x";
                if (stats.containsKey(minKey)) {
                    min = ((LongWritable) stats.get(minKey)).get();
                } else if (stats.containsKey(k)) {
                    min = ((LongWritable) stats.get(k)).get();
                }
                if (stats.containsKey(maxKey)) {
                    max = ((LongWritable) stats.get(maxKey)).get();
                } else if (stats.containsKey(k)) {
                    max = ((LongWritable) stats.get(k)).get();
                }
                long lvalue = ((LongWritable) value.get()).get();
                if (min > lvalue) {
                    min = lvalue;
                }
                if (max < lvalue) {
                    max = lvalue;
                }
                stats.put(k + "n", new LongWritable(min));
                stats.put(k + "x", new LongWritable(max));
            } else if (k.equals("sct")) {
                FloatWritable fvalue = (FloatWritable) value.get();
                ((FloatWritable) val).set(((FloatWritable) val).get() + fvalue.get());
            } else if (k.equals("scd")) {
                MergingDigest tdigest = null;
                MergingDigest tdig = MergingDigest
                        .fromBytes(ByteBuffer.wrap(((BytesWritable) value.get()).getBytes()));
                if (val instanceof BytesWritable) {
                    tdigest = MergingDigest.fromBytes(ByteBuffer.wrap(((BytesWritable) val).getBytes()));
                    tdigest.add(tdig);
                } else {
                    tdigest = tdig;
                }
                ByteBuffer tdigestBytes = ByteBuffer.allocate(tdigest.smallByteSize());
                tdigest.asSmallBytes(tdigestBytes);
                stats.put(k, new BytesWritable(tdigestBytes.array()));
            } else {
                LongWritable lvalue = (LongWritable) value.get();
                ((LongWritable) val).set(((LongWritable) val).get() + lvalue.get());
            }
        }
        reader.close();
    }
    // remove score, fetch interval, and fetch time
    // (used for min/max calculation)
    stats.remove("sc");
    stats.remove("fi");
    stats.remove("ft");
    // removing the tmp folder
    fileSystem.delete(tmpFolder, true);
    return stats;
}

From source file:org.vertx.java.http.eventbusbridge.integration.MessageSendTest.java

@Test
public void testSendingFloatXml() throws IOException {
    final EventBusMessageType messageType = EventBusMessageType.Float;
    final Float sentFloat = Float.MAX_VALUE;
    Map<String, String> expectations = createExpectations("someaddress",
            Base64.encodeAsString(sentFloat.toString()), messageType);
    Handler<Message> messageConsumerHandler = new MessageSendHandler(sentFloat, expectations);
    vertx.eventBus().registerHandler(expectations.get("address"), messageConsumerHandler);
    String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_XML, expectations);
    HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(),
            MediaType.APPLICATION_XML);/*from   w  ww  . j  a v  a 2  s . co  m*/
}

From source file:MSUmpire.SearchResultParser.PepXMLParseHandler.java

private void GetModificationInfo(PSM psmid, Node node) throws XmlPullParserException, XmlPullParserException,
        XmlPullParserException, XmlPullParserException, XmlPullParserException, IOException {
    String PepSeq = psmid.Sequence;
    String modseq = psmid.Sequence;
    String TPPmodseq = node.getAttributes().getNamedItem("modified_peptide").getNodeValue();

    if (node.getAttributes().getNamedItem("mod_nterm_mass") != null) {
        float mass = Float.parseFloat(node.getAttributes().getNamedItem("mod_nterm_mass").getNodeValue());
        ModificationInfo matchmod = null;
        float massdiff = Float.MAX_VALUE;
        for (ModificationInfo mod : singleLCMSID.ModificationList.values()) {
            if (mod.site.equals("N-term")) {
                float diff = Math.abs(mod.mass - mass);
                if (diff < massdiff) {
                    massdiff = diff;//  w  w  w  .j  a v  a 2 s  .c  o  m
                    matchmod = mod;
                }
            }
        }
        if (matchmod != null) {
            psmid.Modifications.add(new ModificationMatch(matchmod.modification.getName(), true, 1));
            modseq = ModStringConvert.AddModIntoSeqBeforeSite(modseq, matchmod.GetKey(), -1);
        } else {
            Logger.getRootLogger().warn("Modification [" + mass + " @ nterm] for spectrum: " + psmid.SpecNumber
                    + " not found in the library:");
        }
    }
    if (node.getAttributes().getNamedItem("mod_cterm_mass") != null) {
        float mass = Float.parseFloat(node.getAttributes().getNamedItem("mod_cterm_mass").getNodeValue());

        ModificationInfo matchmod = null;
        float massdiff = Float.MAX_VALUE;
        for (ModificationInfo mod : singleLCMSID.ModificationList.values()) {
            if (mod.site.equals("C-term")) {
                float diff = Math.abs(mod.mass - mass);
                if (diff < massdiff) {
                    massdiff = diff;
                    matchmod = mod;
                }
            }
        }
        if (matchmod != null) {
            psmid.Modifications
                    .add(new ModificationMatch(matchmod.modification.getName(), true, psmid.Sequence.length()));
            modseq = ModStringConvert.AddModIntoSeqBeforeSite(modseq, matchmod.GetKey(),
                    psmid.Sequence.length() - 1);
        } else {
            Logger.getRootLogger().warn("Modification [" + mass + " @ cterm] for spectrum: " + psmid.SpecNumber
                    + " not found in the library:");
        }
    }

    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        if ("mod_aminoacid_mass".equals(node.getChildNodes().item(i).getNodeName())) {
            int idx = Integer.parseInt(
                    node.getChildNodes().item(i).getAttributes().getNamedItem("position").getNodeValue());
            String site = String.valueOf(PepSeq.charAt(idx - 1));
            float mass = Float.parseFloat(
                    node.getChildNodes().item(i).getAttributes().getNamedItem("mass").getNodeValue());

            ModificationInfo matchmod = null;
            float massdiff = Float.MAX_VALUE;
            for (ModificationInfo mod : singleLCMSID.ModificationList.values()) {
                if (mod.site.equals(site)) {
                    float diff = Math.abs(mod.mass - mass);
                    if (diff < massdiff) {
                        massdiff = diff;
                        matchmod = mod;
                    }
                }
            }
            if (matchmod != null) {
                psmid.Modifications.add(new ModificationMatch(matchmod.modification.getName(), true, idx));
                modseq = ModStringConvert.AddModIntoSeqBeforeSite(modseq, matchmod.GetKey(), idx - 1);
            } else {
                Logger.getRootLogger().warn("Modification [" + mass + " @ " + site + "] for spectrum: "
                        + psmid.SpecNumber + " not found in the library:");
            }
        }
    }
    psmid.ModSeq = modseq;
    psmid.TPPModSeq = TPPmodseq;
    //UpdateFromLuciphor(psmid, modseq);
}

From source file:pipeline.misc_util.Utils.java

private static float min(Object o) {

    if (o instanceof float[]) {
        float the_min = Float.MAX_VALUE;
        float[] fa = (float[]) o;
        for (float element : fa) {
            if (element < the_min)
                the_min = element;//from ww w  . j  a va2 s  .  c  o m
        }
        return the_min;
    } else if (o instanceof short[]) {
        int the_min = Integer.MAX_VALUE;
        short[] fa = (short[]) o;
        for (short element : fa) {
            if ((element & 0xffff) < the_min)
                the_min = (element & 0xffff);
        }
        return the_min;
    } else if (o instanceof byte[]) {
        int the_min = Integer.MAX_VALUE;
        byte[] fa = (byte[]) o;
        for (byte element : fa) {
            if ((element & 0xff) < the_min)
                the_min = (element & 0xff);
        }
        return the_min;
    } else
        throw new RuntimeException("Pixel type not handled in min");
}

From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java

private Set<Float> writeRealAttributes(int filteredCharNumber, Character realChar, boolean wasInteger) {
    int unfilteredCharNumber = realChar.getCharacterId();
    boolean useNormalValues = _context.getUseNormalValues(unfilteredCharNumber);

    List<FloatRange> values = new ArrayList<FloatRange>();
    BitSet inapplicableBits = new BitSet();

    Iterator<FilteredItem> items = _dataSet.filteredItems();
    while (items.hasNext()) {
        FilteredItem item = items.next();
        NumericAttribute attribute = (NumericAttribute) _dataSet.getAttribute(item.getItem().getItemNumber(),
                unfilteredCharNumber);/*from w w w  . j  a v  a 2  s .c o  m*/

        if (attribute == null || attribute.isCodedUnknown() || attribute.isInapplicable()
                || attribute.isVariable()) {
            FloatRange range = new FloatRange(Float.MAX_VALUE);
            values.add(range);
            if (isInapplicable(attribute)) {
                inapplicableBits.set(item.getItemNumber() - 1);
            }
            continue;
        }
        List<NumericRange> ranges = attribute.getNumericValue();
        // This can happen if the attribute has a comment but no value.
        if (ranges.isEmpty()) {
            FloatRange range = new FloatRange(-Float.MAX_VALUE);
            values.add(range);
            if (isInapplicable(attribute)) {
                inapplicableBits.set(item.getItemNumber() - 1);
            }
            continue;
        }
        Range useRange;
        float min = Float.MAX_VALUE;
        float max = -Float.MAX_VALUE;
        for (NumericRange range : ranges) {
            if (_context.hasAbsoluteError(unfilteredCharNumber)) {
                range.setAbsoluteError(_context.getAbsoluteError(unfilteredCharNumber));
            } else if (_context.hasPercentageError(unfilteredCharNumber)) {
                range.setPercentageError(_context.getPercentageError(unfilteredCharNumber));
            }
            if (useNormalValues) {
                useRange = range.getNormalRange();
            } else {
                useRange = range.getFullRange();
            }
            min = Math.min(min, useRange.getMinimumFloat());
            max = Math.max(max, useRange.getMaximumFloat());

        }

        FloatRange floatRange = new FloatRange(min, max);
        values.add(floatRange);
    }

    Set<Float> floats = new HashSet<Float>();
    for (FloatRange range : values) {
        if (range.getMinimumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) {
            floats.add(range.getMinimumFloat());
        } else {
            if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) {
                floats.add(0f); // For CONFOR compatibility, seems wrong.
            }
        }
        if (range.getMaximumFloat() != Float.MAX_VALUE && range.getMinimumFloat() != -Float.MAX_VALUE) {
            floats.add(range.getMaximumFloat());
        } else {
            if (range.getMinimumFloat() == -Float.MAX_VALUE && !wasInteger) {
                floats.add(1.0f); // For CONFOR compatibility, seems wrong.
            }
        }
    }
    List<Float> boundaries = new ArrayList<Float>(floats);
    Collections.sort(boundaries);
    _itemsFile.writeAttributeFloats(filteredCharNumber, inapplicableBits, values, boundaries);

    return floats;
}

From source file:com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter.java

protected boolean isInRange(Number value, String stringValue, Class toType) {
    Number bigValue = null;/*from ww  w. j a  v  a 2s. c  o  m*/
    Number lowerBound = null;
    Number upperBound = null;

    try {
        if (double.class == toType || Double.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Double.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Double.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Double.MAX_VALUE);
        } else if (float.class == toType || Float.class == toType) {
            bigValue = new BigDecimal(stringValue);
            // Float.MIN_VALUE is the smallest positive non-zero number
            lowerBound = BigDecimal.valueOf(Float.MAX_VALUE).negate();
            upperBound = BigDecimal.valueOf(Float.MAX_VALUE);
        } else if (byte.class == toType || Byte.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Byte.MIN_VALUE);
            upperBound = BigInteger.valueOf(Byte.MAX_VALUE);
        } else if (char.class == toType || Character.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Character.MIN_VALUE);
            upperBound = BigInteger.valueOf(Character.MAX_VALUE);
        } else if (short.class == toType || Short.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Short.MIN_VALUE);
            upperBound = BigInteger.valueOf(Short.MAX_VALUE);
        } else if (int.class == toType || Integer.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Integer.MIN_VALUE);
            upperBound = BigInteger.valueOf(Integer.MAX_VALUE);
        } else if (long.class == toType || Long.class == toType) {
            bigValue = new BigInteger(stringValue);
            lowerBound = BigInteger.valueOf(Long.MIN_VALUE);
            upperBound = BigInteger.valueOf(Long.MAX_VALUE);
        }
    } catch (NumberFormatException e) {
        //shoult it fail here? BigInteger doesnt seem to be so nice parsing numbers as NumberFormat
        return true;
    }

    return ((Comparable) bigValue).compareTo(lowerBound) >= 0
            && ((Comparable) bigValue).compareTo(upperBound) <= 0;
}