📄 association.java
字号:
if (action.getVerb() == null) { throw new IllegalArgumentException("the given action object has null verb field."); } else if (action.getCommand() == null) { throw new IllegalArgumentException("the given action object has null command field."); } if (actionList == null) { actionList = new ArrayList(); } return actionList.add(new Action(action.getVerb(), action.getCommand(), action.getDescription())); } /** * Removes a given action from the action list of this <code>Association</code>. * If the action is not contained in the action list, no changes are made to * the action list. * <P> * A valid action should not have null verb or command field. * * @param action a given action. * @return <code>true</code> if the given action is removed successfully * from the action list; <code>false</code> otherwise. */ public boolean removeAction(Action action) { if (action == null) { throw new IllegalArgumentException("The given action is null."); } // Check the specified action object has no null verb and command field. if ((action.getVerb() == null) || (action.getCommand() == null)) { throw new IllegalArgumentException("the given action object has null verb field or command field."); } if (actionList != null) { return actionList.remove(action); } return false; } /** * Returns the action list of this <code>Association</code>. * * @return the action list of the association. */ public List getActionList() { // Make defensive copy if (actionList == null) { return null; } else { List retList = new ArrayList(); Iterator iter = actionList.iterator(); while (iter.hasNext()) { retList.add(iter.next()); } return retList; } } /** * Returns the action, whose verb field is the same with the * specified verb. * * @param verb the specified verb. * @return the action with the specified verb; <code>null</code> if no * approprate action is found. */ public Action getActionByVerb(String verb) { Iterator iter; if (actionList != null) { iter = actionList.iterator(); if (iter != null) { while (iter.hasNext()) { Action temAction = (Action) iter.next(); String temVerb = temAction.getVerb(); if (temVerb.equalsIgnoreCase(verb)) { return temAction; } } } } return null; } /** * Overrides the same method of <code>java.lang.Object</code>. * <p> * Determines whether or not two associations are equal. Two instances * of <code>Association</code> are equal if the values of all the fields * are the same. * * @param other an object to be compared with this <code>Association</code>. * @return <code>true</code> if the object to be compared is an instance of * <code>Association</code> and has the same values; * <code>false</code> otherwise. */ public boolean equals(Object other) { if (!(other instanceof Association)) { return false; } Association otherAssoc = (Association) other; /* * Compares if the basic part of the association (description, iconfile, mimetype) * equals */ boolean isBasicEquals, isActionListEquals, isFileExtListEquals; String otherDesc = otherAssoc.getDescription(); String otherIconFileName = otherAssoc.getIconFileName(); String otherMimeType = otherAssoc.getMimeType(); isBasicEquals = ((description == null ? otherDesc == null : description.equals(otherDesc)) && (iconFileName == null ? otherIconFileName == null : iconFileName.equals(otherIconFileName)) && (mimeType == null ? otherMimeType == null : mimeType.equals(otherMimeType))); if (!isBasicEquals) { return false; } //Compare if the file extension list equals List otherFileExtList = otherAssoc.getFileExtList(); isFileExtListEquals = false; //fileExtlistEqulas when //1. both file extension lists are null //2. neither file extension lists is null and they have same elements if ((fileExtensionList == null) && (otherFileExtList == null)) { isFileExtListEquals = true; } else if ((fileExtensionList != null) && (otherFileExtList != null)) { if ((fileExtensionList.containsAll(otherFileExtList)) && (otherFileExtList.containsAll(fileExtensionList))) { isFileExtListEquals = true; } } if (!isFileExtListEquals) { return false; } //Compare if the action list equals List otherActionList = otherAssoc.getActionList(); isActionListEquals = false; //action list Equlas when //1. both action lists are null //2. neither action lists is null and they have same elements if ((actionList == null) && (otherActionList != null)) { isActionListEquals = true; } else if ((actionList != null) && (otherActionList != null)) { if ((actionList.containsAll(otherActionList)) && (otherActionList.containsAll(actionList))) { isActionListEquals = true; } } return isActionListEquals; } /** * Overrides the same method of <code>java.lang.Object</code>. * <p> * Returns the hashcode for this <code>Association</code>. * * @return a hash code for this <code>Association<code>. */ public int hashCode() { if (hashcode != 0) { int result = 17; if (this.name != null) { result = result * 37 + this.name.hashCode(); } if (this.description != null) { result = result * 37 + this.description.hashCode(); } if (this.mimeType != null) { result = result * 37 + this.mimeType.hashCode(); } if (this.iconFileName != null) { result = result * 37 + this.iconFileName.hashCode(); } if (this.fileExtensionList != null) { result = result * 37 + this.fileExtensionList.hashCode(); } if (this.actionList != null) { result = result * 37 + this.actionList.hashCode(); } hashcode = result; } return hashcode; } /** * Overrides the same method of <code>java.lang.Object</code>. * <p> * Returns a <code>String</code> that represents the value of this * <code>Association</code>. * * <PRE> * The output of this object as a string would be like: * MIME File Name: * Description: * MIME Type: * Icon File: * File Extension: * Action List: * Description: * Verb: * Command: * </PRE> * @return a string representation of this <code>Association</code>. */ public String toString() { String crlfString = "\r\n"; String content = ""; Iterator temIter; content = content.concat("MIME File Name: "); if (this.name != null) { content = content.concat(name); } content = content.concat(crlfString); content = content.concat("Description: "); if (this.description != null) { content = content.concat(description); } content = content.concat(crlfString); content = content.concat("MIME Type: "); if (this.mimeType != null) { content = content.concat(mimeType); } content = content.concat(crlfString); content = content.concat("Icon File: "); if (this.iconFileName != null) { content = content.concat(iconFileName); } content = content.concat(crlfString); content = content.concat("File Extension: "); if (fileExtensionList != null) { temIter = fileExtensionList.iterator(); if (temIter != null) { while (temIter.hasNext()) { content = content.concat((String) temIter.next()); if (temIter.hasNext()) { content = content.concat(" "); } } } } content = content.concat(crlfString); content = content.concat("Action List: "); if (actionList != null) { temIter = actionList.iterator(); if (temIter != null) { content = content.concat(crlfString); while (temIter.hasNext()) { Action temAction = (Action) temIter.next(); content = content.concat(temAction.toString()); } } } content = content.concat(crlfString); return content; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -