Last active
May 29, 2020 13:35
-
-
Save eternalharvest/35214f96036d42be2fe03ffe001595c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LibphonenumberCarrierMappingExample { | |
final static PhoneNumberUtil util = PhoneNumberUtil.getInstance(); | |
final static PhoneNumberToCarrierMapper cmap = PhoneNumberToCarrierMapper.getInstance(); | |
public static void main(String[] argv) | |
{ | |
try { | |
final String numstr = argv[0]; | |
final PhoneNumber number = util.parse(numstr, Locale.JAPAN.getCountry()); | |
System.out.println("[NUMBER]"); | |
System.out.println(String.format(" ORIGINAL INPUT: %s", numstr)); | |
System.out.println(String.format(" INTERNATIONAL: %s", util.format(number, PhoneNumberFormat.INTERNATIONAL))); | |
System.out.println(String.format(" LOCAL FORMAT: %s", util.format(number, PhoneNumberFormat.NATIONAL))); | |
System.out.println(String.format(" NUMBER TYPE: %s", util.getNumberType(number))); | |
System.out.println(); | |
System.out.println("[CARRIER]"); | |
System.out.println(String.format(" ENGLISH: %s", cmap.getNameForNumber(number, Locale.ENGLISH))); | |
System.out.println(String.format(" JAPANESE: %s", cmap.getNameForNumber(number, Locale.JAPANESE))); | |
} catch (ArrayIndexOutOfBoundsException e) { | |
System.err.println("not enough argument, please specify phone number with command line argument!"); | |
} catch (NumberParseException e) { | |
System.err.println(String.format("failed to parse number: '%s'", argv[0])); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment