From b3f724f871dd57c4db958556df1a73f71c8bd6e5 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Thu, 24 Apr 2008 14:42:27 +0000 Subject: [PATCH] Remove use of ArrayStack and rename get(int) to peek(int) which is a better name IMHO. --- import-control.xml | 1 - .../com/puppycrawl/tools/checkstyle/Checker.java | 2 +- .../com/puppycrawl/tools/checkstyle/api/FastStack.java | 5 +++-- .../checkstyle/checks/coding/FinalLocalVariableCheck.java | 2 +- .../checkstyle/checks/indentation/IndentationCheck.java | 7 ++++--- .../com/puppycrawl/tools/checkstyle/api/FastStackTest.java | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/import-control.xml b/import-control.xml index 3810375a0..6fa9f25ad 100755 --- a/import-control.xml +++ b/import-control.xml @@ -38,7 +38,6 @@ - diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index fd523a833..659dd4a1d 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -396,7 +396,7 @@ public class Checker extends AutomaticBean // already contains one sb.append(File.separatorChar); } - sb.append(s.get(i)); + sb.append(s.peek(i)); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FastStack.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FastStack.java index b7880f219..74179276a 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FastStack.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FastStack.java @@ -87,12 +87,13 @@ public class FastStack implements Iterable } /** - * Return the element at the specified index. + * Return the element at the specified index. It does not remove the + * element from the stack. * @param aIndex the index to return * @return the element at the index * @throws IllegalArgumentException if index out of range */ - public E get(int aIndex) + public E peek(int aIndex) { if ((aIndex < 0) || (aIndex >= mEntries.size())) { throw new IllegalArgumentException("index out of range."); diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java index caa46cc4a..c6bb4013e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/coding/FinalLocalVariableCheck.java @@ -185,7 +185,7 @@ public class FinalLocalVariableCheck extends Check private void removeVariable(DetailAST aAST) { for (int i = mScopeStack.size() - 1; i >= 0; i--) { - final Map state = mScopeStack.get(i); + final Map state = mScopeStack.peek(i); final Object obj = state.remove(aAST.getText()); if (obj != null) { break; diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java index bf73d1d0e..88e4212a2 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheck.java @@ -20,9 +20,9 @@ package com.puppycrawl.tools.checkstyle.checks.indentation; import com.puppycrawl.tools.checkstyle.api.Check; import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FastStack; import com.puppycrawl.tools.checkstyle.api.ScopeUtils; import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import org.apache.commons.collections.ArrayStack; // TODO: allow preset indentation styles (IE... GNU style, Sun style, etc...)? @@ -122,7 +122,8 @@ public class IndentationCheck extends Check private int mBraceAdjustment; /** handlers currently in use */ - private final ArrayStack mHandlers = new ArrayStack(); + private final FastStack mHandlers = + FastStack.newInstance(); /** factory from which handlers are distributed */ private final HandlerFactory mHandlerFactory = new HandlerFactory(); @@ -241,7 +242,7 @@ public class IndentationCheck extends Check } final ExpressionHandler handler = mHandlerFactory.getHandler(this, aAST, - (ExpressionHandler) mHandlers.peek()); + mHandlers.peek()); mHandlers.push(handler); try { handler.checkIndentation(); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/api/FastStackTest.java b/src/tests/com/puppycrawl/tools/checkstyle/api/FastStackTest.java index bd791790c..a3e44039b 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/api/FastStackTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/api/FastStackTest.java @@ -35,7 +35,7 @@ public class FastStackTest } assertEquals(num, fs.size()); assertFalse(fs.isEmpty()); - assertEquals(1, fs.get(1).intValue()); + assertEquals(1, fs.peek(1).intValue()); assertEquals(num - 1, fs.peek().intValue()); assertEquals(num, fs.size()); for (int i = 0; i < num; i++)