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;
24 import java.util.Iterator;
26 import org.onap.aaf.misc.env.Env;
27 import org.onap.aaf.misc.env.TimeTaken;
29 public abstract class Marshal<T> implements Parse<T, Marshal.State> {
32 * @see org.onap.aaf.misc.rosetta.Parse#newParsed()
35 public Parsed<State> newParsed() throws ParseException {
36 return new Parsed<State>(new State());
40 public TimeTaken start(Env env) {
41 //TODO is a way to mark not-JSON?
42 return env.start("Rosetta Marshal", Env.JSON);
45 public static class State {
46 // Note: Need a STATEFUL stack... one that will remain stateful until marked as finished
47 // "finished" is know by Iterators with no more to do/null
48 // Thus the concept of "Ladder", which one ascends and decends
49 public Ladder<Iterator<?>> ladder = new Ladder<Iterator<?>>();
50 public boolean smallest = true;
53 public static final Iterator<Void> DONE_ITERATOR = new Iterator<Void>() {
55 public boolean hasNext() {
65 public void remove() {
70 * Typical definition of Done is when Iterator in Ladder is "DONE_ITERATOR"
72 * It is important, however, that the "Ladder Rung" is set to the right level.
77 public boolean amFinished(State state) {
78 return DONE_ITERATOR.equals(state.ladder.peek());