提交 b1331076 编写于 作者: K kohsuke

added subset toString() for improved rendering


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3538 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1bfae6b5
......@@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Collection;
/**
* A particular combination of {@link Axis} values.
......@@ -33,6 +34,37 @@ public final class Combination extends TreeMap<String,String> implements Compara
super.put(e.getKey(),e.getValue());
}
public int compareTo(Combination that) {
int d = this.size()-that.size();
if(d!=0) return d;
Iterator<Map.Entry<String,String>> itr = this.entrySet().iterator();
Iterator<Map.Entry<String,String>> jtr = that.entrySet().iterator();
while(itr.hasNext()) {
Map.Entry<String,String> i = itr.next();
Map.Entry<String,String> j = jtr.next();
d = i.getKey().compareTo(j.getKey());
if(d!=0) return d;
d = i.getValue().compareTo(j.getValue());
if(d!=0) return d;
}
return 0;
}
/**
* Works like {@link #toString()} but only include the given axes.
*/
public String toString(Collection<Axis> subset) {
StringBuilder buf = new StringBuilder();
for (Axis a : subset) {
if(buf.length()>0) buf.append(',');
buf.append(a.name).append('=').append(get(a.name));
}
if(buf.length()==0) buf.append("default"); // special case to avoid 0-length name.
return buf.toString();
}
/**
* Converts to the ID string representation:
* <tt>axisName=value,axisName=value,...</tt>
......@@ -82,22 +114,4 @@ public final class Combination extends TreeMap<String,String> implements Compara
public String remove(Object key) {
throw new UnsupportedOperationException();
}
public int compareTo(Combination that) {
int d = this.size()-that.size();
if(d!=0) return d;
Iterator<Map.Entry<String,String>> itr = this.entrySet().iterator();
Iterator<Map.Entry<String,String>> jtr = that.entrySet().iterator();
while(itr.hasNext()) {
Map.Entry<String,String> i = itr.next();
Map.Entry<String,String> j = jtr.next();
d = i.getKey().compareTo(j.getKey());
if(d!=0) return d;
d = i.getValue().compareTo(j.getValue());
if(d!=0) return d;
}
return 0;
}
}
......@@ -27,7 +27,7 @@
<local:itemLink item="${c}" /> <!-- zero dimension -->
</j:when>
<j:otherwise>
<local:itemLink item="${c}" title="${c.name}"/> <!-- one dimension. use that value -->
<local:itemLink item="${c}" title="${c.combination.toString(o.z)}"/> <!-- one dimension. use the value of the Z-axis -->
</j:otherwise>
</j:choose>
</li>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册