diff options
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java | 8 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java | 10 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java) | 2 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java) | 30 |
4 files changed, 34 insertions, 16 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java index 7ba13797017..735225e461e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueFinder.java @@ -23,10 +23,10 @@ package org.sonar.api.issue; import org.sonar.api.ServerComponent; import org.sonar.api.component.Component; import org.sonar.api.rules.Rule; +import org.sonar.api.utils.Paging; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.Collection; import java.util.List; @@ -62,10 +62,4 @@ public interface IssueFinder extends ServerComponent { @CheckForNull Issue findByKey(String key /* TODO @Nullable Integer currentUserId */); - - /* - Map<RuleKey, Rule> rules(Collection<Issue> issues); - - Map<String, Component> components(Collection<Issue> issues); -*/ } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index 796a6d42df7..d3fedd09ac7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -157,7 +157,7 @@ public class IssueQuery { public static class Builder { private enum Sort { - created, updated, closed, assignee; + created, updated, closed, assignee } private static final int DEFAULT_PAGE_SIZE = 100; @@ -265,15 +265,15 @@ public class IssueQuery { } public Builder pageSize(@Nullable Integer i) { - Preconditions.checkArgument(i == null || i.intValue() > 0, "Page size must be greater than 0 (got " + i + ")"); - Preconditions.checkArgument(i == null || i.intValue() < MAX_PAGE_SIZE, "Page size must be less than " + MAX_PAGE_SIZE + " (got " + i + ")"); + Preconditions.checkArgument(i == null || i > 0, "Page size must be greater than 0 (got " + i + ")"); + Preconditions.checkArgument(i == null || i < MAX_PAGE_SIZE, "Page size must be less than " + MAX_PAGE_SIZE + " (got " + i + ")"); this.pageSize = (i == null ? DEFAULT_PAGE_SIZE : i.intValue()); return this; } public Builder pageIndex(@Nullable Integer i) { - Preconditions.checkArgument(i == null || i.intValue() > 0, "Page index must be greater than 0 (got " + i + ")"); - this.pageIndex = (i == null ? DEFAULT_PAGE_INDEX : i.intValue()); + Preconditions.checkArgument(i == null || i > 0, "Page index must be greater than 0 (got " + i + ")"); + this.pageIndex = (i == null ? DEFAULT_PAGE_INDEX : i); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java index a56d44340e4..67932f0fe59 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/JRubyIssues.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/WebIssues.java @@ -31,7 +31,7 @@ import java.util.Map; * * @since 3.6 */ -public interface JRubyIssues extends ServerComponent { +public interface WebIssues extends ServerComponent { /** * Search for issues. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java index 867cec866ca..0fc31c4b18a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Paging.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/Paging.java @@ -18,10 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.api.issue; +package org.sonar.api.utils; /** - * TODO move outside this package * @since 3.6 */ public class Paging { @@ -30,20 +29,29 @@ public class Paging { private final int pageIndex; private final int total; - public Paging(int pageSize, int pageIndex, int total) { + private Paging(int pageSize, int pageIndex, int total) { this.pageSize = pageSize; this.pageIndex = pageIndex; this.total = total; } + /** + * Page index, starting with 1. + */ public int pageIndex() { return pageIndex; } + /** + * Maximum number of items per page. It is greater than 0. + */ public int pageSize() { return pageSize; } + /** + * Total number of items. It is greater than or equal 0. + */ public int total() { return total; } @@ -52,6 +60,9 @@ public class Paging { return (pageIndex - 1) * pageSize; } + /** + * Number of pages. It is greater than or equal 0. + */ public int pages() { int p = (total / pageSize); if ((total % pageSize) > 0) { @@ -59,4 +70,17 @@ public class Paging { } return p; } + + public static Paging create(int pageSize, int pageIndex, int totalItems) { + if (pageSize<1) { + throw new IllegalArgumentException("Page size must be strictly positive. Got " + pageSize); + } + if (pageIndex<1) { + throw new IllegalArgumentException("Page index must be strictly positive. Got " + pageIndex); + } + if (totalItems<0) { + throw new IllegalArgumentException("Total items must be positive. Got " + totalItems); + } + return new Paging(pageSize, pageIndex, totalItems); + } } |