{@inheritDoc}
()
| 307 | * {@inheritDoc} |
| 308 | */ |
| 309 | @Override |
| 310 | public int size() { |
| 311 | if (size == -1) { |
| 312 | int tempsize = 0; |
| 313 | if ((from instanceof Integer || from instanceof Long) |
| 314 | && (to instanceof Integer || to instanceof Long)) { |
| 315 | // let's fast calculate the size |
| 316 | final BigInteger fromNum = new BigInteger(from.toString()); |
| 317 | final BigInteger toNum = new BigInteger(to.toString()); |
| 318 | final BigInteger sizeNum = toNum.subtract(fromNum).add(new BigInteger("1")); |
| 319 | tempsize = sizeNum.intValue(); |
| 320 | if (!BigInteger.valueOf(tempsize).equals(sizeNum)) { |
| 321 | tempsize = Integer.MAX_VALUE; |
| 322 | } |
| 323 | } else if (from instanceof Character && to instanceof Character) { |
| 324 | // let's fast calculate the size |
| 325 | final char fromNum = (Character) from; |
| 326 | final char toNum = (Character) to; |
| 327 | tempsize = toNum - fromNum + 1; |
| 328 | } else if (((from instanceof BigDecimal || from instanceof BigInteger) && to instanceof Number) || |
| 329 | ((to instanceof BigDecimal || to instanceof BigInteger) && from instanceof Number)) { |
| 330 | // let's fast calculate the size |
| 331 | final BigDecimal fromNum = NumberMath.toBigDecimal((Number) from); |
| 332 | final BigDecimal toNum = NumberMath.toBigDecimal((Number) to); |
| 333 | final BigInteger sizeNum = toNum.subtract(fromNum).add(BigDecimal.ONE).toBigInteger(); |
| 334 | tempsize = sizeNum.intValue(); |
| 335 | if (!BigInteger.valueOf(tempsize).equals(sizeNum)) { |
| 336 | tempsize = Integer.MAX_VALUE; |
| 337 | } |
| 338 | } else { |
| 339 | // let's brute-force calculate the size by iterating start to end |
| 340 | final Iterator<Comparable> iter = new StepIterator(this, 1); |
| 341 | while (iter.hasNext()) { |
| 342 | tempsize++; |
| 343 | // integer overflow |
| 344 | if (tempsize < 0) { |
| 345 | break; |
| 346 | } |
| 347 | iter.next(); |
| 348 | } |
| 349 | } |
| 350 | // integer overflow |
| 351 | if (tempsize < 0) { |
| 352 | tempsize = Integer.MAX_VALUE; |
| 353 | } |
| 354 | size = tempsize; |
| 355 | } |
| 356 | return size; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * {@inheritDoc} |
nothing calls this directly
no test coverage detected