summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-12 14:44:45 (EDT)
committer Henrik Lynggaard Hansen2012-07-12 14:44:45 (EDT)
commita03f0aef2e3272a444e782f5657e44225664e774 (patch)
treeff444915c0493e75b945eb231e6d67c835ee1782
parent2e3f55d880a7c54c95afb2f243678f960c79c6bf (diff)
downloadorg.eclipse.hudson.core-a03f0aef2e3272a444e782f5657e44225664e774.zip
org.eclipse.hudson.core-a03f0aef2e3272a444e782f5657e44225664e774.tar.gz
org.eclipse.hudson.core-a03f0aef2e3272a444e782f5657e44225664e774.tar.bz2
Reformat hudson.searchrefs/changes/43/6743/1
Change-Id: I5005f3e09612ee7d3b6c8d2f8e4985703c2f3276 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/search/CollectionSearchIndex.java24
-rw-r--r--hudson-core/src/main/java/hudson/search/FixedSet.java21
-rw-r--r--hudson-core/src/main/java/hudson/search/ParsedQuickSilver.java75
-rw-r--r--hudson-core/src/main/java/hudson/search/QuickSilver.java26
-rw-r--r--hudson-core/src/main/java/hudson/search/Search.java124
-rw-r--r--hudson-core/src/main/java/hudson/search/SearchIndex.java11
-rw-r--r--hudson-core/src/main/java/hudson/search/SearchIndexBuilder.java36
-rw-r--r--hudson-core/src/main/java/hudson/search/SearchItem.java31
-rw-r--r--hudson-core/src/main/java/hudson/search/SearchItems.java11
-rw-r--r--hudson-core/src/main/java/hudson/search/SearchableModelObject.java18
-rw-r--r--hudson-core/src/main/java/hudson/search/SuggestedItem.java42
-rw-r--r--hudson-core/src/main/java/hudson/search/UnionSearchIndex.java27
-rw-r--r--hudson-core/src/main/java/hudson/search/package.html6
13 files changed, 253 insertions, 199 deletions
diff --git a/hudson-core/src/main/java/hudson/search/CollectionSearchIndex.java b/hudson-core/src/main/java/hudson/search/CollectionSearchIndex.java
index 0b031c5..d08474f 100644
--- a/hudson-core/src/main/java/hudson/search/CollectionSearchIndex.java
+++ b/hudson-core/src/main/java/hudson/search/CollectionSearchIndex.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -22,33 +22,37 @@ import java.util.Map;
/**
* {@link SearchIndex} built on a {@link Map}.
- *
+ *
* @author Kohsuke Kawaguchi
*/
public abstract class CollectionSearchIndex<SMT extends SearchableModelObject> implements SearchIndex {
+
/**
* Gets a single item that exactly matches the given key.
*/
protected abstract SearchItem get(String key);
/**
- * Returns all items in the map.
- * The collection can include null items.
+ * Returns all items in the map. The collection can include null items.
*/
protected abstract Collection<SMT> all();
public void find(String token, List<SearchItem> result) {
SearchItem p = get(token);
- if(p!=null)
+ if (p != null) {
result.add(p);
+ }
}
public void suggest(String token, List<SearchItem> result) {
Collection<SMT> items = all();
- if(items==null) return;
+ if (items == null) {
+ return;
+ }
for (SMT o : items) {
- if(o!=null && getName(o).contains(token))
+ if (o != null && getName(o).contains(token)) {
result.add(o);
+ }
}
}
diff --git a/hudson-core/src/main/java/hudson/search/FixedSet.java b/hudson-core/src/main/java/hudson/search/FixedSet.java
index 874f67d..2dd088a 100644
--- a/hudson-core/src/main/java/hudson/search/FixedSet.java
+++ b/hudson-core/src/main/java/hudson/search/FixedSet.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -26,6 +26,7 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
public class FixedSet implements SearchIndex {
+
private final Collection<? extends SearchItem> items;
public FixedSet(Collection<? extends SearchItem> items) {
@@ -37,14 +38,18 @@ public class FixedSet implements SearchIndex {
}
public void find(String token, List<SearchItem> result) {
- for (SearchItem i : items)
- if(token.equals(i.getSearchName()))
+ for (SearchItem i : items) {
+ if (token.equals(i.getSearchName())) {
result.add(i);
+ }
+ }
}
public void suggest(String token, List<SearchItem> result) {
- for (SearchItem i : items)
- if(i.getSearchName().contains(token))
+ for (SearchItem i : items) {
+ if (i.getSearchName().contains(token)) {
result.add(i);
+ }
+ }
}
}
diff --git a/hudson-core/src/main/java/hudson/search/ParsedQuickSilver.java b/hudson-core/src/main/java/hudson/search/ParsedQuickSilver.java
index f422585..a680d2c 100644
--- a/hudson-core/src/main/java/hudson/search/ParsedQuickSilver.java
+++ b/hudson-core/src/main/java/hudson/search/ParsedQuickSilver.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -26,21 +26,22 @@ import java.util.HashMap;
import java.beans.Introspector;
/**
- * Parsed {@link QuickSilver}s so that {@link SearchIndex} can be easily created.
- * One instance per one class.
+ * Parsed {@link QuickSilver}s so that {@link SearchIndex} can be easily
+ * created. One instance per one class.
*
* @author Kohsuke Kawaguchi
*/
final class ParsedQuickSilver {
- private static final Map<Class,ParsedQuickSilver> TABLE = new HashMap<Class,ParsedQuickSilver>();
+
+ private static final Map<Class, ParsedQuickSilver> TABLE = new HashMap<Class, ParsedQuickSilver>();
synchronized static ParsedQuickSilver get(Class<? extends SearchableModelObject> clazz) {
ParsedQuickSilver pqs = TABLE.get(clazz);
- if(pqs==null)
- TABLE.put(clazz,pqs = new ParsedQuickSilver(clazz));
+ if (pqs == null) {
+ TABLE.put(clazz, pqs = new ParsedQuickSilver(clazz));
+ }
return pqs;
}
-
private final List<Getter> getters = new ArrayList<Getter>();
private ParsedQuickSilver(Class<? extends SearchableModelObject> clazz) {
@@ -48,24 +49,26 @@ final class ParsedQuickSilver {
for (Method m : clazz.getMethods()) {
qs = m.getAnnotation(QuickSilver.class);
- if(qs!=null) {
+ if (qs != null) {
String url = stripGetPrefix(m);
- if(qs.value().length==0)
- getters.add(new MethodGetter(url,splitName(url),m));
- else {
- for (String name : qs.value())
- getters.add(new MethodGetter(url,name,m));
+ if (qs.value().length == 0) {
+ getters.add(new MethodGetter(url, splitName(url), m));
+ } else {
+ for (String name : qs.value()) {
+ getters.add(new MethodGetter(url, name, m));
+ }
}
}
}
for (Field f : clazz.getFields()) {
qs = f.getAnnotation(QuickSilver.class);
- if(qs!=null) {
- if(qs.value().length==0)
- getters.add(new FieldGetter(f.getName(),splitName(f.getName()),f));
- else {
- for (String name : qs.value())
- getters.add(new FieldGetter(f.getName(),name,f));
+ if (qs != null) {
+ if (qs.value().length == 0) {
+ getters.add(new FieldGetter(f.getName(), splitName(f.getName()), f));
+ } else {
+ for (String name : qs.value()) {
+ getters.add(new FieldGetter(f.getName(), name, f));
+ }
}
}
}
@@ -75,9 +78,11 @@ final class ParsedQuickSilver {
* Convert names like "abcDefGhi" to "abc def ghi".
*/
private String splitName(String url) {
- StringBuilder buf = new StringBuilder(url.length()+5);
- for(String token : url.split("(?<=[a-z])(?=[A-Z])")) {
- if(buf.length()>0) buf.append(' ');
+ StringBuilder buf = new StringBuilder(url.length() + 5);
+ for (String token : url.split("(?<=[a-z])(?=[A-Z])")) {
+ if (buf.length() > 0) {
+ buf.append(' ');
+ }
buf.append(Introspector.decapitalize(token));
}
return buf.toString();
@@ -85,13 +90,14 @@ final class ParsedQuickSilver {
private String stripGetPrefix(Method m) {
String n = m.getName();
- if(n.startsWith("get"))
+ if (n.startsWith("get")) {
n = Introspector.decapitalize(n.substring(3));
+ }
return n;
}
-
static abstract class Getter {
+
final String url;
final String searchName;
@@ -104,6 +110,7 @@ final class ParsedQuickSilver {
}
static final class MethodGetter extends Getter {
+
private final Method method;
public MethodGetter(String url, String searchName, Method method) {
@@ -118,16 +125,19 @@ final class ParsedQuickSilver {
throw toError(e);
} catch (InvocationTargetException e) {
Throwable x = e.getTargetException();
- if (x instanceof Error)
+ if (x instanceof Error) {
throw (Error) x;
- if (x instanceof RuntimeException)
+ }
+ if (x instanceof RuntimeException) {
throw (RuntimeException) x;
+ }
throw new Error(e);
}
}
}
static final class FieldGetter extends Getter {
+
private final Field field;
public FieldGetter(String url, String searchName, Field field) {
@@ -151,7 +161,7 @@ final class ParsedQuickSilver {
}
public void addTo(SearchIndexBuilder builder, final Object instance) {
- for (final Getter getter : getters)
+ for (final Getter getter : getters) {
builder.add(new SearchItem() {
public String getSearchName() {
return getter.searchName;
@@ -163,9 +173,12 @@ final class ParsedQuickSilver {
public SearchIndex getSearchIndex() {
Object child = getter.get(instance);
- if(child==null) return SearchIndex.EMPTY;
+ if (child == null) {
+ return SearchIndex.EMPTY;
+ }
return ((SearchableModelObject) child).getSearchIndex();
}
});
+ }
}
}
diff --git a/hudson-core/src/main/java/hudson/search/QuickSilver.java b/hudson-core/src/main/java/hudson/search/QuickSilver.java
index e584208..4aaa680 100644
--- a/hudson-core/src/main/java/hudson/search/QuickSilver.java
+++ b/hudson-core/src/main/java/hudson/search/QuickSilver.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -25,22 +25,20 @@ import java.lang.annotation.Target;
/**
* Indicates a {@link SearchItem} field/getter.
*
- * <p>
- * Fields/getters annotated with this annotation must:
- * <ul>
- * <li>be on the class that extends from {@link SearchableModelObject}.
- * <li>have the return type / field type of {@link SearchableModelObject} (or its subtype.)
- * </ul>
+ * <p> Fields/getters annotated with this annotation must: <ul> <li>be on the
+ * class that extends from {@link SearchableModelObject}. <li>have the return
+ * type / field type of {@link SearchableModelObject} (or its subtype.) </ul>
*
- * <p>
- * Such getter/field indicates an edge in the search graph, and will be added
- * automatically by {@link SearchIndexBuilder#addAllAnnotations(SearchableModelObject)}
- * to a search index.
+ * <p> Such getter/field indicates an edge in the search graph, and will be
+ * added automatically by
+ * {@link SearchIndexBuilder#addAllAnnotations(SearchableModelObject)} to a
+ * search index.
*
* @author Kohsuke Kawaguchi
*/
@Retention(RUNTIME)
@Target({METHOD, FIELD})
public @interface QuickSilver {
+
String[] value() default {};
}
diff --git a/hudson-core/src/main/java/hudson/search/Search.java b/hudson-core/src/main/java/hudson/search/Search.java
index f1d87f3..f4fac21 100644
--- a/hudson-core/src/main/java/hudson/search/Search.java
+++ b/hudson-core/src/main/java/hudson/search/Search.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -43,20 +43,21 @@ import java.util.Set;
* @author Kohsuke Kawaguchi
*/
public class Search {
+
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
List<Ancestor> l = req.getAncestors();
- for( int i=l.size()-1; i>=0; i-- ) {
+ for (int i = l.size() - 1; i >= 0; i--) {
Ancestor a = l.get(i);
if (a.getObject() instanceof SearchableModelObject) {
SearchableModelObject smo = (SearchableModelObject) a.getObject();
SearchIndex index = smo.getSearchIndex();
String query = req.getParameter("q");
- if(!StringUtils.isEmpty(query)) {
+ if (!StringUtils.isEmpty(query)) {
SuggestedItem target = find(index, query);
- if(target!=null) {
+ if (target != null) {
// found
- rsp.sendRedirect2(a.getUrl()+target.getUrl());
+ rsp.sendRedirect2(a.getUrl() + target.getUrl());
return;
}
}
@@ -65,7 +66,7 @@ public class Search {
// no exact match. show the suggestions
rsp.setStatus(SC_NOT_FOUND);
- req.getView(this,"search-failed.jelly").forward(req,rsp);
+ req.getView(this, "search-failed.jelly").forward(req, rsp);
}
/**
@@ -75,7 +76,8 @@ public class Search {
* ["queryString",["comp1","comp2",...]]
* </pre>
*
- * See http://developer.mozilla.org/en/docs/Supporting_search_suggestions_in_search_plugins
+ * See
+ * http://developer.mozilla.org/en/docs/Supporting_search_suggestions_in_search_plugins
*/
public void doSuggestOpenSearch(StaplerRequest req, StaplerResponse rsp, @QueryParameter String q) throws IOException, ServletException {
DataWriter w = Flavor.JSON.createDataWriter(null, rsp);
@@ -83,8 +85,9 @@ public class Search {
w.value(q);
w.startArray();
- for (SuggestedItem item : getSuggestions(req, q))
+ for (SuggestedItem item : getSuggestions(req, q)) {
w.value(item.getPath());
+ }
w.endArray();
w.endArray();
}
@@ -94,26 +97,29 @@ public class Search {
*/
public void doSuggest(StaplerRequest req, StaplerResponse rsp, @QueryParameter String query) throws IOException, ServletException {
Result r = new Result();
- for (SuggestedItem item : getSuggestions(req, query))
+ for (SuggestedItem item : getSuggestions(req, query)) {
r.suggestions.add(new Item(item.getPath()));
+ }
- rsp.serveExposedBean(req,r,Flavor.JSON);
+ rsp.serveExposedBean(req, r, Flavor.JSON);
}
/**
* Gets the list of suggestions that match the given query.
*
- * @return
- * can be empty but never null. The size of the list is always smaller than
- * a certain threshold to avoid showing too many options.
+ * @return can be empty but never null. The size of the list is always
+ * smaller than a certain threshold to avoid showing too many options.
*/
public List<SuggestedItem> getSuggestions(StaplerRequest req, String query) {
Set<String> paths = new HashSet<String>(); // paths already added, to control duplicates
List<SuggestedItem> r = new ArrayList<SuggestedItem>();
for (SuggestedItem i : suggest(makeSuggestIndex(req), query)) {
- if(r.size()>20) break;
- if(paths.add(i.getPath()))
+ if (r.size() > 20) {
+ break;
+ }
+ if (paths.add(i.getPath())) {
r.add(i);
+ }
}
return r;
}
@@ -135,6 +141,7 @@ public class Search {
@ExportedBean
public static class Result {
//TODO: review and check whether we can do it private
+
@Exported
public List<Item> suggestions = new ArrayList<Item>();
@@ -143,8 +150,9 @@ public class Search {
}
}
- @ExportedBean(defaultVisibility=999)
+ @ExportedBean(defaultVisibility = 999)
public static class Item {
+
@Exported
public String name;
@@ -154,6 +162,7 @@ public class Search {
}
private enum Mode {
+
FIND {
void find(SearchIndex index, String token, List<SearchItem> result) {
index.find(token, result);
@@ -166,7 +175,6 @@ public class Search {
};
abstract void find(SearchIndex index, String token, List<SearchItem> result);
-
}
/**
@@ -174,28 +182,37 @@ public class Search {
*/
public static SuggestedItem find(SearchIndex index, String query) {
List<SuggestedItem> r = find(Mode.FIND, index, query);
- if(r.isEmpty()) return null;
- else return r.get(0);
+ if (r.isEmpty()) {
+ return null;
+ } else {
+ return r.get(0);
+ }
}
public static List<SuggestedItem> suggest(SearchIndex index, final String tokenList) {
- class Tag implements Comparable<Tag>{
+ class Tag implements Comparable<Tag> {
+
final SuggestedItem item;
final int distance;
- /** If the path to this suggestion starts with the token list, 1. Otherwise 0. */
+ /**
+ * If the path to this suggestion starts with the token list, 1.
+ * Otherwise 0.
+ */
final int prefixMatch;
Tag(SuggestedItem i) {
item = i;
- distance = EditDistance.editDistance(i.getPath(),tokenList);
- prefixMatch = i.getPath().startsWith(tokenList)?1:0;
+ distance = EditDistance.editDistance(i.getPath(), tokenList);
+ prefixMatch = i.getPath().startsWith(tokenList) ? 1 : 0;
}
public int compareTo(Tag that) {
- int r = this.prefixMatch -that.prefixMatch;
- if(r!=0) return -r; // ones with head match should show up earlier
- return this.distance-that.distance;
+ int r = this.prefixMatch - that.prefixMatch;
+ if (r != 0) {
+ return -r; // ones with head match should show up earlier
+ }
+ return this.distance - that.distance;
}
}
@@ -203,41 +220,46 @@ public class Search {
List<SuggestedItem> items = find(Mode.SUGGEST, index, tokenList);
// sort them
- for( SuggestedItem i : items)
+ for (SuggestedItem i : items) {
buf.add(new Tag(i));
+ }
Collections.sort(buf);
items.clear();
- for (Tag t : buf)
+ for (Tag t : buf) {
items.add(t.item);
+ }
return items;
}
static final class TokenList {
+
private final String[] tokens;
public TokenList(String tokenList) {
tokens = tokenList.split("(?<=\\s)(?=\\S)");
}
- public int length() { return tokens.length; }
+ public int length() {
+ return tokens.length;
+ }
/**
- * Returns {@link List} such that its <tt>get(end)</tt>
- * returns the concatanation of [token_start,...,token_end]
- * (both end inclusive.)
+ * Returns {@link List} such that its <tt>get(end)</tt> returns the
+ * concatanation of [token_start,...,token_end] (both end inclusive.)
*/
public List<String> subSequence(final int start) {
return new AbstractList<String>() {
public String get(int index) {
StringBuilder buf = new StringBuilder();
- for(int i=start; i<=start+index; i++ )
+ for (int i = start; i <= start + index; i++) {
buf.append(tokens[i]);
+ }
return buf.toString().trim();
}
public int size() {
- return tokens.length-start;
+ return tokens.length - start;
}
};
}
@@ -245,36 +267,40 @@ public class Search {
private static List<SuggestedItem> find(Mode m, SearchIndex index, String tokenList) {
TokenList tokens = new TokenList(tokenList);
- if(tokens.length()==0) return Collections.emptyList(); // no tokens given
-
- List<SuggestedItem>[] paths = new List[tokens.length()+1]; // we won't use [0].
- for(int i=1;i<=tokens.length();i++)
+ if (tokens.length() == 0) {
+ return Collections.emptyList(); // no tokens given
+ }
+ List<SuggestedItem>[] paths = new List[tokens.length() + 1]; // we won't use [0].
+ for (int i = 1; i <= tokens.length(); i++) {
paths[i] = new ArrayList<SuggestedItem>();
+ }
List<SearchItem> items = new ArrayList<SearchItem>(); // items found in 1 step
// first token
- int w=1; // width of token
+ int w = 1; // width of token
for (String token : tokens.subSequence(0)) {
items.clear();
- m.find(index,token,items);
- for (SearchItem si : items)
+ m.find(index, token, items);
+ for (SearchItem si : items) {
paths[w].add(new SuggestedItem(si));
+ }
w++;
}
// successive tokens
- for (int j=1; j<tokens.length(); j++) {
+ for (int j = 1; j < tokens.length(); j++) {
// for each length
- w=1;
+ w = 1;
for (String token : tokens.subSequence(j)) {
// for each candidate
for (SuggestedItem r : paths[j]) {
items.clear();
- m.find(r.item.getSearchIndex(),token,items);
- for (SearchItem i : items)
- paths[j+w].add(new SuggestedItem(r,i));
+ m.find(r.item.getSearchIndex(), token, items);
+ for (SearchItem i : items) {
+ paths[j + w].add(new SuggestedItem(r, i));
+ }
}
w++;
}
diff --git a/hudson-core/src/main/java/hudson/search/SearchIndex.java b/hudson-core/src/main/java/hudson/search/SearchIndex.java
index 9e7339a..8568e48 100644
--- a/hudson-core/src/main/java/hudson/search/SearchIndex.java
+++ b/hudson-core/src/main/java/hudson/search/SearchIndex.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -22,6 +22,7 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
public interface SearchIndex {
+
void find(String token, List<SearchItem> result);
/**
@@ -29,7 +30,6 @@ public interface SearchIndex {
* This method returns the superset of {@link #find(String, List)}.
*/
void suggest(String token, List<SearchItem> result);
-
/**
* Empty set.
*/
@@ -37,6 +37,7 @@ public interface SearchIndex {
public void find(String token, List<SearchItem> result) {
// no item to contribute
}
+
public void suggest(String token, List<SearchItem> result) {
// nothing to suggest
}
diff --git a/hudson-core/src/main/java/hudson/search/SearchIndexBuilder.java b/hudson-core/src/main/java/hudson/search/SearchIndexBuilder.java
index d5d6d33..f9fbade 100644
--- a/hudson-core/src/main/java/hudson/search/SearchIndexBuilder.java
+++ b/hudson-core/src/main/java/hudson/search/SearchIndexBuilder.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -23,15 +23,15 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
public final class SearchIndexBuilder {
- private final List<SearchItem> items = new ArrayList<SearchItem>();
+ private final List<SearchItem> items = new ArrayList<SearchItem>();
private final List<SearchIndex> indices = new ArrayList<SearchIndex>();
/**
* Adds all {@link QuickSilver}-annotated properties to the search index.
*/
public SearchIndexBuilder addAllAnnotations(SearchableModelObject o) {
- ParsedQuickSilver.get(o.getClass()).addTo(this,o);
+ ParsedQuickSilver.get(o.getClass()).addTo(this, o);
return this;
}
@@ -39,23 +39,23 @@ public final class SearchIndexBuilder {
* Short for {@code add(urlAsWellAsName,urlAsWellAsName)}
*/
public SearchIndexBuilder add(String urlAsWellAsName) {
- return add(urlAsWellAsName,urlAsWellAsName);
+ return add(urlAsWellAsName, urlAsWellAsName);
}
/**
* Adds a search index under the keyword 'name' to the given URL.
*
- * @param url
- * Relative URL from the source of the search index.
+ * @param url Relative URL from the source of the search index.
*/
public SearchIndexBuilder add(String url, String name) {
- items.add(SearchItems.create(name,url));
+ items.add(SearchItems.create(name, url));
return this;
}
public SearchIndexBuilder add(String url, String... names) {
- for (String name : names)
- add(url,name);
+ for (String name : names) {
+ add(url, name);
+ }
return this;
}
@@ -65,13 +65,14 @@ public final class SearchIndexBuilder {
}
public SearchIndexBuilder add(String url, SearchableModelObject searchable, String name) {
- items.add(SearchItems.create(name,url,searchable));
+ items.add(SearchItems.create(name, url, searchable));
return this;
}
public SearchIndexBuilder add(String url, SearchableModelObject searchable, String... names) {
- for (String name : names)
- add(url,searchable,name);
+ for (String name : names) {
+ add(url, searchable, name);
+ }
return this;
}
@@ -86,8 +87,9 @@ public final class SearchIndexBuilder {
public SearchIndex make() {
SearchIndex r = new FixedSet(items);
- for (SearchIndex index : indices)
- r = new UnionSearchIndex(r,index);
+ for (SearchIndex index : indices) {
+ r = new UnionSearchIndex(r, index);
+ }
return r;
}
}
diff --git a/hudson-core/src/main/java/hudson/search/SearchItem.java b/hudson-core/src/main/java/hudson/search/SearchItem.java
index c4b66bc..88b7990 100644
--- a/hudson-core/src/main/java/hudson/search/SearchItem.java
+++ b/hudson-core/src/main/java/hudson/search/SearchItem.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -21,35 +21,34 @@ import hudson.model.Build;
/**
* Represents an item reachable from {@link SearchIndex}.
*
- * <p>
- * The act of searching in this package is really a traversal of a directed graph.
- * And in that notion, this interface represents an edge, not a node.
- * So it's possible for single entity (let's say {@link Build}) to
- * have multiple {@link SearchItem}s representing it (for example,
- * a 'last successful build' search item and '#123' search item.)
+ * <p> The act of searching in this package is really a traversal of a directed
+ * graph. And in that notion, this interface represents an edge, not a node. So
+ * it's possible for single entity (let's say {@link Build}) to have multiple
+ * {@link SearchItem}s representing it (for example, a 'last successful build'
+ * search item and '#123' search item.)
*
* @author Kohsuke Kawaguchi
*/
public interface SearchItem {
+
/**
* Name of this item. This is matched against the query.
*/
String getSearchName();
+
/**
* Returns the URL of this item relative to the parent {@link SearchItem}.
*
- * @return
- * URL like "foo" or "foo/bar". The path can end with '/'.
- * The path that starts with '/' will be interpreted as the absolute path
- * (within the context path of Hudson.)
+ * @return URL like "foo" or "foo/bar". The path can end with '/'. The path
+ * that starts with '/' will be interpreted as the absolute path (within the
+ * context path of Hudson.)
*/
String getSearchUrl();
/**
* Returns the {@link SearchIndex} to further search into this item.
*
- * @return
- * {@link SearchIndex#EMPTY} if this is a leaf.
+ * @return {@link SearchIndex#EMPTY} if this is a leaf.
*/
SearchIndex getSearchIndex();
}
diff --git a/hudson-core/src/main/java/hudson/search/SearchItems.java b/hudson-core/src/main/java/hudson/search/SearchItems.java
index 1dd97d9..f3d614d 100644
--- a/hudson-core/src/main/java/hudson/search/SearchItems.java
+++ b/hudson-core/src/main/java/hudson/search/SearchItems.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -20,8 +20,9 @@ package hudson.search;
* @author Kohsuke Kawaguchi
*/
public class SearchItems {
+
public static SearchItem create(String searchName, String url) {
- return create(searchName,url, SearchIndex.EMPTY);
+ return create(searchName, url, SearchIndex.EMPTY);
}
public static SearchItem create(final String searchName, final String url, final SearchIndex children) {
diff --git a/hudson-core/src/main/java/hudson/search/SearchableModelObject.java b/hudson-core/src/main/java/hudson/search/SearchableModelObject.java
index 301a842..3b87b86 100644
--- a/hudson-core/src/main/java/hudson/search/SearchableModelObject.java
+++ b/hudson-core/src/main/java/hudson/search/SearchableModelObject.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
-* Kohsuke Kawaguchi
- *
+ * Contributors:
+ *
+ * Kohsuke Kawaguchi
+ *
*
*******************************************************************************/
@@ -21,15 +21,15 @@ import hudson.model.ModelObject;
/**
* {@link ModelObject} that can be searched.
*
- * <p>
- * This interface also extends {@link SearchItem} since
- * often {@link ModelObject}s form a natural tree structure,
- * and it's convenient for the model objects themselves to implement
- * the {@link SearchItem} for the edges that form this tree.
+ * <p> This interface also extends {@link SearchItem} since often
+ * {@link ModelObject}s form a natural tree structure, and it's convenient for
+ * the model objects themselves to implement the {@link SearchItem} for the
+ * edges that form this tree.
*
* @author Kohsuke Kawaguchi
*/
public interface SearchableModelObject extends ModelObject, SearchItem {
+
/**
* This binds {@link Search} object to the URL hierarchy.
*/
diff --git a/hudson-core/src/main/java/hudson/search/SuggestedItem.java b/hudson-core/src/main/java/hudson/search/SuggestedItem.java
index 0c84c07..2c6c6cd 100644
--- a/hudson-core/src/main/java/hudson/search/SuggestedItem.java
+++ b/hudson-core/src/main/java/hudson/search/SuggestedItem.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
+ * Contributors:
+ *
* Kohsuke Kawaguchi
- *
+ *
*
*******************************************************************************/
@@ -22,13 +22,14 @@ package hudson.search;
* @author Kohsuke Kawaguchi
*/
public class SuggestedItem {
+
private final SuggestedItem parent;
//TODO: review and check whether we can do it private
public final SearchItem item;
private String path;
public SuggestedItem(SearchItem top) {
- this(null,top);
+ this(null, top);
}
public SuggestedItem(SuggestedItem parent, SearchItem item) {
@@ -41,20 +42,22 @@ public class SuggestedItem {
}
public String getPath() {
- if(path!=null) return path;
- if(parent==null)
- return path=item.getSearchName();
- else {
+ if (path != null) {
+ return path;
+ }
+ if (parent == null) {
+ return path = item.getSearchName();
+ } else {
StringBuilder buf = new StringBuilder();
getPath(buf);
- return path=buf.toString();
+ return path = buf.toString();
}
}
private void getPath(StringBuilder buf) {
- if(parent==null)
+ if (parent == null) {
buf.append(item.getSearchName());
- else {
+ } else {
parent.getPath(buf);
buf.append(' ').append(item.getSearchName());
}
@@ -62,11 +65,11 @@ public class SuggestedItem {
/**
* Gets the URL to this item.
- * @return
- * URL that starts with '/' but doesn't end with '/'.
- * The path is the combined path from the {@link SearchIndex} where the search started
- * to the final item found. Thus to convert to the actual URL, the caller would need
- * to prepend the URL of the object where the search started.
+ *
+ * @return URL that starts with '/' but doesn't end with '/'. The path is
+ * the combined path from the {@link SearchIndex} where the search started
+ * to the final item found. Thus to convert to the actual URL, the caller
+ * would need to prepend the URL of the object where the search started.
*/
public String getUrl() {
StringBuilder buf = new StringBuilder();
@@ -75,16 +78,17 @@ public class SuggestedItem {
}
private void getUrl(StringBuilder buf) {
- if(parent!=null) {
+ if (parent != null) {
parent.getUrl(buf);
}
String f = item.getSearchUrl();
- if(f.startsWith("/")) {
+ if (f.startsWith("/")) {
buf.setLength(0);
buf.append(f);
} else {
- if(buf.length()==0 || buf.charAt(buf.length()-1)!='/')
+ if (buf.length() == 0 || buf.charAt(buf.length() - 1) != '/') {
buf.append('/');
+ }
buf.append(f);
}
}
diff --git a/hudson-core/src/main/java/hudson/search/UnionSearchIndex.java b/hudson-core/src/main/java/hudson/search/UnionSearchIndex.java
index c8f3820..ec8af65 100644
--- a/hudson-core/src/main/java/hudson/search/UnionSearchIndex.java
+++ b/hudson-core/src/main/java/hudson/search/UnionSearchIndex.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
-*
+ * Contributors:
+ *
* Kohsuke Kawaguchi
- *
+ *
*
*******************************************************************************/
@@ -24,22 +24,23 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
public class UnionSearchIndex implements SearchIndex {
+
public static SearchIndex combine(SearchIndex... sets) {
- SearchIndex p=EMPTY;
+ SearchIndex p = EMPTY;
for (SearchIndex q : sets) {
// allow some of the inputs to be null,
// and also recognize EMPTY
if (q != null && q != EMPTY) {
- if (p == EMPTY)
+ if (p == EMPTY) {
p = q;
- else
- p = new UnionSearchIndex(p,q);
+ } else {
+ p = new UnionSearchIndex(p, q);
+ }
}
}
return p;
}
-
- private final SearchIndex lhs,rhs;
+ private final SearchIndex lhs, rhs;
public UnionSearchIndex(SearchIndex lhs, SearchIndex rhs) {
this.lhs = lhs;
@@ -47,12 +48,12 @@ public class UnionSearchIndex implements SearchIndex {
}
public void find(String token, List<SearchItem> result) {
- lhs.find(token,result);
- rhs.find(token,result);
+ lhs.find(token, result);
+ rhs.find(token, result);
}
public void suggest(String token, List<SearchItem> result) {
- lhs.suggest(token,result);
- rhs.suggest(token,result);
+ lhs.suggest(token, result);
+ rhs.suggest(token, result);
}
}
diff --git a/hudson-core/src/main/java/hudson/search/package.html b/hudson-core/src/main/java/hudson/search/package.html
index 6d6f30b..a5b341c 100644
--- a/hudson-core/src/main/java/hudson/search/package.html
+++ b/hudson-core/src/main/java/hudson/search/package.html
@@ -16,6 +16,6 @@
-->
<html><head/><body>
-<a href="http://docs.blacktree.com/quicksilver/what_is_quicksilver">QuickSilver</a>-like
-search/jump capability for better navigation around the website.
-</body></html> \ No newline at end of file
+ <a href="http://docs.blacktree.com/quicksilver/what_is_quicksilver">QuickSilver</a>-like
+ search/jump capability for better navigation around the website.
+ </body></html> \ No newline at end of file