/** * Returns a copy of this set which can be changed without modifying the original one. * @return never {@code null}. */ @SuppressWarnings("all") public CountSet clone() { return new CountSet(this); }
/** * Add a arbitrary number of integers to the set. * * @param values integer to add to the set. * @return <code>true</code> if the set changed as a result of this invocation, <code>false</code> otherwise. */ public boolean addAll(final int ... values) { ensureCapacity(size + values.length); boolean result = false; for (final int v : values) result = add(v) | result; return result; }
/** * Add all elements present in a int-set. * * @param other the other inset. * * @throws NullPointerException if <code>other</code> is <code>null</code>. * @return <code>true</code> if this set changed due to this operation, <code>false</code> otherwise. */ public boolean addAll(final CountSet other) { return addAll(other.elements,0,other.size); }
/** * Returns the maximum kmerSize available. * * @throws IllegalStateException if no assembly-result was added to the set, thus there is no kmerSize. * * @return greater than 0. */ public int getMaximumKmerSize() { if (kmerSizes.size() == 0) throw new IllegalStateException("there is yet no kmerSize in this assembly result set"); return kmerSizes.max(); }
/** * Returns the minimum kmerSize available. * * @throws IllegalStateException if no assembly-result was added to the set, thus there is no kmerSize. * * @return greater than 0. */ public int getMinimumKmerSize() { if (kmerSizes.size() == 0) throw new IllegalStateException("there is yet no kmerSize in this assembly result set"); return kmerSizes.min(); }
@Test public void testSetToSingleValue() { final CountSet subject = new CountSet(10); subject.setTo(-31); Assert.assertEquals(subject.size(),1); Assert.assertEquals(subject.min(),-31); Assert.assertEquals(subject.max(),-31); Assert.assertTrue(subject.contains(-31)); Assert.assertFalse(subject.contains(-21)); }
final CountSet pathSizes = new CountSet(10); // typically more than enough. pathSizes.setTo(0); final CountSet joiningPathLengths = expectedAlternativePathRejoins.remove(currentVertex); if (joiningPathLengths != null) pathSizes.addAll(joiningPathLengths); pathSizes.incAll(1); blockLength++; final int maxClipping = pathSizes.size() <= 1 ? blockLength : pathSizes.min(); MultiDeBruijnVertex clippingEnd = backwards ? anchoring.rightAnchorVertex : anchoring.leftAnchorVertex; while (!possibleClippingPoints.isEmpty()) {
@Test public void testMinMax() { final int CAPACITY = 10; final CountSet subject = new CountSet(CAPACITY); final int REPEATS = 1000; final Random rnd = new Random(13); final int[] values = new int[REPEATS]; for (int i = 0; i < REPEATS; i++) { int newInt = rnd.nextInt(Integer.MAX_VALUE) * (rnd.nextBoolean() ? -1 : 1); values[i] = newInt; } subject.addAll(values); Arrays.sort(values); Assert.assertEquals(subject.min(),values[0]); Assert.assertEquals(subject.max(),values[REPEATS - 1]); }
@Test public void testSingleValueAdd() { final int CAPACITY = 10; final CountSet subject = new CountSet(CAPACITY); final HashSet<Integer> reasuranceSet = new HashSet<>(CAPACITY); final int REPEATS = 1000; final Random rnd = new Random(13); for (int i = 0; i < REPEATS; i++) { int newInt = rnd.nextInt(500); boolean expectedResult = reasuranceSet.add(newInt); boolean result = subject.add(newInt); Assert.assertEquals(result,expectedResult); Assert.assertEquals(subject.size(),reasuranceSet.size()); } for (final int j : reasuranceSet) Assert.assertTrue(subject.contains(j)); for (int j = 0; j < 501; j++) Assert.assertEquals(subject.contains(j),reasuranceSet.contains(j)); }
@Test public void testArrayValueAdd() { final int CAPACITY = 10; final CountSet subject = new CountSet(CAPACITY); final HashSet<Integer> reasuranceSet = new HashSet<>(CAPACITY); final int REPEATS = 1000; final Random rnd = new Random(13); final int[] values = new int[REPEATS]; final Integer[] valueWrappers = new Integer[REPEATS]; for (int i = 0; i < REPEATS; i++) { int newInt = rnd.nextInt(500); values[i] = newInt; valueWrappers[i] = newInt; } boolean expectedResult = reasuranceSet.addAll(Arrays.asList(valueWrappers)); boolean result = subject.addAll(values); Assert.assertEquals(result,expectedResult); Assert.assertEquals(subject.size(),reasuranceSet.size()); for (final int j : reasuranceSet) Assert.assertTrue(subject.contains(j)); for (int j = 0; j < 501; j++) Assert.assertEquals(subject.contains(j),reasuranceSet.contains(j)); }
@Test public void testAddRange() { final CountSet subject = new CountSet(10); subject.addRange(10,21); Assert.assertEquals(subject.size(),12); for (int i = 10; i < 22; i++) Assert.assertTrue(subject.contains(i)); for (int i = -1; i < 10; i++) Assert.assertFalse(subject.contains(i)); for (int i = 22; i < 31; i++) Assert.assertFalse(subject.contains(i)); }
@Test(dataProvider="capacities") public void testSize(final int capacity) { final CountSet empty = new CountSet(capacity); Assert.assertEquals(empty.size(), 0); CountSet nonEmpty = new CountSet(capacity); for (int i = 0; i < capacity * 3; i++) { nonEmpty.add(i); Assert.assertEquals(nonEmpty.size(),i + 1); } }
@Test public void testIncrease() { final int CAPACITY = 10; final CountSet subject = new CountSet(CAPACITY); final HashSet<Integer> reasuranceSet = new HashSet<>(CAPACITY); final int REPEATS = 1000; final Random rnd = new Random(13); final int[] values = new int[REPEATS]; final Integer[] valueWrappers = new Integer[REPEATS]; for (int i = 0; i < REPEATS; i++) { int newInt = rnd.nextInt(500); values[i] = newInt; valueWrappers[i] = newInt; } subject.incAll(3); for (final int j : reasuranceSet) Assert.assertTrue(subject.contains(j+3)); for (int j = 0; j < 501; j++) Assert.assertEquals(subject.contains(j+3),reasuranceSet.contains(j)); }
@Override public boolean retainAll(final Collection<?> c) { if (size == 0) return false; @SuppressWarnings("all") final CountSet retainIndices = new CountSet(c.size() + 2); retainIndices.add(-1); retainIndices.add(size); for (final Object o : c) { if (!(o instanceof Integer)) continue; final int pos = Arrays.binarySearch(elements,0,size,(int) o); if (pos < 0) continue; retainIndices.add(pos); } if (retainIndices.size == 2) { size = 0; return true; } else if (retainIndices.size == size + 2) { return false; } else { for (int idx = retainIndices.size - 1; idx > 0; idx--) { final int toIdx = retainIndices.elements[idx]; final int fromIdx = retainIndices.elements[idx - 1] + 1; removeIndices(toIdx,fromIdx); } return true; } }
@Test public void testToIntArray() { final CountSet subject = new CountSet(10); subject.addAll(1,4,7); final int[] intArray = subject.toIntArray(); Assert.assertEquals(intArray.length,3); Assert.assertEquals(intArray[0],1); Assert.assertEquals(intArray[1],4); Assert.assertEquals(intArray[2],7); }
final CountSet previous = expectedRejoins.get(v); if (previous == null) expectedRejoins.put(v, depth.clone()); else previous.addAll(depth); final CountSet depthPlusOne = depth.clone(); depthPlusOne.incAll(1); final Set<MultiSampleEdge> nextEdges = backwards ? incomingEdgesOf(v) : outgoingEdgesOf(v); for (final MultiSampleEdge e : nextEdges) {
final int readEnd = Math.max(readStart, afterBlockReadOffset + kmerSize - 1); final byte[][] pathBases = new byte[acrossBlockPaths.size()][]; final CountSet pathSizes = new CountSet(acrossBlockPaths.size()); int nextPath = 0; final ReadSegmentCost readSegmentCost = new ReadSegmentCost(read, p, 0); pathBases[nextPath++] = readSegmentCost.bases = eventBlockPathBases(p, includePathEnds); pathSizes.add(readSegmentCost.bases.length); readSegmentCosts.add(readSegmentCost); pathSizes.add(readEnd - readStart);
/** * Indicates whether there are more than one kmerSize in the set. * * @return {@code true} iff there is more than one kmerSize assembly in the set. */ public boolean hasMultipleKmerSizes() { return kmerSizes.size() > 1; }