1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
49 /** inner peer, or null. */
50 private Object inner;
51 /** outer peer, or null. */
52 private Object outer;
53
54 public XmlNode element() {
55 return element;
56 }
57 public Object inner() {
58 return inner;
59 }
60 public Object outer() {
61 return outer;
62 }
63 }
64
65 private final Map<XmlNode,Entry<XmlNode>> byElement = new IdentityHashMap<XmlNode,Entry<XmlNode>>();
66 private final Map<Object,Entry<XmlNode>> byPeer = new IdentityHashMap<Object,Entry<XmlNode>>();
67 private final Set<XmlNode> usedNodes = new HashSet<XmlNode>();
68
69 /** Records the new element<->inner peer association. */
70 public void addInner( XmlNode element, Object inner ) {
71 Entry<XmlNode> e = byElement.get(element);
72 if(e!=null) {
73 if(e.inner!=null)
74 byPeer.remove(e.inner);
75 e.inner = inner;
76 } else {
77 e = new Entry<XmlNode>();
78 e.element = element;
79 e.inner = inner;
80 }
81
82 byElement.put(element,e);
83
84 Entry<XmlNode> old = byPeer.put(inner,e);
85 if(old!=null) {
86 if(old.outer!=null)
87 byPeer.remove(old.outer);
88 if(old.element!=null)
89 byElement.remove(old.element);
90 }
91 }
92
93 /** Records the new element<->outer peer association. */
94 public void addOuter( XmlNode element, Object outer ) {
95 Entry<XmlNode> e = byElement.get(element);
96 if(e!=null) {
97 if(e.outer!=null)
98 byPeer.remove(e.outer);
99 e.outer = outer;
100 } else {
101 e = new Entry<XmlNode>();
102 e.element = element;
103 e.outer = outer;
104 }
105
106 byElement.put(element,e);
107
108 Entry<XmlNode> old = byPeer.put(outer,e);
109 if(old!=null) {
110 old.outer=null;
111
112 if(old.inner==null)
113 // remove this entry
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
49 /** inner peer, or null. */
50 private Object inner;
51 /** outer peer, or null. */
52 private Object outer;
53
54 public XmlNode element() {
55 return element;
56 }
57 public Object inner() {
58 return inner;
59 }
60 public Object outer() {
61 return outer;
62 }
63 }
64
65 private final Map<XmlNode,Entry<XmlNode>> byElement = new IdentityHashMap<XmlNode,Entry<XmlNode>>();
66 private final Map<Object,Entry<XmlNode>> byPeer = new IdentityHashMap<Object,Entry<XmlNode>>();
67 private final Set<XmlNode> usedNodes = new HashSet<XmlNode>();
68
69 /** Records the new {@code element <->inner} peer association. */
70 public void addInner( XmlNode element, Object inner ) {
71 Entry<XmlNode> e = byElement.get(element);
72 if(e!=null) {
73 if(e.inner!=null)
74 byPeer.remove(e.inner);
75 e.inner = inner;
76 } else {
77 e = new Entry<XmlNode>();
78 e.element = element;
79 e.inner = inner;
80 }
81
82 byElement.put(element,e);
83
84 Entry<XmlNode> old = byPeer.put(inner,e);
85 if(old!=null) {
86 if(old.outer!=null)
87 byPeer.remove(old.outer);
88 if(old.element!=null)
89 byElement.remove(old.element);
90 }
91 }
92
93 /** Records the new {@code element <-> outer} peer association. */
94 public void addOuter( XmlNode element, Object outer ) {
95 Entry<XmlNode> e = byElement.get(element);
96 if(e!=null) {
97 if(e.outer!=null)
98 byPeer.remove(e.outer);
99 e.outer = outer;
100 } else {
101 e = new Entry<XmlNode>();
102 e.element = element;
103 e.outer = outer;
104 }
105
106 byElement.put(element,e);
107
108 Entry<XmlNode> old = byPeer.put(outer,e);
109 if(old!=null) {
110 old.outer=null;
111
112 if(old.inner==null)
113 // remove this entry
|