Shrinks the array to half of its current size if the current number of elements fit into half of the capacity.
@return true if the compaction succeeded, else false (e.g. when the current elements would not fit)
548959
@GuardedBy("lock")
    protected boolean _compact() {
        int new_cap=buffer.length >> 1; // needs to be a power of 2 for efficient modulo operation, e.g. for index()
        // boolean compactable=this.buffer.length > 0 && (size() <= new_cap || (contiguousSpaceAvailable=_contiguousSpaceAvailable(new_cap)));
        boolean compactable=this.buffer.length > 0 && high-low <= new_cap;
        if(!compactable)
            return false; // not enough space to shrink the buffer to half its size
        _copy(new_cap);
        return true;
    }
667081
boolean isCompactionRequired(SegmentProperties info) {
        long startOffset = getCompactionStartOffset(info);
        long lastIndexOffset = this.indexReader.getLastIndexedOffset(info);
        if (startOffset + this.connector.getMaxCompactionSize() >= lastIndexOffset) {
            // Either:
            // 1. Nothing was indexed
            // 2. Compaction has already reached the indexed limit.
            // 3. Not enough "uncompacted" data - at least this.maxCompactLength must be accumulated to trigger a compaction.
            return false;
        }

        long totalEntryCount = this.indexReader.getTotalEntryCount(info);
        long entryCount = this.indexReader.getEntryCount(info);
        long utilization = totalEntryCount == 0 ? 100 : MathHelpers.minMax(Math.round(100.0 * entryCount / totalEntryCount), 0, 100);
        long utilizationThreshold = (int) MathHelpers.minMax(this.indexReader.getCompactionUtilizationThreshold(info), 0, 100);
        return utilization < utilizationThreshold;
    }
1288730
protected List<CmsResource> shrinkToFit(List<CmsResource> result, int maxSize) {

        if ((maxSize > 0) && (result.size() > maxSize)) {
            // cut off all items > count
            result = result.subList(0, maxSize);
        }

        return result;
    }
1312638
public boolean previous()
	{
		// see if it is back to the start already
		if( state == 0 )
			return false;
		else
			state = 1;

		for( int i = c; i >= 0; i-- ) {
			bins[i]--;

			if( i == 0 ) {
				if( bins[0] < 0 ) {
					state = 0;
					// put it back into its first combination
					for( int j = 0; j < bins.length; j++ ) {
						bins[j] = j;
					}
					return false;
				}
				break;
			} else if( bins[i] <= bins[i-1] ) {
				bins[i] = N-1-(c-i);
			} else {
				break;
			}
		}
		return true;
	}
580028
public void compact() {
    if (prev == this) throw new IllegalStateException();
    if (!prev.owner) return; // Cannot compact: prev isn't writable.
    int byteCount = limit - pos;
    int availableByteCount = SIZE - prev.limit + (prev.shared ? 0 : prev.pos);
    if (byteCount > availableByteCount) return; // Cannot compact: not enough writable space.
    writeTo(prev, byteCount);
    pop();
    SegmentPool.recycle(this);
  }
431960
public void shrink (int maximumCapacity) {
		if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
		if (size > maximumCapacity) maximumCapacity = size;
		if (capacity <= maximumCapacity) return;
		maximumCapacity = nextPowerOfTwo(maximumCapacity);
		resize(maximumCapacity);
	}
779259
private static Object resizeArray(Object oldArray, int newSize) {
		int oldSize = java.lang.reflect.Array.getLength(oldArray);
		Class<?> elementType = oldArray.getClass().getComponentType();
		Object newArray = java.lang.reflect.Array.newInstance(
				elementType, newSize);
		int preserveLength = Math.min(oldSize, newSize);
		if (preserveLength > 0) {
			System.arraycopy(oldArray, 0, newArray, 0, preserveLength);
		}
		return newArray;
	}
39668
public boolean put(T t) {
        if (initial) {
            if (size == data.length) {
                if (size < limit * 2) {
                    @SuppressWarnings("unchecked")
                    T[] newData = (T[]) new Object[Math.min(limit, size) * 2];
                    System.arraycopy(data, 0, newData, 0, size);
                    data = newData;
                } else {
                    Arrays.sort(data, comparator);
                    initial = false;
                    size = limit;
                }
                put(t);
            } else {
                data[size++] = t;
            }
            return true;
        }
        if (size == data.length) {
            sortTail();
        }
        if (comparator.compare(t, data[limit - 1]) < 0) {
            data[size++] = t;
            return true;
        }
        return false;
    }
842582
public void compress ()
    {
        for (Iterator<int[]> itr = values().iterator(); itr.hasNext(); ) {
            if (itr.next()[0] == 0) {
                itr.remove();
            }
        }
    }
561059
private void reallocate(int capacity) {
    if (capacity != elements.length) {
      assert (size <= capacity);
      float[] newArray = new float[capacity];
      for (int i = 0; i < size; i++) {
        newArray[i] = elements[i];
      }
      elements = newArray;
    }
  }
