List of usage examples for java.lang Float MAX_VALUE
float MAX_VALUE
To view the source code for java.lang Float MAX_VALUE.
Click Source Link
From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImplTest.java
@Test public void testSetAttribute() throws Exception { Attribute attribute = new AttributeImpl(STRING, "abc"); metacard.setAttribute(attribute);/*from ww w . j av a2s.c o m*/ assertEquals("abc", baseBean.get(STRING)); attribute = new AttributeImpl(BOOLEAN, true); metacard.setAttribute(attribute); assertEquals(true, baseBean.get(BOOLEAN)); Date d = new Date(System.currentTimeMillis()); attribute = new AttributeImpl(DATE, d); metacard.setAttribute(attribute); assertEquals(d, baseBean.get(DATE)); attribute = new AttributeImpl(SHORT, Short.MIN_VALUE); metacard.setAttribute(attribute); assertEquals(Short.MIN_VALUE, baseBean.get(SHORT)); attribute = new AttributeImpl(INTEGER, Integer.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Integer.MAX_VALUE, baseBean.get(INTEGER)); attribute = new AttributeImpl(LONG, Long.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Long.MAX_VALUE, baseBean.get(LONG)); attribute = new AttributeImpl(FLOAT, Float.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Float.MAX_VALUE, baseBean.get(FLOAT)); attribute = new AttributeImpl(DOUBLE, Double.MAX_VALUE); metacard.setAttribute(attribute); assertEquals(Double.MAX_VALUE, baseBean.get(DOUBLE)); Byte[] bytes = new Byte[] { 0x00, 0x01, 0x02, 0x03 }; attribute = new AttributeImpl(BINARY, bytes); metacard.setAttribute(attribute); assertEquals(bytes, baseBean.get(BINARY)); attribute = new AttributeImpl(XML, XML_STRING); metacard.setAttribute(attribute); assertEquals(XML_STRING, baseBean.get(XML)); attribute = new AttributeImpl(OBJECT, XML_STRING); metacard.setAttribute(attribute); assertEquals(XML_STRING, baseBean.get(OBJECT)); List<Serializable> list = new ArrayList<>(); list.add("123"); list.add("234"); list.add("345"); attribute = new AttributeImpl(STRING_LIST, list); metacard.setAttribute(attribute); assertEquals(list, baseBean.get(STRING_LIST)); }
From source file:pl.mg6.android.maps.extensions.demo.AnimateMarkersActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_map); FragmentManager fm = getSupportFragmentManager(); SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map); final GoogleMap map = f.getExtendedMap(); map.addMarker(new MarkerOptions().title("RED").position(new LatLng(-15, -15)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); map.addMarker(new MarkerOptions().title("GREEN").position(new LatLng(-15, 15)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))); map.addMarker(new MarkerOptions().title("BLUE").position(new LatLng(15, -15)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); map.addMarker(new MarkerOptions().title("YELLOW").position(new LatLng(15, 15)) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW))); final Marker.AnimationCallback callback = new Marker.AnimationCallback() { @Override//from www .j av a2 s . c om public void onFinish(Marker marker) { Toast.makeText(AnimateMarkersActivity.this, "Animation finished: " + marker.getTitle(), Toast.LENGTH_SHORT).show(); } @Override public void onCancel(Marker marker, CancelReason reason) { Toast.makeText(AnimateMarkersActivity.this, "Animation canceled: " + marker.getTitle() + ", reason: " + reason, Toast.LENGTH_SHORT) .show(); } }; map.setOnMarkerClickListener(new OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { LatLng position = marker.getPosition(); LatLng targetPosition = randomPositionAcrossTheOcean(position); long duration = random.nextInt(1500) + 1500; Interpolator interpolator = randomInterpolator(); AnimationSettings settings = new AnimationSettings().duration(duration).interpolator(interpolator); marker.animatePosition(targetPosition, settings, callback); return true; } }); map.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng clickPosition) { Marker closest = null; float distanceToClosest = Float.MAX_VALUE; for (Marker marker : map.getMarkers()) { LatLng markerPosition = marker.getPosition(); float distance = LatLngUtils.distanceBetween(clickPosition, markerPosition); if (distanceToClosest > distance) { distanceToClosest = distance; closest = marker; } } if (closest != null) { closest.remove(); } } }); }
From source file:org.opencms.site.CmsSite.java
/** * Constructs a new site object.<p> * // w w w .ja va2 s . c o m * @param siteRoot root directory of this site in the OpenCms VFS * @param siteRootUUID UUID of this site's root directory in the OpenCms VFS * @param title display name of this site * @param siteMatcher the site matcher for this site * @param position the sorting position */ public CmsSite(String siteRoot, CmsUUID siteRootUUID, String title, CmsSiteMatcher siteMatcher, String position) { setSiteRoot(siteRoot); setSiteRootUUID(siteRootUUID); setTitle(title); setSiteMatcher(siteMatcher); // init the position value m_position = Float.MAX_VALUE; try { m_position = Float.parseFloat(position); } catch (Throwable e) { // m_position will have Float.MAX_VALUE, so this site will appear last } m_aliases = new ArrayList<CmsSiteMatcher>(); }
From source file:com.normsstuff.maps4norm.Util.java
/** * Get the altitude data for a specific point * * @param p the point to get the altitude for * @param httpClient can be null if no network query should be performed * @param localContext can be null if no network query should be performed * @return the altitude at point p or -Float.MAX_VALUE if no valid data * could be fetched//ww w.j a v a 2 s. co m * @throws IOException */ static float getAltitude(final LatLng p, final HttpClient httpClient, final HttpContext localContext) throws IOException { if (elevationCache == null) { elevationCache = new HashMap<LatLng, Float>(30); } if (elevationCache.containsKey(p)) { return elevationCache.get(p); } else if (httpClient != null && localContext != null) { float altitude = -Float.MAX_VALUE; String url = "http://maps.googleapis.com/maps/api/elevation/xml?locations=" + String.valueOf(p.latitude) + "," + String.valueOf(p.longitude) + "&sensor=true"; HttpGet httpGet = new HttpGet(url); HttpResponse response = httpClient.execute(httpGet, localContext); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); int r; StringBuilder respStr = new StringBuilder(); while ((r = instream.read()) != -1) respStr.append((char) r); String tagOpen = "<elevation>"; String tagClose = "</elevation>"; if (respStr.indexOf(tagOpen) != -1) { int start = respStr.indexOf(tagOpen) + tagOpen.length(); int end = respStr.indexOf(tagClose); altitude = Float.parseFloat(respStr.substring(start, end)); elevationCache.put(p, altitude); } instream.close(); } return altitude; } else { return elevationCache.get(p); } }
From source file:edu.stanford.slac.archiverappliance.PB.data.StatusSeverityTest.java
private DBR getJCASampleValue(ArchDBRTypes type, int value, int severity, int status) { switch (type) { case DBR_SCALAR_STRING: DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(value) }); retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalss.setSeverity(severity);/*from w w w.ja va2s .c om*/ retvalss.setStatus(status); return retvalss; case DBR_SCALAR_SHORT: DBR_TIME_Short retvalsh; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + value) }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (value - 1000)) }); } else { // Check for some numbers around 0 retvalsh = new DBR_TIME_Short(new short[] { (short) (value - 2000) }); } retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalsh.setSeverity(severity); retvalsh.setStatus(status); return retvalsh; case DBR_SCALAR_FLOAT: DBR_TIME_Float retvalfl; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + value }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (value - 1000) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvalfl = new DBR_TIME_Float(new float[] { (value - 2000.0f) / value }); } retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalfl.setSeverity(severity); retvalfl.setStatus(status); return retvalfl; case DBR_SCALAR_ENUM: DBR_TIME_Enum retvalen; retvalen = new DBR_TIME_Enum(new short[] { (short) (value) }); retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalen.setSeverity(severity); retvalen.setStatus(status); return retvalen; case DBR_SCALAR_BYTE: DBR_TIME_Byte retvalby; retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (value % 255)) }); retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalby.setSeverity(severity); retvalby.setStatus(status); return retvalby; case DBR_SCALAR_INT: DBR_TIME_Int retvalint; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + value }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (value - 1000) }); } else { // Check for some numbers around 0 retvalint = new DBR_TIME_Int(new int[] { (value - 2000) }); } retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalint.setSeverity(severity); retvalint.setStatus(status); return retvalint; case DBR_SCALAR_DOUBLE: DBR_TIME_Double retvaldb; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + value) }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (value - 1000)) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvaldb = new DBR_TIME_Double(new double[] { ((value - 2000.0) / (value * 1000000)) }); } retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvaldb.setSeverity(severity); retvaldb.setStatus(status); return retvaldb; case DBR_WAVEFORM_STRING: DBR_TIME_String retvst; // Varying number of copies of a typical value retvst = new DBR_TIME_String( Collections.nCopies(value, Integer.toString(value)).toArray(new String[0])); retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvst.setSeverity(severity); retvst.setStatus(status); return retvst; case DBR_WAVEFORM_SHORT: DBR_TIME_Short retvsh; retvsh = new DBR_TIME_Short( ArrayUtils.toPrimitive(Collections.nCopies(1, (short) value).toArray(new Short[0]))); retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvsh.setSeverity(severity); retvsh.setStatus(status); return retvsh; case DBR_WAVEFORM_FLOAT: DBR_TIME_Float retvf; // Varying number of copies of a typical value retvf = new DBR_TIME_Float(ArrayUtils.toPrimitive( Collections.nCopies(value, (float) Math.cos(value * Math.PI / 3600)).toArray(new Float[0]))); retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvf.setSeverity(severity); retvf.setStatus(status); return retvf; case DBR_WAVEFORM_ENUM: DBR_TIME_Enum retven; retven = new DBR_TIME_Enum( ArrayUtils.toPrimitive(Collections.nCopies(1024, (short) value).toArray(new Short[0]))); retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retven.setSeverity(severity); retven.setStatus(status); return retven; case DBR_WAVEFORM_BYTE: DBR_TIME_Byte retvb; // Large number of elements in the array retvb = new DBR_TIME_Byte(ArrayUtils .toPrimitive(Collections.nCopies(65536 * value, ((byte) (value % 255))).toArray(new Byte[0]))); retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvb.setSeverity(severity); retvb.setStatus(status); return retvb; case DBR_WAVEFORM_INT: DBR_TIME_Int retvint; // Varying number of copies of a typical value retvint = new DBR_TIME_Int( ArrayUtils.toPrimitive(Collections.nCopies(value, value * value).toArray(new Integer[0]))); retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvint.setSeverity(severity); retvint.setStatus(status); return retvint; case DBR_WAVEFORM_DOUBLE: DBR_TIME_Double retvd; // Varying number of copies of a typical value retvd = new DBR_TIME_Double(ArrayUtils.toPrimitive( Collections.nCopies(value, Math.sin(value * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvd.setSeverity(severity); retvd.setStatus(status); return retvd; case DBR_V4_GENERIC_BYTES: throw new RuntimeException("Currently don't support " + type + " when generating sample data"); default: throw new RuntimeException("We seemed to have missed a DBR type when generating sample data"); } }
From source file:org.esa.s1tbx.ocean.toolviews.polarview.SpectraDataSentinel1.java
public PolarData getPolarData(final int currentRec, final SpectraUnit spectraUnit) throws Exception { final boolean realBand = spectraUnit != SpectraUnit.IMAGINARY; spectrum = getSpectrum(currentRec, realBand); if (waveProductType == WaveProductType.WAVE_SPECTRA) { minValue = Float.MAX_VALUE; maxValue = Float.MIN_VALUE; for (int i = 0; i < spectrum.length; i++) { for (int j = 0; j < spectrum[0].length; j++) { float val = spectrum[i][j]; if (spectraUnit == SpectraUnit.INTENSITY) { val *= val; }//from w w w .j a va 2 s .com spectrum[i][j] = val; minValue = Math.min(minValue, val); maxValue = Math.max(maxValue, val); } } } else if (waveProductType == WaveProductType.CROSS_SPECTRA) { if (spectraUnit == SpectraUnit.AMPLITUDE || spectraUnit == SpectraUnit.INTENSITY) { // complex data final float imagSpectrum[][] = getSpectrum(currentRec, false); minValue = Float.MAX_VALUE; maxValue = Float.MIN_VALUE; for (int i = 0; i < spectrum.length; i++) { for (int j = 0; j < spectrum[0].length; j++) { final float realVal = spectrum[i][j]; final float imagVal = imagSpectrum[i][j]; float val; if (sign(realVal) == sign(imagVal)) { val = realVal * realVal + imagVal * imagVal; } else { val = 0.0F; } if (spectraUnit == SpectraUnit.AMPLITUDE) { val = (float) Math.sqrt(val); } spectrum[i][j] = val; minValue = Math.min(minValue, val); maxValue = Math.max(maxValue, val); } } } } final float rStep = (float) (Math.log(lastWLBin) - Math.log(firstWLBin)) / (float) (numWLBins - 1); double logr = Math.log(firstWLBin) - (rStep / 2.0); final float thFirst = firstDirBins + 5f; final float thStep = -dirBinStep; final float radii[] = new float[spectrum[0].length + 1]; for (int j = 0; j <= spectrum[0].length; j++) { radii[j] = (float) (10000.0 / FastMath.exp(logr)); logr += rStep; } return new PolarData(spectrum, 90f + thFirst, thStep, radii, minValue, maxValue); }
From source file:org.apache.nutch.crawl.DbUpdateMapper.java
@Override public void map(String key, WebPage page, Context context) throws IOException, InterruptedException { // TODO//from ww w . j a v a2 s.c o m Integer urlId = null; String sameUrlId = ""; String urlStatus = AtexpatsConstants.STATUS_NEW; for (Utf8 utf8 : page.getMetadata().keySet()) { if ("urlId".equals(Bytes.toString(utf8.getBytes()))) { try { urlId = Integer.parseInt(Bytes.toString(page.getMetadata().get(utf8)).trim()); } catch (Exception e) { urlId = null; } } if ("sameUrlId".equals(Bytes.toString(utf8.getBytes()))) { try { sameUrlId = Bytes.toString(page.getMetadata().get(utf8)).trim(); } catch (Exception e) { sameUrlId = ""; } } if ("urlStatus".equals(Bytes.toString(utf8.getBytes()))) { try { urlStatus = Bytes.toString(page.getMetadata().get(utf8)).trim(); } catch (Exception e) { urlStatus = AtexpatsConstants.STATUS_NEW; } } } if (urlId != null) { if (urlMap != null && urlMap.containsKey(urlId.toString())) { urlStatus = urlMap.get(urlId.toString()); } } String url = TableUtil.unreverseUrl(key); LOG.info("DbUpdateMapper : url = " + url); LOG.info("DbUpdateMapper : sameUrlId = " + sameUrlId); LOG.info("DbUpdateMapper : urlStatus = " + urlStatus); scoreData.clear(); Map<Utf8, Utf8> outlinks = page.getOutlinks(); if (outlinks != null) { for (Entry<Utf8, Utf8> e : outlinks.entrySet()) { int depth = Integer.MAX_VALUE; Utf8 depthUtf8 = page.getFromMarkers(DbUpdaterJob.DISTANCE); if (depthUtf8 != null) depth = Integer.parseInt(depthUtf8.toString()); scoreData.add(new ScoreDatum(0.0f, e.getKey().toString(), e.getValue().toString(), depth)); } } // TODO: Outlink filtering (i.e. "only keep the first n outlinks") try { scoringFilters.distributeScoreToOutlinks(url, page, scoreData, (outlinks == null ? 0 : outlinks.size())); } catch (ScoringFilterException e) { LOG.warn("Distributing score failed for URL: " + key + " exception:" + StringUtils.stringifyException(e)); } urlWithScore.setUrl(key); urlWithScore.setScore(Float.MAX_VALUE); // TODO Set urlId if (urlId != null) { urlWithScore.setUrlId(urlId); } if (sameUrlId != null) { urlWithScore.setSameUrlId(sameUrlId); } if (urlStatus != null) { urlWithScore.setUrlStatus(urlStatus); } // reset fetch time if status is UP if (AtexpatsConstants.STATUS_UPDATE.equals(urlStatus)) { resetFetchTime(page); } pageWritable.setWebPage(page); nutchWritable.set(pageWritable); context.write(urlWithScore, nutchWritable); for (ScoreDatum scoreDatum : scoreData) { try { String reversedOut = TableUtil.reverseUrl(scoreDatum.getUrl()); scoreDatum.setUrl(url); urlWithScore.setUrl(reversedOut); urlWithScore.setScore(scoreDatum.getScore()); nutchWritable.set(scoreDatum); // TODO Set urlId if (urlId != null) { urlWithScore.setUrlId(urlId); } if (sameUrlId != null) { urlWithScore.setSameUrlId(sameUrlId); } if (urlStatus != null) { urlWithScore.setUrlStatus(urlStatus); } context.write(urlWithScore, nutchWritable); } catch (Exception e) { LOG.error("Failed with out link: " + scoreDatum.getUrl()); LOG.error(e.getMessage()); } } }
From source file:com.stratio.ingestion.sink.cassandra.EventParserTest.java
@Test public void shouldParsePrimitiveTypes() throws Exception { Object integer = EventParser.parseValue("1", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(1); integer = EventParser.parseValue(Integer.toString(Integer.MAX_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MAX_VALUE); integer = EventParser.parseValue(Integer.toString(Integer.MIN_VALUE), DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(Integer.MIN_VALUE); integer = EventParser.parseValue(" 1 2 ", DataType.Name.INT); assertThat(integer).isInstanceOf(Integer.class).isEqualTo(12); Object counter = EventParser.parseValue("1", DataType.Name.COUNTER); assertThat(counter).isEqualTo(1L);/*from www .j a v a2s .c o m*/ counter = EventParser.parseValue(Long.toString(Long.MAX_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MAX_VALUE); counter = EventParser.parseValue(Long.toString(Long.MIN_VALUE), DataType.Name.COUNTER); assertThat(counter).isEqualTo(Long.MIN_VALUE); counter = EventParser.parseValue(" 1 2 ", DataType.Name.COUNTER); assertThat(counter).isEqualTo(12L); Object _float = EventParser.parseValue("1", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue("1.0", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); _float = EventParser.parseValue(Float.toString(Float.MAX_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MAX_VALUE); _float = EventParser.parseValue(Float.toString(Float.MIN_VALUE), DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(Float.MIN_VALUE); _float = EventParser.parseValue(" 1 . 0 ", DataType.Name.FLOAT); assertThat(_float).isInstanceOf(Float.class).isEqualTo(1f); Object _double = EventParser.parseValue("1", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); _double = EventParser.parseValue("0", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(0.0); _double = EventParser.parseValue(Double.toString(Double.MAX_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MAX_VALUE); _double = EventParser.parseValue(Double.toString(Double.MIN_VALUE), DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(Double.MIN_VALUE); _double = EventParser.parseValue(" 1 . 0 ", DataType.Name.DOUBLE); assertThat(_double).isInstanceOf(Double.class).isEqualTo(1.0); for (DataType.Name type : Arrays.asList(DataType.Name.BIGINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(1L); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(0L); bigInteger = EventParser.parseValue(Long.toString(Long.MAX_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MAX_VALUE); bigInteger = EventParser.parseValue(Long.toString(Long.MIN_VALUE), type); assertThat(bigInteger).isInstanceOf(Long.class).isEqualTo(Long.MIN_VALUE); } for (DataType.Name type : Arrays.asList(DataType.Name.VARINT)) { Object bigInteger = EventParser.parseValue("1", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ONE); bigInteger = EventParser.parseValue("0", type); assertThat(bigInteger).isInstanceOf(BigInteger.class).isEqualTo(BigInteger.ZERO); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2L))); bigInteger = EventParser.parseValue( BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L)).toString(), type); assertThat(bigInteger).isInstanceOf(BigInteger.class) .isEqualTo(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2L))); } Object bigDecimal = EventParser.parseValue("1", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(1)); bigDecimal = EventParser.parseValue("0", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(0)); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MAX_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue( BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2)).toString(), DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class) .isEqualTo(BigDecimal.valueOf(Double.MIN_VALUE).multiply(BigDecimal.valueOf(2))); bigDecimal = EventParser.parseValue(" 1 2 ", DataType.Name.DECIMAL); assertThat(bigDecimal).isInstanceOf(BigDecimal.class).isEqualTo(BigDecimal.valueOf(12)); Object string = EventParser.parseValue("string", DataType.Name.TEXT); assertThat(string).isInstanceOf(String.class).isEqualTo("string"); Object bool = EventParser.parseValue("true", DataType.Name.BOOLEAN); assertThat(bool).isInstanceOf(Boolean.class).isEqualTo(true); Object addr = EventParser.parseValue("192.168.1.1", DataType.Name.INET); assertThat(addr).isInstanceOf(InetAddress.class).isEqualTo(InetAddress.getByName("192.168.1.1")); UUID randomUUID = UUID.randomUUID(); Object uuid = EventParser.parseValue(randomUUID.toString(), DataType.Name.UUID); assertThat(uuid).isInstanceOf(UUID.class).isEqualTo(randomUUID); }
From source file:gdsc.core.utils.ConvexHull.java
/** * Create a new convex hull from the given coordinates. * <p>// w w w .ja v a2s . c o m * Uses the gift wrap algorithm to find the convex hull. * <p> * Taken from ij.gui.PolygonRoi and adapted for float coordinates. * * @param xbase * the x base coordinate (origin) * @param ybase * the y base coordinate (origin) * @param xCoordinates * the x coordinates * @param yCoordinates * the y coordinates * @param n * the number of coordinates * @return the convex hull * @throws NullPointerException * if the inputs are null * @throws ArrayIndexOutOfBoundsException * if the yCoordinates are smaller than the xCoordinates */ @SuppressWarnings("unused") private static ConvexHull createGiftWrap(float xbase, float ybase, float[] xCoordinates, float[] yCoordinates, int n) { float[] xx = new float[n]; float[] yy = new float[n]; int n2 = 0; float smallestY = yCoordinates[0]; for (int i = 1; i < n; i++) { if (smallestY > yCoordinates[i]) smallestY = yCoordinates[i]; } float x, y; float smallestX = Float.MAX_VALUE; int p1 = 0; for (int i = 0; i < n; i++) { x = xCoordinates[i]; y = yCoordinates[i]; if (y == smallestY && x < smallestX) { smallestX = x; p1 = i; } } int pstart = p1; float x1, y1, x2, y2, x3, y3; int p2, p3; float determinate; int count = 0; do { x1 = xCoordinates[p1]; y1 = yCoordinates[p1]; p2 = p1 + 1; if (p2 == n) p2 = 0; x2 = xCoordinates[p2]; y2 = yCoordinates[p2]; p3 = p2 + 1; if (p3 == n) p3 = 0; do { x3 = xCoordinates[p3]; y3 = yCoordinates[p3]; determinate = x1 * (y2 - y3) - y1 * (x2 - x3) + (y3 * x2 - y2 * x3); if (determinate > 0) { x2 = x3; y2 = y3; p2 = p3; } p3 += 1; if (p3 == n) p3 = 0; } while (p3 != p1); if (n2 < n) { xx[n2] = x1; yy[n2] = y1; n2++; } else { count++; if (count > 10) return null; } p1 = p2; } while (p1 != pstart); xx = Arrays.copyOf(xx, n2); yy = Arrays.copyOf(yy, n2); return new ConvexHull(xbase, ybase, xx, yy); }
From source file:pt.ist.vaadinframework.ui.DefaultFieldFactory.java
/** * @see pt.ist.vaadinframework.ui.AbstractFieldFactory#makeField(com.vaadin.data.Item, java.lang.Object, * com.vaadin.ui.Component)/*from ww w. j ava2s .c o m*/ */ @Override protected Field makeField(Item item, Object propertyId, Component uiContext) { Class<?> type = item.getItemProperty(propertyId).getType(); if (String.class.isAssignableFrom(type)) { TextField field = new TextField(); field.setNullSettingAllowed(true); field.setNullRepresentation(StringUtils.EMPTY); return field; } if (Collection.class.isAssignableFrom(type) && item.getItemProperty(propertyId) instanceof AbstractBufferedContainer) { return new ContainerEditor<Object>(this, bundlename, ((AbstractBufferedContainer<?, ?, ?>) item.getItemProperty(propertyId)).getElementType()); } if (AbstractDomainObject.class.isAssignableFrom(type)) { Select select = new Select(); select.setWidth(100, Sizeable.UNITS_PERCENTAGE); select.setImmediate(true); return select; } if (Collection.class.isAssignableFrom(type)) { OptionGroup group = new OptionGroup(); group.setMultiSelect(true); group.setWidth(100, Sizeable.UNITS_PERCENTAGE); group.setImmediate(true); return group; } if (Byte.class.isAssignableFrom(type)) { return new PrimitiveField(new ByteValidator(), Byte.toString(Byte.MAX_VALUE).length() + 1); } if (Short.class.isAssignableFrom(type)) { return new PrimitiveField(new ShortValidator(), Short.toString(Short.MAX_VALUE).length() + 1); } if (Integer.class.isAssignableFrom(type)) { return new PrimitiveField(new IntegerValidator(), Integer.toString(Integer.MAX_VALUE).length() + 1); } if (Long.class.isAssignableFrom(type)) { return new PrimitiveField(new LongValidator(), Long.toString(Long.MAX_VALUE).length() + 1); } if (Float.class.isAssignableFrom(type)) { return new PrimitiveField(new FloatValidator(), Float.toString(Float.MAX_VALUE).length() + 1); } if (Double.class.isAssignableFrom(type)) { return new PrimitiveField(new DoubleValidator(), Double.toString(Double.MAX_VALUE).length() + 1); } if (Boolean.class.isAssignableFrom(type)) { return new CheckBox(); } if (Character.class.isAssignableFrom(type)) { return new PrimitiveField(new CharacterValidator(), 1); } if (BigDecimal.class.isAssignableFrom(type)) { return new PrimitiveField(new BigDecimalValidator(), -1); } if (Enum.class.isAssignableFrom(type)) { return new EnumField((Class<? extends Enum<?>>) item.getItemProperty(propertyId).getType()); } if (Date.class.isAssignableFrom(type)) { DateField field = new DateField(); field.setResolution(DateField.RESOLUTION_DAY); return field; } if (Item.class.isAssignableFrom(type)) { Form form = new Form() { @Override public void setPropertyDataSource(Property newDataSource) { setItemDataSource((Item) newDataSource); }; }; form.setImmediate(true); form.setFormFieldFactory(this); return form; } if (MultiLanguageString.class.isAssignableFrom(type)) { return new MultiLanguageStringField(bundlename, Language.pt, Language.en); } if (DateTime.class.isAssignableFrom(type)) { PopupDateTimeField field = new PopupDateTimeField(); field.setResolution(DateField.RESOLUTION_SEC); return field; } if (LocalDate.class.isAssignableFrom(type)) { PopupLocalDateField field = new PopupLocalDateField(); field.setResolution(DateField.RESOLUTION_DAY); return field; } if (URL.class.isAssignableFrom(type)) { TextField field = new TextField(); field.setNullSettingAllowed(true); field.setNullRepresentation(StringUtils.EMPTY); field.addValidator(new URLValidator()); return field; } Select select = new Select(); select.setWidth(100, Sizeable.UNITS_PERCENTAGE); select.setImmediate(true); return select; }