Description
Decodes the String provided which should represent a hexadecimal number into a Long .
License
Open Source License
Parameter
Parameter | Description |
---|
hash | the String to be decoded |
Exception
Parameter | Description |
---|
NumberFormatException | If hash does not contain a valid Long. |
Return
the Long created from decoding the String provided or null if hash is null
Declaration
public static Long toNumber(String hash) throws NumberFormatException
Method Source Code
//package com.java2s;
/* Copyright (C) 2011 Alasdair Mercer, http://neocotic.com/
* //from ww w. jav a 2s . co m
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class Main {
/**
* Decodes the {@code String} provided which should represent a hexadecimal
* number into a {@code Long}.
*
* @param hash
* the {@code String} to be decoded
* @return the {@code Long} created from decoding the {@code String}
* provided or {@code null} if {@code hash} is {@code null}
* @throws NumberFormatException
* If {@code hash} does not contain a valid {@code Long}.
*/
public static Long toNumber(String hash) throws NumberFormatException {
return (hash == null) ? null : Long.decode("0x" + hash);
}
}
Related
- toNumber(char letter)
- toNumber(CharSequence jsonText)
- toNumber(final Object obj)
- toNumber(Object object, Number defaultValue)
- toNumber(Object object, Number defaultValue)
- toNumber(String num)
- toNumber(String s)
- toNumber(String string)
- toNumber(String text)