Example usage for com.google.common.base Preconditions checkPositionIndex

List of usage examples for com.google.common.base Preconditions checkPositionIndex

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkPositionIndex.

Prototype

public static int checkPositionIndex(int index, int size) 

Source Link

Document

Ensures that index specifies a valid position in an array, list or string of size size .

Usage

From source file:io.github.msdk.util.ChromatogramUtil.java

/**
 * Returns the start retention time of this feature.
 *
 * @return a Float./*from   ww  w.  j a  v a 2  s  . c om*/
 * @param rtValues
 *            an array of
 *            {@link io.github.msdk.datamodel.rawdata.ChromatographyInfo}
 *            objects.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
public static @Nullable Float getRtStart(@Nonnull ChromatographyInfo rtValues[], @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(rtValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, rtValues.length);

    if (size == 0)
        return null;

    return rtValues[0].getRetentionTime();
}

From source file:io.github.msdk.util.MsSpectrumUtil.java

/**
 * <p>normalizeIntensity.</p>
 *
 * @param intensityValues an array of float.
 * @param size a {@link java.lang.Integer} object.
 * @param scale a {@link java.lang.Float} object.
 *///ww  w.j  av a2  s.c  om
public static void normalizeIntensity(@Nonnull float intensityValues[], @Nonnull Integer size,
        @Nonnull Float scale) {

    // Parameter check
    Preconditions.checkNotNull(intensityValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, intensityValues.length);
    Preconditions.checkNotNull(scale);

    final float max = getMaxIntensity(intensityValues, size);

    for (int i = 0; i < intensityValues.length; i++) {
        intensityValues[i] = intensityValues[i] / max * scale;
    }

}

From source file:io.github.msdk.util.ChromatogramUtil.java

/**
 * Returns the end retention time of this feature.
 *
 * @return a Float./*w w  w . j  a v  a 2  s. c  o  m*/
 * @param rtValues
 *            an array of
 *            {@link io.github.msdk.datamodel.rawdata.ChromatographyInfo}
 *            objects.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
public static Float getRtEnd(@Nonnull ChromatographyInfo rtValues[], @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(rtValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, rtValues.length);

    if (size == 0)
        return null;

    return rtValues[size - 1].getRetentionTime();

}

From source file:eu.matejkormuth.rpgdavid.text.TextTable.java

/**
 * Renders specified text on specified line and specified index. Index must
 * be bigger then zero and smalled then width of row. If is too long, it
 * will be trunctated./*from   w w  w .  j av a2s . c om*/
 * 
 * @param line
 *            line to insert content at
 * @param index
 *            index to insert content at
 * @param content
 *            content to insert
 */
public void renderText(final int line, final int index, final String content) {
    Preconditions.checkPositionIndex(line, this.lines.length);
    Preconditions.checkPositionIndex(index, this.internalWidth);
    if (content.length() > this.internalWidth - index) {
        this.lines[line].replace(index, index + content.length() - (this.internalWidth - index),
                content.substring(0, content.length() - (this.internalWidth - index)));
    } else {
        this.lines[line].replace(index, index + content.length(), content);
    }
}

From source file:io.github.msdk.util.ChromatogramUtil.java

/**
 * Returns the duration of this feature.
 *
 * @return a float./* w w  w. j a v a  2s. c  o m*/
 * @param rtValues
 *            an array of
 *            {@link io.github.msdk.datamodel.rawdata.ChromatographyInfo}
 *            objects.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
public static @Nullable Float getDuration(@Nonnull ChromatographyInfo rtValues[], @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(rtValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, rtValues.length);

    if (size == 0)
        return null;

    Float start = getRtStart(rtValues, size);
    Float end = getRtEnd(rtValues, size);

    if (start == null || end == null)
        return null;

    return end - start;
}

From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.utils.swing.models.AbstractNameValueTableModel.java

@Override
public String getColumnName(final int column) {
    Preconditions.checkPositionIndex(column, this.columnNames.size());

    return this.columnNames.get(column);
}

From source file:org.apache.kudu.util.Slice.java

/**
 * Transfers this buffer's data to the specified destination starting at
 * the specified absolute {@code index} until the destination's position
 * reaches its limit.//from w w w .  j a v  a 2s. co  m
 *
 * @throws IndexOutOfBoundsException if the specified {@code index} is less than {@code 0} or
 * if {@code index + dst.remaining()} is greater than
 * {@code this.capacity}
 */
public void getBytes(int index, ByteBuffer destination) {
    Preconditions.checkPositionIndex(index, this.length);
    index += offset;
    destination.put(data, index, Math.min(length, destination.remaining()));
}

From source file:io.github.msdk.util.MsSpectrumUtil.java

/**
 * <p>msSpectrumToString.</p>
 *
 * @param mzValues an array of double.//from w w  w  .j  a v a 2s .c  om
 * @param intensityValues an array of float.
 * @param size a {@link java.lang.Integer} object.
 * @return a {@link java.lang.String} object.
 */
@SuppressWarnings("null")
public static @Nonnull String msSpectrumToString(@Nonnull double mzValues[], @Nonnull float intensityValues[],
        @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(mzValues);
    Preconditions.checkNotNull(intensityValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, mzValues.length);
    Preconditions.checkPositionIndex(size, intensityValues.length);

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < size; i++) {
        b.append(mzValues[i]);
        b.append(" ");
        b.append(intensityValues[i]);
        if (i < size - 1)
            b.append("\n");
    }

    return b.toString();

}

From source file:eu.matejkormuth.rpgdavid.text.TextTable.java

/**
 * Inserts specified content at specified line aligning content to center.
 * If is content too long, it will be tructated.
 * /*from   w w w .j av a2  s . c  o  m*/
 * @param line
 *            line to insert at
 * @param content
 *            content to insert
 */
public void renderCenteredText(final int line, final String content) {
    Preconditions.checkPositionIndex(line, this.lines.length);
    Preconditions.checkArgument(content.length() < this.internalWidth);
    this.renderText(line, this.internalWidth / 2 - content.length() / 2, content);
}

From source file:io.github.msdk.util.ChromatogramUtil.java

/**
 * Returns the maximum height of this chromatogram, or null if size == 0.
 *
 * @return a double.//from  w  w w  .  j  a  v a2 s  .c o m
 * @param intensityValues
 *            an array of float.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
public static @Nullable Float getMaxHeight(@Nonnull float[] intensityValues, @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(intensityValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, intensityValues.length);

    if (size == 0)
        return null;

    // Find the maximum intensity index
    int max = 0;
    for (int i = 1; i < size; i++) {
        if (intensityValues[i] > intensityValues[max]) {
            max = i;
        }
    }

    return intensityValues[max];

}