import java.util.*; import java.io.*; public class LongRangeKnownMethods { void testIndexOf(String s) { int idx = s.indexOf("xyz"); if(idx >= 0) { System.out.println("Found"); } else if(idx == -1) { System.out.println("Not found"); } } void testIndexOf2(String s) { int idx = s.indexOf("foo")+3; if(idx == -1) { System.out.println("Bug"); } } void testExternalAnnotations(int i, long l) { if(Integer.bitCount(i) == -1) { System.out.println("Impossible"); } if(Long.numberOfLeadingZeroes(l) <= 64) { System.out.println("Always"); } } private static int twiceIndexOf(String text, int start, int end) { int paragraphStart = text.lastIndexOf("\n\n", start); int paragraphEnd = text.indexOf("\n\n", end); if (paragraphStart >= paragraphEnd) { return text.length(); } return (paragraphStart >= 0 ? paragraphStart + 2 : 0) + (paragraphEnd < 0 ? text.length() : paragraphEnd); } void test(String s) { if (s.isEmpty() && s.length() > 2) { System.out.println("Never"); } } void test2(String s) { if (s.isEmpty() && s.length() == 0) { System.out.println("Ok"); } } void test3(String s) { if (s.startsWith("xyz") && s.length() < 3) { System.out.println("Impossible"); } } void testEmpty(String s) { if (s.isEmpty() && s.startsWith("xyz")) { System.out.println("Impossible"); } } void testOk(String s) { if (s.length() <= 3 && s.endsWith("xyz")) { System.out.println("Possible"); } } void testInterfere(String s, String s2) { if (!s.isEmpty() && s2.startsWith(s)) { if(s2.isEmpty()) { System.out.println(); } } } void test4() { String s = "abcd"; if (s.startsWith("efg")) { System.out.println("Impossible"); } } void testEquals(boolean b, boolean c) { String s1 = b ? "x" : "y"; String s2 = c ? "x" : "b"; if(s1.equals(s2) && b) { System.out.println("B is always true"); } } void testEqualsIgnoreCase(String s) { if(s.equalsIgnoreCase("xyz") && s.isEmpty()) { System.out.println("Never"); } } void testIndexOfUpperBound(String s) { int idx = "abcdefgh".indexOf(s); if(idx > 8) { System.out.println("Impossible"); } } void testMax(int x) { x = Math.max(x, 0); if (x > -1) { System.out.println("Always"); } if (x > 0) { System.out.println("Not always"); } } void testMin(long x, long y) { if (x < 10 && y > 10) { y = Long.min(x, y); if (y > 20) { System.out.println("Impossible"); } } if (y > 20) { System.out.println("Possible"); } } void testMinMax(List rows) { int start = Integer.MAX_VALUE; int end = -1; for (int i = 0; i < rows.size(); i++) { String row = rows.get(i); if (!row.isEmpty()) { start = Math.min(start, i); end = Math.max(end, i); } } if(end >= 0 && start < Integer.MAX_VALUE) { System.out.println("Ok"); } } void testAbs(long x, int y) { x = Math.abs(x); y = Math.abs(y); if (x == Long.MIN_VALUE) { System.out.println("possible"); } if (x == Long.MIN_VALUE + 1) { System.out.println("impossible"); } if (x == Integer.MIN_VALUE) { System.out.println("impossible"); } if (y == Integer.MIN_VALUE) { System.out.println("possible"); } else if(y < 0) { System.out.println("impossible"); } } void testStringComparison(String name) { // Parentheses misplaced -- found in AndroidStudio if (!(name.equals("layout_width") && !(name.equals("layout_height")) && !(name.equals("id")))) { System.out.println("ok"); } } void testFlush(MyReader r) { if(r.getValue().equals("abc")) { r.readNext(); if(r.getValue().equals("abcd")) { System.out.println("ok"); } } } void testNoFlush(MyReader r) { if(r.getValue().equals("abc")) { if(r.getValue().equals("abcd")) { System.out.println("ok"); } } } static class MyReader { private String value = ""; final String getValue() { return value; } void readNext() { value = new Scanner(System.in).next(); } } void testEmptyList(List list) { if (list.get(0).isEmpty() && list.isEmpty()) { System.out.println("impossible"); } } void testEmptyListGet(List list) { if (list.isEmpty()) { System.out.println(list.get(0)); } } void testBoundError(List list) { if (list.size() < 10) { System.out.println(list.get(10)); } } void testCollectionArray(Set currentElements, Object[] elements) { if(!currentElements.isEmpty() && elements.length == currentElements.size()) { if (elements.length > 0) { System.out.println("Yes"); } } } public String getOrThrow(int index, List localVariables) { if (index < localVariables.size()) { return localVariables.get(index); } else if (index < 0) { throw new IndexOutOfBoundsException(); } else return ""; } void testSetFirst(TreeSet set) { if (set.first() == 0 && set.size() > 0) { System.out.println("Impossible"); } } void testMap(HashMap map) { if(map.isEmpty() && map.containsKey("xyz")) { System.out.println("Impossible"); } } void testMapContainsValue(TreeMap map) { if(map.containsValue(1) && map.size() < 1) { System.out.println("Impossible"); } } void testMapEquals(Map map, Map otherMap) { if(map.isEmpty() && otherMap.equals(map) && otherMap.containsValue("xyz")) { System.out.println("Impossible"); } } void testListIndexOf(List list) { if(list.size() == 10 && list.indexOf("xyz") == 15) { System.out.println("Impossible"); } } void testGetUnknown(List list, int index) { if(list.get(index).isEmpty() && list.isEmpty()) { System.out.println("Impossible"); } } native void unknown(); void testNewList() { List list = new ArrayList<>(); if(list.isEmpty()) { System.out.println("Always"); } unknown(); if(list.isEmpty()) { System.out.println("Still always"); } testListIndexOf(list); if(list.isEmpty()) { System.out.println("Not sure anymore"); } } void testDoubleBrace() { List list = new ArrayList() {{ this.add("foo"); this.add("bar"); }}; if(list.isEmpty()) { System.out.println("Not known now"); } } void testSizeCheck() { List list = new ArrayList<>(); list.add(null); if(list.size() == 0) return; if(list.size() == 0) return; } void testStartsWithEmpty(String s1, String s2) { if(s1.startsWith(s2) || s2.isEmpty()) { System.out.println("Oops"); } } void testCalendar(Calendar c) { int month = c.get(Calendar.MONTH); if (month < 0) {} } void testSkip(InputStream is, int amount) throws IOException { long skipped = is.skip(amount); if (skipped > Integer.MAX_VALUE) {} if (skipped < 0) {} if (is.skip(-1) == 0) {} } void testNumberToString(int i, long j) { String s; s = Integer.toHexString(i); if (s.length() < 1) {} if (s.length() < 2) {} if (s.length() > 7) {} if (s.length() > 8) {} s = Integer.toOctalString(i); if (s.length() > 10) {} if (s.length() > 11) {} s = Integer.toBinaryString(i); if (s.length() > 31) {} if (s.length() > 32) {} s = Long.toHexString(j); if (s.length() < 1) {} if (s.length() < 2) {} if (s.length() > 15) {} if (s.length() > 16) {} s = Long.toOctalString(j); if (s.length() > 21) {} if (s.length() > 22) {} s = Long.toBinaryString(j); if (s.length() > 63) {} if (s.length() > 64) {} if (i >= 0 && i < 100) { s = Integer.toBinaryString(i); if (s.length() > 6) {} if (s.length() > 7) {} } } void testChainCall() { if (getByte(0).intValue() == 256) { } } native Byte getByte(int x); void testNumberToStringExact(boolean b) { int i = b ? 123 : 456; String s = Integer.toString(i); if (s.equals("123") || s.equals("456")) {} } }