List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:org.patientview.radar.dao.impl.UserDaoImpl.java
public void savePatientUser(final PatientUser patientUser) throws UserCreationException { // save details of the user into the radar tables try {// w w w. j a v a 2 s . c o m Map<String, Object> patientUserMap = new HashMap<String, Object>() { { put(PATIENT_USER_ID_FIELD_NAME, patientUser.getId()); put(PATIENT_USER_RADAR_NO_FIELD_NAME, patientUser.getRadarNumber()); put(PATIENT_USER_DOB_FIELD_NAME, patientUser.getDateOfBirth()); put(PATIENT_USER_DATE_OF_REGISTRATION_FIELD_NAME, patientUser.getDateRegistered()); } }; if (patientUser.hasValidId()) { String updateSql = buildUpdateQuery(PATIENT_USER_TABLE_NAME, PATIENT_USER_ID_FIELD_NAME, patientUserMap); namedParameterJdbcTemplate.update(updateSql, patientUserMap); } else { Number id = patientUsersInsert.executeAndReturnKey(patientUserMap); patientUser.setId(id.longValue()); } } catch (Exception e) { LOGGER.error("There has been an exception creating the radar user"); throw new UserCreationException("Error creating the radar user", e); } }
From source file:org.squale.squaleweb.util.graph.AuditsSizeMaker.java
/** * Effectue les pr-traitements ncessaires l'affichage 1)efface les doublons en ne rcuprant que le maximum 2) * tri par ordre chronologique//from www.ja va 2 s.co m * * @param pValues le tableau des valeurs * @return la list tri sans doublons avec la valeur maximum (sous forme d'un tableau d'objets 2 cases, la * premire la date (String) la deuxime la taille max du FS sur les audits de la journe). */ private List getSortedList(List pValues) { List result = new ArrayList(0); for (int i = 0; i < pValues.size(); i++) { Object[] combo = (Object[]) pValues.get(i); String date = (String) combo[0]; Number size = (Number) combo[1]; int j; for (j = 0; j < result.size(); j++) { // on est sur la meme journe, on prend le maximum if (((String) ((Object[]) result.get(j))[0]).equals(date)) { Long currentStoredSize = (Long) ((Object[]) result.get(j))[1]; // Si la valeur actuellement stocke est null, on insre de toute facon la nouvelle // Si la nouvelle est null, a ne change rien sinon on insre une bonne valeur if (currentStoredSize == null) { ((Object[]) result.get(j))[1] = size; } else { // La valeur actuelle n'est pas null, on doit grer l'ajout ventuel if (size != null) { // 2 valeurs, on prend le maximum ((Object[]) result.get(j))[1] = new Long( Math.max(currentStoredSize.longValue(), size.longValue())); } // sinon on garde la valeur actuellement stocke } // coupe la boucle j = result.size() + 1; } } // on ne l'a pas trouve, nouvelle valeur on insre le tableau tel quel if (j == result.size()) { result.add(combo); } } return result; }
From source file:com.evolveum.midpoint.repo.sql.helpers.ObjectRetriever.java
public boolean isAnySubordinateAttempt(String upperOrgOid, Collection<String> lowerObjectOids) { Session session = null;/*www . ja v a2s.com*/ try { session = baseHelper.beginReadOnlyTransaction(); Query query; if (lowerObjectOids.size() == 1) { query = session.getNamedQuery("isAnySubordinateAttempt.oneLowerOid"); query.setParameter("dOid", lowerObjectOids.iterator().next()); } else { query = session.getNamedQuery("isAnySubordinateAttempt.moreLowerOids"); query.setParameterList("dOids", lowerObjectOids); } query.setParameter("aOid", upperOrgOid); Number number = (Number) query.uniqueResult(); session.getTransaction().commit(); return number != null && number.longValue() != 0L; } catch (RuntimeException ex) { baseHelper.handleGeneralException(ex, session, null); } finally { baseHelper.cleanupSessionAndResult(session, null); } throw new SystemException("isAnySubordinateAttempt failed somehow, this really should not happen."); }
From source file:org.patientview.radar.dao.impl.UserDaoImpl.java
public void saveProfessionalUser(final ProfessionalUser professionalUser) throws Exception { // save details of the user into the radar tables Map<String, Object> professionalUserMap = new HashMap<String, Object>() { {// ww w.j a v a 2s .c o m put(PROFESSIONAL_USER_SURNAME_FIELD_NAME, professionalUser.getSurname()); put(PROFESSIONAL_USER_FORENAME_FIELD_NAME, professionalUser.getForename()); put(PROFESSIONAL_USER_TITLE_FIELD_NAME, professionalUser.getTitle()); put(PROFESSIONAL_USER_GMC_FIELD_NAME, professionalUser.getGmc()); put(PROFESSIONAL_USER_CENTRE_ROLE_FIELD_NAME, professionalUser.getRole()); put(PROFESSIONAL_USER_PHONE_FIELD_NAME, professionalUser.getPhone()); put(PROFESSIONAL_USER_CENTRE_ID_FIELD_NAME, professionalUser.getCentre().getId()); put(PROFESSIONAL_USER_DATE_JOINED_FIELD_NAME, professionalUser.getDateRegistered()); put(PROFESSIONAL_USER_ID_FIELD_NAME, professionalUser.getId()); } }; if (professionalUser.hasValidId()) { String updateSql = buildUpdateQuery(PROFESSIONAL_USER_TABLE_NAME, PROFESSIONAL_USER_ID_FIELD_NAME, professionalUserMap); namedParameterJdbcTemplate.update(updateSql, professionalUserMap); } else { Number id = professionalUsersInsert.executeAndReturnKey(professionalUserMap); professionalUser.setId(id.longValue()); } // save main user login into the shared rpv table saveUser(professionalUser); // create a mapping and role so they can login to PV // make sure we have all the centre data as sometimes it just the id set Centre centre = utilityDao.getCentre(professionalUser.getCentre().getId()); createUserMappingAndRoleInPatientView(professionalUser.getUserId(), professionalUser.getUsername(), null, centre.getUnitCode(), "unitadmin"); }
From source file:org.hyperic.hq.measurement.server.session.MeasurementDAO.java
/** * @see MeasurementManagerImpl#findNumMetricsPerAgent() */// ww w . j a va 2 s. co m @SuppressWarnings("unchecked") Map<Agent, Long> findNumMetricsPerAgent() { String platSQL = "select a.id, count(m) from Agent a " + "join a.platforms p, " + "Measurement as m " + "join m.template templ " + "join templ.monitorableType monType " + "where " + " monType.appdefType = '1' and m.instanceId = p.id " + "and m.enabled = true " + "group by a"; String serverSQL = "select a.id, count(m) from Agent a " + "join a.platforms p " + "join p.serversBag s, " + "Measurement as m " + "join m.template templ " + "join templ.monitorableType monType " + "where " + " monType.appdefType = '2' and m.instanceId = s.id " + "and m.enabled = true " + "group by a"; String serviceSQL = "select a.id, count(m) from Agent a " + "join a.platforms p " + "join p.serversBag s " + "join s.services v, " + "Measurement as m " + "join m.template templ " + "join templ.monitorableType monType " + "where " + " monType.appdefType = '3' and m.instanceId = v.id " + "and m.enabled = true " + "group by a"; String[] queries = { platSQL, serverSQL, serviceSQL }; Map<Integer, Long> idToCount = new HashMap<Integer, Long>(); for (int i = 0; i < queries.length; i++) { List<Object[]> tuples = getSession().createQuery(queries[i]).list(); for (Object[] tuple : tuples) { Integer id = (Integer) tuple[0]; java.lang.Number count = (java.lang.Number) tuple[1]; Long curCount; curCount = idToCount.get(id); if (curCount == null) { curCount = new Long(0); } curCount = new Long(curCount.longValue() + count.longValue()); idToCount.put(id, curCount); } } Map<Agent, Long> res = new HashMap<Agent, Long>(idToCount.size()); for (Map.Entry<Integer, Long> ent : idToCount.entrySet()) { Integer id = ent.getKey(); Long count = ent.getValue(); res.put(agentDao.findById(id), count); } return res; }
From source file:LongRange.java
/** * <p>Constructs a new <code>LongRange</code> with the specified * minimum and maximum numbers (both inclusive).</p> * // w ww. ja va 2s . com * <p>The arguments may be passed in the order (min,max) or (max,min). The * getMinimum and getMaximum methods will return the correct values.</p> * * @param number1 first number that defines the edge of the range, inclusive * @param number2 second number that defines the edge of the range, inclusive * @throws IllegalArgumentException if either number is <code>null</code> */ public LongRange(Number number1, Number number2) { super(); if (number1 == null || number2 == null) { throw new IllegalArgumentException("The numbers must not be null"); } long number1val = number1.longValue(); long number2val = number2.longValue(); if (number2val < number1val) { this.min = number2val; this.max = number1val; if (number2 instanceof Long) { this.minObject = (Long) number2; } if (number1 instanceof Long) { this.maxObject = (Long) number1; } } else { this.min = number1val; this.max = number2val; if (number1 instanceof Long) { this.minObject = (Long) number1; } if (number2 instanceof Long) { this.maxObject = (Long) number2; } } }
From source file:com.mastfrog.netty.http.client.CookieStore.java
@SuppressWarnings("unchecked") public void read(InputStream in) throws IOException { ObjectMapper om = new ObjectMapper(); List<Map<String, Object>> l = om.readValue(in, List.class); List<DateCookie> cks = new ArrayList<>(); for (Map<String, Object> m : l) { String domain = (String) m.get("domain"); Number maxAge = (Number) m.get("maxAge"); Number timestamp = (Number) m.get("timestamp"); String path = (String) m.get("path"); String name = (String) m.get("name"); String value = (String) m.get("value"); Boolean httpOnly = (Boolean) m.get("httpOnly"); Boolean secure = (Boolean) m.get("secure"); String comment = (String) m.get("comment"); String commentUrl = (String) m.get("commentUrl"); List<Integer> ports = (List<Integer>) m.get("ports"); DateTime ts = timestamp == null ? DateTime.now() : new DateTime(timestamp.longValue()); DateCookie cookie = new DateCookie(new DefaultCookie(name, value), ts); if (cookie.isExpired()) { continue; }// ww w. j a v a 2 s .co m if (domain != null) { cookie.setDomain(domain); } if (maxAge != null) { cookie.setMaxAge(maxAge.longValue()); } if (path != null) { cookie.setPath(path); } if (httpOnly != null) { cookie.setHttpOnly(httpOnly); } if (secure != null) { cookie.setSecure(secure); } if (comment != null) { cookie.setComment(comment); } if (commentUrl != null) { cookie.setCommentUrl(commentUrl); } if (ports != null) { cookie.setPorts(ports); } cks.add(cookie); } if (!cks.isEmpty()) { Lock writeLock = lock.writeLock(); try { writeLock.lock(); cookies.addAll(cks); } finally { writeLock.unlock(); } } }
From source file:weave.servlets.WeaveServlet.java
/** * Tries to convert value to the given type. * @param value The value to cast to a new type. * @param type The desired type./*w w w . ja va 2s .c o m*/ * @return The value, which may have been cast as the new type. */ protected Object cast(Object value, Class<?> type) throws RemoteException { if (type.isInstance(value)) return value; try { if (value == null) // null -> NaN { if (type == double.class || type == Double.class) value = Double.NaN; else if (type == float.class || type == Float.class) value = Float.NaN; return value; } if (value instanceof Map) // Map -> Java Bean { Object bean = type.newInstance(); for (Field field : type.getFields()) { Object fieldValue = ((Map<?, ?>) value).get(field.getName()); fieldValue = cast(fieldValue, field.getType()); field.set(bean, fieldValue); } return bean; } if (type.isArray()) // ? -> T[] { if (value instanceof String) // String -> String[] value = CSVParser.defaultParser.parseCSVRow((String) value, true); if (value instanceof List) // List -> Object[] value = ((List<?>) value).toArray(); if (value.getClass().isArray()) // T1[] -> T2[] { int n = Array.getLength(value); Class<?> itemType = type.getComponentType(); Object output = Array.newInstance(itemType, n); while (n-- > 0) Array.set(output, n, cast(Array.get(value, n), itemType)); return output; } } if (Collection.class.isAssignableFrom(type)) // ? -> <? extends Collection> { value = cast(value, Object[].class); // ? -> Object[] if (value.getClass().isArray()) // T1[] -> Vector<T2> { int n = Array.getLength(value); List<Object> output = new Vector<Object>(n); TypeVariable<?>[] itemTypes = type.getTypeParameters(); Class<?> itemType = itemTypes.length > 0 ? itemTypes[0].getClass() : null; while (n-- > 0) { Object item = Array.get(value, n); if (itemType != null) item = cast(item, itemType); // T1 -> T2 output.set(n, item); } return output; } } if (value instanceof String) // String -> ? { String string = (String) value; // String -> primitive if (type == char.class || type == Character.class) return string.charAt(0); if (type == byte.class || type == Byte.class) return Byte.parseByte(string); if (type == long.class || type == Long.class) return Long.parseLong(string); if (type == int.class || type == Integer.class) return Integer.parseInt(string); if (type == short.class || type == Short.class) return Short.parseShort(string); if (type == float.class || type == Float.class) return Float.parseFloat(string); if (type == double.class || type == Double.class) return Double.parseDouble(string); if (type == boolean.class || type == Boolean.class) return string.equalsIgnoreCase("true"); if (type == InputStream.class) // String -> InputStream { try { return new ByteArrayInputStream(string.getBytes("UTF-8")); } catch (Exception e) { return null; } } } if (value instanceof Number) // Number -> primitive { Number number = (Number) value; if (type == byte.class || type == Byte.class) return number.byteValue(); if (type == long.class || type == Long.class) return number.longValue(); if (type == int.class || type == Integer.class) return number.intValue(); if (type == short.class || type == Short.class) return number.shortValue(); if (type == float.class || type == Float.class) return number.floatValue(); if (type == double.class || type == Double.class) return number.doubleValue(); if (type == char.class || type == Character.class) return Character.toChars(number.intValue())[0]; if (type == boolean.class || type == Boolean.class) return !Double.isNaN(number.doubleValue()) && number.intValue() != 0; } } catch (Exception e) { throw new RemoteException(String.format("Unable to cast %s to %s", value.getClass().getSimpleName(), type.getSimpleName()), e); } // Return original value if not handled above. // Primitives and their Object equivalents will cast automatically. return value; }
From source file:com.redhat.rhn.frontend.xmlrpc.activationkey.ActivationKeyHandler.java
/** * Add server groups to an activation key. * * @param loggedInUser The current user/* w ww . j a va 2 s .com*/ * @param key The activation key to act upon. * @param serverGroupIds List of server group IDs to be added to this activation key. * @return 1 on success, exception thrown otherwise. * * @xmlrpc.doc Add server groups to an activation key. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param("string", "key") * @xmlrpc.param #array_single("int", "serverGroupId") * @xmlrpc.returntype #return_int_success() */ public int addServerGroups(User loggedInUser, String key, List serverGroupIds) { ActivationKeyManager manager = ActivationKeyManager.getInstance(); ActivationKey activationKey = lookupKey(key, loggedInUser); for (Iterator it = serverGroupIds.iterator(); it.hasNext();) { Number serverGroupId = (Number) it.next(); ManagedServerGroup group = null; try { group = ServerGroupManager.getInstance().lookup(new Long(serverGroupId.longValue()), loggedInUser); } catch (LookupException e) { throw new InvalidServerGroupException(e); } manager.addServerGroup(activationKey, group); } return 1; }
From source file:org.jasig.ssp.service.impl.EvaluatedSuccessIndicatorServiceImpl.java
private Pair<Object, String> findOpenAlertsMetric(@Nonnull SuccessIndicator successIndicator, @Nonnull Person person) {/*from w ww. j av a2 s . c o m*/ // Would obviously need to change if we have more states in the future, but for now this is the most efficient // solution. final Number activeRaw = person.getActiveAlertsCount(); final Number closedRaw = person.getClosedAlertsCount(); // No conceptual difference between 'no data' and 0's here. final long active = activeRaw == null ? 0L : activeRaw.longValue(); final long closed = closedRaw == null ? 0L : closedRaw.longValue(); final long total = active + closed; final String display = new StringBuilder().append(active).append("/").append(total).toString(); return new Pair<Object, String>(active, display); }