-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotating classes of util package #1
base: master
Are you sure you want to change the base?
Changes from 9 commits
adde8f7
a1e270d
f0c7f44
91e7996
5187fb2
9170b66
0129347
2940ec6
a87a7fe
428f5fd
9ec2c44
d9f54c8
1bf39c6
a57e7d0
6cee18b
dfe72f2
a74ac32
c608b71
00e9867
112248e
f3cfb7e
855cf84
e96b1a7
ca5ae72
abee324
5bbf6e7
915e208
39f4314
dbb06b9
4e439f5
53d47ef
473c6de
a59a8c5
07fe742
566f7af
1102c66
a91c465
aed29ed
dd1859e
623e052
2cf074f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,6 +365,19 @@ | |
</contributors> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker-qual</artifactId> | ||
<version>2.8.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>jdk8</artifactId> | ||
<version>2.8.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-statistics-distribution</artifactId> | ||
|
@@ -460,6 +473,7 @@ | |
</dependencies> | ||
|
||
<properties> | ||
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk> | ||
<!-- Do not change: "math" is the name of the component even if the | ||
name of the base package evolves with major release numbers | ||
(see "commons.osgi.symbolicName", below). --> | ||
|
@@ -516,6 +530,47 @@ | |
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<!-- This plugin will set properties values using dependency information --> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>properties</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerArguments> | ||
<Xmaxerrs>10000</Xmaxerrs> | ||
<Xmaxwarns>10000</Xmaxwarns> | ||
</compilerArguments> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker</artifactId> | ||
<version>2.8.2</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
<annotationProcessors> | ||
<!-- Add all the checkers you want to enable here --> | ||
<annotationProcessor>org.checkerframework.checker.index.IndexChecker</annotationProcessor> | ||
</annotationProcessors> | ||
<compilerArgs> | ||
<!-- location of the annotated JDK, which comes from a Maven dependency --> | ||
<arg>-Xbootclasspath/p:${annotatedJdk}</arg> | ||
<arg>-AonlyDefs=^org\.apache\.commons\.math4\.util\.</arg> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add |
||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
|
@@ -1048,5 +1103,40 @@ | |
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>mathjax-java8</id> | ||
<activation><jdk>[1.8,)</jdk></activation> | ||
<properties> | ||
<!-- MathJax requires additional Javadoc qualifier for Java8+ --> | ||
<allowscript.javadoc.qualifier>--allow-script-in-comments</allowscript.javadoc.qualifier> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>checker</id> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker</artifactId> | ||
<version>2.8.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.10</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>properties</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ public static void parseAndIgnoreWhitespace(final String source, | |
* @param pos input/output parsing parameter. | ||
* @return the first non-whitespace character. | ||
*/ | ||
@SuppressWarnings("index:argument.type.incompatible") // #1: index < n (source.length) as checked by the condition of the loop and for the first time by the if statement | ||
public static char parseNextCharacter(final String source, | ||
final ParsePosition pos) { | ||
int index = pos.getIndex(); | ||
|
@@ -84,7 +85,7 @@ public static char parseNextCharacter(final String source, | |
if (index < n) { | ||
char c; | ||
do { | ||
c = source.charAt(index++); | ||
c = source.charAt(index++); // #1 | ||
} while (Character.isWhitespace(c) && index < n); | ||
pos.setIndex(index); | ||
|
||
|
@@ -105,6 +106,7 @@ public static char parseNextCharacter(final String source, | |
* @param pos input/output parsing parameter. | ||
* @return the special number. | ||
*/ | ||
@SuppressWarnings("index:argument.type.incompatible") // #1: startIndex is @NonNegative, and as startIndex + n (@NonNegative) < source.length(), startIndex < source.length | ||
private static Number parseNumber(final String source, final double value, | ||
final ParsePosition pos) { | ||
Number ret = null; | ||
|
@@ -118,7 +120,7 @@ private static Number parseNumber(final String source, final double value, | |
final int startIndex = pos.getIndex(); | ||
final int endIndex = startIndex + n; | ||
if (endIndex < source.length() && | ||
source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) { | ||
source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) { // #1 | ||
ret = Double.valueOf(value); | ||
pos.setIndex(endIndex); | ||
} | ||
|
@@ -166,6 +168,7 @@ public static Number parseNumber(final String source, final NumberFormat format, | |
* @param pos input/output parsing parameter. | ||
* @return true if the expected string was there | ||
*/ | ||
@SuppressWarnings("index:argument.type.incompatible") // The substring function is called only when the previous two condition fail, i.e, only when startIndex < source.length() && endIndex <= source.length() | ||
public static boolean parseFixedstring(final String source, | ||
final String expected, | ||
final ParsePosition pos) { | ||
|
@@ -174,7 +177,7 @@ public static boolean parseFixedstring(final String source, | |
final int endIndex = startIndex + expected.length(); | ||
if ((startIndex >= source.length()) || | ||
(endIndex > source.length()) || | ||
(source.substring(startIndex, endIndex).compareTo(expected) != 0)) { | ||
(source.substring(startIndex, endIndex).compareTo(expected) != 0)) { // #1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The explanation |
||
// set index back to start, error index should be the start index | ||
pos.setIndex(startIndex); | ||
pos.setErrorIndex(startIndex); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,10 @@ | |
|
||
import org.apache.commons.math4.exception.NullArgumentException; | ||
|
||
import org.checkerframework.checker.index.qual.IndexFor; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
import org.checkerframework.checker.index.qual.IndexOrHigh; | ||
|
||
|
||
/** | ||
* A Simple K<sup>th</sup> selector implementation to pick up the | ||
|
@@ -76,7 +80,12 @@ public PivotingStrategyInterface getPivotingStrategy() { | |
* @param k the index whose value in the array is of interest | ||
* @return K<sup>th</sup> value | ||
*/ | ||
public double select(final double[] work, final int[] pivotsHeap, final int k) { | ||
@SuppressWarnings({"index:array.access.unsafe.low", "index:argument.type.incompatible"}) /* | ||
#1: node is always @NonNegative as it is changed only in #0.1 where it is minimum of 2*node + 1(or 2) and either pivotsHeap.length or end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then node should be annotated |
||
pivotsHeap.length is @NonNegative as it is a length, end is also @NonNegative as it is initialized 0 and changed only in #0.2 where end = pivot >= k that is @NonNegative | ||
#3: begin and end are @NonNegative as t is assign | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "as t is assign" mean? |
||
*/ | ||
public double select(final double[] work, final int[] pivotsHeap, final @IndexFor("#1") int k) { | ||
int begin = 0; | ||
int end = work.length; | ||
int node = 0; | ||
|
@@ -85,15 +94,15 @@ public double select(final double[] work, final int[] pivotsHeap, final int k) { | |
final int pivot; | ||
|
||
if (usePivotsHeap && node < pivotsHeap.length && | ||
pivotsHeap[node] >= 0) { | ||
pivotsHeap[node] >= 0) { // #1 | ||
// the pivot has already been found in a previous call | ||
// and the array has already been partitioned around it | ||
pivot = pivotsHeap[node]; | ||
pivot = pivotsHeap[node]; // #1 | ||
} else { | ||
// select a pivot and partition work array around it | ||
pivot = partition(work, begin, end, pivotingStrategy.pivotIndex(work, begin, end)); | ||
pivot = partition(work, begin, end, pivotingStrategy.pivotIndex(work, begin, end)); // #2 | ||
if (usePivotsHeap && node < pivotsHeap.length) { | ||
pivotsHeap[node] = pivot; | ||
pivotsHeap[node] = pivot; // #1 | ||
} | ||
} | ||
|
||
|
@@ -102,15 +111,15 @@ public double select(final double[] work, final int[] pivotsHeap, final int k) { | |
return work[k]; | ||
} else if (k < pivot) { | ||
// the element is in the left partition | ||
end = pivot; | ||
node = FastMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); | ||
end = pivot; // #0.2 | ||
node = FastMath.min(2 * node + 1, usePivotsHeap ? pivotsHeap.length : end); // #0.1 | ||
} else { | ||
// the element is in the right partition | ||
begin = pivot + 1; | ||
node = FastMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); | ||
node = FastMath.min(2 * node + 2, usePivotsHeap ? pivotsHeap.length : end); // #0.1 | ||
} | ||
} | ||
Arrays.sort(work, begin, end); | ||
Arrays.sort(work, begin, end); // #3 | ||
return work[k]; | ||
} | ||
|
||
|
@@ -125,7 +134,7 @@ public double select(final double[] work, final int[] pivotsHeap, final int k) { | |
* @param pivot initial index of the pivot | ||
* @return index of the pivot after partition | ||
*/ | ||
private int partition(final double[] work, final int begin, final int end, final int pivot) { | ||
private @NonNegative int partition(final double[] work, final @IndexFor("#1") int begin, final @IndexOrHigh("#1") int end, final @IndexFor("#1") int pivot) { | ||
|
||
final double value = work[pivot]; | ||
work[pivot] = work[begin]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation in this file.