📄 basiccontrolledvocabulary.java
字号:
// compare cventries, ignoring the order in the list boolean entriesEqual = true; CVEntry entry; CVEntry[] otherEntries = other.getEntries();loop: for (int i = 0; i < entries.size(); i++) { entry = (CVEntry) entries.get(i); for (int j = 0; j < otherEntries.length; j++) { if (entry.equals(otherEntries[j])) { continue loop; } } // if we get here the cv entries are unequal entriesEqual = false; break; } return entriesEqual; } /** * return arbitrary fix number since class is mutable * @return hashCode */ public int hashCode() { return 1; } /** * This is a checked way to change the value of an existing CVEntry.<br> * This method (silently) does nothing when the specified entry is not in * this ControlledVocabulary, or when the value already exists in this * CV. * * @param entry the CVEntry * @param value the new value for the entry */ public void modifyEntryValue(CVEntry entry, String value) { if ((entry == null) || (value == null)) { return; } if (!entries.contains(entry)) { return; } if (containsValue(value)) { return; } // the entry is in the list and the new value is not, // replace the oldEntry with a new one CVEntry newEntry = new CVEntry(value, entry.getDescription()); int index = entries.indexOf(entry); entries.set(index, newEntry); if (!initMode) { handleModified(); } } /** * Moves a set of entries up or down in the list of entries of the Vocabulary. * * @param entryArray the entries to move * @param moveType the type of move action, one of MOVE_TO_TOP, MOVE_UP, * MOVE_DOWN or MOVE_TO_BOTTOM */ public void moveEntries(CVEntry[] entryArray, int moveType) { switch (moveType) { case MOVE_TO_TOP: moveToTop(entryArray); break; case MOVE_UP: moveUp(entryArray); break; case MOVE_DOWN: moveDown(entryArray); break; case MOVE_TO_BOTTOM: moveToBottom(entryArray); break; default: break; } } /** * Removes a set of entries from the Vocabulary. * * @param entryArray the entries to remove * @return true if action was completed successfully */ public boolean removeEntries(CVEntry[] entryArray) { if (entryArray == null) { return false; } boolean removed = false; for (int i = 0; i < entryArray.length; i++) { boolean b = entries.remove(entryArray[i]); if (b) { removed = true; } } if (removed) { if (!initMode) { handleModified(); } } return removed; } /** * Removes an entry from the Vocabulary. * * @param entry the entry to remove * @return true if action was completed successfully */ public boolean removeEntry(CVEntry entry) { boolean b = entries.remove(entry); if (b && !initMode) { handleModified(); } return b; } /** * Removes the CVEntry with the specified value from the CV, if present. * * @param value the value to remove * */ public void removeValue(String value) { if (value == null) { return; } CVEntry en; boolean removed = false; for (int i = 0; i < entries.size(); i++) { en = (CVEntry) entries.get(i); if (en.getValue().equals(value)) { //ignore case ?? removed = entries.remove(en); break; } } if (removed) { if (!initMode) { handleModified(); } } } /** * Removes all existing CVEntries and adds the specified new entries. * * @param newEntries the new entries for the CV */ public void replaceAll(CVEntry[] newEntries) { if (newEntries == null) { return; } entries.clear(); addAll(newEntries); if (!initMode) { handleModified(); } } /** * replace an entry with another * @param oldEntry the entry to be replaced * @param newEntry replacement * @return true if action was completed successfully */ public boolean replaceEntry(CVEntry oldEntry, CVEntry newEntry) { if ((oldEntry == null) || (newEntry == null)) { return false; } int index = entries.indexOf(oldEntry); if (index == -1) { return false; } entries.remove(oldEntry); entries.add(index, newEntry); if (!initMode) { handleModified(); } return true; } /** * Override Object's toString method to return the name of the CV. * * @return the name of the CV */ public String toString() { return name; } /** * Sends a general notification to an interested Object, that this CV has been changed.<br> * This method does not specify the kind of modification. */ protected void handleModified() { } /** * Moves the CVEntries in the array to the top of the list.<br> * It is assumed that the entries come in ascending order! * * @param entryArray the array of CVEntry objects */ protected void moveToTop(CVEntry[] entryArray) { if ((entryArray == null) || (entryArray.length == 0)) { return; } CVEntry entry = null; boolean moved = false; for (int i = 0; i < entryArray.length; i++) { entry = entryArray[i]; boolean removed = entries.remove(entry); if (removed) { moved = true; entries.add(i, entry); } } if (moved) { if (!initMode) { handleModified(); } } } /** * Moves the CVEntries in the array down one position in the list.<br> * It is assumed that the entries come in ascending order! * * @param entryArray the array of CVEntry objects */ private void moveDown(CVEntry[] entryArray) { if ((entryArray == null) || (entryArray.length == 0)) { return; } CVEntry entry = null; boolean moved = false; int curIndex; for (int i = entryArray.length - 1; i >= 0; i--) { entry = entryArray[i]; curIndex = entries.indexOf(entry); if ((curIndex >= 0) && (curIndex < (entries.size() - 1))) { boolean removed = entries.remove(entry); if (removed) { moved = true; entries.add(curIndex + 1, entry); } } } if (moved) { if (!initMode) { handleModified(); } } } /** * Moves the CVEntries in the array to the bottom of the list.<br> * It is assumed that the entries come in ascending order! * * @param entryArray the array of CVEntry objects */ private void moveToBottom(CVEntry[] entryArray) { if ((entryArray == null) || (entryArray.length == 0)) { return; } CVEntry entry = null; boolean moved = false; for (int i = 0; i < entryArray.length; i++) { entry = entryArray[i]; boolean removed = entries.remove(entry); if (removed) { moved = true; entries.add(entry); } } if (moved) { if (!initMode) { handleModified(); } } } /** * Moves the CVEntries in the array up one position in the list.<br> * It is assumed that the entries come in ascending order! * * @param entryArray the array of CVEntry objects */ private void moveUp(CVEntry[] entryArray) { if ((entryArray == null) || (entryArray.length == 0)) { return; } CVEntry entry = null; boolean moved = false; int curIndex; for (int i = 0; i < entryArray.length; i++) { entry = entryArray[i]; curIndex = entries.indexOf(entry); if (curIndex > 0) { boolean removed = entries.remove(entry); if (removed) { moved = true; entries.add(curIndex - 1, entry); } } } if (moved) { if (!initMode) { handleModified(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -