From 59a29dc8910076f6d94b834a37ee082b00b6daf2 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 7 Apr 2021 12:41:57 +0700 Subject: [PATCH] Avoid using obsolete collections GitOrigin-RevId: e861fa282c83952bf369e36652dd0e5b506c173b --- .../jdom/output/EclipseNamespaceStack.java | 156 +++++++++--------- .../maven/server/MavenEffectivePomDumper.java | 20 +-- .../maven/dom/MavenVersionComparable.java | 1 + .../intellij/uiDesigner/SelectionState.java | 2 +- .../com/intellij/uiDesigner/XmlWriter.java | 2 +- .../actions/ExpandSelectionAction.java | 3 +- .../actions/ShrinkSelectionAction.java | 3 +- 7 files changed, 94 insertions(+), 93 deletions(-) diff --git a/plugins/eclipse/src/org/jdom/output/EclipseNamespaceStack.java b/plugins/eclipse/src/org/jdom/output/EclipseNamespaceStack.java index b320ffd83106..65f03f655867 100644 --- a/plugins/eclipse/src/org/jdom/output/EclipseNamespaceStack.java +++ b/plugins/eclipse/src/org/jdom/output/EclipseNamespaceStack.java @@ -57,95 +57,97 @@ package org.jdom.output; import org.jdom.Namespace; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Iterator; /** * A non-public utility class used by both {@link XMLOutputter} and * {@link SAXOutputter} to manage namespaces in a JDOM Document * during output. * + * @author Elliotte Rusty Harolde + * @author Fred Trimble + * @author Brett McLaughlin * @version $Revision: 1.13 $, $Date: 2004/02/06 09:28:32 $ - * @author Elliotte Rusty Harolde - * @author Fred Trimble - * @author Brett McLaughlin */ public class EclipseNamespaceStack { + static class NamespaceInfo { + final String prefix; + final String uri; - /** The prefixes available */ - private final Stack prefixes; - - /** The URIs available */ - private final Stack uris; - - /** - * This creates the needed storage. - */ - EclipseNamespaceStack() { - prefixes = new Stack(); - uris = new Stack(); + NamespaceInfo(String prefix, String uri) { + this.prefix = prefix; + this.uri = uri; } - /** - * This will add a new {@link Namespace} - * to those currently available. - * - * @param ns Namespace to add. - */ - public void push(Namespace ns) { - prefixes.push(ns.getPrefix()); - uris.push(ns.getURI()); - } - - /** - * This will remove the topmost (most recently added) - * {@link Namespace}, and return its prefix. - * - * @return String - the popped namespace prefix. - */ - public String pop() { - String prefix = (String)prefixes.pop(); - uris.pop(); - - return prefix; - } - - /** - * This returns the number of available namespaces. - * - * @return int - size of the namespace stack. - */ - public int size() { - return prefixes.size(); - } - - /** - * Given a prefix, this will return the namespace URI most - * rencently (topmost) associated with that prefix. - * - * @param prefix String namespace prefix. - * @return String - the namespace URI for that prefix. - */ - public String getURI(String prefix) { - int index = prefixes.lastIndexOf(prefix); - if (index == -1) { - return null; - } - String uri = (String)uris.elementAt(index); - return uri; - } - - /** - * This will print out the size and current stack, from the - * most recently added {@link Namespace} to - * the "oldest," all to System.out. - */ + @Override public String toString() { - StringBuilder buf = new StringBuilder(); - String sep = System.lineSeparator(); - buf.append("Stack: ").append(prefixes.size()).append(sep); - for (int i = 0; i < prefixes.size(); i++) { - buf.append(prefixes.elementAt(i)).append('&').append(uris.elementAt(i)).append(sep); - } - return buf.toString(); + return prefix + "&" + uri; } + } + + private final Deque myNamespaces = new ArrayDeque<>(); + + /** + * This will add a new {@link Namespace} + * to those currently available. + * + * @param ns Namespace to add. + */ + public void push(Namespace ns) { + myNamespaces.push(new NamespaceInfo(ns.getPrefix(), ns.getURI())); + } + + /** + * This will remove the topmost (most recently added) + * {@link Namespace}, and return its prefix. + * + * @return String - the popped namespace prefix. + */ + public String pop() { + return myNamespaces.pop().prefix; + } + + /** + * This returns the number of available namespaces. + * + * @return int - size of the namespace stack. + */ + public int size() { + return myNamespaces.size(); + } + + /** + * Given a prefix, this will return the namespace URI most + * recently (topmost) associated with that prefix. + * + * @param prefix String namespace prefix. + * @return String - the namespace URI for that prefix. + */ + public String getURI(String prefix) { + Iterator iterator = myNamespaces.descendingIterator(); + while (iterator.hasNext()) { + NamespaceInfo ns = iterator.next(); + if (ns.prefix.equals(prefix)) { + return ns.uri; + } + } + return null; + } + + /** + * This will print out the size and current stack, from the + * most recently added {@link Namespace} to + * the "oldest," all to System.out. + */ + public String toString() { + StringBuilder buf = new StringBuilder(); + String sep = System.lineSeparator(); + buf.append("Stack: ").append(myNamespaces.size()).append(sep); + for (NamespaceInfo info : myNamespaces) { + buf.append(info).append(sep); + } + return buf.toString(); + } } diff --git a/plugins/maven/maven3-server-common/src/org/jetbrains/idea/maven/server/MavenEffectivePomDumper.java b/plugins/maven/maven3-server-common/src/org/jetbrains/idea/maven/server/MavenEffectivePomDumper.java index 221455596c5a..432a2db711d2 100644 --- a/plugins/maven/maven3-server-common/src/org/jetbrains/idea/maven/server/MavenEffectivePomDumper.java +++ b/plugins/maven/maven3-server-common/src/org/jetbrains/idea/maven/server/MavenEffectivePomDumper.java @@ -34,7 +34,7 @@ public final class MavenEffectivePomDumper { /** * The POM XSD URL */ - private static final String POM_XSD_URL = "http://maven.apache.org/maven-v4_0_0.xsd"; + private static final String POM_XSD_URL = "https://maven.apache.org/maven-v4_0_0.xsd"; /** * The Settings XSD URL @@ -123,7 +123,7 @@ public final class MavenEffectivePomDumper { /** * Copy/pasted from org.apache.maven.plugins.help.AbstractEffectiveMojo#writeHeader */ - protected static void writeHeader(XMLWriter writer) { + private static void writeHeader(XMLWriter writer) { XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, " "); // Use ISO8601-format for date and time @@ -138,7 +138,7 @@ public final class MavenEffectivePomDumper { /** * Copy/pasted from org.apache.maven.plugins.help.AbstractEffectiveMojo */ - protected static void writeComment(XMLWriter writer, String comment) { + private static void writeComment(XMLWriter writer, String comment) { XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, " "); XmlWriterUtil.writeComment(writer, comment); @@ -206,8 +206,8 @@ public final class MavenEffectivePomDumper { } ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace("")); - for (Iterator i = rootElement.getDescendants(elementFilter); i.hasNext(); ) { - Element e = (Element)i.next(); + for (Iterator i = rootElement.getDescendants(elementFilter); i.hasNext(); ) { + Element e = i.next(); e.setNamespace(pomNamespace); } @@ -242,12 +242,12 @@ public final class MavenEffectivePomDumper { * {@inheritDoc} */ @Override - public Set keySet() { - Set keynames = super.keySet(); - Vector list = new Vector(keynames); - Collections.sort(list); + public Set keySet() { + Set keys = super.keySet(); + List list = new ArrayList(keys); + Collections.sort(list, null); - return new LinkedHashSet(list); + return new LinkedHashSet(list); } } } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenVersionComparable.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenVersionComparable.java index c816cb83154d..ae36668a3d6f 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenVersionComparable.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenVersionComparable.java @@ -1,6 +1,7 @@ package org.jetbrains.idea.maven.dom; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.Stack; import java.math.BigInteger; import java.util.*; diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java index 3a18f8b48101..6f054f38706e 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/SelectionState.java @@ -6,10 +6,10 @@ import com.intellij.uiDesigner.componentTree.ComponentPtr; import com.intellij.uiDesigner.componentTree.ComponentSelectionListener; import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.radComponents.RadComponent; +import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Stack; /** * This class implements Ctrl+W / Ctrl+Shift+W functionality in the GuiEditor diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/XmlWriter.java b/plugins/ui-designer/src/com/intellij/uiDesigner/XmlWriter.java index dff4ab756a08..56ba12dac7a8 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/XmlWriter.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/XmlWriter.java @@ -20,13 +20,13 @@ import com.intellij.uiDesigner.lw.ColorDescriptor; import com.intellij.uiDesigner.lw.FontDescriptor; import com.intellij.uiDesigner.lw.StringDescriptor; import com.intellij.util.containers.BooleanStack; +import com.intellij.util.containers.Stack; import com.intellij.xml.util.XmlStringUtil; import org.jdom.Attribute; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import java.awt.*; -import java.util.Stack; /** * This is utility for serialization of component hierarchy. diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java index 03d157401926..c66b5b10c31b 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ExpandSelectionAction.java @@ -12,10 +12,9 @@ import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; import com.intellij.uiDesigner.radComponents.RadComponent; import com.intellij.uiDesigner.radComponents.RadContainer; +import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; -import java.util.Stack; - /** * For each component selects all non selected siblings (if any). If * all component's siblings are already selected then selects component's diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java index a2f26a913b06..0a13750e11d3 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/actions/ShrinkSelectionAction.java @@ -10,10 +10,9 @@ import com.intellij.uiDesigner.componentTree.ComponentPtr; import com.intellij.uiDesigner.componentTree.ComponentTreeBuilder; import com.intellij.uiDesigner.designSurface.GuiEditor; import com.intellij.uiDesigner.propertyInspector.DesignerToolWindowManager; +import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; -import java.util.Stack; - /** * @author Anton Katilin * @author Vladimir Kondratyev