List of usage examples for com.google.common.base Preconditions checkPositionIndex
public static int checkPositionIndex(int index, int size)
From source file:com.alibaba.supersonic.base.infrastructure.View.java
/** * Returns a pointer to the mutable (resettable) column. * /*from w ww . j ava 2s. co m*/ * @param column_index * @return */ Column mutableColumn(int column_index) { Preconditions.checkPositionIndex(column_index, columnCount()); return columns_[column_index]; }
From source file:com.alibaba.supersonic.base.infrastructure.TupleSchema.java
/** * Looks up an attribute with the specified name. O(log2(attribute count)). * The attribute must exist in the schema. */// ww w . ja va2 s .c o m public Attribute lookupAttribute(final String attributeName) { int position = lookupAttributePosition(attributeName); Preconditions.checkPositionIndex(position, attributes.size()); return attributes.get(position); }
From source file:eu.project.ttc.engines.morpho.Segmentation.java
private static List<CuttingPoint> getPossibleCuttingPoints(String str, int begin, int end, int nbMaxComponents, int minComponentSize) { List<CuttingPoint> l = Lists.newArrayList(); if (nbMaxComponents <= 1) return l; else {//from w ww. ja v a 2s. c o m String substring = str.substring(begin, end); int hyphenIndex = substring.indexOf(TermSuiteConstants.HYPHEN); if (hyphenIndex != -1) { Preconditions.checkPositionIndex(hyphenIndex + begin, str.length()); Preconditions.checkPositionIndex(hyphenIndex + begin + 1, str.length()); l.add(new CuttingPoint(hyphenIndex + begin, 1, true)); } else { for (int i = minComponentSize; i <= substring.length() - minComponentSize; i++) { Preconditions.checkPositionIndex(begin + i, str.length()); l.add(new CuttingPoint(begin + i, 0, false)); } } return l; } }
From source file:io.github.msdk.util.MsSpectrumUtil.java
/** * Returns the highest intensity value. Returns 0 if the list has no data * points.//from w w w . j a v a2s . com * * @return a {@link java.lang.Float} object. * @param intensityValues * an array of float. * @param size * a {@link java.lang.Integer} object. * @param mzValues * an array of double. * @param mzRange * a {@link com.google.common.collect.Range} object. */ public static @Nonnull Float getMaxIntensity(@Nonnull double mzValues[], @Nonnull float intensityValues[], @Nonnull Integer size, @Nonnull Range<Double> mzRange) { // Parameter check Preconditions.checkNotNull(mzValues); Preconditions.checkNotNull(intensityValues); Preconditions.checkNotNull(size); Preconditions.checkPositionIndex(size, mzValues.length); Preconditions.checkPositionIndex(size, intensityValues.length); Preconditions.checkNotNull(mzRange); Integer topIndex = getBasePeakIndex(mzValues, intensityValues, size, mzRange); if (topIndex == null) return 0f; return intensityValues[topIndex]; }
From source file:org.apache.hadoop.hbase.io.hfile.slab.Slab.java
ByteBuffer alloc(int bufferSize) throws InterruptedException { int newCapacity = Preconditions.checkPositionIndex(bufferSize, blockSize); ByteBuffer returnedBuffer = buffers.take(); returnedBuffer.clear().limit(newCapacity); return returnedBuffer; }
From source file:com.android.ide.common.blame.parser.aapt.ReadOnlyDocument.java
/** * Finds the given text in the document, starting from the given offset. * * @param needle the text to find.// w w w .j av a2 s . c o m * @param offset the starting point of the search. * @return the offset of the found result, or -1 if no match was found. */ int findText(@NonNull String needle, int offset) { Preconditions.checkPositionIndex(offset, mFileContents.length()); return mFileContents.indexOf(needle, offset); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.check.common.views.ResultsTableModel.java
@Override public Class<?> getColumnClass(final int column) { Preconditions.checkPositionIndex(column, COLUMNS_CLASSES.size()); return COLUMNS_CLASSES.get(column); }
From source file:com.alibaba.supersonic.base.infrastructure.View.java
/** * Resets View's columns from a sub-range in an another View. Sets the * row_count as well./*from w w w. ja v a 2s. co m*/ * * @param other * @param offset * @param row_count */ void resetFromSubRange(final View other, int offset, int row_count) { Preconditions.checkPositionIndex(offset, other.rowCount()); for (int i = 0; i < columnCount(); ++i) { mutableColumn(i).resetFromPlusOffset(other.column(i), offset); } setRowCount(row_count); }
From source file:com.android.ide.common.blame.parser.aapt.ReadOnlyDocument.java
int findTextBackwards(String needle, int offset) { Preconditions.checkPositionIndex(offset, mFileContents.length()); return mFileContents.lastIndexOf(needle, offset); }
From source file:com.google.devtools.build.lib.util.LongArrayList.java
/** * Add certain elements from the given array at a certain position in this list. * @param array the array from which to take the elements * @param fromIndex the position of the first element to add * @param length how many elements to add * @param position at which position to add these elements, adds at the end if equal to the size * @return whether this list has changed * @throws IndexOutOfBoundsException if fromIndex and length violate the boundaries of the given * array or atIndex is not a valid index in this array or equal to the size *///from w w w .jav a 2 s. c o m public boolean addAll(long[] array, int fromIndex, int length, int position) { Preconditions.checkNotNull(array); Preconditions.checkPositionIndex(fromIndex + length, array.length); if (length == 0) { return false; } // check other positions later to allow "adding" empty arrays anywhere within this array Preconditions.checkElementIndex(fromIndex, array.length); Preconditions.checkPositionIndex(position, size); copyBackAndGrow(position, length); System.arraycopy(array, fromIndex, this.array, position, length); return true; }