List of usage examples for java.lang Long valueOf
@HotSpotIntrinsicCandidate public static Long valueOf(long l)
From source file:core.controller.DepartemenController.java
@RequestMapping(value = "/delete", method = RequestMethod.GET) public String delete(HttpServletRequest request) { long id = Long.valueOf(request.getParameter("id")); departemenDAO.delete(id);/*from ww w . j av a 2 s. c o m*/ return "redirect:/departemen"; }
From source file:Main.java
/** * convert value to given type.// w w w. j av 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:de.jfachwert.bank.Kontonummer.java
/** * Hierueber wird eine neue Kontonummer angelegt. * * @param nr eine maximal 10-stellige Zahl */ public Kontonummer(String nr) { this(Long.valueOf(verify(nr))); }
From source file:com.nominanuda.hyperapi.JsonAnyValueDecoder.java
@Override protected Object decodeInternal(AnnotatedType p, HttpEntity entity) throws IOException { String s = IO.readAndCloseUtf8(entity.getContent()); if ("null".equals(s)) { return null; } else if ("true".equals(s) || "false".equals(s)) { return Boolean.valueOf(s); } else if (Maths.isNumber(s)) { if (Maths.isInteger(s)) { return Long.valueOf(s); } else {/*from ww w . ja va 2 s . c o m*/ return Double.valueOf(s); } } else if (s.startsWith("\"") && s.length() > 1) { return STRUCT.jsonStringUnescape(s.substring(1, s.length() - 1)); } else { DataStruct ds = STRUCT.parse(new StringReader(s)); return ds; } }
From source file:ext.sns.auth.AccessTokenResponse.java
/** * ?AccessTokenResponse??responseStringnull * // ww w . j ava2 s . co m * @param responseString * @param responseType * @return AccessTokenResponsenull - ??responseString */ public static AccessTokenResponse create(String responseString) { if (StringUtils.isBlank(responseString)) { return null; } AccessTokenResponse response = new AccessTokenResponse(); response.setResultTypeByResponseStr(responseString); if (response.resultType == 1) { Map<String, String> responseMap = null; try { responseMap = parseResponseParam(responseString); } catch (RuntimeException e) { LOGGER.error("AccessTokenResponse?", e); } response.raw = responseString; response.accessToken = responseMap.get("access_token"); String expiresInString = responseMap.get("expires_in"); response.expiresIn = StringUtils.isNumeric(expiresInString) ? Long.valueOf(expiresInString) : null; response.refreshToken = responseMap.get("refresh_token"); response.scope = responseMap.get("scope"); response.tokenType = responseMap.get("token_type"); response.resultObject = responseMap; } else if (response.resultType == 2) { JsonNode responseJSON = null; try { responseJSON = Json.parse(responseString); } catch (RuntimeException e) { LOGGER.error("AccessTokenResponse?", e); } response.raw = responseString; response.accessToken = responseJSON.has("access_token") ? responseJSON.get("access_token").asText() : null; String expiresInString = responseJSON.has("expires_in") ? responseJSON.get("expires_in").asText() : null; response.expiresIn = StringUtils.isNumeric(expiresInString) ? Long.valueOf(expiresInString) : null; response.refreshToken = responseJSON.has("refresh_token") ? responseJSON.get("refresh_token").asText() : null; response.scope = responseJSON.has("scope") ? responseJSON.get("scope").asText() : null; response.tokenType = responseJSON.has("token_type") ? responseJSON.get("token_type").asText() : null; response.resultObject = responseJSON; } else { return null; } return response; }
From source file:org.kee.ssf.service.module.ModuleService.java
public Module save(Module module) { Module pModule = moduleDao.findOne(Long.valueOf(module.getPid())); module.setFullCode(pModule.getFullCode() + ":" + module.getCode()); return moduleDao.save(module); }
From source file:boa.aggregators.StDevAggregator.java
/** {@inheritDoc} */ @Override// ww w . j a va 2 s . co m public void aggregate(final String data, final String metadata) throws IOException, InterruptedException { for (final String s : data.split(";")) { final int idx = s.indexOf(":"); if (idx > 0) { final long count = Long.valueOf(s.substring(idx + 1)); for (int i = 0; i < count; i++) aggregate(Long.valueOf(s.substring(0, idx)), metadata); } else aggregate(Long.valueOf(s), metadata); } }
From source file:com.epam.ipodromproject.service.MainService.java
@Transactional public boolean makeBet(User user, Competition competitionToBet, String money, BetType betType, String horseID) { if ((!userService.canMakeBet(user.getUsername(), money, competitionToBet)) || (!horseService.existsHorseInCompetition(competitionToBet, horseID))) { return false; }//from w w w . ja v a 2 s.c om Date now = new Date(); Horse horse = horseService.getHorseByID(Long.valueOf(horseID)); double moneyToBet = Double.parseDouble(money); if ((CompetitionState.NOT_REGISTERED.equals(competitionToBet.getState())) && (now.compareTo(competitionToBet.getDateOfStart()) <= 0)) { Double coefficient = returnCoefficientDueToBetType( competitionToBet.getHorses().get(horse).getCoefficient(), betType); Bet betInfo = new Bet(moneyToBet, new Date(), betType, horse, user.getPerson(), competitionToBet, coefficient); betService.update(betInfo); userService.makeBet(user, moneyToBet); return true; } else { return false; } }
From source file:gov.nih.nci.caintegrator.common.DateUtil.java
private static String formatDate(String dateString) throws ParseException { String[] dateElements = (dateString.contains("-")) ? dateString.split("-", 3) : dateString.split("/", 3); if (dateElements.length != 3) { throw new ParseException("Invalid date string: " + dateString, 0); }/*from w ww . j a v a2 s .co m*/ return twoDigit.format(Long.valueOf(dateElements[0])) + "/" + twoDigit.format(Long.valueOf(dateElements[1])) + "/" + dateElements[2]; }
From source file:com.alibaba.otter.shared.arbitrate.model.RemedyIndexEventData.java
public static RemedyIndexEventData parseNodeName(String node) { String[] datas = StringUtils.split(node, SPLIT); if (datas.length != 3) { throw new ArbitrateException("remedy index[" + node + "] format is not correctly!"); }/* ww w .j a va2 s. co m*/ RemedyIndexEventData eventData = new RemedyIndexEventData(); eventData.setProcessId(Long.valueOf(datas[0])); eventData.setStartTime(Long.valueOf(datas[1])); eventData.setEndTime(Long.valueOf(datas[2])); return eventData; }