()
| 148 | } |
| 149 | |
| 150 | public String imei() { |
| 151 | char[] str = new char[15]; |
| 152 | int len = str.length; |
| 153 | |
| 154 | // Fill in the first two values of the string based with the specified prefix. |
| 155 | String arr = faker.options().option(REPORTING_BODY_IDENTIFIERS); |
| 156 | str[0] = arr.charAt(0); |
| 157 | str[1] = arr.charAt(1); |
| 158 | |
| 159 | // Fill all the remaining numbers except for the last one with random values. |
| 160 | for (int i=2; i < len - 1; i++) { |
| 161 | str[i] = Character.forDigit(faker.number().numberBetween(0, 9), 10); |
| 162 | } |
| 163 | |
| 164 | // Calculate the Luhn checksum of the values thus far |
| 165 | int lenOffset = (len + 1) % 2; |
| 166 | int t = 0; |
| 167 | int sum = 0; |
| 168 | for (int i = 0; i < len - 1; i++) { |
| 169 | if ((i + lenOffset) % 2 != 0) { |
| 170 | t = Character.getNumericValue(str[i]) * 2; |
| 171 | |
| 172 | if (t > 9) { |
| 173 | t -= 9; |
| 174 | } |
| 175 | |
| 176 | sum += t; |
| 177 | } else { |
| 178 | sum += Character.getNumericValue(str[i]); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Choose the last digit so that it causes the entire string to pass the checksum. |
| 183 | str[len - 1] = Character.forDigit(((10 - (sum % 10)) % 10), 10); |
| 184 | |
| 185 | return new String(str); |
| 186 | } |
| 187 | |
| 188 | private static final String [] REPORTING_BODY_IDENTIFIERS |
| 189 | = {"01", "10", "30", "33", "35", "44", "45", "49", "50", "51", "52", "53", "54", "86", "91", "98", "99"}; |
nothing calls this directly
no test coverage detected