List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:edu.uci.ics.jung.io.PajekNetIOTest.java
public void testMixedSaveLoadSave() throws IOException { Graph<Number, Number> graph1 = new SparseMultigraph<Number, Number>(); for (int i = 0; i < 5; i++) { graph1.addVertex(i);/* w w w.j a v a2 s . c om*/ } int j = 0; List<Number> id = new ArrayList<Number>(graph1.getVertices());//Indexer.getIndexer(graph1); GreekLabels<Number> gl = new GreekLabels<Number>(id); Number[] edges = { 0, 1, 2, 3, 4, 5 }; graph1.addEdge(j++, 0, 1, EdgeType.DIRECTED); graph1.addEdge(j++, 0, 2, EdgeType.DIRECTED); graph1.addEdge(j++, 1, 2, EdgeType.DIRECTED); graph1.addEdge(j++, 1, 3); graph1.addEdge(j++, 1, 4); graph1.addEdge(j++, 4, 3); Map<Number, Number> nr = new HashMap<Number, Number>(); for (int i = 0; i < edges.length; i++) { nr.put(edges[i], new Float(Math.random())); } assertEquals(graph1.getEdgeCount(), 6); // System.err.println(" mixed graph1 = "+graph1); // for(Number edge : graph1.getEdges()) { // System.err.println("edge "+edge+" is directed? "+graph1.getEdgeType(edge)); // } // for(Number v : graph1.getVertices()) { // System.err.println(v+" outedges are "+graph1.getOutEdges(v)); // System.err.println(v+" inedges are "+graph1.getInEdges(v)); // System.err.println(v+" incidentedges are "+graph1.getIncidentEdges(v)); // } String testFilename = "mtest.net"; String testFilename2 = testFilename + "2"; // lay out network Dimension d = new Dimension(100, 200); Transformer<Number, Point2D> vld = TransformerUtils.mapTransformer( LazyMap.decorate(new HashMap<Number, Point2D>(), new RandomLocationTransformer<Number>(d))); PajekNetWriter<Number, Number> pnw = new PajekNetWriter<Number, Number>(); pnw.save(graph1, testFilename, gl, MapTransformer.getInstance(nr), vld); Graph<Number, Number> graph2 = pnr.load(testFilename, graphFactory); Transformer<Number, String> pl = pnr.getVertexLabeller(); List<Number> id2 = new ArrayList<Number>(graph2.getVertices()); Transformer<Number, Point2D> vld2 = pnr.getVertexLocationTransformer(); assertEquals(graph1.getVertexCount(), graph2.getVertexCount()); assertEquals(graph1.getEdgeCount(), graph2.getEdgeCount()); // test vertex labels and locations for (int i = 0; i < graph1.getVertexCount(); i++) { Number v1 = id.get(i); Number v2 = id2.get(i); assertEquals(gl.transform(v1), pl.transform(v2)); assertEquals(vld.transform(v1), vld2.transform(v2)); } // test edge weights Transformer<Number, Number> nr2 = pnr.getEdgeWeightTransformer(); for (Number e2 : graph2.getEdges()) { Pair<Number> endpoints = graph2.getEndpoints(e2); Number v1_2 = endpoints.getFirst(); Number v2_2 = endpoints.getSecond(); Number v1_1 = id.get(id2.indexOf(v1_2)); Number v2_1 = id.get(id2.indexOf(v2_2)); Number e1 = graph1.findEdge(v1_1, v2_1); assertNotNull(e1); assertEquals(nr.get(e1).floatValue(), nr2.transform(e2).floatValue(), 0.0001); } pnw.save(graph2, testFilename2, pl, nr2, vld2); compareIndexedGraphs(graph1, graph2); pnr.setVertexLabeller(null); Graph<Number, Number> graph3 = pnr.load(testFilename2, graphFactory); compareIndexedGraphs(graph2, graph3); File file1 = new File(testFilename); File file2 = new File(testFilename2); Assert.assertTrue(file1.length() == file2.length()); file1.delete(); file2.delete(); }
From source file:TwitterPlanet.java
public void initLocations() { //*// w ww .j av a 2 s.c o m try { dbData = new JSONObject(join(loadStrings(jsonString), "")); // println("results: " + result); results = dbData.getJSONArray("latlong_data"); // total = dbData.getInt("total"); // / set length of arrays LatLongLength = results.length(); // init our marker handler latArray = new float[results.length()]; longArray = new float[results.length()]; // println("LENGTH: " + results.length()); // // let's print this mother out for (int i = 0; i < LatLongLength; i++) { String theLat = results.getJSONObject(i).getString("lat"); String theLong = results.getJSONObject(i).getString("long"); // println(results.getJSONObject(i).getString("lat")); float lt = new Float(theLat); float lo = new Float(theLong); latArray[i] = lt; longArray[i] = lo; } } catch (JSONException e) { println(e); } //*/ initDestroyer(); }
From source file:com.microsoft.tfs.core.memento.XMLMemento.java
/** * {@inheritDoc}//from w ww . j a v a2 s . c om */ @Override public synchronized Float getFloat(final String key) { Check.notNullOrEmpty(key, "key"); //$NON-NLS-1$ final String value = (String) attributes.get(key); if (value == null) { return null; } try { return new Float(value); } catch (final NumberFormatException e) { log.warn(MessageFormat.format("Invalid float for key: {0} value: {1}", key, value), e); //$NON-NLS-1$ return null; } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaBucketDaoTest.java
@Test public void getDropsSince() { Account account = accountDao.findById(1L); DropFilter filter = new DropFilter(); filter.setSinceId(3L);//from w w w .j ava2s . c o m List<Drop> drops = bucketDao.getDrops(1L, filter, 1, 1, account); assertEquals(1, drops.size()); Drop drop = drops.get(0); assertEquals(4, drop.getId()); assertEquals(false, drop.getRead()); assertEquals("twitter", drop.getChannel()); assertEquals("droplet 4 title", drop.getTitle()); assertEquals("droplet 4 content", drop.getContent()); assertEquals("4", drop.getOriginalId()); assertEquals(25, drop.getCommentCount()); assertEquals(2, drop.getIdentity().getId()); assertEquals("identity2_name", drop.getIdentity().getName()); assertEquals("identity2_avatar", drop.getIdentity().getAvatar()); assertNotNull(drop.getOriginalUrl()); assertEquals(3, drop.getOriginalUrl().getId()); assertEquals("http://www.bbc.co.uk/nature/20273855", drop.getOriginalUrl().getUrl()); assertEquals(1, drop.getTags().size()); Tag tag = drop.getTags().get(0); assertEquals(1, tag.getId()); assertEquals("Jeremy Hunt", tag.getTag()); assertEquals("person", tag.getType()); assertEquals(1, drop.getLinks().size()); Link link = drop.getLinks().get(0); assertEquals(10, link.getId()); assertEquals("http://www.bbc.co.uk/sport/0/football/20319573", link.getUrl()); assertEquals(1, drop.getMedia().size()); Media media = drop.getMedia().get(0); assertEquals(1, media.getId()); assertEquals("http://gigaom2.files.wordpress.com/2012/10/datacapspercentage.jpeg", media.getUrl()); assertEquals("image", media.getType()); assertEquals(2, media.getThumbnails().size()); MediaThumbnail thumbnail = media.getThumbnails().get(0); assertEquals( "https://2bcbd22fbb0a02d76141-1680e9dfed1be27cdc47787ec5d4ef89.ssl.cf1.rackcdn.com/625dd7cb656d258b4effb325253e880631699d80345016e9e755b4a04341cda1.peg", thumbnail.getUrl()); assertEquals(80, thumbnail.getSize()); assertEquals(1, drop.getPlaces().size()); Place place = drop.getPlaces().get(0); assertEquals(1, place.getId()); assertEquals("Wales", place.getPlaceName()); assertEquals(new Float(146.11), place.getLongitude()); assertEquals(new Float(-33), place.getLatitude()); }
From source file:net.sourceforge.fenixedu.dataTransferObject.externalServices.TeacherCurricularInformation.java
protected Float getAuthorizationRegimeTime(ExecutionSemester executionSemester) { TeacherAuthorization teacherAuthorization = getTeacher().getTeacherAuthorization(executionSemester); if (teacherAuthorization != null) { Double lessonHours = ((ExternalTeacherAuthorization) teacherAuthorization).getLessonHours(); return new Float(Math.round(lessonHours * 100 / 12)); }//from w w w . ja v a 2 s. c o m return 0f; }
From source file:com.appglu.impl.CrudTemplateTest.java
@Test public void readAllDataTypes() { mockServer.expect(requestTo("http://localhost/appglu/v1/tables/data_types/1?expand_relationships=false")) .andExpect(method(HttpMethod.GET)).andRespond(withSuccess() .body(compactedJson("data/crud_read_all_data_types")).headers(responseHeaders)); Row row = crudOperations.read("data_types", 1); String string = new String("a very long string for test"); Assert.assertEquals(new Boolean(true), row.getBoolean("boolean")); Assert.assertEquals(new Short((short) 1), row.getShort("short")); Assert.assertEquals(new Byte((byte) 2), row.getByte("byte")); Assert.assertEquals(string, new String(row.getByteArray("byteArray"))); Assert.assertEquals(new Float(1.5f), row.getFloat("float")); Assert.assertEquals(new Double(1.5f), row.getDouble("float")); Assert.assertEquals(new Double(7.5d), row.getDouble("double")); Assert.assertEquals(new Integer(10), row.getInt("integer")); Assert.assertEquals(new Long(10), row.getLong("integer")); Assert.assertEquals(new Long(21474836475L), row.getLong("long")); Assert.assertEquals(new BigInteger("10"), row.getBigInteger("integer")); Assert.assertEquals(new BigInteger("21474836475"), row.getBigInteger("long")); Assert.assertEquals(new BigInteger("9223372036854775807123"), row.getBigInteger("bigInteger")); Assert.assertEquals(string, row.getString("string")); Assert.assertEquals("2010-01-15T12:10:00+0000", DateUtils.formatDatetime(row.getDate("datetime"))); Assert.assertEquals("1970-01-01T12:10:00+0000", DateUtils.formatDatetime(row.getDate("time"))); Assert.assertEquals("2010-01-15T00:00:00+0000", DateUtils.formatDatetime(row.getDate("date"))); mockServer.verify();//from w ww . j av a2 s . c o m }
From source file:com.jilk.ros.rosbridge.implementation.JSON.java
public static Object convertJSONPrimitiveToPrimitive(Object o, Class c) { Object result = o;//from ww w .j av a 2 s . c o m if (c.isPrimitive() || Number.class.isAssignableFrom(c)) { if (c.equals(double.class) || c.equals(Double.class)) result = new Double(((Number) o).doubleValue()); else if (c.equals(float.class) || c.equals(Float.class)) result = new Float(((Number) o).floatValue()); else if (c.equals(long.class) || c.equals(Long.class)) result = new Long(((Number) o).longValue()); else if (int.class.equals(c) || c.equals(Integer.class)) result = new Integer(((Number) o).intValue()); else if (c.equals(short.class) || c.equals(Short.class)) result = new Short(((Number) o).shortValue()); else if (c.equals(byte.class) || c.equals(Byte.class)) result = new Byte(((Number) o).byteValue()); } return result; }
From source file:com.netspective.commons.text.ExpressionTextTest.java
public void testValueSourceOrJavaExpressionTextErrors() { Map vars = new HashMap(); vars.put("theBrain", new String("The Brain")); vars.put("pi", new Float(3.14)); vars.put("radius", new Float(2.5)); ValueSourceOrJavaExpressionText jetFour = new ValueSourceOrJavaExpressionText(vars); assertNotNull(jetFour);/*from w ww. j a v a2 s.c o m*/ String javaExpInputFive = "Tom and ${static:Jerry} like ${pi}"; String javaExpOutputFive = jetFour.getFinalText(null, javaExpInputFive); assertEquals("Tom and Jerry like 3.14", javaExpOutputFive); assertNull(jetFour.getStaticExpr()); String javaExpInputSix = "The ${static:perimeter} of this circle is: ${perimeter}"; boolean exceptionThrown = true; String javaExpOutputSix = null; try { javaExpOutputSix = jetFour.getFinalText(null, javaExpInputSix); exceptionThrown = false; } catch (ExpressionTextException e) { assertTrue(exceptionThrown); } assertNull(javaExpOutputSix); ValueContext testVC = new DefaultValueContext(); testVC.setAttribute("test-attribute", new String("Test Attribute - Do NOT Use")); assertEquals(javaExpOutputFive, jetFour.getFinalText(testVC, javaExpInputFive)); exceptionThrown = true; String javaExpOutputString = null; try { javaExpOutputString = jetFour.getFinalText(null); exceptionThrown = false; } catch (Exception e) { assertTrue(exceptionThrown); assertNull(javaExpOutputString); } exceptionThrown = true; javaExpOutputString = null; try { javaExpOutputString = jetFour.getFinalText(testVC); exceptionThrown = false; } catch (Exception e) { assertTrue(exceptionThrown); assertNull(javaExpOutputString); } }
From source file:com.redhat.example.rules.unittest.CsvTestHelper.java
private static Object getImmutableObject(Class<?> clazz, String strV) { if (strV == null) { return null; }//from w w w.ja v a2 s . co m if (clazz.equals(BigDecimal.class)) { return new BigDecimal(strV); } else if (clazz.equals(BigInteger.class)) { return new BigInteger(strV); } else if (clazz.equals(Double.class)) { return new Double(strV); } else if (clazz.equals(Float.class)) { return new Float(strV); } else if (clazz.equals(Integer.class)) { return new Integer(strV); } else if (clazz.equals(Long.class)) { return new Long(strV); } else if (clazz.equals(String.class)) { return strV; } return null; }
From source file:gov.nih.nci.system.web.struts.action.CreateAction.java
public Object convertValue(Class klass, Object value) throws NumberFormatException, Exception { String fieldType = klass.getName(); if (value == null) return null; Object convertedValue = null; try {/* w ww . java 2s . co m*/ if (fieldType.equals("java.lang.Long")) { convertedValue = new Long((String) value); } else if (fieldType.equals("java.lang.Integer")) { convertedValue = new Integer((String) value); } else if (fieldType.equals("java.lang.String")) { convertedValue = value; } else if (fieldType.equals("java.lang.Float")) { convertedValue = new Float((String) value); } else if (fieldType.equals("java.lang.Double")) { convertedValue = new Double((String) value); } else if (fieldType.equals("java.lang.Boolean")) { convertedValue = new Boolean((String) value); } else if (fieldType.equals("java.util.Date")) { SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); convertedValue = format.parse((String) value); } else if (fieldType.equals("java.net.URI")) { convertedValue = new URI((String) value); } else if (fieldType.equals("java.lang.Character")) { convertedValue = new Character(((String) value).charAt(0)); } else if (klass.isEnum()) { Class enumKlass = Class.forName(fieldType); convertedValue = Enum.valueOf(enumKlass, (String) value); } else { throw new Exception("type mismatch - " + fieldType); } } catch (NumberFormatException e) { e.printStackTrace(); log.error("ERROR : " + e.getMessage()); throw e; } catch (Exception ex) { ex.printStackTrace(); log.error("ERROR : " + ex.getMessage()); throw ex; } return convertedValue; }