List of usage examples for java.lang Long floatValue
public float floatValue()
From source file:Main.java
public static void main(String[] args) { Long longObject = new Long("1234567"); float f = longObject.floatValue(); System.out.println("float" + f); }
From source file:Main.java
public static void main(String[] args) { Long lObj = new Long("10"); byte b = lObj.byteValue(); System.out.println(b);/*from w w w . j a v a 2 s. c o m*/ short s = lObj.shortValue(); System.out.println(s); int i = lObj.intValue(); System.out.println(i); float f = lObj.floatValue(); System.out.println(f); double d = lObj.doubleValue(); System.out.println(d); }
From source file:org.apache.hadoop.hive.ql.udf.UDFToFloat.java
public Float evaluate(Long i) { if (i == null) { return null; } else {//from ww w .j a va2 s.c o m return Float.valueOf(i.floatValue()); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java
public boolean isEditValid() { final String S_ProcName = "isEditValid"; if (!hasValue()) { setValue(null);// w w w. j a v a 2 s .com return (true); } boolean retval = super.isEditValid(); if (retval) { try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = false; } else if (obj instanceof Float) { Float v = (Float) obj; Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof Double) { Double v = (Double) obj; Double min = getMinValue().doubleValue(); Double max = getMaxValue().doubleValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof Short) { Short s = (Short) obj; Float v = new Float(s.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof Integer) { Integer i = (Integer) obj; Float v = new Float(i.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof Long) { Long l = (Long) obj; Float v = new Float(l.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Float v = new Float(b.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else if (obj instanceof Number) { Number n = (Number) obj; Float v = new Float(n.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { retval = false; } } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number"); } } return (retval); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java
public Float getFloatValue() { final String S_ProcName = "getFloatValue"; Float retval;/*from w ww. j av a 2 s. c o m*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Float) { Float v = (Float) obj; Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Double) { Double v = (Double) obj; Double min = getMinValue().doubleValue(); Double max = getMaxValue().doubleValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = new Float(v.floatValue()); } else if (obj instanceof Short) { Short s = (Short) obj; Float v = new Float(s.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; Float v = new Float(i.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; Float v = new Float(l.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Float v = new Float(b.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; Float v = new Float(n.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }
From source file:org.sakaiproject.tool.assessment.ui.bean.qti.XMLImportBean.java
public void importAssessment(ValueChangeEvent e) { String sourceType = ContextUtil.lookupParam("sourceType"); String uploadFile = (String) e.getNewValue(); if (uploadFile != null && uploadFile.startsWith("SizeTooBig:")) { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext external = context.getExternalContext(); String paramValue = ((Long) ((ServletContext) external.getContext()) .getAttribute("FILEUPLOAD_SIZE_MAX")).toString(); Long sizeMax = null; float sizeMax_float = 0f; if (paramValue != null) { sizeMax = Long.parseLong(paramValue); sizeMax_float = sizeMax.floatValue() / 1024; }/*from w ww .java 2 s . c o m*/ int sizeMax_int = Math.round(sizeMax_float); ResourceLoader rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.AuthorImportExport"); String sizeTooBigMessage = MessageFormat.format(rb.getString("import_size_too_big"), uploadFile.substring(11), sizeMax_int); FacesMessage message = new FacesMessage(sizeTooBigMessage); FacesContext.getCurrentInstance().addMessage(null, message); // remove unsuccessful file log.debug("****Clean up file:" + uploadFile); File upload = new File(uploadFile); upload.delete(); authorBean.setImportOutcome("importAssessment"); return; } authorBean.setImportOutcome("author"); if ("2".equals(sourceType)) { if (uploadFile.toLowerCase().endsWith(".zip")) { isCP = true; importAssessment(uploadFile, true, true); } else { isCP = false; importAssessment(uploadFile, false, true); } } else { if (uploadFile.toLowerCase().endsWith(".zip")) { isCP = true; importAssessment(uploadFile, true, false); } else { isCP = false; importAssessment(uploadFile, false, false); } } }
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 w ww . j a va 2 s . c om*/ * @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.sakaiproject.tool.assessment.ui.listener.delivery.BeginDeliveryActionListener.java
/** * ACTION./*w ww .j a va 2s .co m*/ * @param ae * @throws AbortProcessingException */ public void processAction(ActionEvent ae) throws AbortProcessingException { log.debug("BeginDeliveryActionListener.processAction() "); // get managed bean and set its action accordingly DeliveryBean delivery = (DeliveryBean) ContextUtil.lookupBean("delivery"); log.debug("****DeliveryBean= " + delivery); String actionString = ContextUtil.lookupParam("actionString"); String publishedId = ContextUtil.lookupParam("publishedId"); String assessmentId = (String) ContextUtil.lookupParam("assessmentId"); if (StringUtils.isNotBlank(actionString)) { // if actionString is null, likely that action & actionString has been set already, // e.g. take assessment via url, actionString is set by LoginServlet. // preview and take assessment is set by the parameter in the jsp pages delivery.setActionString(actionString); } delivery.setDisplayFormat(); if ("previewAssessment".equals(delivery.getActionString()) || "editAssessment".equals(actionString)) { String isFromPrint = ContextUtil.lookupParam("isFromPrint"); if (StringUtils.isNotBlank(isFromPrint)) { delivery.setIsFromPrint(Boolean.parseBoolean(isFromPrint)); } } else { delivery.setIsFromPrint(false); } int action = delivery.getActionMode(); PublishedAssessmentFacade pub = getPublishedAssessmentBasedOnAction(action, delivery, assessmentId, publishedId); AssessmentAccessControlIfc control = pub.getAssessmentAccessControl(); boolean releaseToAnonymous = control.getReleaseTo() != null && control.getReleaseTo().indexOf("Anonymous Users") > -1; if (pub == null) { delivery.setOutcome("poolUpdateError"); throw new AbortProcessingException("pub is null"); } // Does the user have permission to take this action on this assessment in this site? AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization"); if (DeliveryBean.PREVIEW_ASSESSMENT == action) { if (StringUtils.isBlank(publishedId)) { if (!authzBean.isUserAllowedToEditAssessment(assessmentId, pub.getCreatedBy(), false)) { throw new IllegalArgumentException( "User does not have permission to preview assessment id " + assessmentId); } } else { if (!authzBean.isUserAllowedToEditAssessment(publishedId, pub.getCreatedBy(), true)) { throw new IllegalArgumentException( "User does not have permission to preview assessment id " + publishedId); } } } else if (DeliveryBean.REVIEW_ASSESSMENT == action || DeliveryBean.TAKE_ASSESSMENT == action) { if (!releaseToAnonymous && !authzBean.isUserAllowedToTakeAssessment(pub.getPublishedAssessmentId().toString())) { throw new IllegalArgumentException( "User does not have permission to view assessment id " + pub.getPublishedAssessmentId()); } } // Bug 1547: If this is during review and the assessment is retracted for edit now, // set the outcome to isRetractedForEdit2 error page. if (DeliveryBean.REVIEW_ASSESSMENT == action && AssessmentIfc.RETRACT_FOR_EDIT_STATUS.equals(pub.getStatus())) { delivery.setAssessmentTitle(pub.getTitle()); delivery.setHonorPledge(pub.getAssessmentMetaDataByLabel("honorpledge_isInstructorEditable") != null && pub.getAssessmentMetaDataByLabel("honorpledge_isInstructorEditable").toLowerCase() .equals("true")); delivery.setOutcome("isRetractedForEdit2"); return; } // reset DeliveryBean before begin ResetDeliveryListener reset = new ResetDeliveryListener(); reset.processAction(null); // reset timer before begin /* delivery.setTimeElapse("0"); delivery.setTimeElapseAfterFileUpload(null); delivery.setLastTimer(0); delivery.setTimeLimit("0"); */ delivery.setBeginAssessment(true); delivery.setTimeStamp((new Date()).getTime()); delivery.setRedrawAnchorName(""); // protocol = http://servername:8080/; deliverAudioRecording.jsp needs it delivery.setProtocol(ContextUtil.getProtocol()); FacesContext context = FacesContext.getCurrentInstance(); ExternalContext external = context.getExternalContext(); String paramValue = ((Long) ((ServletContext) external.getContext()).getAttribute("FILEUPLOAD_SIZE_MAX")) .toString(); Long sizeMax = null; float sizeMax_float = 0f; if (paramValue != null) { sizeMax = Long.parseLong(paramValue); sizeMax_float = sizeMax.floatValue() / 1024; } delivery.setFileUploadSizeMax(Math.round(sizeMax_float)); delivery.setPublishedAssessment(pub); // populate backing bean from published assessment populateBeanFromPub(delivery, pub); }
From source file:org.deidentifier.arx.DataHandle.java
/** * Returns a float value from the specified cell. * * @param row The cell's row index/* w w w.j a v a 2 s.c o m*/ * @param col The cell's column index * @return the float * @throws ParseException the parse exception */ public Float getFloat(int row, int col) throws ParseException { String value = getValue(row, col); DataType<?> type = getDataType(getAttributeName(col)); if (type instanceof ARXDecimal) { Double _double = ((ARXDecimal) type).parse(value); return _double == null ? null : _double.floatValue(); } else if (type instanceof ARXInteger) { Long _long = ((ARXInteger) type).parse(value); return _long == null ? null : _long.floatValue(); } else { throw new ParseException("Invalid datatype: " + type.getClass().getSimpleName(), col); } }
From source file:com.intuit.tank.vm.settings.AgentConfigCpTest.java
/** * Run the Long getConnectionTimeout() method test. * /*from w w w . j a v a 2 s . c o m*/ * @throws Exception * * @generatedBy CodePro at 9/3/14 3:44 PM */ @Test public void testGetConnectionTimeout_1() throws Exception { AgentConfig fixture = new AgentConfig(new HierarchicalConfiguration()); fixture.setResultsTypeMap(new HashMap()); Long result = fixture.getConnectionTimeout(); assertNotNull(result); assertEquals("40000", result.toString()); assertEquals((byte) 64, result.byteValue()); assertEquals((short) -25536, result.shortValue()); assertEquals(40000, result.intValue()); assertEquals(40000L, result.longValue()); assertEquals(40000.0f, result.floatValue(), 1.0f); assertEquals(40000.0, result.doubleValue(), 1.0); }