Java Code Examples for com.google.common.base.Preconditions#checkPositionIndex()

The following examples show how to use com.google.common.base.Preconditions#checkPositionIndex() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public float dotRow(final Vector vec, int i) {
  Preconditions.checkPositionIndex(i, m);
  Preconditions.checkArgument(vec.size() == n);
  float d = 0.0f;
  for (int j = 0; j < n; j++) {
    d += data[i * n + j] * vec.at(j);
  }
  if (Float.isNaN(d)) {
    throw new IllegalStateException("Encountered NaN.");
  }
  return d;
}
 
Example 2
public void addRow(final Vector vec, int i, float a) {
  Preconditions.checkPositionIndex(i, m);
  Preconditions.checkArgument(vec.size() == n);
  for (int j = 0; j < n; j++) {
    data[i * n + j] += a * vec.at(j);
  }
}
 
Example 3
public void multiplyRow(final Vector nums, int ib, int ie) {
  if (ie == -1) {
    ie = m;
  }
  Preconditions.checkPositionIndex(ie, nums.size());
  for (int i = ib; i < ie; i++) {
    float num = nums.at(i - ib);
    if (n != 0) {
      for (int j = 0; j < this.n; j++) {
        data[i * n + j] *= num;
      }
    }
  }
}
 
Example 4
public void divideRow(final Vector denoms, int ib, int ie) {
  if (ie == -1) {
    ie = m;
  }
  Preconditions.checkPositionIndex(ie, denoms.size());
  for (int i = ib; i < ie; i++) {
    float denom = denoms.at(i - ib);
    if (denom != 0) {
      for (int j = 0; j < this.n; j++) {
        data[i * n + j] /= denom;
      }
    }
  }
}
 
Example 5
public void addRow(ReadableMatrix A, int i, float a) {
  Preconditions.checkPositionIndex(i, A.m());
  Preconditions.checkArgument(m == A.n());
  for (int j = 0; j < A.n(); j++) {
    data[j] += a * A.at(i, j);
  }
}
 
Example 6
public float dotRow(Vector vec, int i) {
  Preconditions.checkPositionIndex(i, m);
  Preconditions.checkArgument(vec.size() == n);
  float norm = 1f;
  if (qnorm) {
    int cPosition = npq.getCentroidsPosition(0, normCodes.get(i));
    norm = npq.getCentroid(cPosition);
  }
  return pq.mulCode(vec, codes, i, norm);
}
 
Example 7
public float dotRow(final Vector vec, int i) {
  Preconditions.checkPositionIndex(i, m);
  Preconditions.checkArgument(vec.size() == n);
  float d = 0.0f;
  float[] r = atRow(i);
  for (int j = 0; j < n; j++) {
    d += r[j] * vec.at(j);
  }
  return d;
}
 
Example 8
Source Project: Bats   File: ImmutableIntList.java    License: Apache License 2.0 4 votes vote down vote up
protected AbstractIndexedListIterator(int size, int position) {
  Preconditions.checkPositionIndex(position, size);
  this.size = size;
  this.position = position;
}
 
Example 9
@Override
public EntryType getType(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id].type;
}
 
Example 10
@Override
public long getCount(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id].count;
}
 
Example 11
Source Project: Cleanstone   File: PropertyInteger.java    License: MIT License 4 votes vote down vote up
@Override
public Integer deserialize(int serializedValue) {
    Preconditions.checkPositionIndex(0, totalValuesAmount - 1);
    return serializedValue + minValue;
}
 
Example 12
public void addAt(int i, float v) {
  Preconditions.checkPositionIndex(i, m);
  data[i] += v;
}
 
Example 13
Source Project: Cleanstone   File: PropertyInteger.java    License: MIT License 4 votes vote down vote up
@Override
public int serialize(Integer value) {
    Preconditions.checkPositionIndex(minValue, maxValue);
    return value - minValue;
}
 
Example 14
public int get(int i) {
  Preconditions.checkPositionIndex(i, codes.length);
  return codes[i];
}
 
Example 15
@Override
public long getCount(int id) {
  Preconditions.checkPositionIndex(id, size);
  position(entryFieldPosition(id, countOffset()));
  return readCount();
}
 
Example 16
@Override
public Entry getEntry(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id];
}
 
Example 17
@Override
public EntryType getType(int id) {
  Preconditions.checkPositionIndex(id, size);
  position(entryFieldPosition(id, typeOffset()));
  return readType();
}
 
Example 18
@Override
public String getWord(int id) {
  Preconditions.checkPositionIndex(id, nWords);
  position(entryPosition(id));
  return readWord();
}
 
Example 19
/**
 * Finds the given text in the document, starting from the given offset.
 *
 * @param needle the text to find.
 * @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);
}
 
Example 20
Source Project: hadoop   File: AclFeature.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Get the entry at the specified position
 * @param pos Position of the entry to be obtained
 * @return integer representation of AclEntry
 * @throws IndexOutOfBoundsException if pos out of bound
 */
int getEntryAt(int pos) {
  Preconditions.checkPositionIndex(pos, entries.length,
      "Invalid position for AclEntry");
  return entries[pos];
}