Search in sources :

Example 1 with NonNegative

use of org.checkerframework.checker.index.qual.NonNegative in project checker-framework by typetools.

the class RandomTestLBC method test.

void test() {
    Random rand = new Random();
    int[] a = new int[8];
    @NonNegative double d1 = Math.random() * a.length;
    @NonNegative int deref = (int) (Math.random() * a.length);
    @NonNegative int deref2 = (int) (rand.nextDouble() * a.length);
    @NonNegative int deref3 = rand.nextInt(a.length);
}
Also used : Random(java.util.Random) NonNegative(org.checkerframework.checker.index.qual.NonNegative)

Example 2 with NonNegative

use of org.checkerframework.checker.index.qual.NonNegative in project checker-framework by typetools.

the class RegexMatcher method m.

static void m(String p, String s) {
    Matcher matcher = Pattern.compile(p).matcher(s);
    // The following line cannot be used as a test,
    // because the relation of matcher to p is not tracked,
    // so the upper bound is not known.
    // s.substring(matcher.start(), matcher.end());
    @NonNegative int i;
    i = matcher.start();
    i = matcher.end();
    // :: error: (assignment.type.incompatible)
    i = matcher.start(1);
    // :: error: (assignment.type.incompatible)
    i = matcher.end(1);
}
Also used : Matcher(java.util.regex.Matcher) NonNegative(org.checkerframework.checker.index.qual.NonNegative)

Example 3 with NonNegative

use of org.checkerframework.checker.index.qual.NonNegative in project checker-framework by typetools.

the class Calendar method getActualMinimum.

/**
 * Returns the minimum value that the specified calendar field
 * could have, given the time value of this <code>Calendar</code>.
 * <p>
 * <p>The default implementation of this method uses an iterative
 * algorithm to determine the actual minimum value for the
 * calendar field. Subclasses should, if possible, override this
 * with a more efficient implementation - in many cases, they can
 * simply return <code>getMinimum()</code>.
 *
 * @param field the calendar field
 * @return the minimum of the given calendar field for the time
 * value of this <code>Calendar</code>
 * @see #getMinimum(int)
 * @see #getMaximum(int)
 * @see #getGreatestMinimum(int)
 * @see #getLeastMaximum(int)
 * @see #getActualMaximum(int)
 * @since 1.2
 */
@NonNegative
public int getActualMinimum(@NonNegative int field) {
    int fieldValue = getGreatestMinimum(field);
    int endValue = getMinimum(field);
    // if we know that the minimum value is always the same, just return it
    if (fieldValue == endValue) {
        return fieldValue;
    }
    // clone the calendar so we don't mess with the real one, and set it to
    // accept anything for the field values
    Calendar work = (Calendar) this.clone();
    work.setLenient(true);
    // now try each value from getLeastMaximum() to getMaximum() one by one until
    // we get a value that normalizes to another value.  The last value that
    // normalizes to itself is the actual minimum for the current date
    int result = fieldValue;
    do {
        work.set(field, fieldValue);
        if (work.get(field) != fieldValue) {
            break;
        } else {
            result = fieldValue;
            fieldValue--;
        }
    } while (fieldValue >= endValue);
    return result;
}
Also used : BuddhistCalendar(sun.util.BuddhistCalendar) NonNegative(org.checkerframework.checker.index.qual.NonNegative)

Example 4 with NonNegative

use of org.checkerframework.checker.index.qual.NonNegative in project checker-framework by typetools.

the class Calendar method getActualMaximum.

/**
 * Returns the maximum value that the specified calendar field
 * could have, given the time value of this
 * <code>Calendar</code>. For example, the actual maximum value of
 * the <code>MONTH</code> field is 12 in some years, and 13 in
 * other years in the Hebrew calendar system.
 * <p>
 * <p>The default implementation of this method uses an iterative
 * algorithm to determine the actual maximum value for the
 * calendar field. Subclasses should, if possible, override this
 * with a more efficient implementation.
 *
 * @param field the calendar field
 * @return the maximum of the given calendar field for the time
 * value of this <code>Calendar</code>
 * @see #getMinimum(int)
 * @see #getMaximum(int)
 * @see #getGreatestMinimum(int)
 * @see #getLeastMaximum(int)
 * @see #getActualMinimum(int)
 * @since 1.2
 */
@NonNegative
public int getActualMaximum(@NonNegative int field) {
    int fieldValue = getLeastMaximum(field);
    int endValue = getMaximum(field);
    // if we know that the maximum value is always the same, just return it.
    if (fieldValue == endValue) {
        return fieldValue;
    }
    // clone the calendar so we don't mess with the real one, and set it to
    // accept anything for the field values.
    Calendar work = (Calendar) this.clone();
    work.setLenient(true);
    // last week of a month or year will contain the first day of the week.
    if (field == WEEK_OF_YEAR || field == WEEK_OF_MONTH)
        work.set(DAY_OF_WEEK, firstDayOfWeek);
    // now try each value from getLeastMaximum() to getMaximum() one by one until
    // we get a value that normalizes to another value.  The last value that
    // normalizes to itself is the actual maximum for the current date
    int result = fieldValue;
    do {
        work.set(field, fieldValue);
        if (work.get(field) != fieldValue) {
            break;
        } else {
            result = fieldValue;
            fieldValue++;
        }
    } while (fieldValue <= endValue);
    return result;
}
Also used : BuddhistCalendar(sun.util.BuddhistCalendar) NonNegative(org.checkerframework.checker.index.qual.NonNegative)

Aggregations

NonNegative (org.checkerframework.checker.index.qual.NonNegative)4 BuddhistCalendar (sun.util.BuddhistCalendar)2 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1