📄 genericentity.java
字号:
19 = left quotation mark 20 = right quotation mark 22 = – 23 = - 25 = tm * */ switch (curChar) { case '\'': value.replace(i, i+1, "'"); break; case '"': value.replace(i, i+1, """); break; case '&': value.replace(i, i+1, "&"); break; case '<': value.replace(i, i+1, "<"); break; case '>': value.replace(i, i+1, ">"); break; case 0xA: // newline, \n needsCdata = true; break; case 0xD: // carriage return, \r needsCdata = true; break; case 0x9: // tab // do nothing, just catch here so it doesn't get into the default break; case 0x5: // elipses (...) value.replace(i, i+1, "..."); break; case 0x12: // apostrophe value.replace(i, i+1, "'"); break; case 0x13: // left quote value.replace(i, i+1, """); break; case 0x14: // right quote value.replace(i, i+1, """); break; case 0x16: // big(?) dash - value.replace(i, i+1, "-"); break; case 0x17: // dash - value.replace(i, i+1, "-"); break; case 0x19: // tm value.replace(i, i+1, "tm"); break; default: if (curChar < 0x20) { // if it is less that 0x20 at this point it is invalid because the only valid values < 0x20 are 0x9, 0xA, 0xD as caught above Debug.logInfo("Removing invalid character [" + curChar + "] numeric value [" + (int) curChar + "] for field " + name + " of entity with PK: " + this.getPrimaryKey().toString(), module); value.deleteCharAt(i); } } } if (needsCdata) { // use valueStr instead of the escaped value, not needed or wanted in a CDATA block cdataMap.put(name, valueStr); } else { writer.print(' '); writer.print(name); writer.print("=\""); // encode the value... writer.print(value.toString()); writer.print("\""); } } } } if (cdataMap.size() == 0) { writer.println("/>"); } else { writer.println('>'); Iterator cdataIter = cdataMap.entrySet().iterator(); while (cdataIter.hasNext()) { Map.Entry entry = (Map.Entry) cdataIter.next(); for (int i = 0; i < (indent << 1); i++) writer.print(' '); writer.print('<'); writer.print((String) entry.getKey()); writer.print("><![CDATA["); writer.print((String) entry.getValue()); writer.print("]]></"); writer.print((String) entry.getKey()); writer.println('>'); } // don't forget to close the entity. for (int i = 0; i < indent; i++) writer.print(' '); writer.print("</"); writer.print(this.getEntityName()); writer.println(">"); } } /** Determines the equality of two GenericEntity objects, overrides the default equals *@param obj The object (GenericEntity) to compare this two *@return boolean stating if the two objects are equal */ public boolean equals(Object obj) { if (obj == null) return false; // from here, use the compareTo method since it is more efficient: try { return this.compareTo(obj) == 0; } catch (ClassCastException e) { return false; } } /** Creates a hashCode for the entity, using the default String hashCode and Map hashCode, overrides the default hashCode *@return Hashcode corresponding to this entity */ public int hashCode() { // divide both by two (shift to right one bit) to maintain scale and add together if (generateHashCode) { cachedHashCode = 0; if (getEntityName() != null) { cachedHashCode += getEntityName().hashCode() >> 1; } cachedHashCode += fields.hashCode() >> 1; generateHashCode = false; } return cachedHashCode; } /** Creates a String for the entity, overrides the default toString *@return String corresponding to this entity */ public String toString() { StringBuffer theString = new StringBuffer(); theString.append("[GenericEntity:"); theString.append(getEntityName()); theString.append(']'); Iterator keyNames = new TreeSet(fields.keySet()).iterator(); while (keyNames.hasNext()) { String curKey = (String) keyNames.next(); Object curValue = fields.get(curKey); theString.append('['); theString.append(curKey); theString.append(','); theString.append(curValue); theString.append('('); theString.append(curValue != null ? curValue.getClass().getName() : ""); theString.append(')'); theString.append(']'); } return theString.toString(); } /** Compares this GenericEntity to the passed object *@param obj Object to compare this to *@return int representing the result of the comparison (-1,0, or 1) */ public int compareTo(Object obj) { // if null, it will push to the beginning if (obj == null) return -1; // rather than doing an if instanceof, just cast it and let it throw an exception if // it fails, this will be faster for the expected case (that it IS a GenericEntity) // if not a GenericEntity throw ClassCastException, as the spec says GenericEntity that = (GenericEntity) obj; int tempResult = this.entityName.compareTo(that.entityName); // if they did not match, we know the order, otherwise compare the primary keys if (tempResult != 0) return tempResult; // both have same entityName, should be the same so let's compare PKs Iterator pkIter = getModelEntity().getPksIterator(); while (pkIter.hasNext()) { ModelField curField = (ModelField) pkIter.next(); Comparable thisVal = (Comparable) this.fields.get(curField.getName()); Comparable thatVal = (Comparable) that.fields.get(curField.getName()); if (thisVal == null) { if (thatVal == null) tempResult = 0; // if thisVal is null, but thatVal is not, return 1 to put this earlier in the list else tempResult = 1; } else { // if thatVal is null, put the other earlier in the list if (thatVal == null) tempResult = -1; else tempResult = thisVal.compareTo(thatVal); } if (tempResult != 0) return tempResult; } // okay, if we got here it means the primaryKeys are exactly the SAME, so compare the rest of the fields Iterator nopkIter = getModelEntity().getNopksIterator(); while (nopkIter.hasNext()) { ModelField curField = (ModelField) nopkIter.next(); if (!curField.getIsAutoCreatedInternal()) { Comparable thisVal = (Comparable) this.fields.get(curField.getName()); Comparable thatVal = (Comparable) that.fields.get(curField.getName()); if (thisVal == null) { if (thatVal == null) { tempResult = 0; // if thisVal is null, but thatVal is not, return 1 to put this earlier in the list } else { tempResult = 1; } } else { // if thatVal is null, put the other earlier in the list if (thatVal == null) { tempResult = -1; } else { tempResult = thisVal.compareTo(thatVal); } } if (tempResult != 0) return tempResult; } } // if we got here it means the two are exactly the same, so return tempResult, which should be 0 return tempResult; } /** Clones this GenericEntity, this is a shallow clone & uses the default shallow HashMap clone *@return Object that is a clone of this GenericEntity */ public Object clone() { GenericEntity newEntity = new GenericEntity(); newEntity.init(this); newEntity.setDelegator(internalDelegator); return newEntity; } // ---- Methods added to implement the Map interface: ---- public Object remove(Object key) { return this.fields.remove(key); } public boolean containsKey(Object key) { return this.fields.containsKey(key); } public java.util.Set entrySet() { return Collections.unmodifiableSet(this.fields.entrySet()); } public Object put(Object key, Object value) { return this.set((String) key, value, true); } public void putAll(java.util.Map map) { this.setFields(map); } public void clear() { this.fields.clear(); } public Object get(Object key) { try { return this.get((String) key); } catch (IllegalArgumentException e) { Debug.logWarning(e, "The field name (or key) [" + key + "] is not valid, printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module); return null; } } public java.util.Set keySet() { return Collections.unmodifiableSet(this.fields.keySet()); } public boolean isEmpty() { return this.fields.isEmpty(); } public java.util.Collection values() { return Collections.unmodifiableCollection(this.fields.values()); } public boolean containsValue(Object value) { return this.fields.containsValue(value); } public int size() { return this.fields.size(); } public boolean matches(EntityCondition condition) { return condition.entityMatches(this); } public static interface NULL { } public static class NullGenericEntity extends GenericEntity implements NULL { protected NullGenericEntity() { } public String toString() { return "[null-entity]"; } } public static class NullField implements NULL { protected NullField() { } public String toString() { return "[null-field]"; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -