]> source.dussan.org Git - sonarqube.git/commitdiff
DAOv.2 - Added Indexable and IndexField to replace enums in Normalizers
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 27 May 2014 16:25:05 +0000 (18:25 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 27 May 2014 16:46:35 +0000 (18:46 +0200)
sonar-server/src/main/java/org/sonar/server/search/IndexField.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/search/Indexable.java [new file with mode: 0644]

diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexField.java b/sonar-server/src/main/java/org/sonar/server/search/IndexField.java
new file mode 100644 (file)
index 0000000..c20aeb0
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.search;
+
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+public class IndexField {
+
+  public static enum Type {
+    KEY, STRING, TEXT, DATE, BOOLEAN, NUMERIC, OBJECT, LIST
+  }
+
+  private Type type;
+  private String field;
+
+  private Boolean sortable;
+  private Boolean searchable;
+  private Boolean matchable;
+
+  IndexField(Type type, String field) {
+    this.type = type;
+    this.field = field;
+  }
+
+  public Boolean sortable() {
+    return sortable;
+  }
+
+  public IndexField sortable(Boolean sortable) {
+    this.sortable = sortable;
+    return this;
+  }
+
+  public Boolean searchable() {
+    return searchable;
+  }
+
+  public IndexField searchable(Boolean searchable) {
+    this.searchable = searchable;
+    return this;
+  }
+
+  public Boolean matchable() {
+    return matchable;
+  }
+
+  public IndexField matchable(Boolean matchable) {
+    this.matchable = matchable;
+    return this;
+  }
+
+  public Type type() {
+    return type;
+  }
+
+  public String field() {
+    return field;
+  }
+
+  @Override
+  public String toString() {
+    return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/search/Indexable.java b/sonar-server/src/main/java/org/sonar/server/search/Indexable.java
new file mode 100644 (file)
index 0000000..97f24ba
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.search;
+
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+import javax.annotation.CheckForNull;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @since 4.4
+ */
+public class Indexable {
+
+  public static Set<IndexField> ALL_FIELDS = new HashSet<IndexField>();
+
+  public static IndexField add(IndexField.Type type, String field){
+    IndexField indexField = new IndexField(type, field);
+    ALL_FIELDS.add(indexField);
+    return indexField;
+  }
+
+  public static IndexField addSearchable(IndexField.Type type, String field){
+    IndexField indexField = new IndexField(type, field)
+      .searchable(true);
+    ALL_FIELDS.add(indexField);
+    return indexField;
+  }
+
+  public static IndexField addSortable(IndexField.Type type, String field){
+    IndexField indexField = new IndexField(type, field)
+      .sortable(true);
+    ALL_FIELDS.add(indexField);
+    return indexField;
+  }
+
+  @CheckForNull
+  public static IndexField fromField(String field){
+    for(IndexField indexField:ALL_FIELDS){
+      if(indexField.field().equals(field)){
+        return indexField;
+      }
+    }
+    return null;
+  }
+
+  @Override
+  public String toString() {
+    return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+  }
+}
+