List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:net.sf.qooxdoo.rpc.RemoteCallUtils.java
/** * Converts JSON types to "normal" java types. * * @param obj the object to convert (must not be * <code>null</code>, but can be * <code>JSONObject.NULL</code>). * @param targetType the desired target type (must not be * <code>null</code>). * * @return the converted object./*from w ww . jav a 2 s .c o m*/ * * @exception IllegalArgumentException thrown if the desired * conversion is not possible. */ public Object toJava(Object obj, Class targetType) { try { if (obj == JSONObject.NULL) { if (targetType == Integer.TYPE || targetType == Double.TYPE || targetType == Boolean.TYPE || targetType == Long.TYPE || targetType == Float.TYPE) { // null does not work for primitive types throw new Exception(); } return null; } if (obj instanceof JSONArray) { Class componentType; if (targetType == null || targetType == Object.class) { componentType = null; } else { componentType = targetType.getComponentType(); } JSONArray jsonArray = (JSONArray) obj; int length = jsonArray.length(); Object retVal = Array.newInstance((componentType == null ? Object.class : componentType), length); for (int i = 0; i < length; ++i) { Array.set(retVal, i, toJava(jsonArray.get(i), componentType)); } return retVal; } if (obj instanceof JSONObject) { JSONObject jsonObject = (JSONObject) obj; JSONArray names = jsonObject.names(); if (targetType == Map.class || targetType == HashMap.class || targetType == null || targetType == Object.class) { HashMap retVal = new HashMap(); if (names != null) { int length = names.length(); String name; for (int i = 0; i < length; ++i) { name = names.getString(i); retVal.put(name, toJava(jsonObject.get(name), null)); } } return retVal; } Object bean; String requestedTypeName = jsonObject.optString("class", null); if (requestedTypeName != null) { Class clazz = resolveClassHint(requestedTypeName, targetType); if (clazz == null || !targetType.isAssignableFrom(clazz)) { throw new Exception(); } bean = clazz.newInstance(); // TODO: support constructor parameters } else { bean = targetType.newInstance(); } if (names != null) { int length = names.length(); String name; PropertyDescriptor desc; for (int i = 0; i < length; ++i) { name = names.getString(i); if (!"class".equals(name)) { desc = PropertyUtils.getPropertyDescriptor(bean, name); if (desc != null && desc.getWriteMethod() != null) { PropertyUtils.setSimpleProperty(bean, name, toJava(jsonObject.get(name), desc.getPropertyType())); } } } } return bean; } if (targetType == null || targetType == Object.class) { return obj; } Class actualTargetType; Class sourceType = obj.getClass(); if (targetType == Integer.TYPE) { actualTargetType = Integer.class; } else if (targetType == Boolean.TYPE) { actualTargetType = Boolean.class; } else if ((targetType == Double.TYPE || targetType == Double.class) && Number.class.isAssignableFrom(sourceType)) { return new Double(((Number) obj).doubleValue()); // TODO: maybe return obj directly if it's a Double } else if ((targetType == Float.TYPE || targetType == Float.class) && Number.class.isAssignableFrom(sourceType)) { return new Float(((Number) obj).floatValue()); } else if ((targetType == Long.TYPE || targetType == Long.class) && Number.class.isAssignableFrom(sourceType)) { return new Long(((Number) obj).longValue()); } else { actualTargetType = targetType; } if (!actualTargetType.isAssignableFrom(sourceType)) { throw new Exception(); } return obj; } catch (IllegalArgumentException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("Cannot convert " + (obj == null ? null : obj.getClass().getName()) + " to " + (targetType == null ? null : targetType.getName())); } }
From source file:chatbot.Chatbot.java
/** ************************************************************************************************ * Calculate TF/IDF and put the results in * HashMap<Integer,HashMap<String,Float>> tfidf * In the process, calculate the euclidean distance of the word * vectors and put in HashMap<Integer,Float> euclid * Note that if the query is included as index -1 then it will * get processed too.//from w w w . j a v a2 s . co m */ private void calcOneTFIDF(Integer int1) { HashMap<String, Integer> tftermlist = tf.get(int1); if (tftermlist == null) { System.out.println("Error in calcOneTFIDF(): bad index: " + int1); return; } HashMap<String, Float> tfidflist = new HashMap<String, Float>(); float euc = 0; Iterator<String> it2 = tftermlist.keySet().iterator(); while (it2.hasNext()) { String term = it2.next(); int tfint = tftermlist.get(term).intValue(); float idffloat = idf.get(term).floatValue(); float tfidffloat = idffloat * tfint; tfidflist.put(term, new Float(tfidffloat)); euc = euc + (tfidffloat * tfidffloat); } euclid.put(int1, new Float((float) Math.sqrt(euc))); tfidf.put(int1, tfidflist); }
From source file:com.netspective.commons.text.ExpressionTextTest.java
public void testJavaExpressionTextErrors() { 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)); JavaExpressionText jetFour = new JavaExpressionText(vars); assertNotNull(jetFour);/*from w ww.j a v a2 s .c o m*/ String javaExpInputFive = "Tom and Jerry like ${pi}"; String javaExpOutputFive = jetFour.getFinalText(null, javaExpInputFive); assertEquals("Tom and Jerry like 3.14", javaExpOutputFive); assertNull(jetFour.getStaticExpr()); String javaExpInputSix = "The 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.amazonaws.hal.client.ConversionUtil.java
private static Object convertFromString(Class<?> clazz, String value) { if (String.class.isAssignableFrom(clazz)) { return value; } else if (int.class.isAssignableFrom(clazz) || Integer.class.isAssignableFrom(clazz)) { return new Integer(value); } else if (long.class.isAssignableFrom(clazz) || Long.class.isAssignableFrom(clazz)) { return new Long(value); } else if (short.class.isAssignableFrom(clazz) || Short.class.isAssignableFrom(clazz)) { return new Short(value); } else if (double.class.isAssignableFrom(clazz) || Double.class.isAssignableFrom(clazz)) { return new Double(value); } else if (float.class.isAssignableFrom(clazz) || Float.class.isAssignableFrom(clazz)) { return new Float(value); } else if (boolean.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz)) { return Boolean.valueOf(value); } else if (char.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)) { return value.charAt(0); } else if (byte.class.isAssignableFrom(clazz) || Byte.class.isAssignableFrom(clazz)) { return new Byte(value); } else if (BigDecimal.class.isAssignableFrom(clazz)) { return new BigDecimal(value); } else if (BigInteger.class.isAssignableFrom(clazz)) { return new BigInteger(value); } else if (Date.class.isAssignableFrom(clazz)) { try {/*from w w w . j a va2 s.c o m*/ return new Date(Long.parseLong(value)); } catch (NumberFormatException e) { try { return DatatypeConverter.parseDateTime(value).getTime(); } catch (IllegalArgumentException e1) { throw new RuntimeException("Unexpected date format: " + value + ". We currently parse xsd:datetime and milliseconds."); } } } else if (clazz.isEnum()) { try { //noinspection unchecked return Enum.valueOf((Class<Enum>) clazz, value); } catch (IllegalArgumentException e) { log.error(String.format( "'%s' is not a recognized enum value for %s. Returning default of %s instead.", value, clazz.getName(), clazz.getEnumConstants()[0])); return clazz.getEnumConstants()[0]; } } else { throw new RuntimeException("Not sure how to convert " + value + " to a " + clazz.getSimpleName()); } }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert/*w w w.j a v a 2 s. c om*/ * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class<?> targetClass) throws IllegalArgumentException { // Assert.notNull(number, "Number must not be null"); // Assert.notNull(targetClass, "Target class must not be null"); if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
/** * Create a HardwareAddress object from its XML representation. * * @param pElement DOM element containing the XML representation of a HardwareAddress object, as created by the * toConfigXML() method. * @throws RuntimeException if unable to instantiate the Hardware address * @see cern.c2mon.shared.common.datatag.address.HardwareAddress#toConfigXML() *///w ww . j a va2s . com public final synchronized HardwareAddress fromConfigXML(Element pElement) { Class hwAddressClass = null; HardwareAddressImpl hwAddress = null; try { hwAddressClass = Class.forName(pElement.getAttribute("class")); hwAddress = (HardwareAddressImpl) hwAddressClass.newInstance(); } catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", cnfe); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", iae); } catch (InstantiationException ie) { ie.printStackTrace(); throw new RuntimeException("Exception caught when instantiating a hardware address from XML", ie); } NodeList fields = pElement.getChildNodes(); Node fieldNode = null; int fieldsCount = fields.getLength(); String fieldName; String fieldValueString; String fieldTypeName = ""; for (int i = 0; i < fieldsCount; i++) { fieldNode = fields.item(i); if (fieldNode.getNodeType() == Node.ELEMENT_NODE) { fieldName = fieldNode.getNodeName(); if (fieldNode.getFirstChild() != null) { fieldValueString = fieldNode.getFirstChild().getNodeValue(); } else { fieldValueString = ""; } try { Field field = hwAddressClass.getDeclaredField(decodeFieldName(fieldName)); fieldTypeName = field.getType().getName(); if (fieldTypeName.equals("short")) { field.setShort(hwAddress, Short.parseShort(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Short")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("int")) { field.setInt(hwAddress, Integer.parseInt(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Integer")) { field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString))); } else if (fieldTypeName.equals("float")) { field.setFloat(hwAddress, Float.parseFloat(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Float")) { field.set(hwAddress, new Float(Float.parseFloat(fieldValueString))); } else if (fieldTypeName.equals("double")) { field.setDouble(hwAddress, Double.parseDouble(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Double")) { field.set(hwAddress, new Double(Double.parseDouble(fieldValueString))); } else if (fieldTypeName.equals("long")) { field.setLong(hwAddress, Long.parseLong(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Long")) { field.set(hwAddress, new Long(Long.parseLong(fieldValueString))); } else if (fieldTypeName.equals("byte")) { field.setByte(hwAddress, Byte.parseByte(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Byte")) { field.set(hwAddress, new Byte(Byte.parseByte(fieldValueString))); } else if (fieldTypeName.equals("char")) { field.setChar(hwAddress, fieldValueString.charAt(0)); } else if (fieldTypeName.equals("java.lang.Character")) { field.set(hwAddress, new Character(fieldValueString.charAt(0))); } else if (fieldTypeName.equals("boolean")) { field.setBoolean(hwAddress, Boolean.getBoolean(fieldValueString)); } else if (fieldTypeName.equals("java.lang.Boolean")) { field.set(hwAddress, new Boolean(Boolean.getBoolean(fieldValueString))); } else if (fieldTypeName.equals("java.util.HashMap")) { field.set(hwAddress, SimpleXMLParser.domNodeToMap(fieldNode)); } else if (field.getType().isEnum()) { Object[] enumConstants = field.getType().getEnumConstants(); for (Object enumConstant : enumConstants) { if (enumConstant.toString().equals(fieldValueString)) { field.set(hwAddress, enumConstant); } } } else { field.set(hwAddress, fieldValueString); } } catch (NoSuchFieldException nsfe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. " + "The following variable does not exist in " + hwAddressClass.toString() + ": \"" + decodeFieldName(fieldName) + "\""; log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new RuntimeException(iae); } catch (NumberFormatException npe) { String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. Field \"" + fieldName + "\" shall not be empty since we expect a \"" + fieldTypeName + "\" value. Please correct the XML configuration for " + hwAddressClass.toString(); log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } } } return hwAddress; }
From source file:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java
/** * *//*from www .j a v a 2 s .c om*/ private Image printPageToImage(int pageIndex, float zoom) throws JRException { Image pageImage = new BufferedImage((int) (jasperPrint.getPageWidth() * zoom) + 1, (int) (jasperPrint.getPageHeight() * zoom) + 1, BufferedImage.TYPE_INT_RGB); JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics()); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom)); exporter.exportReport(); return pageImage; }
From source file:eu.supersede.gr.utility.PointsLogic.java
private void computePoints() { List<HAHPGamePlayerPoint> gamesPlayersPoints = gamesPlayersPointsRepository.findAll(); // cycle on every gamesPlayersPoints for (int i = 0; i < gamesPlayersPoints.size(); i++) { HAHPGame g = gamesRepository.findOne(gamesPlayersPoints.get(i).getGame().getGameId()); // set currentPlayer that is used for other methods g.setCurrentPlayer(gamesPlayersPoints.get(i).getUser()); List<HAHPCriteriasMatrixData> criteriasMatrixDataList = criteriaMatricesRepository.findByGame(g); // calculate the agreementIndex for every gamesPlayersPoints of a game and a specific user Map<String, Double> resultTotal = AHPRest.CalculateAHP(g.getCriterias(), g.getRequirements(), criteriasMatrixDataList, g.getRequirementsMatrixData()); Map<String, Double> resultPersonal = AHPRest.CalculatePersonalAHP( gamesPlayersPoints.get(i).getUser().getUserId(), g.getCriterias(), g.getRequirements(), criteriasMatrixDataList, g.getRequirementsMatrixData()); List<Requirement> gameRequirements = g.getRequirements(); Double sum = 0.0;/*from w w w .j a va 2 s . co m*/ for (int j = 0; j < resultTotal.size(); j++) { Double requirementValueTotal = resultTotal .get(gameRequirements.get(j).getRequirementId().toString()); Double requirementValuePersonal = resultPersonal .get(gameRequirements.get(j).getRequirementId().toString()); sum = sum + (Math.abs(requirementValueTotal - requirementValuePersonal) * (1.0 - requirementValueTotal)); } Double agreementIndex = M - (M * sum); gamesPlayersPoints.get(i).setAgreementIndex(agreementIndex.longValue()); // calculate the positionInVoting for every gamesPlayersPoints of a game and a specific user List<User> players = g.getPlayers(); List<HAHPRequirementsMatrixData> lrmd = requirementsMatricesRepository.findByGame(g); Map<User, Float> gamePlayerVotes = new HashMap<>(); for (User player : players) { Integer total = 0; Integer voted = 0; if (lrmd != null) { for (HAHPRequirementsMatrixData data : lrmd) { for (HAHPPlayerMove pm : data.getPlayerMoves()) { if (pm.getPlayer().getUserId().equals(player.getUserId())) { total++; if (pm.getPlayed() == true && pm.getValue() != null && !pm.getValue().equals(-1l)) { voted++; } } } } } gamePlayerVotes.put(player, total.equals(0) ? 0f : ((new Float(voted) / new Float(total)) * 100)); } LinkedHashMap<User, Float> orderedList = sortHashMapByValues(gamePlayerVotes); List<User> indexes = new ArrayList<>(orderedList.keySet()); Integer index = indexes.indexOf(gamesPlayersPoints.get(i).getUser()); Double positionInVoting = (orderedList.size() - (new Double(index) + 1.0)) + 1.0; gamesPlayersPoints.get(i).setPositionInVoting(positionInVoting.longValue()); // calculate the virtualPosition of a user base on his/her points in a particular game HAHPGamePlayerPoint gpp = gamesPlayersPointsRepository .findByUserAndGame(gamesPlayersPoints.get(i).getUser(), g); List<HAHPGamePlayerPoint> specificGamePlayersPoints = gamesPlayersPointsRepository.findByGame(g); Collections.sort(specificGamePlayersPoints, new CustomComparator()); Long virtualPosition = specificGamePlayersPoints.indexOf(gpp) + 1l; gamesPlayersPoints.get(i).setVirtualPosition(virtualPosition); Long movesPoints = 0l; Long gameProgressPoints = 0l; Long positionInVotingPoints = 0l; Long gameStatusPoints = 0l; Long agreementIndexPoints = 0l; Long totalPoints = 0l; // set the movesPoints movesPoints = g.getMovesDone().longValue(); // setGameProgressPoints gameProgressPoints = (long) Math.floor(g.getPlayerProgress() / 10); // setPositionInVotingPoints if (positionInVoting == 1) { positionInVotingPoints = 5l; } else if (positionInVoting == 2) { positionInVotingPoints = 3l; } else if (positionInVoting == 3) { positionInVotingPoints = 2l; } // setGameStatusPoints if (g.getPlayerProgress() != 100) { gameStatusPoints = -20l; } else { gameStatusPoints = 0l; } // set AgreementIndexPoints agreementIndexPoints = agreementIndex.longValue(); totalPoints = movesPoints.longValue() + gameProgressPoints + positionInVotingPoints + gameStatusPoints + agreementIndexPoints; // set totalPoints 0 if the totalPoints are negative if (totalPoints < 0) { totalPoints = 0l; } gamesPlayersPoints.get(i).setPoints(totalPoints); gamesPlayersPointsRepository.save(gamesPlayersPoints.get(i)); } System.out.println("Finished computing votes"); }
From source file:com.xpn.xwiki.plugin.charts.params.DefaultChartParams2.java
void setAxis(String prefix) throws ParamException { set(prefix + AXIS_VISIBLE_SUFIX, Axis.DEFAULT_AXIS_VISIBLE); set(prefix + AXIS_LINE_VISIBLE_SUFFIX, Boolean.TRUE); set(prefix + AXIS_LINE_COLOR_SUFFIX, Axis.DEFAULT_AXIS_LINE_PAINT); set(prefix + AXIS_LINE_STROKE_SUFFIX, Axis.DEFAULT_AXIS_LINE_STROKE); set(prefix + AXIS_LABEL_SUFFIX, ""); // ? set(prefix + AXIS_LABEL_FONT_SUFFIX, Axis.DEFAULT_AXIS_LABEL_FONT); set(prefix + AXIS_LABEL_COLOR_SUFFIX, Axis.DEFAULT_AXIS_LABEL_PAINT); set(prefix + AXIS_LABEL_INSERTS_SUFFIX, Axis.DEFAULT_AXIS_LABEL_INSETS); set(prefix + AXIS_TICK_LABEL_VISIBLE_SUFFIX, new Boolean(Axis.DEFAULT_TICK_LABELS_VISIBLE)); set(prefix + AXIS_TICK_LABEL_FONT_SUFFIX, Axis.DEFAULT_TICK_LABEL_FONT); set(prefix + AXIS_TICK_LABEL_COLOR_SUFFIX, Axis.DEFAULT_TICK_LABEL_PAINT); set(prefix + AXIS_TICK_LABEL_INSERTS_SUFFIX, Axis.DEFAULT_TICK_LABEL_INSETS); set(prefix + AXIS_TICK_MARK_VISIBLE_SUFFIX, new Boolean(Axis.DEFAULT_TICK_MARKS_VISIBLE)); set(prefix + AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX, new Float(Axis.DEFAULT_TICK_MARK_INSIDE_LENGTH)); set(prefix + AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX, new Float(Axis.DEFAULT_TICK_MARK_OUTSIDE_LENGTH)); set(prefix + AXIS_TICK_MARK_COLOR_SUFFIX, Axis.DEFAULT_TICK_MARK_PAINT); set(prefix + AXIS_TICK_MARK_STROKE_SUFFIX, Axis.DEFAULT_TICK_MARK_STROKE); set(prefix + PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX, Boolean.TRUE); set(prefix + PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX, XYPlot.DEFAULT_GRIDLINE_PAINT); set(prefix + PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX, XYPlot.DEFAULT_GRIDLINE_STROKE); set(prefix + VALUE_AXIS_AUTO_RANGE_SUFFIX, new Boolean(ValueAxis.DEFAULT_AUTO_RANGE)); set(prefix + VALUE_AXIS_AUTO_RANGE_MIN_SIZE_SUFFIX, new Double(ValueAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE)); set(prefix + VALUE_AXIS_AUTO_TICK_UNIT_SUFFIX, new Boolean(ValueAxis.DEFAULT_AUTO_TICK_UNIT_SELECTION)); set(prefix + VALUE_AXIS_LOWER_BOUND_SUFFIX, new Double(ValueAxis.DEFAULT_LOWER_BOUND)); set(prefix + VALUE_AXIS_UPPER_BOUND_SUFFIX, new Double(ValueAxis.DEFAULT_UPPER_BOUND)); set(prefix + AXIS_LOWER_MARGIN_SUFFIX, new Double(ValueAxis.DEFAULT_LOWER_MARGIN)); set(prefix + AXIS_UPPER_MARGIN_SUFFIX, new Double(ValueAxis.DEFAULT_UPPER_MARGIN)); set(prefix + VALUE_AXIS_VERTICAL_TICK_LABELS_SUFFIX, Boolean.FALSE); set(prefix + NUMBER_AXIS_AUTO_RANGE_INCLUDES_ZERO_SUFFIX, new Boolean(NumberAxis.DEFAULT_AUTO_RANGE_INCLUDES_ZERO)); set(prefix + NUMBER_AXIS_AUTO_RANGE_STICKY_ZERO_SUFFIX, new Boolean(NumberAxis.DEFAULT_AUTO_RANGE_STICKY_ZERO)); set(prefix + NUMBER_AXIS_RANGE_TYPE_SUFFIX, RangeType.FULL); set(prefix + NUMBER_AXIS_NUMBER_TICK_UNIT_SUFFIX, NumberAxis.DEFAULT_TICK_UNIT); set(prefix + NUMBER_AXIS_NUMBER_FORMAT_OVERRIDE_SUFFIX, (NumberFormat) null); set(prefix + DATE_AXIS_DATE_FORMAT_OVERRIDE_SUFFIX, (DateFormat) null); set(prefix + DATE_AXIS_LOWER_DATE_SUFFIX, DateAxis.DEFAULT_DATE_RANGE.getLowerDate()); set(prefix + DATE_AXIS_UPPER_DATE_SUFFIX, DateAxis.DEFAULT_DATE_RANGE.getUpperDate()); set(prefix + DATE_AXIS_DATE_TICK_MARK_POSITION_SUFFIX, DateTickMarkPosition.START); set(prefix + DATE_AXIS_DATE_TICK_UNIT_SUFFIX, DateAxis.DEFAULT_DATE_TICK_UNIT); set(prefix + CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX, new Double(CategoryAxis.DEFAULT_CATEGORY_MARGIN)); set(prefix + CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX, CategoryLabelPositions.STANDARD); set(prefix + CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX, new Integer(4)); set(prefix + CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX, new Integer(1)); set(prefix + CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX, new Float(0.0f)); }
From source file:com.whirlycott.cache.CacheDecorator.java
/** * Calculates the adaptive hit rate for this cache. * //from ww w .java2 s. co m * @return adaptive hit ratio. */ public float getAdaptiveRatio() { final int copy[] = new int[adaptiveMemorySize]; System.arraycopy(adaptiveResults, 0, copy, 0, adaptiveMemorySize); int positives = 0; for (final int element : copy) { if (element == 1) { positives++; } } // log.info("Positives: " + positives + "; Total: " + // adaptiveMemorySize); return new Float(positives).floatValue() / new Float(adaptiveMemorySize).floatValue(); }