Java Long Number Create toLong(Object x)

Here you can find the source of toLong(Object x)

Description

to Long

License

Open Source License

Declaration

static Long toLong(Object x) 

Method Source Code

//package com.java2s;
/**//from   w w  w .  j av a  2  s.c o  m
 * Copyright (c) 2012, Thilo Planz. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation (the "License").
 *
 * 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.
 *
 * You should have received a copy of the License along with this program.
 * If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
 */

public class Main {
    static Long toLong(Object x) {
        if (x == null)
            return null;
        if (x instanceof Long)
            return (Long) x;
        if (x instanceof Integer)
            return Long.valueOf(((Integer) x).intValue());
        if (x instanceof String)
            return Long.valueOf((String) x);
        throw new IllegalArgumentException("cannot convert `" + x + "` into a Long");
    }
}

Related

  1. toLong(Object value)
  2. toLong(Object value)
  3. toLong(Object value)
  4. toLong(Object value)
  5. toLong(Object value, long defaultValue)
  6. toLong(short[] arr)
  7. toLong(String input, int radix, long defaultValue)
  8. toLong(String numeric)
  9. toLong(String param)