1 package org.apache.lucene.search; 2 3 18 19 import java.util.ArrayList ; 20 21 22 public class Explanation implements java.io.Serializable { 23 private float value; private String description; private ArrayList details; 27 public Explanation() {} 28 29 public Explanation(float value, String description) { 30 this.value = value; 31 this.description = description; 32 } 33 34 35 public float getValue() { return value; } 36 37 public void setValue(float value) { this.value = value; } 38 39 40 public String getDescription() { return description; } 41 42 public void setDescription(String description) { 43 this.description = description; 44 } 45 46 47 public Explanation[] getDetails() { 48 if (details == null) 49 return null; 50 return (Explanation[])details.toArray(new Explanation[0]); 51 } 52 53 54 public void addDetail(Explanation detail) { 55 if (details == null) 56 details = new ArrayList (); 57 details.add(detail); 58 } 59 60 61 public String toString() { 62 return toString(0); 63 } 64 private String toString(int depth) { 65 StringBuffer buffer = new StringBuffer (); 66 for (int i = 0; i < depth; i++) { 67 buffer.append(" "); 68 } 69 buffer.append(getValue()); 70 buffer.append(" = "); 71 buffer.append(getDescription()); 72 buffer.append("\n"); 73 74 Explanation[] details = getDetails(); 75 if (details != null) { 76 for (int i = 0 ; i < details.length; i++) { 77 buffer.append(details[i].toString(depth+1)); 78 } 79 } 80 81 return buffer.toString(); 82 } 83 84 85 86 public String toHtml() { 87 StringBuffer buffer = new StringBuffer (); 88 buffer.append("<ul>\n"); 89 90 buffer.append("<li>"); 91 buffer.append(getValue()); 92 buffer.append(" = "); 93 buffer.append(getDescription()); 94 buffer.append("</li>\n"); 95 96 Explanation[] details = getDetails(); 97 if (details != null) { 98 for (int i = 0 ; i < details.length; i++) { 99 buffer.append(details[i].toHtml()); 100 } 101 } 102 103 buffer.append("</ul>\n"); 104 105 return buffer.toString(); 106 } 107 } 108 | Popular Tags |