List of usage examples for com.google.common.base Preconditions checkPositionIndex
public static int checkPositionIndex(int index, int size)
From source file:com.lithium.yoda.DateString.java
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { Preconditions.checkPositionIndex(1, arguments.length); timeCop = (LongObjectInspector) arguments[0]; outFormatter = DateTimeFormat.forPattern( ((WritableConstantStringObjectInspector) arguments[1]).getWritableConstantValue().toString()); return PrimitiveObjectInspectorFactory.javaStringObjectInspector; }
From source file:org.apache.mahout.math.PivotedMatrix.java
private static void swap(int[] pivot, int[] unpivot, int i, int j) { Preconditions.checkPositionIndex(i, pivot.length); Preconditions.checkPositionIndex(j, pivot.length); if (i != j) { int tmp = pivot[i]; pivot[i] = pivot[j];//from ww w. j av a 2 s . c o m pivot[j] = tmp; unpivot[pivot[i]] = i; unpivot[pivot[j]] = j; } }
From source file:com.google.security.zynamics.reil.translators.TranslationHelpers.java
/** * Generates a mask which starts at the lsb parameter and is width wide * * @param lsb the least significant bit valid 0-size.getBits(). * @param width the width valid 1-(lsb+width)-1 <=size.getBits(). * @param size The size of the mask valid 4-64. In OperandSize. * @return The mask.//from w ww. j av a 2s. c om */ public static long generateZeroMask(final int lsb, final int width, final OperandSize size) { Preconditions.checkNotNull(size, "Size argument can not be null"); Preconditions.checkPositionIndex(lsb, size.getBitSize() - 1); Preconditions.checkArgument(width >= 1); Preconditions.checkPositionIndex((lsb + width) - 1, size.getBitSize()); long mask = getAllBitsMask(size); final long msb = (lsb + width) - 1; final long xorBit = 1; for (long i = lsb; i <= msb; i++) { mask = (mask ^ (xorBit << i)); } return mask & getAllBitsMask(size); }
From source file:edu.byu.nlp.util.DenseCounter.java
/** {@inheritDoc} */ @Override/*from w w w .j a v a2 s . c o m*/ public int incrementCount(Integer ele, int val) { Preconditions.checkNotNull(ele); Preconditions.checkPositionIndex(ele, counts.length); int ret = counts[ele]; counts[ele] += val; return ret; }
From source file:ca.draconic.stipple.wangtiles.RecursiveTile.java
protected int errorsForSubtile(int x, int y, RecursiveTile<T> subtile) { final int subup, subdown, subleft, subright; Preconditions.checkPositionIndex(x, k); Preconditions.checkPositionIndex(y, k); if (x == 0) { subleft = getSet().colourSequences[this.left][y]; } else {/*from w w w . j av a 2 s. com*/ subleft = getSubtile(x - 1, y).right; } if (x == k - 1) { subright = getSet().colourSequences[this.right][y]; } else { subright = getSubtile(x + 1, y).left; } if (y == 0) { subup = getSet().colourSequences[this.up][x]; } else { subup = getSubtile(x, y - 1).down; } if (y == k - 1) { subdown = getSet().colourSequences[this.down][x]; } else { subdown = getSubtile(x, y + 1).up; } int errors = 0; if (subup != subtile.up) errors++; if (subdown != subtile.down) errors++; if (subleft != subtile.left) errors++; if (subright != subtile.right) errors++; return errors; }
From source file:io.github.msdk.util.MsSpectrumUtil.java
/** * Calculates the total ion current (=sum of all intensity values) * * @return a {@link java.lang.Float} object. * @param intensityValues/*from w w w . ja va 2s .c o m*/ * 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 getTIC(@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); float tic = 0f; for (int i = 0; i < size; i++) { if (mzRange.contains(mzValues[i])) tic += intensityValues[i]; } return tic; }
From source file:edu.byu.nlp.util.DenseCounter.java
/** {@inheritDoc} */ @Override/*w w w. j av a2 s . c o m*/ public int getCount(Integer ele) { Preconditions.checkNotNull(ele); Preconditions.checkPositionIndex(ele, counts.length); return counts[ele]; }
From source file:com.google.devtools.build.lib.util.LongArrayList.java
/** * Add a value at a specific position to this list. All elements at larger indices will * shift to the right by one./*from w w w . j av a 2s .c o m*/ * @param position may be any index within the array or equal to the size, to append at the end * @throws IndexOutOfBoundsException if the index is outside the interval [0, {@link #size()}) */ public void add(int position, long value) { Preconditions.checkPositionIndex(position, size); copyBackAndGrow(position, 1); set(position, value); }
From source file:com.eviware.loadui.ui.fx.util.Pager.java
public void setPage(int page) { Preconditions.checkPositionIndex(page, getNumPages() - 1); this.page.set(page); }
From source file:yaphyre.films.ImageFile.java
private void setColor(int x, int y, Color color) { Preconditions.checkPositionIndex(x, xResolution); Preconditions.checkPositionIndex(y, yResolution); pixelColors[y * xResolution + x] = color; }