Commit 7a0d8c84 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

Use generic for-iterarors as much as possible

parent 346ef269
Pipeline #513021 passed with stage
in 12 seconds
......@@ -117,14 +117,12 @@ public class TransmorphTask extends Task {
System.err.println("message = "+msg);
System.err.println("reloc = "+reloc);
// This should print all the arguments
for(Enumeration<Param> e = paramVect.elements();e.hasMoreElements();) {
Param p = e.nextElement();
for( Param p : paramVect ) {
System.err.println(p.getName()+" = "+p.getSelect());
}
} //end for
}
for(Enumeration<Param> e = paramVect.elements();e.hasMoreElements();) {
Param p = e.nextElement();
for( Param p : paramVect ) {
parameters.setParameter(p.getName(), (Object)p.getSelect());
}
......
......@@ -97,12 +97,11 @@ public final class TApplyProcess extends TProcessComposite {
for (int i1=0; i1 < iListLocalOut.length ; i1++){
if (process.getNameOut(i).equals(iListLocalOut[i1])) {
iListOut[i1]= process.getOut(i);
} //end if
} //end for
}//end if
} //end if
}//end for
//System.out.println("fin for");
}
}
}
}
}
for(int i=0 ; i < process.getNameIn().length ; i++) {
//System.out.println(process.getNameIn(i).getCompositeName());
......@@ -131,40 +130,35 @@ public final class TApplyProcess extends TProcessComposite {
// I am not sure that this does not double with generatePort ??
for(int i = 0; i<nameIn.length;i++){
iListIn [i] = new XML_Port(locIn[i],this,0,XML_Port.IN);
iListIn[i] = new XML_Port(locIn[i],this,0,XML_Port.IN);
listOfProcessIn.put(locIn[i],this);
} //end for
}
for(int i = 0; i<nameOut.length;i++){
iListOut[i] = new XML_Port(locOut[i],this,0,XML_Port.OUT);
listOfProcessOut.put(locOut[i],this);
} //end for
} //end proc
}
}
public void generatePort(){
for(int i = 0; i<nameIn.length;i++){
iListIn [i].setName(nameIn[i]);
iListIn[i].setName(nameIn[i]);
} //end for
}
for(int i = 0; i<nameOut.length;i++){
iListOut [i].setName(nameOut[i]);
} //end for
} //end proc
iListOut[i].setName(nameOut[i]);
}
}
/**
* Initializes inner processes when ApplyProcess is inside a Loop.
*/
public void reset() throws TMException, SAXException {
listOfChannel = new Hashtable<String,TChannel>();
test=false;
for (int i=0;i<listOfProcess.size();i++){
TProcess process = listOfProcess.elementAt(i);
if (process instanceof TTransformation){
((TTransformation)process).reset();
}
if (process instanceof TApplyProcess){
((TApplyProcess)process).reset();
}
test = false;
for ( TProcess process: listOfProcess ) { // JE2022: reset could be applied to any...
if (process instanceof TTransformation) process.reset();
if (process instanceof TApplyProcess) process.reset();
bindPorts(process);
}
}
} //end class
}
......@@ -159,8 +159,8 @@ public final class TLoop extends TProcessComposite {
super(pIn, pOut, pParam);
// managers creation.
managers = new LoopManagerHandler[nameIn.length];
for (int i = 0; i < nameIn.length; i++) {
managers[i] = new LoopManagerHandler(this);
for ( int i = 0; i < nameIn.length; i++ ) {
managers[i] = new LoopManagerHandler(this);
}
listOfProcess = new Vector<TProcess>();
iterators = new Vector<TIterator>();
......@@ -187,62 +187,64 @@ public final class TLoop extends TProcessComposite {
}
process.generatePort();
for (int i = 0; i < process.getNameOut().length; i++) {
if (process.getNameOut(i).equals("_null_")) {
String s = process.getNameOut(i);
if ( s.equals("_null_")) {
this.addChannel(new TChannel("_null_", process, null));
} else {
listOfProcessOut.put(process.getNameOut(i), process);
TProcess isSameIn = listOfProcessIn.get(process.getNameOut(i));
TProcess isBuf = listOfProcessBuf.get(process.getNameOut(i));
//System.out.println("name out "+process.getNameOut(i)+ isSameIn+" "+isBuf);
listOfProcessOut.put( s, process);
TProcess isSameIn = listOfProcessIn.get( s );
TProcess isBuf = listOfProcessBuf.get( s );
//System.out.println("name out "+s+ isSameIn+" "+isBuf);
if ((isSameIn != null)) {
//System.out.println("is same in");
this.addChannel(new TChannel(process.getNameOut(i), process, isSameIn));
listOfProcessIn.remove(process.getNameOut(i));
listOfProcessOut.remove(process.getNameOut(i));
this.addChannel(new TChannel( s, process, isSameIn ));
listOfProcessIn.remove( s );
listOfProcessOut.remove( s );
} else {// may be a composite port or feedback
for (int i1 = 0; i1 < iListLocalOut.length; i1++) {
if ((process.getNameOut(i).equals(iListLocalOut[i1])) && (isBuf != null)) {
if ((s.equals(iListLocalOut[i1])) && (isBuf != null)) {
//creates feedback
//System.out.println("is feedback");
int position = 0;
for (int j = 0; j < nameBuf.length; j++) {
if (nameBuf[j].equals(process.getNameOut(i))) {
if (nameBuf[j].equals( s )) {
position = j;
}
}
XML_Port port1 = new XML_Port(process.getNameOut(i), this, managers[position].buffer, position, XML_Port.IN);
XML_Port port1 = new XML_Port( s, this, managers[position].buffer, position, XML_Port.IN );
try {
XML_Port.link(process.getOut(i), port1);
listOfProcessOut.remove(process.getNameOut(i));
XML_Port.link(process.getOut(i), port1);
listOfProcessOut.remove(i);
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
XML_Port port2 = new XML_Port(process.getNameOut(i), this, this, position, XML_Port.OUT);
XML_Port port2 = new XML_Port( s, this, this, position, XML_Port.OUT );
//System.out.println("test out "+port2.getName());
iListOut[position] = port2;
} //end if
else if (process.getNameOut(i).equals(iListLocalOut[i1])) {
else if ( s.equals(iListLocalOut[i1]) ) {
//composite port
//System.out.println("is composite");
iListOut[i1] = process.getOut(i);
}
}//end for
}//end if
}//end if
}//end for
}
}
}
}
for (int i = 0; i < process.getNameIn().length; i++) {
listOfProcessIn.put(process.getNameIn(i), process);
TProcess isSameOut = listOfProcessOut.get(process.getNameIn(i));
TProcess isBuf = listOfProcessBuf.get(process.getNameIn(i));
//System.out.println("name in "+process.getNameIn(i));
String s = process.getNameIn(i);
listOfProcessIn.put( s, process);
TProcess isSameOut = listOfProcessOut.get( s);
TProcess isBuf = listOfProcessBuf.get( s);
//System.out.println("name in "+ s);
if ((isSameOut != null)||(isBuf != null)) {
if (isBuf == null) {
this.addChannel(new TChannel(process.getNameIn(i), isSameOut, process));
listOfProcessIn.remove(process.getNameIn(i));
listOfProcessOut.remove(process.getNameIn(i));
this.addChannel(new TChannel( s, isSameOut, process));
listOfProcessIn.remove( s);
listOfProcessOut.remove( s);
// System.out.println("is same in");
} else {
......@@ -250,44 +252,44 @@ public final class TLoop extends TProcessComposite {
//creates feedback
int position = 0;
for (int j = 0; j < nameBuf.length; j++) {
if (nameBuf[j].equals(process.getNameIn(i))) {
if (nameBuf[j].equals( s)) {
position = j;
}
}
// System.out.println("is feedback");
//System.out.println("Position in " + position);
XML_Port port1 = new XML_Port(process.getNameIn(i), this, managers[position].buffer, position, XML_Port.IN);
XML_Port port1 = new XML_Port( s, this, managers[position].buffer, position, XML_Port.IN);
XML_Port port2;
try {
if(isSameOut!=null)
XML_Port.link(isSameOut.getOut(i), port1);
//listOfProcessBuf.remove(process.getNameIn(i));
//listOfProcessBuf.remove( s);
if (isFirstLoop) {
port2 = new XML_Port(process.getNameIn(i), this, this, position, XML_Port.OUT);
port2 = new XML_Port( s, this, this, position, XML_Port.OUT);
XML_Port.link(port2, process.getIn(i));
// System.out.println("test in "+port2.getName());
}
listOfProcessIn.remove(process.getNameIn(i));
listOfProcessIn.remove( s);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {// may be a composite port
for (int i1 = 0; i1 < iListLocalIn.length; i1++) {
if (process.getNameIn(i).equals(iListLocalIn[i1])) {
if ( s.equals(iListLocalIn[i1])) {
// System.out.println("is composite");
managers[i1].loopHandler.setInnerHandler((ContentHandler)process.getIn(i).getContent());
XML_Port port = new XML_Port(process.getNameIn(i), this, managers[i1], i1, XML_Port.IN);
XML_Port port = new XML_Port( s, this, managers[i1], i1, XML_Port.IN);
iListIn[i1] = port;
}//end if
}// end for
}//end if
}// end for
}
}
}
}
}
/**
......@@ -308,17 +310,17 @@ public final class TLoop extends TProcessComposite {
String name = locIn[i];
iListIn[i] = new XML_Port(name, this, i, XML_Port.IN);
listOfProcessIn.put(name, this);
}//end for
}
for (int i = 0; i < nameOut.length; i++) {
String name = locOut[i];
iListOut[i] = new XML_Port(name, this, i, XML_Port.OUT);
listOfProcessOut.put(name, this);
}//end for
}
for (int i = 0; i < nameBuf.length; i++) {
String name = locBuf[i];
iListBuf[i] = new XML_Port(name, this, managers[i], i, XML_Port.IN);
listOfProcessBuf.put(name, this);
}//end for
}
}
......@@ -327,7 +329,7 @@ public final class TLoop extends TProcessComposite {
* been generated before.
*/
public void generatePort() {
}//end proc
}
/**
* Initializes all inner processes for a new loop. Due to a xalan bug,
......@@ -341,12 +343,11 @@ public final class TLoop extends TProcessComposite {
public void reset() throws TMRuntimeException, TMException, SAXException {
listOfChannel = new Hashtable<String,TChannel>();
isFirstLoop = false;
for (int i = 0; i < listOfProcess.size(); i++) {
TProcess process = listOfProcess.elementAt(i);
for ( TProcess process: listOfProcess ) {
process.reset();
bindPorts(process);
}//end for
}//end reset
}
}
/**
* Sets one of the output handler of this loop with the content handler of
......@@ -369,8 +370,8 @@ public final class TLoop extends TProcessComposite {
//System.out.println("ADDED ITERATOR "+iterator);
iterators.add(iterator);
if (iterator.getType().equals("fixpoint")) {
for (int i = 0; i < managers.length; i++) {
managers[i].setTestHandler();
for ( LoopManagerHandler lmh: managers ) {
lmh.setTestHandler();
}
}
}
......@@ -423,36 +424,30 @@ public final class TLoop extends TProcessComposite {
if (isReady()) {
//all loop have called this method and are ready to start a new loop. Now ,It's time to test iterators values
for (int i = 0; i < iterators.size(); i++) {
TIterator iterator = iterators.elementAt(i);
if (!(iterator.hasMoreElements())) {
stop = true;
}
else {
if (!(iterator.getType().equals("fixpoint"))) {
if (iterator.getType().equals("file")) {
fileName = (String)iterator.nextElement();
}
else {
iteratorParameters.setParameter(iterator.getName(), iterator.nextElement());
}
}
else {
iterator.nextElement();
}
}
for ( TIterator iterator: iterators ) {
if (!(iterator.hasMoreElements())) {
stop = true;
} else if (!(iterator.getType().equals("fixpoint"))) {
if (iterator.getType().equals("file")) {
fileName = (String)iterator.nextElement();
} else {
iteratorParameters.setParameter(iterator.getName(), iterator.nextElement());
}
} else {
iterator.nextElement();
}
// testing difference between last input and output. If no difference, stop loop.
}
// testing difference between last input and output. If no difference, stop loop.
int counter = 0;
for (int i = 0; i < managers.length; i++) {
if (managers[i].loopHandler instanceof TestHandler) {
if (!(((TestHandler)managers[i].loopHandler).isDiff())) {
counter++;
}
if (counter == managers.length) {
stop = true;
}
for ( LoopManagerHandler lmh: managers ) {
if (lmh.loopHandler instanceof TestHandler) {
if ( !(((TestHandler)lmh.loopHandler).isDiff()) ) {
counter++;
}
if (counter == managers.length) {
stop = true;
}
}
}
if (!stop) {// each managers starts a new loop
loopCounter++;
......@@ -460,43 +455,40 @@ public final class TLoop extends TProcessComposite {
if (loopCounter != 1) {
this.reset();
}
for (int j = 0; j < listOfProcess.size(); j++) {
TProcess process = listOfProcess.get(j);
process.setParameters(iListOfParameters);
for (int i = 0; i < iterators.size(); i++) {
TIterator iterator = iterators.elementAt(i);
String n = fileName;
// System.out.println("SERIALIZER :"+n);
if (iterator.getType().equals("file")) {
if (!(process instanceof TReader))
process.setParameter(iterator.getName(), n.substring(fileName.lastIndexOf('/') + 1));
else
process.setParameter("file", fileName);
} else if (!(iterator.getType().equals("fixpoint"))) {
process.setParameters(iteratorParameters);
}
}
if (process instanceof TProcessBasic) {
((TProcessBasic)process).initParameters();
}
for ( TProcess process: listOfProcess ) {
process.setParameters(iListOfParameters);
for ( TIterator iterator: iterators ) {
String n = fileName;
// System.out.println("SERIALIZER :"+n);
if (iterator.getType().equals("file")) {
if (!(process instanceof TReader))
process.setParameter(iterator.getName(), n.substring(fileName.lastIndexOf('/') + 1));
else
process.setParameter("file", fileName);
} else if (!(iterator.getType().equals("fixpoint"))) {
process.setParameters(iteratorParameters);
}
}
if (process instanceof TProcessBasic) {
((TProcessBasic)process).initParameters();
}
}
for (int i = 0; i < managers.length; i++) {
//System.out.println("NEW LOOP " + loopCounter);
managers[i].loopHandler.newLoop();
for ( LoopManagerHandler lmh: managers ) {
//System.out.println("NEW LOOP " + loopCounter);
lmh.loopHandler.newLoop();
}
for (int i = 0; i < listOfGenerator.size(); i++) {
//System.out.println("GENERATOR :"+fileName);
((TReader)listOfGenerator.get(i)).execProcess();
for ( TProcess proc: listOfGenerator ) {
//System.out.println("GENERATOR :"+fileName);
((TReader)proc).execProcess();
}
for (int i = 0; i < managers.length; i++) {
//System.out.println("FLUSH BUFFER ");
managers[i].buffer.flushBuffer();
for ( LoopManagerHandler lmh: managers ) {
//System.out.println("FLUSH BUFFER ");
lmh.buffer.flushBuffer();
}
} else {// end loop
//System.out.println("END LOOP");
for (int i = 0; i < managers.length; i++) {
managers[i].loopHandler.endLoop();
for ( LoopManagerHandler lmh: managers ) {
lmh.loopHandler.endLoop();
}
}
}
......
/**
* $Id: TMain.java,v 1.2 2003-01-07 08:13:59 triolet Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
* Copyright (C) 2022 INRIA.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
* https://gitlab.inria.fr/moex/transmorpher - http://transmorpher.inrialpes.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -54,36 +53,36 @@ public class TMain extends TProcessComposite {
process.generatePort() ;
//System.out.println("debut for " + process);
for(int i=0 ; i < process.getNameOut().length ; i++) {
if(process.getNameOut(i).equals("_null_")) {
for( String s: process.getNameOut() ) {
if( s.equals("_null_") ) {
this.addChannel(new TChannel("_null_",process,null));
// else if(process.getNameOut(i).equals("_stdout_")) {
} else {
listOfProcessOut.put(process.getNameOut(i),process);
TProcess isSameIn = (TProcess)listOfProcessIn.get(process.getNameOut(i));
if(isSameIn!=null){
this.addChannel(new TChannel(process.getNameOut(i),process,isSameIn));
listOfProcessIn.remove(process.getNameOut(i));
listOfProcessOut.remove(process.getNameOut(i));
}//end if
} //end if
}//end for
listOfProcessOut.put( s, process );
TProcess isSameIn = (TProcess)listOfProcessIn.get( s );
if( isSameIn != null ){
this.addChannel(new TChannel( s, process, isSameIn));
listOfProcessIn.remove( s );
listOfProcessOut.remove( s );
}
}
}
//System.out.println("fin for");
for(int i=0 ; i < process.getNameIn().length ; i++) {
for( String s: process.getNameIn() ) {
//if(process.getNameOut(i).equals("_stdin_")) {
//} else {
//System.out.println(process.getNameIn(i).getCompositeName());
listOfProcessIn.put(process.getNameIn(i),process);
TProcess isSameOut =(TProcess)listOfProcessOut.get(process.getNameIn(i));
listOfProcessIn.put( s, process );
TProcess isSameOut =(TProcess)listOfProcessOut.get( s );
if(isSameOut!=null){
this.addChannel(new TChannel(process.getNameIn(i),isSameOut,process));
listOfProcessIn.remove(process.getNameIn(i));
listOfProcessOut.remove(process.getNameIn(i));
} //end if
//} // end if
this.addChannel(new TChannel( s, isSameOut, process ));
listOfProcessIn.remove( s );
listOfProcessOut.remove( s );
}
//}
} //end for
}
//System.out.println("fin");
}
}
......@@ -37,7 +37,7 @@ import java.io.IOException;
import org.xml.sax.SAXException;
public abstract class TProcessBasic extends TProcess_Impl implements Runnable{
public abstract class TProcessBasic extends TProcess_Impl implements Runnable {
/** the name of the father */
//protected String nameFather = null ; <= move to process
......
......@@ -72,8 +72,8 @@ public class TProcessComponent extends TProcessComposite {
this.addChannel(new TChannel(process.getNameOut(i),vSameIn,process));
listOfProcessIn.remove(process.getNameOut(i));
listOfProcessOut.remove(process.getNameOut(i));
} //end if
}//end for
}
}
for(int i=0 ; i < process.getNameIn().length ; i++) {
//System.out.println("out : "+process.getNameIn(i));
......@@ -83,8 +83,8 @@ public class TProcessComponent extends TProcessComposite {
this.addChannel(new TChannel(process.getNameIn(i),process,vSameOut));
listOfProcessIn.remove(process.getNameIn(i));
listOfProcessOut.remove(process.getNameIn(i));
} //end if
} //end for
}
}
}
public int getNumber(){
......
......@@ -65,7 +65,7 @@ public abstract class TProcessComposite extends TProcess_Impl {
protected Hashtable<String,TChannel> listOfChannel = null;
/** the list of the Generator of our transmorpher. May contain no element.*/
protected Vector<TProcess> listOfGenerator = null;
protected Vector<TReader> listOfGenerator = null;
/** the list of PortProcess In */
protected Hashtable<String,TProcess> listOfProcessIn = null;
......@@ -86,13 +86,12 @@ public abstract class TProcessComposite extends TProcess_Impl {
setParameters( p );
listOfProcessBasic = new Vector<TProcess>(NB_PROCESS_RISE*5);
listOfChannel = new Hashtable<String,TChannel>(NB_PROCESS_RISE*5);
listOfGenerator = new Vector<TProcess>(NB_PROCESS_RISE*5);
listOfGenerator = new Vector<TReader>(NB_PROCESS_RISE*5);
listOfProcessIn = new Hashtable<String,TProcess>(NB_PROCESS_RISE*5);
listOfProcessOut = new Hashtable<String,TProcess>(NB_PROCESS_RISE*5);
listOfApplyProcess = new Vector<TProcess>(NB_PROCESS_RISE*5);
}