1 23 package org.apache.slide.webdav.util; 24 25 27 34 public class ViolatedPrecondition { 35 36 41 public static final String PRECONDITION_MUST_NOT_BE_NULL = "Parameter 'precondition' must not be null"; 42 43 44 49 protected int statusCode = WebdavStatus.SC_FORBIDDEN; 50 51 54 protected String precondition = null; 55 protected String explanation = null; 56 57 60 protected String stringRepresentation = null; 61 62 63 64 82 public ViolatedPrecondition(String precondition, int statusCode) { 83 this(precondition, statusCode, null); 84 } 85 86 public ViolatedPrecondition(String precondition, int statusCode, String explanation) { 87 88 if (precondition == null) { 89 throw new IllegalArgumentException (PRECONDITION_MUST_NOT_BE_NULL); 90 } 91 92 this.precondition = precondition; 93 this.statusCode = statusCode; 94 this.explanation = explanation; 95 } 96 97 102 public String getPrecondition() { 103 return precondition; 104 } 105 106 111 public int getStatusCode() { 112 return statusCode; 113 } 114 115 public void setExplanation(String explanation) { 116 this.explanation = explanation; 117 } 118 119 public String getExplanation() { 120 return explanation; 121 } 122 123 132 public boolean equals(Object other) { 133 134 boolean isEqual = false; 135 if (other instanceof ViolatedPrecondition) { 136 ViolatedPrecondition otherViolatedPrecondition = (ViolatedPrecondition)other; 137 isEqual = getPrecondition().equals(otherViolatedPrecondition.getPrecondition()); 138 isEqual &= ( getStatusCode() == otherViolatedPrecondition.getStatusCode() ); 139 } 140 141 return isEqual; 142 } 143 144 150 public int hashCode() { 151 return 13*getPrecondition().hashCode() + getStatusCode(); 152 } 153 154 159 public String toString() { 160 161 if (stringRepresentation == null) { 162 StringBuffer buffer = new StringBuffer ("ViolatedPrecondition["); 163 buffer.append(getPrecondition()); 164 buffer.append(", "); 165 buffer.append(getStatusCode()); 166 buffer.append(" "); 167 buffer.append(WebdavStatus.getStatusText(getStatusCode())); 168 buffer.append("]"); 169 stringRepresentation = buffer.toString(); 170 } 171 return stringRepresentation; 172 } 173 } 174 175 | Popular Tags |