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

The following examples show how to use com.google.common.base.Preconditions#checkPositionIndex() . 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
Source File: Matrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: Matrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: Matrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: Matrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: Vector.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: MMapMatrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 7
Source File: QMatrix.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 8
Source File: PropertyInteger.java    From Cleanstone with MIT License 4 votes vote down vote up
@Override
public int serialize(Integer value) {
    Preconditions.checkPositionIndex(minValue, maxValue);
    return value - minValue;
}
 
Example 9
Source File: MMapDictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String getWord(int id) {
  Preconditions.checkPositionIndex(id, nWords);
  position(entryPosition(id));
  return readWord();
}
 
Example 10
Source File: MMapDictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public EntryType getType(int id) {
  Preconditions.checkPositionIndex(id, size);
  position(entryFieldPosition(id, typeOffset()));
  return readType();
}
 
Example 11
Source File: Dictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Entry getEntry(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id];
}
 
Example 12
Source File: MMapDictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public long getCount(int id) {
  Preconditions.checkPositionIndex(id, size);
  position(entryFieldPosition(id, countOffset()));
  return readCount();
}
 
Example 13
Source File: QCodeArray.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public int get(int i) {
  Preconditions.checkPositionIndex(i, codes.length);
  return codes[i];
}
 
Example 14
Source File: ImmutableIntList.java    From Bats with 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 15
Source File: Vector.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void addAt(int i, float v) {
  Preconditions.checkPositionIndex(i, m);
  data[i] += v;
}
 
Example 16
Source File: PropertyInteger.java    From Cleanstone with MIT License 4 votes vote down vote up
@Override
public Integer deserialize(int serializedValue) {
    Preconditions.checkPositionIndex(0, totalValuesAmount - 1);
    return serializedValue + minValue;
}
 
Example 17
Source File: Dictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public long getCount(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id].count;
}
 
Example 18
Source File: Dictionary.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public EntryType getType(int id) {
  Preconditions.checkPositionIndex(id, size);
  return words[id].type;
}
 
Example 19
Source File: ReadOnlyDocument.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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 File: AclFeature.java    From hadoop with 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];
}