List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:com.mobileman.projecth.web.util.NumUtils.java
public static Long convert2long(String str) { try {/*from w ww . j a v a 2 s . c om*/ if (StringUtils.isNotBlank(str)) { return Long.parseLong(str); } } catch (Exception ex) { } return null; }
From source file:Main.java
public static void setField(Object object, String fieldName, Object fieldValue) { Class<?> objectClass = object.getClass(); if (objectClass != null) { try {//from w w w.j a va2 s.co m Field field = objectClass.getDeclaredField(fieldName); field.setAccessible(true); Type type = field.getGenericType(); //This is bad, but dear God I can't figure out how to convert a runtime Type to its actual type through reflection. I know how in C#.... if (type.toString().toLowerCase().contains("short")) { fieldValue = Short.parseShort((String) fieldValue); } else if (type.toString().toLowerCase().contains("integer")) { fieldValue = Integer.parseInt((String) fieldValue); } else if (type.toString().toLowerCase().contains("long")) { fieldValue = Long.parseLong((String) fieldValue); } else if (type.toString().toLowerCase().contains("boolean")) { fieldValue = "1".equals(fieldValue); //Java, you're the worst language. And SQLite isn't helping. } field.set(object, fieldValue); } catch (NoSuchFieldException e) { return; } catch (Exception e) { throw new IllegalStateException(e); } } }
From source file:jp.primecloud.auto.tool.management.iaasgw.IaasGatewayScriptFactory.java
public static IaasGatewayScriptService createIaasGatewayScriptService(CommandLine commandLine) { Long platformNo = Long.parseLong(commandLine.getOptionValue("platformno")); Long userNo = Long.parseLong(commandLine.getOptionValue("userno")); return new IaasGatewayScriptService(userNo, platformNo); }
From source file:Main.java
/** * Gets the long value of an attribute in given XML * /*from w w w .ja v a 2 s .c om*/ * @see #getAttribute(String, String, String) * @param inputXml Source XML * @param tag Tag name * @param attribute Attribute name * @return Value of the attribute parsed as long */ public static long getLongAttribute(final String inputXml, final String tag, final String attribute) { return Long.parseLong(getAttribute(inputXml, tag, attribute)); }
From source file:Main.java
private static void setterValue(PropertyDescriptor property, Object mapValue, Object object) throws InvocationTargetException, IllegalAccessException, ParseException { Method setter = property.getWriteMethod(); if (mapValue == null) { setter.invoke(object, mapValue); return;//from w w w . j av a 2 s.c om } Class propertyType = property.getPropertyType(); String type = propertyType.getName(); String value = mapValue.toString(); if (type.equals("java.lang.String")) { setter.invoke(object, value); } else if (type.equals("java.lang.Integer")) { setter.invoke(object, Integer.parseInt(value)); } else if (type.equals("java.lang.Long")) { setter.invoke(object, Long.parseLong(value)); } else if (type.equals("java.math.BigDecimal")) { setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value))); } else if (type.equals("java.math.BigInteger")) { setter.invoke(object, BigInteger.valueOf(Long.parseLong(value))); } else if (type.equals("java.util.Date")) { setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); } else if (type.equals("java.lang.Boolean")) { setter.invoke(object, Boolean.valueOf(value)); } else if (type.equals("java.lang.Float")) { setter.invoke(object, Float.parseFloat(value)); } else if (type.equals("java.lang.Double")) { setter.invoke(object, Double.parseDouble(value)); } else if (type.equals("java.lang.byte[]")) { setter.invoke(object, value.getBytes()); } else { setter.invoke(object, value); } }
From source file:Main.java
public static HashMap<String, String> tran2Hash(String info) { HashMap<String, String> temp = new HashMap<String, String>(); String username = info.substring(0, info.indexOf(",")); info = info.substring(info.indexOf(",") + 1); String nickname = info.substring(0, info.indexOf(",")); info = info.substring(info.indexOf(",") + 1); String head = info.substring(0, info.indexOf(",")); info = info.substring(info.indexOf(",") + 1); String fanssum = info.substring(0, info.indexOf(",")); info = info.substring(info.indexOf(",") + 1); String verifytype = info.substring(0, info.indexOf(",")); info = info.substring(info.indexOf(",") + 1); String reposttime = info.substring(0, info.indexOf("=")); String repostercount = info.substring(info.indexOf("=") + 1); reposttime = getTime(Long.parseLong(reposttime)); temp.put("username", username); temp.put("nickname", nickname); temp.put("head", head); temp.put("fanssum", fanssum); temp.put("verifytype", verifytype); temp.put("reposttime", reposttime); temp.put("repostercount", repostercount); return temp;//w w w. j a v a 2s . co m }
From source file:Main.java
public static long[] getLongArrayfromString(final String string, final char token) { if (string == null) return new long[0]; final String[] items_string_array = string.split(String.valueOf(token)); final ArrayList<Long> items_list = new ArrayList<Long>(); for (final String id_string : items_string_array) { try {//from w w w. j a v a2 s .c o m items_list.add(Long.parseLong(id_string)); } catch (final NumberFormatException e) { // Ignore. } } final int list_size = items_list.size(); final long[] array = new long[list_size]; for (int i = 0; i < list_size; i++) { array[i] = items_list.get(i); } return array; }
From source file:com.intel.cosbench.client.amplistor.AmpliUtils.java
public static AmpliPolicy policyFromResponse(HttpResponse response) { AmpliPolicy newPolicy = new AmpliPolicy(); newPolicy.id = unquotedString(response.getFirstHeader(AmpliPolicy.ID).getValue()); newPolicy.spread_Width = Long.parseLong(response.getFirstHeader(AmpliPolicy.SPREAD_WIDTH).getValue()); newPolicy.safety = Long.parseLong(response.getFirstHeader(AmpliPolicy.SAFETY).getValue()); newPolicy.hierarchy_Rules = unfold(response.getFirstHeader(AmpliPolicy.HIERARYCHY_RULES).getValue()) .toArray();//from w w w . j ava 2 s. c o m newPolicy.max_Superblock_Size = Long .parseLong(response.getFirstHeader(AmpliPolicy.MAX_SUPERBLOCK_SIZE).getValue()); newPolicy.safety_Strategy = unfold(response.getFirstHeader(AmpliPolicy.SAFETY_STRATEGY).getValue()) .toArray(); newPolicy.n_Messages = Long.parseLong(response.getFirstHeader(AmpliPolicy.N_MESSAGES).getValue()); return newPolicy; }
From source file:Main.java
public static long getVideoAssetDurationMilliSec(Context context, Uri uri) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(context, uri); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); return Long.parseLong(time); }
From source file:Util.java
/** Parse comma-separated list of longs and return as array. */ public static long[] splitLongs(String str) throws IllegalArgumentException { StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); long[] list = new long[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Long.parseLong(token); }//from w ww. j a v a 2 s . c om return list; }