import java.util.List; public class LongRangeBasics { void testSwitch(int i) { switch (i) { case 0: System.out.println("0"); break; case 1: System.out.println("1"); return; case 2: System.out.println("2"); return; default: System.out.println("default"); break; } if(i == 0) { System.out.println("ouch"); } // i > 0 and i < 3 means (i == 1 || i == 2); in both cases we already returned if(i > 0 && i < 3) { System.out.println("oops"); } } void test(int i) { if(i > 5) { if(i < 0) { System.out.println("Hello"); } } } void test2(char c) { int i = c; if(i > 0x10000) { System.out.println("Hello"); } } void test3(String s) { int i = s.charAt(0); if(i > 0x10000) { System.out.println("Hello"); } } void test4(String s) { if(s.charAt(0) < 0x10000) { System.out.println("Hello"); } } void test1(int i, int j) { if(i > 0 && j > i) { // j > i which is > 0 means that j >= 2 if(j == 1) { if(i < 0) { System.out.println("oops"); } } } } void testLength(String s) { if(s.length() < 2) { if(s.length() > 4) { System.out.println("Never"); } if(s.length() == 1) { System.out.println("One"); } else if(s.length() == 0) { System.out.println("Empty"); } } if(s.length() < 0) { System.out.println("Never"); } } void testArrayLength(int[] arr) { if (arr.length > 0) { System.out.println("Ok"); } else if(arr.length == 0) { System.out.println("Empty"); } if (arr.length < 0) { System.out.println("Impossible"); } } static void testTwoLengths(int[] data) { String s1 = data.length > 0 ? "foo" : null; String s2 = data.length == 0 ? null : "bar"; if(s1 == null || s2 == null) { System.out.println("Test"); } } static final String FOO = "bar"; void testStaticLength() { if(FOO.isEmpty()) System.out.println("nope"); } void testWrongMerge(boolean a, boolean b, int c) { int currentLevel = 0; if (a) { currentLevel = c; } if(currentLevel > 0 && b || currentLevel < 0) { } } void testLength2(String name) { boolean completeDigits = name.length() > 1; for (int j = 1; j < name.length(); ++j) { completeDigits &= Character.isDigit(name.charAt(j)); if (!completeDigits) break; } if (completeDigits) name = "this"; System.out.println(name); } void testLengthNonFlushed(String s) { if (s.length() > 10) { System.out.println(s); if (s.length() > 5) { System.out.println(s); } } } void getMax(List points, String source) { int min = Integer.MAX_VALUE; int nextSelectedIndex = -1; for (int i = points.size() - 1; i >= 0; i--) { final int distance = calcDistance(source, points.get(i)); if (distance < min) { min = distance; nextSelectedIndex = i; } } if (min == Integer.MAX_VALUE) { return; } if (nextSelectedIndex == -1) { System.out.println("Impossible"); } System.out.println(nextSelectedIndex); } private int calcDistance(String s1, String s2) { return s1.length() - s2.length(); } public void testBitwiseAnd() { int state = getState() & 0xF; switch (state) { case 24: System.out.println("Impossible"); } } public void testBitwiseAndOk() { if((getState() & 0x1) == 0x1) { System.out.println("ok"); } } void testDouble(double d) { if(d > 0 && d < 1) { System.out.println("ok"); } } private int getState() { return (int)(Math.random() * 100); } String extract(String line) { int i = line.lastIndexOf(' '); int j = line.lastIndexOf(' ', i - 1); i = (j >= 0) ? j : 0; if (i < 0 || i == line.length() - 1){ throw new RuntimeException(); } return line.substring(i + 1); } void testNPE(String s1, String s2) { int code = (s1 == null ? 0 : 1) + (s2 == null ? 0 : 1); if(code == 2) { System.out.println(s1.trim()); System.out.println(s2.trim()); } if(code == 0) { System.out.println(s1.trim()); System.out.println(s2.trim()); } } void testLoopInitializer(List l) { int count = l != null ? l.size() : 0; for (int i = count - 1; i >= 0; i--) { try { Object o = l.get(i); } catch (Exception e) { e.printStackTrace(); } } } void testLoopLong() { // IDEA-196624 long maxCount = 3_000_000_000L; for ( long xx = 0; xx < maxCount; xx += 1 ) { System.out.println(); } } void testLoopInt() { long maxCount = 3_000_000_000L; for ( int xx = 0; xx < maxCount; xx += 1 ) { System.out.println(); } } }