List of usage examples for java.lang Long valueOf
@HotSpotIntrinsicCandidate public static Long valueOf(long l)
From source file:Main.java
/** * Gets the attribute value as long from node. * /*from w w w.j a v a 2s. c om*/ * @param node the node * @param attributeName the attribute name * * @return the attribute value as long from node */ public static Long getAttributeValueAsLongFromNode(XmlPullParser node, String attributeName) { String attribute = node.getAttributeValue(null, attributeName); if (isNullOrEmpty(attribute)) { return null; } else { return Long.valueOf(attribute); } }
From source file:PrimitiveUtils.java
public static Object read(String value, Class type) { Object ret = value;/*from w w w . j av a 2 s. c om*/ if (Integer.TYPE.equals(type)) { ret = Integer.valueOf(value); } if (Byte.TYPE.equals(type)) { ret = Byte.valueOf(value); } if (Short.TYPE.equals(type)) { ret = Short.valueOf(value); } if (Long.TYPE.equals(type)) { ret = Long.valueOf(value); } if (Float.TYPE.equals(type)) { ret = Float.valueOf(value); } if (Double.TYPE.equals(type)) { ret = Double.valueOf(value); } if (Boolean.TYPE.equals(type)) { ret = Boolean.valueOf(value); } if (Character.TYPE.equals(type)) { ret = value.charAt(0); } // TODO others. return ret; }
From source file:Main.java
/** * Gets the element value as long from node. * /*from w ww . ja v a 2 s.c o m*/ * @param node the node * @param valueName the value name * * @return the element value as long from node * @throws XmlPullParserException */ public static Long getElementValueAsLongFromNode(XmlPullParser node) throws IOException, XmlPullParserException { String value = node.nextText(); if (isNullOrEmpty(value)) { return null; } else { return Long.valueOf(value); } }
From source file:Main.java
public static ArrayList<long[]> getRanking(Activity activity, String mode2, long newRecord, long currentTime) { ArrayList<long[]> rankList = new ArrayList<long[]>(); String rankRecord = getStoredVar(activity, "ranking_" + mode2); if (rankRecord.equals("") == false) { String[] records = rankRecord.split(","); boolean inserted = false; for (int i = 0; i < records.length; i += 2) { if (inserted == false && (Long.valueOf(records[i]) / 1000) > (newRecord / 1000)) { long[] l = { newRecord, currentTime, 1 }; rankList.add(l);/* w w w . jav a2 s. c om*/ long[] l2 = { Long.valueOf(records[i]), Long.valueOf(records[i + 1]), 0 }; rankList.add(l2); inserted = true; } else { long[] l = { Long.valueOf(records[i]), Long.valueOf(records[i + 1]), 0 }; rankList.add(l); } if (rankList.size() == 5) { break; } } if (inserted == false && rankList.size() < 5) { long[] l = { newRecord, currentTime, 1 }; rankList.add(l); } } else { long[] l = { newRecord, currentTime, 1 }; rankList.add(l); } String newRank = ""; for (int i = 0; i < rankList.size(); i++) { if (newRank.equals("") == false) { newRank += ","; } newRank += (new Long(rankList.get(i)[0])).toString() + "," + (new Long(rankList.get(i)[1])).toString(); } if (newRank.equals("") == false) { setStoredVar(activity, "ranking_" + mode2, newRank); } return rankList; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T getJsonObjectValue(JSONObject jsonObject, String key, Class<T> clazz) { T t = null;/* w ww . jav a 2 s. com*/ try { if (clazz == Integer.class) { t = (T) Integer.valueOf(jsonObject.getInt(key)); } else if (clazz == Boolean.class) { t = (T) Boolean.valueOf(jsonObject.getBoolean(key)); } else if (clazz == String.class) { t = (T) String.valueOf(jsonObject.getString(key)); } else if (clazz == Double.class) { t = (T) Double.valueOf(jsonObject.getDouble(key)); } else if (clazz == JSONObject.class) { t = (T) jsonObject.getJSONObject(key); } else if (clazz == JSONArray.class) { t = (T) jsonObject.getJSONArray(key); } else if (clazz == Long.class) { t = (T) Long.valueOf(jsonObject.getLong(key)); } } catch (JSONException e) { e.printStackTrace(); } return t; }
From source file:Main.java
public static String getPhotoPathFromContentUri(Context context, Uri uri) { String photoPath = ""; if (context == null || uri == null) { return photoPath; }//from w w w . j av a 2 s.com if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { String docId = DocumentsContract.getDocumentId(uri); if (isExternalStorageDocument(uri)) { String[] split = docId.split(":"); if (split.length >= 2) { String type = split[0]; if ("primary".equalsIgnoreCase(type)) { photoPath = Environment.getExternalStorageDirectory() + "/" + split[1]; } } } else if (isDownloadsDocument(uri)) { Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); photoPath = getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(uri)) { String[] split = docId.split(":"); if (split.length >= 2) { String type = split[0]; Uri contentUris = null; if ("image".equals(type)) { contentUris = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUris = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUris = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; photoPath = getDataColumn(context, contentUris, selection, selectionArgs); } } } else if ("file".equalsIgnoreCase(uri.getScheme())) { photoPath = uri.getPath(); } else { photoPath = getDataColumn(context, uri, null, null); } return photoPath; }
From source file:com.codestudio.dorm.web.util.PartyAuthUtil.java
/** * ???null/*from ww w . j ava 2 s . com*/ * * @param request * @param response * @return */ public static Party getPartyInfo(HttpServletRequest request, HttpServletResponse response) { Party party = null; UserCookieManager userCookieManager = new UserCookieManager(request, response, null, "/"); String partyId = userCookieManager.getTempCookie(UserCookieManager.PARTY_ID, null); if (StringUtils.isNotBlank(partyId)) { party = new Party(); party.setId(Long.valueOf(partyId)); party.setPartyNum(userCookieManager.getTempCookie(UserCookieManager.PARTY_NUM, null)); } return party; }
From source file:Main.java
public static String getAbsolutePath(final Context context, final Uri uri) { // DocumentProvider if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }//w w w. j a va 2s . com } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:Main.java
@TargetApi(19) public static String getImageAbsolutePath(Context context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from w w w. j a v a2 s . c o m*/ } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static String handleKitKatVersion(final Context context, final Uri uri) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String[] split = getMediaData(uri); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from ww w . j a v a 2s . c o m*/ // TODO handle non-primary volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String[] split = getMediaData(uri); final String type = split[0]; Uri contentUri = getContentUri(type); final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } return null; }