List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:op.tools.SYSTools.java
public static BigDecimal parseDecimal(String test) { NumberFormat nf = DecimalFormat.getNumberInstance(); test = assimilateDecimalSeparators(test); Number num; try {//from w w w .j a va 2 s .co m num = nf.parse(test); } catch (Exception ex) { num = null; } BigDecimal wert = null; if (num != null) { if (num instanceof Long) { wert = new BigDecimal(num.longValue()); } else if (num instanceof Double) { wert = new BigDecimal(num.doubleValue()); } else if (num instanceof BigDecimal) { wert = (BigDecimal) num; } else { wert = null; } } return wert; }
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java
private Object convertNumberTypes(Object val, String javaColType) { Number n = (Number) val; if (javaColType.equals(BYTE_TYPE)) { return n.byteValue(); } else if (javaColType.equals(SHORT_TYPE)) { return n.shortValue(); } else if (javaColType.equals(INTEGER_TYPE)) { return n.intValue(); } else if (javaColType.equals(LONG_TYPE)) { return n.longValue(); } else if (javaColType.equals(FLOAT_TYPE)) { return n.floatValue(); } else if (javaColType.equals(DOUBLE_TYPE)) { return n.doubleValue(); } else if (javaColType.equals(BIG_DECIMAL_TYPE)) { return new BigDecimal(n.doubleValue()); } else if (javaColType.equals(BOOLEAN_TYPE)) { return n.byteValue() == 0 ? Boolean.FALSE : Boolean.TRUE; } else if (javaColType.equals(STRING_TYPE)) { return n.toString(); }/*from ww w .j a v a2s . c o m*/ return null; }
From source file:org.jbpm.bpel.integration.server.SoapHandler.java
protected ObjectMessage receiveResponse(Session jmsSession, Destination replyTo, String requestId, JbpmContext jbpmContext) throws JMSException, SOAPFaultException { // set up consumer String selector = "JMSCorrelationID='" + requestId + '\''; MessageConsumer consumer = jmsSession.createConsumer(replyTo, selector); try {// w w w .j ava2 s . c om // receive response message log.debug("listening for response: destination=" + replyTo + ", requestId=" + requestId); Number responseTimeout = getResponseTimeout(jbpmContext); ObjectMessage jmsResponse = (ObjectMessage) (responseTimeout != null ? consumer.receive(responseTimeout.longValue()) : consumer.receive()); // did a message arrive in time? if (jmsResponse == null) { log.debug("response timeout expired: destination=" + replyTo + ", requestId" + requestId); throw new SOAPFaultException(SoapBindConstants.SERVER_FAULTCODE, SoapBindConstants.TIMEOUT_FAULTSTRING, null, null); } jmsResponse.acknowledge(); log.debug("received response: " + RequestListener.messageToString(jmsResponse)); return jmsResponse; } finally { // release consumer resources consumer.close(); } }
From source file:org.jbpm.bpel.integration.server.SoapHandler.java
protected ObjectMessage sendRequest(SOAPMessage soapMessage, Session jmsSession, JbpmContext jbpmContext) throws SOAPException, JMSException { // create a jms message to deliver the incoming content ObjectMessage jmsRequest = jmsSession.createObjectMessage(); // put the partner link identified by handle in a jms property PartnerLinkEntry partnerLinkEntry = integrationControl.getPartnerLinkEntry(portTypeName, serviceName, portName);//from w w w . j a va2 s.c o m long partnerLinkId = partnerLinkEntry.getId(); jmsRequest.setLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP, partnerLinkId); Operation operation = determineOperation(soapMessage); if (operation == null) throw new SOAPException("could not determine operation to perform"); // put the operation name in a jms property String operationName = operation.getName(); jmsRequest.setStringProperty(IntegrationConstants.OPERATION_NAME_PROP, operationName); log.debug("received request: partnerLink=" + partnerLinkId + ", operation=" + operationName); // extract message content HashMap requestParts = new HashMap(); formatter.readMessage(operationName, soapMessage, requestParts, MessageDirection.INPUT); jmsRequest.setObject(requestParts); // fill message properties BpelProcessDefinition process = integrationControl.getDeploymentDescriptor() .findProcessDefinition(jbpmContext); MessageType requestType = process.getImportDefinition() .getMessageType(operation.getInput().getMessage().getQName()); fillCorrelationProperties(requestParts, jmsRequest, requestType.getPropertyAliases()); // set up producer MessageProducer producer = jmsSession.createProducer(partnerLinkEntry.getDestination()); try { // is the exchange pattern request/response? if (operation.getOutput() != null) { Destination replyTo = integrationControl.getIntegrationServiceFactory().getResponseDestination(); jmsRequest.setJMSReplyTo(replyTo); // have jms discard request message if response timeout expires Number responseTimeout = getResponseTimeout(jbpmContext); if (responseTimeout != null) producer.setTimeToLive(responseTimeout.longValue()); } else { // have jms discard message if one-way timeout expires Number oneWayTimeout = getOneWayTimeout(jbpmContext); if (oneWayTimeout != null) producer.setTimeToLive(oneWayTimeout.longValue()); } // send request message producer.send(jmsRequest); log.debug("sent request: " + RequestListener.messageToString(jmsRequest)); return jmsRequest; } finally { // release producer resources producer.close(); } }
From source file:com.scit.sling.test.MockValueMap.java
@SuppressWarnings("unchecked") private <T> T convertType(Object o, Class<T> type) { if (o == null) { return null; }/* w ww . j a va 2 s . c o m*/ if (o.getClass().isArray() && type.isArray()) { if (type.getComponentType().isAssignableFrom(o.getClass().getComponentType())) { return (T) o; } else { // we need to convert the elements in the array Object array = Array.newInstance(type.getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) { Array.set(array, i, convertType(Array.get(o, i), type.getComponentType())); } return (T) array; } } if (o.getClass().isAssignableFrom(type)) { return (T) o; } if (String.class.isAssignableFrom(type)) { // Format dates if (o instanceof Calendar) { return (T) formatDate((Calendar) o); } else if (o instanceof Date) { return (T) formatDate((Date) o); } else if (o instanceof DateTime) { return (T) formatDate((DateTime) o); } return (T) String.valueOf(o); } else if (o instanceof DateTime) { DateTime dt = (DateTime) o; if (Calendar.class.isAssignableFrom(type)) { return (T) dt.toCalendar(Locale.getDefault()); } else if (Date.class.isAssignableFrom(type)) { return (T) dt.toDate(); } else if (Number.class.isAssignableFrom(type)) { return convertType(dt.getMillis(), type); } } else if (o instanceof Number && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) (Byte) ((Number) o).byteValue(); } else if (Double.class.isAssignableFrom(type)) { return (T) (Double) ((Number) o).doubleValue(); } else if (Float.class.isAssignableFrom(type)) { return (T) (Float) ((Number) o).floatValue(); } else if (Integer.class.isAssignableFrom(type)) { return (T) (Integer) ((Number) o).intValue(); } else if (Long.class.isAssignableFrom(type)) { return (T) (Long) ((Number) o).longValue(); } else if (Short.class.isAssignableFrom(type)) { return (T) (Short) ((Number) o).shortValue(); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal(o.toString()); } } else if (o instanceof Number && type.isPrimitive()) { final Number num = (Number) o; if (type == byte.class) { return (T) new Byte(num.byteValue()); } else if (type == double.class) { return (T) new Double(num.doubleValue()); } else if (type == float.class) { return (T) new Float(num.floatValue()); } else if (type == int.class) { return (T) new Integer(num.intValue()); } else if (type == long.class) { return (T) new Long(num.longValue()); } else if (type == short.class) { return (T) new Short(num.shortValue()); } } else if (o instanceof String && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) new Byte((String) o); } else if (Double.class.isAssignableFrom(type)) { return (T) new Double((String) o); } else if (Float.class.isAssignableFrom(type)) { return (T) new Float((String) o); } else if (Integer.class.isAssignableFrom(type)) { return (T) new Integer((String) o); } else if (Long.class.isAssignableFrom(type)) { return (T) new Long((String) o); } else if (Short.class.isAssignableFrom(type)) { return (T) new Short((String) o); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal((String) o); } } throw new NotImplementedException( "Can't handle conversion from " + o.getClass().getName() + " to " + type.getName()); }
From source file:org.openconcerto.erp.core.reports.history.ui.HistoriqueClientBilanPanel.java
public synchronized void updateChequeData(final List<Integer> listId) { ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { @Override/*from w w w . j a v a 2s . c o m*/ public void run() { final SQLBase base = ((ComptaPropsConfiguration) ComptaPropsConfiguration.getInstance()) .getSQLBaseSociete(); final SQLTable table = base.getTable("CHEQUE_A_ENCAISSER"); long valueTotalTmp = 0; long valueNonEncaisseTmp = 0; if (listId != null && listId.size() > 0) { // Total final SQLSelect select = new SQLSelect(); select.addSelect(table.getField("MONTANT"), "SUM"); select.setWhere(new Where(table.getKey(), listId)); Number n = (Number) base.getDBSystemRoot().getDataSource().executeScalar(select.asString()); if (n != null) { valueTotalTmp = n.longValue(); } // Total non encaiss select.setWhere(new Where(table.getKey(), listId) .and(new Where(table.getField("ENCAISSE"), "=", Boolean.FALSE))); n = (Number) base.getDBSystemRoot().getDataSource().executeScalar(select.asString()); if (n != null) { valueNonEncaisseTmp = n.longValue(); } } setNbTotalCheques(listId == null ? 0 : listId.size()); setNbChequesNonEncaisses(valueNonEncaisseTmp); setTotalCheques(valueTotalTmp); updateLabels(); } }); }
From source file:com.sindicetech.siren.solr.facet.SirenFieldFacetExtractor.java
private void generateFacetsForCustomDatatypeLeaf(ObjectNode object, String fieldName, ExtendedJsonField sirenField, String path, List<SirenFacetEntry> facets) { Iterator<Entry<String, JsonNode>> iterator = object.getFields(); String datatype = null;/*from w w w . j a v a 2 s. c o m*/ String value = null; while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); if ("_datatype_".equals(entry.getKey())) { datatype = entry.getValue().asText(); } else if ("_value_".equals(entry.getKey())) { value = entry.getValue().asText(); } else { logger.warn("Unexpected field {} in custom datatype object: {}", entry.getKey(), object.asText()); continue; } } if (datatype == null || value == null) { logger.warn( "Unexpected form of custom datatype object: {}. Not generating facets for this nested object.", object.asText()); return; } SirenFacetEntry entry = new SirenFacetEntry(); entry.fieldName = fieldName; entry.path = path; Datatype customDatatype = sirenField.getDatatypes().get(datatype); if (customDatatype instanceof TrieDatatype) { NumericAnalyzer analyzer = (NumericAnalyzer) customDatatype.getAnalyzer(); NumericParser parser = analyzer.getNumericParser(); try { Number number = parser.parse(new StringReader(value)); if ((number instanceof Float) || (number instanceof Double)) { entry.datatype = FacetDatatype.DOUBLE; entry.value = number.doubleValue(); } else if ((number instanceof Integer) || (number instanceof Long)) { entry.datatype = FacetDatatype.LONG; entry.value = number.longValue(); } else { logger.warn( "Unknown number type {} in custom datatype in nested object {}. Not creating facet field.", number.getClass().getCanonicalName(), object.asText()); return; } } catch (IOException e) { logger.warn("Problem parsing custom datatype {} in nested object {}: " + e.getMessage(), datatype, object.asText()); return; } } else { entry.datatype = FacetDatatype.STRING; entry.value = value; } facets.add(entry); }
From source file:com.krawler.br.nodes.Activity.java
/** * converts the given object value to the given primitive type's wrapper class * if possible (if it is a <tt>Number</tt>) * * @param type the premitive type name, may be: * <ul>//from w ww . j a v a2 s .c o m * <li><tt>byte</tt> * <li><tt>char</tt> * <li><tt>short</tt> * <li><tt>int</tt> * <li><tt>long</tt> * <li><tt>float</tt> * <li><tt>double</tt> * </ul> * @param value the original value * @return the converted value */ private Object convert(String type, Object value) { Object val = value; if (value instanceof Number) { Number num = (Number) value; if (Byte.class.getCanonicalName().equals(type)) val = new Byte(num.byteValue()); else if (Character.class.getCanonicalName().equals(type)) val = new Character((char) num.intValue()); else if (Short.class.getCanonicalName().equals(type)) val = new Short(num.shortValue()); else if (Integer.class.getCanonicalName().equals(type)) val = new Integer(num.intValue()); else if (Long.class.getCanonicalName().equals(type)) val = new Long(num.longValue()); else if (Float.class.getCanonicalName().equals(type)) val = new Float(num.floatValue()); else if (Double.class.getCanonicalName().equals(type)) val = new Double(num.doubleValue()); } return val; }
From source file:org.openconcerto.erp.core.reports.history.ui.HistoriqueClientBilanPanel.java
public synchronized void updateVCData(final List<Integer> listId) { ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { @Override/*from www .j a v a 2s. co m*/ public void run() { final SQLBase base = ((ComptaPropsConfiguration) ComptaPropsConfiguration.getInstance()) .getSQLBaseSociete(); long valueTotal = 0; if (listId != null && listId.size() > 0) { final SQLSelect select = new SQLSelect(); final SQLTable table = base.getTable("SAISIE_VENTE_COMPTOIR"); select.addSelect(table.getField("MONTANT_HT"), "SUM"); select.setWhere(new Where(table.getKey(), listId)); final Number n = (Number) base.getDBSystemRoot().getDataSource() .executeScalar(select.asString()); if (n != null) { valueTotal = n.longValue(); } } setNbVentesComptoir(listId == null ? 0 : listId.size()); setTotalVentesComptoir(valueTotal); updateLabels(); } }); }
From source file:org.openconcerto.erp.core.reports.history.ui.HistoriqueClientBilanPanel.java
public synchronized void updateEcheance(final List<Integer> listId) { ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { @Override//from www . j a va 2 s . c om public void run() { long valueTotal = 0; if (listId != null && listId.size() > 0) { final SQLBase base = ((ComptaPropsConfiguration) ComptaPropsConfiguration.getInstance()) .getSQLBaseSociete(); final SQLSelect select = new SQLSelect(); final SQLTable table = base.getTable("ECHEANCE_CLIENT"); select.addSelect(table.getField("MONTANT"), "SUM"); select.setWhere(new Where(table.getKey(), listId)); final Number n = (Number) base.getDBSystemRoot().getDataSource() .executeScalar(select.asString()); if (n != null) { valueTotal = n.longValue(); } } setNbFacturesImpayees(listId == null ? 0 : listId.size()); setTotalFacturesImpayees(valueTotal); updateLabels(); } }); }