fun test_nCopiesILjava_lang_Object() { val o = Any() var l: MutableList<*> = Collections.nCopies(100, o) var i: Iterator<*> = l.iterator() val first = i.next()!! assertTrue("Returned list consists of copies not refs", first === o) assertEquals("Returned list of incorrect size", 100, l.size) assertTrue("Contains", l.contains(o)) assertTrue("Contains null", !l.contains(null)) assertTrue("null nCopies contains", !Collections.nCopies(2, null).contains(o)) assertTrue("null nCopies contains null", Collections.nCopies(2, null).contains(null)) l = Collections.nCopies(20, null) i = l.iterator() var counter = 0 while (i.hasNext()) { assertTrue("List is too large", counter < 20) assertNull("Element should be null: $counter", i.next()) counter++ } try { l.add(o) fail("Returned list is not immutable") } catch (e: UnsupportedOperationException) { return } try { Collections.nCopies(-2, HashSet()) fail("nCopies with negative arg didn't throw IAE") } catch (e: IllegalArgumentException) { } }
add a + b + 1 , returning the result in a . The a value is treated as a BigInteger of length ( b.length * 8 ) bits . The result is modulo 2^b.length in case of overflow .