diff options
Diffstat (limited to 'misc/rosetta/src')
31 files changed, 285 insertions, 285 deletions
diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InJson.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InJson.java index 353261a0..582c750c 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InJson.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InJson.java @@ -32,7 +32,7 @@ public class InJson implements Parse<Reader, State> { public Parsed<State> parse(Reader r, Parsed<State> parsed) throws ParseException { // First things first, if there's a "leftover" event, process that immediately State state = (State)parsed.state; - if(state.unsent > 0) { + if (state.unsent > 0) { parsed.event = state.unsent; state.unsent = 0; return parsed; @@ -45,13 +45,13 @@ public class InJson implements Parse<Reader, State> { boolean go = true; try { // Gather data from Reader, looking for special characters when not in Quotes - while(go && (ch=r.read())>=0) { - if(state.braces>=0 || ch==Parse.START_OBJ) { // ignore garbage/whitespace before content + while (go && (ch=r.read())>=0) { + if (state.braces>=0 || ch==Parse.START_OBJ) { // ignore garbage/whitespace before content c=(char)ch; // Character is a quote. - if(c=='"') { - if(inQuotes) { - if(escaped) { // if escaped Quote, add to data. + if (c=='"') { + if (inQuotes) { + if (escaped) { // if escaped Quote, add to data. sb.append(c); escaped = false; } else { @@ -62,9 +62,9 @@ public class InJson implements Parse<Reader, State> { inQuotes = true; } } else { // Not a Quote - if(inQuotes) { - if(c=='\\') { - if(escaped) { + if (inQuotes) { + if (c=='\\') { + if (escaped) { sb.append("\\\\"); escaped = false; } else { @@ -80,7 +80,7 @@ public class InJson implements Parse<Reader, State> { parsed.isString = false; break; case Parse.START_OBJ: - if(state.braces++ == 0) { + if (state.braces++ == 0) { parsed.event = START_DOC; state.unsent = c; } else { @@ -89,7 +89,7 @@ public class InJson implements Parse<Reader, State> { go = false; break; case Parse.END_OBJ: - if(--state.braces == 0) { + if (--state.braces == 0) { parsed.event = c; state.unsent = END_DOC; } else { @@ -99,7 +99,7 @@ public class InJson implements Parse<Reader, State> { break; // These three end the data gathering, and send it along with the event that is ending the data gathering case Parse.NEXT: - if(parsed.name.startsWith("__")) { + if (parsed.name.startsWith("__")) { parsed.event = Parse.ATTRIB; parsed.name = parsed.name.substring(2); } else { diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InXML.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InXML.java index 91b7c57d..175a2aa2 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InXML.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/InXML.java @@ -51,13 +51,13 @@ public class InXML implements Parse<Reader, State> { State state = parsed.state; // OK, before anything else, see if there is leftover processing, if so, do it! - if(state.unevaluated!=null) { + if (state.unevaluated!=null) { DerTag dt = state.unevaluated; state.unevaluated = null; - if(!state.greatExp.eval(parsed, dt))return parsed; + if (!state.greatExp.eval(parsed, dt))return parsed; } - if(state.hasAttributes()) { + if (state.hasAttributes()) { Prop prop = state.pop(); parsed.event = Parse.ATTRIB; parsed.name = prop.tag; @@ -73,14 +73,14 @@ public class InXML implements Parse<Reader, State> { boolean go = true; try { - while(go && (ch=r.read())>=0) { + while (go && (ch=r.read())>=0) { c = (char)ch; - if(c == '"') { - if(state.greatExp instanceof LeafExpectations) { // within a set of Tags, make a Quote + if (c == '"') { + if (state.greatExp instanceof LeafExpectations) { // within a set of Tags, make a Quote sb.append(c); } else { - if(inQuotes) { - if(escaped) { + if (inQuotes) { + if (escaped) { sb.append('\\'); sb.append(c); escaped = false; @@ -92,11 +92,11 @@ public class InXML implements Parse<Reader, State> { inQuotes = true; } } - } else if(inQuotes) { + } else if (inQuotes) { sb.append(c); - } else if(c=='&') { + } else if (c=='&') { XmlEscape.xmlEscape(sb,r); - } else if(c=='\\') { + } else if (c=='\\') { escaped=true; } else { switch(c) { @@ -106,9 +106,9 @@ public class InXML implements Parse<Reader, State> { break; default: // don't add Whitespace to start of SB... saves removing later - if(sb.length()>0) { + if (sb.length()>0) { sb.append(c); - } else if(!Character.isWhitespace(c)) { + } else if (!Character.isWhitespace(c)) { sb.append(c); } } @@ -142,16 +142,16 @@ public class InXML implements Parse<Reader, State> { String tag = null; try { - if((ch = r.read())<0) throw new ParseException("Reader content ended before complete"); - if(ch=='?') { + if ((ch = r.read())<0) throw new ParseException("Reader content ended before complete"); + if (ch=='?') { isXmlInfo = true; } // TODO Check for !-- comments do { c=(char)ch; - if(c=='"') { - if(inQuotes) { - if(escaped) { + if (c=='"') { + if (inQuotes) { + if (escaped) { sb.append(c); escaped = false; } else { @@ -160,7 +160,7 @@ public class InXML implements Parse<Reader, State> { } else { inQuotes = true; } - } else if(inQuotes) { + } else if (inQuotes) { sb.append(c); } else { switch(c) { @@ -184,13 +184,13 @@ public class InXML implements Parse<Reader, State> { // sb.setLength(0); // break; case '?': - if(!isXmlInfo)sb.append(c); + if (!isXmlInfo)sb.append(c); break; default: sb.append(c); } } - } while(go && (ch=r.read())>=0); + } while (go && (ch=r.read())>=0); } catch (IOException e) { throw new ParseException(e); } @@ -198,14 +198,14 @@ public class InXML implements Parse<Reader, State> { } private void endField(String tag, StringBuilder sb) { - if(name==null) { + if (name==null) { name = sb.toString(); sb.setLength(0); } else { String value = sb.toString(); sb.setLength(0); - if(tag !=null && value != null) { - if(props==null)props = new ArrayList<>(); + if (tag !=null && value != null) { + if (props==null)props = new ArrayList<>(); props.add(new Prop(tag,value)); } } @@ -217,7 +217,7 @@ public class InXML implements Parse<Reader, State> { sb.append(" Tag\n"); sb.append(" Name: "); sb.append(name); - if(props!=null) for(Prop p : props) { + if (props!=null) for (Prop p : props) { sb.append("\n "); sb.append(p.tag); sb.append("=\""); @@ -250,7 +250,7 @@ public class InXML implements Parse<Reader, State> { } public void push(Prop prop) { - if(attribs==null) { + if (attribs==null) { attribs = new ArrayList<>(); idx = 0; } @@ -259,9 +259,9 @@ public class InXML implements Parse<Reader, State> { public Prop pop() { Prop rv = null; - if(attribs!=null) { + if (attribs!=null) { rv = attribs.get(idx++); - if(idx>=attribs.size())attribs = null; + if (idx>=attribs.size())attribs = null; } return rv; } @@ -282,8 +282,8 @@ public class InXML implements Parse<Reader, State> { // Recursively look back for any namespaces protected Map<String,String> getNS() { - if(ns!=null)return ns; - if(prev!=null) { + if (ns!=null)return ns; + if (prev!=null) { return prev.getNS(); } return null; @@ -291,47 +291,47 @@ public class InXML implements Parse<Reader, State> { private void addNS(Prop prop) { Map<String,String> existingNS = getNS(); - if(ns==null)ns = new HashMap<>(); + if (ns==null)ns = new HashMap<>(); // First make a copy of previous NSs so that we have everything we need, but can overwrite, if necessary - if(existingNS!=null && ns!=existingNS) { + if (existingNS!=null && ns!=existingNS) { ns.putAll(ns); } ns.put(prop.tag, prop.value); } private JaxInfo getDerived(State state, JaxInfo ji, DerTag derTag) throws ParseException { - if(derTag==null)return ji; + if (derTag==null)return ji; List<Prop> props = derTag.props; Prop derived = null; - if(props!=null) { + if (props!=null) { // Load Namespaces (if any) - for(Prop prop : props) { - if(prop.tag.startsWith("xmlns:")) { + for (Prop prop : props) { + if (prop.tag.startsWith("xmlns:")) { addNS(prop); } } - for(Prop prop : props) { - if(prop.tag.endsWith(":type")) { + for (Prop prop : props) { + if (prop.tag.endsWith(":type")) { int idx = prop.tag.indexOf(':'); String potentialNS = "xmlns:"+prop.tag.substring(0,idx); Map<String,String> ns = getNS(); boolean noNamespace = false; - if(ns==null) { + if (ns==null) { noNamespace = true; } else { String nsVal = ns.get(potentialNS); - if(nsVal==null) noNamespace = true; + if (nsVal==null) noNamespace = true; else { derived = new Prop(Parsed.EXTENSION_TAG,prop.value); state.push(derived); } } - if(noNamespace) { + if (noNamespace) { throw new ParseException(prop.tag + " utilizes an invalid Namespace prefix"); } - } else if(!prop.tag.startsWith("xmlns")) { + } else if (!prop.tag.startsWith("xmlns")) { state.push(prop); } } @@ -348,10 +348,10 @@ public class InXML implements Parse<Reader, State> { // @Override public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException { - if(derTag.isXmlInfo) { + if (derTag.isXmlInfo) { parsed.event = START_DOC; - } else if(ji.name.equals(derTag.name)) { - if(derTag.isEndTag) { + } else if (ji.name.equals(derTag.name)) { + if (derTag.isEndTag) { parsed.event = END_DOC; parsed.state.greatExp = prev; } else { @@ -374,22 +374,22 @@ public class InXML implements Parse<Reader, State> { // @Override public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException { - if(derTag.isEndTag && ji.name.equals(derTag.name)) { + if (derTag.isEndTag && ji.name.equals(derTag.name)) { parsed.state.greatExp = prev; parsed.event = END_OBJ; - if(printName)parsed.name = ji.name; + if (printName)parsed.name = ji.name; } else { //Standard Members - for(JaxInfo memb : ji.members) { - if(memb.name.equals(derTag.name)) { + for (JaxInfo memb : ji.members) { + if (memb.name.equals(derTag.name)) { parsed.name = memb.name; - if(memb.isArray) { + if (memb.isArray) { parsed.state.unevaluated = derTag; // evaluate within Array Context parsed.event = START_ARRAY; parsed.state.greatExp = new ArrayExpectations(parsed.state,memb,this); return false; - } else if(memb.isObject()) { - if(derTag.isEndTag) { + } else if (memb.isObject()) { + if (derTag.isEndTag) { throw new ParseException("Unexpected End Tag </" + derTag.name + '>'); } else { parsed.event = START_OBJ; @@ -398,7 +398,7 @@ public class InXML implements Parse<Reader, State> { return false; } } else { // a leaf - if(derTag.isEndTag) { + if (derTag.isEndTag) { throw new ParseException("Misplaced End Tag </" + parsed.name + '>'); } else { parsed.state.greatExp = new LeafExpectations(parsed.state,memb, this); @@ -421,7 +421,7 @@ public class InXML implements Parse<Reader, State> { // @Override public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException { - if(ji.name.equals(derTag.name) && derTag.isEndTag) { + if (ji.name.equals(derTag.name) && derTag.isEndTag) { parsed.event = NEXT; parsed.isString = ji.isString; parsed.state.greatExp = prev; @@ -435,18 +435,18 @@ public class InXML implements Parse<Reader, State> { private static class ArrayExpectations extends GreatExpectations { public ArrayExpectations(State state, JaxInfo ji, GreatExpectations prev) throws ParseException { super(state, ji, prev,null); - if(state.arrayInfo==null)state.arrayInfo=new Stack<ArrayState>(); + if (state.arrayInfo==null)state.arrayInfo=new Stack<ArrayState>(); state.arrayInfo.push(new ArrayState()); } // @Override public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException { - if(ji.name.equals(derTag.name) && !derTag.isEndTag) { - if(ji.isObject()) { - if(derTag.isEndTag) { + if (ji.name.equals(derTag.name) && !derTag.isEndTag) { + if (ji.isObject()) { + if (derTag.isEndTag) { throw new ParseException("Unexpected End Tag </" + derTag.name + '>'); } else { ArrayState ai = parsed.state.arrayInfo.peek(); - if(ai.firstObj || ai.didNext) { + if (ai.firstObj || ai.didNext) { ai.firstObj = false; ai.didNext = false; parsed.event = START_OBJ; @@ -459,7 +459,7 @@ public class InXML implements Parse<Reader, State> { } } } else { // a leave - if(derTag.isEndTag) { + if (derTag.isEndTag) { throw new ParseException("Misplaced End Tag </" + parsed.name + '>'); } else { parsed.state.greatExp = new LeafExpectations(parsed.state, ji, this); diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxInfo.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxInfo.java index edc5f787..d209f02f 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxInfo.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxInfo.java @@ -65,22 +65,22 @@ public class JaxInfo { public int getType() { - if(isArray)return ARRAY; - else if(members!=null)return OBJECT; + if (isArray)return ARRAY; + else if (members!=null)return OBJECT; return DATA; } public JaxInfo getDerived(String derivedName) { JaxInfo derived; // Lazy Instantiation - if(extensions == null) { + if (extensions == null) { extensions = new HashMap<>(); derived = null; } else { derived = extensions.get(derivedName); } - if(derived == null) { + if (derived == null) { //TODO for the moment, Classes are in same package Package pkg = clss.getPackage(); try { @@ -95,8 +95,8 @@ public class JaxInfo { } public static JaxInfo get(JaxInfo[] fields, String name) { - for(JaxInfo f : fields) { - if(name.equals(f.name)) return f; + for (JaxInfo f : fields) { + if (name.equals(f.name)) return f; } return null; } @@ -128,7 +128,7 @@ public class JaxInfo { */ public static JaxInfo build(Class<?> cls, String ... rootNns) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException { String defaultNS; - if(rootNns.length>0 && rootNns[0]!=null) { + if (rootNns.length>0 && rootNns[0]!=null) { defaultNS = rootNns[0]; } else { Package pkg = cls.getPackage(); @@ -136,15 +136,15 @@ public class JaxInfo { defaultNS = xs==null?"":xs.namespace(); } String name; - if(rootNns.length>1) { + if (rootNns.length>1) { name = rootNns[1]; } else { XmlRootElement xre = cls.getAnnotation(XmlRootElement.class); - if(xre!=null) { + if (xre!=null) { name = xre.name(); } else { XmlType xt = cls.getAnnotation(XmlType.class); - if(xt!=null) { + if (xt!=null) { name=xt.name(); } else { throw new ParseException("Need a JAXB Object with XmlRootElement, or stipulate in parms"); @@ -162,10 +162,10 @@ public class JaxInfo { Class<?> cls = clazz; // Build up Method names from JAXB Annotations XmlType xt; - while((xt = cls.getAnnotation(XmlType.class))!=null) { - if(fields==null)fields = new ArrayList<>(); - for(String field : xt.propOrder()) { - if("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array + while ((xt = cls.getAnnotation(XmlType.class))!=null) { + if (fields==null)fields = new ArrayList<>(); + for (String field : xt.propOrder()) { + if ("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array Field rf = cls.getDeclaredField(field); Class<?> ft = rf.getType(); @@ -175,27 +175,27 @@ public class JaxInfo { String namespace = defaultNS; XmlElement xe = rf.getAnnotation(XmlElement.class); - if(xe!=null) { + if (xe!=null) { xmlName=xe.name(); required = xe.required(); nillable = false; - if(DEFAULT.equals(xmlName)) { + if (DEFAULT.equals(xmlName)) { xmlName = field; } namespace = xe.namespace(); - if(DEFAULT.equals(namespace)) { + if (DEFAULT.equals(namespace)) { namespace = defaultNS; } } // If object is a List, then it is possible multiple, per XML/JAXB evaluation - if(ft.isAssignableFrom(List.class)) { + if (ft.isAssignableFrom(List.class)) { Type t = rf.getGenericType(); String classname = t.toString(); int start = classname.indexOf('<'); int end = classname.indexOf('>'); Class<?> genClass = Class.forName(classname.substring(start+1, end)); xe = genClass.getAnnotation(XmlElement.class); - if(xe!=null && !DEFAULT.equals(xe.namespace())) { + if (xe!=null && !DEFAULT.equals(xe.namespace())) { namespace = xe.namespace(); } // add recursed recursed member, marked as array @@ -208,7 +208,7 @@ public class JaxInfo { } cls = cls.getSuperclass(); }; - if(fields!=null) { + if (fields!=null) { JaxInfo[] rv = new JaxInfo[fields.size()]; fields.toArray(rv); return rv; @@ -219,17 +219,17 @@ public class JaxInfo { public StringBuilder dump(StringBuilder sb, int idx) { - for(int i=0;i<idx;++i)sb.append(' '); + for (int i=0;i<idx;++i)sb.append(' '); sb.append("Field "); sb.append(name); sb.append(" ["); sb.append(clss.getName()); sb.append("] "); - if(isArray)sb.append(" (array)"); - if(required)sb.append(" (required)"); - if(nillable)sb.append(" (nillable)"); - if(members!=null) { - for(JaxInfo f : members) { + if (isArray)sb.append(" (array)"); + if (required)sb.append(" (required)"); + if (nillable)sb.append(" (nillable)"); + if (members!=null) { + for (JaxInfo f : members) { sb.append('\n'); f.dump(sb,idx+2); } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxSet.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxSet.java index 6a779fb8..2d7af059 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxSet.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/JaxSet.java @@ -45,11 +45,11 @@ public class JaxSet<T> { members = new TreeMap<>(); XmlType xmltype = cls.getAnnotation(XmlType.class); Class<?> paramType[] = new Class[] {String.class}; - for(String str : xmltype.propOrder()) { + for (String str : xmltype.propOrder()) { try { String setName = "set" + Character.toUpperCase(str.charAt(0)) + str.subSequence(1, str.length()); Method meth = cls.getMethod(setName,paramType ); - if(meth!=null) { + if (meth!=null) { members.put(str, new Setter<T>(meth) { public void set(T o, Object t) throws ParseException { try { @@ -78,7 +78,7 @@ public class JaxSet<T> { synchronized(jsets) { @SuppressWarnings("unchecked") JaxSet<X> js = (JaxSet<X>)jsets.get(cls); - if(js == null) { + if (js == null) { jsets.put(cls, js = new JaxSet<>(cls)); } return js; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Ladder.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Ladder.java index 5e03ac91..6ff627b9 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Ladder.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Ladder.java @@ -55,7 +55,7 @@ public class Ladder<T> { public void top() { rung = struts.length-1; - while(rung>0 && struts[rung]==null)--rung; + while (rung>0 && struts[rung]==null)--rung; } public int howHigh() { @@ -63,7 +63,7 @@ public class Ladder<T> { } public void jumpTo(int rung) { - if(rung>=struts.length) { + if (rung>=struts.length) { Object[] temp = new Object[init_size*((rung/init_size)+1)]; System.arraycopy(struts, 0, temp, 0, struts.length); struts = temp; @@ -83,7 +83,7 @@ public class Ladder<T> { public void ascend() { ++rung; - if(rung>=struts.length) { + if (rung>=struts.length) { Object[] temp = new Object[struts.length+init_size]; System.arraycopy(struts, 0, temp, 0, struts.length); struts = temp; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Marshal.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Marshal.java index 4b8d2bf3..3729d1e3 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Marshal.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Marshal.java @@ -59,7 +59,7 @@ public abstract class Marshal<T> implements Parse<T, Marshal.State> { @Override public Void next() { - if(!hasNext()) { + if (!hasNext()) { throw new NoSuchElementException(); } return null; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJax.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJax.java index 2716c8be..4fb52d86 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJax.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJax.java @@ -35,8 +35,8 @@ public class OutJax extends Out { public <IN,S> void extract(IN in, Writer writer, Parse<IN, S> parse, boolean... options) throws IOException, ParseException { Parsed<S> p = parse.newParsed(); JaxEval je = this.jaxEval; - while((p = parse.parse(in,p.reuse())).valid()) { - if(je==null)throw new ParseException("Incomplete content"); + while ((p = parse.parse(in,p.reuse())).valid()) { + if (je==null)throw new ParseException("Incomplete content"); je = je.eval(p); } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJson.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJson.java index d0a26784..6c868378 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJson.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutJson.java @@ -33,7 +33,7 @@ public class OutJson extends Out { public<IN,S> void extract(IN in, Writer writer, Parse<IN, S> prs, boolean ... options) throws IOException, ParseException { Parsed<S> p = prs.newParsed(); IndentPrintWriter ipw; - if(options.length>0 && options[0]) { // is Pretty + if (options.length>0 && options[0]) { // is Pretty ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer); writer = ipw; } else { @@ -47,13 +47,13 @@ public class OutJson extends Out { char afterName=0, beforeName=0, maybe = 0, prev=0; int count = 0; - while((p = prs.parse(in,p.reuse())).valid()) { + while ((p = prs.parse(in,p.reuse())).valid()) { ++count; switch(p.event) { case 1: continue; case 2: - if(count==2) { // it's empty, write open/close on it's own + if (count==2) { // it's empty, write open/close on it's own writer.append('{'); writer.append('}'); } @@ -61,7 +61,7 @@ public class OutJson extends Out { return; case '{': afterName = '{'; - if(jsonLevel.peek().printObjectName) { + if (jsonLevel.peek().printObjectName) { print = true; } else { // don't print names on first print=false; @@ -70,7 +70,7 @@ public class OutJson extends Out { jsonLevel.push(new LevelStack(true)); break; case '}': - if(p.hasData()) { // if we have data, we print that, so may need to prepend a comma. + if (p.hasData()) { // if we have data, we print that, so may need to prepend a comma. maybe = jsonLevel.peek().listItem(); } else { // No data means just print, p.name = ""; // XML tags come through with names, but no data @@ -81,7 +81,7 @@ public class OutJson extends Out { break; case '[': afterName = p.event; - if((prev==',' && !hadData) || prev==']')maybe=','; + if ((prev==',' && !hadData) || prev==']')maybe=','; else maybe = jsonLevel.peek().listItem(); jsonLevel.push(new LevelStack(false)); @@ -89,8 +89,8 @@ public class OutJson extends Out { break; case ']': afterName = p.event; - if(p.hasData()) { - if(prev==',' && !hadData)maybe=','; + if (p.hasData()) { + if (prev==',' && !hadData)maybe=','; else maybe = jsonLevel.peek().listItem(); } else { p.name = ""; // XML tags come through with names, but no data @@ -101,7 +101,7 @@ public class OutJson extends Out { break; case 3: case ',': - if(!p.hasData()) { + if (!p.hasData()) { p.isString=false; print=false; } else { @@ -113,36 +113,36 @@ public class OutJson extends Out { print = true; } - if(maybe!=0) { - if(ipw==null)writer.append(maybe); + if (maybe!=0) { + if (ipw==null)writer.append(maybe); else ipw.println(maybe); maybe = 0; } - if(beforeName!=0) { - if(ipw==null)writer.append(beforeName); + if (beforeName!=0) { + if (ipw==null)writer.append(beforeName); else ipw.println(beforeName); beforeName = 0; } - if(print) { - if(p.hasName()) { + if (print) { + if (p.hasName()) { writer.append('"'); - if(p.event==3)writer.append("__"); + if (p.event==3)writer.append("__"); writer.append(p.name); writer.append("\":"); } - if(p.hasData()) { - if(p.isString) { + if (p.hasData()) { + if (p.isString) { writer.append('"'); escapedWrite(writer, p.sb); writer.append('"'); - } else if(p.sb.length()>0) { + } else if (p.sb.length()>0) { writer.append(p.sb); } } } - if(afterName!=0) { - if(ipw==null)writer.append(afterName); + if (afterName!=0) { + if (ipw==null)writer.append(afterName); else { switch(afterName) { case '{': @@ -155,7 +155,7 @@ public class OutJson extends Out { ipw.print(afterName); break; case ']': - if(prev=='}' || prev==',')ipw.println(); + if (prev=='}' || prev==',')ipw.println(); ipw.dec(); ipw.print(afterName); break; @@ -170,7 +170,7 @@ public class OutJson extends Out { afterName = 0; } - if(ipw!=null) { + if (ipw!=null) { switch(p.event) { case '[': ipw.inc(); @@ -187,11 +187,11 @@ public class OutJson extends Out { private void escapedWrite(Writer writer, StringBuilder sb) throws IOException { char c; - for(int i=0;i<sb.length();++i) { + for (int i=0;i<sb.length();++i) { switch(c=sb.charAt(i)) { case '\\': writer.append(c); - if(i<sb.length()) { + if (i<sb.length()) { c=sb.charAt(++i); writer.append(c); } @@ -221,7 +221,7 @@ public class OutJson extends Out { } public char listItem() { - if(first_n_List) { + if (first_n_List) { first_n_List=false; return 0; } else { diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutRaw.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutRaw.java index babf53de..f07498b3 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutRaw.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutRaw.java @@ -30,7 +30,7 @@ public class OutRaw extends Out{ public<IN,S> void extract(IN in, Writer writer, Parse<IN,S> prs, boolean ... options) throws IOException, ParseException { Parsed<S> p = prs.newParsed(); - while((p = prs.parse(in,p.reuse())).valid()) { + while ((p = prs.parse(in,p.reuse())).valid()) { writer.append(p.toString()); writer.append('\n'); } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutXML.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutXML.java index a887cb96..6472c88e 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutXML.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/OutXML.java @@ -43,9 +43,9 @@ public class OutXML extends Out{ public OutXML(String root, String ... params) { this.root = root; props = new ArrayList<>(); - for(String p : params) { + for (String p : params) { String[] tv=p.split("="); - if(tv.length==2) + if (tv.length==2) props.add(new Prop(tv[0],tv[1])); } } @@ -71,8 +71,8 @@ public class OutXML extends Out{ boolean pretty = (options.length>0&&options[0]); IndentPrintWriter ipw; - if(pretty) { - if(writer instanceof IndentPrintWriter) { + if (pretty) { + if (writer instanceof IndentPrintWriter) { ipw = (IndentPrintWriter)writer; } else { writer = ipw = new IndentPrintWriter(writer); @@ -82,19 +82,19 @@ public class OutXML extends Out{ } boolean closeTag = false; Level level = new Level(null); - while((p = prs.parse(in,p.reuse())).valid()) { - if(!p.hasName() && level.multi!=null) { + while ((p = prs.parse(in,p.reuse())).valid()) { + if (!p.hasName() && level.multi!=null) { p.name=level.multi; } - if(closeTag && p.event!=Parse.ATTRIB) { + if (closeTag && p.event!=Parse.ATTRIB) { writer.append('>'); - if(pretty)writer.append('\n'); + if (pretty)writer.append('\n'); closeTag = false; } switch(p.event) { case Parse.START_DOC: - if(!(options.length>1&&options[1])) // if not a fragment, print XML Info data - if(pretty)ipw.println(XML_INFO); + if (!(options.length>1&&options[1])) // if not a fragment, print XML Info data + if (pretty)ipw.println(XML_INFO); else writer.append(XML_INFO); break; case Parse.END_DOC: @@ -102,21 +102,21 @@ public class OutXML extends Out{ case Parse.START_OBJ: stack.push(level); level = new Level(level); - if(p.hasName()) { + if (p.hasName()) { closeTag = tag(writer,level.sbw,pretty,pretty,p.name,null); - } else if(root!=null && stack.size()==1) { // first Object + } else if (root!=null && stack.size()==1) { // first Object closeTag = tag(writer,level.sbw,pretty,pretty,root,null); // Write Root Props - for(Prop prop : props) { + for (Prop prop : props) { attrib(writer,pretty,prop.tag, prop.value,level); } } - if(pretty)ipw.inc(); + if (pretty)ipw.inc(); break; case Parse.END_OBJ: - if(p.hasData()) + if (p.hasData()) closeTag = tag(writer,writer,pretty,false,p.name, XmlEscape.convert(p.sb)); - if(pretty)ipw.dec(); + if (pretty)ipw.dec(); writer.append(level.sbw.getBuffer()); level = stack.pop(); break; @@ -124,16 +124,16 @@ public class OutXML extends Out{ level.multi = p.name; break; case Parse.END_ARRAY: - if(p.hasData()) + if (p.hasData()) closeTag = tag(writer,writer,pretty,false, p.name, XmlEscape.convert(p.sb)); level.multi=null; break; case Parse.ATTRIB: - if(p.hasData()) + if (p.hasData()) attrib(writer,pretty,p.name, XmlEscape.convert(p.sb), level); break; case Parse.NEXT: - if(p.hasData()) + if (p.hasData()) closeTag = tag(writer,writer,pretty, false,p.name, XmlEscape.convert(p.sb)); break; } @@ -156,15 +156,15 @@ public class OutXML extends Out{ public boolean hasPrinted(String ns, String value, boolean create) { boolean rv = false; - if(nses==null) { - if(prev!=null)rv = prev.hasPrinted(ns, value, false); + if (nses==null) { + if (prev!=null)rv = prev.hasPrinted(ns, value, false); } else { String v = nses.get(ns); return value.equals(v); // note: accomodates not finding NS as well } - if(create && !rv) { - if(nses == null) nses = new HashMap<>(); + if (create && !rv) { + if (nses == null) nses = new HashMap<>(); nses.put(ns, value); } return rv; @@ -177,25 +177,25 @@ public class OutXML extends Out{ private boolean tag(Writer fore, Writer aft, boolean pretty, boolean returns, String tag, String data) throws IOException { fore.append('<'); fore.append(tag); - if(data!=null) { + if (data!=null) { fore.append('>'); // if no data, it may need some attributes... fore.append(data); - if(returns)fore.append('\n'); + if (returns)fore.append('\n'); } aft.append("</"); aft.append(tag); aft.append(">"); - if(pretty)aft.append('\n'); + if (pretty)aft.append('\n'); return data==null; } private void attrib(Writer fore, boolean pretty, String tag, String value, Level level) throws IOException { String realTag = tag.startsWith("__")?tag.substring(2):tag; // remove __ - if(realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance + if (realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance fore.append(" xsi:type=\""); fore.append(value); fore.append('"'); - if(!level.hasPrinted(XMLNS_XSI, XML_SCHEMA_INSTANCE,true)) { + if (!level.hasPrinted(XMLNS_XSI, XML_SCHEMA_INSTANCE,true)) { fore.append(' '); fore.append(XMLNS_XSI); fore.append("=\""); @@ -203,8 +203,8 @@ public class OutXML extends Out{ fore.append("\""); } } else { - if(realTag.startsWith("xmlns:") ) { - if(level.hasPrinted(realTag, value, true)) { + if (realTag.startsWith("xmlns:") ) { + if (level.hasPrinted(realTag, value, true)) { return; } } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Parsed.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Parsed.java index a4c679db..29a86de8 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Parsed.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Parsed.java @@ -73,15 +73,15 @@ public class Parsed<S> { public String toString() { StringBuilder sb2 = new StringBuilder(); - if(event<40)sb2.append((int)event); + if (event<40)sb2.append((int)event); else sb2.append(event); sb2.append(" - "); sb2.append(name); - if(sb.length()>0) { + if (sb.length()>0) { sb2.append(" : "); - if(isString)sb2.append('"'); + if (isString)sb2.append('"'); sb2.append(sb); - if(isString)sb2.append('"'); + if (isString)sb2.append('"'); } return sb2.toString(); } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Prop.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Prop.java index ae9c8934..d46fc8be 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Prop.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Prop.java @@ -31,7 +31,7 @@ class Prop { public Prop(String t_equals_v) { String[] tv = t_equals_v.split("="); - if(tv.length>1) { + if (tv.length>1) { tag = tv[0]; value = tv[1]; } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Saved.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Saved.java index a596b705..efb4ce4b 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Saved.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/Saved.java @@ -50,20 +50,20 @@ public class Saved extends Out implements Parse<Reader, State>{ // @Override public<IN,S> void extract(IN in, Writer ignore, Parse<IN,S> parser, boolean ... options) throws IOException, ParseException { Parsed<S> p = parser.newParsed(); - if(!append) { + if (!append) { // reuse array if not too big - if(content==null||content.length>INIT_SIZE*3) { + if (content==null||content.length>INIT_SIZE*3) { content = new Content[INIT_SIZE]; idx = -1; } else do { content[idx]=null; - } while(--idx>=0); + } while (--idx>=0); } // Note: idx needs to be -1 on initialization and no appendages - while((p = parser.parse(in,p.reuse())).valid()) { - if(!(append && (p.event==START_DOC || p.event==END_DOC))) { // skip any start/end of document in appendages - if(++idx>=content.length) { + while ((p = parser.parse(in,p.reuse())).valid()) { + if (!(append && (p.event==START_DOC || p.event==END_DOC))) { // skip any start/end of document in appendages + if (++idx>=content.length) { Content temp[] = new Content[content.length*2]; System.arraycopy(content, 0, temp, 0, idx); content = temp; @@ -76,7 +76,7 @@ public class Saved extends Out implements Parse<Reader, State>{ // @Override public Parsed<State> parse(Reader ignore, Parsed<State> parsed) throws ParseException { int i; - if((i=parsed.state.count++)<=idx) + if ((i=parsed.state.count++)<=idx) content[i].load(parsed); else parsed.event = Parse.NONE; @@ -85,9 +85,9 @@ public class Saved extends Out implements Parse<Reader, State>{ public Content[] cut(char event, int count) { append = true; - for(int i=idx;i>=0;--i) { - if(content[i].event==event) count--; - if(count==0) { + for (int i=idx;i>=0;--i) { + if (content[i].event==event) count--; + if (count==0) { Content[] appended = new Content[idx-i+1]; System.arraycopy(content, i, appended, 0, appended.length); idx = i-1; @@ -98,8 +98,8 @@ public class Saved extends Out implements Parse<Reader, State>{ } public void paste(Content[] appended) { - if(appended!=null) { - if(idx+appended.length>content.length) { + if (appended!=null) { + if (idx+appended.length>content.length) { Content temp[] = new Content[content.length*2]; System.arraycopy(content, 0, temp, 0, idx); content = temp; @@ -134,7 +134,7 @@ public class Saved extends Out implements Parse<Reader, State>{ p.isString = isString; p.event = event; p.name = name; - if(str!=null) + if (str!=null) p.sb.append(str); } @@ -144,14 +144,14 @@ public class Saved extends Out implements Parse<Reader, State>{ sb.append(" - "); sb.append(name); sb.append(": "); - if(isString)sb.append('"'); + if (isString)sb.append('"'); sb.append(str); - if(isString)sb.append('"'); + if (isString)sb.append('"'); sb.append(' '); - if(props!=null) { + if (props!=null) { boolean comma = false; - for(Prop prop : props) { - if(comma)sb.append(','); + for (Prop prop : props) { + if (comma)sb.append(','); else comma = true; sb.append(prop.tag); sb.append('='); diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/XmlEscape.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/XmlEscape.java index 1b0eec07..3007ea95 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/XmlEscape.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/XmlEscape.java @@ -36,13 +36,13 @@ public class XmlEscape { try { int c; StringBuilder esc = new StringBuilder(); - for(int cnt = 0;cnt<9 /*max*/; ++cnt) { - if((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence"); - if(c!=';') { + for (int cnt = 0;cnt<9 /*max*/; ++cnt) { + if ((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence"); + if (c!=';') { esc.append((char)c); } else { // evaluate Integer i = charMap.get(esc.toString()); - if(i==null) { + if (i==null) { // leave in nasty XML format for now. sb.append('&'); sb.append(esc); @@ -69,20 +69,20 @@ public class XmlEscape { public static String convert(StringBuilder insb) { int idx, ch; StringBuilder sb=null; - for(idx=0;idx<insb.length();++idx) { + for (idx=0;idx<insb.length();++idx) { ch = insb.charAt(idx); - if(ch>=160 || ch==34 || ch==38 || ch==39 || ch==60 || ch==62) { + if (ch>=160 || ch==34 || ch==38 || ch==39 || ch==60 || ch==62) { sb = new StringBuilder(); sb.append(insb,0,idx); break; } } - if(sb==null)return insb.toString(); + if (sb==null)return insb.toString(); - for(int i=idx;i<insb.length();++i) { + for (int i=idx;i<insb.length();++i) { ch = insb.charAt(i); - if(ch<160) { + if (ch<160) { switch(ch) { case 34: sb.append("""); break; case 38: sb.append("&"); break; @@ -94,7 +94,7 @@ public class XmlEscape { } } else { // use map String s = intMap.get(ch); - if(s==null)sb.append((char)ch); + if (s==null)sb.append((char)ch); else { sb.append('&'); sb.append(s); @@ -362,8 +362,8 @@ public class XmlEscape { charMap.put("hearts",9829); charMap.put("diams",9830); - for( Entry<String, Integer> es: charMap.entrySet()) { - if(es.getValue()>=160); // save small space... note that no longer has amp, etc. + for ( Entry<String, Integer> es: charMap.entrySet()) { + if (es.getValue()>=160); // save small space... note that no longer has amp, etc. intMap.put(es.getValue(), es.getKey()); } } diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaDF.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaDF.java index 69926974..a95da8ea 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaDF.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaDF.java @@ -217,7 +217,7 @@ public class RosettaDF<T> extends BaseDataFactory implements DataFactory<T> { * @return */ public RosettaDF<T> rootMarshal(Marshal<T> marshal) { - if(marshal instanceof DocMarshal) { + if (marshal instanceof DocMarshal) { this.marshal = marshal; } else { this.marshal = DocMarshal.root(marshal); @@ -229,7 +229,7 @@ public class RosettaDF<T> extends BaseDataFactory implements DataFactory<T> { Out out = getOut(outType); TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? try { - if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if (marshal==null) { // Unknown marshaller... do working XML marshal/extraction StringWriter sw = new StringWriter(); jaxMar.marshal(trans.debug(), t, sw, options); out.extract(new StringReader(sw.toString()), new OutputStreamWriter(os), inXML,options); @@ -247,7 +247,7 @@ public class RosettaDF<T> extends BaseDataFactory implements DataFactory<T> { Out out = getOut(outType); TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? try { - if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if (marshal==null) { // Unknown marshaller... do working XML marshal/extraction StringWriter sw = new StringWriter(); jaxMar.marshal(trans.debug(), t, sw, options); out.extract(new StringReader(sw.toString()), writer, inXML,options); diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaData.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaData.java index 97f68dae..fa29dcdc 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaData.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/env/RosettaData.java @@ -129,7 +129,7 @@ public class RosettaData<T> implements Data<T>{ Parse<?,?> in = df.getIn(inType); TimeTaken tt = in.start(trans); try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if (df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction StringWriter sw = new StringWriter(); df.jaxMar.marshal(trans.debug(), t, sw, options); saved.extract(new StringReader(xml = sw.toString()), (Writer)null, df.inXML); @@ -169,15 +169,15 @@ public class RosettaData<T> implements Data<T>{ Out out = df.getOut(outType); TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? try { - if(outType==TYPE.XML) { - if(xml==null) { + if (outType==TYPE.XML) { + if (xml==null) { StringWriter sw = new StringWriter(); out.extract(null, sw, saved, options); xml = sw.toString(); } return xml; } else { // is JSON - if(json==null) { + if (json==null) { StringWriter sw = new StringWriter(); out.extract(null, sw, saved, options); json = sw.toString(); @@ -197,9 +197,9 @@ public class RosettaData<T> implements Data<T>{ Out out = df.getOut(outType); TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? try { - if(outType==TYPE.XML && xml!=null) { + if (outType==TYPE.XML && xml!=null) { os.write(xml.getBytes()); - } else if(outType==TYPE.JSON && json!=null) { + } else if (outType==TYPE.JSON && json!=null) { os.write(json.getBytes()); } else { out.extract(null, os, saved, options); @@ -217,9 +217,9 @@ public class RosettaData<T> implements Data<T>{ Out out = df.getOut(outType); TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? try { - if(outType==TYPE.XML && xml!=null) { + if (outType==TYPE.XML && xml!=null) { writer.append(xml); - } else if(outType==TYPE.JSON && json!=null) { + } else if (outType==TYPE.JSON && json!=null) { writer.append(json); } else { out.extract(null, writer, saved, options); @@ -260,7 +260,7 @@ public class RosettaData<T> implements Data<T>{ Out out = df.getOut(outType); TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if (df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction StringWriter sw = new StringWriter(); df.jaxMar.marshal(trans.debug(), t, sw, options); out.extract(new StringReader(xml = sw.toString()), writer, df.inXML,options); @@ -278,8 +278,8 @@ public class RosettaData<T> implements Data<T>{ Out out = df.getOut(outType); TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction - if(outType.equals(TYPE.XML)) { + if (df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if (outType.equals(TYPE.XML)) { df.jaxMar.marshal(trans.debug(), t, os, options); } else { StringWriter sw = new StringWriter(); diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DataWriter.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DataWriter.java index 849a3214..0617e01d 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DataWriter.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DataWriter.java @@ -127,7 +127,7 @@ public abstract class DataWriter<T> { // String in "HexString" or the processing in // "String.format" //sb.append("0x"); - for(int i=0;i<ba.length;++i) { + for (int i=0;i<ba.length;++i) { byte b = ba[i]; sb.append(chars[((b&0xF0)>>4)]); sb.append(chars[b&0xF]); diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DocMarshal.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DocMarshal.java index 6cabe068..1fa17010 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DocMarshal.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/DocMarshal.java @@ -40,18 +40,18 @@ public class DocMarshal<T> extends Marshal<T> { public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException { Ladder<Iterator<?>> ladder = parsed.state.ladder; Iterator<?> iter = ladder.peek(); - if(iter==null) { + if (iter==null) { ladder.push(PENDING_ITERATOR); parsed.event = START_DOC; } else if (DONE_ITERATOR.equals(iter)) { } else { ladder.ascend(); // look at field info Iterator<?> currFieldIter = ladder.peek(); - if(!DONE_ITERATOR.equals(currFieldIter)){ + if (!DONE_ITERATOR.equals(currFieldIter)){ parsed = root.parse(t, parsed); } ladder.descend(); - if(DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) { + if (DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) { parsed.event = END_DOC; ladder.push(DONE_ITERATOR); } @@ -68,7 +68,7 @@ public class DocMarshal<T> extends Marshal<T> { @Override public Void next() { - if(!hasNext()) { + if (!hasNext()) { throw new NoSuchElementException(); } return null; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/FieldArray.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/FieldArray.java index 48f3608d..abc19b26 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/FieldArray.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/FieldArray.java @@ -44,9 +44,9 @@ public abstract class FieldArray<T,S> extends Marshal<T> { public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException { Ladder<Iterator<?>> ladder = parsed.state.ladder; Iterator<?> iter = ladder.peek(); - if(iter==null) { + if (iter==null) { List<S> list = data(t); - if(list.isEmpty() && parsed.state.smallest) { + if (list.isEmpty() && parsed.state.smallest) { ladder.push(DONE_ITERATOR); } else { ladder.push(new ListIterator<S>(list)); @@ -59,24 +59,24 @@ public abstract class FieldArray<T,S> extends Marshal<T> { Iterator<?> memIter = ladder.peek(); ListIterator<S> mems = (ListIterator<S>)iter; S mem; - if(memIter==null) { + if (memIter==null) { mem=mems.next(); - } else if(!DONE_ITERATOR.equals(memIter)) { + } else if (!DONE_ITERATOR.equals(memIter)) { mem=mems.peek(); - } else if(iter.hasNext()) { + } else if (iter.hasNext()) { mem=null; ladder.push(null); } else { mem=null; } - if(mem!=null) { + if (mem!=null) { parsed.isString=dataWriter.write(mem, parsed.sb); parsed.event = NEXT; } ladder.descend(); - if(mem==null) { - if(iter.hasNext()) { + if (mem==null) { + if (iter.hasNext()) { parsed.event = NEXT; } else { parsed.event = END_ARRAY; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjArray.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjArray.java index 384e0c98..9c64e83d 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjArray.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjArray.java @@ -44,9 +44,9 @@ public abstract class ObjArray<T,S> extends Marshal<T> { public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException { Ladder<Iterator<?>> ladder = parsed.state.ladder; Iterator<?> iter = ladder.peek(); - if(iter==null) { + if (iter==null) { List<S> list = data(t); - if(list.isEmpty() && parsed.state.smallest) { + if (list.isEmpty() && parsed.state.smallest) { ladder.push(DONE_ITERATOR); } else { ladder.push(new ListIterator<S>(list)); @@ -58,22 +58,22 @@ public abstract class ObjArray<T,S> extends Marshal<T> { Iterator<?> memIter = ladder.peek(); ListIterator<S> mems = (ListIterator<S>)iter; S mem; - if(memIter==null) { + if (memIter==null) { mem=mems.next(); - } else if(!DONE_ITERATOR.equals(memIter)) { + } else if (!DONE_ITERATOR.equals(memIter)) { mem=mems.peek(); - } else if(iter.hasNext()) { + } else if (iter.hasNext()) { mem=null; ladder.push(null); } else { mem=null; } - if(mem!=null) + if (mem!=null) parsed = subMarshaller.parse(mem, parsed); ladder.descend(); - if(mem==null) { - if(iter.hasNext()) { + if (mem==null) { + if (iter.hasNext()) { parsed.event = NEXT; } else { parsed.event = END_ARRAY; diff --git a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjMarshal.java b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjMarshal.java index 31e214b5..d96a44d0 100644 --- a/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjMarshal.java +++ b/misc/rosetta/src/main/java/org/onap/aaf/misc/rosetta/marshal/ObjMarshal.java @@ -47,9 +47,9 @@ public abstract class ObjMarshal<T> extends Marshal<T> { */ @SuppressWarnings("unchecked") protected void add(Marshal<T> pm) { - if(pml==null) { + if (pml==null) { pml = new Marshal[Ladder.DEFAULT_INIT_SIZE]; - } else if(end>pml.length) { + } else if (end>pml.length) { Object temp[] = pml; pml = new Marshal[pml.length+Ladder.DEFAULT_INIT_SIZE]; System.arraycopy(temp, 0, pml, 0, pml.length); @@ -66,8 +66,8 @@ public abstract class ObjMarshal<T> extends Marshal<T> { public Parsed<State> parse(T in, Parsed<State> parsed) throws ParseException { Ladder<Iterator<?>> ladder = parsed.state.ladder; Iterator<Marshal<T>> iter = (Iterator<Marshal<T>>)ladder.peek(); - if(iter==null) { - if(pml.length>0) { + if (iter==null) { + if (pml.length>0) { ladder.push(new FieldsIterator()); parsed.event = START_OBJ; } else { @@ -78,22 +78,22 @@ public abstract class ObjMarshal<T> extends Marshal<T> { ladder.ascend(); // look at field info Iterator<?> currFieldIter = ladder.peek(); Marshal<T> marshal; - if(currFieldIter==null) { + if (currFieldIter==null) { marshal=fields.next(); - } else if(!DONE_ITERATOR.equals(currFieldIter)) { + } else if (!DONE_ITERATOR.equals(currFieldIter)) { marshal=fields.peek(); - if(marshal==null && fields.hasNext())marshal=fields.next(); - } else if(fields.hasNext()) { + if (marshal==null && fields.hasNext())marshal=fields.next(); + } else if (fields.hasNext()) { marshal=fields.next(); ladder.push(null); } else { marshal=null; } - if(marshal!=null) + if (marshal!=null) parsed = marshal.parse(in, parsed); ladder.descend(); - if(marshal==null || parsed.event==NONE) { + if (marshal==null || parsed.event==NONE) { parsed.event = END_OBJ; ladder.push(DONE_ITERATOR); } @@ -111,7 +111,7 @@ public abstract class ObjMarshal<T> extends Marshal<T> { @Override public Marshal<T> next() { - if(!hasNext()) { + if (!hasNext()) { throw new NoSuchElementException(); } return pml[++idx]; diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromJSON.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromJSON.java index 3e12f594..67565122 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromJSON.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromJSON.java @@ -90,7 +90,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.JSON); - } while(report.go()); + } while (report.go()); String result = sbw.toString(); System.out.println(result); @@ -120,7 +120,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.JSON); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -147,7 +147,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.JSON); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -175,7 +175,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.JSON); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -218,7 +218,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -260,7 +260,7 @@ public class JU_FromJSON { tt.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromXML.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromXML.java index 2a4e3d2d..4fefe622 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromXML.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_FromXML.java @@ -100,7 +100,7 @@ public class JU_FromXML { tt.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -127,7 +127,7 @@ public class JU_FromXML { tt.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -136,7 +136,7 @@ public class JU_FromXML { @Test public void warmup() throws Exception { - if(ITERATIONS>20) { + if (ITERATIONS>20) { System.out.println("*** Warmup JAXB ***"); JAXBumar jaxbUmar = new JAXBumar(LargerData.class); @@ -170,7 +170,7 @@ public class JU_FromXML { all.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); @@ -209,7 +209,7 @@ public class JU_FromXML { all.done(); } report.glean(trans,Env.XML); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); } @@ -225,7 +225,7 @@ public class JU_FromXML { Trans trans = EnvFactory.newTrans(); LargerData ld; - for(int i=0;i<ITERATIONS;++i) { + for (int i=0;i<ITERATIONS;++i) { sbw.reset(); TimeTaken all = trans.start("Combo", Env.SUB); try { @@ -247,7 +247,7 @@ public class JU_FromXML { } sbw.append('\n'); Metric m; - if(ITERATIONS>20) { + if (ITERATIONS>20) { m = trans.auditTrail(0,null); } else { m = trans.auditTrail(0, sbw.getBuffer()); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_JSON.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_JSON.java index 9ab06e7c..af58ea57 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_JSON.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_JSON.java @@ -123,7 +123,7 @@ public class JU_JSON { System.out.println(sw); String result = sw.toString(); - if(!result.equals(cmp)) { + if (!result.equals(cmp)) { sw.getBuffer().setLength(0); new OutRaw().extract(new StringReader(str), sw, in); System.out.println(sw); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Ladder.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Ladder.java index 229f1bf4..fd6142b1 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Ladder.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Ladder.java @@ -32,22 +32,22 @@ public class JU_Ladder { public void test() { Ladder<String> ladder = new Ladder<String>(); - for(int i=0;i<30;++i) { - for(int j=0;j<i;++j)ladder.ascend(); + for (int i=0;i<30;++i) { + for (int j=0;j<i;++j)ladder.ascend(); String str = "Rung " + i; assertEquals(ladder.peek(),null); ladder.push(str); assertEquals(str,ladder.peek()); assertEquals(str,ladder.pop()); assertEquals(null,ladder.peek()); - for(int j=0;j<i;++j)ladder.descend(); + for (int j=0;j<i;++j)ladder.descend(); } assertEquals(ladder.height(),32); // Sizing, when naturally created is by 8 ladder.cutTo(8); assertEquals(ladder.height(),8); - for(int i=0;i<30;++i) { + for (int i=0;i<30;++i) { ladder.jumpTo(i); String str = "Rung " + i; assertEquals(ladder.peek(),null); @@ -57,7 +57,7 @@ public class JU_Ladder { ladder.bottom(); - for(int i=0;i<30;++i) { + for (int i=0;i<30;++i) { assertEquals("Rung " + i,ladder.peek()); ladder.ascend(); } @@ -66,7 +66,7 @@ public class JU_Ladder { ladder.top(); assertEquals("Rung 29",ladder.peek()); - for(int i=0;i<30;++i) { + for (int i=0;i<30;++i) { ladder.jumpTo(i); assertEquals("Rung " + i,ladder.peek()); } diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_RosettaDF.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_RosettaDF.java index 1a5f86f3..ccc29317 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_RosettaDF.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_RosettaDF.java @@ -95,7 +95,7 @@ public class JU_RosettaDF { tt.done(); } report.glean(trans, 1,2,3,4,5); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw); @@ -117,7 +117,7 @@ public class JU_RosettaDF { RosettaData<?> data = df.newData(trans).in(Data.TYPE.JSON).out(Data.TYPE.XML); data.direct(new StringReader(JU_FromJSON.str), sbw); report.glean(trans); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Saved.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Saved.java index de1b5500..a0847f4c 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Saved.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Saved.java @@ -95,7 +95,7 @@ public class JU_Saved<b> { tt.done(); } report.glean(trans,1,2,3,4); - } while(report.go()); + } while (report.go()); report.report(sbw); System.out.println(sbw.toString()); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Struct.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Struct.java index 7e767e5d..40c41596 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Struct.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Struct.java @@ -57,7 +57,7 @@ public class JU_Struct { // Setter<SampleData> setter = jaxSet.setter("id"); // setter.set(sd, "Your ID"); // -// for(Entry<String, Getter<SampleData>> es : jaxSet.getters()) { +// for (Entry<String, Getter<SampleData>> es : jaxSet.getters()) { // System.out.print(es.getKey()); // System.out.print(' '); // System.out.println(es.getValue().get(sd)); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Types.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Types.java index 032f9f1c..2aca5f52 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Types.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/JU_Types.java @@ -120,9 +120,9 @@ public class JU_Types { Multi multi = new Multi(); MultiMarshal pmulti = new MultiMarshal(); - for(int i=0;i<10;++i) { + for (int i=0;i<10;++i) { System.out.println("===== Multi Iteration " + i + " ====="); - if(i>0) { + if (i>0) { multi.getSingle().add(setSData()); } System.out.println(" ===== RAW ====="); @@ -151,9 +151,9 @@ public class JU_Types { Multi multi = new Multi(); DocMarshal<Multi> doc = DocMarshal.root(new MultiMarshal()); - for(int i=0;i<3;++i) { + for (int i=0;i<3;++i) { System.out.println("===== Multi Iteration " + i + " ====="); - if(i>0) { + if (i>0) { multi.getSingle().add(setSData()); } System.out.println(" ===== RAW ====="); @@ -194,14 +194,14 @@ public class JU_Types { Trans trans = env.newTrans(); RosettaData<Multi> data = df.newData(trans); // Prime pump - for(int i=0;i<100;++i) { + for (int i=0;i<100;++i) { data.load(multi); } trans = env.newTrans(); data = df.newData(trans); int iters = 10000; - for(int i=0;i<iters;++i) { + for (int i=0;i<iters;++i) { data.load(multi); } Metric metrics = trans.auditTrail(0, null,Env.JSON,Env.XML); @@ -215,13 +215,13 @@ public class JU_Types { data = df.newData(trans); // Prime pump - for(int i=0;i<100;++i) { + for (int i=0;i<100;++i) { data.load(multi); } trans = env.newTrans(); data = df.newData(trans); - for(int i=0;i<iters;++i) { + for (int i=0;i<iters;++i) { data.load(multi); } metrics = trans.auditTrail(0, null,Env.JSON,Env.XML); @@ -235,14 +235,14 @@ public class JU_Types { data = df.newData(trans); StringBuilderWriter sbw = new StringBuilderWriter(256); // Prime pump - for(int i=0;i<100;++i) { + for (int i=0;i<100;++i) { sbw.reset(); data.direct(multi, sbw, true); } trans = env.newTrans(); data = df.newData(trans); - for(int i=0;i<iters;++i) { + for (int i=0;i<iters;++i) { sbw.reset(); data.direct(multi, sbw, true); } @@ -287,7 +287,7 @@ public class JU_Types { System.out.println(sw); String result = sw.toString(); - if(!result.equals(str)) { + if (!result.equals(str)) { sw.getBuffer().setLength(0); new OutRaw().extract(new StringReader(str), sw, in); System.out.println(sw); diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/OutDump.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/OutDump.java index 6ebd07a3..7e230822 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/OutDump.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/OutDump.java @@ -38,7 +38,7 @@ public class OutDump extends Out{ Parsed<S> p = prs.newParsed(); - while((p = prs.parse(in,p.reuse())).valid()) { + while ((p = prs.parse(in,p.reuse())).valid()) { switch(p.event) { case Parse.START_OBJ: ipw.append("Start Object "); @@ -71,9 +71,9 @@ public class OutDump extends Out{ } private void printData(IndentPrintWriter ipw, Parsed<?> parsed) { - if(parsed.hasData()) { + if (parsed.hasData()) { ipw.append("Data:["); - if(parsed.hasName()) { + if (parsed.hasName()) { ipw.append(parsed.name); ipw.append(" : "); } diff --git a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/Report.java b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/Report.java index df4fec07..acb33010 100644 --- a/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/Report.java +++ b/misc/rosetta/src/test/java/org/onap/aaf/misc/rosetta/test/Report.java @@ -46,7 +46,7 @@ public class Report { Metric m = trans.auditTrail(0, null, type); total+=m.total; int min = Math.min(buckets.length, m.buckets.length); - for(int b=0;b<min;++b) { + for (int b=0;b<min;++b) { buckets[b]+=m.buckets[b]; } } @@ -59,7 +59,7 @@ public class Report { public void report(Writer sbw) throws IOException { sbw.append("\n"+count + " entries, Total Time: " + total + "ms, Avg Time: " + total/count + "ms\n"); int min = Math.min(buckets.length, names.length); - for(int i=0;i<min;++i) { + for (int i=0;i<min;++i) { sbw.append(" Time: " + names[i] + ' ' + buckets[i] + "ms, Avg Time: " + buckets[i]/count + "ms\n"); } |