Java Long to longToOther(Object val, Class dest)

Here you can find the source of longToOther(Object val, Class dest)

Description

long To Other

License

Apache License

Declaration

public static Object longToOther(Object val, Class<?> dest) 

Method Source Code

//package com.java2s;
/**/*from  www .j  ava 2  s  .  c  o  m*/
 * 
 * Copyright 2014 The Darks ORM Project (Liu lihua)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static Object longToOther(Object val, Class<?> dest) {
        if (val instanceof Long) {
            Long l = (Long) val;
            if (dest.equals(Integer.class) || dest.equals(int.class)) {
                return l.intValue();
            } else if (dest.equals(Float.class) || dest.equals(float.class)) {
                return l.floatValue();
            } else if (dest.equals(Double.class) || dest.equals(double.class)) {
                return l.doubleValue();
            } else if (dest.equals(Byte.class) || dest.equals(byte.class)) {
                return l.byteValue();
            } else if (dest.equals(Short.class) || dest.equals(short.class)) {
                return l.shortValue();
            } else if (dest.equals(long.class)) {
                return l.longValue();
            } else if (dest.equals(String.class)) {
                return String.valueOf(l);
            }
        }
        return val;
    }
}

Related

  1. longToNBuf(long l, char[] chars)
  2. longToNetworkByteOrderArray(long addr)
  3. longToNetworkBytes(long value)
  4. longToNumberWithDecimalPlaces(long longValue, int decimalPlaces)
  5. LongToOctString(final long value)
  6. longToPrefixCoded(final long val, final int shift, final char[] buffer)
  7. longToRegisters(long v)
  8. longToRemoteAddrTo(long remoteAddr)
  9. longToSortableBytes(long value, byte[] result, int offset)