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:eu.matejkormuth.rpgdavid.text.TextTable.java

/**
 * Formats line to specified style. Use after rendering all content!
 * //from  w ww.j a v a  2 s . c o  m
 * @param line
 *            line to apply style to
 * @param style
 *            style to apply to line
 */
public void formatLine(final int line, final String style) {
    Preconditions.checkPositionIndex(line, this.lines.length);
    this.lines[line].insert(0, style);
}

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

/**
 * Returns the asymmetry factor of this feature.
 *
 * @return a {@link java.lang.Double} object.
 * @param rtValues/*from   w  w  w. j  a  v a 2 s .  c om*/
 *            an array of
 *            {@link io.github.msdk.datamodel.rawdata.ChromatographyInfo}
 *            objects.
 * @param intensityValues
 *            an array of float.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
public static @Nullable Double getAsymmetryFactor(@Nonnull ChromatographyInfo rtValues[],
        @Nonnull float[] intensityValues, @Nonnull Integer size) {

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

    if (size == 0)
        return null;

    Float height = getMaxHeight(intensityValues, size);
    Float rt = getRt(rtValues, intensityValues, size);

    if (height == null || rt == null)
        return null;

    double rtValues3[] = findRTs(height * 0.1, rt, rtValues, intensityValues, size);
    Double af = (rtValues3[1] - rt) / (rt - rtValues3[0]);
    if (af < 0) {
        af = null;
    }
    return af;
}

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

/**
 * Formats specified part of specified line to specified style.
 * //from  w  ww.j  a  va 2s.co m
 * @param line
 *            line to format
 * @param index
 *            index, where style should start
 * @param length
 *            length of styled content
 * @param style
 *            style to apply to region
 */
public void formatPart(final int line, final int index, final int length, final String style) {
    Preconditions.checkPositionIndex(line, this.lines.length);
    this.lines[line].insert(index, style);
    this.lines[line].insert(index + style.length() + length, RESET_STYLE);
}

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

/**
 * Applies specified style to specified text, if found in specified line.
 * //  w  w w  . ja v a 2 s.c  o  m
 * @param line
 *            line to search for
 * @param formatted
 *            text to apply style to
 * @param style
 *            style to be applied
 */
public void formatString(final int line, final String formatted, final String style) {
    Preconditions.checkPositionIndex(line, this.lines.length);
    int index = this.lines[line].indexOf(formatted);
    this.formatPart(line, index, formatted.length(), style);
}

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

private static double[] findRTs(double intensity, float rt, @Nonnull ChromatographyInfo rtValues[],
        @Nonnull float[] intensityValues, @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(rtValues);
    Preconditions.checkNotNull(intensityValues);
    Preconditions.checkNotNull(size);/*from   w  w w.ja  v  a  2 s  .  c  o  m*/
    Preconditions.checkPositionIndex(size, rtValues.length);
    Preconditions.checkPositionIndex(size, intensityValues.length);

    double lastDiff1 = intensity, lastDiff2 = intensity, currentDiff;
    double x1 = 0, x2 = 0, x3 = 0, x4 = 0, y1 = 0, y2 = 0, y3 = 0, y4 = 0, currentRT;

    // Find the data points closet to input intensity on both side of the
    // apex
    for (int i = 1; i < size - 1; i++) {

        currentDiff = Math.abs(intensity - intensityValues[i]);
        currentRT = rtValues[i].getRetentionTime();

        if (currentDiff < lastDiff1 & currentDiff > 0 & currentRT <= rt) {
            x1 = rtValues[i].getRetentionTime();
            y1 = intensityValues[i];
            x2 = rtValues[i + 1].getRetentionTime();
            y2 = intensityValues[i + 1];
            lastDiff1 = currentDiff;
        } else if (currentDiff < lastDiff2 & currentDiff > 0 & currentRT >= rt) {
            x3 = rtValues[i - 1].getRetentionTime();
            y3 = intensityValues[i - 1];
            x4 = rtValues[i].getRetentionTime();
            y4 = intensityValues[i];
            lastDiff2 = currentDiff;
        }

    }

    // Calculate RT value for input intensity based on linear regression
    double slope, intercept, rt1, rt2;
    if (y1 > 0) {
        slope = (y2 - y1) / (x2 - x1);
        intercept = y1 - (slope * x1);
        rt1 = (intensity - intercept) / slope;
    } else { // Straight drop of peak to 0 intensity
        rt1 = x2;
    }
    if (y4 > 0) {
        slope = (y4 - y3) / (x4 - x3);
        intercept = y3 - (slope * x3);
        rt2 = (intensity - intercept) / slope;
    } else { // Straight drop of peak to 0 intensity
        rt2 = x3;
    }

    return new double[] { rt1, rt2 };
}

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

/**
 * Returns content of specified line.//w  w  w.  j  a  v a  2  s .  co m
 * 
 * @param index
 *            line to get content of
 * @return content of specified line
 */
public String getLine(final int index) {
    Preconditions.checkPositionIndex(index, this.lines.length);
    return this.lines[index].toString();
}