1 19 20 package edu.umd.cs.findbugs; 21 22 import java.io.IOException ; 23 import java.io.Serializable ; 24 25 import edu.umd.cs.findbugs.annotations.NonNull; 26 import edu.umd.cs.findbugs.annotations.CheckForNull; 27 import edu.umd.cs.findbugs.xml.XMLAttributeList; 28 import edu.umd.cs.findbugs.xml.XMLWriteable; 29 import edu.umd.cs.findbugs.xml.XMLOutput; 30 31 34 public class BugDesignation implements XMLWriteable, Serializable { 35 36 38 public static final String UNCLASSIFIED = "UNCLASSIFIED"; 39 40 41 43 @NonNull private String designation = UNCLASSIFIED; 44 45 private String user; 47 48 private long timestamp; 49 50 51 private String annotationText; 53 54 60 @NonNull public String getDesignationKey() { 61 return designation; 62 } 63 64 74 public void setDesignationKey(String designationKey) { 75 designation = (designationKey!=null ? designationKey : UNCLASSIFIED); 76 } 77 78 79 @CheckForNull public String getUser() { 80 return user; 81 } 82 public void setUser(String u) { 83 user = u; 84 } 85 86 public long getTimestamp() { 87 return timestamp; 88 } 89 public void setTimestamp(long ts) { 90 timestamp = ts; 91 } 92 93 @CheckForNull public String getAnnotationText() { 94 return annotationText; 95 } 96 public void setAnnotationText(String s) { 97 annotationText = s; 98 } 99 100 public void writeXML(XMLOutput xmlOutput) throws IOException { 101 XMLAttributeList attributeList = new XMLAttributeList(); 102 if (designation != null && !UNCLASSIFIED.equals(designation)) 104 attributeList.addAttribute("designation", designation); 105 if (user != null && !"".equals(user)) 106 attributeList.addAttribute("user", user); 107 if (timestamp > 0) 108 attributeList.addAttribute("timestamp", String.valueOf(timestamp)); 109 110 if ((annotationText != null && !"".equals(annotationText))) { 111 xmlOutput.openTag("UserAnnotation", attributeList); 112 xmlOutput.writeCDATA(annotationText); 113 xmlOutput.closeTag("UserAnnotation"); 114 } else { 115 xmlOutput.openCloseTag("UserAnnotation", attributeList); 116 } 117 } 118 119 120 public void merge(@CheckForNull BugDesignation other) { 121 if (other == null) return; 122 boolean changed = false; 123 if ( (annotationText==null || annotationText.length()==0) 124 && other.annotationText!=null && other.annotationText.length()>0) { 125 annotationText = other.annotationText; 126 changed = true; 127 } 128 if ( (designation==null || UNCLASSIFIED.equals(designation) || designation.length()==0) 129 && other.designation!=null && other.designation.length()>0) { 130 designation = other.designation; 131 changed = true; 132 } 133 if (!changed) return; 135 if ( (user==null || user.length()==0) && other.user!=null && other.user.length()>0) { 136 user = other.user; 137 } 138 if (timestamp==0 && other.timestamp!=0) { 139 timestamp = other.timestamp; 140 } 141 } 142 143 } 144 | Popular Tags |