@Test public void shouldParseNumberWithLeadingAndTrailingSpaces() { assertEquals(new Asn(65536l), Asn.parse(" AS65536 ")); }
public static Asn parse(String text) { try { String asnString = Validate.notNull(text, "AS Number must not be null").trim().toUpperCase(); if (asnString.startsWith("AS")) { asnString = asnString.substring(2); } long low; long high = 0L; int indexOfDot = asnString.indexOf('.'); if (indexOfDot != -1) { low = Validate.checkRange(Long.valueOf(asnString.substring(indexOfDot + 1)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); high = Validate.checkRange(Long.valueOf(asnString.substring(0, indexOfDot)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); } else { low = Long.valueOf(asnString); } return new Asn((high << SIXTEEN) | low); } catch (Exception ex) { throw new IllegalArgumentException("Invalid AS number: '" + text + "'. Details: " + ex.getMessage(), ex); } }
Asn implements SingleInternetResource<Asn, AsnRange>, Comparable<Asn> { public static Asn parse(String text) { try { String asnString = Validate.notNull(text, "AS Number must not be null").trim().toUpperCase(); if (asnString.startsWith("AS")) { asnString = asnString.substring(2); } long low; long high = 0L; int indexOfDot = asnString.indexOf('.'); if (indexOfDot != -1) { low = Validate.checkRange(Long.valueOf(asnString.substring(indexOfDot + 1)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); high = Validate.checkRange(Long.valueOf(asnString.substring(0, indexOfDot)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); } else { low = Long.valueOf(asnString); } return new Asn((high << SIXTEEN) | low); } catch (Exception ex) { throw new IllegalArgumentException("Invalid AS number: '" + text + "'. Details: " + ex.getMessage(), ex); } } }
Asn implements SingleInternetResource<Asn, AsnRange>, Comparable<Asn> { public static Asn parse(String text) { try { String asnString = Validate.notNull(text, "AS Number must not be null").trim().toUpperCase(); if (asnString.startsWith("AS")) { asnString = asnString.substring(2); } long low; long high = 0L; int indexOfDot = asnString.indexOf('.'); if (indexOfDot != -1) { low = Validate.checkRange(Long.valueOf(asnString.substring(indexOfDot + 1)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); high = Validate.checkRange(Long.valueOf(asnString.substring(0, indexOfDot)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); } else { low = Long.valueOf(asnString); } return new Asn((high << SIXTEEN) | low); } catch (Exception ex) { throw new IllegalArgumentException("Invalid AS number: '" + text + "'. Details: " + ex.getMessage(), ex); } } Asn(Long value); }
Asn implements SingleInternetResource<Asn, AsnRange>, Comparable<Asn> { public static Asn parse(String text) { try { String asnString = Validate.notNull(text, "AS Number must not be null").trim().toUpperCase(); if (asnString.startsWith("AS")) { asnString = asnString.substring(2); } long low; long high = 0L; int indexOfDot = asnString.indexOf('.'); if (indexOfDot != -1) { low = Validate.checkRange(Long.valueOf(asnString.substring(indexOfDot + 1)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); high = Validate.checkRange(Long.valueOf(asnString.substring(0, indexOfDot)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); } else { low = Long.valueOf(asnString); } return new Asn((high << SIXTEEN) | low); } catch (Exception ex) { throw new IllegalArgumentException("Invalid AS number: '" + text + "'. Details: " + ex.getMessage(), ex); } } Asn(Long value); static Asn of(Long value); static Asn of(String value); static Asn parse(String text); boolean is16Bit(); boolean is32Bit(); @Override int compareTo(Asn other); @Override Asn next(); @Override Asn previous(); @Override boolean hasNext(); @Override boolean hasPrevious(); @Override String toString(); @Override AsnRange asRange(); @Override int bitSize(); @Override BigInteger asBigInteger(); @Override boolean equals(Object o); @Override int hashCode(); }
Asn implements SingleInternetResource<Asn, AsnRange>, Comparable<Asn> { public static Asn parse(String text) { try { String asnString = Validate.notNull(text, "AS Number must not be null").trim().toUpperCase(); if (asnString.startsWith("AS")) { asnString = asnString.substring(2); } long low; long high = 0L; int indexOfDot = asnString.indexOf('.'); if (indexOfDot != -1) { low = Validate.checkRange(Long.valueOf(asnString.substring(indexOfDot + 1)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); high = Validate.checkRange(Long.valueOf(asnString.substring(0, indexOfDot)), ASN_MIN_VALUE, ASN_16_BIT_MAX_VALUE); } else { low = Long.valueOf(asnString); } return new Asn((high << SIXTEEN) | low); } catch (Exception ex) { throw new IllegalArgumentException("Invalid AS number: '" + text + "'. Details: " + ex.getMessage(), ex); } } Asn(Long value); static Asn of(Long value); static Asn of(String value); static Asn parse(String text); boolean is16Bit(); boolean is32Bit(); @Override int compareTo(Asn other); @Override Asn next(); @Override Asn previous(); @Override boolean hasNext(); @Override boolean hasPrevious(); @Override String toString(); @Override AsnRange asRange(); @Override int bitSize(); @Override BigInteger asBigInteger(); @Override boolean equals(Object o); @Override int hashCode(); static final long ASN_MIN_VALUE; static final long ASN_16_BIT_MAX_VALUE; static final long ASN_32_BIT_MAX_VALUE; static final Asn FIRST_ASN; static final Asn LAST_16_BIT_ASN; static final Asn LAST_32_BIT_ASN; static final int NUMBER_OF_BITS; }