Polish: replace the synchronized class "Stack" by an unsynchronized one such as "Deque".

This commit is contained in:
igor-suhorukov
2018-02-11 13:26:20 +03:00
committed by Juergen Hoeller
parent 3cbb2b7616
commit 711b0f50f2
8 changed files with 47 additions and 39 deletions

View File

@@ -16,13 +16,13 @@
package org.springframework.beans.factory.parsing;
import java.util.Stack;
import java.util.LinkedList;
import org.springframework.lang.Nullable;
/**
* Simple {@link Stack}-based structure for tracking the logical position during
* a parsing process. {@link Entry entries} are added to the stack at
* Simple {@link LinkedList}-based structure for tracking the logical position during
* a parsing process. {@link Entry entries} are added to the LinkedList at
* each point during the parse phase in a reader-specific manner.
*
* <p>Calling {@link #toString()} will render a tree-style view of the current logical
@@ -40,49 +40,49 @@ public final class ParseState {
private static final char TAB = '\t';
/**
* Internal {@link Stack} storage.
* Internal {@link LinkedList} storage.
*/
private final Stack<Entry> state;
private final LinkedList<Entry> state;
/**
* Create a new {@code ParseState} with an empty {@link Stack}.
* Create a new {@code ParseState} with an empty {@link LinkedList}.
*/
public ParseState() {
this.state = new Stack<>();
this.state = new LinkedList<>();
}
/**
* Create a new {@code ParseState} whose {@link Stack} is a {@link Object#clone clone}
* Create a new {@code ParseState} whose {@link LinkedList} is a {@link Object#clone clone}
* of that of the passed in {@code ParseState}.
*/
@SuppressWarnings("unchecked")
private ParseState(ParseState other) {
this.state = (Stack<Entry>) other.state.clone();
this.state = (LinkedList<Entry>) other.state.clone();
}
/**
* Add a new {@link Entry} to the {@link Stack}.
* Add a new {@link Entry} to the {@link LinkedList}.
*/
public void push(Entry entry) {
this.state.push(entry);
}
/**
* Remove an {@link Entry} from the {@link Stack}.
* Remove an {@link Entry} from the {@link LinkedList}.
*/
public void pop() {
this.state.pop();
}
/**
* Return the {@link Entry} currently at the top of the {@link Stack} or
* {@code null} if the {@link Stack} is empty.
* Return the {@link Entry} currently at the top of the {@link LinkedList} or
* {@code null} if the {@link LinkedList} is empty.
*/
@Nullable
public Entry peek() {
return this.state.empty() ? null : this.state.peek();
return this.state.isEmpty() ? null : this.state.peek();
}
/**

View File

@@ -16,7 +16,8 @@
package org.springframework.beans.factory.xml;
import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
@@ -46,7 +47,7 @@ public final class ParserContext {
@Nullable
private BeanDefinition containingBeanDefinition;
private final Stack<ComponentDefinition> containingComponents = new Stack<>();
private final Deque<ComponentDefinition> containingComponents = new ArrayDeque<>();
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
@@ -96,7 +97,7 @@ public final class ParserContext {
@Nullable
public CompositeComponentDefinition getContainingComponent() {
return (!this.containingComponents.isEmpty() ?
(CompositeComponentDefinition) this.containingComponents.lastElement() : null);
(CompositeComponentDefinition) this.containingComponents.getLast() : null);
}
public void pushContainingComponent(CompositeComponentDefinition containingComponent) {