View Javadoc
1   package org.eclipse.aether.internal.impl.collect.df;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  
24  import org.eclipse.aether.graph.DependencyNode;
25  
26  /**
27   * Internal helper for {@link DfDependencyCollector}. Originally (pre-1.8.0) this same class was located a
28   * package higher.
29   *
30   * @since 1.8.0
31   */
32  final class NodeStack
33  {
34  
35      @SuppressWarnings( {"checkstyle:magicnumber" } )
36      // CHECKSTYLE_OFF: MagicNumber
37      ArrayList<DependencyNode> nodes = new ArrayList<>( 96 );
38      // CHECKSTYLE_ON: MagicNumber
39  
40      public DependencyNode top()
41      {
42          if ( nodes.isEmpty() )
43          {
44              throw new IllegalStateException( "stack empty" );
45          }
46          return nodes.get( nodes.size() - 1 );
47      }
48  
49      public void push( DependencyNode node )
50      {
51          nodes.add( node );
52      }
53  
54      public void pop()
55      {
56          if ( nodes.isEmpty() )
57          {
58              throw new IllegalStateException( "stack empty" );
59          }
60          nodes.remove( nodes.size() - 1 );
61      }
62  
63      public int size()
64      {
65          return nodes.size();
66      }
67  
68      public DependencyNode get( int index )
69      {
70          return nodes.get( index );
71      }
72  
73      @Override
74      public String toString()
75      {
76          return nodes.toString();
77      }
78  
79  }