Java String Divide divide(Object o1, Object o2, String type)

Here you can find the source of divide(Object o1, Object o2, String type)

Description

divide

License

Apache License

Declaration

public static Object divide(Object o1, Object o2, String type) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static Object divide(Object o1, Object o2, String type) {
        if (type.equalsIgnoreCase("double") || type.equalsIgnoreCase("float")) {
            return add((Double) o1, (Double) o2);
        } else if (type.equalsIgnoreCase("int") || type.equalsIgnoreCase("integer")
                || type.equalsIgnoreCase("long")) {
            return add((Long) o1, (Long) o2);
        } else if (type.equalsIgnoreCase("string")) {
            return "";
        } else if (type.equalsIgnoreCase("date")) {
            return null;
        }/*ww  w  . j a v  a 2  s . c  o  m*/
        return null;
    }

    private static Long divide(Long o1, Long o2) {
        return o1 / o2;
    }

    private static Double divide(Double o1, Double o2) {
        return o1 / o2;
    }

    public static Object add(Object o1, Object o2, String type) {
        if (type.equalsIgnoreCase("double") || type.equals("float")) {
            return add((Double) o1, (Double) o2);
        } else if (type.equalsIgnoreCase("int") || type.equalsIgnoreCase("integer")
                || type.equalsIgnoreCase("long")) {
            return add((Long) o1, (Long) o2);
        } else if (type.equalsIgnoreCase("string")) {
            return ((String) o1).concat((String) o2);
        } else if (type.equalsIgnoreCase("date")) {
            return null;
        }
        return null;
    }

    private static Long add(Long o1, Long o2) {
        return o1 + o2;
    }

    private static Double add(Double o1, Double o2) {
        return o1 + o2;
    }
}

Related

  1. div(String content, String extra)
  2. div(String second, String first)
  3. div(String text)
  4. divide(final String s)
  5. divide(String m)
  6. divide(String str, char c)
  7. divide(String ts, String ms)
  8. divide(String type)