List of usage examples for com.google.common.base Preconditions checkPositionIndex
public static int checkPositionIndex(int index, int size)
From source file:yaphyre.films.ImageFile.java
private Color getColor(int x, int y) { Preconditions.checkPositionIndex(x, xResolution); Preconditions.checkPositionIndex(y, yResolution); return pixelColors[y * xResolution + x]; }
From source file:io.github.msdk.util.MsSpectrumUtil.java
/** * Returns the highest intensity value. Returns 0 if the list has no data * points./*from ww w .j a va 2 s .c o m*/ * * @return a {@link java.lang.Float} object. * @param intensityValues * an array of float. * @param size * a {@link java.lang.Integer} object. */ public static @Nonnull Float getMaxIntensity(@Nonnull float intensityValues[], @Nonnull Integer size) { // Parameter check Preconditions.checkNotNull(intensityValues); Preconditions.checkNotNull(size); Preconditions.checkPositionIndex(size, intensityValues.length); Integer topIndex = getBasePeakIndex(intensityValues, size); if (topIndex == null) return 0f; return intensityValues[topIndex]; }
From source file:com.alibaba.supersonic.base.infrastructure.TupleSchema.java
/** * Returns the attribute at the specified position. * @param position the specified position. * @return the attribute at the specified position. *///from w w w. j a v a 2 s . co m public Attribute getAttributeAt(final int position) { Preconditions.checkPositionIndex(position, attributes.size()); return attributes.get(position); }
From source file:io.github.msdk.util.ChromatogramUtil.java
/** * <p>//from ww w. ja va 2 s . com * calculateMz. * </p> * * @param intensityValues * an array of float. * @param mzValues * an array of double. * @param method * a * {@link io.github.msdk.util.ChromatogramUtil.CalculationMethod} * object. * @return a {@link java.lang.Double} object. * @param size * a {@link java.lang.Integer} object. */ public static @Nullable Double calculateMz(@Nonnull double[] mzValues, @Nonnull float[] intensityValues, @Nonnull Integer size, @Nonnull CalculationMethod method) { // Parameter check Preconditions.checkNotNull(mzValues); Preconditions.checkNotNull(intensityValues); Preconditions.checkNotNull(size); Preconditions.checkPositionIndex(size, mzValues.length); Preconditions.checkPositionIndex(size, intensityValues.length); if (size == 0) return null; double newMz = 0; double sum = 0; int values = 0; switch (method) { case allAverage: for (int i = 0; i < size; i++) { if (mzValues[i] > 0) { values++; sum = sum + mzValues[i]; } } newMz = sum / values; break; case allMedian: double index = Math.floor(size / 2); if (mzValues.length % 2 == 0) { // even sum = mzValues[(int) index] + mzValues[(int) index + 1]; newMz = sum / 2; } else { // odd newMz = mzValues[(int) index]; } break; case fwhmAverage: // Find the maximum intensity float max = intensityValues[0]; for (int i = 1; i < size; i++) { if (intensityValues[i] > max) { max = intensityValues[i]; } } // Calculate m/z for (int i = 0; i < intensityValues.length; i++) { if (intensityValues[i] > max / 2) { values++; sum = sum + mzValues[i]; } } newMz = sum / values; break; case fwhmMedian: // TODO } return newMz; }
From source file:org.renyan.leveldb.table.BlockBuilder.java
public void add(Slice key, Slice value) { Preconditions.checkNotNull(key, "key is null"); Preconditions.checkNotNull(value, "value is null"); Preconditions.checkState(!finished, "block is finished"); Preconditions.checkPositionIndex(restartBlockEntryCount, blockRestartInterval); Preconditions.checkArgument(lastKey == null || comparator.compare(key, lastKey) > 0, "key must be greater than last key"); int sharedKeyBytes = 0; if (restartBlockEntryCount < blockRestartInterval) { sharedKeyBytes = calculateSharedBytes(key, lastKey); } else {/*from ww w .ja va2 s. c o m*/ // restart prefix compression restartPositions.add(block.size()); restartBlockEntryCount = 0; } int nonSharedKeyBytes = key.length() - sharedKeyBytes; // write "<shared><non_shared><value_size>" VariableLengthQuantity.writeVariableLengthInt(sharedKeyBytes, block); VariableLengthQuantity.writeVariableLengthInt(nonSharedKeyBytes, block); VariableLengthQuantity.writeVariableLengthInt(value.length(), block); // write non-shared key bytes block.writeBytes(key, sharedKeyBytes, nonSharedKeyBytes); // write value bytes block.writeBytes(value, 0, value.length()); // update last key lastKey = key; // update state entryCount++; restartBlockEntryCount++; }
From source file:com.alibaba.supersonic.base.infrastructure.View.java
/** * Returns an immutable reference to the specified column. * @param column_index/* w w w . ja v a 2 s . c o m*/ * @return */ public final Column column(int column_index) { Preconditions.checkPositionIndex(column_index, columnCount()); return columns_[column_index]; }
From source file:ca.draconic.stipple.wangtiles.RecursiveTile.java
@SuppressWarnings("unchecked") protected RecursiveTile<T> getBetterTile(int x, int y, Random rand) { Preconditions.checkPositionIndex(x, k); Preconditions.checkPositionIndex(y, k); List<RecursiveTile<T>> better = new ArrayList<>(); List<RecursiveTile<T>> equal = new ArrayList<>(); int currentErrors = errorsForSubtile(x, y); RecursiveTile<T> currentTile = getSubtile(x, y); for (RecursiveTile<T> tile : (Set<RecursiveTile<T>>) set.getTiles()) { int newErrors = errorsForSubtile(x, y, tile); if (currentErrors > newErrors) better.add(tile);//from w w w .j a v a2 s . c om else if (currentErrors == newErrors && tile != currentTile) equal.add(tile); } if (!better.isEmpty()) return better.get(rand.nextInt(better.size())); else if (!equal.isEmpty()) return equal.get(rand.nextInt(equal.size())); else return currentTile; }
From source file:edu.byu.nlp.util.DoubleArrays.java
/** * Swaps two elements in a subarray that begins at index startIndex. index1 and index2 are relative to startIndex. * /*from w w w. j ava2s . c o m*/ * @throws IndexOutOfBoundsException if arr.length <= (startIndex + index1 or startIndex + index2) < 0 */ public static void swap(final double[] arr, int startIndex, int index1, int index2) { Preconditions.checkNotNull(arr); Preconditions.checkPositionIndex(startIndex + index1, arr.length); Preconditions.checkPositionIndex(startIndex + index2, arr.length); double tmp = arr[startIndex + index1]; arr[startIndex + index1] = arr[startIndex + index2]; arr[startIndex + index2] = tmp; }
From source file:org.janusgraph.diskstorage.util.StaticArrayEntryList.java
@Override public Entry get(int index) { Preconditions.checkPositionIndex(index, limitAndValuePos.length); int offset = index > 0 ? getLimit(limitAndValuePos[index - 1]) : 0; Map<EntryMetaData, Object> metadata = EntryMetaData.EMPTY_METADATA; if (hasMetaData()) { metadata = new EntryMetaData.Map(); offset = parseMetaData(metadata, offset); }/*from w ww. j av a 2 s .co m*/ return new StaticEntry(index, offset, getLimit(limitAndValuePos[index]), getValuePos(limitAndValuePos[index]), metadata); }
From source file:org.apache.tajo.storage.HashShuffleAppenderManager.java
protected int getVolumeId(Path path) { int i = 0;//ww w . j a va2s . co m for (String rootPath : temporalPaths) { if (path.toString().startsWith(rootPath)) { break; } i++; } Preconditions.checkPositionIndex(i, temporalPaths.size() - 1); return i; }