553635
protected boolean mergeSegments() {

		// See if merging will cause a degenerate case
		if( splits.size() <= 3 )
			return false;

		boolean change = false;
		work.reset();

		for( int i = 0; i < splits.size; i++ ) {
			int start = splits.data[i];
			int end = splits.data[(i+2)%splits.size];

			if( selectSplitOffset(start,circularDistance(start,end)) < 0 ) {
				// merge the two lines by not adding it
				change = true;
			} else {
				work.add(splits.data[(i + 1)%splits.size]);
			}

		}

		// swap the two lists
		GrowQueue_I32 tmp = work;
		work = splits;
		splits = tmp;

		return change;
	}
1332055
public void shrink(final int iSize) throws IOException {
    final int filledUpTo = getFilledUpTo();
    if (iSize >= filledUpTo)
      return;

    OLogManager.instance().debug(this, "Shrinking filled file from " + filledUpTo + " to " + iSize + " bytes. " + toString());

    setFilledUpTo(iSize);
  }
348680
private Iterable<Segment> getCompactableSegments(Storage storage, SegmentManager manager) {
    List<Segment> segments = new ArrayList<>(manager.segments().size());
    Iterator<Segment> iterator = manager.segments().iterator();
    Segment segment = iterator.next();
    while (iterator.hasNext()) {
      Segment nextSegment = iterator.next();

      // Segments that have already been compacted are eligible for compaction. For uncompacted segments, the segment must be full, consist
      // of entries less than the minorIndex, and a later segment with at least one committed entry must exist in the log. This ensures that
      // a non-empty entry always remains at the end of the log.
      if (segment.isCompacted() || (segment.isFull() && segment.lastIndex() < compactor.minorIndex() && nextSegment.firstIndex() <= manager.commitIndex() && !nextSegment.isEmpty())) {
        // Calculate the percentage of entries that have been released in the segment.
        double compactablePercentage = segment.releaseCount() / (double) segment.count();

        // If the percentage of entries released times the segment version meets the compaction threshold,
        // add the segment to the segments list for compaction.
        if (compactablePercentage * segment.descriptor().version() >= storage.compactionThreshold()) {
          segments.add(segment);
        }
      }

      segment = nextSegment;
    }
    return segments;
  }
311633
private void compact()
  {
    if (words != null && ((lastWordIndex + 1) << 1) < words.length) {
      words = Arrays.copyOf(words, lastWordIndex + 1);
    }
  }
1178112
public boolean hasRunCompression() {
    for (int i = 0; i < this.highLowContainer.size(); i++) {
      Container c = this.highLowContainer.getContainerAtIndex(i);
      if (c instanceof RunContainer) {
        return true;
      }
    }
    return false;
  }
277229
private boolean shrinkBlock() throws StructureException,
			RefinerFailedException {

		// Let shrink moves only if the repeat is larger enough
		if (repeatCore <= Lmin)
			return false;

		// Select column by maximum distance
		updateMultipleAlignment();
		Matrix residueDistances = MultipleAlignmentTools
				.getAverageResidueDistances(msa);

		double maxDist = Double.MIN_VALUE;
		double[] colDistances = new double[length];
		int res = 0;
		for (int col = 0; col < length; col++) {
			int normalize = 0;
			for (int s = 0; s < order; s++) {
				if (residueDistances.get(s, col) != -1) {
					colDistances[col] += residueDistances.get(s, col);
					normalize++;
				}
			}
			colDistances[col] /= normalize;
			if (colDistances[col] > maxDist) {
				// geometric distribution
				if (rnd.nextDouble() > 0.5) {
					maxDist = colDistances[col];
					res = col;
				}
			}
		}

		for (int su = 0; su < order; su++) {
			Integer residue = block.get(su).get(res);
			block.get(su).remove(res);
			if (residue != null)
				freePool.add(residue);
			Collections.sort(freePool);
		}
		length--;
		checkGaps();
		return true;
	}
1238993
private boolean hasSameStructure() {
        Object wrappedCollection = getWrappedValue();
        if (wrappedCollection == null) {
            return bufferedListModel.size() == 0;
        }
        else if (wrappedCollection instanceof Object[]) {
            Object[] wrappedArray = (Object[])wrappedCollection;
            if (wrappedArray.length != bufferedListModel.size()) {
                return false;
            }
            for (int i = 0; i < bufferedListModel.size(); i++) {
                if(super.hasValueChanged(wrappedArray[i], bufferedListModel.get(i))) {
                    return false;
                }
            }
        }
        else {
            if (((Collection)wrappedCollection).size() != bufferedListModel.size()) {
                return false;
            }
            for (Iterator i = ((Collection)wrappedCollection).iterator(), j = bufferedListModel.iterator(); i.hasNext();) {
                if (super.hasValueChanged(i.next(), j.next())) {
                    return false;
                }
            }
        }
        return true;
    }