List of usage examples for java.lang Double valueOf
@HotSpotIntrinsicCandidate public static Double valueOf(double d)
From source file:gda.spring.propertyeditors.RealVectorPropertyEditor.java
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.hasText(text)) { try {/* w w w . j av a2 s . co m*/ // remove spaces text = text.replace(" ", ""); // remove leading/trailing braces text = text.replace("{", "").replace("}", ""); String[] valueStrings = text.split(","); double[] values = new double[valueStrings.length]; for (int j = 0; j < valueStrings.length; j++) { values[j] = Double.valueOf(valueStrings[j]); } RealVector vector = MatrixUtils.createRealVector(values); setValue(vector); } catch (Throwable e) { throw new IllegalArgumentException( "Could not convert " + StringUtils.quote(text) + " to a RealVector", e); } } else { setValue(null); } }
From source file:com.acc.populator.AbstractHttpRequestDataPopulator.java
protected Double updateDoubleValueFromRequest(final HttpServletRequest request, final String paramName, final Double defaultValue) { final String booleanString = updateStringValueFromRequest(request, paramName, null); if (booleanString == null) { return defaultValue; }/* w w w . j a va 2s .c o m*/ return Double.valueOf(booleanString); }
From source file:ml.shifu.shifu.core.binning.obj.NumBinInfo.java
public static List<NumBinInfo> constructNumBinfo(String binsData, char fieldSeparator) { List<NumBinInfo> binInfos = new ArrayList<NumBinInfo>(); List<Double> thresholds = new ArrayList<Double>(); thresholds.add(Double.NEGATIVE_INFINITY); if (StringUtils.isNotBlank(binsData)) { String[] fields = StringUtils.split(binsData, fieldSeparator); if (fields != null) { for (String field : fields) { Double val = null; try { val = Double.valueOf(field); thresholds.add(val); } catch (Exception e) { // skip illegal double }/*from www. j a v a 2 s. com*/ } } } thresholds.add(Double.POSITIVE_INFINITY); Collections.sort(thresholds); for (int i = 0; i < thresholds.size() - 1; i++) { binInfos.add(new NumBinInfo(thresholds.get(i), thresholds.get(i + 1))); } return binInfos; }
From source file:Main.java
/** * convert value to given type./* w w w . ja v a 2 s . c om*/ * null safe. * * @param value value for convert * @param type will converted type * @return value while converted */ public static Object convertCompatibleType(Object value, Class<?> type) { if (value == null || type == null || type.isAssignableFrom(value.getClass())) { return value; } if (value instanceof String) { String string = (String) value; if (char.class.equals(type) || Character.class.equals(type)) { if (string.length() != 1) { throw new IllegalArgumentException(String.format("CAN NOT convert String(%s) to char!" + " when convert String to char, the String MUST only 1 char.", string)); } return string.charAt(0); } else if (type.isEnum()) { return Enum.valueOf((Class<Enum>) type, string); } else if (type == BigInteger.class) { return new BigInteger(string); } else if (type == BigDecimal.class) { return new BigDecimal(string); } else if (type == Short.class || type == short.class) { return Short.valueOf(string); } else if (type == Integer.class || type == int.class) { return Integer.valueOf(string); } else if (type == Long.class || type == long.class) { return Long.valueOf(string); } else if (type == Double.class || type == double.class) { return Double.valueOf(string); } else if (type == Float.class || type == float.class) { return Float.valueOf(string); } else if (type == Byte.class || type == byte.class) { return Byte.valueOf(string); } else if (type == Boolean.class || type == boolean.class) { return Boolean.valueOf(string); } else if (type == Date.class) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) value); } catch (ParseException e) { throw new IllegalStateException("Failed to parse date " + value + " by format " + DATE_FORMAT + ", cause: " + e.getMessage(), e); } } else if (type == Class.class) { return forName((String) value); } } else if (value instanceof Number) { Number number = (Number) value; if (type == byte.class || type == Byte.class) { return number.byteValue(); } else if (type == short.class || type == Short.class) { return number.shortValue(); } else if (type == int.class || type == Integer.class) { return number.intValue(); } else if (type == long.class || type == Long.class) { return number.longValue(); } else if (type == float.class || type == Float.class) { return number.floatValue(); } else if (type == double.class || type == Double.class) { return number.doubleValue(); } else if (type == BigInteger.class) { return BigInteger.valueOf(number.longValue()); } else if (type == BigDecimal.class) { return BigDecimal.valueOf(number.doubleValue()); } else if (type == Date.class) { return new Date(number.longValue()); } } else if (value instanceof Collection) { Collection collection = (Collection) value; if (type.isArray()) { int length = collection.size(); Object array = Array.newInstance(type.getComponentType(), length); int i = 0; for (Object item : collection) { Array.set(array, i++, item); } return array; } else if (!type.isInterface()) { try { Collection result = (Collection) type.newInstance(); result.addAll(collection); return result; } catch (Throwable e) { e.printStackTrace(); } } else if (type == List.class) { return new ArrayList<>(collection); } else if (type == Set.class) { return new HashSet<>(collection); } } else if (value.getClass().isArray() && Collection.class.isAssignableFrom(type)) { Collection collection; if (!type.isInterface()) { try { collection = (Collection) type.newInstance(); } catch (Throwable e) { collection = new ArrayList<>(); } } else if (type == Set.class) { collection = new HashSet<>(); } else { collection = new ArrayList<>(); } int length = Array.getLength(value); for (int i = 0; i < length; i++) { collection.add(Array.get(value, i)); } return collection; } return value; }
From source file:com.esri.gpt.server.openls.provider.util.Point.java
public void setX(String p_strX) { m_strX = p_strX; m_X = Double.valueOf(p_strX).doubleValue(); }
From source file:org.osiam.storage.helper.DataBaseSchemeVersionValidator.java
@PostConstruct public void checkVersion() throws InterruptedException { DBVersion version = em.find(DBVersion.class, DBVersion.DB_VERSION); if (version == null || !Double.valueOf(version.getVersion()).equals(DBVersion.DB_VERSION)) { throw new IllegalStateException("Database Scheme " + DBVersion.DB_VERSION + " not found. " + "The reason may be that the wrong database scheme is enrolled, please contact a System-Administrator"); }//from w ww .ja va 2s .co m }
From source file:it.nicola_amatucci.util.Json.java
public static <T> T object_from_json(JSONObject json, Class<T> objClass) throws Exception { T t = null;//from w w w .j a v a 2s . c o m Object o = null; try { //create new object instance t = objClass.newInstance(); //object fields Field[] fields = objClass.getFields(); for (Field field : fields) { //field name o = json.get(field.getName()); if (o.equals(null)) continue; //field value try { String typeName = field.getType().getSimpleName(); if (typeName.equals("String")) { o = json.getString(field.getName()); //String } else if (typeName.equals("boolean")) { o = Integer.valueOf(json.getInt(field.getName())); //boolean } else if (typeName.equals("int")) { o = Integer.valueOf(json.getInt(field.getName())); //int } else if (typeName.equals("long")) { o = Long.valueOf(json.getLong(field.getName())); //long } else if (typeName.equals("double")) { o = Double.valueOf(json.getDouble(field.getName())); //double } else if (typeName.equals("Date")) { o = new SimpleDateFormat(Json.DATA_FORMAT).parse(o.toString()); //data } else if (field.getType().isArray()) { JSONArray arrayJSON = new JSONArray(o.toString()); T[] arrayOfT = (T[]) null; try { //create object array Class c = Class.forName(field.getType().getName()).getComponentType(); arrayOfT = (T[]) Array.newInstance(c, arrayJSON.length()); //parse objects for (int i = 0; i < json.length(); i++) arrayOfT[i] = (T) object_from_json(arrayJSON.getJSONObject(i), c); } catch (Exception e) { throw e; } o = arrayOfT; } else { o = object_from_json(new JSONObject(o.toString()), field.getType()); //object } } catch (Exception e) { throw e; } t.getClass().getField(field.getName()).set(t, o); } } catch (Exception e) { throw e; } return t; }
From source file:tr.gov.ptt.gr1tahsilatuyg.managedbean.ChartBean.java
@PostConstruct public void doldurChart() { chartListe = tahsilatBorcService.chartVerisiGetir(); for (Object[] chartElement : chartListe) { pieChartModel.set(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString())); }/*from w w w. ja v a 2s. c o m*/ /*pieChartModel.set("ASK", 1400); pieChartModel.set("PTT", 200); pieChartModel.set("TELEKOM", 1000);*/ }
From source file:com.itemanalysis.psychometrics.cfa.GeneralizedLeastSquares.java
public double gfi() { double fit = 0.0; double q = Double.valueOf(model.getNumberOfItems()).doubleValue(); RealMatrix I = new IdentityMatrix(nItems); RealMatrix P = SIGMA.multiply(VCinv); RealMatrix D = I.subtract(P);/*from w w w . j a v a2s . co m*/ RealMatrix D2 = D.multiply(D); fit = 1.0 - D2.getTrace() / q; return fit; }
From source file:com.userweave.domain.service.impl.GeneralStatisticsImpl.java
public GeneralStatisticsImpl(SummaryStatistics stats, Integer overallStarted, Integer started, Integer finished) {/*ww w.j a v a2s . c o m*/ this(overallStarted, started, finished, stats == null ? 0L : Double.valueOf(stats.getMean()).longValue(), stats == null ? 0L : stats.getStandardDeviation()); }