我在下面的代码中遇到了itemTree.stopEditing()的问题.
我可以很好地编辑设备.编辑将节点文本从IP地址更改为beIP地址+主机名(使字符串更长).问题是,编辑后,JTree显示IP后跟"..."
看起来Tree没有更新它的UI.我以为使用树的编辑功能会自动更新UI?我该怎么办?
this.setShowsRootHandles(true);
this.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
System.out.println("\n[MyItemTree]mousePressed");
MyItemTree itemTree = (MyItemTree) e.getSource();
TreePath tp = itemTree.getPathForLocation(e.getX(), e.getY());
Rectangle pathBounds = itemTree.getUI().getPathBounds(itemTree, tp);
TreePath[] selectionPaths = itemTree.getSelectionPaths();//what if this is empty?
Object lastPathComponent = tp.getLastPathComponent();// what if this is empty?
digOutNodesForSelection((DefaultMutableTreeNode) lastPathComponent, itemTree);
itemTree.setEditable(true);
ArrayList<DefaultMutableTreeNode> nodes = new ArrayList();
for (int i = 0; i < selectionPaths.length; i++) {
Object lastPathComponent1 = selectionPaths[i].getLastPathComponent();
//Should only be adding the Leaf Nodes here
if (lastPathComponent1 instanceof …Run Code Online (Sandbox Code Playgroud) 我有这个字符串.我试图从每个条目拉出接口,nameif和安全级别.
!
interface OUTSIDE
nameif OUTSIDE
security-level 0
ip address 47.237.34.219 255.255.255.248 standby 47.237.34.220
authentication key eigrp 20 ***** key-id 20
authentication mode eigrp 20 md5
!
interface QA
nameif QA
security-level 100
ip address 47.237.34.89 255.255.255.248 standby 47.237.34.90
authentication key eigrp 20 ***** key-id 20
authentication mode eigrp 20 md5
!
interface QASUSEENCEXT
nameif QASUSEENCEXT
security-level 93
ip address 47.77.146.1 255.255.254.0 standby 47.77.146.2
!
interface QASUSEENCSNSTV
nameif QASUSEENCSNSTV
security-level 80
ip address 47.77.140.1 255.255.254.0 standby 47.77.140.2
!
interface QAWINSECDB …Run Code Online (Sandbox Code Playgroud) 我的 HashSet 包含多个具有相同 HashCode 的“AccessRequest”。我只希望有一个实例。我不认为具有相同 HashCode 的项目可以出现在 HashSet 中。我在这里做错了什么?
更新:基于 HashSet 只保留一个不等于列表中另一个项目的假设,并且也许我的 equals/hash 方法需要简化,我已经更新了我的问题。我仍然收到多个在我的哈希集中评估为等于的项目。
以下是“AccessRequest”中的 HashCode 和 Equals 方法
更新:我更新了我的哈希值,等于只有我需要“等于”的必要字段
@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + Objects.hashCode(this.targets);
hash = 79 * hash + Objects.hashCode(this.sources);
hash = 79 * hash + Objects.hashCode(this.destinations);
hash = 79 * hash + Objects.hashCode(this.services);
hash = 79 * hash + Objects.hashCode(this.action);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true; …Run Code Online (Sandbox Code Playgroud)