Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- v 1.0
- private static String toStringOrNull(Object o) {
- if(o instanceof String)
- return (!"".equals(o) && o != null) ? (String)o : "";
- else if(o instanceof Date)
- return (o != null) ? new SimpleDateFormat("dd-MM-yyyy").format(o) : "";
- else
- return ( o != null)? o.toString() : "";
- }
- V 2.10
- private static String toStringOrNull(Object o) {
- return (o != null) ? o.toString() : "";
- }
- private static String toStringOrNull(String o) {
- return (o != null &&
- o.length()>0
- && !"null".equalsIgnoreCase(o))
- ? (String) o : "";
- }
- private static String toStringOrNull(Date o) {
- return (o != null) ? new SimpleDateFormat("dd-MM-yyyy").format(o) : "";
- }
- private static String toStringOrNull(Date o, String formatStr) {
- return (o != null) ? new SimpleDateFormat(formatStr).format(o) : "";
- }
- private static String toStringOrNull(BigDecimal o, Boolean flagNumDecimale) {
- if (flagNumDecimale){
- if(o != null){
- if( ( o.doubleValue() % 1) == 0) //se non ha decimali
- return Integer.valueOf(o.intValue()).toString() + ",00";
- else{
- String[] splitter = o.toString().split("\\.");
- splitter[0].length();
- if( splitter[1].length() < 2)
- return o.toString()+"0";
- }
- }
- else
- return "0,00";
- // return (o != null) ?
- // ( ((((BigDecimal) o).doubleValue() % 1) == 0) ?
- // o.toString() + ",00"
- // : o.toString())
- // : "";
- }
- return o!= null ? o.toString() : "";
- }
- private static String toStringOrNull(Double o, Boolean flagNumDecimale) {
- if (flagNumDecimale){
- if(o != null){
- if( ( ( (Double) o).doubleValue() % 1) == 0) //se non ha decimali
- return Integer.valueOf(o.intValue()).toString() + ",00";
- else{
- String[] splitter = o.toString().split("\\.");
- splitter[0].length();
- if( splitter[1].length() < 2)
- return o.toString()+"0";
- // double x = o - Math.floor(o);
- // x = x - (int) x * 10;
- // x = Math.pow(x, 10);
- // //se ha un decimale aggiungo uno 0
- // return x <= 9 ? o.toString()+"0" : o.toString();
- }
- }else
- return "0,00";
- // return (o != null) ? ( ((((Double) o).doubleValue() % 1) == 0) ? Integer
- // .valueOf(o.intValue()).toString() + ",00"
- // : o.toString() )
- // : "";
- }
- return (o != null) ? o.toString() : "";
- }
- private static double doubleOrNull(Object o){
- if(o!= null){
- int scale = (int) Math.pow(10, 3);
- return (double) Math.round((Double)o * scale) / scale;
- }
- return (Double)0.00;
- }
- private static double doubleOrNull(BigDecimal o){
- if(o!= null){
- int scale = (int) Math.pow(10, 3);
- return (double) Math.round(o.doubleValue() * scale) / scale;
- }
- return (Double)0.00;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement