📄 itemcontainer.java
字号:
/* * Copyright 2006 Marcel Schoffelmeer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.s10r.manager.model;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import com.s10r.util.Observable;import com.s10r.util.ObservableList;import com.s10r.util.Observer;/** * Container class that acts as a container for all ManagerItems: labels * and password entries. * In addition to holding the list of items, it also provides convenience * methods for lookup. * * @author mms * */public class ItemContainer implements Observable{ ObservableList<ManagerItem> items = new ObservableList<ManagerItem>(); public List<ItemLabel> getLabels() { List<ItemLabel> labels = new ArrayList<ItemLabel>(); for (Iterator<ManagerItem> it = items.getItemIterator(); it.hasNext(); ) { ManagerItem item = it.next(); if (item instanceof ItemLabel) { labels.add((ItemLabel)item); } } return labels; } public ItemLabel getLabel(String name) { for (ItemLabel label: getLabels()) { if (label.getName().equalsIgnoreCase(name)) { return label; } } return null; } public PasswordEntry getPasswordEntry(String name) { for (PasswordEntry entry: getPasswordEntries()) { if (entry.getName().equalsIgnoreCase(name)) { return entry; } } return null; } public boolean contains(ItemLabel importLabel) { return items.contains(importLabel); } public boolean containsLabel(String name) { return getLabel(name) != null; } public boolean containsPasswordEntry(String name) { return getPasswordEntry(name) != null; } public List<PasswordEntry> getPasswordEntries() { List<PasswordEntry> entries = new ArrayList<PasswordEntry>(); for (Iterator<ManagerItem> it = items.getItemIterator(); it.hasNext(); ) { ManagerItem item = it.next(); if (item instanceof PasswordEntry) { entries.add((PasswordEntry)item); } } return entries; } public void add(ManagerItem item) { items.add(item); } public void addAll(List<ManagerItem> addItems) { items.addAll(addItems); } public void addAll(ItemContainer addTtems) { addAll(addTtems.getItems()); } public void remove(ManagerItem item) { items.remove(item); } /** * Removes the given label from the container. Any label references * in the password entries will be removed. * * @param label the ItemLabel to remove from the container */ public void remove(ItemLabel label) { for (PasswordEntry entry: getPasswordEntries() ) { if (entry.hasLabel(label)) { entry.removeLabel(label); } } items.remove(label); } public void clear() { items.clear(); } public void addObserver(Observer observer) { items.addObserver(observer); } public void clearObservers() { items.clearObservers(); } public void removeObserver(Observer observer) { items.removeObserver(observer); } public Object[] toArray() { return items.toArray(); } public List<ManagerItem> getItems() { return items.getItems(); } public int size() { return items.size(); } public boolean labelInUse(ItemLabel label) { for (PasswordEntry entry: getPasswordEntries()) { if (entry.hasLabel(label)) { return true; } } return false; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("ItemContainer(items = " + items); sb.append(")"); return sb.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -