GsmBasicCharsetExtensionTableCounter.java

1
package fr.sii.ogham.sms.splitter;
2
3
/**
4
 * Every character present in base character table count as 1 octet.
5
 * 
6
 * Every character present in extended character table count as 2 octets (escape
7
 * character followed by extension character).
8
 * 
9
 * @author Aurélien Baudet
10
 */
11
public class GsmBasicCharsetExtensionTableCounter implements LengthCounter {
12
	private static final int MAXIMUM_SPLIT_SEGMENT_LENGTH = 153;
13
	private static final char[] EXT_CHARS = { '\f', '^', '{', '}', '\\', '[', '~', ']', '|', '\u20ac' };
14
15
	/**
16
	 * If extended characters are found in the string, each character must be
17
	 * count as 2 characters. As they are already present in the original
18
	 * string, add the number of extended characters to original string length.
19
	 */
20
	@Override
21
	public int count(String str) {
22
		int originalLength = str.length();
23
		int extendedChars = countExtendedChars(str);
24
		// There is a edge case where the whole message can't fit in a single
25
		// segment, contains extended characters only and the segments are full.
26
		//
27
		// As the message can't fit in one segment so it must be
28
		// split in segments of 153 characters.
29
		// So it could hypothetically fit in segments of 153 characters.
30
		// But it can't because the extended character can't be cut in the
31
		// middle.
32
		// We need to add 1 to message length to generate an additional segment
33
		// TODO: improve this
34 3 1. count : negated conditional → RUN_ERROR
2. count : Replaced integer modulus with multiplication → RUN_ERROR
3. count : negated conditional → RUN_ERROR
		if (originalLength == extendedChars && extendedChars % MAXIMUM_SPLIT_SEGMENT_LENGTH == 0) {
35 3 1. count : Replaced integer addition with subtraction → RUN_ERROR
2. count : Replaced integer addition with subtraction → RUN_ERROR
3. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → RUN_ERROR
			return originalLength + extendedChars + 1;
36
		}
37 2 1. count : Replaced integer addition with subtraction → RUN_ERROR
2. count : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → RUN_ERROR
		return originalLength + extendedChars;
38
	}
39
40
	private static int countExtendedChars(String str) {
41
		int found = 0;
42
		int len = str.length();
43 2 1. countExtendedChars : negated conditional → RUN_ERROR
2. countExtendedChars : changed conditional boundary → RUN_ERROR
		for (int i = 0; i < len; i++) {
44
			int search = 0;
45
			char c = str.charAt(i);
46 2 1. countExtendedChars : changed conditional boundary → RUN_ERROR
2. countExtendedChars : negated conditional → RUN_ERROR
			for (; search < EXT_CHARS.length; search++) {
47 1 1. countExtendedChars : negated conditional → RUN_ERROR
				if (c == EXT_CHARS[search]) {
48 1 1. countExtendedChars : Changed increment from 1 to -1 → RUN_ERROR
					found++;
49
					break;
50
				}
51
			}
52
		}
53 1 1. countExtendedChars : replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::countExtendedChars → RUN_ERROR
		return found;
54
	}
55
56
}

Mutations

34

1.1
Location : count
Killed by :
negated conditional → RUN_ERROR

2.2
Location : count
Killed by :
Replaced integer modulus with multiplication → RUN_ERROR

3.3
Location : count
Killed by :
negated conditional → RUN_ERROR

35

1.1
Location : count
Killed by :
Replaced integer addition with subtraction → RUN_ERROR

2.2
Location : count
Killed by :
Replaced integer addition with subtraction → RUN_ERROR

3.3
Location : count
Killed by :
replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → RUN_ERROR

37

1.1
Location : count
Killed by :
Replaced integer addition with subtraction → RUN_ERROR

2.2
Location : count
Killed by :
replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::count → RUN_ERROR

43

1.1
Location : countExtendedChars
Killed by :
negated conditional → RUN_ERROR

2.2
Location : countExtendedChars
Killed by :
changed conditional boundary → RUN_ERROR

46

1.1
Location : countExtendedChars
Killed by :
changed conditional boundary → RUN_ERROR

2.2
Location : countExtendedChars
Killed by :
negated conditional → RUN_ERROR

47

1.1
Location : countExtendedChars
Killed by :
negated conditional → RUN_ERROR

48

1.1
Location : countExtendedChars
Killed by :
Changed increment from 1 to -1 → RUN_ERROR

53

1.1
Location : countExtendedChars
Killed by :
replaced int return with 0 for fr/sii/ogham/sms/splitter/GsmBasicCharsetExtensionTableCounter::countExtendedChars → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1