2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.rosetta;
26 * A Ladder is a Stack like Storage Class, but where you can ascend and descend while
27 * the elements exists.
29 * Like an extension ladder, you can make taller as you go
34 public class Ladder<T> {
35 public static final int DEFAULT_INIT_SIZE=8;
36 private final int init_size;
37 private int rung; // as in ladder
38 private Object[] struts;
42 init_size = DEFAULT_INIT_SIZE;
43 struts=new Object[init_size];
46 public Ladder(int initSize) {
49 struts=new Object[init_size];
52 public void bottom() {
57 rung = struts.length-1;
58 while (rung>0 && struts[rung]==null)--rung;
61 public int howHigh() {
65 public void jumpTo(int rung) {
66 if (rung>=struts.length) {
67 Object[] temp = new Object[init_size*((rung/init_size)+1)];
68 System.arraycopy(struts, 0, temp, 0, struts.length);
78 public void cutTo(int rungs) {
79 Object[] temp = new Object[rungs];
80 System.arraycopy(struts, 0, temp, 0, Math.min(rungs, struts.length));
84 public void ascend() {
86 if (rung>=struts.length) {
87 Object[] temp = new Object[struts.length+init_size];
88 System.arraycopy(struts, 0, temp, 0, struts.length);
93 public void descend() {
97 @SuppressWarnings("unchecked")
99 return (T)struts[rung];
102 public void push(T t) {
106 @SuppressWarnings("unchecked")
108 T t = (T)struts[rung];