target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void insertFromLeftTest() { final String s = "0123456789"; assertEquals(insertFromLeft(s, 0, "-"), "0123456789"); assertEquals(insertFromLeft(s, 1, "-"), "0-1-2-3-4-5-6-7-8-9"); assertEquals(insertFromLeft("ahmet", 1, " "), "a h m e t"); assertEquals(insertFromLeft(s, 2, "-"), "01-23-45-67-89"); assertEquals(insertFromLeft(s, 3, "-"), "012-345-678-9"); assertEquals(insertFromLeft(s, 5, "-"), "01234-56789"); assertEquals(insertFromLeft(s, 6, "-"), "012345-6789"); assertEquals(insertFromLeft(s, 9, "-"), "012345678-9"); assertEquals(insertFromLeft(s, 10, "-"), "0123456789"); assertEquals(insertFromLeft(s, 12, "-"), "0123456789"); assertEquals(insertFromLeft(s, 2, "--"), "01--23--45--67--89"); }
|
public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test(expected = IllegalArgumentException.class) public void insertFromLeftExceptionTest2() { insertFromLeft("123", -1, "-"); }
|
public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String insertFromLeft(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int i = 0; for (char c : str.toCharArray()) { b.append(c); i++; if (i % interval == 0 && i <= str.length() - 1) { b.append(stringToInsert); } } return b.toString(); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void insertFromRightTest() { final String s = "0123456789"; assertEquals(insertFromRight(s, 0, "-"), "0123456789"); assertEquals(insertFromRight(s, 1, "-"), "0-1-2-3-4-5-6-7-8-9"); assertEquals(insertFromRight(s, 2, "-"), "01-23-45-67-89"); assertEquals(insertFromRight(s, 3, "-"), "0-123-456-789"); assertEquals(insertFromRight(s, 5, "-"), "01234-56789"); assertEquals(insertFromRight(s, 6, "-"), "0123-456789"); assertEquals(insertFromRight(s, 9, "-"), "0-123456789"); assertEquals(insertFromRight(s, 10, "-"), "0123456789"); assertEquals(insertFromRight(s, 12, "-"), "0123456789"); assertEquals(insertFromRight(s, 2, "--"), "01--23--45--67--89"); assertEquals(insertFromRight(s, 3, "--"), "0--123--456--789"); }
|
public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test(expected = IllegalArgumentException.class) public void insertFromRightExceptionTest2() { insertFromRight("123", -1, "-"); }
|
public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String insertFromRight(String str, int interval, String stringToInsert) { if (interval < 0) { throw new IllegalArgumentException("interval value cannot be negative."); } if (str == null || interval == 0 || interval >= str.length() || isNullOrEmpty(stringToInsert)) { return str; } StringBuilder b = new StringBuilder(); int j = 0; for (int i = str.length() - 1; i >= 0; i--) { b.append(str.charAt(i)); j++; if (j % interval == 0 && j <= str.length() - 1) { b.append(stringToInsert); } } return reverse(b.toString()); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testRightPad_StringInt() { assertEquals(null, rightPad(null, 5)); assertEquals(" ", rightPad("", 5)); assertEquals("abc ", rightPad("abc", 5)); assertEquals("abc", rightPad("abc", 2)); assertEquals("abc", rightPad("abc", -1)); }
|
public static String rightPad(String str, int size) { return rightPad(str, size, ' '); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testRightPad_StringIntChar() { assertEquals(null, rightPad(null, 5, ' ')); assertEquals(" ", rightPad("", 5, ' ')); assertEquals("abc ", rightPad("abc", 5, ' ')); assertEquals("abc", rightPad("abc", 2, ' ')); assertEquals("abc", rightPad("abc", -1, ' ')); assertEquals("abcxx", rightPad("abc", 5, 'x')); String str = rightPad("aaa", 10000, 'a'); assertEquals(10000, str.length()); }
|
public static String rightPad(String str, int size) { return rightPad(str, size, ' '); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testRightPad_StringIntString() { assertEquals(null, rightPad(null, 5, "-+")); assertEquals(" ", rightPad("", 5, " ")); assertEquals(null, rightPad(null, 8, null)); assertEquals("abc-+-+", rightPad("abc", 7, "-+")); assertEquals("abc-+~", rightPad("abc", 6, "-+~")); assertEquals("abc-+", rightPad("abc", 5, "-+~")); assertEquals("abc", rightPad("abc", 2, " ")); assertEquals("abc", rightPad("abc", -1, " ")); assertEquals("abc ", rightPad("abc", 5, null)); assertEquals("abc ", rightPad("abc", 5, "")); }
|
public static String rightPad(String str, int size) { return rightPad(str, size, ' '); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String rightPad(String str, int size) { return rightPad(str, size, ' '); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testLeftPad_StringInt() { assertEquals(null, leftPad(null, 5)); assertEquals(" ", leftPad("", 5)); assertEquals(" abc", leftPad("abc", 5)); assertEquals("abc", leftPad("abc", 2)); }
|
public static String leftPad(String str, int size) { return leftPad(str, size, " "); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testLeftPad_StringIntChar() { assertEquals(null, leftPad(null, 5, ' ')); assertEquals(" ", leftPad("", 5, ' ')); assertEquals(" abc", leftPad("abc", 5, ' ')); assertEquals("xxabc", leftPad("abc", 5, 'x')); assertEquals("\uffff\uffffabc", leftPad("abc", 5, '\uffff')); assertEquals("abc", leftPad("abc", 2, ' ')); String str = leftPad("aaa", 10000, 'a'); assertEquals(10000, str.length()); }
|
public static String leftPad(String str, int size) { return leftPad(str, size, " "); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testLeftPad_StringIntString() { assertEquals(null, leftPad(null, 5, "-+")); assertEquals(null, leftPad(null, 5, null)); assertEquals(" ", leftPad("", 5, " ")); assertEquals("-+-+abc", leftPad("abc", 7, "-+")); assertEquals("-+~abc", leftPad("abc", 6, "-+~")); assertEquals("-+abc", leftPad("abc", 5, "-+~")); assertEquals("abc", leftPad("abc", 2, " ")); assertEquals("abc", leftPad("abc", -1, " ")); assertEquals(" abc", leftPad("abc", 5, null)); assertEquals(" abc", leftPad("abc", 5, "")); }
|
public static String leftPad(String str, int size) { return leftPad(str, size, " "); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String leftPad(String str, int size) { return leftPad(str, size, " "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void stemEndingTest2() { TurkishMorphology morphology = TurkishMorphology.builder() .setLexicon("üzmek", "yüz", "güz").build(); List<String> endings = Lists.newArrayList("düm"); StemEndingGraph graph = new StemEndingGraph(morphology, endings); CharacterGraphDecoder spellChecker = new CharacterGraphDecoder(graph.stemGraph); List<ScoredItem<String>> res = spellChecker.getSuggestionsWithScores("yüzdüm"); Assert.assertEquals(3, res.size()); assertContainsAll(res, "yüzdüm", "üzdüm", "güzdüm"); }
|
public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); static final Map<Character, String> TURKISH_FQ_NEAR_KEY_MAP; static final Map<Character, String> TURKISH_Q_NEAR_KEY_MAP; static final DiacriticsIgnoringMatcher DIACRITICS_IGNORING_MATCHER; final float maxPenalty; final boolean checkNearKeySubstitution; public Map<Character, String> nearKeyMap; }
|
@Test public void testWhiteSpacesToSingleSpace() { assertEquals(whiteSpacesToSingleSpace(null), null); assertEquals(whiteSpacesToSingleSpace(""), ""); assertEquals(whiteSpacesToSingleSpace("asd"), "asd"); assertEquals(whiteSpacesToSingleSpace("a a"), "a a"); assertEquals(whiteSpacesToSingleSpace(" "), " "); assertEquals(whiteSpacesToSingleSpace("\t"), " "); assertEquals(whiteSpacesToSingleSpace("\n"), " "); assertEquals(whiteSpacesToSingleSpace("\t \n"), " "); assertEquals(whiteSpacesToSingleSpace(" \t \n\r \f"), " "); assertEquals(whiteSpacesToSingleSpace(" a\t a\r\fa"), " a a a"); }
|
public static String whiteSpacesToSingleSpace(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return MULTI_SPACE.matcher(WHITE_SPACE_EXCEPT_SPACE.matcher(str).replaceAll(" ")) .replaceAll(" "); }
|
Strings { public static String whiteSpacesToSingleSpace(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return MULTI_SPACE.matcher(WHITE_SPACE_EXCEPT_SPACE.matcher(str).replaceAll(" ")) .replaceAll(" "); } }
|
Strings { public static String whiteSpacesToSingleSpace(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return MULTI_SPACE.matcher(WHITE_SPACE_EXCEPT_SPACE.matcher(str).replaceAll(" ")) .replaceAll(" "); } private Strings(); }
|
Strings { public static String whiteSpacesToSingleSpace(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return MULTI_SPACE.matcher(WHITE_SPACE_EXCEPT_SPACE.matcher(str).replaceAll(" ")) .replaceAll(" "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String whiteSpacesToSingleSpace(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return MULTI_SPACE.matcher(WHITE_SPACE_EXCEPT_SPACE.matcher(str).replaceAll(" ")) .replaceAll(" "); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testEliminateWhiteSpaces() { assertEquals(eliminateWhiteSpaces(null), null); assertEquals(eliminateWhiteSpaces(""), ""); assertEquals(eliminateWhiteSpaces("asd"), "asd"); assertEquals(eliminateWhiteSpaces("a "), "a"); assertEquals(eliminateWhiteSpaces("a a "), "aa"); assertEquals(eliminateWhiteSpaces("a \t a \t\r\f"), "aa"); }
|
public static String eliminateWhiteSpaces(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return WHITE_SPACE.matcher(str).replaceAll(""); }
|
Strings { public static String eliminateWhiteSpaces(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return WHITE_SPACE.matcher(str).replaceAll(""); } }
|
Strings { public static String eliminateWhiteSpaces(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return WHITE_SPACE.matcher(str).replaceAll(""); } private Strings(); }
|
Strings { public static String eliminateWhiteSpaces(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return WHITE_SPACE.matcher(str).replaceAll(""); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String eliminateWhiteSpaces(String str) { if (str == null) { return null; } if (str.isEmpty()) { return str; } return WHITE_SPACE.matcher(str).replaceAll(""); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testSubstringAfterFirst() { assertEquals(subStringAfterFirst("hello", "el"), "lo"); assertEquals(subStringAfterFirst("hellohello", "el"), "lohello"); assertEquals(subStringAfterFirst("hello", "hello"), ""); assertEquals(subStringAfterFirst("hello", ""), "hello"); assertEquals(subStringAfterFirst("hello", null), "hello"); assertEquals(subStringAfterFirst("", "el"), ""); assertEquals(subStringAfterFirst(null, "el"), null); }
|
public static String subStringAfterFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } }
|
Strings { public static String subStringAfterFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } }
|
Strings { public static String subStringAfterFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); }
|
Strings { public static String subStringAfterFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String subStringAfterFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testSubstringAfterLast() { assertEquals(subStringAfterLast("hello\\world", "\\"), "world"); assertEquals(subStringAfterLast("hello", "el"), "lo"); assertEquals(subStringAfterLast("hellohello", "el"), "lo"); assertEquals(subStringAfterLast("hello", "hello"), ""); assertEquals(subStringAfterLast("hello", ""), "hello"); assertEquals(subStringAfterLast("hello", null), "hello"); assertEquals(subStringAfterLast("", "el"), ""); assertEquals(subStringAfterLast(null, "el"), null); }
|
public static String subStringAfterLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } }
|
Strings { public static String subStringAfterLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } }
|
Strings { public static String subStringAfterLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); }
|
Strings { public static String subStringAfterLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String subStringAfterLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } else { return str.substring(pos + s.length()); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testSubstringUntilFirst() { assertEquals(subStringUntilFirst("hello", "el"), "h"); assertEquals(subStringUntilFirst("hellohello", "el"), "h"); assertEquals(subStringUntilFirst("hello", "hello"), ""); assertEquals(subStringUntilFirst("hello", ""), "hello"); assertEquals(subStringUntilFirst("hello", null), "hello"); assertEquals(subStringUntilFirst("", "el"), ""); assertEquals(subStringUntilFirst(null, "el"), null); }
|
public static String subStringUntilFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(0, pos); } }
|
Strings { public static String subStringUntilFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(0, pos); } } }
|
Strings { public static String subStringUntilFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(0, pos); } } private Strings(); }
|
Strings { public static String subStringUntilFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(0, pos); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String subStringUntilFirst(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.indexOf(s); if (pos < 0) { return str; } else { return str.substring(0, pos); } } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testSubstringUntilLast() { assertEquals(subStringUntilLast("hello", "el"), "h"); assertEquals(subStringUntilLast("hellohello", "el"), "helloh"); assertEquals(subStringUntilLast("hello", "hello"), ""); assertEquals(subStringUntilLast("hello", ""), "hello"); assertEquals(subStringUntilLast("hello", null), "hello"); assertEquals(subStringUntilLast("", "el"), ""); assertEquals(subStringUntilLast(null, "el"), null); }
|
public static String subStringUntilLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } return str.substring(0, pos); }
|
Strings { public static String subStringUntilLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } return str.substring(0, pos); } }
|
Strings { public static String subStringUntilLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } return str.substring(0, pos); } private Strings(); }
|
Strings { public static String subStringUntilLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } return str.substring(0, pos); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String subStringUntilLast(String str, String s) { if (isNullOrEmpty(str) || isNullOrEmpty(s)) { return str; } final int pos = str.lastIndexOf(s); if (pos < 0) { return str; } return str.substring(0, pos); } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testGrams() { assertArrayEquals(separateGrams("hello", 1), new String[]{"h", "e", "l", "l", "o"}); assertArrayEquals(separateGrams("hello", 2), new String[]{"he", "el", "ll", "lo"}); assertArrayEquals(separateGrams("hello", 3), new String[]{"hel", "ell", "llo"}); assertArrayEquals(separateGrams("hello", 4), new String[]{"hell", "ello"}); assertArrayEquals(separateGrams("hello", 5), new String[]{"hello"}); assertArrayEquals(separateGrams("hello", 6), EMPTY_STRING_ARRAY); }
|
public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test(expected = IllegalArgumentException.class) public void gram0sizeExceptionTest() { separateGrams("123", 0); }
|
public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
|
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }
|
@Test public void testtoByteArray() { Assert.assertArrayEquals(Bytes.toByteArray(0x7e, 0xac, 0x8a, 0x93), ba); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test(expected = IllegalArgumentException.class) public void testtoByteArrayNegativeException() { Assert.assertArrayEquals(Bytes.toByteArray(-1, 0xac, 0x8a, 0x93), ba); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void stemEndingTest3() { TurkishMorphology morphology = TurkishMorphology.builder().setLexicon("o", "ol", "ola") .build(); List<String> endings = Lists.newArrayList("arak", "acak"); StemEndingGraph graph = new StemEndingGraph(morphology, endings); CharacterGraphDecoder spellChecker = new CharacterGraphDecoder(graph.stemGraph); List<ScoredItem<String>> res = spellChecker.getSuggestionsWithScores("olarak"); assertContainsAll(res, "olarak", "olacak", "olaarak"); }
|
public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); static final Map<Character, String> TURKISH_FQ_NEAR_KEY_MAP; static final Map<Character, String> TURKISH_Q_NEAR_KEY_MAP; static final DiacriticsIgnoringMatcher DIACRITICS_IGNORING_MATCHER; final float maxPenalty; final boolean checkNearKeySubstitution; public Map<Character, String> nearKeyMap; }
|
@Test(expected = IllegalArgumentException.class) public void testtoByteArrayLArgeNumberException() { Assert.assertArrayEquals(Bytes.toByteArray(256, 0xac, 0x8a, 0x93), ba); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToInt() { assertEquals(Bytes.toInt(ba, true), bigEndianInt); assertEquals(Bytes.toInt(ba, false), littleEndianInt); assertEquals(Bytes.toInt((byte) 0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, true), bigEndianInt); assertEquals(Bytes.toInt((byte) 0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, false), littleEndianInt); assertEquals(Bytes.toInt(new byte[]{0x7e, (byte) 0xac, (byte) 0x8a}, true), 0x7eac8a); assertEquals(Bytes.toInt(new byte[]{0x7e, (byte) 0xac, (byte) 0x8a}, false), 0x8aac7e); assertEquals(Bytes.toInt(new byte[]{0x7e, (byte) 0xac}, true), 0x7eac); assertEquals(Bytes.toInt(new byte[]{0x7e, (byte) 0xac}, false), 0xac7e); assertEquals(Bytes.toInt(new byte[]{0x7e}, true), 0x7e); assertEquals(Bytes.toInt(new byte[]{0x7e}, false), 0x7e); assertEquals(Bytes.toInt(new byte[]{0x2f, (byte) 0xff}, false), 0xff2f); }
|
public static int toInt(byte[] pb, boolean bigEndian) { switch (pb.length) { case 1: return pb[0] & 0xff; case 2: if (bigEndian) { return (pb[0] << 8 & 0xff00) | (pb[1] & 0xff); } else { return (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 3: if (bigEndian) { return (pb[0] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[2] & 0xff); } else { return (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 4: if (bigEndian) { return (pb[0] << 24 & 0xff000000) | (pb[1] << 16 & 0xff0000) | (pb[2] << 8 & 0xff00) | (pb[3] & 0xff); } else { return (pb[3] << 24 & 0xff000000) | (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } default: throw new IllegalArgumentException("1,2,3 or 4 byte arrays allowed. size:" + pb.length); } }
|
Bytes { public static int toInt(byte[] pb, boolean bigEndian) { switch (pb.length) { case 1: return pb[0] & 0xff; case 2: if (bigEndian) { return (pb[0] << 8 & 0xff00) | (pb[1] & 0xff); } else { return (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 3: if (bigEndian) { return (pb[0] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[2] & 0xff); } else { return (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 4: if (bigEndian) { return (pb[0] << 24 & 0xff000000) | (pb[1] << 16 & 0xff0000) | (pb[2] << 8 & 0xff00) | (pb[3] & 0xff); } else { return (pb[3] << 24 & 0xff000000) | (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } default: throw new IllegalArgumentException("1,2,3 or 4 byte arrays allowed. size:" + pb.length); } } }
|
Bytes { public static int toInt(byte[] pb, boolean bigEndian) { switch (pb.length) { case 1: return pb[0] & 0xff; case 2: if (bigEndian) { return (pb[0] << 8 & 0xff00) | (pb[1] & 0xff); } else { return (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 3: if (bigEndian) { return (pb[0] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[2] & 0xff); } else { return (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 4: if (bigEndian) { return (pb[0] << 24 & 0xff000000) | (pb[1] << 16 & 0xff0000) | (pb[2] << 8 & 0xff00) | (pb[3] & 0xff); } else { return (pb[3] << 24 & 0xff000000) | (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } default: throw new IllegalArgumentException("1,2,3 or 4 byte arrays allowed. size:" + pb.length); } } }
|
Bytes { public static int toInt(byte[] pb, boolean bigEndian) { switch (pb.length) { case 1: return pb[0] & 0xff; case 2: if (bigEndian) { return (pb[0] << 8 & 0xff00) | (pb[1] & 0xff); } else { return (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 3: if (bigEndian) { return (pb[0] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[2] & 0xff); } else { return (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 4: if (bigEndian) { return (pb[0] << 24 & 0xff000000) | (pb[1] << 16 & 0xff0000) | (pb[2] << 8 & 0xff00) | (pb[3] & 0xff); } else { return (pb[3] << 24 & 0xff000000) | (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } default: throw new IllegalArgumentException("1,2,3 or 4 byte arrays allowed. size:" + pb.length); } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static int toInt(byte[] pb, boolean bigEndian) { switch (pb.length) { case 1: return pb[0] & 0xff; case 2: if (bigEndian) { return (pb[0] << 8 & 0xff00) | (pb[1] & 0xff); } else { return (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 3: if (bigEndian) { return (pb[0] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[2] & 0xff); } else { return (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } case 4: if (bigEndian) { return (pb[0] << 24 & 0xff000000) | (pb[1] << 16 & 0xff0000) | (pb[2] << 8 & 0xff00) | (pb[3] & 0xff); } else { return (pb[3] << 24 & 0xff000000) | (pb[2] << 16 & 0xff0000) | (pb[1] << 8 & 0xff00) | (pb[0] & 0xff); } default: throw new IllegalArgumentException("1,2,3 or 4 byte arrays allowed. size:" + pb.length); } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testNormalize() { assertEquals(Bytes.normalize(0xff, 8), -1); assertEquals(Bytes.normalize(0x8000, 16), Short.MIN_VALUE); }
|
public static int normalize(int i, int bitCount) { int max = 0xffffffff >>> (32 - bitCount); if (i > max) { throw new IllegalArgumentException("The integer cannot fit to bit boundaries."); } if (i > (max >>> 1)) { return i - (max + 1); } else { return i; } }
|
Bytes { public static int normalize(int i, int bitCount) { int max = 0xffffffff >>> (32 - bitCount); if (i > max) { throw new IllegalArgumentException("The integer cannot fit to bit boundaries."); } if (i > (max >>> 1)) { return i - (max + 1); } else { return i; } } }
|
Bytes { public static int normalize(int i, int bitCount) { int max = 0xffffffff >>> (32 - bitCount); if (i > max) { throw new IllegalArgumentException("The integer cannot fit to bit boundaries."); } if (i > (max >>> 1)) { return i - (max + 1); } else { return i; } } }
|
Bytes { public static int normalize(int i, int bitCount) { int max = 0xffffffff >>> (32 - bitCount); if (i > max) { throw new IllegalArgumentException("The integer cannot fit to bit boundaries."); } if (i > (max >>> 1)) { return i - (max + 1); } else { return i; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static int normalize(int i, int bitCount) { int max = 0xffffffff >>> (32 - bitCount); if (i > max) { throw new IllegalArgumentException("The integer cannot fit to bit boundaries."); } if (i > (max >>> 1)) { return i - (max + 1); } else { return i; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToByte() { byte[] baReverse = {(byte) 0x93, (byte) 0x8a, (byte) 0xac, 0x7e}; Assert.assertArrayEquals(Bytes.toByteArray(bigEndianInt, true), ba); Assert.assertArrayEquals(Bytes.toByteArray(bigEndianInt, false), baReverse); Assert.assertArrayEquals(Bytes.toByteArray(littleEndianInt, false), ba); Assert.assertArrayEquals(Bytes.toByteArray(littleEndianInt, true), baReverse); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToByteShort() { byte[] baShort = {0x43, (byte) 0xac}; byte[] baShortReverse = {(byte) 0xac, 0x43}; short bigEndianShort = 0x43ac; short littleEndianShort = (short) 0xac43; Assert.assertArrayEquals(Bytes.toByteArray(bigEndianShort, true), baShort); Assert.assertArrayEquals(Bytes.toByteArray(bigEndianShort, false), baShortReverse); Assert.assertArrayEquals(Bytes.toByteArray(littleEndianShort, false), baShort); Assert.assertArrayEquals(Bytes.toByteArray(littleEndianShort, true), baShortReverse); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToIntArray() { int[] intArrBig = {0x7eac8a93, 0x66AABBCC}; int[] intArrLittle = {0x938aac7e, 0xCCBBAA66,}; byte[] barr = {0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, false), intArrLittle); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 4, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 4, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA}; intArrBig = new int[]{0x7eac8a, 0x9366aa}; intArrLittle = new int[]{0x8aac7e, 0xaa6693}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 3, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 3, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA}; intArrBig = new int[]{0x7eac, 0x8a93, 0x66aa}; intArrLittle = new int[]{0xac7e, 0x938a, 0xaa66}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 2, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 2, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a}; intArrBig = new int[]{0x7e, 0xac, 0x8a}; intArrLittle = new int[]{0x7e, 0xac, 0x8a}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 1, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 1, false), intArrLittle); }
|
public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; }
|
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; } }
|
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; } }
|
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToByteArrayShort() { byte[] baBe = {0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93}; byte[] baLe = {(byte) 0xac, 0x7e, (byte) 0x93, (byte) 0x8a}; short[] sarr = {0x7eac, (short) 0x8a93}; Assert.assertArrayEquals(Bytes.toByteArray(sarr, sarr.length, true), baBe); Assert.assertArrayEquals(Bytes.toByteArray(sarr, sarr.length, false), baLe); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testByteArray() { Assert.assertArrayEquals(Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE, 0x45), new byte[]{(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE, 0x45}); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToByteArrayInt() { int[] sarr4 = {0xCAFEBABE, 0xDEADBEEF}; int[] sarr3 = {0xCAFEBA, 0xDEADBE}; int[] sarr2 = {0xCAFE, 0xDEAD}; int[] sarr1 = {0xCA, 0xFE, 0xBA, 0xBE}; Assert.assertArrayEquals(Bytes.toByteArray(sarr4, sarr4.length, 4, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE, 0xDE, 0xAD, 0xBE, 0xEF)); Assert.assertArrayEquals(Bytes.toByteArray(sarr4, sarr4.length, 4, false), Bytes.toByteArray(0xBE, 0xBA, 0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr3, sarr3.length, 3, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xDE, 0xAD, 0xBE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr3, sarr3.length, 3, false), Bytes.toByteArray(0xBA, 0xFE, 0xCA, 0xBE, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr2, sarr2.length, 2, true), Bytes.toByteArray(0xCA, 0xFE, 0xDE, 0xAD)); Assert.assertArrayEquals(Bytes.toByteArray(sarr2, sarr2.length, 2, false), Bytes.toByteArray(0xFE, 0xCA, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr1, sarr1.length, 1, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr1, sarr1.length, 1, false), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE)); }
|
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testToShort() { byte[] barr = {0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93}; short[] sarrBe = {0x7eac, (short) 0x8a93}; short[] sarrLe = {(short) 0xac7e, (short) 0x938a}; Assert.assertArrayEquals(Bytes.toShortArray(barr, barr.length, true), sarrBe); Assert.assertArrayEquals(Bytes.toShortArray(barr, barr.length, false), sarrLe); }
|
public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 2); short[] result = new short[size / 2]; int i = 0; for (int j = 0; j < size; j += 2) { if (bigEndian) { result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff); } else { result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff); } } return result; }
|
Bytes { public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 2); short[] result = new short[size / 2]; int i = 0; for (int j = 0; j < size; j += 2) { if (bigEndian) { result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff); } else { result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff); } } return result; } }
|
Bytes { public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 2); short[] result = new short[size / 2]; int i = 0; for (int j = 0; j < size; j += 2) { if (bigEndian) { result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff); } else { result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff); } } return result; } }
|
Bytes { public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 2); short[] result = new short[size / 2]; int i = 0; for (int j = 0; j < size; j += 2) { if (bigEndian) { result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff); } else { result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff); } } return result; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 2); short[] result = new short[size / 2]; int i = 0; for (int j = 0; j < size; j += 2) { if (bigEndian) { result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff); } else { result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff); } } return result; } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void stemEndingTest() { TurkishMorphology morphology = TurkishMorphology.builder() .setLexicon("Türkiye", "Bayram").build(); List<String> endings = Lists.newArrayList("ında", "de"); StemEndingGraph graph = new StemEndingGraph(morphology, endings); CharacterGraphDecoder spellChecker = new CharacterGraphDecoder(graph.stemGraph); List<ScoredItem<String>> res = spellChecker.getSuggestionsWithScores("türkiyede"); assertContainsAll(res, "türkiyede"); }
|
public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); }
|
CharacterGraphDecoder { public List<ScoredItem<String>> getSuggestionsWithScores(String input) { Decoder decoder = new Decoder(); return getMatches(input, decoder); } CharacterGraphDecoder(float maxPenalty); CharacterGraphDecoder(); CharacterGraphDecoder(CharacterGraph graph); CharacterGraphDecoder(float maxPenalty, Map<Character, String> nearKeyMap); CharacterGraph getGraph(); void addWord(String word); void addWords(String... words); void addWords(List<String> vocabulary); List<ScoredItem<String>> getSuggestionsWithScores(String input); List<ScoredItem<String>> getSuggestionsWithScores(String input, CharMatcher matcher); FloatValueMap<String> decode(String input); List<String> getSuggestions(String input); List<String> getSuggestions(String input, CharMatcher matcher); List<String> getSuggestionsSorted(String input); static final Map<Character, String> TURKISH_FQ_NEAR_KEY_MAP; static final Map<Character, String> TURKISH_Q_NEAR_KEY_MAP; static final DiacriticsIgnoringMatcher DIACRITICS_IGNORING_MATCHER; final float maxPenalty; final boolean checkNearKeySubstitution; public Map<Character, String> nearKeyMap; }
|
@Test public void toHextTest() { assertEquals(toHex((byte) 0), "0"); assertEquals(toHex((byte) 1), "1"); assertEquals(toHex((byte) 15), "f"); assertEquals(toHex((byte) 127), "7f"); assertEquals(toHex((byte) 0xcc), "cc"); assertEquals(toHex(new byte[]{(byte) 0x01}), "1"); assertEquals(toHex(new byte[]{(byte) 0xcc}), "cc"); assertEquals(toHex(new byte[]{0x00, 0x00}), "0"); assertEquals(toHex(new byte[]{0x01, 0x1f, (byte) 0xcc}), "11fcc"); assertEquals(toHex(new byte[]{0x01, 0x1f, 0x00}), "11f00"); assertEquals(toHex(new byte[]{0x00, 0x01, 0x1f, 0x01, 0x00, 0x00}), "11f010000"); }
|
public static String toHex(byte b) { return String.format("%x", b); }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test(expected = NullPointerException.class) public void toHexExceptionTest() { toHex(null); }
|
public static String toHex(byte b) { return String.format("%x", b); }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static String toHex(byte b) { return String.format("%x", b); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void toHexWithZerostWithZerosTest() { assertEquals(toHexWithZeros((byte) 0), "00"); assertEquals(toHexWithZeros((byte) 1), "01"); assertEquals(toHexWithZeros((byte) 15), "0f"); assertEquals(toHexWithZeros((byte) 127), "7f"); assertEquals(toHexWithZeros((byte) 0xcc), "cc"); assertEquals(toHexWithZeros(new byte[]{(byte) 0x01}), "01"); assertEquals(toHexWithZeros(new byte[]{(byte) 0xcc}), "cc"); assertEquals(toHexWithZeros(new byte[]{0x00, 0x00}), "0000"); assertEquals(toHexWithZeros(new byte[]{0x01, 0x1f, (byte) 0xcc}), "011fcc"); assertEquals(toHexWithZeros(new byte[]{0x01, 0x1f, 0x00}), "011f00"); assertEquals(toHexWithZeros(new byte[]{0x00, 0x01, 0x1f, 0x01, 0x00, 0x00}), "00011f010000"); }
|
public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test(expected = NullPointerException.class) public void toHexWithZerosExceptionTest() { toHexWithZeros(null); }
|
public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static String toHexWithZeros(byte b) { if (b == 0) { return "00"; } String s = toHex(b); if (s.length() == 1) { return "0" + s; } else { return s; } } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test @Ignore(value = "Not a test") public void dump() throws IOException { Bytes.hexDump(new byte[]{0x01}, 20); }
|
public static void hexDump(OutputStream os, byte[] bytes, int columns) throws IOException { Dumper.hexDump(new ByteArrayInputStream(bytes, 0, bytes.length), os, columns, bytes.length); }
|
Bytes { public static void hexDump(OutputStream os, byte[] bytes, int columns) throws IOException { Dumper.hexDump(new ByteArrayInputStream(bytes, 0, bytes.length), os, columns, bytes.length); } }
|
Bytes { public static void hexDump(OutputStream os, byte[] bytes, int columns) throws IOException { Dumper.hexDump(new ByteArrayInputStream(bytes, 0, bytes.length), os, columns, bytes.length); } }
|
Bytes { public static void hexDump(OutputStream os, byte[] bytes, int columns) throws IOException { Dumper.hexDump(new ByteArrayInputStream(bytes, 0, bytes.length), os, columns, bytes.length); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
|
Bytes { public static void hexDump(OutputStream os, byte[] bytes, int columns) throws IOException { Dumper.hexDump(new ByteArrayInputStream(bytes, 0, bytes.length), os, columns, bytes.length); } static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
boolean bigEndian); static int[] toReducedBitIntArray(
byte[] ba,
final int amount,
int bytePerInteger,
int bitAmount,
boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testUtf8() throws IOException { String content = new SimpleTextReader(utf8_tr_with_bom.getFile(), "utf-8").asString(); assertEquals(content, "\u015fey"); }
|
public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
@Test public void multilineTest() throws IOException { List<String> list = new SimpleTextReader(multi_line_text_file.getFile()).asStringList(); assertEquals(list.size(), 17); assertEquals(list.get(1), "uno"); assertEquals(list.get(2), " dos"); }
|
public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
@Test public void multilineConstarintTest() throws IOException { List<String> list = new SimpleTextReader.Builder(multi_line_text_file.getFile()) .allowMatchingRegexp("^[^#]") .ignoreWhiteSpaceLines() .trim() .build() .asStringList(); assertEquals(list.size(), 12); assertEquals(list.get(0), "uno"); assertEquals(list.get(1), "dos"); }
|
public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
SimpleTextReader implements AutoCloseable { public List<String> asStringList() throws IOException { return IOs.readAsStringList(getReader(), trim, filters.toArray(new Filter[0])); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
@Test public void asStringTest() throws IOException { String a = new SimpleTextReader(multi_line_text_file.getFile()).asString(); System.out.println(a); }
|
public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
SimpleTextReader implements AutoCloseable { public String asString() throws IOException { String res = IOs.readAsString(getReader()); if (trim) { return res.trim(); } else { return res; } } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
@Test public void iterableTest() throws IOException { int i = 0; for (String s : new SimpleTextReader(multi_line_text_file.getFile()).getIterableReader()) { if (i == 1) { assertEquals(s.trim(), "uno"); } if (i == 2) { assertEquals(s.trim(), "dos"); } if (i == 3) { assertEquals(s.trim(), "tres"); } i++; } assertEquals(i, 17); }
|
public IterableLineReader getIterableReader() throws IOException { return new IterableLineReader(getReader(), trim, filters); }
|
SimpleTextReader implements AutoCloseable { public IterableLineReader getIterableReader() throws IOException { return new IterableLineReader(getReader(), trim, filters); } }
|
SimpleTextReader implements AutoCloseable { public IterableLineReader getIterableReader() throws IOException { return new IterableLineReader(getReader(), trim, filters); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); }
|
SimpleTextReader implements AutoCloseable { public IterableLineReader getIterableReader() throws IOException { return new IterableLineReader(getReader(), trim, filters); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
SimpleTextReader implements AutoCloseable { public IterableLineReader getIterableReader() throws IOException { return new IterableLineReader(getReader(), trim, filters); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(String fileName); SimpleTextReader(String fileName, String encoding); SimpleTextReader(InputStream is); SimpleTextReader(InputStream is, String encoding); static SimpleTextReader trimmingUTF8Reader(File file); static LineIterator trimmingUTF8LineIterator(File file); static IterableLineReader trimmingUTF8IterableLineReader(File file); static SimpleTextReader trimmingReader(InputStream is, String encoding); static LineIterator trimmingLineIterator(InputStream is, String encoding); static IterableLineReader trimmingIterableLineReader(InputStream is, String encoding); String getEncoding(); SimpleTextReader cloneForStream(InputStream is); SimpleTextReader cloneForFile(File file); byte[] asByteArray(); String asString(); List<String> asStringList(); IterableLineReader getIterableReader(); LineIterator getLineIterator(); long countLines(); void close(); }
|
@Test public void testGeneration1() { WordGenerator wordGenerator = new WordGenerator(getMorphotactics("elma")); List<String> morphemes = Lists.newArrayList("A3pl", "P1pl"); List<Result> results = wordGenerator.generate( "elma", morphemes ); Assert.assertTrue(results.size() > 0); Assert.assertEquals("elmalarımız", results.get(0).surface); }
|
public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTransitions.getPrefixMatches(stem, false); return generate(stem, candidates, morphemes); }
|
WordGenerator { public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTransitions.getPrefixMatches(stem, false); return generate(stem, candidates, morphemes); } }
|
WordGenerator { public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTransitions.getPrefixMatches(stem, false); return generate(stem, candidates, morphemes); } WordGenerator(TurkishMorphotactics morphotactics); }
|
WordGenerator { public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTransitions.getPrefixMatches(stem, false); return generate(stem, candidates, morphemes); } WordGenerator(TurkishMorphotactics morphotactics); static WordGenerator forDebug(TurkishMorphotactics morphotactics); AnalysisDebugData getDebugData(); List<Result> generate(String stem, List<String> morphemeIds); List<Result> generate(DictionaryItem item, List<Morpheme> morphemes); List<Result> generate(DictionaryItem item, Morpheme... morphemes); List<Result> generate(DictionaryItem item, String... morphemeIds); }
|
WordGenerator { public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTransitions.getPrefixMatches(stem, false); return generate(stem, candidates, morphemes); } WordGenerator(TurkishMorphotactics morphotactics); static WordGenerator forDebug(TurkishMorphotactics morphotactics); AnalysisDebugData getDebugData(); List<Result> generate(String stem, List<String> morphemeIds); List<Result> generate(DictionaryItem item, List<Morpheme> morphemes); List<Result> generate(DictionaryItem item, Morpheme... morphemes); List<Result> generate(DictionaryItem item, String... morphemeIds); }
|
@Test public void testCompareTo() { Hash a = Hash.fromString("000000"); Hash b = Hash.fromString("000123"); assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); }
|
@Override public int compareTo(Hash o) { if (bytes.length != o.bytes.length) { return bytes.length - o.bytes.length; } BigInteger a = new BigInteger(1, bytes); BigInteger b = new BigInteger(1, o.bytes); return a.compareTo(b); }
|
Hash implements Comparable<Hash> { @Override public int compareTo(Hash o) { if (bytes.length != o.bytes.length) { return bytes.length - o.bytes.length; } BigInteger a = new BigInteger(1, bytes); BigInteger b = new BigInteger(1, o.bytes); return a.compareTo(b); } }
|
Hash implements Comparable<Hash> { @Override public int compareTo(Hash o) { if (bytes.length != o.bytes.length) { return bytes.length - o.bytes.length; } BigInteger a = new BigInteger(1, bytes); BigInteger b = new BigInteger(1, o.bytes); return a.compareTo(b); } Hash(byte[] bytes); }
|
Hash implements Comparable<Hash> { @Override public int compareTo(Hash o) { if (bytes.length != o.bytes.length) { return bytes.length - o.bytes.length; } BigInteger a = new BigInteger(1, bytes); BigInteger b = new BigInteger(1, o.bytes); return a.compareTo(b); } Hash(byte[] bytes); byte[] getBytes(); String getBytesAsString(); static Hash fromString(String str); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(Hash o); static Hash hash(Object input, HashAlgorithm alg); static Hash hash160(byte[] bytes); static Hash hash256(byte[] bytes); static Hash sha256(byte[] bytes); static Hash ripemd160(byte[] bytes); static Hash sha1(byte[] bytes); static Hash hash160(Hash obj); static Hash hash256(Hash obj); static Hash ripemd160(Hash obj); static Hash sha256(Hash obj); static Hash sha1(Hash obj); static Hash hash160(String obj); static Hash hash256(String obj); static Hash ripemd160(String obj); static Hash sha256(String obj); static Hash sha1(String obj); static Hash hash160(Boolean obj); static Hash hash256(Boolean obj); static Hash ripemd160(Boolean obj); static Hash sha256(Boolean obj); static Hash sha1(Boolean obj); static Hash hash160(Number obj); static Hash hash256(Number obj); static Hash ripemd160(Number obj); static Hash sha256(Number obj); static Hash sha1(Number obj); }
|
Hash implements Comparable<Hash> { @Override public int compareTo(Hash o) { if (bytes.length != o.bytes.length) { return bytes.length - o.bytes.length; } BigInteger a = new BigInteger(1, bytes); BigInteger b = new BigInteger(1, o.bytes); return a.compareTo(b); } Hash(byte[] bytes); byte[] getBytes(); String getBytesAsString(); static Hash fromString(String str); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(Hash o); static Hash hash(Object input, HashAlgorithm alg); static Hash hash160(byte[] bytes); static Hash hash256(byte[] bytes); static Hash sha256(byte[] bytes); static Hash ripemd160(byte[] bytes); static Hash sha1(byte[] bytes); static Hash hash160(Hash obj); static Hash hash256(Hash obj); static Hash ripemd160(Hash obj); static Hash sha256(Hash obj); static Hash sha1(Hash obj); static Hash hash160(String obj); static Hash hash256(String obj); static Hash ripemd160(String obj); static Hash sha256(String obj); static Hash sha1(String obj); static Hash hash160(Boolean obj); static Hash hash256(Boolean obj); static Hash ripemd160(Boolean obj); static Hash sha256(Boolean obj); static Hash sha1(Boolean obj); static Hash hash160(Number obj); static Hash hash256(Number obj); static Hash ripemd160(Number obj); static Hash sha256(Number obj); static Hash sha1(Number obj); }
|
@Test public void changePassword() throws KeyStoreException { ECKeyStore ks = new ECKeyStore(); PrivateKey k1 = PrivateKey.fresh(NetworkType.TESTNET); String alias1 = ks.addKey(k1); ks.changePassword("test".toCharArray()); PrivateKey k2 = ks.getKey(ECKeyStore.getUniqueID(k1)); assertTrue(ks.containsKey(alias1)); assertArrayEquals(k1.getBytes(), k2.getBytes()); assertEquals(k1.getNetworkType(), k2.getNetworkType()); }
|
public void changePassword(char[] password) throws KeyStoreException { try { for (String alias : Collections.list(ks.aliases())) { Entry entry = ks.getEntry(alias, new PasswordProtection(this.password)); ks.setEntry(alias, entry, new PasswordProtection(password)); } Arrays.fill(this.password, '0'); this.password = Arrays.copyOf(password, password.length); } catch (NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new KeyStoreException(e); } }
|
ECKeyStore { public void changePassword(char[] password) throws KeyStoreException { try { for (String alias : Collections.list(ks.aliases())) { Entry entry = ks.getEntry(alias, new PasswordProtection(this.password)); ks.setEntry(alias, entry, new PasswordProtection(password)); } Arrays.fill(this.password, '0'); this.password = Arrays.copyOf(password, password.length); } catch (NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new KeyStoreException(e); } } }
|
ECKeyStore { public void changePassword(char[] password) throws KeyStoreException { try { for (String alias : Collections.list(ks.aliases())) { Entry entry = ks.getEntry(alias, new PasswordProtection(this.password)); ks.setEntry(alias, entry, new PasswordProtection(password)); } Arrays.fill(this.password, '0'); this.password = Arrays.copyOf(password, password.length); } catch (NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new KeyStoreException(e); } } ECKeyStore(); ECKeyStore(char[] password); ECKeyStore(InputStream input, char[] password); }
|
ECKeyStore { public void changePassword(char[] password) throws KeyStoreException { try { for (String alias : Collections.list(ks.aliases())) { Entry entry = ks.getEntry(alias, new PasswordProtection(this.password)); ks.setEntry(alias, entry, new PasswordProtection(password)); } Arrays.fill(this.password, '0'); this.password = Arrays.copyOf(password, password.length); } catch (NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new KeyStoreException(e); } } ECKeyStore(); ECKeyStore(char[] password); ECKeyStore(InputStream input, char[] password); static String getUniqueID(PrivateKey key); String addKey(PrivateKey key); PrivateKey getKey(String keyID); boolean containsKey(String keyID); void store(File ksFile); void changePassword(char[] password); }
|
ECKeyStore { public void changePassword(char[] password) throws KeyStoreException { try { for (String alias : Collections.list(ks.aliases())) { Entry entry = ks.getEntry(alias, new PasswordProtection(this.password)); ks.setEntry(alias, entry, new PasswordProtection(password)); } Arrays.fill(this.password, '0'); this.password = Arrays.copyOf(password, password.length); } catch (NoSuchAlgorithmException | UnrecoverableEntryException e) { throw new KeyStoreException(e); } } ECKeyStore(); ECKeyStore(char[] password); ECKeyStore(InputStream input, char[] password); static String getUniqueID(PrivateKey key); String addKey(PrivateKey key); PrivateKey getKey(String keyID); boolean containsKey(String keyID); void store(File ksFile); void changePassword(char[] password); }
|
@Test public void testBrokenFile() throws Exception { MemoryMetricsCollectorWithProcFile collector = new MemoryMetricsCollectorWithProcFile() .setPath(createFile("I am a weird android manufacturer")); MemoryMetrics snapshot = new MemoryMetrics(); collector.getSnapshot(snapshot); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(snapshot.vmSizeKb).isEqualTo(-1); assertThat(snapshot.vmRssKb).isEqualTo(-1); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
@Test public void testSetWithoutAttribution() { WakeLockMetrics metrics = new WakeLockMetrics(); metrics.heldTimeMs = 10l; metrics.acquiredCount = 31; WakeLockMetrics alternate = new WakeLockMetrics(); alternate.set(metrics); assertThat(alternate).isEqualTo(metrics); }
|
@Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }
|
@Test public void testSetWithAttribution() { WakeLockMetrics metrics = new WakeLockMetrics(true); metrics.heldTimeMs = 10l; metrics.acquiredCount = 23; metrics.tagTimeMs.put("TestWakeLock", 10l); WakeLockMetrics alternate = new WakeLockMetrics(true); alternate.set(metrics); assertThat(alternate).isEqualTo(metrics); }
|
@Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics set(WakeLockMetrics b) { heldTimeMs = b.heldTimeMs; acquiredCount = b.acquiredCount; if (b.isAttributionEnabled && isAttributionEnabled) { tagTimeMs.clear(); tagTimeMs.putAll(b.tagTimeMs); } return this; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }
|
@Test public void testSumWithAttribution() { WakeLockMetrics metricsA = new WakeLockMetrics(true); metricsA.heldTimeMs = 20l; metricsA.acquiredCount = 4; metricsA.tagTimeMs.put("TestWakeLock1", 10l); metricsA.tagTimeMs.put("TestWakeLock3", 10l); WakeLockMetrics metricsB = new WakeLockMetrics(true); metricsB.heldTimeMs = 20l; metricsB.acquiredCount = 5; metricsB.tagTimeMs.put("TestWakeLock2", 10l); metricsB.tagTimeMs.put("TestWakeLock3", 10l); WakeLockMetrics output = new WakeLockMetrics(true); output.tagTimeMs.put("Test", 1L); output.heldTimeMs = 100L; output.acquiredCount = 442; metricsA.sum(metricsB, output); WakeLockMetrics expectedOutput = new WakeLockMetrics(true); expectedOutput.heldTimeMs = 40l; expectedOutput.acquiredCount = 9; expectedOutput.tagTimeMs.put("TestWakeLock1", 10l); expectedOutput.tagTimeMs.put("TestWakeLock2", 10l); expectedOutput.tagTimeMs.put("TestWakeLock3", 20l); assertThat(output).isEqualTo(expectedOutput); }
|
@Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; } }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs + b.heldTimeMs; output.acquiredCount = acquiredCount + b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); output.tagTimeMs.put( tag, tagTimeMs.valueAt(i) + (currentTimeMs == null ? 0 : currentTimeMs)); } for (int i = 0, size = b.tagTimeMs.size(); i < size; i++) { String tag = b.tagTimeMs.keyAt(i); if (tagTimeMs.get(tag) == null) { output.tagTimeMs.put(tag, b.tagTimeMs.valueAt(i)); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }
|
@Test public void testDiffWithAttribution() { WakeLockMetrics metricsA = new WakeLockMetrics(true); metricsA.heldTimeMs = 25l; metricsA.acquiredCount = 100; metricsA.tagTimeMs.put("TestWakeLock1", 15l); metricsA.tagTimeMs.put("TestWakeLock2", 10l); WakeLockMetrics metricsB = new WakeLockMetrics(true); metricsB.heldTimeMs = 20l; metricsB.acquiredCount = 90; metricsB.tagTimeMs.put("TestWakeLock1", 10l); metricsB.tagTimeMs.put("TestWakeLock2", 10l); WakeLockMetrics output = new WakeLockMetrics(true); output.tagTimeMs.put("Test", 1L); output.acquiredCount = 341; output.heldTimeMs = 100L; metricsA.diff(metricsB, output); WakeLockMetrics expectedOutput = new WakeLockMetrics(true); expectedOutput.acquiredCount = 10; expectedOutput.heldTimeMs = 5l; expectedOutput.tagTimeMs.put("TestWakeLock1", 5l); assertThat(output).isEqualTo(expectedOutput); }
|
@Override public WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs - b.heldTimeMs; output.acquiredCount = acquiredCount - b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); long difference = tagTimeMs.valueAt(i) - (currentTimeMs == null ? 0 : currentTimeMs); if (difference != 0) { output.tagTimeMs.put(tag, difference); } } } } return output; }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs - b.heldTimeMs; output.acquiredCount = acquiredCount - b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); long difference = tagTimeMs.valueAt(i) - (currentTimeMs == null ? 0 : currentTimeMs); if (difference != 0) { output.tagTimeMs.put(tag, difference); } } } } return output; } }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs - b.heldTimeMs; output.acquiredCount = acquiredCount - b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); long difference = tagTimeMs.valueAt(i) - (currentTimeMs == null ? 0 : currentTimeMs); if (difference != 0) { output.tagTimeMs.put(tag, difference); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs - b.heldTimeMs; output.acquiredCount = acquiredCount - b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); long difference = tagTimeMs.valueAt(i) - (currentTimeMs == null ? 0 : currentTimeMs); if (difference != 0) { output.tagTimeMs.put(tag, difference); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { @Override public WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output) { if (output == null) { output = new WakeLockMetrics(isAttributionEnabled); } if (b == null) { output.set(this); } else { output.heldTimeMs = heldTimeMs - b.heldTimeMs; output.acquiredCount = acquiredCount - b.acquiredCount; if (output.isAttributionEnabled) { output.tagTimeMs.clear(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { String tag = tagTimeMs.keyAt(i); Long currentTimeMs = b.tagTimeMs.get(tag); long difference = tagTimeMs.valueAt(i) - (currentTimeMs == null ? 0 : currentTimeMs); if (difference != 0) { output.tagTimeMs.put(tag, difference); } } } } return output; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }
|
@Test public void testAttributionToJSONObject() throws JSONException { WakeLockMetrics metrics = new WakeLockMetrics(); metrics.isAttributionEnabled = true; metrics.acquiredCount = 2; metrics.heldTimeMs = 400; metrics.tagTimeMs.put("Test", 100l); JSONObject attribution = metrics.attributionToJSONObject(); assertThat(attribution.length()).isEqualTo(1); assertThat(attribution.has("Test")).isTrue(); assertThat(attribution.getLong("Test")).isEqualTo(100); }
|
public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); }
|
WakeLockMetrics extends SystemMetrics<WakeLockMetrics> { public @Nullable JSONObject attributionToJSONObject() throws JSONException { if (!isAttributionEnabled) { return null; } JSONObject attribution = new JSONObject(); for (int i = 0, size = tagTimeMs.size(); i < size; i++) { long currentTagTimeMs = tagTimeMs.valueAt(i); if (currentTagTimeMs > 0) { attribution.put(tagTimeMs.keyAt(i), currentTagTimeMs); } } return attribution; } WakeLockMetrics(); WakeLockMetrics(boolean isAttributionEnabled); @Override WakeLockMetrics sum(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics diff(@Nullable WakeLockMetrics b, @Nullable WakeLockMetrics output); @Override WakeLockMetrics set(WakeLockMetrics b); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Nullable JSONObject attributionToJSONObject(); public boolean isAttributionEnabled; final SimpleArrayMap<String, Long> tagTimeMs; public long heldTimeMs; public long acquiredCount; }
|
@Test(expected = RuntimeException.class) public void testMetricsWithTheSameTag() { CompositeMetricsSerializer serializer = new CompositeMetricsSerializer(); serializer.addMetricsSerializer(A.class, new ASerializer()); serializer.addMetricsSerializer(B.class, new BSerializer()); }
|
public <T extends SystemMetrics<T>> CompositeMetricsSerializer addMetricsSerializer( Class<T> metricsClass, SystemMetricsSerializer<T> serializer) { Class<? extends SystemMetrics<?>> existingClass = mDeserializerClasses.get(serializer.getTag()); if (existingClass != null && existingClass != metricsClass) { throw new RuntimeException( "Serializers " + existingClass.getCanonicalName() + " and " + metricsClass.getCanonicalName() + " have a conflicting tag: `" + serializer.getTag() + "`."); } mSerializers.put(metricsClass, serializer); mDeserializers.put(serializer.getTag(), serializer); mDeserializerClasses.put(serializer.getTag(), metricsClass); return this; }
|
CompositeMetricsSerializer extends SystemMetricsSerializer<CompositeMetrics> { public <T extends SystemMetrics<T>> CompositeMetricsSerializer addMetricsSerializer( Class<T> metricsClass, SystemMetricsSerializer<T> serializer) { Class<? extends SystemMetrics<?>> existingClass = mDeserializerClasses.get(serializer.getTag()); if (existingClass != null && existingClass != metricsClass) { throw new RuntimeException( "Serializers " + existingClass.getCanonicalName() + " and " + metricsClass.getCanonicalName() + " have a conflicting tag: `" + serializer.getTag() + "`."); } mSerializers.put(metricsClass, serializer); mDeserializers.put(serializer.getTag(), serializer); mDeserializerClasses.put(serializer.getTag(), metricsClass); return this; } }
|
CompositeMetricsSerializer extends SystemMetricsSerializer<CompositeMetrics> { public <T extends SystemMetrics<T>> CompositeMetricsSerializer addMetricsSerializer( Class<T> metricsClass, SystemMetricsSerializer<T> serializer) { Class<? extends SystemMetrics<?>> existingClass = mDeserializerClasses.get(serializer.getTag()); if (existingClass != null && existingClass != metricsClass) { throw new RuntimeException( "Serializers " + existingClass.getCanonicalName() + " and " + metricsClass.getCanonicalName() + " have a conflicting tag: `" + serializer.getTag() + "`."); } mSerializers.put(metricsClass, serializer); mDeserializers.put(serializer.getTag(), serializer); mDeserializerClasses.put(serializer.getTag(), metricsClass); return this; } }
|
CompositeMetricsSerializer extends SystemMetricsSerializer<CompositeMetrics> { public <T extends SystemMetrics<T>> CompositeMetricsSerializer addMetricsSerializer( Class<T> metricsClass, SystemMetricsSerializer<T> serializer) { Class<? extends SystemMetrics<?>> existingClass = mDeserializerClasses.get(serializer.getTag()); if (existingClass != null && existingClass != metricsClass) { throw new RuntimeException( "Serializers " + existingClass.getCanonicalName() + " and " + metricsClass.getCanonicalName() + " have a conflicting tag: `" + serializer.getTag() + "`."); } mSerializers.put(metricsClass, serializer); mDeserializers.put(serializer.getTag(), serializer); mDeserializerClasses.put(serializer.getTag(), metricsClass); return this; } CompositeMetricsSerializer addMetricsSerializer(
Class<T> metricsClass, SystemMetricsSerializer<T> serializer); @Override long getTag(); @Override void serializeContents(CompositeMetrics metrics, DataOutput output); @Override boolean deserializeContents(CompositeMetrics metrics, DataInput input); }
|
CompositeMetricsSerializer extends SystemMetricsSerializer<CompositeMetrics> { public <T extends SystemMetrics<T>> CompositeMetricsSerializer addMetricsSerializer( Class<T> metricsClass, SystemMetricsSerializer<T> serializer) { Class<? extends SystemMetrics<?>> existingClass = mDeserializerClasses.get(serializer.getTag()); if (existingClass != null && existingClass != metricsClass) { throw new RuntimeException( "Serializers " + existingClass.getCanonicalName() + " and " + metricsClass.getCanonicalName() + " have a conflicting tag: `" + serializer.getTag() + "`."); } mSerializers.put(metricsClass, serializer); mDeserializers.put(serializer.getTag(), serializer); mDeserializerClasses.put(serializer.getTag(), metricsClass); return this; } CompositeMetricsSerializer addMetricsSerializer(
Class<T> metricsClass, SystemMetricsSerializer<T> serializer); @Override long getTag(); @Override void serializeContents(CompositeMetrics metrics, DataOutput output); @Override boolean deserializeContents(CompositeMetrics metrics, DataInput input); }
|
@Test public void testSerializeContents() throws Exception { T instance = createInitializedInstance(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); getSerializer().serializeContents(instance, new DataOutputStream(baos)); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); T output = createInstance(); assertThat(getSerializer().deserializeContents(output, new DataInputStream(bais))).isTrue(); assertThat(output).isEqualTo(instance); }
|
public abstract void serializeContents(T metrics, DataOutput output) throws IOException;
|
SystemMetricsSerializer { public abstract void serializeContents(T metrics, DataOutput output) throws IOException; }
|
SystemMetricsSerializer { public abstract void serializeContents(T metrics, DataOutput output) throws IOException; }
|
SystemMetricsSerializer { public abstract void serializeContents(T metrics, DataOutput output) throws IOException; final void serialize(T metrics, DataOutput output); final boolean deserialize(T metrics, DataInput input); abstract long getTag(); abstract void serializeContents(T metrics, DataOutput output); abstract boolean deserializeContents(T metrics, DataInput input); }
|
SystemMetricsSerializer { public abstract void serializeContents(T metrics, DataOutput output) throws IOException; final void serialize(T metrics, DataOutput output); final boolean deserialize(T metrics, DataInput input); abstract long getTag(); abstract void serializeContents(T metrics, DataOutput output); abstract boolean deserializeContents(T metrics, DataInput input); }
|
@Test public void testRandomContents() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream daos = new DataOutputStream(baos); daos.writeChars("Random test string that doesn't make any sense"); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); T output = createInstance(); assertThat(getSerializer().deserialize(output, dis)).isFalse(); }
|
public final boolean deserialize(T metrics, DataInput input) throws IOException { if (input.readShort() != MAGIC || input.readShort() != VERSION || input.readLong() != getTag()) { return false; } return deserializeContents(metrics, input); }
|
SystemMetricsSerializer { public final boolean deserialize(T metrics, DataInput input) throws IOException { if (input.readShort() != MAGIC || input.readShort() != VERSION || input.readLong() != getTag()) { return false; } return deserializeContents(metrics, input); } }
|
SystemMetricsSerializer { public final boolean deserialize(T metrics, DataInput input) throws IOException { if (input.readShort() != MAGIC || input.readShort() != VERSION || input.readLong() != getTag()) { return false; } return deserializeContents(metrics, input); } }
|
SystemMetricsSerializer { public final boolean deserialize(T metrics, DataInput input) throws IOException { if (input.readShort() != MAGIC || input.readShort() != VERSION || input.readLong() != getTag()) { return false; } return deserializeContents(metrics, input); } final void serialize(T metrics, DataOutput output); final boolean deserialize(T metrics, DataInput input); abstract long getTag(); abstract void serializeContents(T metrics, DataOutput output); abstract boolean deserializeContents(T metrics, DataInput input); }
|
SystemMetricsSerializer { public final boolean deserialize(T metrics, DataInput input) throws IOException { if (input.readShort() != MAGIC || input.readShort() != VERSION || input.readLong() != getTag()) { return false; } return deserializeContents(metrics, input); } final void serialize(T metrics, DataOutput output); final boolean deserialize(T metrics, DataInput input); abstract long getTag(); abstract void serializeContents(T metrics, DataOutput output); abstract boolean deserializeContents(T metrics, DataInput input); }
|
@Test public void testInvalidMetricsSkipped() { TimeMetrics timeMetrics = new TimeMetrics(); timeMetrics.realtimeMs = 100; timeMetrics.uptimeMs = 10; CompositeMetrics metrics = new CompositeMetrics().putMetric(TimeMetrics.class, timeMetrics); metrics.setIsValid(TimeMetrics.class, false); mReporter.reportTo(metrics, mEvent); assertThat(mEvent.eventMap.size()).isEqualTo(0); }
|
public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event); CompositeMetricsReporter addMetricsReporter(
Class<T> metricsClass, SystemMetricsReporter<T> reporter); @Nullable T getReporter(
Class<S> metricsClass); }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event); CompositeMetricsReporter addMetricsReporter(
Class<T> metricsClass, SystemMetricsReporter<T> reporter); @Nullable T getReporter(
Class<S> metricsClass); }
|
@Test public void testValidMetricsLogged() { TimeMetrics timeMetrics = new TimeMetrics(); timeMetrics.realtimeMs = 100; timeMetrics.uptimeMs = 10; CompositeMetrics metrics = new CompositeMetrics().putMetric(TimeMetrics.class, timeMetrics); metrics.setIsValid(TimeMetrics.class, true); mReporter.reportTo(metrics, mEvent); assertThat(mEvent.eventMap.size()).isEqualTo(2); }
|
public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event); CompositeMetricsReporter addMetricsReporter(
Class<T> metricsClass, SystemMetricsReporter<T> reporter); @Nullable T getReporter(
Class<S> metricsClass); }
|
CompositeMetricsReporter implements SystemMetricsReporter<CompositeMetrics> { public void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event) { for (int i = 0; i < mMetricsReporterMap.size(); i++) { Class<? extends SystemMetrics> metricsClass = mMetricsReporterMap.keyAt(i); if (metrics.isValid(metricsClass)) { SystemMetrics systemMetrics = metrics.getMetric(metricsClass); SystemMetricsReporter reporter = mMetricsReporterMap.get(metricsClass); reporter.reportTo(systemMetrics, event); } } } void reportTo(CompositeMetrics metrics, SystemMetricsReporter.Event event); CompositeMetricsReporter addMetricsReporter(
Class<T> metricsClass, SystemMetricsReporter<T> reporter); @Nullable T getReporter(
Class<S> metricsClass); }
|
@Test public void test_blank() { collector.getSnapshot(metrics); assertThat(metrics.total.activeTimeMs).isEqualTo(0); assertThat(metrics.total.powerMah).isEqualTo(0); assertThat(metrics.total.wakeUpTimeMs).isEqualTo(0); }
|
@Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }
|
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; } }
|
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; } }
|
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; } @Override int hashCode(); synchronized void disable(); synchronized void register(SensorEventListener listener, Sensor sensor); synchronized void unregister(SensorEventListener listener, @Nullable Sensor sensor); @Override synchronized boolean getSnapshot(SensorMetrics snapshot); @Override SensorMetrics createMetrics(); }
|
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; } @Override int hashCode(); synchronized void disable(); synchronized void register(SensorEventListener listener, Sensor sensor); synchronized void unregister(SensorEventListener listener, @Nullable Sensor sensor); @Override synchronized boolean getSnapshot(SensorMetrics snapshot); @Override SensorMetrics createMetrics(); }
|
@Test public void testZeroLogging() { CameraMetrics zeroMetrics = new CameraMetrics(); ReporterEvent event = new ReporterEvent(); mCameraMetricsReporter.reportTo(zeroMetrics, event); assertThat(event.eventMap.isEmpty()).isTrue(); }
|
@Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } @Override void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event); }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } @Override void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event); static final String CAMERA_OPEN_TIME_MS; static final String CAMERA_PREVIEW_TIME_MS; }
|
@Test public void testNonZeroLogging() { CameraMetrics metrics1 = new CameraMetrics(); metrics1.cameraOpenTimeMs = 0; metrics1.cameraPreviewTimeMs = 200; ReporterEvent event = new ReporterEvent(); mCameraMetricsReporter.reportTo(metrics1, event); assertThat(event.eventMap.get(mCameraMetricsReporter.CAMERA_OPEN_TIME_MS)).isNull(); assertThat(event.eventMap.get(mCameraMetricsReporter.CAMERA_PREVIEW_TIME_MS)).isEqualTo(200L); CameraMetrics metrics2 = new CameraMetrics(); metrics2.cameraOpenTimeMs = 200; metrics2.cameraPreviewTimeMs = 400; mCameraMetricsReporter.reportTo(metrics2, event); assertThat(event.eventMap.get(mCameraMetricsReporter.CAMERA_OPEN_TIME_MS)).isEqualTo(200L); assertThat(event.eventMap.get(mCameraMetricsReporter.CAMERA_PREVIEW_TIME_MS)).isEqualTo(400L); }
|
@Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } @Override void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event); }
|
CameraMetricsReporter implements SystemMetricsReporter<CameraMetrics> { @Override public void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event) { if (metrics.cameraOpenTimeMs != 0) { event.add(CAMERA_OPEN_TIME_MS, metrics.cameraOpenTimeMs); } if (metrics.cameraPreviewTimeMs != 0) { event.add(CAMERA_PREVIEW_TIME_MS, metrics.cameraPreviewTimeMs); } } @Override void reportTo(CameraMetrics metrics, SystemMetricsReporter.Event event); static final String CAMERA_OPEN_TIME_MS; static final String CAMERA_PREVIEW_TIME_MS; }
|
@Test public void testZeroLogging() { mReporter.reportTo(mMetrics, mEvent); assertThat(mEvent.eventMap.isEmpty()).isTrue(); }
|
@Override public void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event) { JSONObject output = metrics.toJSONObject(); if (output != null && output.length() != 0) { event.add(CPU_TIME_IN_STATE_S, output.toString()); } }
|
CpuFrequencyMetricsReporter implements SystemMetricsReporter<CpuFrequencyMetrics> { @Override public void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event) { JSONObject output = metrics.toJSONObject(); if (output != null && output.length() != 0) { event.add(CPU_TIME_IN_STATE_S, output.toString()); } } }
|
CpuFrequencyMetricsReporter implements SystemMetricsReporter<CpuFrequencyMetrics> { @Override public void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event) { JSONObject output = metrics.toJSONObject(); if (output != null && output.length() != 0) { event.add(CPU_TIME_IN_STATE_S, output.toString()); } } }
|
CpuFrequencyMetricsReporter implements SystemMetricsReporter<CpuFrequencyMetrics> { @Override public void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event) { JSONObject output = metrics.toJSONObject(); if (output != null && output.length() != 0) { event.add(CPU_TIME_IN_STATE_S, output.toString()); } } @Override void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event); }
|
CpuFrequencyMetricsReporter implements SystemMetricsReporter<CpuFrequencyMetrics> { @Override public void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event) { JSONObject output = metrics.toJSONObject(); if (output != null && output.length() != 0) { event.add(CPU_TIME_IN_STATE_S, output.toString()); } } @Override void reportTo(CpuFrequencyMetrics metrics, SystemMetricsReporter.Event event); }
|
@Test public void testEmpty() throws Exception { QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile("")); boolean result = collector.getTotalBytes(mBytes); assertThat(result).isFalse(); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testBlank() throws Exception { QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(HEADERS + "\n")); boolean result = collector.getTotalBytes(mBytes); assertThat(result).isTrue(); assertThat(mBytes).isEqualTo(new long[8]); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testWifi() throws Exception { StringBuilder contents = new StringBuilder(); contents.append(HEADERS).append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("iface", "wlan0"); put("cnt_set", "1"); put("rx_bytes", "100"); put("tx_bytes", "200"); } })); contents.append("\n"); QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(contents.toString())); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes[WIFI | TX | FG]).isEqualTo(200); assertThat(mBytes[WIFI | RX | FG]).isEqualTo(100); assertThat(mBytes[MOBILE | TX | FG]).isEqualTo(0); assertThat(mBytes[MOBILE | RX | FG]).isEqualTo(0); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testMobile() throws Exception { StringBuilder contents = new StringBuilder(); contents.append(HEADERS).append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("iface", "rmnet0"); put("cnt_set", "1"); put("rx_bytes", "100"); put("tx_bytes", "200"); } })); contents.append("\n"); QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(contents.toString())); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes[WIFI | TX | FG]).isEqualTo(0); assertThat(mBytes[WIFI | RX | FG]).isEqualTo(0); assertThat(mBytes[MOBILE | TX | FG]).isEqualTo(200); assertThat(mBytes[MOBILE | RX | FG]).isEqualTo(100); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testUidChecks() throws Exception { StringBuilder contents = new StringBuilder(); contents.append(HEADERS).append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("uid_tag_int", "1"); put("iface", "rmnet0"); put("rx_bytes", "100"); put("tx_bytes", "200"); } })); contents.append("\n"); QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(contents.toString())); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes).isEqualTo(new long[8]); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testWhitelistedInterfaces() throws Exception { StringBuilder contents = new StringBuilder(); contents.append(HEADERS).append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("iface", "dummy0"); put("rx_bytes", "100"); put("tx_bytes", "200"); } })); contents.append("\n"); QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(contents.toString())); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes).isEqualTo(new long[8]); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testCntSet() throws Exception { StringBuilder contents = new StringBuilder(); contents.append(HEADERS).append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("iface", "rmnet0"); put("cnt_set", "1"); put("rx_bytes", "100"); put("tx_bytes", "200"); } })); contents.append("\n"); contents.append( createEntry( new HashMap<String, String>() { { put("iface", "rmnet0"); put("cnt_set", "0"); put("rx_bytes", "1"); put("tx_bytes", "2"); } })); contents.append("\n"); QTagUidNetworkBytesCollector collector = new TestableCollector().setQTagUidStatsFile(createFile(contents.toString())); assertThat(collector.getTotalBytes(mBytes)).isTrue(); long[] expected = new long[8]; Arrays.fill(expected, 0); expected[MOBILE | TX | FG] = 200; expected[MOBILE | RX | FG] = 100; expected[MOBILE | TX | BG] = 2; expected[MOBILE | RX | BG] = 1; assertThat(mBytes).isEqualTo(expected); }
|
@Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
QTagUidNetworkBytesCollector extends NetworkBytesCollector { @Override public boolean getTotalBytes(long[] bytes) { try { if (mProcFileReader == null) { mProcFileReader = new ProcFileReader(getPath()); } mProcFileReader.reset(); if (!mProcFileReader.isValid() || !mProcFileReader.hasNext()) { return false; } Arrays.fill(bytes, 0); mProcFileReader.skipLine(); while (mProcFileReader.hasNext()) { mProcFileReader.skipSpaces(); mProcFileReader.readWord(mBuffer); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); long uid = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); boolean isWifi = WIFI_IFACE.compareTo(mBuffer) == 0; boolean isMobile = !isWifi && DUMMY_IFACE.compareTo(mBuffer) != 0 && LOOPBACK_IFACE.compareTo(mBuffer) != 0; if (uid != UID || !(isWifi || isMobile)) { mProcFileReader.skipLine(); continue; } long cntSet = mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); int field = 0; field |= (isWifi ? WIFI : MOBILE); field |= (cntSet == 0 ? BG : FG); bytes[field | RX] += mProcFileReader.readNumber(); mProcFileReader.skipSpaces(); mProcFileReader.skipSpaces(); bytes[field | TX] += mProcFileReader.readNumber(); mProcFileReader.skipLine(); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse file", pe); return false; } return true; } @Override boolean supportsBgDistinction(); @Override boolean getTotalBytes(long[] bytes); }
|
@Test public void testEmpty() throws Exception { TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); collector.getTotalBytes(mBytes); assertThat(mBytes).isEqualTo(new long[8]); }
|
@Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
@Test public void testInitialValues() throws Exception { ShadowTrafficStats.setUidRxBytes(10000); ShadowTrafficStats.setUidTxBytes(20000); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes).isEqualTo(new long[] {0, 0, 10000, 20000, 0, 0, 0, 0}); }
|
@Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
@Test public void testVirtualMemory() throws Exception { String statm = "4 2 0 4 0 0 0"; MemoryMetricsCollectorWithProcFile collector = new MemoryMetricsCollectorWithProcFile().setPath(createFile(statm)); MemoryMetrics snapshot = new MemoryMetrics(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(snapshot.vmSizeKb).isEqualTo(16); assertThat(snapshot.vmRssKb).isEqualTo(8); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
@Test public void testUnsupportedValues() throws Exception { ShadowTrafficStats.setUidRxBytes(UNSUPPORTED); ShadowTrafficStats.setUidTxBytes(UNSUPPORTED); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isFalse(); }
|
@Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
@Test public void testBroadcastNetworkChanges() throws Exception { ShadowTrafficStats.setUidRxBytes(10000); ShadowTrafficStats.setUidTxBytes(20000); TrafficStatsNetworkBytesCollector collector = new TrafficStatsNetworkBytesCollector(RuntimeEnvironment.application); assertThat(collector.getTotalBytes(mBytes)).isTrue(); ShadowTrafficStats.setUidRxBytes(11000); ShadowTrafficStats.setUidTxBytes(22000); ConnectivityManager connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE); ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(connectivityManager); NetworkInfo networkInfo = ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true); shadowConnectivityManager.setActiveNetworkInfo(networkInfo); collector.mReceiver.onReceive(null, null); ShadowTrafficStats.setUidRxBytes(11100); ShadowTrafficStats.setUidTxBytes(22200); assertThat(collector.getTotalBytes(mBytes)).isTrue(); assertThat(mBytes[RX | MOBILE]).isEqualTo(11000); assertThat(mBytes[TX | MOBILE]).isEqualTo(22000); assertThat(mBytes[RX | WIFI]).isEqualTo(100); assertThat(mBytes[TX | WIFI]).isEqualTo(200); }
|
@Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
TrafficStatsNetworkBytesCollector extends NetworkBytesCollector { @Override public synchronized boolean getTotalBytes(long[] bytes) { if (!mIsValid) { return false; } updateTotalBytes(); System.arraycopy(mTotalBytes, 0, bytes, 0, bytes.length); return true; } TrafficStatsNetworkBytesCollector(Context context); @Override boolean supportsBgDistinction(); @Override synchronized boolean getTotalBytes(long[] bytes); }
|
@Test public void testSingleRadioActive() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int radioActiveS = radioMonitor.onRadioActivate(0L, 3000L); assertThat(radioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(3 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMultipleSequentialRadioActive() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int firstRadioActiveS = radioMonitor.onRadioActivate(0L, 2000L); assertThat(firstRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(2 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); int secondRadioActiveS = radioMonitor.onRadioActivate(2000L, 3000L); assertThat(secondRadioActiveS, is(2 + WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(3 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); int thirdRadioActiveS = radioMonitor.onRadioActivate(3000L, 4000L); assertThat(thirdRadioActiveS, is(3 + WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(4 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMultipleSequentialAfterTailRadioActive() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int firstRadioActiveS = radioMonitor.onRadioActivate(0L, 2000L); assertThat(firstRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(2 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); long delay = TimeUnit.SECONDS.toMillis(WAKEUP_INTERVAL_S); int secondRadioActiveS = radioMonitor.onRadioActivate(2000L + delay, 3000L + delay); assertThat(secondRadioActiveS, is(2 + WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(3 + 2 * WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(2)); int thirdRadioActiveS = radioMonitor.onRadioActivate(3000L + 2 * delay, 4000L + 2 * delay); assertThat(thirdRadioActiveS, is(3 + 2 * WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(4 + 3 * WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(3)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMultipleParallelRadioActiveFirstEndBeforeSecond() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int firstRadioActiveS = radioMonitor.onRadioActivate(1000L, 2000L); assertThat(firstRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(1 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); int secondRadioActiveS = radioMonitor.onRadioActivate(2000L, 3000L); assertThat(secondRadioActiveS, is(1 + WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(2 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMultipleParallelRadioActiveFirstEndWithSecond() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int firstRadioActiveS = radioMonitor.onRadioActivate(1000L, 3000L); assertThat(firstRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(2 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); int secondRadioActiveS = radioMonitor.onRadioActivate(2000L, 3000L); assertThat(secondRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(2 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMultipleParallelRadioActiveFirstEndAfterSecond() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); int firstRadioActiveS = radioMonitor.onRadioActivate(1000L, 4000L); assertThat(firstRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(3 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); int secondRadioActiveS = radioMonitor.onRadioActivate(2000L, 3000L); assertThat(secondRadioActiveS, is(0)); assertThat(getRadioActiveS(radioMonitor), is(3 + WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(1)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testMixedRadioActive() throws Exception { MonotonicRadioMonitor radioMonitor = new MonotonicRadioMonitor(WAKEUP_INTERVAL_S); radioMonitor.onRadioActivate(1000L, 4000L); radioMonitor.onRadioActivate(2000L, 3000L); radioMonitor.onRadioActivate(15000L, 18000L); radioMonitor.onRadioActivate(16000L, 18000L); int radioActiveS = radioMonitor.onRadioActivate(29000L, 30000L); assertThat(radioActiveS, is(6 + 2 * WAKEUP_INTERVAL_S)); assertThat(getRadioActiveS(radioMonitor), is(7 + 3 * WAKEUP_INTERVAL_S)); assertThat(radioMonitor.mWakeupCounter.get(), is(3)); }
|
public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
MonotonicRadioMonitor { public int onRadioActivate(long transferStartMs, long transferEndMs) { long transferStartS = TimeUnit.MILLISECONDS.toSeconds(transferStartMs); long transferEndS = TimeUnit.MILLISECONDS.toSeconds(transferEndMs); long expectedNextIdleAndTotals; long newNextIdleAndTotals; boolean casSucceeded = false; do { expectedNextIdleAndTotals = mNextIdleTimeActive.get(); newNextIdleAndTotals = adjustTotalsAndNextIdle(transferStartS, transferEndS, expectedNextIdleAndTotals); } while (nextIdle(expectedNextIdleAndTotals) < nextIdle(newNextIdleAndTotals) && !(casSucceeded = mNextIdleTimeActive.compareAndSet(expectedNextIdleAndTotals, newNextIdleAndTotals))); if (casSucceeded) { if (nextIdle(expectedNextIdleAndTotals) <= transferStartS) { mWakeupCounter.getAndIncrement(); } return totalTxS(expectedNextIdleAndTotals) + totalTailS(expectedNextIdleAndTotals); } else { return 0; } } MonotonicRadioMonitor(int wakeUpTimeS); int onRadioActivate(long transferStartMs, long transferEndMs); long getTotalTxS(); long getTotalTailS(); long getWakeupCount(); }
|
@Test public void testBrokenFile() throws Exception { DiskMetricsCollectorWithProcFile collector = new DiskMetricsCollectorWithProcFile() .setPath(createFile("I am a weird android"), createFile("manufacturer")); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isFalse(); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
@Test public void testDefaultDisabled() { ShadowDebug.setNativeHeapSize(4 * 1024); ShadowDebug.setNativeHeapAllocatedSize(3 * 1024); MemoryMetrics snapshot = new MemoryMetrics(); MemoryMetricsCollector collector = new MemoryMetricsCollector(); collector.getSnapshot(snapshot); assertThat(collector.getSnapshot(snapshot)).isFalse(); assertThat(snapshot.nativeHeapSizeKb).isEqualTo(0); assertThat(snapshot.nativeHeapAllocatedKb).isEqualTo(0); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
MemoryMetricsCollector extends SystemMetricsCollector<MemoryMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(MemoryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } snapshot.sequenceNumber = mCounter.incrementAndGet(); snapshot.javaHeapMaxSizeKb = getRuntimeMaxMemory() / KB; snapshot.javaHeapAllocatedKb = (getRuntimeTotalMemory() - getRuntimeFreeMemory()) / KB; snapshot.nativeHeapSizeKb = Debug.getNativeHeapSize() / KB; snapshot.nativeHeapAllocatedKb = Debug.getNativeHeapAllocatedSize() / KB; snapshot.vmSizeKb = -1; snapshot.vmRssKb = -1; try { ProcFileReader reader = mProcFileReader.get(); if (reader == null) { reader = new ProcFileReader(getPath()); mProcFileReader.set(reader); } reader.reset(); if (reader.isValid()) { snapshot.vmSizeKb = readField(reader); snapshot.vmRssKb = readField(reader); } } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse memory (statm) field", pe); } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(MemoryMetrics snapshot); synchronized void enable(); @Override MemoryMetrics createMetrics(); }
|
@Test public void testDefaultDisabled() throws Exception { DiskMetricsCollector collector = new DiskMetricsCollector(); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isFalse(); assertThat(snapshot.rcharBytes).isEqualTo(0); assertThat(snapshot.wcharBytes).isEqualTo(0); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
@Test public void testRealProcfile() throws Exception { String io = "rchar: 100\n" + "wchar: 101\n" + "syscr: 1000\n" + "syscw: 1001\n" + "read_bytes: 500\n" + "write_bytes: 501\n" + "cancelled_write_bytes: 10\n"; String stat = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46"; DiskMetricsCollectorWithProcFile collector = new DiskMetricsCollectorWithProcFile().setPath(createFile(io), createFile(stat)); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(snapshot.rcharBytes).isEqualTo(100); assertThat(snapshot.wcharBytes).isEqualTo(101); assertThat(snapshot.syscrCount).isEqualTo(1000); assertThat(snapshot.syscwCount).isEqualTo(1001); assertThat(snapshot.readBytes).isEqualTo(500); assertThat(snapshot.writeBytes).isEqualTo(501); assertThat(snapshot.cancelledWriteBytes).isEqualTo(10); assertThat(snapshot.majorFaults).isEqualTo(12); assertThat(snapshot.blkIoTicks).isEqualTo(42); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
@Test public void testRealProcfileRepeat() throws Exception { String io = "rchar: 100\n" + "wchar: 101\n" + "syscr: 1000\n" + "syscw: 1001\n" + "read_bytes: 500\n" + "write_bytes: 501\n" + "cancelled_write_bytes: 10\n"; String stat = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46"; DiskMetricsCollectorWithProcFile collector = new DiskMetricsCollectorWithProcFile().setPath(createFile(io), createFile(stat)); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(snapshot.rcharBytes).isEqualTo(100); assertThat(snapshot.wcharBytes).isEqualTo(101); assertThat(snapshot.syscrCount).isEqualTo(1000); assertThat(snapshot.syscwCount).isEqualTo(1001); assertThat(snapshot.readBytes).isEqualTo(500); assertThat(snapshot.writeBytes).isEqualTo(501); assertThat(snapshot.cancelledWriteBytes).isEqualTo(10); assertThat(snapshot.majorFaults).isEqualTo(12); assertThat(snapshot.blkIoTicks).isEqualTo(42); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
@Test public void testRealProcfileWithNegative() throws Exception { String io = "rchar: 100\n" + "wchar: 101\n" + "syscr: 1000\n" + "syscw: 1001\n" + "read_bytes: 500\n" + "write_bytes: 501\n" + "cancelled_write_bytes: -1\n"; String stat = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46"; DiskMetricsCollectorWithProcFile collector = new DiskMetricsCollectorWithProcFile().setPath(createFile(io), createFile(stat)); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isTrue(); assertThat(snapshot.rcharBytes).isEqualTo(100); assertThat(snapshot.wcharBytes).isEqualTo(101); assertThat(snapshot.syscrCount).isEqualTo(1000); assertThat(snapshot.syscwCount).isEqualTo(1001); assertThat(snapshot.readBytes).isEqualTo(500); assertThat(snapshot.writeBytes).isEqualTo(501); assertThat(snapshot.cancelledWriteBytes).isEqualTo(-1); assertThat(snapshot.majorFaults).isEqualTo(12); assertThat(snapshot.blkIoTicks).isEqualTo(42); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
|
@Test public void testNullSnapshot() { mExpectedException.expect(IllegalArgumentException.class); mCollector.getSnapshot(null); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Test public void allSnapshotsSucceed() throws Exception { mACollector.succeeds = true; mACollector.currentValue = 100; mBCollector.succeeds = true; mBCollector.currentValue = 120; assertThat(mCollector.getSnapshot(mMetrics)).isTrue(); assertThat(mMetrics.getMetrics().size()).isEqualTo(2); assertThat(mMetrics.getMetric(A.class).value).isEqualTo(100); assertThat(mMetrics.isValid(A.class)).isEqualTo(true); assertThat(mMetrics.getMetric(B.class).value).isEqualTo(120); assertThat(mMetrics.isValid(B.class)).isEqualTo(true); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Test public void partialFailures() throws Exception { mACollector.succeeds = true; mACollector.currentValue = 100; mBCollector.succeeds = false; assertThat(mCollector.getSnapshot(mMetrics)).isTrue(); assertThat(mMetrics.getMetrics().size()).isEqualTo(2); assertThat(mMetrics.getMetric(A.class).value).isEqualTo(100); assertThat(mMetrics.isValid(A.class)).isEqualTo(true); assertThat(mMetrics.isValid(B.class)).isEqualTo(false); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Test public void allSnapshotsFail() throws Exception { mACollector.succeeds = false; mBCollector.succeeds = false; assertThat(mCollector.getSnapshot(mMetrics)).isFalse(); assertThat(mMetrics.getMetrics().size()).isEqualTo(2); assertThat(mMetrics.isValid(A.class)).isEqualTo(false); assertThat(mMetrics.isValid(B.class)).isEqualTo(false); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Test public void subsetSnapshots() throws Exception { mACollector.currentValue = 100; mACollector.succeeds = true; CompositeMetrics m = new CompositeMetrics().putMetric(A.class, new A()); mCollector.getSnapshot(m); assertThat(mCollector.getSnapshot(m)).isTrue(); assertThat(m.getMetrics().size()).isEqualTo(1); assertThat(m.getMetric(A.class).value).isEqualTo(100); assertThat(m.isValid(A.class)).isEqualTo(true); assertThat(m.getMetric(B.class)).isNull(); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Test public void supersetSnapshots() throws Exception { mACollector.currentValue = 100; mACollector.succeeds = true; CompositeMetrics m = new CompositeMetrics().putMetric(A.class, new A()).putMetric(C.class, new C()); mCollector.getSnapshot(m); assertThat(mCollector.getSnapshot(m)).isTrue(); assertThat(m.getMetrics().size()).isEqualTo(2); assertThat(m.getMetric(A.class).value).isEqualTo(100); assertThat(m.isValid(A.class)).isEqualTo(true); assertThat(m.getMetric(B.class)).isNull(); assertThat(m.isValid(C.class)).isFalse(); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
CompositeMetricsCollector extends SystemMetricsCollector<CompositeMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(CompositeMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); boolean result = false; SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics = snapshot.getMetrics(); for (int i = 0, size = snapshotMetrics.size(); i < size; i++) { Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i); SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass); boolean snapshotResult = false; if (collector != null) { SystemMetrics metric = snapshot.getMetric(metricsClass); snapshotResult = collector.getSnapshot(metric); } snapshot.setIsValid(metricsClass, snapshotResult); result |= snapshotResult; } return result; } protected CompositeMetricsCollector(Builder builder); T getMetricsCollector(
Class<S> metricsClass); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(CompositeMetrics snapshot); @Override CompositeMetrics createMetrics(); }
|
@Override @Test public void testSum() throws Exception { MemoryMetrics a = createMemoryMetrics(1); MemoryMetrics b = createMemoryMetrics(2); MemoryMetrics sum = new MemoryMetrics(); MemoryMetricsCollector collector = new MemoryMetricsCollector(); collector.enable(); collector.getSnapshot(a); collector.getSnapshot(b); sum = b.sum(a, sum); assertThat(sum.sequenceNumber).isEqualTo(b.sequenceNumber); assertThat(sum.javaHeapMaxSizeKb).isEqualTo(b.javaHeapMaxSizeKb); assertThat(sum.javaHeapAllocatedKb).isEqualTo(b.javaHeapAllocatedKb); assertThat(sum.nativeHeapSizeKb).isEqualTo(b.nativeHeapSizeKb); assertThat(sum.nativeHeapAllocatedKb).isEqualTo(b.nativeHeapAllocatedKb); assertThat(sum.vmSizeKb).isEqualTo(b.vmSizeKb); assertThat(sum.vmRssKb).isEqualTo(b.vmRssKb); sum = a.sum(b, null); assertThat(sum.sequenceNumber).isEqualTo(b.sequenceNumber); assertThat(sum.javaHeapMaxSizeKb).isEqualTo(b.javaHeapMaxSizeKb); assertThat(sum.javaHeapAllocatedKb).isEqualTo(b.javaHeapAllocatedKb); assertThat(sum.nativeHeapSizeKb).isEqualTo(b.nativeHeapSizeKb); assertThat(sum.nativeHeapAllocatedKb).isEqualTo(b.nativeHeapAllocatedKb); assertThat(sum.vmSizeKb).isEqualTo(b.vmSizeKb); assertThat(sum.vmRssKb).isEqualTo(b.vmRssKb); }
|
public MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output) { if (output == null) { output = new MemoryMetrics(); } if (b == null) { output.set(this); } else { MemoryMetrics latest = sequenceNumber > b.sequenceNumber ? this : b; output.sequenceNumber = latest.sequenceNumber; output.javaHeapMaxSizeKb = latest.javaHeapMaxSizeKb; output.javaHeapAllocatedKb = latest.javaHeapAllocatedKb; output.nativeHeapSizeKb = latest.nativeHeapSizeKb; output.nativeHeapAllocatedKb = latest.nativeHeapAllocatedKb; output.vmSizeKb = latest.vmSizeKb; output.vmRssKb = latest.vmRssKb; } return output; }
|
MemoryMetrics extends SystemMetrics<MemoryMetrics> { public MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output) { if (output == null) { output = new MemoryMetrics(); } if (b == null) { output.set(this); } else { MemoryMetrics latest = sequenceNumber > b.sequenceNumber ? this : b; output.sequenceNumber = latest.sequenceNumber; output.javaHeapMaxSizeKb = latest.javaHeapMaxSizeKb; output.javaHeapAllocatedKb = latest.javaHeapAllocatedKb; output.nativeHeapSizeKb = latest.nativeHeapSizeKb; output.nativeHeapAllocatedKb = latest.nativeHeapAllocatedKb; output.vmSizeKb = latest.vmSizeKb; output.vmRssKb = latest.vmRssKb; } return output; } }
|
MemoryMetrics extends SystemMetrics<MemoryMetrics> { public MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output) { if (output == null) { output = new MemoryMetrics(); } if (b == null) { output.set(this); } else { MemoryMetrics latest = sequenceNumber > b.sequenceNumber ? this : b; output.sequenceNumber = latest.sequenceNumber; output.javaHeapMaxSizeKb = latest.javaHeapMaxSizeKb; output.javaHeapAllocatedKb = latest.javaHeapAllocatedKb; output.nativeHeapSizeKb = latest.nativeHeapSizeKb; output.nativeHeapAllocatedKb = latest.nativeHeapAllocatedKb; output.vmSizeKb = latest.vmSizeKb; output.vmRssKb = latest.vmRssKb; } return output; } MemoryMetrics(); }
|
MemoryMetrics extends SystemMetrics<MemoryMetrics> { public MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output) { if (output == null) { output = new MemoryMetrics(); } if (b == null) { output.set(this); } else { MemoryMetrics latest = sequenceNumber > b.sequenceNumber ? this : b; output.sequenceNumber = latest.sequenceNumber; output.javaHeapMaxSizeKb = latest.javaHeapMaxSizeKb; output.javaHeapAllocatedKb = latest.javaHeapAllocatedKb; output.nativeHeapSizeKb = latest.nativeHeapSizeKb; output.nativeHeapAllocatedKb = latest.nativeHeapAllocatedKb; output.vmSizeKb = latest.vmSizeKb; output.vmRssKb = latest.vmRssKb; } return output; } MemoryMetrics(); @Override MemoryMetrics set(MemoryMetrics metrics); MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output); @Override MemoryMetrics diff(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
|
MemoryMetrics extends SystemMetrics<MemoryMetrics> { public MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output) { if (output == null) { output = new MemoryMetrics(); } if (b == null) { output.set(this); } else { MemoryMetrics latest = sequenceNumber > b.sequenceNumber ? this : b; output.sequenceNumber = latest.sequenceNumber; output.javaHeapMaxSizeKb = latest.javaHeapMaxSizeKb; output.javaHeapAllocatedKb = latest.javaHeapAllocatedKb; output.nativeHeapSizeKb = latest.nativeHeapSizeKb; output.nativeHeapAllocatedKb = latest.nativeHeapAllocatedKb; output.vmSizeKb = latest.vmSizeKb; output.vmRssKb = latest.vmRssKb; } return output; } MemoryMetrics(); @Override MemoryMetrics set(MemoryMetrics metrics); MemoryMetrics sum(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output); @Override MemoryMetrics diff(@Nullable MemoryMetrics b, @Nullable MemoryMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); public long sequenceNumber; public long javaHeapMaxSizeKb; public long javaHeapAllocatedKb; public long nativeHeapSizeKb; public long nativeHeapAllocatedKb; public long vmSizeKb; public long vmRssKb; }
|
@Test public void testGetSnapshot() { ShadowSystemClock.setElapsedRealtime(1); mAppWakeupMetricsCollector.recordWakeupStart(AppWakeupMetrics.WakeupReason.ALARM, "key1"); ShadowSystemClock.setElapsedRealtime(2); mAppWakeupMetricsCollector.recordWakeupStart( AppWakeupMetrics.WakeupReason.JOB_SCHEDULER, "key2"); ShadowSystemClock.setElapsedRealtime(3); mAppWakeupMetricsCollector.recordWakeupStart( AppWakeupMetrics.WakeupReason.JOB_SCHEDULER, "key3"); ShadowSystemClock.setElapsedRealtime(4); mAppWakeupMetricsCollector.recordWakeupStart(AppWakeupMetrics.WakeupReason.ALARM, "key4"); mAppWakeupMetricsCollector.getSnapshot(mAppWakeupMetrics); assertThat(mAppWakeupMetrics.appWakeups.size()).isEqualTo(0); ShadowSystemClock.setElapsedRealtime(20); mAppWakeupMetricsCollector.recordWakeupEnd("key1"); ShadowSystemClock.setElapsedRealtime(30); mAppWakeupMetricsCollector.recordWakeupEnd("key3"); ShadowSystemClock.setElapsedRealtime(35); mAppWakeupMetricsCollector.getSnapshot(mAppWakeupMetrics); assertThat(mAppWakeupMetrics.appWakeups.size()).isEqualTo(2); assertThat(mAppWakeupMetrics.appWakeups.get("key1")) .isEqualTo(new WakeupDetails(WakeupReason.ALARM, 1, 19)); assertThat(mAppWakeupMetrics.appWakeups.get("key3")) .isEqualTo(new WakeupDetails(WakeupReason.JOB_SCHEDULER, 1, 27)); ShadowSystemClock.setElapsedRealtime(41); mAppWakeupMetricsCollector.recordWakeupStart(AppWakeupMetrics.WakeupReason.ALARM, "key1"); ShadowSystemClock.setElapsedRealtime(50); mAppWakeupMetricsCollector.recordWakeupEnd("key1"); ShadowSystemClock.setElapsedRealtime(57); mAppWakeupMetricsCollector.recordWakeupEnd("key2"); mAppWakeupMetricsCollector.getSnapshot(mAppWakeupMetrics); assertThat(mAppWakeupMetrics.appWakeups.size()).isEqualTo(3); assertThat(mAppWakeupMetrics.appWakeups.get("key1")) .isEqualTo(new WakeupDetails(WakeupReason.ALARM, 2, 28)); assertThat(mAppWakeupMetrics.appWakeups.get("key2")) .isEqualTo(new WakeupDetails(WakeupReason.JOB_SCHEDULER, 1, 55)); assertThat(mAppWakeupMetrics.appWakeups.get("key3")) .isEqualTo(new WakeupDetails(WakeupReason.JOB_SCHEDULER, 1, 27)); ShadowSystemClock.setElapsedRealtime(65); mAppWakeupMetricsCollector.recordWakeupStart(AppWakeupMetrics.WakeupReason.ALARM, "key4"); ShadowSystemClock.setElapsedRealtime(65); mAppWakeupMetricsCollector.recordWakeupEnd("key1"); mAppWakeupMetricsCollector.getSnapshot(mAppWakeupMetrics); assertThat(mAppWakeupMetrics.appWakeups.size()).isEqualTo(3); assertThat(mAppWakeupMetrics.appWakeups.get("key1")) .isEqualTo(new WakeupDetails(WakeupReason.ALARM, 2, 28)); assertThat(mAppWakeupMetrics.appWakeups.get("key2")) .isEqualTo(new WakeupDetails(WakeupReason.JOB_SCHEDULER, 1, 55)); assertThat(mAppWakeupMetrics.appWakeups.get("key3")) .isEqualTo(new WakeupDetails(WakeupReason.JOB_SCHEDULER, 1, 27)); }
|
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(AppWakeupMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.appWakeups.clear(); for (int i = 0; i < mMetrics.appWakeups.size(); i++) { WakeupDetails details = new WakeupDetails(); details.set(mMetrics.appWakeups.valueAt(i)); snapshot.appWakeups.put(mMetrics.appWakeups.keyAt(i), details); } return true; }
|
AppWakeupMetricsCollector extends SystemMetricsCollector<AppWakeupMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(AppWakeupMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.appWakeups.clear(); for (int i = 0; i < mMetrics.appWakeups.size(); i++) { WakeupDetails details = new WakeupDetails(); details.set(mMetrics.appWakeups.valueAt(i)); snapshot.appWakeups.put(mMetrics.appWakeups.keyAt(i), details); } return true; } }
|
AppWakeupMetricsCollector extends SystemMetricsCollector<AppWakeupMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(AppWakeupMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.appWakeups.clear(); for (int i = 0; i < mMetrics.appWakeups.size(); i++) { WakeupDetails details = new WakeupDetails(); details.set(mMetrics.appWakeups.valueAt(i)); snapshot.appWakeups.put(mMetrics.appWakeups.keyAt(i), details); } return true; } AppWakeupMetricsCollector(); }
|
AppWakeupMetricsCollector extends SystemMetricsCollector<AppWakeupMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(AppWakeupMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.appWakeups.clear(); for (int i = 0; i < mMetrics.appWakeups.size(); i++) { WakeupDetails details = new WakeupDetails(); details.set(mMetrics.appWakeups.valueAt(i)); snapshot.appWakeups.put(mMetrics.appWakeups.keyAt(i), details); } return true; } AppWakeupMetricsCollector(); @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(AppWakeupMetrics snapshot); @Override AppWakeupMetrics createMetrics(); synchronized void recordWakeupStart(AppWakeupMetrics.WakeupReason reason, String id); synchronized void recordWakeupEnd(String id); }
|
AppWakeupMetricsCollector extends SystemMetricsCollector<AppWakeupMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(AppWakeupMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.appWakeups.clear(); for (int i = 0; i < mMetrics.appWakeups.size(); i++) { WakeupDetails details = new WakeupDetails(); details.set(mMetrics.appWakeups.valueAt(i)); snapshot.appWakeups.put(mMetrics.appWakeups.keyAt(i), details); } return true; } AppWakeupMetricsCollector(); @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(AppWakeupMetrics snapshot); @Override AppWakeupMetrics createMetrics(); synchronized void recordWakeupStart(AppWakeupMetrics.WakeupReason reason, String id); synchronized void recordWakeupEnd(String id); }
|
@Test @Override public void testSum() throws Exception { AppWakeupMetrics a = getAppWakeupMetrics(4, 0); AppWakeupMetrics b = getAppWakeupMetrics(7, 10); AppWakeupMetrics output = new AppWakeupMetrics(); a.sum(b, output); assertThat(output.appWakeups.size()).isEqualTo(7); verifyKeyAndReason(output.appWakeups); verifyWakeupDetails(output.appWakeups.valueAt(0), 10, 12); verifyWakeupDetails(output.appWakeups.valueAt(1), 12, 14); verifyWakeupDetails(output.appWakeups.valueAt(2), 14, 16); verifyWakeupDetails(output.appWakeups.valueAt(3), 16, 18); verifyWakeupDetails(output.appWakeups.valueAt(4), 14, 15); verifyWakeupDetails(output.appWakeups.valueAt(5), 15, 16); verifyWakeupDetails(output.appWakeups.valueAt(6), 16, 17); }
|
@Override public AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).sum(b.appWakeups.get(tag), output.appWakeups.get(tag)); } for (int i = 0; i < b.appWakeups.size(); i++) { String tag = b.appWakeups.keyAt(i); if (!output.appWakeups.containsKey(tag)) { output.appWakeups.put(tag, b.appWakeups.valueAt(i)); } } } return output; }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).sum(b.appWakeups.get(tag), output.appWakeups.get(tag)); } for (int i = 0; i < b.appWakeups.size(); i++) { String tag = b.appWakeups.keyAt(i); if (!output.appWakeups.containsKey(tag)) { output.appWakeups.put(tag, b.appWakeups.valueAt(i)); } } } return output; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).sum(b.appWakeups.get(tag), output.appWakeups.get(tag)); } for (int i = 0; i < b.appWakeups.size(); i++) { String tag = b.appWakeups.keyAt(i); if (!output.appWakeups.containsKey(tag)) { output.appWakeups.put(tag, b.appWakeups.valueAt(i)); } } } return output; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).sum(b.appWakeups.get(tag), output.appWakeups.get(tag)); } for (int i = 0; i < b.appWakeups.size(); i++) { String tag = b.appWakeups.keyAt(i); if (!output.appWakeups.containsKey(tag)) { output.appWakeups.put(tag, b.appWakeups.valueAt(i)); } } } return output; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).sum(b.appWakeups.get(tag), output.appWakeups.get(tag)); } for (int i = 0; i < b.appWakeups.size(); i++) { String tag = b.appWakeups.keyAt(i); if (!output.appWakeups.containsKey(tag)) { output.appWakeups.put(tag, b.appWakeups.valueAt(i)); } } } return output; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); public SimpleArrayMap<String, WakeupDetails> appWakeups; }
|
@Test @Override public void testDiff() throws Exception { AppWakeupMetrics a = getAppWakeupMetrics(7, 5); AppWakeupMetrics b = getAppWakeupMetrics(4, 10); AppWakeupMetrics output = new AppWakeupMetrics(); b.diff(a, output); assertThat(output.appWakeups.size()).isEqualTo(4); verifyKeyAndReason(output.appWakeups); verifyWakeupDetails(output.appWakeups.valueAt(0), 5, 5); verifyWakeupDetails(output.appWakeups.valueAt(1), 5, 5); verifyWakeupDetails(output.appWakeups.valueAt(2), 5, 5); verifyWakeupDetails(output.appWakeups.valueAt(3), 5, 5); }
|
@Override public AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).diff(b.appWakeups.get(tag), output.appWakeups.get(tag)); } } return output; }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).diff(b.appWakeups.get(tag), output.appWakeups.get(tag)); } } return output; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).diff(b.appWakeups.get(tag), output.appWakeups.get(tag)); } } return output; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).diff(b.appWakeups.get(tag), output.appWakeups.get(tag)); } } return output; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { @Override public AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output) { if (output == null) { output = new AppWakeupMetrics(); } if (b == null) { output.set(this); } else { output.appWakeups.clear(); for (int i = 0; i < appWakeups.size(); i++) { String tag = appWakeups.keyAt(i); output.appWakeups.put(tag, new WakeupDetails(appWakeups.valueAt(i).reason)); appWakeups.valueAt(i).diff(b.appWakeups.get(tag), output.appWakeups.get(tag)); } } return output; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); public SimpleArrayMap<String, WakeupDetails> appWakeups; }
|
@Test public void testWakeupAttribution() throws JSONException { AppWakeupMetrics metrics = new AppWakeupMetrics(); metrics.appWakeups.put( "wakeup", new AppWakeupMetrics.WakeupDetails(AppWakeupMetrics.WakeupReason.ALARM, 1L, 100L)); JSONArray json = metrics.toJSON(); assertThat(json.length()).isEqualTo(1); JSONObject wakeup = json.getJSONObject(0); assertThat(wakeup.getInt("time_ms")).isEqualTo(100); assertThat(wakeup.getInt("count")).isEqualTo(1); assertThat(wakeup.getString("type")).isEqualTo("ALARM"); assertThat(wakeup.getString("key")).isEqualTo("wakeup"); }
|
public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; } }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); }
|
AppWakeupMetrics extends SystemMetrics<AppWakeupMetrics> { public JSONArray toJSON() throws JSONException { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < appWakeups.size(); i++) { JSONObject obj = new JSONObject(); AppWakeupMetrics.WakeupDetails details = appWakeups.valueAt(i); obj.put("key", appWakeups.keyAt(i)); obj.put("type", details.reason.toString()); obj.put("count", details.count); obj.put("time_ms", details.wakeupTimeMs); jsonArray.put(obj); } return jsonArray; } @Override AppWakeupMetrics set(AppWakeupMetrics metrics); @Override AppWakeupMetrics sum(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override AppWakeupMetrics diff(@Nullable AppWakeupMetrics b, @Nullable AppWakeupMetrics output); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); JSONArray toJSON(); public SimpleArrayMap<String, WakeupDetails> appWakeups; }
|
@Test public void testInitialSnapshot() { ShadowSystemClock.setElapsedRealtime(5000); when(mContext.registerReceiver( Matchers.isNull(BroadcastReceiver.class), Matchers.any(IntentFilter.class))) .thenReturn(createBatteryIntent(BatteryManager.BATTERY_STATUS_CHARGING, 20, 100)); DeviceBatteryMetrics metrics = new DeviceBatteryMetrics(); DeviceBatteryMetricsCollector collector = new DeviceBatteryMetricsCollector(mContext); ShadowSystemClock.setElapsedRealtime(10000); collector.getSnapshot(metrics); verifySnapshot(metrics, 20, 0, 5000); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
@Test public void testEmptyBatteryIntent() { DeviceBatteryMetrics metrics = new DeviceBatteryMetrics(); DeviceBatteryMetricsCollector collector = new DeviceBatteryMetricsCollector(mContext); collector.getSnapshot(metrics); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
@Test public void testNullSnapshot() { when(mContext.registerReceiver( Matchers.isNull(BroadcastReceiver.class), Matchers.any(IntentFilter.class))) .thenReturn(createBatteryIntent(BatteryManager.BATTERY_STATUS_CHARGING, 20, 100)); DeviceBatteryMetricsCollector collector = new DeviceBatteryMetricsCollector(mContext); mExpectedException.expect(IllegalArgumentException.class); collector.getSnapshot(null); }
|
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.