From 294a70fcf42291a2863fee933cb18255e3c29ab7 Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Wed, 24 Oct 2012 21:45:03 +0000 Subject: [PATCH] Negate state value. --- pom.xml | 2 +- src/main/java/pl/com/it_crowd/youtrack/api/Filter.java | 10 +++++++--- src/main/java/pl/com/it_crowd/youtrack/api/defaults/StateValues.java | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- src/test/java/pl/com/it_crowd/youtrack/api/rest/FilterTest.java | 5 ++++- 4 files changed, 72 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index a9decb7..7a8f793 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ pl.com.it_crowd.youtrack.api.rest - ${build.sourceDirectory} + ${project.build.sourceDirectory} false false diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/Filter.java b/src/main/java/pl/com/it_crowd/youtrack/api/Filter.java index 11a91bc..b0721c5 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/Filter.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/Filter.java @@ -58,7 +58,7 @@ public final class Filter { return new Filter().resolved(date); } - public static Filter stateFilter(StateValues state) + public static Filter stateFilter(StateValues... state) { return new Filter().state(state); } @@ -191,9 +191,13 @@ public final class Filter { return this; } - public Filter state(StateValues state) + public Filter state(StateValues... state) { - return state(state.getFilterValue()); + final StringBuilder stringBuilder = new StringBuilder(); + for (StateValues value : state) { + stringBuilder.append(",").append(value.getFilterValue()); + } + return state(stringBuilder.length() > 0 ? stringBuilder.substring(1) : stringBuilder.toString()); } public Filter summary(String summary) diff --git a/src/main/java/pl/com/it_crowd/youtrack/api/defaults/StateValues.java b/src/main/java/pl/com/it_crowd/youtrack/api/defaults/StateValues.java index 9bf42d3..fa626d4 100644 --- a/src/main/java/pl/com/it_crowd/youtrack/api/defaults/StateValues.java +++ b/src/main/java/pl/com/it_crowd/youtrack/api/defaults/StateValues.java @@ -1,9 +1,34 @@ package pl.com.it_crowd.youtrack.api.defaults; public enum StateValues { - Submitted, Open, InProgress("{In Progress}", "In Progress"), ToBeDiscussed("{To be discussed}", "To be discussed"), Reopened, CantReproduce( - "{Can't Reproduce}", "Can't Reproduce"), Duplicate, Fixed, WontFix("{Won't fix}", "Won't fix"), - Incomplete, Obsolete, Verified, New, Resolved("Resolved", null), Unresolved("Unresolved", null); + Submitted, + Open, + InProgress("{In Progress}", "In Progress"), + ToBeDiscussed("{To be discussed}", "To be discussed"), + Reopened, + CantReproduce("{Can't Reproduce}", "Can't Reproduce"), + Duplicate, + Fixed, + WontFix("{Won't fix}", "Won't fix"), + Incomplete, + Obsolete, + Verified, + New, + NotSubmitted(true, Submitted), + NotOpen(true, Open), + NotInProgress(true, InProgress), + NotToBeDiscussed(true, ToBeDiscussed), + NotReopened(true, Reopened), + NotCantReproduce(true, CantReproduce), + NotDuplicate(true, Duplicate), + NotFixed(true, Fixed), + NotWontFix(true, WontFix), + NotIncomplete(true, Incomplete), + NotObsolete(true, Open), + NotVerified(true, Verified), + NotNew(true, New), + Resolved("Resolved", null), + Unresolved("Unresolved", null); // ------------------------------ FIELDS ------------------------------ @@ -11,29 +36,54 @@ public enum StateValues { private String filterValue; + private boolean not; + // --------------------------- CONSTRUCTORS --------------------------- private StateValues() { - filterValue = name(); - commandValue = name(); + this(false); + } + + private StateValues(boolean not) + { + this(not, null, null); } private StateValues(String filterValue, String commandValue) { - this.filterValue = filterValue; - this.commandValue = commandValue; + this(false, filterValue, commandValue); + } + + private StateValues(boolean not, StateValues value) + { + this(not, value.getFilterValue(), value.getCommandValue()); + } + + private StateValues(boolean not, String filterValue, String commandValue) + { + this.not = not; + this.filterValue = filterValue == null ? name() : filterValue; + this.commandValue = commandValue == null ? name() : commandValue; + } + +// ------------------------ CANONICAL METHODS ------------------------ + + @Override + public String toString() + { + return getCommandValue(); } -// --------------------- GETTER / SETTER METHODS --------------------- +// -------------------------- OTHER METHODS -------------------------- public String getCommandValue() { - return commandValue; + return (not ? "-" : "") + commandValue; } public String getFilterValue() { - return filterValue; + return (not ? "-" : "") + filterValue; } } diff --git a/src/test/java/pl/com/it_crowd/youtrack/api/rest/FilterTest.java b/src/test/java/pl/com/it_crowd/youtrack/api/rest/FilterTest.java index 9757ef8..0e71f20 100644 --- a/src/test/java/pl/com/it_crowd/youtrack/api/rest/FilterTest.java +++ b/src/test/java/pl/com/it_crowd/youtrack/api/rest/FilterTest.java @@ -119,6 +119,10 @@ public class FilterTest { Assert.assertEquals("state:" + encodeURL("Obsolete"), Filter.stateFilter(StateValues.Obsolete).toString()); Assert.assertEquals("state:" + encodeURL("Open"), Filter.stateFilter(StateValues.Open).toString()); Assert.assertEquals("state:" + encodeURL("{Won't fix}"), Filter.stateFilter(StateValues.WontFix).toString()); + Assert.assertEquals("state:" + encodeURL("-{Won't fix}"), Filter.stateFilter(StateValues.NotWontFix).toString()); + Assert.assertEquals("state:" + encodeURL("-Verified"), Filter.stateFilter(StateValues.NotVerified).toString()); + Assert.assertEquals("state:" + encodeURL("-Verified,{Can't Reproduce},Obsolete,{Won't fix}"), + Filter.stateFilter(StateValues.NotVerified, StateValues.CantReproduce, StateValues.Obsolete, StateValues.WontFix).toString()); } @Test @@ -143,7 +147,6 @@ public class FilterTest { } @Test - public void updaterFilter() { Assert.assertEquals("updated by:bernard", Filter.updaterFilter("bernard").toString()); -- libgit2 0.24.0