List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:forge.card.mana.ManaCost.java
private Float getCompareWeight() { if (this.compareWeight == null) { float weight = this.genericCost; for (final ManaCostShard s : this.shards) { weight += s.getCmpc();//www .j ava 2 s . c o m } if (this.hasNoCost) { weight = -1; // for those who doesn't even have a 0 sign on card } this.compareWeight = Float.valueOf(weight); } return this.compareWeight; }
From source file:de.kp.ames.web.core.render.ScRenderer.java
/** * @param value//from w w w .j av a 2 s . c o m * @return */ private int toIntegerValue(String value) { try { return Float.valueOf(value).intValue(); } catch (NumberFormatException e) { // do nothing } finally { // do nothing } return 0; }
From source file:com.liferay.portal.search.elasticsearch.internal.document.DefaultElasticsearchDocumentFactory.java
protected Object translateValue(Field field, String value) { if (!field.isNumeric()) { return value; }//from w w w . j a v a 2s .co m Class<? extends Number> clazz = field.getNumericClass(); if (clazz.equals(Float.class)) { return Float.valueOf(value); } else if (clazz.equals(Integer.class)) { return Integer.valueOf(value); } else if (clazz.equals(Long.class)) { return Long.valueOf(value); } else if (clazz.equals(Short.class)) { return Short.valueOf(value); } return Double.valueOf(value); }
From source file:com.pivotal.gemfire.tools.pulse.internal.service.ClusterMembersRGraphService.java
/** * function used for getting all members details in format of JSON Object * array defined under a cluster. This function create json based on the * relation of physical host and members related to it. * /*from ww w . j ava 2 s . c o m*/ * @param cluster * @param host * @param port * @return Array list of JSON objects for required fields of members in * cluster */ private JSONObject getPhysicalServerJson(Cluster cluster, String host, String port) throws JSONException { Map<String, List<Cluster.Member>> physicalToMember = cluster.getPhysicalToMember(); JSONObject clusterTopologyJSON = new JSONObject(); clusterTopologyJSON.put(this.ID, cluster.getClusterId()); clusterTopologyJSON.put(this.NAME, cluster.getClusterId()); JSONObject data1 = new JSONObject(); clusterTopologyJSON.put(this.DATA, data1); JSONArray childHostArray = new JSONArray(); DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); updateAlertLists(cluster); for (Map.Entry<String, List<Cluster.Member>> physicalToMem : physicalToMember.entrySet()) { String hostName = physicalToMem.getKey(); Float hostCpuUsage = 0.0F; Long hostMemoryUsage = (long) 0; Double hostLoadAvg = 0.0; int hostNumThreads = 0; Long hostSockets = (long) 0; Long hostOpenFDs = (long) 0; boolean hostSevere = false; boolean hostError = false; boolean hostWarning = false; String hostStatus; JSONObject childHostObject = new JSONObject(); childHostObject.put(this.ID, hostName); childHostObject.put(this.NAME, hostName); JSONArray membersArray = new JSONArray(); List<Cluster.Member> memberList = physicalToMem.getValue(); for (Cluster.Member member : memberList) { JSONObject memberJSONObj = new JSONObject(); memberJSONObj.put(this.ID, member.getId()); memberJSONObj.put(this.NAME, member.getName()); JSONObject memberData = new JSONObject(); Long currentHeap = member.getCurrentHeapSize(); Long usedHeapSize = cluster.getUsedHeapSize(); if (usedHeapSize > 0) { float heapUsage = (currentHeap.floatValue() / usedHeapSize.floatValue()) * 100; memberData.put(this.MEMORY_USAGE, Double.valueOf(df2.format(heapUsage))); } else memberData.put(this.MEMORY_USAGE, 0); Float currentCPUUsage = member.getCpuUsage(); memberData.put(this.CPU_USAGE, Float.valueOf(df2.format(currentCPUUsage))); memberData.put(this.REGIONS, member.getMemberRegions().size()); memberData.put(this.HOST, member.getHost()); if ((member.getMemberPort() == null) || (member.getMemberPort().equals(""))) { memberData.put(this.PORT, "-"); } else { memberData.put(this.PORT, member.getMemberPort()); } // Number of member clients if (PulseController.getPulseProductSupport() .equalsIgnoreCase(PulseConstants.PRODUCT_NAME_GEMFIREXD)) { memberData.put(this.CLIENTS, member.getNumGemFireXDClients()); } else { memberData.put(this.CLIENTS, member.getMemberClientsHMap().size()); } memberData.put(this.GC_PAUSES, member.getGarbageCollectionCount()); memberData.put(this.NUM_THREADS, member.getNumThreads()); // Host CPU Usage is aggregate of all members cpu usage // hostCpuUsage = hostCpuUsage + currentCPUUsage; hostCpuUsage = member.getHostCpuUsage(); hostMemoryUsage = hostMemoryUsage + member.getCurrentHeapSize(); hostLoadAvg = member.getLoadAverage(); hostNumThreads = member.getNumThreads(); hostSockets = member.getTotalFileDescriptorOpen(); hostOpenFDs = member.getTotalFileDescriptorOpen(); // defining the status of Member Icons for R Graph based on the alerts // created for that member String memberNodeType = ""; // for severe alert if (severeAlertList.contains(member.getName())) { memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_SEVERE); if (!hostSevere) { hostSevere = true; } } // for error alerts else if (errorAlertsList.contains(member.getName())) { memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_ERROR); if (!hostError) { hostError = true; } } // for warning alerts else if (warningAlertsList.contains(member.getName())) { memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_WARNING); if (!hostWarning) hostWarning = true; } else { memberNodeType = getMemberNodeType(member, this.MEMBER_NODE_TYPE_NORMAL); } memberData.put("nodeType", memberNodeType); memberData.put("$type", memberNodeType); memberData.put(this.GATEWAY_SENDER, member.getGatewaySenderList().size()); if (member.getGatewayReceiver() != null) { memberData.put(this.GATEWAY_RECEIVER, "1"); } else { memberData.put(this.GATEWAY_RECEIVER, "0"); } memberJSONObj.put(this.DATA, memberData); memberJSONObj.put(this.CHILDREN, new JSONArray()); membersArray.put(memberJSONObj); } JSONObject data = new JSONObject(); data.put(this.LOAD_AVG, hostLoadAvg); data.put(this.SOCKETS, hostSockets); data.put(this.OPENFDS, hostOpenFDs); data.put(this.THREADS, hostNumThreads); data.put(this.CPU_USAGE, Double.valueOf(df2.format(hostCpuUsage))); data.put(this.MEMORY_USAGE, hostMemoryUsage); String hostNodeType; // setting physical host status if (hostSevere) { hostStatus = this.MEMBER_NODE_TYPE_SEVERE; hostNodeType = "hostSevereNode"; } else if (hostError) { hostStatus = this.MEMBER_NODE_TYPE_ERROR; hostNodeType = "hostErrorNode"; } else if (hostWarning) { hostStatus = this.MEMBER_NODE_TYPE_WARNING; hostNodeType = "hostWarningNode"; } else { hostStatus = this.MEMBER_NODE_TYPE_NORMAL; hostNodeType = "hostNormalNode"; } data.put("hostStatus", hostStatus); data.put("$type", hostNodeType); childHostObject.put(this.DATA, data); childHostObject.put(this.CHILDREN, membersArray); childHostArray.put(childHostObject); } clusterTopologyJSON.put(this.CHILDREN, childHostArray); return clusterTopologyJSON; }
From source file:org.alfresco.serializers.types.DefaultTypeConverter.java
@SuppressWarnings("rawtypes") private DefaultTypeConverter() { ////from w ww . j a v a 2s. c o m // From string // addConverter(String.class, Class.class, new TypeConverter.Converter<String, Class>() { public Class convert(String source) { try { return Class.forName(source); } catch (ClassNotFoundException e) { throw new TypeConversionException("Failed to convert string to class: " + source, e); } } }); addConverter(String.class, Boolean.class, new TypeConverter.Converter<String, Boolean>() { public Boolean convert(String source) { return Boolean.valueOf(source); } }); addConverter(String.class, Character.class, new TypeConverter.Converter<String, Character>() { public Character convert(String source) { if ((source == null) || (source.length() == 0)) { return null; } return Character.valueOf(source.charAt(0)); } }); addConverter(String.class, Number.class, new TypeConverter.Converter<String, Number>() { public Number convert(String source) { try { return DecimalFormat.getNumberInstance().parse(source); } catch (ParseException e) { throw new TypeConversionException("Failed to parse number " + source, e); } } }); addConverter(String.class, Byte.class, new TypeConverter.Converter<String, Byte>() { public Byte convert(String source) { return Byte.valueOf(source); } }); addConverter(String.class, Short.class, new TypeConverter.Converter<String, Short>() { public Short convert(String source) { return Short.valueOf(source); } }); addConverter(String.class, Integer.class, new TypeConverter.Converter<String, Integer>() { public Integer convert(String source) { return Integer.valueOf(source); } }); addConverter(String.class, Long.class, new TypeConverter.Converter<String, Long>() { public Long convert(String source) { return Long.valueOf(source); } }); addConverter(String.class, Float.class, new TypeConverter.Converter<String, Float>() { public Float convert(String source) { return Float.valueOf(source); } }); addConverter(String.class, Double.class, new TypeConverter.Converter<String, Double>() { public Double convert(String source) { return Double.valueOf(source); } }); addConverter(String.class, BigInteger.class, new TypeConverter.Converter<String, BigInteger>() { public BigInteger convert(String source) { return new BigInteger(source); } }); addConverter(String.class, BigDecimal.class, new TypeConverter.Converter<String, BigDecimal>() { public BigDecimal convert(String source) { return new BigDecimal(source); } }); addConverter(BasicDBObject.class, BigDecimal.class, new TypeConverter.Converter<BasicDBObject, BigDecimal>() { public BigDecimal convert(BasicDBObject source) { String type = (String) source.get("t"); if (type.equals("FIXED_POINT")) { String number = (String) source.get("n"); Integer precision = (Integer) source.get("p"); MathContext ctx = new MathContext(precision); return new BigDecimal(number, ctx); } else { throw new IllegalArgumentException("Invalid source object for conversion " + source + ", expected a Fixed Decimal object"); } } }); addConverter(String.class, Date.class, new TypeConverter.Converter<String, Date>() { public Date convert(String source) { try { Date date = ISO8601DateFormat.parse(source); return date; } catch (PlatformRuntimeException e) { throw new TypeConversionException("Failed to convert date " + source + " to string", e); } catch (AlfrescoRuntimeException e) { throw new TypeConversionException("Failed to convert date " + source + " to string", e); } } }); addConverter(String.class, Duration.class, new TypeConverter.Converter<String, Duration>() { public Duration convert(String source) { return new Duration(source); } }); addConverter(String.class, QName.class, new TypeConverter.Converter<String, QName>() { public QName convert(String source) { return QName.createQName(source); } }); addConverter(BasicDBObject.class, QName.class, new TypeConverter.Converter<BasicDBObject, QName>() { public QName convert(BasicDBObject source) { String type = (String) source.get("t"); if (type.equals("QNAME")) { String qname = (String) source.get("v"); return QName.createQName(qname); } else { throw new IllegalArgumentException(); } } }); addConverter(String.class, ContentData.class, new TypeConverter.Converter<String, ContentData>() { public ContentData convert(String source) { return ContentData.createContentProperty(source); } }); addConverter(String.class, NodeRef.class, new TypeConverter.Converter<String, NodeRef>() { public NodeRef convert(String source) { return new NodeRef(source); } }); addConverter(BasicDBObject.class, NodeRef.class, new TypeConverter.Converter<BasicDBObject, NodeRef>() { public NodeRef convert(BasicDBObject source) { String type = (String) source.get("t"); if (!type.equals("NODEREF")) { throw new IllegalArgumentException( "Invalid source object for conversion " + source + ", expected a NodeRef object"); } String protocol = (String) source.get("p"); String storeId = (String) source.get("s"); String id = (String) source.get("id"); NodeRef nodeRef = new NodeRef(new StoreRef(protocol, storeId), id); return nodeRef; } }); addConverter(String.class, StoreRef.class, new TypeConverter.Converter<String, StoreRef>() { public StoreRef convert(String source) { return new StoreRef(source); } }); addConverter(BasicDBObject.class, StoreRef.class, new TypeConverter.Converter<BasicDBObject, StoreRef>() { public StoreRef convert(BasicDBObject source) { String type = (String) source.get("t"); if (!type.equals("STOREREF")) { throw new IllegalArgumentException( "Invalid source object for conversion " + source + ", expected a StoreRef object"); } String protocol = (String) source.get("p"); String storeId = (String) source.get("s"); return new StoreRef(protocol, storeId); } }); addConverter(String.class, ChildAssociationRef.class, new TypeConverter.Converter<String, ChildAssociationRef>() { public ChildAssociationRef convert(String source) { return new ChildAssociationRef(source); } }); addConverter(String.class, AssociationRef.class, new TypeConverter.Converter<String, AssociationRef>() { public AssociationRef convert(String source) { return new AssociationRef(source); } }); addConverter(String.class, InputStream.class, new TypeConverter.Converter<String, InputStream>() { public InputStream convert(String source) { try { return new ByteArrayInputStream(source.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new TypeConversionException("Encoding not supported", e); } } }); addConverter(String.class, MLText.class, new TypeConverter.Converter<String, MLText>() { public MLText convert(String source) { return new MLText(source); } }); addConverter(BasicDBObject.class, MLText.class, new TypeConverter.Converter<BasicDBObject, MLText>() { public MLText convert(BasicDBObject source) { String type = (String) source.get("t"); if (!type.equals("MLTEXT")) { throw new IllegalArgumentException( "Invalid source object for conversion " + source + ", expected a NodeRef object"); } MLText mlText = new MLText(); for (String languageTag : source.keySet()) { String text = (String) source.get(languageTag); Locale locale = Locale.forLanguageTag(languageTag); mlText.put(locale, text); } return mlText; } }); // addConverter(BasicDBObject.class, ContentDataWithId.class, new TypeConverter.Converter<BasicDBObject, ContentDataWithId>() // { // public ContentDataWithId convert(BasicDBObject source) // { // String type = (String)source.get("t"); // if(!type.equals("CONTENT_DATA_ID")) // { // throw new IllegalArgumentException("Invalid source object for conversion " // + source // + ", expected a ContentDataWithId object"); // } // String contentUrl = (String)source.get("u"); // String mimeType = (String)source.get("m"); // Long size = (Long)source.get("s"); // String encoding = (String)source.get("e"); // String languageTag = (String)source.get("l"); // Long id = (Long)source.get("id"); // Locale locale = Locale.forLanguageTag(languageTag); // // ContentData contentData = new ContentData(contentUrl, mimeType, size, encoding, locale); // ContentDataWithId contentDataWithId = new ContentDataWithId(contentData, id); // return contentDataWithId; // } // }); addConverter(BasicDBObject.class, ContentData.class, new TypeConverter.Converter<BasicDBObject, ContentData>() { public ContentData convert(BasicDBObject source) { ContentData contentData = null; String type = (String) source.get("t"); if (type.equals("CONTENT")) { String contentUrl = (String) source.get("u"); String mimeType = (String) source.get("m"); Long size = (Long) source.get("s"); String encoding = (String) source.get("e"); String languageTag = (String) source.get("l"); Locale locale = Locale.forLanguageTag(languageTag); contentData = new ContentData(contentUrl, mimeType, size, encoding, locale); } else if (type.equals("CONTENT_DATA_ID")) { String contentUrl = (String) source.get("u"); String mimeType = (String) source.get("m"); Long size = (Long) source.get("s"); String encoding = (String) source.get("e"); String languageTag = (String) source.get("l"); Locale locale = Locale.forLanguageTag(languageTag); contentData = new ContentData(contentUrl, mimeType, size, encoding, locale); } else { throw new IllegalArgumentException("Invalid source object for conversion " + source + ", expected a ContentData object"); } return contentData; } }); addConverter(BasicDBObject.class, String.class, new TypeConverter.Converter<BasicDBObject, String>() { public String convert(BasicDBObject source) { // TODO distinguish between different BasicDBObject representations e.g. for MLText, ... Set<String> languageTags = source.keySet(); if (languageTags.size() == 0) { throw new IllegalArgumentException("Persisted MLText is invalid " + source); } else if (languageTags.size() > 1) { // TODO logger.warn("Persisted MLText has more than 1 locale " + source); } String languageTag = languageTags.iterator().next(); String text = source.getString(languageTag); return text; } }); addConverter(String.class, Locale.class, new TypeConverter.Converter<String, Locale>() { public Locale convert(String source) { return I18NUtil.parseLocale(source); } }); addConverter(String.class, Period.class, new TypeConverter.Converter<String, Period>() { public Period convert(String source) { return new Period(source); } }); addConverter(String.class, VersionNumber.class, new TypeConverter.Converter<String, VersionNumber>() { public VersionNumber convert(String source) { return new VersionNumber(source); } }); // // From Locale // addConverter(Locale.class, String.class, new TypeConverter.Converter<Locale, String>() { public String convert(Locale source) { String localeStr = source.toString(); if (localeStr.length() < 6) { localeStr += "_"; } return localeStr; } }); // // From VersionNumber // addConverter(VersionNumber.class, String.class, new TypeConverter.Converter<VersionNumber, String>() { public String convert(VersionNumber source) { return source.toString(); } }); // // From MLText // addConverter(MLText.class, String.class, new TypeConverter.Converter<MLText, String>() { public String convert(MLText source) { return source.getDefaultValue(); } }); addConverter(MLText.class, BasicDBObject.class, new TypeConverter.Converter<MLText, BasicDBObject>() { public BasicDBObject convert(MLText source) { BasicDBObject dbObject = new BasicDBObject("t", "MLTEXT"); for (Map.Entry<Locale, String> entry : source.entrySet()) { dbObject.put(entry.getKey().toLanguageTag(), entry.getValue()); } return dbObject; } }); // addConverter(ContentDataWithId.class, BasicDBObject.class, new TypeConverter.Converter<ContentDataWithId, BasicDBObject>() // { // public BasicDBObject convert(ContentDataWithId source) // { // BasicDBObject dbObject = new BasicDBObject("t", "CONTENT_DATA_ID"); // // String contentUrl = source.getContentUrl(); // Long id = source.getId(); // String languageTag = source.getLocale().toLanguageTag(); // String encoding = source.getEncoding(); // long size = source.getSize(); // String mimeType = source.getMimetype(); // // dbObject.put("u", contentUrl); // dbObject.put("m", mimeType); // dbObject.put("s", size); // dbObject.put("e", encoding); // dbObject.put("l", languageTag); // dbObject.put("id", id); // return dbObject; // } // }); addConverter(ContentData.class, BasicDBObject.class, new TypeConverter.Converter<ContentData, BasicDBObject>() { public BasicDBObject convert(ContentData source) { BasicDBObject dbObject = new BasicDBObject("t", "CONTENT"); String contentUrl = source.getContentUrl(); String languageTag = source.getLocale().toLanguageTag(); String encoding = source.getEncoding(); long size = source.getSize(); String mimeType = source.getMimetype(); dbObject.put("u", contentUrl); dbObject.put("m", mimeType); dbObject.put("s", size); dbObject.put("e", encoding); dbObject.put("l", languageTag); return dbObject; } }); // // From enum // addConverter(Enum.class, String.class, new TypeConverter.Converter<Enum, String>() { public String convert(Enum source) { return source.toString(); } }); // From Period addConverter(Period.class, String.class, new TypeConverter.Converter<Period, String>() { public String convert(Period source) { return source.toString(); } }); // From Class addConverter(Class.class, String.class, new TypeConverter.Converter<Class, String>() { public String convert(Class source) { return source.getName(); } }); // // Number to Subtypes and Date // addConverter(Number.class, Boolean.class, new TypeConverter.Converter<Number, Boolean>() { public Boolean convert(Number source) { return new Boolean(source.longValue() > 0); } }); addConverter(Number.class, Byte.class, new TypeConverter.Converter<Number, Byte>() { public Byte convert(Number source) { return Byte.valueOf(source.byteValue()); } }); addConverter(Number.class, Short.class, new TypeConverter.Converter<Number, Short>() { public Short convert(Number source) { return Short.valueOf(source.shortValue()); } }); addConverter(Number.class, Integer.class, new TypeConverter.Converter<Number, Integer>() { public Integer convert(Number source) { return Integer.valueOf(source.intValue()); } }); addConverter(Number.class, Long.class, new TypeConverter.Converter<Number, Long>() { public Long convert(Number source) { return Long.valueOf(source.longValue()); } }); addConverter(Number.class, Float.class, new TypeConverter.Converter<Number, Float>() { public Float convert(Number source) { return Float.valueOf(source.floatValue()); } }); addConverter(Number.class, Double.class, new TypeConverter.Converter<Number, Double>() { public Double convert(Number source) { return Double.valueOf(source.doubleValue()); } }); addConverter(Number.class, Date.class, new TypeConverter.Converter<Number, Date>() { public Date convert(Number source) { return new Date(source.longValue()); } }); addConverter(Number.class, String.class, new TypeConverter.Converter<Number, String>() { public String convert(Number source) { return source.toString(); } }); addConverter(Number.class, BigInteger.class, new TypeConverter.Converter<Number, BigInteger>() { public BigInteger convert(Number source) { if (source instanceof BigDecimal) { return ((BigDecimal) source).toBigInteger(); } else { return BigInteger.valueOf(source.longValue()); } } }); addConverter(Number.class, BigDecimal.class, new TypeConverter.Converter<Number, BigDecimal>() { public BigDecimal convert(Number source) { if (source instanceof BigInteger) { return new BigDecimal((BigInteger) source); } else if (source instanceof Double) { return BigDecimal.valueOf((Double) source); } else if (source instanceof Float) { Float val = (Float) source; if (val.isInfinite()) { // What else can we do here? this is 3.4 E 38 so is fairly big return new BigDecimal(Float.MAX_VALUE); } return BigDecimal.valueOf((Float) source); } else { return BigDecimal.valueOf(source.longValue()); } } }); addDynamicTwoStageConverter(Number.class, String.class, InputStream.class); // // Date, Timestamp -> // addConverter(Timestamp.class, Date.class, new TypeConverter.Converter<Timestamp, Date>() { public Date convert(Timestamp source) { return new Date(source.getTime()); } }); addConverter(Date.class, Number.class, new TypeConverter.Converter<Date, Number>() { public Number convert(Date source) { return Long.valueOf(source.getTime()); } }); addConverter(Date.class, String.class, new TypeConverter.Converter<Date, String>() { public String convert(Date source) { try { return ISO8601DateFormat.format(source); } catch (PlatformRuntimeException e) { throw new TypeConversionException("Failed to convert date " + source + " to string", e); } } }); addConverter(Date.class, Calendar.class, new TypeConverter.Converter<Date, Calendar>() { public Calendar convert(Date source) { Calendar calendar = Calendar.getInstance(); calendar.setTime(source); return calendar; } }); addConverter(Date.class, GregorianCalendar.class, new TypeConverter.Converter<Date, GregorianCalendar>() { public GregorianCalendar convert(Date source) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(source); return calendar; } }); addDynamicTwoStageConverter(Date.class, String.class, InputStream.class); // // Boolean -> // final Long LONG_FALSE = new Long(0L); final Long LONG_TRUE = new Long(1L); addConverter(Boolean.class, Long.class, new TypeConverter.Converter<Boolean, Long>() { public Long convert(Boolean source) { return source.booleanValue() ? LONG_TRUE : LONG_FALSE; } }); addConverter(Boolean.class, String.class, new TypeConverter.Converter<Boolean, String>() { public String convert(Boolean source) { return source.toString(); } }); addDynamicTwoStageConverter(Boolean.class, String.class, InputStream.class); // // Character -> // addConverter(Character.class, String.class, new TypeConverter.Converter<Character, String>() { public String convert(Character source) { return source.toString(); } }); addDynamicTwoStageConverter(Character.class, String.class, InputStream.class); // // Duration -> // addConverter(Duration.class, String.class, new TypeConverter.Converter<Duration, String>() { public String convert(Duration source) { return source.toString(); } }); addDynamicTwoStageConverter(Duration.class, String.class, InputStream.class); // // Byte // addConverter(Byte.class, String.class, new TypeConverter.Converter<Byte, String>() { public String convert(Byte source) { return source.toString(); } }); addDynamicTwoStageConverter(Byte.class, String.class, InputStream.class); // // Short // addConverter(Short.class, String.class, new TypeConverter.Converter<Short, String>() { public String convert(Short source) { return source.toString(); } }); addDynamicTwoStageConverter(Short.class, String.class, InputStream.class); // // Integer // addConverter(Integer.class, String.class, new TypeConverter.Converter<Integer, String>() { public String convert(Integer source) { return source.toString(); } }); addDynamicTwoStageConverter(Integer.class, String.class, InputStream.class); // // Long // addConverter(Long.class, String.class, new TypeConverter.Converter<Long, String>() { public String convert(Long source) { return source.toString(); } }); addDynamicTwoStageConverter(Long.class, String.class, InputStream.class); // // Float // addConverter(Float.class, String.class, new TypeConverter.Converter<Float, String>() { public String convert(Float source) { return source.toString(); } }); addDynamicTwoStageConverter(Float.class, String.class, InputStream.class); // // Double // addConverter(Double.class, String.class, new TypeConverter.Converter<Double, String>() { public String convert(Double source) { return source.toString(); } }); addDynamicTwoStageConverter(Double.class, String.class, InputStream.class); // // BigInteger // addConverter(BigInteger.class, String.class, new TypeConverter.Converter<BigInteger, String>() { public String convert(BigInteger source) { return source.toString(); } }); addDynamicTwoStageConverter(BigInteger.class, String.class, InputStream.class); // // Calendar // addConverter(Calendar.class, Date.class, new TypeConverter.Converter<Calendar, Date>() { public Date convert(Calendar source) { return source.getTime(); } }); addConverter(Calendar.class, String.class, new TypeConverter.Converter<Calendar, String>() { public String convert(Calendar source) { try { return ISO8601DateFormat.format(source.getTime()); } catch (PlatformRuntimeException e) { throw new TypeConversionException("Failed to convert date " + source + " to string", e); } } }); // // BigDecimal // addConverter(BigDecimal.class, BasicDBObject.class, new TypeConverter.Converter<BigDecimal, BasicDBObject>() { public BasicDBObject convert(BigDecimal source) { String number = source.toPlainString(); int precision = source.precision(); BasicDBObject dbObject = new BasicDBObject(); dbObject.put("t", "FIXED_POINT"); dbObject.put("n", number); dbObject.put("p", precision); return dbObject; } }); addConverter(BigDecimal.class, String.class, new TypeConverter.Converter<BigDecimal, String>() { public String convert(BigDecimal source) { return source.toString(); } }); addDynamicTwoStageConverter(BigDecimal.class, String.class, InputStream.class); // // QName // addConverter(QName.class, String.class, new TypeConverter.Converter<QName, String>() { public String convert(QName source) { return source.toString(); } }); addDynamicTwoStageConverter(QName.class, String.class, InputStream.class); // // EntityRef (NodeRef, ChildAssociationRef, NodeAssociationRef) // addConverter(EntityRef.class, String.class, new TypeConverter.Converter<EntityRef, String>() { public String convert(EntityRef source) { return source.toString(); } }); addConverter(EntityRef.class, BasicDBObject.class, new TypeConverter.Converter<EntityRef, BasicDBObject>() { public BasicDBObject convert(EntityRef source) { BasicDBObject ret = null; if (source instanceof NodeRef) { NodeRef nodeRef = (NodeRef) source; BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("t", "NODEREF"); builder.add("p", nodeRef.getStoreRef().getProtocol()); builder.add("s", nodeRef.getStoreRef().getIdentifier()); builder.add("id", nodeRef.getId()); ret = (BasicDBObject) builder.get(); } else if (source instanceof StoreRef) { StoreRef storeRef = (StoreRef) source; BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("t", "STOREREF"); builder.add("p", storeRef.getProtocol()); builder.add("s", storeRef.getIdentifier()); ret = (BasicDBObject) builder.get(); } else { throw new IllegalArgumentException(); } return ret; } }); addDynamicTwoStageConverter(EntityRef.class, String.class, InputStream.class); // // ContentData // addConverter(ContentData.class, String.class, new TypeConverter.Converter<ContentData, String>() { public String convert(ContentData source) { return source.getInfoUrl(); } }); addDynamicTwoStageConverter(ContentData.class, String.class, InputStream.class); // // Path // addConverter(Path.class, String.class, new TypeConverter.Converter<Path, String>() { public String convert(Path source) { return source.toString(); } }); addDynamicTwoStageConverter(Path.class, String.class, InputStream.class); // // Content Reader // addConverter(ContentReader.class, InputStream.class, new TypeConverter.Converter<ContentReader, InputStream>() { public InputStream convert(ContentReader source) { return source.getContentInputStream(); } }); addConverter(ContentReader.class, String.class, new TypeConverter.Converter<ContentReader, String>() { public String convert(ContentReader source) { // Getting the string from the ContentReader binary is meaningless return source.toString(); } }); // // Content Writer // addConverter(ContentWriter.class, String.class, new TypeConverter.Converter<ContentWriter, String>() { public String convert(ContentWriter source) { return source.toString(); } }); addConverter(Collection.class, BasicDBList.class, new TypeConverter.Converter<Collection, BasicDBList>() { public BasicDBList convert(Collection source) { BasicDBList ret = new BasicDBList(); for (Object o : source) { ret.add(o); } return ret; } }); addConverter(BasicDBList.class, Collection.class, new TypeConverter.Converter<BasicDBList, Collection>() { @SuppressWarnings("unchecked") public Collection convert(BasicDBList source) { Collection ret = new LinkedList(); for (Object o : source) { ret.add(o); } return ret; } }); // // Input Stream // addConverter(InputStream.class, String.class, new TypeConverter.Converter<InputStream, String>() { public String convert(InputStream source) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int read; while ((read = source.read(buffer)) > 0) { out.write(buffer, 0, read); } byte[] data = out.toByteArray(); return new String(data, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new TypeConversionException("Cannot convert input stream to String.", e); } catch (IOException e) { throw new TypeConversionException("Conversion from stream to string failed", e); } finally { if (source != null) { try { source.close(); } catch (IOException e) { //NOOP } } } } }); addDynamicTwoStageConverter(InputStream.class, String.class, Date.class); addDynamicTwoStageConverter(InputStream.class, String.class, Double.class); addDynamicTwoStageConverter(InputStream.class, String.class, Long.class); addDynamicTwoStageConverter(InputStream.class, String.class, Boolean.class); addDynamicTwoStageConverter(InputStream.class, String.class, QName.class); addDynamicTwoStageConverter(InputStream.class, String.class, Path.class); addDynamicTwoStageConverter(InputStream.class, String.class, NodeRef.class); }
From source file:ml.dmlc.xgboost4j.java.Booster.java
/** * evaluate with given dmatrixs./* www. j ava 2 s.c o m*/ * * @param evalMatrixs dmatrixs for evaluation * @param evalNames name for eval dmatrixs, used for check results * @param iter current eval iteration * @param metricsOut output array containing the evaluation metrics for each evalMatrix * @return eval information * @throws XGBoostError native error */ public String evalSet(DMatrix[] evalMatrixs, String[] evalNames, int iter, float[] metricsOut) throws XGBoostError { String stringFormat = evalSet(evalMatrixs, evalNames, iter); String[] metricPairs = stringFormat.split("\t"); for (int i = 1; i < metricPairs.length; i++) { metricsOut[i - 1] = Float.valueOf(metricPairs[i].split(":")[1]); } return stringFormat; }
From source file:de.perdian.commons.servlet.ServletUtils.java
/** * Extracts the locales supported by the client that sent a given request. * According to RFC 2161 the result list will be sorted according to any * specified preferenc value (see the RFC for details) * * @param servletRequest// w ww . ja va 2 s . co m * the request from which to extract the information * @param defaultLocales * the locales to be returned if no locales could be extracted from the * request * @return * a {@code List} containing the accepted {@code java.util.Locale} * objects. If no locales are found in the request, then the method will * return the default locale list or an empty list if no default locales * have been passed - never {@code null} */ public static List<Locale> extractAcceptedLocales(HttpServletRequest servletRequest, List<Locale> defaultLocales) { Map<Float, List<Locale>> localeValuesByPriority = new TreeMap<>((o1, o2) -> -1 * Float.compare(o1, o2)); String headerValue = servletRequest.getHeader("accept-language"); if (headerValue != null) { StringTokenizer headerTokenizer = new StringTokenizer(headerValue, ","); while (headerTokenizer.hasMoreElements()) { String header = headerTokenizer.nextToken().trim(); int semicolonSeparator = header.indexOf(";"); String localeValue = semicolonSeparator > 0 ? header.substring(0, semicolonSeparator) : header; Locale locale = LocaleUtils.toLocale(localeValue); if (locale != null) { Float qValue = Float.valueOf(1f); String qParameter = ";q="; int qParameterIndex = header.indexOf(qParameter); if (qParameterIndex > 0) { try { String qParameterValue = header.substring(qParameterIndex + qParameter.length()); qValue = Float.valueOf(qParameterValue); } catch (Exception e) { // Ignore here and use the default } } List<Locale> targetList = localeValuesByPriority.get(qValue); if (targetList == null) { targetList = new ArrayList<>(); localeValuesByPriority.put(qValue, targetList); } targetList.add(locale); } } } List<Locale> localeValues = new ArrayList<>(); for (Map.Entry<Float, List<Locale>> localeValueEntry : localeValuesByPriority.entrySet()) { for (Locale locale : localeValueEntry.getValue()) { localeValues.add(locale); } } if (localeValues.isEmpty() && defaultLocales != null) { localeValues.addAll(defaultLocales); } return Collections.unmodifiableList(localeValues); }
From source file:magma.agent.perception.impl.ServerMessageParser.java
/** * Parse a symbol tree node into a Gyro Perceptor object * /*from w w w . ja va2 s . com*/ * @param node Symbol tree node * @return Gyro Perceptor object */ private GyroPerceptor parseGyro(SymbolNode node) throws PerceptorConversionException { if (!(node.getChild(1) instanceof SymbolNode) || !(node.getChild(2) instanceof SymbolNode)) throw new PerceptorConversionException("Malformed Message: " + node.toString()); try { /* Check content */ SymbolNode nameNode = (SymbolNode) node.getChild(1); SymbolNode rotationNode = (SymbolNode) node.getChild(2); if (!nameNode.getChild(0).content().equals("n")) throw new PerceptorConversionException("name expected: " + node.toString()); if (!rotationNode.getChild(0).content().equals("rt")) throw new PerceptorConversionException("rotation expected: " + node.toString()); return new GyroPerceptor(nameNode.getChild(1).content(), Float.valueOf(rotationNode.getChild(1).content()), Float.valueOf(rotationNode.getChild(2).content()), Float.valueOf(rotationNode.getChild(3).content())); } catch (IndexOutOfBoundsException e) { throw new PerceptorConversionException("Malformed node: " + node.toString()); } }
From source file:org.apache.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes attrs, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); final Table table = getTable(tableName); for (int i = 0; i < attrs.getLength(); i++) { Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType(); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; }/* w w w .j av a 2 s . com*/ switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.REAL: case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BLOB: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); query.setParameter(i + 1, attrs.getValue(i)); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: query.setParameter(i + 1, attrs.getValue(i)); } } }
From source file:gov.nih.nci.caintegrator.domain.analysis.GisticAllLesionsFileParser.java
private Double roundToThreeDecimalPlaces(String value) { float floatValue = Float.valueOf(value); return Double.valueOf(Math.round(floatValue * DECIMAL_1000) / DECIMAL_1000); }