List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Main.java
public static Node getRoot(String documentAsString) { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try {//from www . j a v a2 s . c o m final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); final Document document = documentBuilder.parse(new InputSource(new StringReader(documentAsString))); return document.getFirstChild(); } catch (ParserConfigurationException e) { throw new IllegalStateException(e); } catch (SAXException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static void set(String key, Object obj) { HashMap map = (HashMap) s_var.get(); if (map == null) throw new IllegalStateException("Thread local not exists!"); if (obj == null) map.remove(key);// ww w . j av a2 s. co m else map.put(key, obj); }
From source file:Main.java
/** find a palindromic number given a starting point, by * calling ourself until we get a number that is palindromic. */// w w w . j a v a2s . c o m public static BigInteger findPalindrome(BigInteger num) { if (num.compareTo(BigInteger.ZERO) < 0) throw new IllegalStateException("negative"); if (isPalindrome(num)) return num; if (verbose) System.out.println("Trying " + num); return findPalindrome(num.add(reverseNumber(num))); }
From source file:Main.java
public static byte[] toUtf8Bytes(String data) { try {/* w w w. j ava2 s . c o m*/ return data == null ? null : data.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static String toUtf8String(byte[] data) { try {/*from ww w . ja v a 2 s. com*/ return data == null ? null : new String(data, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static byte[] toAsciiBytes(String data) { try {// w w w. j a v a2 s.c o m return data == null ? null : data.getBytes("US-ASCII"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:Main.java
/** * Validate that a number is a power of two. * * @param value to be validated./*from w w w.ja v a 2s .c om*/ */ public static void validatePositivePowerOfTwo(final int value) { if (value > 0 && 1 == (value & (value - 1))) { throw new IllegalStateException("Value must be a positive power of two"); } }
From source file:Main.java
public static String toAsciiString(byte[] data) { try {/*from w w w . j a v a 2 s .co m*/ return data == null ? null : new String(data, "US-ASCII"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }
From source file:Main.java
public static boolean nextStartTagInsideTree(final XmlPullParser pp, final String tagNamespace, final String tagName) throws XmlPullParserException, IOException { if (tagNamespace == null && tagName == null) throw new IllegalArgumentException( "namespace and name argument can not be both null:" + pp.getPositionDescription()); if (pp.getEventType() != XmlPullParser.START_TAG && pp.getEventType() != XmlPullParser.END_TAG) throw new IllegalStateException( "expected START_TAG of parent or END_TAG of child:" + pp.getPositionDescription()); while (true) { final int eventType = pp.next(); if (eventType == XmlPullParser.START_TAG) { final String name = pp.getName(); final String namespace = pp.getNamespace(); boolean matches = (tagNamespace != null && tagNamespace.equals(namespace)) || (tagName != null && tagName.equals(name)); if (matches) return true; skipSubTree(pp);// w ww .ja va2 s .c om pp.require(XmlPullParser.END_TAG, namespace, name); } else if (eventType == XmlPullParser.END_TAG) { return false; } } }
From source file:Main.java
public static String encodeUriSegment(String segment) { try {/*from www. ja v a 2 s . co m*/ return URLEncoder.encode(segment, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } }