44 */
55package org .hibernate .internal .util .collections ;
66
7- import java .lang .reflect .Array ;
87import java .util .Arrays ;
98import java .util .NoSuchElementException ;
109import java .util .function .BiFunction ;
2120 * @author Marco Belladelli
2221 */
2322public final class StandardStack <T > implements Stack <T > {
24- private T [] elements ;
23+ private Object [] elements ;
2524 private int top = 0 ;
2625
27- private Class <T > type ;
26+ public StandardStack () {
27+ }
28+
29+ public StandardStack (T initialValue ) {
30+ push ( initialValue );
31+ }
2832
33+ /**
34+ * @deprecated use the default constructor instead
35+ */
36+ @ Deprecated (forRemoval = true )
2937 public StandardStack (Class <T > type ) {
30- this .type = type ;
3138 }
3239
40+ /**
41+ * @deprecated use {@link #StandardStack(Object)} instead.
42+ */
43+ @ Deprecated (forRemoval = true )
3344 public StandardStack (Class <T > type , T initial ) {
34- this ( type );
3545 push ( initial );
3646 }
3747
3848 @ SuppressWarnings ("unchecked" )
3949 private void init () {
40- elements = (T []) Array .newInstance ( type , 8 );
41- type = null ;
50+ elements = (T []) new Object [8 ];
4251 }
4352
4453 @ Override
@@ -57,7 +66,7 @@ public T pop() {
5766 if ( isEmpty () ) {
5867 throw new NoSuchElementException ();
5968 }
60- T e = elements [--top ];
69+ T e = ( T ) elements [--top ];
6170 elements [top ] = null ;
6271 return e ;
6372 }
@@ -67,23 +76,23 @@ public T getCurrent() {
6776 if ( isEmpty () ) {
6877 return null ;
6978 }
70- return elements [top - 1 ];
79+ return ( T ) elements [top - 1 ];
7180 }
7281
7382 @ Override
7483 public T peek (int offsetFromTop ) {
7584 if ( isEmpty () ) {
7685 return null ;
7786 }
78- return elements [top - offsetFromTop - 1 ];
87+ return ( T ) elements [top - offsetFromTop - 1 ];
7988 }
8089
8190 @ Override
8291 public T getRoot () {
8392 if ( isEmpty () ) {
8493 return null ;
8594 }
86- return elements [0 ];
95+ return ( T ) elements [0 ];
8796 }
8897
8998 @ Override
@@ -107,14 +116,14 @@ public void clear() {
107116 @ Override
108117 public void visitRootFirst (Consumer <T > action ) {
109118 for ( int i = 0 ; i < top ; i ++ ) {
110- action .accept ( elements [i ] );
119+ action .accept ( ( T ) elements [i ] );
111120 }
112121 }
113122
114123 @ Override
115124 public <X > X findCurrentFirst (Function <T , X > function ) {
116125 for ( int i = top - 1 ; i >= 0 ; i -- ) {
117- final X result = function .apply ( elements [i ] );
126+ final X result = function .apply ( ( T ) elements [i ] );
118127 if ( result != null ) {
119128 return result ;
120129 }
@@ -125,7 +134,7 @@ public <X> X findCurrentFirst(Function<T, X> function) {
125134 @ Override
126135 public <X , Y > X findCurrentFirstWithParameter (Y parameter , BiFunction <T , Y , X > biFunction ) {
127136 for ( int i = top - 1 ; i >= 0 ; i -- ) {
128- final X result = biFunction .apply ( elements [i ], parameter );
137+ final X result = biFunction .apply ( ( T ) elements [i ], parameter );
129138 if ( result != null ) {
130139 return result ;
131140 }
@@ -138,4 +147,5 @@ private void grow() {
138147 final int jump = ( oldCapacity < 64 ) ? ( oldCapacity + 2 ) : ( oldCapacity >> 1 );
139148 elements = Arrays .copyOf ( elements , oldCapacity + jump );
140149 }
150+
141151}
0 commit comments