List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException(String s)
NumberFormatException
with the specified detail message. From source file:org.terrier.utility.UnitUtils.java
public static long parseLong(String str) { if (str == null) throw new NullPointerException(); int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Long.parseLong(str); long ret = Long.parseLong(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return ret * G_FACTOR; case "M": return ret * M_FACTOR; case "K": return ret * K_FACTOR; case "Gi": return ret * Gi_FACTOR; case "Mi": return ret * Mi_FACTOR; case "Ki": return ret * Ki_FACTOR; }/*from ww w. j av a 2s. c o m*/ throw new NumberFormatException(str + " can't be correctly parsed."); }
From source file:com.enonic.cms.business.MockSitePropertiesService.java
public Integer getPropertyAsInteger(String key, SiteKey siteKey) { String svalue = getProperty(key, siteKey); if (svalue != null && !StringUtils.isNumeric(svalue)) { throw new NumberFormatException( "Invalid value of property " + key + " = " + svalue + " in site-" + siteKey + ".properties"); }/*w w w . j a v a 2 s . c om*/ return svalue == null ? null : new Integer(svalue); }
From source file:ByteRange.java
public ByteRange(String string) throws NumberFormatException { string = string.trim();//from ww w .j a va 2s .co m int dashPos = string.indexOf('-'); int length = string.length(); if (string.indexOf(',') != -1) { throw new NumberFormatException("Simple ByteRange String contains a comma."); } if (dashPos > 0) { this.start = Integer.parseInt(string.substring(0, dashPos)); } else { this.start = Long.MIN_VALUE; } if (dashPos < length - 1) { this.end = Integer.parseInt(string.substring(dashPos + 1, length)); } else { this.end = Long.MAX_VALUE; } if (this.start > this.end) { throw new NumberFormatException("Start value is greater than end value."); } }
From source file:com.enonic.cms.core.structure.SiteProperties.java
public Integer getPropertyAsInteger(final SitePropertyNames key) { String svalue = StringUtils.trimToNull(properties.getProperty(key.getKeyName())); if (svalue != null && !StringUtils.isNumeric(svalue)) { throw new NumberFormatException( "Invalid value of property " + key + " = " + svalue + " in site-" + siteKey + ".properties"); }// ww w . ja v a 2 s.co m return svalue == null ? null : new Integer(svalue); }
From source file:Main.java
/** * Convert the bytes within the specified range of the given byte * array into a signed long in the given radix . The range extends * from <code>start</code> till, but not including <code>end</code>. <p> * * Based on java.lang.Long.parseLong()/* ww w . j a va2 s . c o m*/ */ public static long parseLong(byte[] b, int start, int end, int radix) throws NumberFormatException { if (b == null) throw new NumberFormatException("null"); long result = 0; boolean negative = false; int i = start; long limit; long multmin; int digit; if (end > start) { if (b[i] == '-') { negative = true; limit = Long.MIN_VALUE; i++; } else { limit = -Long.MAX_VALUE; } multmin = limit / radix; if (i < end) { digit = Character.digit((char) b[i++], radix); if (digit < 0) { throw new NumberFormatException("illegal number: " + toString(b, start, end)); } else { result = -digit; } } while (i < end) { // Accumulating negatively avoids surprises near MAX_VALUE digit = Character.digit((char) b[i++], radix); if (digit < 0) { throw new NumberFormatException("illegal number"); } if (result < multmin) { throw new NumberFormatException("illegal number"); } result *= radix; if (result < limit + digit) { throw new NumberFormatException("illegal number"); } result -= digit; } } else { throw new NumberFormatException("illegal number"); } if (negative) { if (i > start + 1) { return result; } else { /* Only got "-" */ throw new NumberFormatException("illegal number"); } } else { return -result; } }
From source file:org.apache.commons.functor.example.kata.four.ToInteger.java
public Integer evaluate(String str) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < str.length(); i++) { if (Character.isDigit(str.charAt(i))) { buf.append(str.charAt(i));//from www . ja va 2 s. com } else { break; } } try { return new Integer(buf.toString()); } catch (NumberFormatException e) { throw new NumberFormatException(str); } }
From source file:com.sap.prd.mobile.ios.mios.RemoveTrailingCharactersVersionTransformer.java
public String transform(String version) throws NumberFormatException { final String originalVersion = version; if (version == null) throw new NullPointerException("Version was null."); String[] parts = version.split("\\."); List<String> result = new ArrayList<String>(); int length = (limit == -1 ? parts.length : Math.min(parts.length, limit)); for (int i = 0; i < length; i++) { String part = removeTrailingNonNumbers(parts[i]); if (part.trim().isEmpty()) part = "0"; if (Long.parseLong(part) < 0) { throw new NumberFormatException("Invalid version found: '" + originalVersion + "'. Negativ version part found: " + parts[i] + "."); }/*from ww w. j av a 2s .c om*/ result.add(part); if (!parts[i].matches("\\d+")) break; } while (result.size() < limit) result.add("0"); return StringUtils.join(result, '.'); }
From source file:nz.gate5a.schoolstories.importer.NceaQualificationCreator.java
private BigDecimal bigDecimal(String value) { try {//from w ww . ja v a 2 s . c om if (StringUtils.isEmpty(value)) { return null; } return new BigDecimal(value); } catch (NumberFormatException e) { throw new NumberFormatException(value); } }
From source file:org.terrier.utility.UnitUtils.java
public static int parseInt(String str) { if (str == null) throw new NullPointerException(); final int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Integer.parseInt(str); int ret = Integer.parseInt(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return (int) (ret * G_FACTOR); case "M": return (int) (ret * M_FACTOR); case "K": return (int) (ret * K_FACTOR); case "Gi": return (int) (ret * Gi_FACTOR); case "Mi": return (int) (ret * Mi_FACTOR); case "Ki": return (int) (ret * Ki_FACTOR); }//from w w w . ja v a 2 s . c o m throw new NumberFormatException(str + " can't be correctly parsed."); }
From source file:org.kitodo.production.plugin.opac.pica.OpacResponseHandler.java
/** * SAX parser callback method./* ww w .j av a 2 s . c om*/ */ @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { // Eingefgt am 8.5.2007 if (localName.equals("RESULT") && atts.getValue("error") != null && atts.getValue("error").equalsIgnoreCase("ILLEGAL")) { throw new SAXException(new IllegalArgumentException()); } if (localName.equals("SESSIONVAR")) { sessionVar = atts.getValue("name"); readSessionVar = true; } if (localName.equals("SET")) { String hits = atts.getValue("hits"); if (hits == null) { throw new NumberFormatException("null"); } numberOfHits = Integer.parseInt(hits); } if (localName.equals("SHORTTITLE")) { readTitle = true; title = ""; opacResponseItemPpns.add(atts.getValue("PPN")); } }