text
stringlengths
30
1.67M
<s> package gov . nasa . daveml . dave2sl ; </s>
<s> package gov . nasa . daveml . dave2sl ; import gov . nasa . daveml . dave . * ; import java . io . IOException ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Iterator ; public class MatFileWriter extends FileWriter { int caseNumberCount ; String modelName ; SLDiagram diagram ; ArrayList < String > missingOutputs ; public MatFileWriter ( SLDiagram diagram , String fileName ) throws IOException { super ( fileName ) ; this . diagram = diagram ; this . caseNumberCount = <NUM_LIT:0> ; } public void writeln ( String cbuf ) throws IOException { super . write ( cbuf + "<STR_LIT:n>" ) ; } public void writeDataHeader ( String modelName ) throws IOException { this . modelName = modelName ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; } public void writeDataFooter ( ) throws IOException { } public void writeVerifyScriptHeader ( String modelName ) { this . modelName = modelName ; try { this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; } } public void writeVerifyScriptFooter ( ) { try { this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT:;>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; } } public void writeCheckCaseFromStaticShot ( StaticShot ss ) { Iterator < VectorInfo > it ; Iterator < String > nameit ; boolean found ; VectorInfo vi = null ; VectorInfoArrayList inputs = ss . getInputs ( ) ; VectorInfoArrayList outputs = ss . getOutputs ( ) ; ArrayList < String > modelInputNames = this . diagram . getInputNames ( ) ; ArrayList < String > modelOutputNames = this . diagram . getOutputNames ( ) ; String caseName = ss . getName ( ) ; try { this . caseNumberCount ++ ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT:U+0020-U+0020>" + caseName ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT>" + caseName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT>" ) ; nameit = modelInputNames . iterator ( ) ; while ( nameit . hasNext ( ) ) { String name = nameit . next ( ) ; found = false ; it = inputs . iterator ( ) ; while ( it . hasNext ( ) ) { vi = it . next ( ) ; String equivMDLname = MDLNameList . convertToMDLString ( vi . getName ( ) ) ; if ( name . equals ( equivMDLname ) ) { found = true ; this . writeln ( vi . getValue ( ) + "<STR_LIT>" + vi . getName ( ) ) ; } } if ( ! found ) { System . err . println ( "<STR_LIT>" + name + "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; } } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; nameit = modelOutputNames . iterator ( ) ; VectorInfoArrayList outputInfo = new VectorInfoArrayList ( modelOutputNames . size ( ) ) ; while ( nameit . hasNext ( ) ) { String name = nameit . next ( ) ; found = false ; it = outputs . iterator ( ) ; while ( it . hasNext ( ) ) { vi = it . next ( ) ; String equivMDLname = MDLNameList . convertToMDLString ( vi . getName ( ) ) ; if ( name . equals ( equivMDLname ) ) { found = true ; outputInfo . add ( vi ) ; } } if ( ! found ) { vi = new VectorInfo ( name , "<STR_LIT>" , null , false ) ; vi . setTolerance ( Double . POSITIVE_INFINITY ) ; outputInfo . add ( vi ) ; if ( this . missingOutputs == null ) { this . missingOutputs = new ArrayList < String > ( <NUM_LIT:10> ) ; } if ( ! this . missingOutputs . contains ( name ) ) { System . err . println ( "<STR_LIT>" + name + "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; this . missingOutputs . add ( name ) ; } } } this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT>" ) ; it = outputInfo . iterator ( ) ; while ( it . hasNext ( ) ) { vi = it . next ( ) ; if ( vi . getTolerance ( ) != Double . POSITIVE_INFINITY ) { this . writeln ( vi . getValue ( ) + "<STR_LIT>" + vi . getName ( ) ) ; } else { this . writeln ( <NUM_LIT:0> + "<STR_LIT>" + vi . getName ( ) + "<STR_LIT>" ) ; } } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + this . caseNumberCount + "<STR_LIT>" ) ; it = outputInfo . iterator ( ) ; while ( it . hasNext ( ) ) { vi = it . next ( ) ; if ( vi . getTolerance ( ) != Double . POSITIVE_INFINITY ) { this . writeln ( vi . getTolerance ( ) + "<STR_LIT>" + vi . getName ( ) ) ; } else { this . writeln ( "<STR_LIT>" + vi . getName ( ) + "<STR_LIT>" ) ; } } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; } } public void writeMatrix ( String arrayName , ArrayList < Double > table , int [ ] dims ) throws IOException { this . writeMatrix ( arrayName , table , dims , <NUM_LIT:0> , "<STR_LIT>" ) ; } private int writeMatrix ( String arrayName , ArrayList < Double > table , int [ ] dims , int startIndex , String higherDims ) throws IOException { int offset ; int i , j ; switch ( dims . length ) { case <NUM_LIT:0> : return <NUM_LIT:0> ; case <NUM_LIT:1> : if ( higherDims . length ( ) == <NUM_LIT:0> ) this . write ( arrayName + "<STR_LIT>" ) ; for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { Double theValue = table . get ( i + startIndex ) ; this . write ( theValue . toString ( ) ) ; if ( i < dims [ <NUM_LIT:0> ] - <NUM_LIT:1> ) this . write ( "<STR_LIT:U+002CU+0020>" ) ; } if ( higherDims . length ( ) == <NUM_LIT:0> ) this . write ( "<STR_LIT>" ) ; return i ; case <NUM_LIT:2> : if ( higherDims . length ( ) == <NUM_LIT:0> ) this . write ( arrayName + "<STR_LIT>" ) ; else this . write ( arrayName + "<STR_LIT>" + higherDims + "<STR_LIT>" ) ; for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { int [ ] newDims = new int [ <NUM_LIT:1> ] ; newDims [ <NUM_LIT:0> ] = dims [ <NUM_LIT:1> ] ; offset = writeMatrix ( arrayName , table , newDims , startIndex , "<STR_LIT:U+0020>" ) ; if ( i < dims [ <NUM_LIT:0> ] - <NUM_LIT:1> ) this . write ( "<STR_LIT>" ) ; startIndex = startIndex + offset ; } this . write ( "<STR_LIT>" ) ; return startIndex ; case <NUM_LIT:3> : for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { int [ ] newDims = new int [ <NUM_LIT:2> ] ; newDims [ <NUM_LIT:0> ] = dims [ <NUM_LIT:1> ] ; newDims [ <NUM_LIT:1> ] = dims [ <NUM_LIT:2> ] ; String hDims = new String ( "<STR_LIT:U+002C>" + ( i + <NUM_LIT:1> ) + higherDims + "<STR_LIT:)>" ) ; offset = writeMatrix ( arrayName , table , newDims , startIndex , hDims ) ; startIndex = offset ; } return startIndex ; default : for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { int [ ] newDims = new int [ dims . length - <NUM_LIT:1> ] ; for ( j = <NUM_LIT:0> ; j < ( dims . length - <NUM_LIT:1> ) ; j ++ ) newDims [ j ] = dims [ j + <NUM_LIT:1> ] ; String hDims = new String ( "<STR_LIT:U+002C>" + ( i + <NUM_LIT:1> ) + higherDims ) ; offset = writeMatrix ( arrayName , table , newDims , startIndex , hDims ) ; startIndex = offset ; } return startIndex ; } } } </s>
<s> package gov . nasa . daveml . dave2sl ; import java . io . IOException ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Date ; import java . util . Iterator ; import java . text . SimpleDateFormat ; public class SLFileWriter extends FileWriter { int indent ; SLDiagram diagram ; String subsysName ; int subsysHeight ; int gridSpacing = <NUM_LIT:5> ; int subsysTopLine = <NUM_LIT> ; int greaterNumPortSpacing = <NUM_LIT:30> ; int lesserNumPortSpacing = <NUM_LIT:30> ; int greaterNumPortVertOffset ; int lesserNumPortVertOffset ; int subsysVertCL = <NUM_LIT> ; int subsysWidth = <NUM_LIT> ; int subsysPad = <NUM_LIT> ; public SLFileWriter ( SLDiagram theDiagram , String fileName ) throws IOException { super ( fileName ) ; this . diagram = theDiagram ; this . indent = <NUM_LIT:0> ; this . subsysName = "<STR_LIT:unknown>" ; } public void writeln ( String cbuf ) throws IOException { int i ; for ( i = <NUM_LIT:0> ; i < this . indent ; i ++ ) super . write ( "<STR_LIT:U+0020>" ) ; super . write ( cbuf + "<STR_LIT:n>" ) ; } public void addBlock ( String protoPath , String blockName , String paramString ) throws IOException { String cmdline = "<STR_LIT>" + protoPath + "<STR_LIT>" + this . subsysName + "<STR_LIT:/>" + blockName + "<STR_LIT:'>" ; if ( paramString . length ( ) > <NUM_LIT:0> ) cmdline = cmdline + "<STR_LIT:U+002C>" + paramString ; cmdline = cmdline + "<STR_LIT>" ; this . writeln ( cmdline ) ; } public void addBuiltInBlock ( String builtInType , String blockName , String paramString ) throws IOException { String protoType = "<STR_LIT>" + builtInType ; this . addBlock ( protoType , blockName , paramString ) ; } public void setParam ( String blockName , String paramName , String paramValue ) throws IOException { this . writeln ( "<STR_LIT>" + this . subsysName + "<STR_LIT:/>" + blockName + "<STR_LIT>" + paramName + "<STR_LIT>" + paramValue + "<STR_LIT>" ) ; } public void addLine ( String fromBlock , int fromPort , String toBlock , int toPort , String name ) throws IOException { String cmdline = "<STR_LIT>" + this . subsysName + "<STR_LIT>" + fromBlock + "<STR_LIT:/>" + fromPort + "<STR_LIT>" + toBlock + "<STR_LIT:/>" + toPort + "<STR_LIT>" ; this . writeln ( cmdline ) ; this . writeln ( "<STR_LIT>" + name + "<STR_LIT>" ) ; } public void writeSLHeader ( String modelName ) throws IOException { int lesserNumPorts ; int greaterNumPorts ; int windowVertOffset = <NUM_LIT> ; int windowHorzOffset = <NUM_LIT> ; this . subsysName = modelName + "<STR_LIT:/>" + modelName ; if ( this . diagram . getNumOutputs ( ) > this . diagram . getNumInputs ( ) ) { greaterNumPorts = this . diagram . getNumOutputs ( ) ; lesserNumPorts = this . diagram . getNumInputs ( ) ; } else { greaterNumPorts = this . diagram . getNumInputs ( ) ; lesserNumPorts = this . diagram . getNumOutputs ( ) ; } subsysHeight = greaterNumPorts * greaterNumPortSpacing ; int totalGreaterNumPortVertSpace = greaterNumPortSpacing * ( greaterNumPorts - <NUM_LIT:1> ) ; this . greaterNumPortVertOffset = ( subsysHeight - totalGreaterNumPortVertSpace ) / <NUM_LIT:2> ; lesserNumPortSpacing = this . gridSpacing * ( int ) ( Math . floor ( ( this . subsysHeight / ( ( double ) ( lesserNumPorts ) - <NUM_LIT> ) ) / ( double ) this . gridSpacing ) ) ; int totalLesserNumPortVertSpace = lesserNumPortSpacing * ( lesserNumPorts - <NUM_LIT:1> ) ; this . lesserNumPortVertOffset = ( subsysHeight - totalLesserNumPortVertSpace ) / <NUM_LIT:2> ; int topOfBox = subsysTopLine - greaterNumPortVertOffset ; int lesserNumPortFirstLineVertPos = topOfBox + this . lesserNumPortVertOffset ; float gridPos = ( float ) lesserNumPortFirstLineVertPos / ( float ) this . gridSpacing ; int intGridPos = Math . round ( gridPos ) ; this . lesserNumPortVertOffset = intGridPos * this . gridSpacing - topOfBox ; this . writeln ( "<STR_LIT:%>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT:%>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . write ( "<STR_LIT>" + modelName + "<STR_LIT:'>" ) ; if ( this . diagram . getLibFlag ( ) ) { this . writeln ( "<STR_LIT>" ) ; } else { this . writeln ( "<STR_LIT>" ) ; } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + windowHorzOffset + "<STR_LIT:U+002CU+0020>" + windowVertOffset + "<STR_LIT:U+002CU+0020>" + ( windowHorzOffset + <NUM_LIT:2> * subsysVertCL ) + "<STR_LIT:U+002CU+0020>" + ( windowVertOffset + subsysHeight + <NUM_LIT:2> * subsysPad ) + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . write ( "<STR_LIT>" + this . subsysName + "<STR_LIT:'>" ) ; this . writeln ( "<STR_LIT>" + ( subsysVertCL - subsysWidth / <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + topOfBox + "<STR_LIT:U+002CU+0020>" + ( subsysVertCL + subsysWidth / <NUM_LIT:2> ) + "<STR_LIT:U+002CU+0020>" + ( topOfBox + subsysHeight ) + "<STR_LIT>" ) ; if ( this . diagram . getEnabledFlag ( ) ) { this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . write ( "<STR_LIT>" + this . subsysName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . indent = <NUM_LIT:4> ; } public void writeSLFooter ( String version , String modelName ) throws IOException { int count ; int topOfPort ; ArrayList < String > names ; String name ; Iterator < String > it ; int vertSpace ; int portWidth = <NUM_LIT:30> ; int portHeight = <NUM_LIT> ; int extraPad = <NUM_LIT> ; int inportX = this . subsysVertCL - ( this . subsysWidth / <NUM_LIT:2> + subsysPad + portWidth + extraPad ) ; int outportX = this . subsysVertCL + ( this . subsysWidth / <NUM_LIT:2> + subsysPad + extraPad ) ; SimpleDateFormat timeStamp = new SimpleDateFormat ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; names = this . diagram . getOutputNames ( ) ; it = names . iterator ( ) ; count = <NUM_LIT:0> ; while ( it . hasNext ( ) ) { count ++ ; name = it . next ( ) ; this . writeln ( "<STR_LIT>" + this . subsysName + "<STR_LIT:/>" + name + "<STR_LIT>" + count + "<STR_LIT>" ) ; } this . indent = <NUM_LIT:0> ; if ( ! this . diagram . getLibFlag ( ) ) { this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; if ( this . diagram . getNumOutputs ( ) < this . diagram . getNumInputs ( ) ) { vertSpace = this . greaterNumPortSpacing ; topOfPort = subsysTopLine - portHeight / <NUM_LIT:2> ; } else { vertSpace = this . lesserNumPortSpacing ; topOfPort = subsysTopLine - portHeight / <NUM_LIT:2> + lesserNumPortVertOffset - greaterNumPortVertOffset ; } count = <NUM_LIT:0> ; names = this . diagram . getInputNames ( ) ; it = names . iterator ( ) ; while ( it . hasNext ( ) ) { count ++ ; name = it . next ( ) ; this . write ( "<STR_LIT>" + modelName + "<STR_LIT:/>" + name + "<STR_LIT>" ) ; this . writeln ( inportX + "<STR_LIT:U+002CU+0020>" + topOfPort + "<STR_LIT:U+002CU+0020>" + ( inportX + portWidth ) + "<STR_LIT:U+002CU+0020>" + ( topOfPort + portHeight ) + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + name + "<STR_LIT>" + modelName + "<STR_LIT:/>" + count + "<STR_LIT>" ) ; topOfPort = topOfPort + vertSpace ; } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; if ( this . diagram . getNumOutputs ( ) > this . diagram . getNumInputs ( ) ) { vertSpace = this . greaterNumPortSpacing ; topOfPort = subsysTopLine - portHeight / <NUM_LIT:2> ; } else { vertSpace = this . lesserNumPortSpacing ; topOfPort = subsysTopLine - portHeight / <NUM_LIT:2> + lesserNumPortVertOffset - greaterNumPortVertOffset ; } count = <NUM_LIT:0> ; names = this . diagram . getOutputNames ( ) ; it = names . iterator ( ) ; while ( it . hasNext ( ) ) { count ++ ; name = it . next ( ) ; this . write ( "<STR_LIT>" + modelName + "<STR_LIT:/>" + name + "<STR_LIT>" ) ; this . writeln ( outportX + "<STR_LIT:U+002CU+0020>" + topOfPort + "<STR_LIT:U+002CU+0020>" + ( outportX + portWidth ) + "<STR_LIT:U+002CU+0020>" + ( topOfPort + portHeight ) + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + modelName + "<STR_LIT:/>" + count + "<STR_LIT>" + name + "<STR_LIT>" ) ; topOfPort = topOfPort + vertSpace ; } } this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + version + "<STR_LIT>" + subsysVertCL + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + modelName + "<STR_LIT>" ) ; this . writeln ( "<STR_LIT>" + version ) ; this . writeln ( "<STR_LIT>" + timeStamp . format ( new Date ( ) ) + "<STR_LIT:.>" ) ; } } </s>
<s> package gov . nasa . daveml . dave2sl ; import gov . nasa . daveml . dave . * ; import java . io . File ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Iterator ; public class DAVE2SL extends DAVE { String mdlFileName ; String matFileName ; SLDiagram myDiagram ; boolean warnRunTimeFlag ; boolean makeLib ; boolean makeEnabledSubSys ; public DAVE2SL ( ) { super ( ) ; this . warnRunTimeFlag = false ; this . makeLib = false ; this . makeEnabledSubSys = false ; } public DAVE2SL ( String [ ] args ) { this ( ) ; this . parseOptions ( args ) ; if ( this . isVerbose ( ) ) { this . getModel ( ) . makeVerbose ( ) ; } } public boolean makeLib ( ) { return this . makeLib ; } @ Override public void setInputFileName ( String fn ) { super . setInputFileName ( fn ) ; this . mdlFileName = this . getStubName ( ) + "<STR_LIT>" ; this . matFileName = this . getStubName ( ) + "<STR_LIT>" ; } private void parseOptions ( String inArgs [ ] ) { String exampleUse = "<STR_LIT>" ; int numArgs = inArgs . length ; this . setArgs ( inArgs ) ; if ( numArgs > <NUM_LIT:0> ) { int parsedArgs = <NUM_LIT:0> ; if ( this . matchOptionArgs ( "<STR_LIT:c>" , "<STR_LIT:count>" ) ) { this . setGenStatsFlag ( ) ; parsedArgs ++ ; } if ( this . matchOptionArgs ( "<STR_LIT:d>" , "<STR_LIT>" ) ) { this . makeVerbose ( ) ; parsedArgs ++ ; } if ( this . matchOptionArgs ( "<STR_LIT>" , "<STR_LIT>" ) ) { this . warnRunTimeFlag = true ; parsedArgs ++ ; } if ( this . matchOptionArgs ( "<STR_LIT>" , "<STR_LIT>" ) ) { this . makeLib = true ; parsedArgs ++ ; } if ( this . matchOptionArgs ( "<STR_LIT:e>" , "<STR_LIT>" ) ) { this . makeEnabledSubSys = true ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT>" , "<STR_LIT:version>" ) ) { System . out . println ( "<STR_LIT>" + getVersion ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } if ( parsedArgs < ( numArgs - <NUM_LIT:1> ) ) { if ( numArgs == <NUM_LIT:2> ) { System . err . println ( "<STR_LIT>" + getArgs ( ) [ <NUM_LIT:2> ] + "<STR_LIT>" ) ; } else { System . err . println ( "<STR_LIT>" + ( numArgs - <NUM_LIT:1> ) + "<STR_LIT>" ) ; } System . err . println ( exampleUse ) ; System . exit ( <NUM_LIT:0> ) ; } } else { System . out . println ( exampleUse ) ; System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . setInputFileName ( inArgs [ numArgs - <NUM_LIT:1> ] ) ; } public void createModel ( ) throws IOException { this . myDiagram = new SLDiagram ( this . getModel ( ) ) ; if ( this . warnRunTimeFlag ) { this . myDiagram . setWarnOnClip ( ) ; } if ( this . makeLib ) { this . myDiagram . setLibFlag ( ) ; } if ( this . makeEnabledSubSys ) { this . myDiagram . setEnabledFlag ( ) ; } File file = new File ( this . getStubName ( ) ) ; String modelName = file . getName ( ) ; SLFileWriter mdlWriter = new SLFileWriter ( this . myDiagram , this . mdlFileName ) ; MatFileWriter matWriter = new MatFileWriter ( this . myDiagram , this . matFileName ) ; mdlWriter . writeSLHeader ( modelName ) ; matWriter . writeDataHeader ( modelName ) ; this . myDiagram . createModel ( mdlWriter , matWriter ) ; mdlWriter . writeSLFooter ( this . getVersion ( ) , modelName ) ; matWriter . writeDataFooter ( ) ; mdlWriter . close ( ) ; matWriter . close ( ) ; } public void createVerifyScript ( ) { MatFileWriter scriptWriter ; String modelName = this . getModel ( ) . getName ( ) ; String scriptFileName = modelName + "<STR_LIT>" ; try { scriptWriter = new MatFileWriter ( this . myDiagram , scriptFileName ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; return ; } scriptWriter . writeVerifyScriptHeader ( modelName ) ; CheckData cd = this . getCheckcaseData ( ) ; ArrayList < StaticShot > al = cd . getStaticShots ( ) ; Iterator < StaticShot > it = al . iterator ( ) ; while ( it . hasNext ( ) ) { StaticShot ss = it . next ( ) ; scriptWriter . writeCheckCaseFromStaticShot ( ss ) ; } scriptWriter . writeVerifyScriptFooter ( ) ; try { scriptWriter . close ( ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; } } public static void main ( String args [ ] ) { boolean success = false ; DAVE2SL dave2sl = new DAVE2SL ( args ) ; try { System . out . println ( "<STR_LIT>" ) ; success = dave2sl . parseFile ( ) ; } catch ( Exception e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } System . out . println ( "<STR_LIT>" ) ; try { if ( dave2sl . hasCheckcases ( ) ) { System . out . println ( "<STR_LIT>" ) ; if ( ! dave2sl . verify ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } } } catch ( NoSuchMethodError e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } try { if ( dave2sl . getGenStatsFlag ( ) ) { dave2sl . reportStats ( ) ; } } catch ( NoSuchMethodError e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } System . out . println ( "<STR_LIT>" ) ; try { dave2sl . createModel ( ) ; } catch ( IOException e ) { return ; } if ( dave2sl . makeLib ( ) ) { System . out . println ( "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" ) ; } if ( dave2sl . hasCheckcases ( ) ) { System . out . println ( "<STR_LIT>" ) ; dave2sl . createVerifyScript ( ) ; System . out . println ( "<STR_LIT>" ) ; } System . out . println ( "<STR_LIT>" + dave2sl . getStubName ( ) + "<STR_LIT:.>" ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . util . ArrayList ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class FuncTableTest extends TestCase { protected Model _model ; protected Element _gtd ; protected FuncTable _gft ; protected BreakpointSet _bpAlpha1 ; protected BreakpointSet _bpDe1 ; protected final Double EPS = <NUM_LIT> ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _bpAlpha1 = BreakpointSetTest . generateSampleAlphaBreakpointSet ( _model ) ; _bpDe1 = BreakpointSetTest . generateSampleElevBreakpointSet ( _model ) ; _gtd = generateSampleGriddedTableDefDOM ( ) ; _gft = new FuncTable ( _gtd , _model ) ; } public void testFuncTableModel ( ) { FuncTable ft = new FuncTable ( _model ) ; assertNotNull ( ft ) ; assertEquals ( <NUM_LIT:0> , ft . numDim ( ) ) ; assertEquals ( "<STR_LIT>" , ft . getName ( ) ) ; assertEquals ( <NUM_LIT:0> , ft . size ( ) ) ; } public void testFuncTableStringElementModel ( ) { FuncTable ft = null ; assertNotNull ( _gtd ) ; try { ft = new FuncTable ( "<STR_LIT>" , _gtd , _model ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertNotNull ( ft ) ; assertEquals ( "<STR_LIT>" , ft . getGTID ( ) ) ; } public void testFuncTableElementModel ( ) { assertNotNull ( _gft ) ; } public void testFuncTableStringStringStringStringIntModel ( ) { FuncTable ft = new FuncTable ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; assertNotNull ( ft ) ; assertEquals ( "<STR_LIT>" , ft . getGTID ( ) ) ; assertEquals ( "<STR_LIT>" , ft . getName ( ) ) ; assertEquals ( "<STR_LIT>" , ft . getDescription ( ) ) ; assertEquals ( <NUM_LIT:6> , ft . size ( ) ) ; StringWriter writer = new StringWriter ( ) ; try { ft . printTable ( new PrintWriter ( writer ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public void testRegister ( ) { } public void testMakeVerbose ( ) { assertFalse ( _gft . isVerbose ( ) ) ; _gft . makeVerbose ( ) ; assertTrue ( _gft . isVerbose ( ) ) ; _gft . silence ( ) ; assertFalse ( _gft . isVerbose ( ) ) ; } public void testAddBPID ( ) { _gft . addBPID ( <NUM_LIT:3> , "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _gft . getBPID ( <NUM_LIT:3> ) ) ; } public void testGetBPIterator ( ) { Iterator < String > bpit = _gft . getBPIterator ( ) ; assertNotNull ( bpit ) ; assertTrue ( bpit . hasNext ( ) ) ; assertEquals ( "<STR_LIT>" , bpit . next ( ) ) ; assertTrue ( bpit . hasNext ( ) ) ; assertEquals ( "<STR_LIT>" , bpit . next ( ) ) ; assertFalse ( bpit . hasNext ( ) ) ; } public void testGetBPID ( ) { assertEquals ( "<STR_LIT>" , _gft . getBPID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , _gft . getBPID ( <NUM_LIT:2> ) ) ; try { assertEquals ( "<STR_LIT>" , _gft . getBPID ( <NUM_LIT:3> ) ) ; fail ( "<STR_LIT>" ) ; } catch ( IndexOutOfBoundsException e ) { } } public void testGetName ( ) { assertEquals ( "<STR_LIT>" , _gft . getName ( ) ) ; } public void testGetGTID ( ) { assertEquals ( "<STR_LIT>" , _gft . getGTID ( ) ) ; } public void testSize ( ) { assertEquals ( <NUM_LIT> , _gft . size ( ) ) ; } public void testNumDim ( ) { assertEquals ( <NUM_LIT:2> , _gft . numDim ( ) ) ; } public void testDim ( ) { assertEquals ( <NUM_LIT:5> , _gft . dim ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:12> , _gft . dim ( <NUM_LIT:1> ) ) ; } public void testGetDimensions ( ) { int [ ] dims = _gft . getDimensions ( ) ; assertNotNull ( dims ) ; assertEquals ( <NUM_LIT:2> , dims . length ) ; assertEquals ( <NUM_LIT:5> , dims [ <NUM_LIT:0> ] ) ; assertEquals ( <NUM_LIT:12> , dims [ <NUM_LIT:1> ] ) ; } public void testGetValues ( ) { ArrayList < Double > vals = _gft . getValues ( ) ; assertNotNull ( vals ) ; assertEquals ( <NUM_LIT> , vals . size ( ) ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:0> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:11> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT> ) , EPS ) ; assertEquals ( - <NUM_LIT> , vals . get ( <NUM_LIT> ) , EPS ) ; assertEquals ( - <NUM_LIT> , vals . get ( <NUM_LIT> ) , EPS ) ; try { vals . get ( - <NUM_LIT:1> ) ; fail ( "<STR_LIT>" ) ; } catch ( IndexOutOfBoundsException e ) { } try { vals . get ( <NUM_LIT> ) ; fail ( "<STR_LIT>" ) ; } catch ( IndexOutOfBoundsException e ) { } } public void testPrintTableWriter ( ) { int expectedLines = <NUM_LIT:5> ; int expectedLength = <NUM_LIT> ; StringWriter writer = new StringWriter ( ) ; StringBuffer buffer ; String osName = System . getProperty ( "<STR_LIT>" ) ; assertNotNull ( writer ) ; try { _gft . printTable ( writer ) ; buffer = writer . getBuffer ( ) ; if ( osName . contains ( "<STR_LIT>" ) ) { expectedLength += expectedLines ; } assertEquals ( expectedLength , buffer . length ( ) ) ; String [ ] lines = buffer . toString ( ) . split ( System . getProperty ( "<STR_LIT>" ) ) ; assertEquals ( expectedLines , lines . length ) ; assertNotNull ( lines [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:0> ] ) ; assertNotNull ( lines [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertNotNull ( lines [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:2> ] ) ; assertNotNull ( lines [ <NUM_LIT:3> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:3> ] ) ; assertNotNull ( lines [ <NUM_LIT:4> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:4> ] ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public void testGetPt ( ) { boolean dontExpectException = false ; checkPt ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , dontExpectException ) ; checkPt ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT> , dontExpectException ) ; checkPt ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT> , dontExpectException ) ; checkPt ( <NUM_LIT:4> , <NUM_LIT:0> , - <NUM_LIT> , dontExpectException ) ; checkPt ( <NUM_LIT:4> , <NUM_LIT:11> , - <NUM_LIT> , dontExpectException ) ; boolean expectException = true ; checkPt ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:0> , expectException ) ; checkPt ( - <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , expectException ) ; checkPt ( - <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:0> , expectException ) ; checkPt ( <NUM_LIT:0> , - <NUM_LIT:1> , <NUM_LIT:0> , expectException ) ; checkPt ( <NUM_LIT:4> , <NUM_LIT:12> , <NUM_LIT:0> , expectException ) ; checkPt ( <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT:0> , expectException ) ; checkPt ( <NUM_LIT:5> , <NUM_LIT:12> , <NUM_LIT:0> , expectException ) ; } protected void checkPt ( int index1 , int index2 , double expectedValue , boolean expectException ) { double point = Double . NaN ; int [ ] indices = new int [ <NUM_LIT:2> ] ; indices [ <NUM_LIT:0> ] = index1 ; indices [ <NUM_LIT:1> ] = index2 ; try { point = _gft . getPt ( indices ) ; if ( expectException ) { fail ( "<STR_LIT>" + index1 + "<STR_LIT:U+002CU+0020>" + index2 + "<STR_LIT:]>" ) ; } else { assertEquals ( expectedValue , point , EPS ) ; } } catch ( Exception e ) { if ( expectException ) { } else { fail ( "<STR_LIT>" + index1 + "<STR_LIT:U+002CU+0020>" + index2 + "<STR_LIT>" ) ; } } } public static Element generateSampleGriddedTableDefDOM ( ) { Element dataTableElement = new Element ( "<STR_LIT>" ) ; dataTableElement . addContent ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; Element bpRef1 = new Element ( "<STR_LIT>" ) ; bpRef1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element bpRef2 = new Element ( "<STR_LIT>" ) ; bpRef2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element breakpointRefs = new Element ( "<STR_LIT>" ) ; breakpointRefs . addContent ( bpRef1 ) ; breakpointRefs . addContent ( bpRef2 ) ; Element gtd = new Element ( "<STR_LIT>" ) ; gtd . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; gtd . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; gtd . addContent ( breakpointRefs ) ; gtd . addContent ( dataTableElement ) ; return gtd ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathMinusTest extends TestCase { protected Model _model ; protected Signal _minusAlpha ; protected Signal _alphaMinusBeta ; protected Signal _alphaSignal ; protected Signal _betaSignal ; protected BlockMathMinus _unaryMinusBlock ; protected BlockMathMinus _binaryMinusBlock ; protected BlockMathConstant _constantBetaBlock ; protected BlockMathConstant _constantAlphaBlock ; @ Override protected void setUp ( ) { _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _minusAlpha = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , _model ) ; Element alphaEl = new Element ( "<STR_LIT>" ) ; alphaEl . addContent ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( new Element ( "<STR_LIT>" ) ) ; applyElement . addContent ( alphaEl ) ; _unaryMinusBlock = new BlockMathMinus ( applyElement , _model ) ; _unaryMinusBlock . addConstInput ( "<STR_LIT>" , <NUM_LIT:1> ) ; _alphaSignal = _unaryMinusBlock . getInput ( <NUM_LIT:0> ) ; _constantAlphaBlock = ( BlockMathConstant ) _alphaSignal . getSource ( ) ; try { _unaryMinusBlock . addOutput ( _minusAlpha ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } _alphaMinusBeta = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , _model ) ; Element betaEl = new Element ( "<STR_LIT>" ) ; betaEl . addContent ( "<STR_LIT>" ) ; applyElement . addContent ( betaEl ) ; _binaryMinusBlock = new BlockMathMinus ( applyElement , _model ) ; _alphaSignal . addSink ( _binaryMinusBlock , <NUM_LIT:1> ) ; _binaryMinusBlock . addConstInput ( "<STR_LIT>" , <NUM_LIT:2> ) ; _betaSignal = _binaryMinusBlock . getInput ( <NUM_LIT:1> ) ; _constantBetaBlock = ( BlockMathConstant ) _betaSignal . getSource ( ) ; try { _binaryMinusBlock . addOutput ( _alphaMinusBeta ) ; } catch ( DAVEException e2 ) { fail ( "<STR_LIT>" + e2 . getMessage ( ) ) ; } _model . wireBlocks ( ) ; try { _model . initialize ( ) ; } catch ( DAVEException e3 ) { fail ( "<STR_LIT>" + e3 . getMessage ( ) ) ; } } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result1 = _unaryMinusBlock . genCode ( ) ; assertEquals ( "<STR_LIT>" , result1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result1 . getVarName ( <NUM_LIT:0> ) ) ; CodeAndVarNames result2 = _binaryMinusBlock . genCode ( ) ; assertEquals ( "<STR_LIT>" , result2 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result2 . getVarName ( <NUM_LIT:0> ) ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result1 = _unaryMinusBlock . genCode ( ) ; assertEquals ( "<STR_LIT>" , result1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result1 . getVarName ( <NUM_LIT:0> ) ) ; CodeAndVarNames result2 = _binaryMinusBlock . genCode ( ) ; assertEquals ( "<STR_LIT>" , result2 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result2 . getVarName ( <NUM_LIT:0> ) ) ; } public void testDescribeSelf ( ) { StringWriter writer = new StringWriter ( ) ; try { _unaryMinusBlock . describeSelf ( writer ) ; } catch ( IOException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , writer . toString ( ) ) ; writer = new StringWriter ( ) ; try { _binaryMinusBlock . describeSelf ( writer ) ; } catch ( IOException e2 ) { fail ( "<STR_LIT>" + e2 . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , writer . toString ( ) ) ; } public void testGetValue ( ) { assertEquals ( <NUM_LIT> , _unaryMinusBlock . getValue ( ) , <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , _binaryMinusBlock . getValue ( ) , <NUM_LIT> ) ; } public void testIsReady ( ) { assertTrue ( _unaryMinusBlock . isReady ( ) ) ; assertTrue ( _binaryMinusBlock . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _unaryMinusBlock . allInputsReady ( ) ) ; assertTrue ( _binaryMinusBlock . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( _unaryMinusBlock . isVerbose ( ) ) ; _unaryMinusBlock . makeVerbose ( ) ; assertTrue ( _unaryMinusBlock . isVerbose ( ) ) ; _unaryMinusBlock . silence ( ) ; assertFalse ( _unaryMinusBlock . isVerbose ( ) ) ; } public void testGetModels ( ) { assertEquals ( _model . getName ( ) , _unaryMinusBlock . getModel ( ) . getName ( ) ) ; assertEquals ( _model . getName ( ) , _binaryMinusBlock . getModel ( ) . getName ( ) ) ; } public void testGetSetName ( ) { assertEquals ( "<STR_LIT>" , _unaryMinusBlock . getName ( ) ) ; _unaryMinusBlock . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _unaryMinusBlock . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , _unaryMinusBlock . getType ( ) ) ; assertEquals ( "<STR_LIT>" , _binaryMinusBlock . getType ( ) ) ; } public void testGetVarID ( ) { assertEquals ( "<STR_LIT>" , _unaryMinusBlock . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , _binaryMinusBlock . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , _binaryMinusBlock . getVarID ( <NUM_LIT:2> ) ) ; } public void testGetVarIDIterator ( ) { Iterator < String > it ; String s ; it = _unaryMinusBlock . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( "<STR_LIT>" , s ) ; assertFalse ( it . hasNext ( ) ) ; it = _binaryMinusBlock . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( "<STR_LIT>" , s ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( "<STR_LIT>" , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutput ( ) { Signal s ; s = _unaryMinusBlock . getOutput ( ) ; assertEquals ( _minusAlpha , s ) ; s = _binaryMinusBlock . getOutput ( ) ; assertEquals ( _alphaMinusBeta , s ) ; } public void getGetInputIterator ( ) { Iterator < Signal > it ; Signal s ; it = _unaryMinusBlock . getInputIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _alphaSignal , s ) ; assertFalse ( it . hasNext ( ) ) ; it = _binaryMinusBlock . getInputIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _alphaSignal , s ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _betaSignal , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , _unaryMinusBlock . getOutputVarID ( ) ) ; assertEquals ( "<STR_LIT>" , _binaryMinusBlock . getOutputVarID ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:1> , _unaryMinusBlock . numInputs ( ) ) ; assertEquals ( <NUM_LIT:2> , _binaryMinusBlock . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:1> , _unaryMinusBlock . numVarIDs ( ) ) ; assertEquals ( <NUM_LIT:2> , _binaryMinusBlock . numVarIDs ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathProductTest extends TestCase { protected Model _model ; protected Signal _outputSignal ; protected Signal _value1Signal ; protected Signal _value2Signal ; protected String _value1SignalID ; protected String _value2SignalID ; protected BlockMathConstant _value1Block ; protected BlockMathConstant _value2Block ; protected BlockMathProduct _block ; private StringWriter _writer ; private final double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { String routineName = "<STR_LIT>" ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _value1Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value2Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value1SignalID = "<STR_LIT>" ; _value2SignalID = "<STR_LIT>" ; _value1Signal = new Signal ( "<STR_LIT>" , _value1SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value2Signal = new Signal ( "<STR_LIT>" , _value2SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value1Block . addOutput ( _value1Signal ) ; _value2Block . addOutput ( _value2Signal ) ; _outputSignal = new Signal ( "<STR_LIT>" , _model ) ; Element theValue1 = new Element ( "<STR_LIT>" ) ; theValue1 . addContent ( "<STR_LIT>" ) ; Element theValue2 = new Element ( "<STR_LIT>" ) ; theValue2 . addContent ( "<STR_LIT>" ) ; Element theTimesElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( theTimesElement ) ; applyElement . addContent ( theValue1 ) ; applyElement . addContent ( theValue2 ) ; _block = new BlockMathProduct ( applyElement , _model ) ; _block . addInput ( _value1Signal , <NUM_LIT:1> ) ; _block . addInput ( _value2Signal , <NUM_LIT:2> ) ; _block . addOutput ( _outputSignal ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName ) ; } } public void testGetBlockType ( ) { assertEquals ( "<STR_LIT>" , _block . getBlockType ( ) ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; _block . blockType = "<STR_LIT>" ; result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; _block . blockType = "<STR_LIT>" ; result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; _block . blockType = "<STR_LIT>" ; result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; _block . blockType = "<STR_LIT>" ; result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; } private void checkVarNames ( CodeAndVarNames result ) { assertEquals ( <NUM_LIT:3> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:2> ) ) ; } public void testDescribeSelfFileWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public void testGetValue ( ) { assertEquals ( - <NUM_LIT> , _block . getValue ( ) , EPS ) ; } public void testIsReady ( ) { assertTrue ( _block . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _block . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( _block . isVerbose ( ) ) ; _block . makeVerbose ( ) ; assertTrue ( _block . isVerbose ( ) ) ; _block . silence ( ) ; assertFalse ( _block . isVerbose ( ) ) ; } public void testGetName ( ) { assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , _block . getType ( ) ) ; } public void testGetVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , _block . getVarID ( <NUM_LIT:2> ) ) ; } public void testGetInputIterator ( ) { Signal s ; Iterator < Signal > it = _block . getInputIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _value1Signal , s ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _value2Signal , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutput ( ) { assertEquals ( _outputSignal , _block . getOutput ( ) ) ; } public void testGetVarIDIterator ( ) { String name ; Iterator < String > it = _block . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getOutputVarID ( ) ) ; } public void testSetName ( ) { _block . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:2> , _block . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:2> , _block . numVarIDs ( ) ) ; } public void testUpdate ( ) { String routineName = "<STR_LIT>" ; _value1Block . setValue ( <NUM_LIT> ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + routineName ) ; } try { _model . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName ) ; } assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import junit . framework . * ; public class BlockInputTest extends TestCase { private Signal _fs ; private BlockInput _bi ; private Model _m ; private StringWriter _writer ; protected void setUp ( ) throws Exception { _m = new Model ( <NUM_LIT:2> , <NUM_LIT:2> ) ; _fs = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , _m ) ; _bi = new BlockInput ( _fs , _m ) ; _writer = new StringWriter ( ) ; try { _m . initialize ( ) ; } catch ( DAVEException e ) { assertTrue ( false ) ; } _bi . update ( ) ; } public void testConstructor ( ) { Model m = new Model ( <NUM_LIT:1> , <NUM_LIT:1> ) ; assertTrue ( m != null ) ; Signal s = new Signal ( "<STR_LIT>" , m ) ; assertTrue ( s != null ) ; Block b = new BlockInput ( s , m ) ; assertTrue ( b != null ) ; assertEquals ( "<STR_LIT>" , b . getType ( ) ) ; assertEquals ( "<STR_LIT>" , b . getName ( ) ) ; assertEquals ( <NUM_LIT:0> , b . numInputs ( ) ) ; assertEquals ( <NUM_LIT:0> , b . numVarIDs ( ) ) ; assertTrue ( b . outputConnected ( ) ) ; assertEquals ( "<STR_LIT>" , b . getOutputVarID ( ) ) ; assertEquals ( s , b . getOutput ( ) ) ; assertEquals ( <NUM_LIT:1> , m . getNumBlocks ( ) ) ; } public void testIsReady ( ) { assertTrue ( _bi . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _bi . allInputsReady ( ) ) ; } public void testVerbosity ( ) { assertFalse ( _bi . isVerbose ( ) ) ; _bi . makeVerbose ( ) ; assertTrue ( _bi . isVerbose ( ) ) ; _bi . silence ( ) ; assertFalse ( _bi . isVerbose ( ) ) ; } public void testSetInputValue ( ) { _bi . setInputValue ( - <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , _bi . getValue ( ) , <NUM_LIT> ) ; } public void testGetUnits ( ) { assertEquals ( "<STR_LIT>" , _bi . getUnits ( ) ) ; } public void testGetSeqNumber ( ) { assertEquals ( <NUM_LIT:1> , _bi . getSeqNumber ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , _bi . getOutputVarID ( ) ) ; } public void testGenCcode ( ) { _m . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames cvn = new CodeAndVarNames ( ) ; cvn . append ( _bi . genCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; } public void testGenFcode ( ) { _m . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames cvn = new CodeAndVarNames ( ) ; cvn . append ( _bi . genCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; } public void testDescribeSelf ( ) { try { _bi . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" , _writer . toString ( ) ) ; } public static Test suite ( ) { return new TestSuite ( BlockInputTest . class ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . ByteArrayOutputStream ; import java . io . PrintStream ; import org . jdom . Element ; import junit . framework . TestCase ; public class StaticShotTest extends TestCase { protected StaticShot _ss ; protected final double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _ss = new StaticShot ( genStaticShotElement ( ) ) ; } public void testStaticShot ( ) { assertNotNull ( _ss ) ; } public void testGetName ( ) { assertEquals ( "<STR_LIT>" , _ss . getName ( ) ) ; } public void testGetInputs ( ) { VectorInfoArrayList inputs = _ss . getInputs ( ) ; assertNotNull ( inputs ) ; assertEquals ( <NUM_LIT:3> , inputs . size ( ) ) ; checkSignal ( inputs , <NUM_LIT:0> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; checkSignal ( inputs , <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> ) ; checkSignal ( inputs , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0.0> ) ; } public void testGetOutputs ( ) { VectorInfoArrayList outputs = _ss . getOutputs ( ) ; assertNotNull ( outputs ) ; assertEquals ( <NUM_LIT:3> , outputs . size ( ) ) ; checkSignal ( outputs , <NUM_LIT:0> , "<STR_LIT>" , "<STR_LIT>" , - <NUM_LIT> , <NUM_LIT> ) ; checkSignal ( outputs , <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> ) ; checkSignal ( outputs , <NUM_LIT:2> , "<STR_LIT>" , "<STR_LIT>" , - <NUM_LIT> , <NUM_LIT> ) ; } public void testLoadInputVector ( ) { VectorInfoArrayList inVec = new VectorInfoArrayList ( <NUM_LIT:3> ) ; VectorInfo airspeed = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , true ) ; airspeed . setValue ( <NUM_LIT> ) ; inVec . add ( airspeed ) ; VectorInfo alpha = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , true ) ; alpha . setValue ( <NUM_LIT> ) ; inVec . add ( alpha ) ; try { _ss . loadInputVector ( inVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" + "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } VectorInfo beta = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , true ) ; beta . setValue ( <NUM_LIT> ) ; inVec . add ( beta ) ; try { _ss . loadInputVector ( inVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } String bad_units = "<STR_LIT>" ; beta . setUnits ( bad_units ) ; try { _ss . loadInputVector ( inVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" + "<STR_LIT>" + bad_units + "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } beta . setUnits ( "<STR_LIT>" ) ; try { _ss . loadInputVector ( inVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } alpha . signalName = "<STR_LIT>" ; try { _ss . loadInputVector ( inVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } } public void testCheckOutputs ( ) { ByteArrayOutputStream myStream = new ByteArrayOutputStream ( ) ; PrintStream ps = new PrintStream ( myStream ) ; VectorInfoArrayList outVec = new VectorInfoArrayList ( <NUM_LIT:3> ) ; VectorInfo X = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; X . setValue ( - <NUM_LIT> ) ; X . setTolerance ( <NUM_LIT> ) ; outVec . add ( X ) ; VectorInfo Y = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; Y . setValue ( <NUM_LIT> ) ; Y . setTolerance ( <NUM_LIT> ) ; outVec . add ( Y ) ; try { _ss . checkOutputs ( outVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" + "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } VectorInfo Z = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; Z . setValue ( - <NUM_LIT> ) ; Z . setTolerance ( <NUM_LIT> ) ; outVec . add ( Z ) ; try { _ss . checkOutputs ( outVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } X . signalName = "<STR_LIT>" ; try { _ss . checkOutputs ( outVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } X . signalName = "<STR_LIT>" ; try { _ss . checkOutputs ( outVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } String bad_units = "<STR_LIT>" ; Z . setUnits ( bad_units ) ; try { _ss . checkOutputs ( outVec ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { String expectedMessage = "<STR_LIT>" + "<STR_LIT>" + bad_units + "<STR_LIT>" ; assertEquals ( expectedMessage , e . getMessage ( ) ) ; } Z . setUnits ( "<STR_LIT>" ) ; try { _ss . checkOutputs ( outVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } double tol = Y . getTolerance ( ) ; double nomval = Y . getValue ( ) ; Y . setValue ( nomval + <NUM_LIT> * tol ) ; try { _ss . checkOutputs ( outVec ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } Y . setValue ( nomval + <NUM_LIT> * tol ) ; try { _ss . checkOutputs ( outVec , ps ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } String errMsg ; String expectedMsg ; errMsg = myStream . toString ( ) ; String newline = System . getProperty ( "<STR_LIT>" ) ; expectedMsg = newline + "<STR_LIT>" + newline + "<STR_LIT>" + newline + "<STR_LIT>" + newline ; assertEquals ( expectedMsg , errMsg ) ; myStream = new ByteArrayOutputStream ( ) ; ps = new PrintStream ( myStream ) ; Y . setValue ( nomval - <NUM_LIT> * tol ) ; try { _ss . checkOutputs ( outVec , ps ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } errMsg = myStream . toString ( ) ; expectedMsg = newline + "<STR_LIT>" + newline + "<STR_LIT>" + newline + "<STR_LIT>" + newline ; assertEquals ( expectedMsg , errMsg ) ; } protected Element genStaticShotElement ( ) { Element staticShot = new Element ( "<STR_LIT>" ) ; staticShot . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; staticShot . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element checkInputs = new Element ( "<STR_LIT>" ) ; Element inputSignal1 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkInputs . addContent ( inputSignal1 ) ; Element inputSignal2 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkInputs . addContent ( inputSignal2 ) ; Element inputSignal3 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkInputs . addContent ( inputSignal3 ) ; staticShot . addContent ( checkInputs ) ; Element internalValues = new Element ( "<STR_LIT>" ) ; Element internalSignal1 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" ) ; internalValues . addContent ( internalSignal1 ) ; Element internalSignal2 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" ) ; internalValues . addContent ( internalSignal2 ) ; Element internalSignal3 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" ) ; internalValues . addContent ( internalSignal3 ) ; staticShot . addContent ( internalValues ) ; Element checkOutputs = new Element ( "<STR_LIT>" ) ; Element outputSignal1 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkOutputs . addContent ( outputSignal1 ) ; Element outputSignal2 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkOutputs . addContent ( outputSignal2 ) ; Element outputSignal3 = buildSignalElement ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; checkOutputs . addContent ( outputSignal3 ) ; staticShot . addContent ( checkOutputs ) ; return staticShot ; } protected Element buildSignalElement ( String name , String units , String value ) { Element signal = new Element ( "<STR_LIT>" ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( name ) ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( units ) ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( value ) ) ; return signal ; } protected Element buildSignalElement ( String varID , String value ) { Element signal = new Element ( "<STR_LIT>" ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( varID ) ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( value ) ) ; return signal ; } protected Element buildSignalElement ( String name , String units , String value , String tol ) { Element signal = buildSignalElement ( name , units , value ) ; signal . addContent ( new Element ( "<STR_LIT>" ) . addContent ( tol ) ) ; return signal ; } protected void checkSignal ( VectorInfoArrayList signals , int index , String name , String units , double value ) { checkSignal ( signals , index , name , units , value , Double . NaN ) ; } protected void checkSignal ( VectorInfoArrayList signals , int index , String name , String units , double value , double tolerance ) { VectorInfo signal ; assertNotNull ( signals ) ; signal = signals . get ( index ) ; assertNotNull ( signal ) ; assertEquals ( name , signal . getName ( ) ) ; assertEquals ( units , signal . getUnits ( ) ) ; assertEquals ( value , signal . getValue ( ) , EPS ) ; assertEquals ( tolerance , signal . getTolerance ( ) , EPS ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import junit . framework . * ; import java . util . ArrayList ; import java . util . Iterator ; public class SignalTest extends TestCase { private Signal _ds ; private Signal _ss ; private Signal _fs ; private Signal _cs ; private Block _bc ; private Block _bd ; private Model _m ; private final double eps = <NUM_LIT> ; @ Override protected void setUp ( ) { _m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _ds = new Signal ( ) ; _ss = new Signal ( "<STR_LIT>" , _m ) ; _fs = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , _m ) ; _fs . setLowerLimit ( - <NUM_LIT> ) ; _fs . setUpperLimit ( <NUM_LIT> ) ; _bc = new BlockMathConstant ( "<STR_LIT>" , _m ) ; _bd = new BlockOutput ( _ss , _m ) ; } public void testToValidId ( ) { String input = "<STR_LIT>" ; String expected = "<STR_LIT>" ; assertTrue ( Signal . toValidId ( input ) . equals ( expected ) ) ; input = "<STR_LIT>" ; expected = "<STR_LIT>" ; assertTrue ( Signal . toValidId ( input ) . equals ( expected ) ) ; } public void testDefaultCtor ( ) { assertTrue ( ( _ds . getName ( ) . equals ( "<STR_LIT>" ) ) ) ; try { assertTrue ( _ds . sourceReady ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { assertTrue ( true ) ; } assertTrue ( ( _ds . getVarID ( ) . equals ( "<STR_LIT>" ) ) ) ; assertTrue ( ( _ds . getUnits ( ) == null ? "<STR_LIT>" == null : _ds . getUnits ( ) . equals ( "<STR_LIT>" ) ) ) ; assertTrue ( _ds . getSource ( ) == null ) ; assertTrue ( _ds . getSourcePort ( ) == <NUM_LIT:0> ) ; assertFalse ( _ds . hasSource ( ) ) ; assertFalse ( _ds . hasDest ( ) ) ; assertFalse ( _ds . hasIC ( ) ) ; assertFalse ( _ds . isInput ( ) ) ; assertFalse ( _ds . isControl ( ) ) ; assertFalse ( _ds . isDisturbance ( ) ) ; assertFalse ( _ds . isState ( ) ) ; assertFalse ( _ds . isStateDeriv ( ) ) ; assertFalse ( _ds . isInput ( ) ) ; assertFalse ( _ds . isOutput ( ) ) ; assertFalse ( _ds . isStdAIAA ( ) ) ; assertFalse ( _ds . isDerived ( ) ) ; assertFalse ( _ds . isDefined ( ) ) ; assertFalse ( _ds . hasLowerLimit ( ) ) ; assertFalse ( _ds . hasUpperLimit ( ) ) ; assertFalse ( _ds . isLimited ( ) ) ; assertTrue ( Double . isInfinite ( _ds . getLowerLimit ( ) ) ) ; assertTrue ( Double . isInfinite ( _ds . getUpperLimit ( ) ) ) ; } public void testFullCtor ( ) { assertTrue ( ( _fs . getName ( ) == null ? "<STR_LIT>" == null : _fs . getName ( ) . equals ( "<STR_LIT>" ) ) ) ; assertTrue ( ( _fs . getVarID ( ) == null ? "<STR_LIT>" == null : _fs . getVarID ( ) . equals ( "<STR_LIT>" ) ) ) ; assertTrue ( ( _fs . getUnits ( ) == null ? "<STR_LIT>" == null : _fs . getUnits ( ) . equals ( "<STR_LIT>" ) ) ) ; assertTrue ( _fs . getSource ( ) == null ) ; assertTrue ( _fs . getSourcePort ( ) == <NUM_LIT:0> ) ; assertFalse ( _fs . hasSource ( ) ) ; assertFalse ( _fs . hasDest ( ) ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; assertFalse ( _fs . isDerived ( ) ) ; assertFalse ( _fs . isDefined ( ) ) ; assertTrue ( _fs . hasLowerLimit ( ) ) ; assertTrue ( _fs . hasUpperLimit ( ) ) ; assertTrue ( _fs . isLimited ( ) ) ; assertEquals ( - <NUM_LIT> , _fs . getLowerLimit ( ) , eps ) ; assertEquals ( <NUM_LIT> , _fs . getUpperLimit ( ) , eps ) ; } public void testSingleSignal ( ) { assertTrue ( _bd != null ) ; assertTrue ( _ss . getName ( ) . equals ( "<STR_LIT>" ) ) ; try { assertTrue ( _ss . sourceReady ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { assertTrue ( true ) ; } try { _bc . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _bc . addOutput ( _ss ) ; assertTrue ( _ss . sourceReady ( ) ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { assertEquals ( - <NUM_LIT> , _ss . sourceValue ( ) , <NUM_LIT> ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _m . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertTrue ( _ss . getVarID ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( _ss . getUnits ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( _ss . getSource ( ) == _bc ) ; assertTrue ( _ss . getSourcePort ( ) == <NUM_LIT:1> ) ; assertTrue ( _ss . hasSource ( ) ) ; assertTrue ( _ss . hasDest ( ) ) ; assertFalse ( _ss . hasIC ( ) ) ; assertFalse ( _ss . isInput ( ) ) ; assertFalse ( _ss . isControl ( ) ) ; assertFalse ( _ss . isDisturbance ( ) ) ; assertFalse ( _ss . isState ( ) ) ; assertFalse ( _ss . isStateDeriv ( ) ) ; assertFalse ( _ss . isInput ( ) ) ; assertFalse ( _ss . isOutput ( ) ) ; assertFalse ( _ss . isStdAIAA ( ) ) ; assertFalse ( _ss . isDerived ( ) ) ; assertFalse ( _ss . isDefined ( ) ) ; assertFalse ( _ss . hasLowerLimit ( ) ) ; assertFalse ( _ss . hasUpperLimit ( ) ) ; assertFalse ( _ss . isLimited ( ) ) ; assertTrue ( Double . isInfinite ( _ss . getLowerLimit ( ) ) ) ; assertTrue ( Double . isInfinite ( _ss . getUpperLimit ( ) ) ) ; BlockArrayList dests = _ss . getDests ( ) ; assertTrue ( dests != null ) ; assertTrue ( dests . size ( ) == <NUM_LIT:1> ) ; Iterator < Block > dbi = dests . iterator ( ) ; assertTrue ( dbi . hasNext ( ) ) ; Block destBlock = ( Block ) dbi . next ( ) ; assertTrue ( destBlock == _bd ) ; ArrayList < Integer > destPorts = _ss . getDestPortNumbers ( ) ; assertTrue ( destPorts != null ) ; assertTrue ( destPorts . size ( ) == <NUM_LIT:1> ) ; Iterator < Integer > dpi = destPorts . iterator ( ) ; assertTrue ( dpi . hasNext ( ) ) ; Integer destPort = ( Integer ) dpi . next ( ) ; assertTrue ( destPort == <NUM_LIT:1> ) ; } private void checkCode ( int lang , Signal sig , String id ) { CodeAndVarNames cvn ; _m . setCodeDialect ( lang ) ; sig . clearDerivedFlag ( ) ; cvn = sig . genCode ( ) ; assertFalse ( cvn . getVarNames ( ) == null ) ; assertEquals ( <NUM_LIT:1> , cvn . getVarNames ( ) . size ( ) ) ; assertTrue ( id . equals ( cvn . getVarName ( <NUM_LIT:0> ) ) ) ; assertTrue ( id . equals ( cvn . getCode ( ) ) ) ; assertFalse ( sig . isDefined ( ) ) ; sig . clearDefinedFlag ( ) ; sig . setDerivedFlag ( ) ; cvn = sig . genCode ( ) ; assertFalse ( cvn . getVarNames ( ) == null ) ; assertEquals ( <NUM_LIT:0> , cvn . getVarNames ( ) . size ( ) ) ; assertTrue ( "<STR_LIT>" . equals ( cvn . getCode ( ) ) ) ; assertFalse ( sig . isDefined ( ) ) ; } private void checkCode ( Signal sig , String id ) { checkCode ( Model . DT_ANSI_C , sig , id ) ; sig . clearDefinedFlag ( ) ; checkCode ( Model . DT_FORTRAN , sig , id ) ; } public void testGenCode_DefaultSignal ( ) { Signal sig = _ds ; String id = "<STR_LIT>" ; checkCode ( sig , id ) ; } public void testGenCode_SingleSignal ( ) { Signal sig = _ss ; String id = "<STR_LIT>" ; checkCode ( sig , id ) ; } public void testGenCode_FullSignal ( ) { Signal sig = _fs ; String id = "<STR_LIT>" ; checkCode ( sig , id ) ; } public void testVerbose ( ) { assertFalse ( _ss . isVerbose ( ) ) ; _ss . makeVerbose ( ) ; assertTrue ( _ss . isVerbose ( ) ) ; _ss . silence ( ) ; assertFalse ( _ss . isVerbose ( ) ) ; } public void testSetGetLimits ( ) { _ds . setLowerLimit ( "<STR_LIT>" ) ; assertTrue ( _ds . hasLowerLimit ( ) ) ; assertFalse ( _ds . hasUpperLimit ( ) ) ; assertTrue ( _ds . isLimited ( ) ) ; assertEquals ( - <NUM_LIT> , _ds . getLowerLimit ( ) , eps ) ; _ds . setLowerLimit ( - <NUM_LIT> ) ; assertTrue ( _ds . hasLowerLimit ( ) ) ; assertFalse ( _ds . hasUpperLimit ( ) ) ; assertTrue ( _ds . isLimited ( ) ) ; assertEquals ( - <NUM_LIT> , _ds . getLowerLimit ( ) , eps ) ; _ds . setUpperLimit ( "<STR_LIT>" ) ; assertTrue ( _ds . hasLowerLimit ( ) ) ; assertTrue ( _ds . hasUpperLimit ( ) ) ; assertTrue ( _ds . isLimited ( ) ) ; assertEquals ( + <NUM_LIT> , _ds . getUpperLimit ( ) , eps ) ; assertEquals ( - <NUM_LIT> , _ds . getLowerLimit ( ) , eps ) ; _ds . setUpperLimit ( <NUM_LIT> ) ; assertTrue ( _ds . hasLowerLimit ( ) ) ; assertTrue ( _ds . hasUpperLimit ( ) ) ; assertTrue ( _ds . isLimited ( ) ) ; assertEquals ( + <NUM_LIT> , _ds . getUpperLimit ( ) , eps ) ; assertEquals ( - <NUM_LIT> , _ds . getLowerLimit ( ) , eps ) ; } public void testClearIsOutputFlag ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; _fs . clearIsOutputFlag ( ) ; assertFalse ( _fs . isOutput ( ) ) ; } public void testDeepCopy ( ) { Signal s2 = new Signal ( _fs ) ; assertTrue ( s2 . getName ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( s2 . getVarID ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( s2 . getUnits ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( s2 . getSource ( ) == null ) ; assertTrue ( s2 . getSourcePort ( ) == <NUM_LIT:0> ) ; assertFalse ( s2 . hasSource ( ) ) ; assertFalse ( s2 . hasDest ( ) ) ; assertFalse ( s2 . hasIC ( ) ) ; assertFalse ( s2 . isInput ( ) ) ; assertFalse ( s2 . isControl ( ) ) ; assertFalse ( s2 . isDisturbance ( ) ) ; assertFalse ( s2 . isState ( ) ) ; assertFalse ( s2 . isStateDeriv ( ) ) ; assertFalse ( s2 . isInput ( ) ) ; assertFalse ( s2 . isOutput ( ) ) ; assertFalse ( s2 . isStdAIAA ( ) ) ; assertFalse ( s2 . isDerived ( ) ) ; assertTrue ( s2 . hasLowerLimit ( ) ) ; assertTrue ( s2 . hasUpperLimit ( ) ) ; assertTrue ( s2 . isLimited ( ) ) ; assertEquals ( - <NUM_LIT> , s2 . getLowerLimit ( ) , eps ) ; assertEquals ( <NUM_LIT> , s2 . getUpperLimit ( ) , eps ) ; try { assertTrue ( _ds . sourceReady ( ) ) ; fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { assertTrue ( true ) ; } } public void testSignalMarkedAsInput ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertTrue ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsControl ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertTrue ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsDisturbance ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertTrue ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalIncorrectlyMarkedAsBothInputAndControl ( ) { setFullSignalWithFlags ( "<STR_LIT>" , "<STR_LIT>" ) ; assertFalse ( _fs . hasIC ( ) ) ; assertTrue ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalIncorrectlyMarkedAsBothInputAndDisturbance ( ) { setFullSignalWithFlags ( "<STR_LIT>" , "<STR_LIT>" ) ; assertFalse ( _fs . hasIC ( ) ) ; assertTrue ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalIncorrectlyMarkedAsBothControlAndDisturbance ( ) { setFullSignalWithFlags ( "<STR_LIT>" , "<STR_LIT>" ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertTrue ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsState ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertTrue ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsStateDeriv ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertTrue ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsOutput ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertTrue ( _fs . isOutput ( ) ) ; assertFalse ( _fs . isStdAIAA ( ) ) ; } public void testSignalMarkedAsStdAIAA ( ) { setFullSignalWithFlags ( "<STR_LIT>" , null ) ; assertFalse ( _fs . hasIC ( ) ) ; assertFalse ( _fs . isInput ( ) ) ; assertFalse ( _fs . isControl ( ) ) ; assertFalse ( _fs . isDisturbance ( ) ) ; assertFalse ( _fs . isState ( ) ) ; assertFalse ( _fs . isStateDeriv ( ) ) ; assertFalse ( _fs . isOutput ( ) ) ; assertTrue ( _fs . isStdAIAA ( ) ) ; } public void testSignalWithICBelowMinLimit ( ) { buildAndTestSignalWithIcPlusLimit ( - <NUM_LIT> , - <NUM_LIT> , null , - <NUM_LIT> ) ; } public void testSignalWithICAboveMinLimit ( ) { buildAndTestSignalWithIcPlusLimit ( <NUM_LIT> , - <NUM_LIT> , null , <NUM_LIT> ) ; } public void testSignalWithICBelowMaxLimit ( ) { buildAndTestSignalWithIcPlusLimit ( <NUM_LIT> , null , <NUM_LIT> , <NUM_LIT> ) ; } public void testSignalWithICAboveMaxLimit ( ) { buildAndTestSignalWithIcPlusLimit ( <NUM_LIT> , null , <NUM_LIT> , <NUM_LIT> ) ; } public void testSignalWithICBelowMinMaxLimit ( ) { buildAndTestSignalWithIcPlusLimit ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; } public void testSignalWithICInsideMinMaxLimit ( ) { buildAndTestSignalWithIcPlusLimit ( <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; } public void testSignalWithICAboveMinMaxLimit ( ) { buildAndTestSignalWithIcPlusLimit ( <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; } public void testSignalWithCalcBelowMinLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , null , - <NUM_LIT> ) ; } public void testSignalWithCalcAboveMinLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( <NUM_LIT:0.0> , <NUM_LIT> , - <NUM_LIT> , null , <NUM_LIT> ) ; } public void testSignalWithCalcBelowMaxLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( <NUM_LIT> , <NUM_LIT> , null , + <NUM_LIT> , <NUM_LIT> ) ; } public void testSignalWithCalcAboveMaxLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( + <NUM_LIT> , <NUM_LIT> , null , + <NUM_LIT> , + <NUM_LIT> ) ; } public void testSignalWithCalcBelowMinMaxLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , + <NUM_LIT> , - <NUM_LIT> ) ; } public void testSignalWithCalcInsideMinMaxLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , + <NUM_LIT> , - <NUM_LIT> ) ; } public void testSignalWithCalcAboveMinMaxLimit ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( + <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> , + <NUM_LIT> , + <NUM_LIT> ) ; } public void testSignalElementWithNumericConstant_ctor ( ) { _ds = null ; _ss = null ; _fs = null ; _bc = null ; _bd = null ; Element theDesc1 = new Element ( "<STR_LIT:description>" ) ; theDesc1 . addContent ( "<STR_LIT>" ) ; Element theValue = new Element ( "<STR_LIT>" ) ; theValue . addContent ( "<STR_LIT>" ) ; Element absElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( absElement ) ; applyElement . addContent ( theValue ) ; Element mathElement = new Element ( "<STR_LIT>" ) ; mathElement . addContent ( applyElement ) ; Element calcElement = new Element ( "<STR_LIT>" ) ; calcElement . addContent ( mathElement ) ; Element calcVarDef ; calcVarDef = new Element ( "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . addContent ( theDesc1 ) ; calcVarDef . addContent ( calcElement ) ; Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; Signal theSignal = new Signal ( calcVarDef , m ) ; assertTrue ( theSignal != null ) ; assertTrue ( theSignal . hasSource ( ) ) ; assertFalse ( theSignal . hasDest ( ) ) ; assertFalse ( theSignal . hasIC ( ) ) ; Block abs_1 = theSignal . getSource ( ) ; assertTrue ( abs_1 != null ) ; assertEquals ( "<STR_LIT>" , abs_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numVarIDs ( ) ) ; assertTrue ( abs_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getOutputVarID ( ) ) ; assertEquals ( theSignal , abs_1 . getOutput ( ) ) ; assertTrue ( abs_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:2> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:2> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumOutputBlocks ( ) ) ; try { m . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { assertEquals ( <NUM_LIT> , theSignal . sourceValue ( ) , <NUM_LIT> ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } m . setCodeDialect ( Model . DT_ANSI_C ) ; assertTrue ( theSignal . genCode ( ) . getCode ( ) . equals ( "<STR_LIT>" ) ) ; } public void testSignalElementWithBlockConstant_ctor ( ) { _ds = null ; _ss = null ; _fs = null ; _bc = null ; _bd = null ; Element theDesc1 = new Element ( "<STR_LIT:description>" ) ; theDesc1 . addContent ( "<STR_LIT>" ) ; Element theValue = new Element ( "<STR_LIT>" ) ; theValue . addContent ( "<STR_LIT>" ) ; Element absElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( absElement ) ; applyElement . addContent ( theValue ) ; Element mathElement = new Element ( "<STR_LIT>" ) ; mathElement . addContent ( applyElement ) ; Element calcElement = new Element ( "<STR_LIT>" ) ; calcElement . addContent ( mathElement ) ; Element calcVarDef ; Element constVarDef ; calcVarDef = new Element ( "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . addContent ( theDesc1 ) ; calcVarDef . addContent ( calcElement ) ; Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; constVarDef = new Element ( "<STR_LIT>" ) ; constVarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; constVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; constVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; constVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Signal beta = new Signal ( constVarDef , m ) ; assertTrue ( beta != null ) ; assertFalse ( beta . hasSource ( ) ) ; assertFalse ( beta . hasDest ( ) ) ; assertTrue ( beta . hasIC ( ) ) ; Signal dv = new Signal ( calcVarDef , m ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertFalse ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; Block abs_1 = dv . getSource ( ) ; assertTrue ( abs_1 != null ) ; assertEquals ( "<STR_LIT>" , abs_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numVarIDs ( ) ) ; assertFalse ( abs_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getOutputVarID ( ) ) ; assertEquals ( dv , abs_1 . getOutput ( ) ) ; assertTrue ( abs_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:1> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:2> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumOutputBlocks ( ) ) ; m . wireBlocks ( ) ; assertTrue ( beta != null ) ; assertFalse ( beta . hasSource ( ) ) ; assertTrue ( beta . hasDest ( ) ) ; assertTrue ( beta . hasIC ( ) ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertFalse ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; assertTrue ( abs_1 != null ) ; assertEquals ( "<STR_LIT>" , abs_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numVarIDs ( ) ) ; assertTrue ( abs_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getOutputVarID ( ) ) ; assertEquals ( dv , abs_1 . getOutput ( ) ) ; assertTrue ( abs_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:1> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:2> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumOutputBlocks ( ) ) ; m . hookUpIO ( ) ; assertTrue ( beta != null ) ; assertTrue ( beta . hasSource ( ) ) ; assertTrue ( beta . hasDest ( ) ) ; assertTrue ( beta . hasIC ( ) ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertTrue ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; assertTrue ( abs_1 != null ) ; assertEquals ( "<STR_LIT>" , abs_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:1> , abs_1 . numVarIDs ( ) ) ; assertTrue ( abs_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , abs_1 . getOutputVarID ( ) ) ; assertEquals ( dv , abs_1 . getOutput ( ) ) ; assertTrue ( abs_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:3> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:2> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:1> , m . getNumOutputBlocks ( ) ) ; try { m . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { assertTrue ( dv . sourceReady ( ) ) ; assertEquals ( <NUM_LIT> , dv . sourceValue ( ) , <NUM_LIT> ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } m . setCodeDialect ( Model . DT_ANSI_C ) ; assertTrue ( beta . genCode ( ) . getCode ( ) . equals ( "<STR_LIT>" ) ) ; assertTrue ( dv . genCode ( ) . getCode ( ) . equals ( "<STR_LIT>" ) ) ; } public void testSignalElementWithCalculation ( ) { buildAndTestModelWithCalcAndMinMaxLimits ( <NUM_LIT> , <NUM_LIT> , null , null , <NUM_LIT> * <NUM_LIT> ) ; } private void buildAndTestModelWithCalcAndMinMaxLimits ( Double a , Double b , Double min , Double max , Double expectedValue ) { Model m = buildModelWithCalculationATimeBAndMinMaxLimits ( a , b , min , max ) ; try { m . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } SignalArrayList sal = m . getSignals ( ) ; Signal dv = sal . findByID ( "<STR_LIT>" ) ; assertNotNull ( dv ) ; try { assertTrue ( dv . sourceReady ( ) ) ; assertEquals ( expectedValue , dv . sourceValue ( ) , <NUM_LIT> ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } private Model buildModelWithCalculationATimeBAndMinMaxLimits ( Double a , Double b , Double min , Double max ) { boolean calcIsLimited = false ; Element theDesc1 = new Element ( "<STR_LIT:description>" ) ; theDesc1 . addContent ( "<STR_LIT>" ) ; Element firstArg = new Element ( "<STR_LIT>" ) ; firstArg . addContent ( "<STR_LIT:A>" ) ; Element secondArg = new Element ( "<STR_LIT>" ) ; secondArg . addContent ( "<STR_LIT:B>" ) ; Element timesElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( timesElement ) ; applyElement . addContent ( firstArg ) ; applyElement . addContent ( secondArg ) ; Element mathElement = new Element ( "<STR_LIT>" ) ; mathElement . addContent ( applyElement ) ; Element calcElement = new Element ( "<STR_LIT>" ) ; calcElement . addContent ( mathElement ) ; Element calcVarDef ; Element arg1VarDef ; Element arg2VarDef ; calcVarDef = new Element ( "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . addContent ( theDesc1 ) ; calcVarDef . addContent ( calcElement ) ; if ( min != null ) { calcVarDef . setAttribute ( "<STR_LIT>" , min . toString ( ) ) ; calcIsLimited = true ; } if ( max != null ) { calcVarDef . setAttribute ( "<STR_LIT>" , max . toString ( ) ) ; calcIsLimited = true ; } Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; arg1VarDef = new Element ( "<STR_LIT>" ) ; arg1VarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT:a>" ) ; arg1VarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT:A>" ) ; arg1VarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; arg1VarDef . setAttribute ( "<STR_LIT>" , a . toString ( ) ) ; Signal aSig = new Signal ( arg1VarDef , m ) ; assertTrue ( aSig != null ) ; assertFalse ( aSig . hasSource ( ) ) ; assertFalse ( aSig . hasDest ( ) ) ; assertTrue ( aSig . hasIC ( ) ) ; arg2VarDef = new Element ( "<STR_LIT>" ) ; arg2VarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT:b>" ) ; arg2VarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT:B>" ) ; arg2VarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; arg2VarDef . setAttribute ( "<STR_LIT>" , b . toString ( ) ) ; Signal bSig = new Signal ( arg2VarDef , m ) ; assertTrue ( bSig != null ) ; assertFalse ( bSig . hasSource ( ) ) ; assertFalse ( bSig . hasDest ( ) ) ; assertTrue ( bSig . hasIC ( ) ) ; Signal dv = new Signal ( calcVarDef , m ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertFalse ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; Block times_1 = dv . getSource ( ) ; assertTrue ( times_1 != null ) ; assertEquals ( "<STR_LIT>" , times_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numVarIDs ( ) ) ; assertFalse ( times_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT:A>" , times_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT:B>" , times_1 . getVarID ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , times_1 . getOutputVarID ( ) ) ; assertEquals ( dv , times_1 . getOutput ( ) ) ; assertTrue ( times_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:1> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:3> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumOutputBlocks ( ) ) ; m . wireBlocks ( ) ; assertTrue ( aSig != null ) ; assertFalse ( aSig . hasSource ( ) ) ; assertTrue ( aSig . hasDest ( ) ) ; assertTrue ( aSig . hasIC ( ) ) ; assertTrue ( bSig != null ) ; assertFalse ( bSig . hasSource ( ) ) ; assertTrue ( bSig . hasDest ( ) ) ; assertTrue ( bSig . hasIC ( ) ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertFalse ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; assertTrue ( times_1 != null ) ; assertEquals ( "<STR_LIT>" , times_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numVarIDs ( ) ) ; assertTrue ( times_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT:A>" , times_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT:B>" , times_1 . getVarID ( <NUM_LIT:2> ) ) ; assertEquals ( "<STR_LIT>" , times_1 . getOutputVarID ( ) ) ; assertEquals ( dv , times_1 . getOutput ( ) ) ; assertTrue ( times_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; assertEquals ( <NUM_LIT:1> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:3> , m . getNumSignals ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , m . getNumOutputBlocks ( ) ) ; m . hookUpIO ( ) ; assertTrue ( aSig != null ) ; assertTrue ( aSig . hasSource ( ) ) ; assertTrue ( aSig . hasDest ( ) ) ; assertTrue ( aSig . hasIC ( ) ) ; assertTrue ( bSig != null ) ; assertTrue ( bSig . hasSource ( ) ) ; assertTrue ( bSig . hasDest ( ) ) ; assertTrue ( bSig . hasIC ( ) ) ; assertTrue ( dv != null ) ; assertTrue ( dv . hasSource ( ) ) ; assertTrue ( dv . hasDest ( ) ) ; assertFalse ( dv . hasIC ( ) ) ; assertTrue ( times_1 != null ) ; assertEquals ( "<STR_LIT>" , times_1 . getName ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numInputs ( ) ) ; assertEquals ( <NUM_LIT:2> , times_1 . numVarIDs ( ) ) ; assertTrue ( times_1 . allInputsConnected ( ) ) ; assertEquals ( "<STR_LIT:A>" , times_1 . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT:B>" , times_1 . getVarID ( <NUM_LIT:2> ) ) ; if ( calcIsLimited ) { assertEquals ( "<STR_LIT>" , times_1 . getOutputVarID ( ) ) ; } else { assertEquals ( "<STR_LIT>" , times_1 . getOutputVarID ( ) ) ; assertEquals ( dv , times_1 . getOutput ( ) ) ; } assertTrue ( times_1 . outputConnected ( ) ) ; assertTrue ( m != null ) ; if ( calcIsLimited ) { assertEquals ( <NUM_LIT:5> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:4> , m . getNumSignals ( ) ) ; } else { assertEquals ( <NUM_LIT:4> , m . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:3> , m . getNumSignals ( ) ) ; } assertEquals ( <NUM_LIT:0> , m . getNumInputBlocks ( ) ) ; assertEquals ( <NUM_LIT:1> , m . getNumOutputBlocks ( ) ) ; return m ; } private void buildAndTestSignalWithIcPlusLimit ( Double ic , Double min , Double max , Double expectedValue ) { _m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; VectorInfoArrayList outputs = null ; VectorInfoArrayList inputs = null ; String icString = null ; String minString = null ; String maxString = null ; if ( ic != null ) icString = ic . toString ( ) ; if ( min != null ) minString = min . toString ( ) ; if ( max != null ) maxString = max . toString ( ) ; setFullSignalWithICMinMax ( icString , minString , maxString ) ; BlockArrayList dests = _fs . getDests ( ) ; assertTrue ( dests != null ) ; assertEquals ( <NUM_LIT:1> , dests . size ( ) ) ; Block blk = dests . get ( <NUM_LIT:0> ) ; assertTrue ( blk != null ) ; assertTrue ( blk instanceof BlockLimiter ) ; BlockLimiter limBlk = ( BlockLimiter ) blk ; assertTrue ( ( min == null ) ^ limBlk . hasLowerLimit ( ) ) ; assertTrue ( ( max == null ) ^ limBlk . hasUpperLimit ( ) ) ; if ( min != null ) assertEquals ( min , limBlk . getLowerLimit ( ) , eps ) ; if ( max != null ) assertEquals ( max , limBlk . getUpperLimit ( ) , eps ) ; try { outputs = _m . getOutputVector ( ) ; inputs = _m . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT:1> , outputs . size ( ) ) ; assertEquals ( <NUM_LIT:0> , inputs . size ( ) ) ; VectorInfo output = outputs . get ( <NUM_LIT:0> ) ; try { _m . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( expectedValue , output . getValue ( ) , eps ) ; } private void setFullSignalWithFlags ( String flagValue1 , String flagValue2 ) { _fs = null ; Element theDesc1 = new Element ( "<STR_LIT:description>" ) ; theDesc1 . addContent ( "<STR_LIT>" ) ; Element calcVarDef ; Element flag1 = new Element ( flagValue1 ) ; Element flag2 = null ; if ( flagValue2 != null ) flag2 = new Element ( flagValue2 ) ; calcVarDef = new Element ( "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; calcVarDef . addContent ( theDesc1 ) ; calcVarDef . addContent ( flag1 ) ; if ( flagValue2 != null ) calcVarDef . addContent ( flag2 ) ; _fs = new Signal ( calcVarDef , _m ) ; assertEquals ( "<STR_LIT>" , _fs . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _fs . getVarID ( ) ) ; assertEquals ( "<STR_LIT>" , _fs . getUnits ( ) ) ; assertTrue ( _fs . getSource ( ) == null ) ; assertTrue ( _fs . getSourcePort ( ) == <NUM_LIT:0> ) ; assertFalse ( _fs . hasSource ( ) ) ; assertFalse ( _fs . hasDest ( ) ) ; assertFalse ( _fs . isDerived ( ) ) ; } private void setFullSignalWithICMinMax ( String ICValue , String minValue , String maxValue ) { _fs = null ; Element theDesc1 = new Element ( "<STR_LIT:description>" ) ; theDesc1 . addContent ( "<STR_LIT>" ) ; Element varDef ; varDef = new Element ( "<STR_LIT>" ) ; varDef . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; varDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; varDef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; if ( ICValue != null ) varDef . setAttribute ( "<STR_LIT>" , ICValue ) ; if ( minValue != null ) varDef . setAttribute ( "<STR_LIT>" , minValue ) ; if ( maxValue != null ) varDef . setAttribute ( "<STR_LIT>" , maxValue ) ; varDef . addContent ( theDesc1 ) ; varDef . addContent ( new Element ( "<STR_LIT>" ) ) ; _fs = new Signal ( varDef , _m ) ; assertEquals ( "<STR_LIT>" , _fs . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _fs . getVarID ( ) ) ; assertEquals ( "<STR_LIT>" , _fs . getUnits ( ) ) ; assertTrue ( _fs . getSource ( ) == null ) ; assertTrue ( _fs . getSourcePort ( ) == <NUM_LIT:0> ) ; assertFalse ( _fs . hasSource ( ) ) ; assertFalse ( _fs . hasDest ( ) ) ; assertFalse ( _fs . isDerived ( ) ) ; _m . hookUpIO ( ) ; try { _m . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public static Test suite ( ) { return new TestSuite ( SignalTest . class ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; import org . junit . Before ; import org . junit . AfterClass ; import org . junit . BeforeClass ; import org . junit . Test ; import static org . junit . Assert . * ; public class CodeAndVarNamesTest { CodeAndVarNames cvn0 , cvn1 , cvn2 ; public CodeAndVarNamesTest ( ) { } @ BeforeClass public static void setUpClass ( ) throws Exception { } @ AfterClass public static void tearDownClass ( ) throws Exception { } @ Before public void setUp ( ) { cvn0 = new CodeAndVarNames ( ) ; cvn1 = new CodeAndVarNames ( "<STR_LIT>" ) ; cvn1 . addVarName ( "<STR_LIT>" ) ; cvn2 = new CodeAndVarNames ( "<STR_LIT>" ) ; cvn2 . addVarName ( "<STR_LIT>" ) ; } @ Test public void testAppend ( ) { cvn1 . append ( cvn2 ) ; assertEquals ( "<STR_LIT>" , cvn1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; cvn0 . append ( cvn1 ) ; assertEquals ( "<STR_LIT>" , cvn0 . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , cvn0 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn0 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn0 . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; } @ Test public void testAppendCode ( ) { cvn1 . appendCode ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , cvn1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; } @ Test public void testPrependCode ( ) { cvn1 . prependCode ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , cvn1 . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; } @ Test public void testAddVarName ( ) { cvn1 . addVarName ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:2> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; } @ Test public void testGetVarNames ( ) { ArrayList < String > varNames ; varNames = cvn0 . getVarNames ( ) ; assertNotNull ( varNames ) ; assertEquals ( <NUM_LIT:0> , varNames . size ( ) ) ; varNames = cvn1 . getVarNames ( ) ; assertEquals ( <NUM_LIT:1> , varNames . size ( ) ) ; assertEquals ( "<STR_LIT>" , varNames . get ( <NUM_LIT:0> ) ) ; varNames = cvn2 . getVarNames ( ) ; assertEquals ( <NUM_LIT:1> , varNames . size ( ) ) ; assertEquals ( "<STR_LIT>" , varNames . get ( <NUM_LIT:0> ) ) ; } @ Test ( expected = IndexOutOfBoundsException . class ) public void testGetVarName ( ) { assertEquals ( <NUM_LIT:1> , cvn1 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( <NUM_LIT:1> , cvn2 . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getVarName ( <NUM_LIT:0> ) ) ; String varName = cvn1 . getVarName ( <NUM_LIT:1> ) ; } @ Test public void testGetCode ( ) { assertEquals ( "<STR_LIT>" , cvn0 . getCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn1 . getCode ( ) ) ; assertEquals ( "<STR_LIT>" , cvn2 . getCode ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathSwitchTest extends TestCase { protected Model _model ; private StringWriter _writer ; protected BlockMathSwitch _block ; protected BlockMathConstant _inputBlock ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _block = generateSampleSwitch ( _model ) ; SignalArrayList theSignals = _model . getSignals ( ) ; Signal inputSignal = theSignals . findByID ( "<STR_LIT>" ) ; assertNotNull ( inputSignal ) ; Block theBlock = inputSignal . getSource ( ) ; assertNotNull ( theBlock ) ; assertEquals ( "<STR_LIT>" , theBlock . myType ) ; _inputBlock = ( BlockMathConstant ) theBlock ; assertNotNull ( _inputBlock ) ; } public void testUpdate ( ) { assertNotNull ( _block ) ; String routineName = "<STR_LIT>" ; _model . wireBlocks ( ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT:0.0> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( <NUM_LIT:0.0> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT:0.0> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; } private double checkSwitch ( Double switchVal ) { String routineName = "<STR_LIT>" ; _inputBlock . setValue ( switchVal ) ; try { _model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + switchVal . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } return _block . getValue ( ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT:U+0020U+0020>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( code , cvn . getCode ( ) ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( code , cvn . getCode ( ) ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } private BlockMathSwitch generateSampleSwitch ( Model model ) { Block swValueBlock ; String swValueSignalID ; Signal swValueSignal ; Signal outputSignal ; swValueBlock = new BlockMathConstant ( "<STR_LIT>" , model ) ; swValueSignalID = "<STR_LIT>" ; swValueSignal = new Signal ( "<STR_LIT>" , swValueSignalID , "<STR_LIT>" , <NUM_LIT:1> , model ) ; try { swValueBlock . addOutput ( swValueSignal ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } outputSignal = new Signal ( "<STR_LIT>" , model ) ; Element swValue = new Element ( "<STR_LIT>" ) ; swValue . addContent ( "<STR_LIT>" ) ; Element zero = new Element ( "<STR_LIT>" ) ; zero . addContent ( "<STR_LIT:0>" ) ; Element lt = new Element ( "<STR_LIT>" ) ; Element innerApply = new Element ( "<STR_LIT>" ) ; innerApply . addContent ( lt ) ; innerApply . addContent ( swValue ) ; innerApply . addContent ( zero ) ; Element minusOne = new Element ( "<STR_LIT>" ) ; minusOne . addContent ( "<STR_LIT:-1>" ) ; Element piece = new Element ( "<STR_LIT>" ) ; piece . addContent ( minusOne ) ; piece . addContent ( innerApply ) ; Element one = new Element ( "<STR_LIT>" ) ; one . addContent ( "<STR_LIT:1>" ) ; Element otherwise = new Element ( "<STR_LIT>" ) ; otherwise . addContent ( one ) ; Element piecewise = new Element ( "<STR_LIT>" ) ; piecewise . addContent ( piece ) ; piecewise . addContent ( otherwise ) ; Element outerApply = new Element ( "<STR_LIT>" ) ; outerApply . addContent ( piecewise ) ; BlockMathSwitch bms = null ; bms = new BlockMathSwitch ( outerApply , model ) ; try { bms . addOutput ( outputSignal ) ; _model . wireBlocks ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + "<STR_LIT>" + e . getMessage ( ) ) ; } return bms ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathAbsTest extends TestCase { protected Model _model ; protected BlockMathAbs _block ; private StringWriter _writer ; protected Signal _sig , _outSig ; protected BlockMathConstant _const ; @ Override protected void setUp ( ) { _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; Element ciElement = new Element ( "<STR_LIT>" ) ; ciElement . addContent ( "<STR_LIT>" ) ; Element absElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( absElement ) ; applyElement . addContent ( ciElement ) ; _block = new BlockMathAbs ( applyElement , _model ) ; _const = new BlockMathConstant ( "<STR_LIT>" , _model ) ; Signal sig = new Signal ( "<STR_LIT>" , _model ) ; _outSig = new Signal ( "<STR_LIT>" , _model ) ; _block . addInput ( sig , <NUM_LIT:1> ) ; try { _block . addOutput ( _outSig ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } try { _const . addOutput ( sig ) ; } catch ( DAVEException e2 ) { fail ( "<STR_LIT>" + e2 . getMessage ( ) ) ; } } public void testBlockMathAbsCtor ( ) { Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; Element theValue = new Element ( "<STR_LIT>" ) ; theValue . addContent ( "<STR_LIT>" ) ; Element absElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( absElement ) ; applyElement . addContent ( theValue ) ; Block theBlock = new BlockMathAbs ( applyElement , m ) ; assertTrue ( theBlock != null ) ; assertEquals ( "<STR_LIT>" , theBlock . myName ) ; assertEquals ( "<STR_LIT>" , theBlock . getName ( ) ) ; assertEquals ( "<STR_LIT>" , theBlock . myType ) ; assertEquals ( "<STR_LIT>" , theBlock . getType ( ) ) ; assertEquals ( <NUM_LIT:1> , theBlock . numInputs ( ) ) ; assertEquals ( <NUM_LIT:1> , theBlock . numVarIDs ( ) ) ; assertEquals ( "<STR_LIT>" , theBlock . getVarID ( <NUM_LIT:1> ) ) ; assertFalse ( theBlock . isReady ( ) ) ; } public void testUpdate ( ) { _const . setValue ( <NUM_LIT> ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } try { _block . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT> , _block . getValue ( ) , <NUM_LIT> ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; } public void testDescribeSelf ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; e . printStackTrace ( ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public void testGetValue ( ) { try { _block . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT> , _block . getValue ( ) , <NUM_LIT> ) ; } public void testIsReady ( ) { assertFalse ( _block . isReady ( ) ) ; try { _block . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertTrue ( _block . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _block . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( _block . isVerbose ( ) ) ; _block . makeVerbose ( ) ; assertTrue ( _block . isVerbose ( ) ) ; _block . silence ( ) ; assertFalse ( _block . isVerbose ( ) ) ; } public void testGetModel ( ) { assertEquals ( _model . getName ( ) , _block . getModel ( ) . getName ( ) ) ; } public void testGetSetName ( ) { assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; _block . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , _block . getType ( ) ) ; } public void testGetVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getVarID ( <NUM_LIT:1> ) ) ; } public void testGetVarIDIterator ( ) { Iterator < String > it = _block . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; String s = it . next ( ) ; assertEquals ( "<STR_LIT>" , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutput ( ) { Signal s = _block . getOutput ( ) ; assertEquals ( _outSig , s ) ; } public void getGetInputIterator ( ) { Iterator < Signal > it = _block . getInputIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; Signal s = it . next ( ) ; assertEquals ( _sig , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getOutputVarID ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:1> , _block . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:1> , _block . numVarIDs ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathMinmaxTest extends TestCase { protected Model modelMax , modelMin ; private final double EPS = <NUM_LIT> ; protected BlockMathMinmax minBlock , maxBlock ; @ Override protected void setUp ( ) throws Exception { String routineName = "<STR_LIT>" ; modelMin = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; modelMax = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; minBlock = setUpExtremaModel ( "<STR_LIT>" , routineName , modelMin ) ; maxBlock = setUpExtremaModel ( "<STR_LIT>" , routineName , modelMax ) ; } private BlockMathMinmax setUpExtremaModel ( String op , String routineName , Model _model ) throws Exception { Signal _outputSignal ; Signal _value1Signal ; Signal _value2Signal ; String _value1SignalID ; String _value2SignalID ; BlockInput _input1Block ; BlockInput _input2Block ; BlockOutput _outputBlock ; BlockMathMinmax _block ; VectorInfoArrayList _inputVector ; VectorInfoArrayList _outputVector ; _value1SignalID = "<STR_LIT>" ; _value2SignalID = "<STR_LIT>" ; _value1Signal = new Signal ( "<STR_LIT>" , _value1SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value2Signal = new Signal ( "<STR_LIT>" , _value2SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _input1Block = new BlockInput ( _value1Signal , _model ) ; _input2Block = new BlockInput ( _value2Signal , _model ) ; _outputSignal = new Signal ( "<STR_LIT>" , _model ) ; _outputBlock = new BlockOutput ( _outputSignal , _model ) ; Element theValue1 = new Element ( "<STR_LIT>" ) ; theValue1 . addContent ( "<STR_LIT>" ) ; Element theValue2 = new Element ( "<STR_LIT>" ) ; theValue2 . addContent ( "<STR_LIT>" ) ; Element theMaxElement = new Element ( op ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( theMaxElement ) ; applyElement . addContent ( theValue1 ) ; applyElement . addContent ( theValue2 ) ; _block = new BlockMathMinmax ( applyElement , _model ) ; _block . addInput ( _value1Signal , <NUM_LIT:1> ) ; _block . addInput ( _value2Signal , <NUM_LIT:2> ) ; _block . addOutput ( _outputSignal ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName ) ; } _inputVector = _model . getInputVector ( ) ; assert ( _inputVector != null ) ; assertEquals ( <NUM_LIT:2> , _inputVector . size ( ) ) ; VectorInfo _input1 = _inputVector . get ( <NUM_LIT:0> ) ; assert ( _input1 != null ) ; _input1 . setValue ( "<STR_LIT:2.0>" ) ; VectorInfo _input2 = _inputVector . get ( <NUM_LIT:1> ) ; assert ( _input2 != null ) ; _input2 . setValue ( "<STR_LIT>" ) ; _model . hookUpIO ( ) ; _outputVector = _model . getOutputVector ( ) ; assert ( _outputVector != null ) ; try { _model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + op + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } return _block ; } public void testDescribeSelfWriter ( ) { testDescribeSelf ( "<STR_LIT>" , maxBlock , "<STR_LIT:2.0>" ) ; testDescribeSelf ( "<STR_LIT>" , minBlock , "<STR_LIT>" ) ; } private void testDescribeSelf ( String op , BlockMathMinmax block , String valString ) { StringWriter writer = new StringWriter ( ) ; try { block . describeSelf ( writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + op + "<STR_LIT>" + "<STR_LIT>" + valString + "<STR_LIT>" , writer . toString ( ) ) ; } public void testGetValue ( ) { assertEquals ( <NUM_LIT> , maxBlock . getValue ( ) , EPS ) ; assertEquals ( - <NUM_LIT> , minBlock . getValue ( ) , EPS ) ; } public void testIsReady ( ) { assertTrue ( maxBlock . isReady ( ) ) ; assertTrue ( minBlock . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( maxBlock . allInputsReady ( ) ) ; assertTrue ( minBlock . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( maxBlock . isVerbose ( ) ) ; maxBlock . makeVerbose ( ) ; assertTrue ( maxBlock . isVerbose ( ) ) ; maxBlock . silence ( ) ; assertFalse ( maxBlock . isVerbose ( ) ) ; } public void testGetName ( ) { assertEquals ( "<STR_LIT>" , maxBlock . getName ( ) ) ; assertEquals ( "<STR_LIT>" , minBlock . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , maxBlock . getType ( ) ) ; assertEquals ( "<STR_LIT>" , minBlock . getType ( ) ) ; } public void testGetVarID ( ) { assertEquals ( "<STR_LIT>" , maxBlock . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , maxBlock . getVarID ( <NUM_LIT:2> ) ) ; } public void testGetVarIDIterator ( ) { String name ; Iterator < String > it = maxBlock . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , maxBlock . getOutputVarID ( ) ) ; assertEquals ( "<STR_LIT>" , minBlock . getOutputVarID ( ) ) ; } public void testSetName ( ) { maxBlock . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , maxBlock . getName ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:2> , maxBlock . numInputs ( ) ) ; assertEquals ( <NUM_LIT:2> , minBlock . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:2> , maxBlock . numVarIDs ( ) ) ; assertEquals ( <NUM_LIT:2> , minBlock . numVarIDs ( ) ) ; } public void testUpdate ( ) { String routineName = "<STR_LIT>" ; checkMax ( modelMax , <NUM_LIT> , <NUM_LIT> , routineName ) ; checkMax ( modelMax , <NUM_LIT> , - <NUM_LIT> , routineName ) ; checkMax ( modelMax , <NUM_LIT> , - <NUM_LIT> , routineName ) ; checkMax ( modelMax , <NUM_LIT> , <NUM_LIT> , routineName ) ; checkMax ( modelMax , - <NUM_LIT> , - <NUM_LIT> , routineName ) ; checkMin ( modelMin , <NUM_LIT> , <NUM_LIT> , routineName ) ; checkMin ( modelMin , <NUM_LIT> , - <NUM_LIT> , routineName ) ; checkMin ( modelMin , <NUM_LIT> , - <NUM_LIT> , routineName ) ; checkMin ( modelMin , <NUM_LIT> , <NUM_LIT> , routineName ) ; checkMin ( modelMin , - <NUM_LIT> , - <NUM_LIT> , routineName ) ; } private void checkMax ( Model model , Double n1 , Double n2 , String callingName ) { String routineName = callingName + "<STR_LIT>" ; VectorInfoArrayList inputs = null ; try { inputs = model . getInputVector ( ) ; Iterator < VectorInfo > it = inputs . iterator ( ) ; VectorInfo input1 = it . next ( ) ; VectorInfo input2 = it . next ( ) ; input1 . setValue ( n1 ) ; input2 . setValue ( n2 ) ; try { model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + n1 . toString ( ) + "<STR_LIT:U+002CU+0020>" + n2 . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } VectorInfoArrayList outputs = model . getOutputVector ( ) ; it = outputs . iterator ( ) ; VectorInfo output = it . next ( ) ; assertEquals ( Math . max ( n1 , n2 ) , output . getValue ( ) ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } } private void checkMin ( Model model , Double n1 , Double n2 , String callingName ) { String routineName = callingName + "<STR_LIT>" ; VectorInfoArrayList inputs = null ; try { inputs = model . getInputVector ( ) ; Iterator < VectorInfo > it = inputs . iterator ( ) ; VectorInfo input1 = it . next ( ) ; VectorInfo input2 = it . next ( ) ; input1 . setValue ( n1 ) ; input2 . setValue ( n2 ) ; try { model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + n1 . toString ( ) + "<STR_LIT:U+002CU+0020>" + n2 . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } VectorInfoArrayList outputs = model . getOutputVector ( ) ; it = outputs . iterator ( ) ; VectorInfo output = it . next ( ) ; assertEquals ( Math . min ( n1 , n2 ) , output . getValue ( ) ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } } } </s>
<s> package gov . nasa . daveml . dave ; import junit . framework . * ; public class BlockArrayListTest extends TestCase { private Signal _fs ; private BlockInput _bi ; private BlockMathConstant _b1 ; private BlockMathConstant _b2 ; private BlockMathConstant _b3 ; private Model _m ; private BlockArrayList _bal ; protected void setUp ( ) throws Exception { _m = new Model ( <NUM_LIT:2> , <NUM_LIT:2> ) ; _fs = new Signal ( ) ; _bi = new BlockInput ( _fs , _m ) ; _b1 = new BlockMathConstant ( "<STR_LIT:1>" , _m ) ; _b2 = new BlockMathConstant ( "<STR_LIT:2>" , _m ) ; _b3 = new BlockMathConstant ( "<STR_LIT:3>" , _m ) ; _bal = new BlockArrayList ( <NUM_LIT:3> ) ; } public void testConstructor ( ) throws Exception { assertEquals ( <NUM_LIT:0> , _bal . size ( ) ) ; assertTrue ( _bal . isEmpty ( ) ) ; try { _bal . get ( <NUM_LIT:0> ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception e ) { } } public void testAddToList ( ) { _bal . add ( _b1 ) ; assertEquals ( <NUM_LIT:1> , _bal . size ( ) ) ; assertTrue ( _bal . contains ( _b1 ) ) ; assertFalse ( _bal . contains ( _b2 ) ) ; assertFalse ( _bal . contains ( _b3 ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:0> ) ) ; try { _bal . get ( <NUM_LIT:1> ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception e ) { } try { _bal . get ( <NUM_LIT:2> ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception e ) { } _bal . add ( _b2 ) ; assertEquals ( <NUM_LIT:2> , _bal . size ( ) ) ; assertTrue ( _bal . contains ( _b1 ) ) ; assertTrue ( _bal . contains ( _b2 ) ) ; assertFalse ( _bal . contains ( _b3 ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:0> ) ) ; assertEquals ( _b2 , _bal . get ( <NUM_LIT:1> ) ) ; try { _bal . get ( <NUM_LIT:2> ) ; fail ( "<STR_LIT>" ) ; } catch ( Exception e ) { } _bal . add ( _b3 ) ; assertEquals ( <NUM_LIT:3> , _bal . size ( ) ) ; assertTrue ( _bal . contains ( _b1 ) ) ; assertTrue ( _bal . contains ( _b2 ) ) ; assertTrue ( _bal . contains ( _b3 ) ) ; assertFalse ( _bal . contains ( _bi ) ) ; assertEquals ( <NUM_LIT:0> , _bal . indexOf ( _b1 ) ) ; assertEquals ( <NUM_LIT:1> , _bal . indexOf ( _b2 ) ) ; assertEquals ( <NUM_LIT:2> , _bal . indexOf ( _b3 ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:0> ) ) ; assertEquals ( _b2 , _bal . get ( <NUM_LIT:1> ) ) ; assertEquals ( _b3 , _bal . get ( <NUM_LIT:2> ) ) ; } public void testAdd4BlkTo3BlkList ( ) { _bal . add ( _b1 ) ; _bal . add ( _b2 ) ; _bal . add ( _b3 ) ; _bal . add ( _bi ) ; assertEquals ( <NUM_LIT:4> , _bal . size ( ) ) ; assertTrue ( _bal . contains ( _b1 ) ) ; assertTrue ( _bal . contains ( _b2 ) ) ; assertTrue ( _bal . contains ( _b3 ) ) ; assertTrue ( _bal . contains ( _bi ) ) ; assertEquals ( <NUM_LIT:0> , _bal . indexOf ( _b1 ) ) ; assertEquals ( <NUM_LIT:1> , _bal . indexOf ( _b2 ) ) ; assertEquals ( <NUM_LIT:2> , _bal . indexOf ( _b3 ) ) ; assertEquals ( <NUM_LIT:3> , _bal . indexOf ( _bi ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:0> ) ) ; assertEquals ( _b2 , _bal . get ( <NUM_LIT:1> ) ) ; assertEquals ( _b3 , _bal . get ( <NUM_LIT:2> ) ) ; assertEquals ( _bi , _bal . get ( <NUM_LIT:3> ) ) ; } public void testAddDuptoBlkList ( ) { _bal . add ( _b1 ) ; _bal . add ( _b2 ) ; _bal . add ( _b1 ) ; _bal . add ( _b2 ) ; assertEquals ( <NUM_LIT:4> , _bal . size ( ) ) ; assertTrue ( _bal . contains ( _b1 ) ) ; assertTrue ( _bal . contains ( _b2 ) ) ; assertFalse ( _bal . contains ( _b3 ) ) ; assertFalse ( _bal . contains ( _bi ) ) ; assertEquals ( <NUM_LIT:0> , _bal . indexOf ( _b1 ) ) ; assertEquals ( <NUM_LIT:1> , _bal . indexOf ( _b2 ) ) ; assertEquals ( <NUM_LIT:2> , _bal . lastIndexOf ( _b1 ) ) ; assertEquals ( <NUM_LIT:3> , _bal . lastIndexOf ( _b2 ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:0> ) ) ; assertEquals ( _b2 , _bal . get ( <NUM_LIT:1> ) ) ; assertEquals ( _b1 , _bal . get ( <NUM_LIT:2> ) ) ; assertEquals ( _b2 , _bal . get ( <NUM_LIT:3> ) ) ; } public static Test suite ( ) { return new TestSuite ( BlockArrayListTest . class ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Iterator ; import junit . framework . TestCase ; public class ParseTextTest extends TestCase { protected final double EPS = <NUM_LIT> ; protected ParseText pt ; protected void setUp ( ) throws Exception { super . setUp ( ) ; pt = new ParseText ( "<STR_LIT>" ) ; } public void testNext ( ) { try { assertEquals ( - <NUM_LIT> , pt . next ( ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertFalse ( pt . eof ( ) ) ; assertTrue ( pt . validNumber ( ) ) ; try { assertEquals ( <NUM_LIT> , pt . next ( ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertFalse ( pt . eof ( ) ) ; assertTrue ( pt . validNumber ( ) ) ; try { assertEquals ( <NUM_LIT> , pt . next ( ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertFalse ( pt . eof ( ) ) ; assertTrue ( pt . validNumber ( ) ) ; try { assertEquals ( <NUM_LIT> , pt . next ( ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertFalse ( pt . eof ( ) ) ; assertTrue ( pt . validNumber ( ) ) ; try { assertEquals ( Double . NaN , pt . next ( ) ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertTrue ( pt . eof ( ) ) ; assertFalse ( pt . validNumber ( ) ) ; } public void testBadList1 ( ) { double value = <NUM_LIT:0> ; ParseText badList = new ParseText ( "<STR_LIT>" ) ; assertNotNull ( badList ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( Double . NaN , value ) ; assertFalse ( badList . goodNumber ) ; assertFalse ( badList . validNumber ( ) ) ; assertTrue ( badList . eof ( ) ) ; } public void testBadList2 ( ) { double value = <NUM_LIT:0> ; ParseText badList = new ParseText ( "<STR_LIT>" ) ; assertNotNull ( badList ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( Double . NaN , value ) ; assertFalse ( badList . goodNumber ) ; assertFalse ( badList . validNumber ( ) ) ; assertTrue ( badList . eof ( ) ) ; } public void testBadList3 ( ) { double value = <NUM_LIT:0> ; ParseText badList = new ParseText ( "<STR_LIT>" ) ; assertNotNull ( badList ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( Double . NaN , value ) ; assertFalse ( badList . goodNumber ) ; assertFalse ( badList . validNumber ( ) ) ; assertTrue ( badList . eof ( ) ) ; } public void testBadList4 ( ) { double value = <NUM_LIT:0> ; ParseText badList = new ParseText ( "<STR_LIT>" ) ; assertNotNull ( badList ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT> , value ) ; assertTrue ( badList . validNumber ( ) ) ; assertFalse ( badList . eof ( ) ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( Double . NaN , value ) ; assertFalse ( badList . goodNumber ) ; assertFalse ( badList . validNumber ( ) ) ; assertTrue ( badList . eof ( ) ) ; } public void testBadList5 ( ) { double value = <NUM_LIT:0> ; ParseText badList = new ParseText ( "<STR_LIT>" ) ; assertNotNull ( badList ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT> , value ) ; assertTrue ( badList . validNumber ( ) ) ; assertFalse ( badList . eof ( ) ) ; try { value = badList . next ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( Double . NaN , value ) ; assertFalse ( badList . goodNumber ) ; assertFalse ( badList . validNumber ( ) ) ; assertTrue ( badList . eof ( ) ) ; } public void testToList ( ) { ArrayList < Double > theList = null ; try { theList = pt . toList ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertNotNull ( theList ) ; Iterator < Double > it = theList . iterator ( ) ; assertNotNull ( it ) ; assertTrue ( it . hasNext ( ) ) ; assertEquals ( - <NUM_LIT> , it . next ( ) ) ; assertTrue ( it . hasNext ( ) ) ; assertEquals ( <NUM_LIT> , it . next ( ) ) ; assertTrue ( it . hasNext ( ) ) ; assertEquals ( <NUM_LIT> , it . next ( ) ) ; assertTrue ( it . hasNext ( ) ) ; assertEquals ( <NUM_LIT> , it . next ( ) ) ; assertFalse ( it . hasNext ( ) ) ; } public void testToListString ( ) { ArrayList < Double > answers = new ArrayList < Double > ( <NUM_LIT:2> ) ; answers . add ( - <NUM_LIT> ) ; answers . add ( <NUM_LIT> ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; answers . add ( - <NUM_LIT> ) ; compareStringToList ( "<STR_LIT>" , answers ) ; compareStringToList ( "<STR_LIT>" , answers ) ; } protected void compareStringToList ( String string , ArrayList < Double > expectedValues ) { ArrayList < Double > theList = null ; try { theList = ParseText . toList ( string ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + string + "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( expectedValues . size ( ) , theList . size ( ) ) ; Iterator < Double > it = theList . iterator ( ) ; assertNotNull ( it ) ; Iterator < Double > ev_it = expectedValues . iterator ( ) ; while ( ev_it . hasNext ( ) ) { assertTrue ( it . hasNext ( ) ) ; assertEquals ( ev_it . next ( ) , it . next ( ) , EPS ) ; } assertFalse ( it . hasNext ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import junit . framework . TestCase ; public class BlockBPTest extends TestCase { protected Model _model ; protected BreakpointSet _bps ; protected BlockBP _bpb ; protected Signal _inSig ; protected Signal _outSig ; protected BlockMathConstant _sourceBlock ; private StringWriter _writer ; private final Double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _writer = new StringWriter ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _inSig = new Signal ( "<STR_LIT>" , _model ) ; _outSig = new Signal ( "<STR_LIT>" , _model ) ; _sourceBlock = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _sourceBlock . addOutput ( _inSig ) ; try { _bps = new BreakpointSet ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , _model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _bpb = new BlockBP ( "<STR_LIT>" , "<STR_LIT>" , _inSig , _outSig , _model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public void testBlockBP ( ) { assertNotNull ( _bpb ) ; } public void testUpdate ( ) { tryBPBupdate ( ) ; assertEquals ( <NUM_LIT> , _bpb . getValue ( ) , EPS ) ; _sourceBlock . setValue ( <NUM_LIT:0.0> ) ; tryBPBupdate ( ) ; assertEquals ( <NUM_LIT> , _bpb . getValue ( ) , EPS ) ; _sourceBlock . setValue ( - <NUM_LIT> ) ; tryBPBupdate ( ) ; assertEquals ( <NUM_LIT> , _bpb . getValue ( ) , EPS ) ; _sourceBlock . setValue ( <NUM_LIT> ) ; tryBPBupdate ( ) ; assertEquals ( <NUM_LIT> , _bpb . getValue ( ) , EPS ) ; } public void testGetBPID ( ) { assertEquals ( "<STR_LIT>" , _bpb . getBPID ( ) ) ; } public void testLength ( ) { assertEquals ( <NUM_LIT:12> , _bpb . length ( ) ) ; } public void testGetBPset ( ) { assertEquals ( _bps , _bpb . getBPset ( ) ) ; } public void testDescribeSelfFileWriter ( ) { try { _bpb . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } protected void tryBPBupdate ( ) { try { _bpb . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . Arrays ; import java . util . Collection ; import junit . framework . TestCase ; public class VectorInfoArrayListTest extends TestCase { protected void setUp ( ) throws Exception { super . setUp ( ) ; } public void testVectorInfoArrayList ( ) { VectorInfoArrayList vial = new VectorInfoArrayList ( ) ; assertNotNull ( vial ) ; } public void testVectorInfoArrayListInt ( ) { VectorInfoArrayList vial = new VectorInfoArrayList ( <NUM_LIT> ) ; assertNotNull ( vial ) ; } public void testVectorInfoArrayListCollectionOfVectorInfo ( ) { VectorInfo vi1 = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; VectorInfo vi2 = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; VectorInfo vi3 = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , false ) ; Collection < VectorInfo > c = Arrays . asList ( vi1 , vi2 , vi3 ) ; VectorInfoArrayList vial = new VectorInfoArrayList ( c ) ; assertNotNull ( vial ) ; assertEquals ( <NUM_LIT:3> , vial . size ( ) ) ; VectorInfo vi = vial . get ( <NUM_LIT:0> ) ; assertNotNull ( vi ) ; assertEquals ( "<STR_LIT>" , vi . getName ( ) ) ; vi = vial . get ( <NUM_LIT:1> ) ; assertNotNull ( vi ) ; assertEquals ( "<STR_LIT>" , vi . getName ( ) ) ; vi = vial . get ( <NUM_LIT:2> ) ; assertNotNull ( vi ) ; assertEquals ( "<STR_LIT>" , vi . getName ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import junit . framework . * ; public class ModelTest extends TestCase { Model _simple ; protected void setUp ( ) { _simple = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; } public void testName ( ) { assertTrue ( _simple . getName ( ) == "<STR_LIT>" ) ; _simple . setName ( "<STR_LIT>" ) ; assertTrue ( _simple . getName ( ) == "<STR_LIT>" ) ; } public void testCycleCounter ( ) { assertTrue ( _simple . getCycleCounter ( ) == <NUM_LIT:0> ) ; _simple . incrementCycleCounter ( ) ; assertTrue ( _simple . getCycleCounter ( ) == <NUM_LIT:1> ) ; _simple . resetCycleCounter ( ) ; assertTrue ( _simple . getCycleCounter ( ) == <NUM_LIT:0> ) ; } public void testVerboseFlag ( ) { assertFalse ( _simple . isVerbose ( ) ) ; _simple . makeVerbose ( ) ; assertTrue ( _simple . isVerbose ( ) ) ; } public void testAddBlocks ( ) { Signal s = new Signal ( "<STR_LIT>" , _simple ) ; assertTrue ( _simple . getNumInputBlocks ( ) == <NUM_LIT:0> ) ; assertTrue ( _simple . getNumOutputBlocks ( ) == <NUM_LIT:0> ) ; new BlockInput ( s , _simple ) ; assertTrue ( _simple . getNumInputBlocks ( ) == <NUM_LIT:1> ) ; assertTrue ( _simple . getNumOutputBlocks ( ) == <NUM_LIT:0> ) ; new BlockOutput ( s , _simple ) ; assertTrue ( _simple . getNumInputBlocks ( ) == <NUM_LIT:1> ) ; assertTrue ( _simple . getNumOutputBlocks ( ) == <NUM_LIT:1> ) ; } public static Test suite ( ) { return new TestSuite ( ModelTest . class ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockFuncTableTest extends TestCase { protected Model _model ; protected BreakpointSet _bpAlpha1 ; protected BreakpointSet _bpDe1 ; protected BlockBP _alpha1BpBlock ; protected BlockBP _de1BpBlock ; protected Signal _alphaSig ; protected Signal _deSig ; protected Signal _alphaIndexOffsetSig ; protected Signal _deIndexOffsetSig ; protected Signal _cmtSig ; protected BlockMathConstant _alphaSourceBlock ; protected BlockMathConstant _deSourceBlock ; protected BlockFuncTable _bft ; private StringWriter _writer ; private final Double EPS = <NUM_LIT> ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _writer = new StringWriter ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _alphaSig = new Signal ( "<STR_LIT>" , _model ) ; _deSig = new Signal ( "<STR_LIT>" , _model ) ; _cmtSig = new Signal ( "<STR_LIT>" , _model ) ; _alphaSourceBlock = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _deSourceBlock = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _alphaSourceBlock . addOutput ( _alphaSig ) ; _deSourceBlock . addOutput ( _deSig ) ; _bpAlpha1 = BreakpointSetTest . generateSampleAlphaBreakpointSet ( _model ) ; _bpDe1 = BreakpointSetTest . generateSampleElevBreakpointSet ( _model ) ; Element functionElement = generateExampleBlockFuncTableDOM ( ) ; _bft = new BlockFuncTable ( functionElement , _model ) ; _deIndexOffsetSig = _bft . getInput ( <NUM_LIT:0> ) ; _alphaIndexOffsetSig = _bft . getInput ( <NUM_LIT:1> ) ; _de1BpBlock = ( BlockBP ) _deIndexOffsetSig . getSource ( ) ; _alpha1BpBlock = ( BlockBP ) _alphaIndexOffsetSig . getSource ( ) ; } public void testUpdate ( ) { try { _model . initialize ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } assertTrue ( _bft . isReady ( ) ) ; try { _bft . update ( ) ; } catch ( DAVEException e2 ) { fail ( "<STR_LIT>" + e2 . getMessage ( ) ) ; } assertEquals ( - <NUM_LIT> , _bft . getValue ( ) , EPS ) ; checkFuncValue ( - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> ) ; checkFuncValue ( - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; checkFuncValue ( <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> ) ; } private void checkFuncValue ( Double alpha , Double de , Double expectedValue ) { _alphaSourceBlock . setValue ( alpha ) ; _deSourceBlock . setValue ( de ) ; try { _alpha1BpBlock . update ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + e1 . getMessage ( ) ) ; } try { _de1BpBlock . update ( ) ; } catch ( DAVEException e2 ) { fail ( "<STR_LIT>" + e2 . getMessage ( ) ) ; } try { _bft . update ( ) ; } catch ( DAVEException e3 ) { fail ( "<STR_LIT>" + e3 . getMessage ( ) ) ; } assertEquals ( expectedValue , _bft . getValue ( ) , EPS ) ; } public void testBlockFuncTableElementModel ( ) { assertNotNull ( _bft ) ; assertEquals ( <NUM_LIT:2> , _bft . numInputs ( ) ) ; assertEquals ( "<STR_LIT>" , _bft . getOutputVarID ( ) ) ; } public void testBlockFuncTableBlockFuncTable ( ) { } public void testGetFunctionTableDef ( ) { FuncTable gft = _bft . getFunctionTableDef ( ) ; assertNotNull ( gft ) ; } public void testParseSimpleFunction ( ) { } public void testPrintTableWriter ( ) { int expectedLines = <NUM_LIT:5> ; int expectedLength = <NUM_LIT> ; StringWriter writer = new StringWriter ( ) ; StringBuffer buffer ; String osName = System . getProperty ( "<STR_LIT>" ) ; assertNotNull ( writer ) ; try { _bft . printTable ( writer ) ; buffer = writer . getBuffer ( ) ; if ( osName . contains ( "<STR_LIT>" ) ) { expectedLength += expectedLines ; } assertEquals ( expectedLength , buffer . length ( ) ) ; String [ ] lines = buffer . toString ( ) . split ( System . getProperty ( "<STR_LIT>" ) ) ; assertEquals ( expectedLines , lines . length ) ; assertNotNull ( lines [ <NUM_LIT:0> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:0> ] ) ; assertNotNull ( lines [ <NUM_LIT:1> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:1> ] ) ; assertNotNull ( lines [ <NUM_LIT:2> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:2> ] ) ; assertNotNull ( lines [ <NUM_LIT:3> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:3> ] ) ; assertNotNull ( lines [ <NUM_LIT:4> ] ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , lines [ <NUM_LIT:4> ] ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public void testGetDescription ( ) { String descr = _bft . getDescription ( ) ; assertEquals ( "<STR_LIT>" , descr ) ; } public void testDescribeSelf ( ) { try { _bft . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } String str = _writer . toString ( ) ; assertNotNull ( str ) ; assertEquals ( <NUM_LIT> , str . length ( ) ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" , str ) ; } public static Element generateExampleBlockFuncTableDOM ( ) { Element griddedTableDef = FuncTableTest . generateSampleGriddedTableDefDOM ( ) ; Element funcDefn = new Element ( "<STR_LIT>" ) ; funcDefn . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; funcDefn . addContent ( griddedTableDef ) ; Element iVarRef1 = new Element ( "<STR_LIT>" ) ; iVarRef1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef1 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element iVarRef2 = new Element ( "<STR_LIT>" ) ; iVarRef2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; iVarRef2 . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element dVarRef = new Element ( "<STR_LIT>" ) ; dVarRef . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Element descriptionElement = new Element ( "<STR_LIT:description>" ) ; descriptionElement . addContent ( "<STR_LIT>" + System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" ) ; Element functionElement = new Element ( "<STR_LIT>" ) ; functionElement . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; functionElement . addContent ( descriptionElement ) ; functionElement . addContent ( iVarRef1 ) ; functionElement . addContent ( iVarRef2 ) ; functionElement . addContent ( dVarRef ) ; functionElement . addContent ( funcDefn ) ; return functionElement ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathRelationTest extends TestCase { protected Model _model ; protected Signal _outputSignal ; protected Signal _value1Signal ; protected Signal _value2Signal ; protected String _value1SignalID ; protected String _value2SignalID ; protected BlockMathConstant _value1Block ; protected BlockMathConstant _value2Block ; protected BlockMathRelation _block ; private StringWriter _writer ; protected String routineName = "<STR_LIT>" ; private final double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; String theRoutineName = "<STR_LIT>" ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _value1Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value2Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value1SignalID = "<STR_LIT>" ; _value2SignalID = "<STR_LIT>" ; _value1Signal = new Signal ( "<STR_LIT>" , _value1SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value2Signal = new Signal ( "<STR_LIT>" , _value2SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value1Block . addOutput ( _value1Signal ) ; _value2Block . addOutput ( _value2Signal ) ; _outputSignal = new Signal ( "<STR_LIT>" , _model ) ; Element theValue1 = new Element ( "<STR_LIT>" ) ; theValue1 . addContent ( "<STR_LIT>" ) ; Element theValue2 = new Element ( "<STR_LIT>" ) ; theValue2 . addContent ( "<STR_LIT>" ) ; Element theTimesElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( theTimesElement ) ; applyElement . addContent ( theValue1 ) ; applyElement . addContent ( theValue2 ) ; _block = new BlockMathRelation ( applyElement , _model ) ; _block . addInput ( _value1Signal , <NUM_LIT:1> ) ; _block . addInput ( _value2Signal , <NUM_LIT:2> ) ; _block . addOutput ( _outputSignal ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + theRoutineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } } public final void testGetSetValidateUpdateRelation ( ) { try { _model . getInputVector ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" + routineName ) ; } assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( - <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertTrue ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , false ) ) ; assertEquals ( "<STR_LIT>" , _block . getRelationOp ( ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , true ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT>" , <NUM_LIT> , true ) ) ; assertFalse ( checkRelation ( <NUM_LIT> , "<STR_LIT:-->" , <NUM_LIT> , true ) ) ; } public final void testBlockMathRelation ( ) { assertNotNull ( _block ) ; assertEquals ( <NUM_LIT:1> , _block . getValue ( ) , EPS ) ; } public void testGenCcode ( ) { CodeAndVarNames cvn ; String expected ; _model . setCodeDialect ( Model . DT_ANSI_C ) ; _block . getOutput ( ) . setDerivedFlag ( ) ; cvn = _block . genCode ( ) ; expected = "<STR_LIT>" ; assertEquals ( expected , cvn . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , cvn . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:1> ) ) ; _block . getOutput ( ) . clearDerivedFlag ( ) ; cvn = _block . genCode ( ) ; expected = "<STR_LIT>" + expected + "<STR_LIT>" ; assertEquals ( expected , cvn . getCode ( ) ) ; assertEquals ( <NUM_LIT:3> , cvn . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:2> ) ) ; } public void testGenFcode ( ) { CodeAndVarNames cvn ; String expected ; _model . setCodeDialect ( Model . DT_FORTRAN ) ; _block . getOutput ( ) . setDerivedFlag ( ) ; cvn = _block . genCode ( ) ; expected = "<STR_LIT>" ; assertEquals ( expected , cvn . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , cvn . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:1> ) ) ; _block . getOutput ( ) . clearDerivedFlag ( ) ; cvn = _block . genCode ( ) ; expected = "<STR_LIT>" + expected + "<STR_LIT:n>" ; assertEquals ( expected , cvn . getCode ( ) ) ; assertEquals ( <NUM_LIT:3> , cvn . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , cvn . getVarName ( <NUM_LIT:2> ) ) ; } public void testDescribeSelfFileWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } private boolean checkRelation ( Double n1 , String relation , Double n2 , boolean expectException ) { _value1Block . setValue ( n1 ) ; _value2Block . setValue ( n2 ) ; try { _block . setRelationOp ( relation ) ; } catch ( DAVEException e1 ) { if ( ! expectException ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + n1 . toString ( ) + "<STR_LIT:U+0020>" + relation + "<STR_LIT:U+0020>" + n2 . toString ( ) + "<STR_LIT>" + e1 . getMessage ( ) ) ; } } try { _model . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + n1 . toString ( ) + "<STR_LIT:U+0020>" + relation + "<STR_LIT:U+0020>" + n2 . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } return ( _block . getValue ( ) == <NUM_LIT:1> ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import junit . framework . TestCase ; import gov . nasa . daveml . dave . VectorInfo ; public class VectorInfoTest extends TestCase { protected VectorInfo _vi ; protected Model _model ; protected VectorInfoArrayList _inputs ; protected VectorInfoArrayList _outputs ; private final double EPS = <NUM_LIT> ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _vi = new VectorInfo ( ) ; _model = genSampleModel ( ) ; _inputs = _model . getInputVector ( ) ; _outputs = _model . getOutputVector ( ) ; } public void testVectorInfo ( ) { assertNotNull ( _vi ) ; assertEquals ( "<STR_LIT>" , _vi . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _vi . getUnits ( ) ) ; assertEquals ( null , _vi . getSource ( ) ) ; assertEquals ( null , _vi . getSink ( ) ) ; assertEquals ( Double . NaN , _vi . getValue ( ) ) ; assertEquals ( Double . NaN , _vi . getTolerance ( ) ) ; } public void testVectorInfoStringStringBlockBoolean ( ) { _vi = new VectorInfo ( "<STR_LIT>" , "<STR_LIT>" , null , true ) ; assertNotNull ( _vi ) ; assertEquals ( "<STR_LIT>" , _vi . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _vi . getUnits ( ) ) ; assertEquals ( null , _vi . getSource ( ) ) ; assertEquals ( null , _vi . getSink ( ) ) ; assertEquals ( Double . NaN , _vi . getValue ( ) ) ; assertEquals ( Double . NaN , _vi . getTolerance ( ) ) ; } public void testSetUnits ( ) { _vi . setUnits ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _vi . getUnits ( ) ) ; } public void testSetValueDouble ( ) { _vi . setValue ( - <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , _vi . getValue ( ) , EPS ) ; } public void testSetValueString ( ) { _vi . setValue ( "<STR_LIT>" ) ; assertEquals ( - <NUM_LIT> , _vi . getValue ( ) , EPS ) ; } public void testSetToleranceDouble ( ) { _vi . setTolerance ( - <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , _vi . getTolerance ( ) , EPS ) ; } public void testSetToleranceString ( ) { _vi . setTolerance ( "<STR_LIT>" ) ; assertEquals ( - <NUM_LIT> , _vi . getTolerance ( ) , EPS ) ; } public void testIsInput ( ) { assertNotNull ( _inputs ) ; VectorInfo input0 = _inputs . get ( <NUM_LIT:0> ) ; assertTrue ( input0 . isInput ( ) ) ; } public void testGetSource ( ) { VectorInfo output0 = _outputs . get ( <NUM_LIT:0> ) ; assertFalse ( output0 . isInput ( ) ) ; BlockOutput outblk = output0 . getSource ( ) ; assertNotNull ( outblk ) ; assertEquals ( "<STR_LIT>" , outblk . getType ( ) ) ; } public void testGetSink ( ) { VectorInfo input0 = _inputs . get ( <NUM_LIT:0> ) ; BlockInput inblk = input0 . getSink ( ) ; assertNotNull ( inblk ) ; assertEquals ( "<STR_LIT>" , inblk . getType ( ) ) ; } protected Model genSampleModel ( ) { Element theValue = new Element ( "<STR_LIT>" ) ; theValue . addContent ( "<STR_LIT>" ) ; Element minus = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( minus ) ; applyElement . addContent ( theValue ) ; Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; Signal in = new Signal ( "<STR_LIT>" , m ) ; Signal out = new Signal ( "<STR_LIT>" , m ) ; new BlockInput ( in , m ) ; new BlockOutput ( out , m ) ; Block gain = new BlockMathMinus ( applyElement , m ) ; try { gain . addOutput ( out ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { gain . hookUp ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } return m ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import junit . framework . TestCase ; public class BlockOutputTest extends TestCase { private Model _model ; private String _signalID ; private Signal _signal ; private BlockMathConstant _constBlock ; private BlockOutput _block ; protected StringWriter _writer ; private final double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _writer = new StringWriter ( ) ; _model = new Model ( <NUM_LIT:4> , <NUM_LIT:4> ) ; _signalID = "<STR_LIT>" ; _signal = new Signal ( _signalID , _model ) ; _constBlock = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _constBlock . addOutput ( _signal ) ; assertNotNull ( _constBlock ) ; _model . hookUpIO ( ) ; assertTrue ( _signal . hasDest ( ) ) ; BlockArrayList destBlocks = _signal . getDests ( ) ; assertNotNull ( destBlocks ) ; assertEquals ( <NUM_LIT:1> , destBlocks . size ( ) ) ; Block destBlock = destBlocks . get ( <NUM_LIT:0> ) ; assertNotNull ( destBlock ) ; assertEquals ( "<STR_LIT>" , destBlock . getType ( ) ) ; _block = ( BlockOutput ) destBlock ; assertEquals ( Double . NaN , _block . getValue ( ) ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public void testGetValue ( ) { assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; } public void testUpdate ( ) { try { _model . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _model . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; _constBlock . setValue ( "<STR_LIT>" ) ; try { _model . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; assertEquals ( - <NUM_LIT> , _block . getValue ( ) , EPS ) ; } } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , cvn . getCode ( ) ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , cvn . getCode ( ) ) ; } public void testGetUnits ( ) { assertEquals ( "<STR_LIT>" , _block . getUnits ( ) ) ; } public void testGetSeqNumber ( ) { assertEquals ( <NUM_LIT:1> , _block . getSeqNumber ( ) ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . util . ArrayList ; public class BlockMathFunctionExtensionTest extends BlockMathFunctionTest { final double piOver4 = Math . PI / <NUM_LIT> ; protected void setUp ( ) throws Exception { super . setUp ( ) ; instantiateAtan2Function ( <NUM_LIT> , <NUM_LIT> ) ; } public void testBlockMathFunction_ctor ( ) { instantiateAtan2Function ( <NUM_LIT:0.0> , <NUM_LIT> ) ; assertEquals ( <NUM_LIT:0.0> , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( <NUM_LIT> , <NUM_LIT> ) ; assertEquals ( <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( <NUM_LIT> , <NUM_LIT:0.0> ) ; assertEquals ( <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( <NUM_LIT> , - <NUM_LIT> ) ; assertEquals ( <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( <NUM_LIT:0.0> , - <NUM_LIT> ) ; assertEquals ( <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( - <NUM_LIT> , <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( - <NUM_LIT> , <NUM_LIT:0.0> ) ; assertEquals ( - <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( - <NUM_LIT> , - <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> * piOver4 , _block . getValue ( ) , EPS ) ; instantiateAtan2Function ( <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ; assertEquals ( <NUM_LIT:0.0> , _block . getValue ( ) , EPS ) ; } public void testUpdate ( ) { updateExistingBlock ( "<STR_LIT>" , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:0.0> ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT:0.0> , - <NUM_LIT> , <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , <NUM_LIT> , - <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , <NUM_LIT:0.0> , - <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> * piOver4 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) ; } public void updateExistingBlock ( String func , double arg1 , double arg2 , double expectedValue ) { BlockMathConstant constBlk = null ; constBlk = getUpstreamConstBlk1 ( ) ; constBlk . setValue ( arg1 ) ; constBlk = getUpstreamConstBlk2 ( ) ; constBlk . setValue ( arg2 ) ; try { _block . setFunction ( func ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _block . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( expectedValue , _block . getValue ( ) , EPS ) ; } protected void instantiateAtan2Function ( double argument1 , double argument2 ) { String csymbol = "<STR_LIT>" ; String attrName1 = "<STR_LIT>" ; String attrValue1 = "<STR_LIT>" ; String attrName2 = "<STR_LIT>" ; String attrValue2 = "<STR_LIT:text>" ; String extFuncName = "<STR_LIT>" ; ArrayList < Double > args = new ArrayList < Double > ( ) ; boolean expectException = false ; args . add ( argument1 ) ; args . add ( argument2 ) ; instantiateFunction ( csymbol , "<STR_LIT>" , attrName1 , attrValue1 , attrName2 , attrValue2 , extFuncName , args , expectException ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathSwitch2Test extends TestCase { protected Model _model ; private StringWriter _writer ; protected BlockMathSwitch _block ; protected BlockMathConstant _inputBlock ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _block = generateSampleSwitch ( _model ) ; SignalArrayList theSignals = _model . getSignals ( ) ; Signal inputSignal = theSignals . findByID ( "<STR_LIT>" ) ; assertNotNull ( inputSignal ) ; Block theBlock = inputSignal . getSource ( ) ; assertNotNull ( theBlock ) ; assertEquals ( "<STR_LIT>" , theBlock . myType ) ; _inputBlock = ( BlockMathConstant ) theBlock ; assertNotNull ( _inputBlock ) ; } public void testUpdate ( ) { assertNotNull ( _block ) ; String routineName = "<STR_LIT>" ; _model . wireBlocks ( ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:0.0> , checkSwitch ( - <NUM_LIT:0.0> ) ) ; assertEquals ( <NUM_LIT:0.0> , checkSwitch ( <NUM_LIT:0.0> ) ) ; assertEquals ( <NUM_LIT:0.0> , checkSwitch ( + <NUM_LIT:0.0> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; } private double checkSwitch ( Double switchVal ) { String routineName = "<STR_LIT>" ; _inputBlock . setValue ( switchVal ) ; try { _model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + switchVal . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } return _block . getValue ( ) ; } private void checkCode ( String code ) { Signal defaultInput = _block . inputs . get ( <NUM_LIT:2> ) ; defaultInput . setDefinedFlag ( ) ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( code , cvn . getCode ( ) ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT:U+0020U+0020>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; checkCode ( code ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; checkCode ( code ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public static BlockMathSwitch generateSampleSwitch ( Model model ) { Block swValueBlock ; String swValueSignalID ; Signal swValueSignal ; Signal outputSignal ; swValueBlock = new BlockMathConstant ( "<STR_LIT>" , model ) ; swValueSignalID = "<STR_LIT>" ; swValueSignal = new Signal ( "<STR_LIT>" , swValueSignalID , "<STR_LIT>" , <NUM_LIT:1> , model ) ; try { swValueBlock . addOutput ( swValueSignal ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } outputSignal = new Signal ( "<STR_LIT>" , model ) ; Element innerApply1 = new Element ( "<STR_LIT>" ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT:-1>" ) ) ; Element innerApply2 = new Element ( "<STR_LIT>" ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT:1>" ) ) ; Element piece1 = new Element ( "<STR_LIT>" ) ; piece1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT:-1>" ) ) ; piece1 . addContent ( innerApply1 ) ; Element piece2 = new Element ( "<STR_LIT>" ) ; piece2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT:1>" ) ) ; piece2 . addContent ( innerApply2 ) ; Element otherwise = new Element ( "<STR_LIT>" ) ; otherwise . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; Element piecewise = new Element ( "<STR_LIT>" ) ; piecewise . addContent ( piece1 ) ; piecewise . addContent ( piece2 ) ; piecewise . addContent ( otherwise ) ; Element outerApply = new Element ( "<STR_LIT>" ) ; outerApply . addContent ( piecewise ) ; BlockMathSwitch bms = null ; bms = new BlockMathSwitch ( outerApply , model ) ; try { bms . addOutput ( outputSignal ) ; model . wireBlocks ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + "<STR_LIT>" + e . getMessage ( ) ) ; } return bms ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import java . util . logging . Level ; import java . util . logging . Logger ; import junit . framework . * ; public class BlockMathConstantTest extends TestCase { protected Model _model ; protected BlockMathConstant _block ; protected Signal _outSig ; protected StringWriter _writer ; @ Override protected void setUp ( ) { _model = new Model ( ) ; _outSig = new Signal ( "<STR_LIT>" , _model ) ; _block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; try { _block . addOutput ( _outSig ) ; } catch ( DAVEException ex ) { Logger . getLogger ( BlockMathConstantTest . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } _writer = new StringWriter ( ) ; } public void testGetValue ( ) { assertTrue ( _block . getValue ( ) == - <NUM_LIT> ) ; } public void testSetValueString ( ) { _block . setValue ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) ) ; } public void testSetValueDouble ( ) { _block . setValue ( - <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , _block . getValue ( ) ) ; } public void testUpdate ( ) { _block . setValue ( <NUM_LIT> ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e1 ) { fail ( "<STR_LIT>" ) ; } try { _model . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" ) ; } assertEquals ( <NUM_LIT> , _block . getValue ( ) , <NUM_LIT> ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:1> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; } public void testDescribeSelf ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public void testIsReady ( ) { assertTrue ( _block . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _block . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( _block . isVerbose ( ) ) ; _block . makeVerbose ( ) ; assertTrue ( _block . isVerbose ( ) ) ; _block . silence ( ) ; assertFalse ( _block . isVerbose ( ) ) ; } public void testGetModel ( ) { assertEquals ( _model . getName ( ) , _block . getModel ( ) . getName ( ) ) ; } public void testGetSetName ( ) { assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; _block . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , _block . getType ( ) ) ; } public void testGetVarIDIterator ( ) { Iterator < String > it = _block . getVarIDIterator ( ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutput ( ) { Signal s = _block . getOutput ( ) ; assertEquals ( _outSig , s ) ; } public void getGetInputIterator ( ) { Iterator < Signal > it = _block . getInputIterator ( ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( _outSig . getVarID ( ) , _block . getOutputVarID ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:0> , _block . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:0> , _block . numVarIDs ( ) ) ; } public static Test suite ( ) { return new TestSuite ( BlockMathConstantTest . class ) ; } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathSumTest extends TestCase { protected Model _model ; protected Signal _outputSignal ; protected Signal _value1Signal ; protected Signal _value2Signal ; protected String _value1SignalID ; protected String _value2SignalID ; protected BlockMathConstant _value1Block ; protected BlockMathConstant _value2Block ; protected BlockMathSum _block ; private StringWriter _writer ; private final double EPS = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { String routineName = "<STR_LIT>" ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _value1Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value2Block = new BlockMathConstant ( "<STR_LIT>" , _model ) ; _value1SignalID = "<STR_LIT>" ; _value2SignalID = "<STR_LIT>" ; _value1Signal = new Signal ( "<STR_LIT>" , _value1SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value2Signal = new Signal ( "<STR_LIT>" , _value2SignalID , "<STR_LIT>" , <NUM_LIT:1> , _model ) ; _value1Block . addOutput ( _value1Signal ) ; _value2Block . addOutput ( _value2Signal ) ; _outputSignal = new Signal ( "<STR_LIT>" , _model ) ; Element theValue1 = new Element ( "<STR_LIT>" ) ; theValue1 . addContent ( "<STR_LIT>" ) ; Element theValue2 = new Element ( "<STR_LIT>" ) ; theValue2 . addContent ( "<STR_LIT>" ) ; Element thePlusElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( thePlusElement ) ; applyElement . addContent ( theValue1 ) ; applyElement . addContent ( theValue2 ) ; _block = new BlockMathSum ( applyElement , _model ) ; _block . addInput ( _value1Signal , <NUM_LIT:1> ) ; _block . addInput ( _value2Signal , <NUM_LIT:2> ) ; _block . addOutput ( _outputSignal ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName ) ; } } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result = _block . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; this . checkVarNames ( result ) ; } public void checkVarNames ( CodeAndVarNames result ) { assertEquals ( <NUM_LIT:3> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:2> ) ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public void testGetValue ( ) { assertEquals ( - <NUM_LIT> , _block . getValue ( ) , EPS ) ; } public void testIsReady ( ) { assertTrue ( _block . isReady ( ) ) ; } public void testAllInputsReady ( ) { assertTrue ( _block . allInputsReady ( ) ) ; } public void testMakeVerbose ( ) { assertFalse ( _block . isVerbose ( ) ) ; _block . makeVerbose ( ) ; assertTrue ( _block . isVerbose ( ) ) ; _block . silence ( ) ; assertFalse ( _block . isVerbose ( ) ) ; } public void testGetName ( ) { assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testGetType ( ) { assertEquals ( "<STR_LIT>" , _block . getType ( ) ) ; } public void testGetVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getVarID ( <NUM_LIT:1> ) ) ; assertEquals ( "<STR_LIT>" , _block . getVarID ( <NUM_LIT:2> ) ) ; } public void testGetInputIterator ( ) { Signal s ; Iterator < Signal > it = _block . getInputIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _value1Signal , s ) ; assertTrue ( it . hasNext ( ) ) ; s = it . next ( ) ; assertEquals ( _value2Signal , s ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutput ( ) { assertEquals ( _outputSignal , _block . getOutput ( ) ) ; } public void testGetVarIDIterator ( ) { String name ; Iterator < String > it = _block . getVarIDIterator ( ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertTrue ( it . hasNext ( ) ) ; name = it . next ( ) ; assertEquals ( "<STR_LIT>" , name ) ; assertFalse ( it . hasNext ( ) ) ; } public void testGetOutputVarID ( ) { assertEquals ( "<STR_LIT>" , _block . getOutputVarID ( ) ) ; } public void testSetName ( ) { _block . setName ( "<STR_LIT>" ) ; assertEquals ( "<STR_LIT>" , _block . getName ( ) ) ; } public void testNumInputs ( ) { assertEquals ( <NUM_LIT:2> , _block . numInputs ( ) ) ; } public void testNumVarIDs ( ) { assertEquals ( <NUM_LIT:2> , _block . numVarIDs ( ) ) ; } public void testUpdate ( ) { String routineName = new String ( "<STR_LIT>" ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } checkSum ( <NUM_LIT> , <NUM_LIT> ) ; checkSum ( <NUM_LIT> , - <NUM_LIT> ) ; checkSum ( <NUM_LIT> , - <NUM_LIT> ) ; checkSum ( <NUM_LIT> , <NUM_LIT> ) ; checkSum ( - <NUM_LIT> , - <NUM_LIT> ) ; } private void checkSum ( Double n1 , Double n2 ) { String routineName = new String ( "<STR_LIT>" ) ; _value1Block . setValue ( n1 ) ; _value2Block . setValue ( n2 ) ; try { _model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + n1 . toString ( ) + "<STR_LIT>" + n2 . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( n1 + n2 , _block . getValue ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathSwitch3Test extends TestCase { protected Model _model ; private StringWriter _writer ; protected BlockMathSwitch _block ; protected BlockMathConstant _inputBlock ; protected BlockMathConstant _upperLimitBlock ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; _writer = new StringWriter ( ) ; _block = generateSampleSwitch ( _model ) ; SignalArrayList theSignals = _model . getSignals ( ) ; Signal inputSignal = theSignals . findByID ( "<STR_LIT>" ) ; assertNotNull ( inputSignal ) ; Block theBlock = inputSignal . getSource ( ) ; assertNotNull ( theBlock ) ; assertEquals ( "<STR_LIT>" , theBlock . myType ) ; _inputBlock = ( BlockMathConstant ) theBlock ; assertNotNull ( _inputBlock ) ; inputSignal = theSignals . findByID ( "<STR_LIT>" ) ; assertNotNull ( inputSignal ) ; theBlock = inputSignal . getSource ( ) ; assertNotNull ( theBlock ) ; assertEquals ( "<STR_LIT>" , theBlock . myType ) ; _upperLimitBlock = ( BlockMathConstant ) theBlock ; assertNotNull ( _upperLimitBlock ) ; } public void testUpdate ( ) { assertNotNull ( _block ) ; String routineName = "<STR_LIT>" ; _model . wireBlocks ( ) ; try { _model . getInputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; } _upperLimitBlock . setValue ( <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( <NUM_LIT:0.0> , checkSwitch ( <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; _upperLimitBlock . setValue ( <NUM_LIT> ) ; assertEquals ( - <NUM_LIT> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( - <NUM_LIT:1.0> , checkSwitch ( - <NUM_LIT> ) ) ; assertEquals ( <NUM_LIT:0.0> , checkSwitch ( <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT:1.0> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; assertEquals ( + <NUM_LIT> , checkSwitch ( + <NUM_LIT> ) ) ; } private double checkSwitch ( Double switchVal ) { String routineName = "<STR_LIT>" ; _inputBlock . setValue ( switchVal ) ; try { _model . cycle ( ) ; } catch ( Exception e ) { fail ( "<STR_LIT>" + routineName + "<STR_LIT>" + switchVal . toString ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } return _block . getValue ( ) ; } private void checkCode ( String code ) { Signal defaultInput = _block . inputs . get ( <NUM_LIT:2> ) ; defaultInput . setDefinedFlag ( ) ; CodeAndVarNames cvn = _block . genCode ( ) ; assertEquals ( code , cvn . getCode ( ) ) ; } public void testGenCcode ( ) { _model . setCodeDialect ( Model . DT_ANSI_C ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT:U+0020U+0020>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; checkCode ( code ) ; } public void testGenFcode ( ) { _model . setCodeDialect ( Model . DT_FORTRAN ) ; String code = "<STR_LIT>" ; String indent = "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; code = code + indent + "<STR_LIT>" ; checkCode ( code ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } public static BlockMathSwitch generateSampleSwitch ( Model model ) { Block alpMaxLim = new BlockMathConstant ( "<STR_LIT>" , model ) ; Signal alpMaxLimSignal = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; Block alpUnlim = new BlockMathConstant ( "<STR_LIT:0>" , model ) ; Signal alpUnlimSignal = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; Signal outputSignal = new Signal ( "<STR_LIT>" , model ) ; try { alpMaxLim . addOutput ( alpMaxLimSignal ) ; alpUnlim . addOutput ( alpUnlimSignal ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } Element innerApply1 = new Element ( "<STR_LIT>" ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; innerApply1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; Element innerApply2 = new Element ( "<STR_LIT>" ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; innerApply2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; Element piece1 = new Element ( "<STR_LIT>" ) ; piece1 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; piece1 . addContent ( innerApply1 ) ; Element piece2 = new Element ( "<STR_LIT>" ) ; piece2 . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; piece2 . addContent ( innerApply2 ) ; Element otherwise = new Element ( "<STR_LIT>" ) ; otherwise . addContent ( new Element ( "<STR_LIT>" ) . addContent ( "<STR_LIT>" ) ) ; Element piecewise = new Element ( "<STR_LIT>" ) ; piecewise . addContent ( piece1 ) ; piecewise . addContent ( piece2 ) ; piecewise . addContent ( otherwise ) ; Element outerApply = new Element ( "<STR_LIT>" ) ; outerApply . addContent ( piecewise ) ; BlockMathSwitch bms = null ; bms = new BlockMathSwitch ( outerApply , model ) ; try { bms . addOutput ( outputSignal ) ; model . wireBlocks ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + "<STR_LIT>" + e . getMessage ( ) ) ; } return bms ; } } </s>
<s> package gov . nasa . daveml . dave ; import junit . framework . TestCase ; public class NameListTest extends TestCase { protected NameList nl ; protected void setUp ( ) throws Exception { super . setUp ( ) ; nl = new NameList ( <NUM_LIT:4> ) ; nl . add ( "<STR_LIT>" ) ; nl . add ( "<STR_LIT>" ) ; nl . add ( "<STR_LIT>" ) ; } public void testFixName ( ) { assertEquals ( "<STR_LIT>" , nl . fixName ( "<STR_LIT>" ) ) ; } public void testIsUnique ( ) { assertTrue ( nl . isUnique ( "<STR_LIT>" ) ) ; assertFalse ( nl . isUnique ( "<STR_LIT>" ) ) ; } public void testAddUnique ( ) { nl . addUnique ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:4> , nl . size ( ) ) ; assertEquals ( "<STR_LIT>" , nl . get ( <NUM_LIT:3> ) ) ; nl . addUnique ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:5> , nl . size ( ) ) ; assertEquals ( "<STR_LIT>" , nl . get ( <NUM_LIT:4> ) ) ; nl . addUnique ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:6> , nl . size ( ) ) ; assertEquals ( "<STR_LIT>" , nl . get ( <NUM_LIT:5> ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; import junit . framework . TestCase ; public class TreeFileWriterTest extends TestCase { Model _m ; TreeFileWriter _w ; String _fileName ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _m = genSampleModel ( ) ; _fileName = "<STR_LIT>" ; _w = new TreeFileWriter ( _fileName ) ; } public void testTreeFileWriter ( ) { assertNotNull ( _w ) ; } public void testDescribe ( ) { try { _w . describe ( _m ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _w . close ( ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } FileReader f = null ; try { f = new FileReader ( _fileName ) ; } catch ( FileNotFoundException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertNotNull ( f ) ; char [ ] buf = new char [ <NUM_LIT:1000> ] ; try { f . read ( buf ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } String contents = new String ( buf ) ; int end = contents . lastIndexOf ( '<STR_LIT:\n>' ) ; String expectedMessage = "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT:n>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ; assertEquals ( expectedMessage , contents . substring ( <NUM_LIT:0> , end ) ) ; } protected Model genSampleModel ( ) { Model m = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; Block constBlk = new BlockMathConstant ( "<STR_LIT>" , m ) ; Signal sig = new Signal ( "<STR_LIT>" , m ) ; try { constBlk . addOutput ( sig ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } new BlockOutput ( sig , m ) ; return m ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; import org . jdom . Element ; import junit . framework . TestCase ; public class BreakpointSetTest extends TestCase { protected Model _model ; protected BreakpointSet _bps ; protected BlockBP _bpb ; private final Double EPS = <NUM_LIT> ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; } public void testBreakpointSetModel ( ) { _bps = new BreakpointSet ( _model ) ; assertEquals ( "<STR_LIT>" , _bps . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _bps . getBPID ( ) ) ; assertEquals ( <NUM_LIT:0> , _bps . length ( ) ) ; assertFalse ( _bps . isVerbose ( ) ) ; assertNull ( _bps . values ( ) ) ; } public void testBreakpointSetElementModel ( ) { Element bpValElement = new Element ( "<STR_LIT>" ) ; bpValElement . addContent ( "<STR_LIT>" ) ; Element descriptionElement = new Element ( "<STR_LIT:description>" ) ; descriptionElement . addContent ( "<STR_LIT>" ) ; Element bpDefElement = new Element ( "<STR_LIT>" ) ; bpDefElement . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; bpDefElement . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; bpDefElement . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; bpDefElement . addContent ( descriptionElement ) ; bpDefElement . addContent ( bpValElement ) ; try { _bps = new BreakpointSet ( bpDefElement , _model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } checkBPS ( ) ; assertEquals ( "<STR_LIT>" , _bps . myDescription ) ; } public void testBreakpointSetStringStringStringStringModel ( ) { try { _bps = new BreakpointSet ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , _model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } checkBPS ( ) ; assertEquals ( "<STR_LIT>" , _bps . myDescription ) ; } public void testRegister ( ) { _bps = new BreakpointSet ( _model ) ; _bps . register ( _bpb ) ; assertNotNull ( _bps . users ) ; BlockBP bpb = ( BlockBP ) _bps . users . get ( <NUM_LIT:0> ) ; assertEquals ( _bpb , bpb ) ; } public void testIsVerbose ( ) { _bps = new BreakpointSet ( _model ) ; assertFalse ( _bps . isVerbose ( ) ) ; _bps . makeVerbose ( ) ; assertTrue ( _bps . isVerbose ( ) ) ; _bps . silence ( ) ; assertFalse ( _bps . isVerbose ( ) ) ; } private void checkBPS ( ) { assertNotNull ( _bps ) ; assertEquals ( "<STR_LIT>" , _bps . getName ( ) ) ; assertEquals ( "<STR_LIT>" , _bps . getBPID ( ) ) ; assertEquals ( <NUM_LIT:12> , _bps . length ( ) ) ; assertFalse ( _bps . isVerbose ( ) ) ; assertNotNull ( _bps . values ( ) ) ; ArrayList < Double > vals = _bps . values ( ) ; assertNotNull ( vals ) ; assertEquals ( <NUM_LIT:12> , vals . size ( ) ) ; checkValues ( vals ) ; } private void checkValues ( ArrayList < Double > vals ) { assertEquals ( - <NUM_LIT> , vals . get ( <NUM_LIT:0> ) , EPS ) ; assertEquals ( - <NUM_LIT> , vals . get ( <NUM_LIT:1> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:2> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:3> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:4> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:5> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:6> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:7> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:8> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:9> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:10> ) , EPS ) ; assertEquals ( <NUM_LIT> , vals . get ( <NUM_LIT:11> ) , EPS ) ; } public static BreakpointSet generateSampleAlphaBreakpointSet ( Model model ) { BreakpointSet bpAlpha = null ; try { bpAlpha = new BreakpointSet ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } return bpAlpha ; } public static BreakpointSet generateSampleElevBreakpointSet ( Model model ) { BreakpointSet bpDE = null ; try { bpDE = new BreakpointSet ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , model ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } return bpDE ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import junit . framework . TestCase ; public class BlockLimiterTest extends TestCase { private Model model ; private BlockInput inputBlk ; private BlockLimiter symLimBlk ; private BlockLimiter hiLimBlk ; private BlockLimiter loLimBlk ; private BlockLimiter noLimBlk ; private BlockLimiter swapLimBlk ; private Signal symOut , hiOut , loOut , noOut , swapOut ; private Signal inputSignal ; private StringWriter _writer ; private BlockLimiter blockArray [ ] ; private VectorInfoArrayList inputVector ; private VectorInfoArrayList outputVector ; private VectorInfo input ; final private double eps = <NUM_LIT> ; private double inputValue [ ] = { - <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> } ; private double expectedValue [ ] [ ] = { { - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> , - <NUM_LIT> } , { <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> } , { + <NUM_LIT> , + <NUM_LIT> , + <NUM_LIT> , + <NUM_LIT> , + <NUM_LIT> } } ; public BlockLimiterTest ( String testName ) { super ( testName ) ; } @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _writer = new StringWriter ( ) ; assert ( _writer != null ) ; model = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; assert ( model != null ) ; inputSignal = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:3> , model ) ; assert ( inputSignal != null ) ; inputBlk = new BlockInput ( inputSignal , model ) ; assert ( inputBlk != null ) ; symOut = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; assert ( symOut != null ) ; hiOut = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; assert ( hiOut != null ) ; loOut = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; assert ( loOut != null ) ; noOut = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; assert ( noOut != null ) ; swapOut = new Signal ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , model ) ; assert ( swapOut != null ) ; symLimBlk = new BlockLimiter ( inputSignal , model , - <NUM_LIT> , <NUM_LIT> ) ; assert ( symLimBlk != null ) ; symLimBlk . addOutput ( symOut ) ; hiLimBlk = new BlockLimiter ( inputSignal , model , Double . NEGATIVE_INFINITY , <NUM_LIT> ) ; assert ( hiLimBlk != null ) ; hiLimBlk . addOutput ( hiOut ) ; loLimBlk = new BlockLimiter ( inputSignal , model , - <NUM_LIT> , Double . POSITIVE_INFINITY ) ; assert ( loLimBlk != null ) ; loLimBlk . addOutput ( loOut ) ; noLimBlk = new BlockLimiter ( inputSignal , model , Double . NEGATIVE_INFINITY , Double . POSITIVE_INFINITY ) ; assert ( noLimBlk != null ) ; noLimBlk . addOutput ( noOut ) ; swapLimBlk = new BlockLimiter ( inputSignal , model , + <NUM_LIT> , - <NUM_LIT> ) ; assert ( swapLimBlk != null ) ; swapLimBlk . addOutput ( swapOut ) ; blockArray = new BlockLimiter [ <NUM_LIT:5> ] ; blockArray [ <NUM_LIT:0> ] = symLimBlk ; blockArray [ <NUM_LIT:1> ] = hiLimBlk ; blockArray [ <NUM_LIT:2> ] = loLimBlk ; blockArray [ <NUM_LIT:3> ] = noLimBlk ; blockArray [ <NUM_LIT:4> ] = swapLimBlk ; inputVector = model . getInputVector ( ) ; assert ( inputVector != null ) ; assertEquals ( <NUM_LIT:1> , inputVector . size ( ) ) ; input = inputVector . get ( <NUM_LIT:0> ) ; assert ( input != null ) ; model . hookUpIO ( ) ; model . initialize ( ) ; outputVector = model . getOutputVector ( ) ; assert ( outputVector != null ) ; assertEquals ( <NUM_LIT:5> , outputVector . size ( ) ) ; } @ Override protected void tearDown ( ) throws Exception { super . tearDown ( ) ; } public void testGetValue ( ) { for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { input . setValue ( inputValue [ i ] ) ; try { model . cycle ( ) ; } catch ( DAVEException e ) { String msg = e . getMessage ( ) ; } for ( int j = <NUM_LIT:0> ; j < outputVector . size ( ) ; j ++ ) { double value = outputVector . get ( j ) . getValue ( ) ; assertEquals ( expectedValue [ i ] [ j ] , value , eps ) ; } } } public void testGetUnits ( ) { BlockLimiter blk ; for ( int j = <NUM_LIT:0> ; j < blockArray . length ; j ++ ) { blk = blockArray [ j ] ; assertEquals ( "<STR_LIT>" , blk . getUnits ( ) ) ; } } public void testGenCcode ( ) { BlockLimiter blk ; model . setCodeDialect ( Model . DT_ANSI_C ) ; CodeAndVarNames result = new CodeAndVarNames ( ) ; blk = blockArray [ <NUM_LIT:0> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:1> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:2> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:3> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:4> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; } public void testGenFcode ( ) { BlockLimiter blk ; model . setCodeDialect ( Model . DT_FORTRAN ) ; CodeAndVarNames result = new CodeAndVarNames ( ) ; blk = blockArray [ <NUM_LIT:0> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:1> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:2> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; blk = blockArray [ <NUM_LIT:3> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; blk = blockArray [ <NUM_LIT:4> ] ; result = blk . genCode ( ) ; assertEquals ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , result . getCode ( ) ) ; assertEquals ( <NUM_LIT:2> , result . getVarNames ( ) . size ( ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:0> ) ) ; assertEquals ( "<STR_LIT>" , result . getVarName ( <NUM_LIT:1> ) ) ; } public void testDescribeSelf ( ) throws Exception { BlockLimiter blk ; for ( int i = <NUM_LIT:0> ; i < blockArray . length ; i ++ ) { blk = blockArray [ i ] ; _writer = new StringWriter ( ) ; String testString = _writer . toString ( ) ; try { blk . describeSelf ( _writer ) ; } catch ( IOException e ) { assertTrue ( false ) ; } assertEquals ( "<STR_LIT>" + blk . getOutput ( ) . getName ( ) + "<STR_LIT>" + "<STR_LIT>" + Double . toString ( blk . getLowerLimit ( ) ) + "<STR_LIT>" + Double . toString ( blk . getUpperLimit ( ) ) + "<STR_LIT:.>" , _writer . toString ( ) ) ; } } public void testHasLowerLimit ( ) { assert ( symLimBlk . hasLowerLimit ( ) ) ; assert ( ! hiLimBlk . hasLowerLimit ( ) ) ; assert ( loLimBlk . hasLowerLimit ( ) ) ; assert ( ! noLimBlk . hasLowerLimit ( ) ) ; assert ( swapLimBlk . hasLowerLimit ( ) ) ; } public void testHasUpperLimit ( ) { assert ( symLimBlk . hasUpperLimit ( ) ) ; assert ( hiLimBlk . hasUpperLimit ( ) ) ; assert ( ! loLimBlk . hasUpperLimit ( ) ) ; assert ( ! noLimBlk . hasUpperLimit ( ) ) ; assert ( swapLimBlk . hasUpperLimit ( ) ) ; } public void testGetLowerLimit ( ) { assertEquals ( - <NUM_LIT> , symLimBlk . getLowerLimit ( ) , eps ) ; assert ( Double . isInfinite ( hiLimBlk . getLowerLimit ( ) ) ) ; assertEquals ( - <NUM_LIT> , loLimBlk . getLowerLimit ( ) , eps ) ; assert ( Double . isInfinite ( noLimBlk . getLowerLimit ( ) ) ) ; assertEquals ( - <NUM_LIT> , swapLimBlk . getLowerLimit ( ) , eps ) ; } public void testGetUpperLimit ( ) { assertEquals ( + <NUM_LIT> , symLimBlk . getUpperLimit ( ) , eps ) ; assertEquals ( + <NUM_LIT> , hiLimBlk . getUpperLimit ( ) , eps ) ; assert ( Double . isInfinite ( loLimBlk . getUpperLimit ( ) ) ) ; assert ( Double . isInfinite ( noLimBlk . getUpperLimit ( ) ) ) ; assertEquals ( + <NUM_LIT> , swapLimBlk . getUpperLimit ( ) , eps ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . Arrays ; import java . util . Collection ; import junit . framework . TestCase ; public class SignalArrayListTest extends TestCase { protected SignalArrayList _list ; protected Signal _sig1 ; protected Signal _sig2 ; protected Signal _sig3 ; protected Signal _sig4 ; protected Signal _sig5 ; protected Model _model ; protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:2> , <NUM_LIT:2> ) ; _list = new SignalArrayList ( <NUM_LIT:5> ) ; _sig1 = new Signal ( "<STR_LIT>" , _model ) ; _sig2 = new Signal ( "<STR_LIT>" , _model ) ; _sig3 = new Signal ( "<STR_LIT>" , _model ) ; _sig4 = new Signal ( "<STR_LIT>" , _model ) ; _sig5 = new Signal ( "<STR_LIT>" , _model ) ; _list . add ( _sig1 ) ; _list . add ( _sig2 ) ; _list . add ( _sig3 ) ; _list . add ( _sig4 ) ; _list . add ( _sig5 ) ; } public void testSignalArrayList ( ) { SignalArrayList list = new SignalArrayList ( ) ; assertNotNull ( list ) ; } public void testSignalArrayListInt ( ) { assertNotNull ( _list ) ; } public void testSignalArrayListCollectionOfSignal ( ) { Collection < Signal > c = Arrays . asList ( _sig1 , _sig2 , _sig3 , _sig4 , _sig5 ) ; SignalArrayList list = new SignalArrayList ( c ) ; assertNotNull ( list ) ; checkSignalArrayList ( list ) ; } public void testFindByID ( ) { checkSignalArrayList ( _list ) ; } protected void checkSignalArrayList ( SignalArrayList list ) { Signal sig = null ; Integer i = <NUM_LIT:5> ; while ( i > <NUM_LIT:0> ) { String id = "<STR_LIT>" + i . toString ( ) ; sig = list . findByID ( id ) ; assertNotNull ( sig ) ; assertEquals ( id , sig . getVarID ( ) ) ; i -- ; } sig = list . findByID ( "<STR_LIT>" ) ; assertNull ( sig ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . StringWriter ; import java . util . ArrayList ; import java . util . Iterator ; import org . jdom . Element ; import junit . framework . TestCase ; public class BlockMathFunctionTest extends TestCase { protected Model _model ; protected StringWriter _writer ; protected BlockMathFunction _block ; protected final double EPS = <NUM_LIT> ; protected final double COS_0p5 = <NUM_LIT> ; protected final double SIN_0p5 = <NUM_LIT> ; protected final double TAN_0p5 = <NUM_LIT> ; @ Override protected void setUp ( ) throws Exception { super . setUp ( ) ; _model = new Model ( <NUM_LIT:1> , <NUM_LIT:1> ) ; _writer = new StringWriter ( ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; } public void testBlockMathFunction_ctor ( ) { instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; assertEquals ( COS_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; assertEquals ( SIN_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; assertEquals ( TAN_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - <NUM_LIT> , false ) ; assertEquals ( COS_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - <NUM_LIT> , false ) ; assertEquals ( - SIN_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - <NUM_LIT> , false ) ; assertEquals ( - TAN_0p5 , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; assertEquals ( <NUM_LIT:0.0> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , false ) ; assertEquals ( <NUM_LIT:1.0> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , COS_0p5 , false ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , SIN_0p5 , false ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , TAN_0p5 , false ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - COS_0p5 , false ) ; assertEquals ( Math . PI - <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - SIN_0p5 , false ) ; assertEquals ( - <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , - TAN_0p5 , false ) ; assertEquals ( - <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , <NUM_LIT:4> , false ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:16> , <NUM_LIT> / <NUM_LIT> , false ) ; assertEquals ( <NUM_LIT> , _block . getValue ( ) , EPS ) ; instantiateFunction ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> , <NUM_LIT:4> , true ) ; } public void testUpdate ( ) { updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , COS_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , SIN_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , TAN_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , COS_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , - SIN_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , - <NUM_LIT> , - TAN_0p5 ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:0.0> ) ; updateExistingBlock ( "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:1.0> ) ; updateExistingBlock ( "<STR_LIT>" , COS_0p5 , <NUM_LIT> ) ; updateExistingBlock ( "<STR_LIT>" , SIN_0p5 , <NUM_LIT> ) ; updateExistingBlock ( "<STR_LIT>" , TAN_0p5 , <NUM_LIT> ) ; updateExistingBlock ( "<STR_LIT>" , - COS_0p5 , Math . PI - <NUM_LIT> ) ; updateExistingBlock ( "<STR_LIT>" , - SIN_0p5 , - <NUM_LIT> ) ; updateExistingBlock ( "<STR_LIT>" , - TAN_0p5 , - <NUM_LIT> ) ; } public void updateExistingBlock ( String func , double arg , double expectedValue ) { BlockMathConstant constBlk = getUpstreamConstBlk1 ( ) ; constBlk . setValue ( arg ) ; try { _block . setFunction ( func ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { _block . update ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( expectedValue , _block . getValue ( ) , EPS ) ; } protected BlockMathConstant getUpstreamConstBlk ( int index ) { Signal s = _block . getInput ( index - <NUM_LIT:1> ) ; assertNotNull ( s ) ; Block sourceBlk = s . getSource ( ) ; assertNotNull ( sourceBlk ) ; assertEquals ( "<STR_LIT>" , sourceBlk . getType ( ) ) ; return ( BlockMathConstant ) sourceBlk ; } protected BlockMathConstant getUpstreamConstBlk1 ( ) { return this . getUpstreamConstBlk ( <NUM_LIT:1> ) ; } protected BlockMathConstant getUpstreamConstBlk2 ( ) { return this . getUpstreamConstBlk ( <NUM_LIT:2> ) ; } public void testDescribeSelfWriter ( ) { try { _block . describeSelf ( _writer ) ; } catch ( IOException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( "<STR_LIT>" + "<STR_LIT>" , _writer . toString ( ) ) ; } protected void instantiateFunction ( String func , String name , double argument , boolean expectException ) { ArrayList < Double > args = new ArrayList < Double > ( ) ; args . add ( argument ) ; instantiateFunction ( func , name , args , expectException ) ; } protected void instantiateFunction ( String func , String name , double argument1 , double argument2 , boolean expectException ) { ArrayList < Double > args = new ArrayList < Double > ( ) ; args . add ( argument1 ) ; args . add ( argument2 ) ; instantiateFunction ( func , name , args , expectException ) ; } protected void instantiateFunction ( String func , String name , ArrayList < Double > args , boolean expectException ) { instantiateFunction ( func , name , null , null , null , null , null , args , expectException ) ; } protected void instantiateFunction ( String func , String name , String funcAttributeName1 , String funcAttributeValue1 , String funcAttributeName2 , String funcAttributeValue2 , String extendedFunctionName , ArrayList < Double > args , boolean expectException ) { Element argElement ; Element applyElement = new Element ( "<STR_LIT>" ) ; Element funcElement = new Element ( func ) ; applyElement . addContent ( funcElement ) ; if ( funcAttributeName1 != null ) { funcElement . setAttribute ( funcAttributeName1 , funcAttributeValue1 ) ; if ( funcAttributeName2 != null ) { funcElement . setAttribute ( funcAttributeName2 , funcAttributeValue2 ) ; } if ( extendedFunctionName != null ) { funcElement . addContent ( extendedFunctionName ) ; } } Iterator < Double > it = args . iterator ( ) ; while ( it . hasNext ( ) ) { argElement = new Element ( "<STR_LIT>" ) ; argElement . addContent ( it . next ( ) . toString ( ) ) ; applyElement . addContent ( argElement ) ; } _block = null ; _model = new Model ( <NUM_LIT:1> , <NUM_LIT:1> ) ; try { if ( "<STR_LIT>" . equals ( func ) ) { _block = new BlockMathFunctionExtension ( applyElement , _model ) ; } else { _block = new BlockMathFunction ( applyElement , _model ) ; } if ( expectException ) fail ( "<STR_LIT>" ) ; } catch ( DAVEException e ) { if ( expectException ) { } else fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } if ( ! expectException ) { assertNotNull ( _block ) ; assertEquals ( name , _block . getType ( ) ) ; if ( extendedFunctionName == null ) assertEquals ( func , _block . getFuncType ( ) ) ; else assertEquals ( extendedFunctionName , _block . getFuncType ( ) ) ; assertEquals ( Double . NaN , _block . getValue ( ) ) ; try { _model . initialize ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + "<STR_LIT>" + e . getMessage ( ) ) ; } } } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import junit . framework . * ; public class GeneralBlockTest extends TestCase { Model _simple ; Model _complexMath ; Signal mySignal ; BlockMathConstant myConstBlock ; @ Override protected void setUp ( ) { _simple = new Model ( <NUM_LIT:3> , <NUM_LIT:3> ) ; Model constModel = new Model ( <NUM_LIT:2> , <NUM_LIT:2> ) ; myConstBlock = new BlockMathConstant ( "<STR_LIT>" , constModel ) ; Element theValue = new Element ( "<STR_LIT>" ) ; theValue . addContent ( "<STR_LIT>" ) ; Element absElement = new Element ( "<STR_LIT>" ) ; Element applyElement = new Element ( "<STR_LIT>" ) ; applyElement . addContent ( absElement ) ; applyElement . addContent ( theValue ) ; Element mathElement = new Element ( "<STR_LIT>" ) ; mathElement . addContent ( applyElement ) ; Element calcElement = new Element ( "<STR_LIT>" ) ; calcElement . addContent ( mathElement ) ; Element descElement = new Element ( "<STR_LIT:description>" ) ; descElement . addContent ( "<STR_LIT>" ) ; java . util . ArrayList < Element > list = new java . util . ArrayList < Element > ( <NUM_LIT:3> ) ; list . add ( descElement ) ; list . add ( calcElement ) ; Element varDefElement = new Element ( "<STR_LIT>" ) ; varDefElement . setContent ( list ) ; varDefElement . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; varDefElement . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; varDefElement . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; mySignal = new Signal ( varDefElement , _simple ) ; varDefElement . removeChild ( "<STR_LIT>" ) ; descElement . addContent ( "<STR_LIT>" ) ; varDefElement . setAttribute ( "<STR_LIT:name>" , "<STR_LIT>" ) ; varDefElement . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Signal ignored = new Signal ( varDefElement , _simple ) ; _simple . wireBlocks ( ) ; _simple . hookUpIO ( ) ; } public static Test suite ( ) { return new TestSuite ( GeneralBlockTest . class ) ; } public void testConstBlock ( ) { assertEquals ( - <NUM_LIT> , myConstBlock . getValue ( ) ) ; } public void testSignal ( ) { assertEquals ( "<STR_LIT>" , mySignal . getName ( ) ) ; assertEquals ( "<STR_LIT>" , mySignal . getUnits ( ) ) ; } public void testRenameOutVarID ( ) { Block upstreamBlock = mySignal . getSource ( ) ; assertTrue ( upstreamBlock != null ) ; assertEquals ( "<STR_LIT>" , upstreamBlock . getOutputVarID ( ) ) ; mySignal . setVarID ( "<STR_LIT>" ) ; upstreamBlock . renameOutVarID ( ) ; assertEquals ( "<STR_LIT>" , upstreamBlock . getOutputVarID ( ) ) ; } public void testModel ( ) { assertEquals ( <NUM_LIT:3> , _simple . getNumBlocks ( ) ) ; assertEquals ( <NUM_LIT:0> , _simple . getNumTables ( ) ) ; assertEquals ( <NUM_LIT:2> , _simple . getNumSignals ( ) ) ; } public void testMathFunc ( ) { Model mathFuncModel = new Model ( <NUM_LIT:10> , <NUM_LIT:10> ) ; Element input = new Element ( "<STR_LIT>" ) ; input . setAttribute ( "<STR_LIT:name>" , "<STR_LIT:X>" ) ; input . setAttribute ( "<STR_LIT>" , "<STR_LIT:X>" ) ; input . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Signal ignored = new Signal ( input , mathFuncModel ) ; Element X1 = new Element ( "<STR_LIT>" ) ; X1 . addContent ( "<STR_LIT:X>" ) ; Element aTanX = new Element ( "<STR_LIT>" ) ; aTanX . addContent ( new Element ( "<STR_LIT>" ) ) ; aTanX . addContent ( X1 ) ; Element tanATanX = new Element ( "<STR_LIT>" ) ; tanATanX . addContent ( new Element ( "<STR_LIT>" ) ) ; tanATanX . addContent ( aTanX ) ; Element X2 = new Element ( "<STR_LIT>" ) ; X2 . addContent ( "<STR_LIT:X>" ) ; Element cosX = new Element ( "<STR_LIT>" ) ; cosX . addContent ( new Element ( "<STR_LIT>" ) ) ; cosX . addContent ( X2 ) ; Element aCosCosX = new Element ( "<STR_LIT>" ) ; aCosCosX . addContent ( new Element ( "<STR_LIT>" ) ) ; aCosCosX . addContent ( cosX ) ; Element denom = new Element ( "<STR_LIT>" ) ; denom . addContent ( new Element ( "<STR_LIT>" ) ) ; denom . addContent ( aCosCosX ) ; denom . addContent ( tanATanX ) ; Element X3 = new Element ( "<STR_LIT>" ) ; X3 . addContent ( "<STR_LIT:X>" ) ; Element sinX = new Element ( "<STR_LIT>" ) ; sinX . addContent ( new Element ( "<STR_LIT>" ) ) ; sinX . addContent ( X3 ) ; Element aSinSinX = new Element ( "<STR_LIT>" ) ; aSinSinX . addContent ( new Element ( "<STR_LIT>" ) ) ; aSinSinX . addContent ( sinX ) ; Element trig = new Element ( "<STR_LIT>" ) ; trig . addContent ( new Element ( "<STR_LIT>" ) ) ; trig . addContent ( aSinSinX ) ; trig . addContent ( denom ) ; Element X4 = new Element ( "<STR_LIT>" ) ; X4 . addContent ( "<STR_LIT:X>" ) ; Element xToTheTrigPwr = new Element ( "<STR_LIT>" ) ; xToTheTrigPwr . addContent ( new Element ( "<STR_LIT>" ) ) ; xToTheTrigPwr . addContent ( X4 ) ; xToTheTrigPwr . addContent ( trig ) ; Element X5 = new Element ( "<STR_LIT>" ) ; X5 . addContent ( "<STR_LIT:X>" ) ; Element negX = new Element ( "<STR_LIT>" ) ; negX . addContent ( new Element ( "<STR_LIT>" ) ) ; negX . addContent ( X5 ) ; Element xToTheTrigPwrMinusX = new Element ( "<STR_LIT>" ) ; xToTheTrigPwrMinusX . addContent ( new Element ( "<STR_LIT>" ) ) ; xToTheTrigPwrMinusX . addContent ( xToTheTrigPwr ) ; xToTheTrigPwrMinusX . addContent ( negX ) ; Element math = new Element ( "<STR_LIT>" ) ; math . addContent ( xToTheTrigPwrMinusX ) ; Element calc = new Element ( "<STR_LIT>" ) ; calc . addContent ( math ) ; Element output = new Element ( "<STR_LIT>" ) ; output . addContent ( calc ) ; output . setAttribute ( "<STR_LIT:name>" , "<STR_LIT:Y>" ) ; output . setAttribute ( "<STR_LIT>" , "<STR_LIT:Y>" ) ; output . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; Signal ignored2 = new Signal ( output , mathFuncModel ) ; mathFuncModel . wireBlocks ( ) ; mathFuncModel . hookUpIO ( ) ; VectorInfoArrayList inputs = null ; VectorInfoArrayList outputs = null ; try { inputs = mathFuncModel . getInputVector ( ) ; outputs = mathFuncModel . getOutputVector ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertNotNull ( inputs ) ; assertEquals ( <NUM_LIT:1> , inputs . size ( ) ) ; assertNotNull ( outputs ) ; assertEquals ( <NUM_LIT:1> , outputs . size ( ) ) ; VectorInfo theInput = ( VectorInfo ) inputs . get ( <NUM_LIT:0> ) ; assertNotNull ( theInput ) ; assertEquals ( "<STR_LIT:X>" , theInput . getName ( ) ) ; VectorInfo theOutput = ( VectorInfo ) outputs . get ( <NUM_LIT:0> ) ; assertNotNull ( theOutput ) ; assertEquals ( "<STR_LIT:Y>" , theOutput . getName ( ) ) ; theInput . setValue ( <NUM_LIT> ) ; try { mathFuncModel . cycle ( ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } assertEquals ( - <NUM_LIT> , theOutput . getValue ( ) , <NUM_LIT> ) ; try { theInput . setValue ( + <NUM_LIT:1> ) ; mathFuncModel . cycle ( ) ; assertEquals ( <NUM_LIT:0> , theOutput . getValue ( ) , <NUM_LIT> ) ; theInput . setValue ( + <NUM_LIT:2> ) ; mathFuncModel . cycle ( ) ; assertEquals ( - <NUM_LIT> , theOutput . getValue ( ) , <NUM_LIT> ) ; theInput . setValue ( + <NUM_LIT:3> ) ; mathFuncModel . cycle ( ) ; assertEquals ( - <NUM_LIT> , theOutput . getValue ( ) , <NUM_LIT> ) ; } catch ( DAVEException e ) { fail ( "<STR_LIT>" + e . getMessage ( ) ) ; } } public static void main ( String [ ] args ) { junit . textui . TestRunner . run ( suite ( ) ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Attribute ; import org . jdom . Element ; import org . jdom . Namespace ; import java . util . ArrayList ; import java . util . Iterator ; import java . io . FileWriter ; import java . io . IOException ; public class Signal { Model ourModel ; String myName ; String myVarID ; String myUnits ; String description ; Block source ; int sourcePort ; BlockArrayList dests ; ArrayList < Integer > destPorts ; boolean hasIC ; private String IC ; private boolean isInput ; private boolean isControl ; private boolean isDisturbance ; private boolean isState ; private boolean isStateDeriv ; private boolean isOutput ; private boolean isStdAIAA ; boolean verboseFlag = false ; private boolean derived = false ; private boolean defined = false ; private boolean marked = false ; private double lowerLim = Double . NEGATIVE_INFINITY ; private double upperLim = Double . POSITIVE_INFINITY ; public Signal ( ) { ourModel = null ; myName = "<STR_LIT>" ; myVarID = "<STR_LIT>" ; myUnits = "<STR_LIT>" ; source = null ; sourcePort = <NUM_LIT:0> ; description = "<STR_LIT>" ; dests = null ; destPorts = null ; hasIC = false ; IC = "<STR_LIT>" ; isInput = false ; isControl = false ; isDisturbance = false ; isState = false ; isStateDeriv = false ; isOutput = false ; isStdAIAA = false ; derived = false ; defined = false ; lowerLim = Double . NEGATIVE_INFINITY ; upperLim = Double . POSITIVE_INFINITY ; marked = false ; } public Signal ( String signalName , Model m ) { this ( signalName , Signal . toValidId ( signalName ) , "<STR_LIT>" , <NUM_LIT:1> , m ) ; } public Signal ( String signalName , String varID , String units , int numConnects , Model m ) { this ( ) ; ourModel = m ; myName = signalName ; if ( signalName == null ) myName = "<STR_LIT>" ; myVarID = varID ; if ( varID == null ) myVarID = "<STR_LIT>" + m . getNumSignals ( ) ; myUnits = units ; dests = new BlockArrayList ( numConnects ) ; destPorts = new ArrayList < Integer > ( numConnects ) ; m . add ( this ) ; } public Signal ( Element signalElement , Model m ) { this ( signalElement . getAttributeValue ( "<STR_LIT:name>" ) , m ) ; String name = signalElement . getName ( ) ; if ( name . equals ( "<STR_LIT>" ) ) { this . handleApply ( signalElement , m ) ; } else if ( name . equals ( "<STR_LIT>" ) ) { myVarID = signalElement . getAttributeValue ( "<STR_LIT>" ) ; myUnits = signalElement . getAttributeValue ( "<STR_LIT>" ) ; Attribute theIC = signalElement . getAttribute ( "<STR_LIT>" ) ; if ( theIC != null ) { this . hasIC = true ; this . IC = theIC . getValue ( ) ; } Attribute minVal = signalElement . getAttribute ( "<STR_LIT>" ) ; if ( minVal != null ) { this . setLowerLimit ( minVal . getValue ( ) ) ; } Attribute maxVal = signalElement . getAttribute ( "<STR_LIT>" ) ; if ( maxVal != null ) { this . setUpperLimit ( maxVal . getValue ( ) ) ; } Element isInputElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isControlElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isDisturbanceElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isStateElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isStateDerivElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isOutputElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; Element isStdAIAAElement = signalElement . getChild ( "<STR_LIT>" , signalElement . getNamespace ( ) ) ; if ( isInputElement != null ) { this . isInput = true ; } else { if ( isControlElement != null ) { this . isControl = true ; } else { if ( isDisturbanceElement != null ) this . isDisturbance = true ; } } if ( isStateElement != null ) this . isState = true ; if ( isStateDerivElement != null ) this . isStateDeriv = true ; if ( isOutputElement != null ) this . isOutput = true ; if ( isStdAIAAElement != null ) this . isStdAIAA = true ; this . description = signalElement . getChildTextNormalize ( "<STR_LIT:description>" , signalElement . getNamespace ( ) ) ; if ( this . description == null ) this . description = "<STR_LIT>" ; this . handleCalculation ( signalElement , m ) ; } else { System . err . println ( "<STR_LIT>" + name + "<STR_LIT>" ) ; } } protected static String toValidId ( String input ) { String output = "<STR_LIT>" ; if ( input != null ) output = input . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:_>" ) ; return output ; } private void handleCalculation ( Element theVarDefElement , Model m ) { Element calc = theVarDefElement . getChild ( "<STR_LIT>" , theVarDefElement . getNamespace ( ) ) ; if ( calc != null ) { if ( verboseFlag ) System . out . println ( "<STR_LIT>" + myName + "<STR_LIT:...>" ) ; Element math = this . findMathMLChild ( calc , "<STR_LIT>" ) ; if ( math != null ) { if ( verboseFlag ) System . out . println ( "<STR_LIT>" ) ; Element apply = this . findMathMLChild ( math , "<STR_LIT>" ) ; if ( apply != null ) { if ( verboseFlag ) System . out . println ( "<STR_LIT>" ) ; this . handleApply ( apply , m ) ; } } else { System . err . println ( "<STR_LIT>" + myName + "<STR_LIT>" ) ; } } } private Element findMathMLChild ( Element e , String elementType ) { Namespace mathml = Namespace . getNamespace ( "<STR_LIT>" , "<STR_LIT>" ) ; Element child ; child = e . getChild ( elementType , mathml ) ; if ( child == null ) child = e . getChild ( elementType ) ; return child ; } public Signal ( Signal s ) { this ( ) ; this . ourModel = s . ourModel ; this . myName = s . myName ; this . myVarID = s . myVarID ; this . myUnits = s . myUnits ; this . source = s . source ; this . sourcePort = s . sourcePort ; this . hasIC = s . hasIC ; this . IC = s . IC ; this . lowerLim = s . lowerLim ; this . upperLim = s . upperLim ; this . isOutput = s . isOutput ; this . derived = s . derived ; this . dests = new BlockArrayList ( s . dests . size ( ) ) ; Iterator < Block > dest_iterator = s . dests . iterator ( ) ; while ( dest_iterator . hasNext ( ) ) this . dests . add ( dest_iterator . next ( ) ) ; this . destPorts = new ArrayList < Integer > ( s . destPorts . size ( ) ) ; Iterator < Integer > port_iterator = s . destPorts . iterator ( ) ; while ( port_iterator . hasNext ( ) ) this . destPorts . add ( port_iterator . next ( ) ) ; } public boolean sourceReady ( ) throws DAVEException { if ( source == null ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; return source . isReady ( ) ; } public double sourceValue ( ) throws DAVEException { if ( source == null ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; return source . getValue ( ) ; } public void makeVerbose ( ) { this . verboseFlag = true ; } public void silence ( ) { this . verboseFlag = false ; } public boolean isVerbose ( ) { return this . verboseFlag ; } private Block handleApply ( Element applyElement , Model m ) { Block b = BlockMath . factory ( applyElement , m ) ; if ( b == null ) System . err . println ( "<STR_LIT>" ) ; else { try { b . addOutput ( this ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } } return b ; } public void setName ( String theName ) { this . myName = theName ; } public void setUnits ( String theUnits ) { this . myUnits = theUnits ; } public void setVarID ( String theVarID ) { this . myVarID = theVarID ; if ( this . source != null ) this . source . renameOutVarID ( ) ; BlockArrayList sinks = this . getDests ( ) ; ArrayList < Integer > sinkPorts = this . getDestPortNumbers ( ) ; if ( ( sinks != null ) && ( sinkPorts != null ) ) for ( int i = <NUM_LIT:0> ; i < sinks . size ( ) ; i ++ ) { Block blk = sinks . get ( i ) ; blk . renameInVarID ( sinkPorts . get ( i ) ) ; if ( blk instanceof BlockBP ) { Signal sig = blk . getOutput ( ) ; sig . setVarID ( theVarID ) ; } } } public void setDerivedFlag ( ) { this . derived = true ; } public void clearDerivedFlag ( ) { this . derived = false ; } public boolean isDerived ( ) { return this . derived ; } protected void setDefinedFlag ( ) { this . defined = true ; } protected void clearDefinedFlag ( ) { this . defined = false ; } public boolean isDefined ( ) { return this . defined ; } public void mark ( ) { this . marked = true ; } public void unmark ( ) { this . marked = false ; } public boolean isMarked ( ) { return this . marked ; } boolean hasLowerLimit ( ) { return lowerLim != Double . NEGATIVE_INFINITY ; } boolean hasUpperLimit ( ) { return upperLim != Double . POSITIVE_INFINITY ; } boolean isLimited ( ) { return hasLowerLimit ( ) || hasUpperLimit ( ) ; } protected final void setLowerLimit ( String strValue ) { lowerLim = Double . parseDouble ( strValue ) ; } void setLowerLimit ( double value ) { lowerLim = value ; } double getLowerLimit ( ) { return lowerLim ; } protected final void setUpperLimit ( String strValue ) { upperLim = Double . parseDouble ( strValue ) ; } void setUpperLimit ( double value ) { upperLim = value ; } double getUpperLimit ( ) { return upperLim ; } void clearIsOutputFlag ( ) { this . isOutput = false ; } public void addSource ( Block sourceBlock , int portNum ) { source = sourceBlock ; sourcePort = portNum ; } public void addSink ( Block sinkBlock , int portNum ) { dests . add ( sinkBlock ) ; destPorts . add ( new Integer ( portNum ) ) ; sinkBlock . addInput ( this , portNum ) ; } public BlockArrayList getDests ( ) { return this . dests ; } public ArrayList < Integer > getDestPortNumbers ( ) { return this . destPorts ; } public void setPortNumber ( int portIndex , int newPortNumber ) { destPorts . set ( portIndex , new Integer ( newPortNumber ) ) ; } public String getName ( ) { return myName ; } public String getVarID ( ) { return myVarID ; } public String getUnits ( ) { return myUnits ; } public Block getSource ( ) { return source ; } public int getSourcePort ( ) { return sourcePort ; } public boolean hasSource ( ) { return ( source != null ) ; } public boolean hasDest ( ) { if ( this . dests == null ) return false ; return ( ! dests . isEmpty ( ) ) ; } public void removeDestBlocks ( ) { if ( this . dests != null ) this . dests . clear ( ) ; if ( this . destPorts != null ) this . destPorts . clear ( ) ; } public boolean hasIC ( ) { return this . hasIC ; } public String getIC ( ) { return this . IC ; } public boolean isInput ( ) { return this . isInput ; } public boolean isControl ( ) { return this . isControl ; } public boolean isDisturbance ( ) { return this . isDisturbance ; } public boolean isState ( ) { return this . isState ; } public boolean isStateDeriv ( ) { return this . isStateDeriv ; } public boolean isOutput ( ) { return this . isOutput ; } public boolean isStdAIAA ( ) { return this . isStdAIAA ; } public void setDescription ( String newDescription ) { this . description = newDescription ; } public String getDescription ( ) { return this . description ; } public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; if ( this . isDerived ( ) ) { if ( this . source != null ) { cvn . appendCode ( "<STR_LIT:(>" ) ; cvn . append ( this . source . genCode ( ) ) ; cvn . appendCode ( "<STR_LIT:)>" ) ; } } else { cvn . appendCode ( this . getVarID ( ) ) ; cvn . addVarName ( this . getVarID ( ) ) ; } if ( this . source != null ) this . setDefinedFlag ( ) ; return cvn ; } public void describeSelf ( FileWriter writer ) throws IOException { int numDests = dests . size ( ) ; Block outputBlock ; Integer outputBPort ; int thePortNum ; writer . write ( "<STR_LIT>" + myName + "<STR_LIT>" + myUnits + "<STR_LIT>" + myVarID + "<STR_LIT>" ) ; if ( source == null ) writer . write ( "<STR_LIT>" ) ; else { writer . write ( "<STR_LIT>" + sourcePort + "<STR_LIT>" ) ; writer . write ( source . getName ( ) + "<STR_LIT:U+0020toU+0020>" ) ; } switch ( numDests ) { case <NUM_LIT:0> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:1> : thePortNum = ( destPorts . get ( <NUM_LIT:0> ) ) . intValue ( ) ; writer . write ( "<STR_LIT>" + thePortNum + "<STR_LIT>" ) ; outputBlock = dests . get ( <NUM_LIT:0> ) ; writer . write ( outputBlock . getName ( ) + "<STR_LIT:.>" ) ; break ; default : writer . write ( "<STR_LIT>" + numDests + "<STR_LIT>" ) ; Iterator < Block > outBlockIterator = dests . iterator ( ) ; Iterator < Integer > outBPortIterator = destPorts . iterator ( ) ; while ( outBlockIterator . hasNext ( ) ) { outputBlock = outBlockIterator . next ( ) ; outputBPort = outBPortIterator . next ( ) ; thePortNum = outputBPort . intValue ( ) ; writer . write ( "<STR_LIT>" + thePortNum + "<STR_LIT>" + outputBlock . getName ( ) ) ; if ( outBlockIterator . hasNext ( ) ) writer . write ( "<STR_LIT:n>" ) ; } } } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . util . ArrayList ; import org . jdom . Element ; import org . jdom . Namespace ; public class BreakpointSet { String bpid ; ArrayList < Double > bpValues ; String myDescription ; String myName ; Model myModel ; boolean verbose ; BlockArrayList users ; public BreakpointSet ( Model m ) { this . bpid = "<STR_LIT>" ; this . bpValues = null ; this . myDescription = "<STR_LIT>" ; this . myName = "<STR_LIT>" ; this . myModel = m ; this . verbose = false ; this . users = new BlockArrayList ( <NUM_LIT:3> ) ; } public BreakpointSet ( Element bpdef , Model m ) throws DAVEException { this ( m ) ; if ( bpdef . getAttributeValue ( "<STR_LIT:name>" ) != null ) this . myName = bpdef . getAttributeValue ( "<STR_LIT:name>" ) ; else this . myName = null ; this . bpid = bpdef . getAttributeValue ( "<STR_LIT>" ) ; if ( this . bpid == null ) throw new DAVEException ( "<STR_LIT>" + this . myName ) ; m . register ( this ) ; Namespace ns = null ; Element parent = bpdef . getParentElement ( ) ; if ( parent != null ) ns = parent . getNamespace ( ) ; Element descrip = bpdef . getChild ( "<STR_LIT:description>" , ns ) ; if ( descrip != null ) this . myDescription = descrip . getTextTrim ( ) ; else this . myDescription = null ; this . users = new BlockArrayList ( <NUM_LIT:5> ) ; Element set = bpdef . getChild ( "<STR_LIT>" , ns ) ; try { this . bpValues = ParseText . toList ( set . getTextTrim ( ) ) ; } catch ( IOException e ) { throw new DAVEException ( "<STR_LIT>" + this . bpid ) ; } if ( this . bpValues == null ) { throw new DAVEException ( "<STR_LIT>" + this . bpid ) ; } if ( this . bpValues . size ( ) < <NUM_LIT:1> ) { throw new DAVEException ( "<STR_LIT>" + this . bpid ) ; } } public BreakpointSet ( String setName , String bpID , String setValues , String description , Model m ) throws DAVEException { this ( m ) ; this . myName = setName ; this . myDescription = description ; this . bpid = bpID ; this . verbose = false ; try { this . bpValues = ParseText . toList ( setValues ) ; } catch ( IOException e ) { throw new DAVEException ( "<STR_LIT>" + this . myName ) ; } m . register ( this ) ; } public void register ( BlockBP userBlockBP ) { this . users . add ( userBlockBP ) ; } public boolean isVerbose ( ) { return this . verbose ; } public void makeVerbose ( ) { this . verbose = true ; } public void silence ( ) { this . verbose = false ; } public String getName ( ) { return this . myName ; } public String getBPID ( ) { return this . bpid ; } public int length ( ) { if ( bpValues == null ) return <NUM_LIT:0> ; return this . bpValues . size ( ) ; } public ArrayList < Double > values ( ) { return this . bpValues ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; public class BlockInput extends Block { String units ; public BlockInput ( Signal theSignal , Model m ) { super ( theSignal . getName ( ) , "<STR_LIT>" , <NUM_LIT:0> , m ) ; this . units = theSignal . getUnits ( ) ; try { this . addOutput ( theSignal ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } } public void setInputValue ( double theValue ) { this . value = theValue ; } public String getUnits ( ) { return this . units ; } public int getSeqNumber ( ) { BlockArrayList modelInputs = this . ourModel . getInputBlocks ( ) ; return modelInputs . indexOf ( this ) + <NUM_LIT:1> ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; String code = "<STR_LIT>" ; Signal theSignal = this . getOutput ( ) ; if ( theSignal != null ) { cvn . addVarName ( outVarID ) ; code += outVarID ; if ( theSignal . isStdAIAA ( ) ) code += "<STR_LIT:U+0020(>" + theSignal . getName ( ) + "<STR_LIT:)>" ; code += "<STR_LIT>" ; if ( units . equalsIgnoreCase ( "<STR_LIT>" ) ) code += "<STR_LIT>" ; else code += "<STR_LIT>" + units + "<STR_LIT:'>" ; } cvn . appendCode ( this . wrapComment ( code ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT:U+0020(>" + units + "<STR_LIT:)>" ) ; } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } this . resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathProduct extends BlockMath { String blockType ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathProduct ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; this . blockType = first . getName ( ) ; this . setName ( blockType + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( blockType . equals ( "<STR_LIT>" ) ) { this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } else if ( blockType . equals ( "<STR_LIT>" ) ) { if ( kids . size ( ) != <NUM_LIT:3> ) System . err . println ( "<STR_LIT>" + ( kids . size ( ) - <NUM_LIT:1> ) ) ; else this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } else if ( blockType . equals ( "<STR_LIT>" ) ) { if ( kids . size ( ) != <NUM_LIT:3> ) System . err . println ( "<STR_LIT>" + ( kids . size ( ) - <NUM_LIT:1> ) ) ; else this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } else { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + blockType ) ; } } public String getBlockType ( ) { return this . blockType ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Iterator < Signal > inputSig = inputs . iterator ( ) ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } while ( inputSig . hasNext ( ) ) { Signal inSig = inputSig . next ( ) ; cvn . append ( inSig . genCode ( ) ) ; if ( inputSig . hasNext ( ) ) { if ( this . blockType . equals ( "<STR_LIT>" ) ) cvn . appendCode ( "<STR_LIT:*>" ) ; else if ( this . blockType . equals ( "<STR_LIT>" ) ) cvn . appendCode ( "<STR_LIT:/>" ) ; else if ( this . blockType . equals ( "<STR_LIT>" ) ) cvn . appendCode ( "<STR_LIT:/>" ) ; } } if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { Iterator < Signal > theInputs ; double [ ] inputVals ; Signal theInput ; int index = <NUM_LIT:0> ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } theInputs = this . inputs . iterator ( ) ; inputVals = new double [ this . inputs . size ( ) ] ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { inputVals [ index ] = theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + inputVals [ index ] ) ; } index ++ ; } if ( this . blockType . equals ( "<STR_LIT>" ) ) { this . value = <NUM_LIT:1.0> ; for ( int i = <NUM_LIT:0> ; i < inputVals . length ; i ++ ) this . value *= inputVals [ i ] ; } else { this . value = inputVals [ <NUM_LIT:0> ] / inputVals [ <NUM_LIT:1> ] ; } resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . PrintWriter ; import java . io . Writer ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . jdom . Element ; import org . jdom . Namespace ; public class BlockFuncTable extends Block { boolean simple ; String gtID ; FuncTable functionTableDef ; String description ; String functionDefName ; Namespace ns ; public BlockFuncTable ( Element function , Model m ) throws IOException { super ( function . getAttributeValue ( "<STR_LIT:name>" ) , "<STR_LIT>" , <NUM_LIT:3> , m ) ; this . ns = function . getNamespace ( ) ; if ( function . getChild ( "<STR_LIT:description>" , this . ns ) != null ) this . description = function . getChild ( "<STR_LIT:description>" , this . ns ) . getTextTrim ( ) ; else this . description = "<STR_LIT>" ; this . functionDefName = "<STR_LIT>" ; if ( function . getChild ( "<STR_LIT>" , this . ns ) != null ) { this . simple = false ; this . functionDefName = function . getChild ( "<STR_LIT>" , this . ns ) . getAttributeValue ( "<STR_LIT:name>" ) ; if ( this . functionDefName == null ) { this . functionDefName = "<STR_LIT>" + this . ourModel . getNumBlocks ( ) ; } this . setName ( this . functionDefName ) ; Element gt = function . getChild ( "<STR_LIT>" , this . ns ) . getChild ( "<STR_LIT>" , this . ns ) ; Element gtd = function . getChild ( "<STR_LIT>" , this . ns ) . getChild ( "<STR_LIT>" , this . ns ) ; Element gtr = function . getChild ( "<STR_LIT>" , this . ns ) . getChild ( "<STR_LIT>" , this . ns ) ; if ( gt != null ) { String internalID = this . getName ( ) + "<STR_LIT>" ; this . functionTableDef = new FuncTable ( internalID , gt , m ) ; } else if ( gtd != null ) { this . functionTableDef = new FuncTable ( gtd , m ) ; } else if ( gtr != null ) { this . gtID = gtr . getAttributeValue ( "<STR_LIT>" ) ; this . functionTableDef = this . ourModel . getTableByID ( this . gtID ) ; if ( this . functionTableDef == null ) { System . err . println ( "<STR_LIT>" + this . functionDefName + "<STR_LIT>" + this . gtID ) ; System . exit ( <NUM_LIT:0> ) ; } } else { System . err . println ( "<STR_LIT>" + this . functionDefName + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . functionTableDef . register ( this ) ; parseVarIDsFromFunctionElement ( function ) ; } else { this . simple = true ; if ( function . getChild ( "<STR_LIT>" , this . ns ) == null ) { System . err . println ( "<STR_LIT>" + this . myName + "<STR_LIT:'>" ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } else parseSimpleFunction ( function ) ; } hookUpOutput ( function ) ; hookUpInputs ( ) ; } public BlockFuncTable ( BlockFuncTable b ) { super ( b ) ; this . simple = b . simple ; this . gtID = b . gtID ; this . functionTableDef = b . functionTableDef ; this . description = b . description ; this . functionDefName = b . functionDefName ; } public FuncTable getFunctionTableDef ( ) { return this . functionTableDef ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) void parseSimpleFunction ( Element function ) throws IOException { Element outTable = function . getChild ( "<STR_LIT>" , this . ns ) ; List < Element > iVarPts = function . getChildren ( "<STR_LIT>" , this . ns ) ; Iterator < Element > iVarPtsIterator = iVarPts . iterator ( ) ; String funcTableName = "<STR_LIT>" + this . myName + "<STR_LIT>" ; this . functionTableDef = new FuncTable ( funcTableName , funcTableName , outTable . getTextTrim ( ) , "<STR_LIT>" , iVarPts . size ( ) , ourModel ) ; if ( this . functionTableDef == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . functionTableDef . register ( this ) ; this . outVarID = outTable . getAttributeValue ( "<STR_LIT>" ) ; int i = <NUM_LIT:1> ; while ( iVarPtsIterator . hasNext ( ) ) { Element iVarPtsElement = iVarPtsIterator . next ( ) ; String inVarID = iVarPtsElement . getAttributeValue ( "<STR_LIT>" ) ; this . addVarID ( i , inVarID ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inVarID + "<STR_LIT>" + this . functionDefName ) ; String bpName = "<STR_LIT>" + this . myName + "<STR_LIT>" + i ; this . functionTableDef . addBPID ( i - <NUM_LIT:1> , bpName ) ; Element inTable = function . getChild ( "<STR_LIT>" , this . ns ) ; if ( inTable == null ) { System . err . println ( "<STR_LIT>" + this . functionDefName ) ; System . exit ( <NUM_LIT:0> ) ; } String bpDescription = new String ( "<STR_LIT>" + this . getName ( ) ) ; try { new BreakpointSet ( bpName , bpName , inTable . getTextTrim ( ) , bpDescription , this . ourModel ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + bpName + "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + bpName + "<STR_LIT>" + this . functionDefName ) ; i ++ ; } this . functionTableDef . setDimensions ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) protected void parseVarIDsFromFunctionElement ( Element function ) { List < Element > iVarRefs = function . getChildren ( "<STR_LIT>" , this . ns ) ; Iterator < Element > iVarRefIterator = iVarRefs . iterator ( ) ; int i = <NUM_LIT:0> ; while ( iVarRefIterator . hasNext ( ) ) { Element iVarRefElement = iVarRefIterator . next ( ) ; String theVarID = iVarRefElement . getAttributeValue ( "<STR_LIT>" ) ; this . addVarID ( i + <NUM_LIT:1> , theVarID ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theVarID ) ; i ++ ; } Element outVar = function . getChild ( "<STR_LIT>" , this . ns ) ; this . outVarID = outVar . getAttributeValue ( "<STR_LIT>" ) ; } protected String hookUpOutput ( Element function ) { Element depVar = function . getChild ( "<STR_LIT>" , this . ns ) ; if ( depVar == null ) depVar = function . getChild ( "<STR_LIT>" , this . ns ) ; String depVarID = depVar . getAttributeValue ( "<STR_LIT>" ) ; Iterator < Signal > sigIterator = this . ourModel . getSignals ( ) . iterator ( ) ; boolean depVarSignalFound = false ; Signal dVsig = null ; while ( sigIterator . hasNext ( ) ) { dVsig = sigIterator . next ( ) ; if ( depVarID . equals ( dVsig . getVarID ( ) ) ) { depVarSignalFound = true ; break ; } } if ( ! depVarSignalFound ) { System . err . println ( "<STR_LIT>" + depVarID + "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } try { this . addOutput ( dVsig ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + depVarID + "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } return dVsig . getName ( ) ; } protected void createAndHookUpIWPath ( String bpID , String varID , String iwSignalID , int portNum ) { Signal connector = null ; if ( this . isVerbose ( ) ) System . out . print ( "<STR_LIT>" + varID + "<STR_LIT>" ) ; Signal theBPInputSignal = ourModel . getSignals ( ) . findByID ( varID ) ; if ( theBPInputSignal != null ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" ) ; String connectorName = theBPInputSignal . getName ( ) + "<STR_LIT>" + bpID ; String units = theBPInputSignal . getUnits ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + connectorName + "<STR_LIT>" + iwSignalID + "<STR_LIT>" + units + "<STR_LIT:'>" ) ; connector = new Signal ( connectorName , iwSignalID , units , <NUM_LIT:2> , ourModel ) ; connector . setDerivedFlag ( ) ; connector . addSink ( this , portNum + <NUM_LIT:1> ) ; } else { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + iwSignalID + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } try { new BlockBP ( bpID , bpID , theBPInputSignal , connector , ourModel ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } } protected void hookUpInputs ( ) { int portCount = <NUM_LIT:0> ; Iterator < String > iVarIDIterator = this . getVarIDIterator ( ) ; Iterator < String > bpIDIterator = this . functionTableDef . getBPIterator ( ) ; String signalVarID = null ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + this . myName ) ; while ( bpIDIterator . hasNext ( ) ) { String bpID = bpIDIterator . next ( ) ; if ( this . isVerbose ( ) ) System . out . print ( "<STR_LIT>" + bpID + "<STR_LIT:'>" ) ; if ( ! iVarIDIterator . hasNext ( ) ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT:'>" + this . getName ( ) + "<STR_LIT>" + bpID + "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } else { signalVarID = iVarIDIterator . next ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + signalVarID + "<STR_LIT:'>" ) ; } String iwSignalID = signalVarID + "<STR_LIT>" + bpID ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + iwSignalID + "<STR_LIT:'>" ) ; Signal theSignal = ourModel . getSignals ( ) . findByID ( iwSignalID ) ; if ( theSignal != null ) { theSignal . addSink ( this , portCount + <NUM_LIT:1> ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + iwSignalID + "<STR_LIT>" + ( portCount + <NUM_LIT:1> ) ) ; } else { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + iwSignalID + "<STR_LIT>" ) ; createAndHookUpIWPath ( bpID , signalVarID , iwSignalID , portCount ) ; } portCount ++ ; } } public void reorderInputsForMDL ( ) { if ( this . numInputs ( ) > <NUM_LIT:2> ) { Iterator < Signal > theInputsIterator = this . getInputIterator ( ) ; while ( theInputsIterator . hasNext ( ) ) { Signal theInput = theInputsIterator . next ( ) ; BlockArrayList destBlocks = theInput . getDests ( ) ; ArrayList < Integer > destPorts = theInput . getDestPortNumbers ( ) ; Iterator < Block > destBlockIterator = destBlocks . iterator ( ) ; Iterator < Integer > destPortIterator = destPorts . iterator ( ) ; int thePortIndex = <NUM_LIT:0> ; while ( destBlockIterator . hasNext ( ) ) { Block destBlock = destBlockIterator . next ( ) ; Integer destPort = destPortIterator . next ( ) ; if ( destBlock == this ) { int oldPortNumber = destPort . intValue ( ) ; int newPortNumber = ( this . numInputs ( ) + <NUM_LIT:1> ) - oldPortNumber ; if ( oldPortNumber == ( this . numInputs ( ) - <NUM_LIT:1> ) ) newPortNumber = <NUM_LIT:1> ; if ( oldPortNumber == ( this . numInputs ( ) ) ) newPortNumber = <NUM_LIT:2> ; theInput . setPortNumber ( thePortIndex , newPortNumber ) ; } thePortIndex ++ ; } } } } public void printTable ( Writer writer ) throws IOException { FuncTable gft = this . getFunctionTableDef ( ) ; if ( gft != null ) gft . printTable ( writer ) ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" + this . functionTableDef . size ( ) + "<STR_LIT>" ) ; } public void update ( ) throws DAVEException { int numInputs ; Iterator < Signal > theInputs ; Signal theInput ; double [ ] iwv ; int [ ] iv ; int index = <NUM_LIT:0> ; boolean ready = true ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } numInputs = this . inputs . size ( ) ; if ( numInputs != this . functionTableDef . numDim ( ) ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; theInputs = this . inputs . iterator ( ) ; iwv = new double [ numInputs ] ; iv = new int [ numInputs ] ; if ( verbose ) System . out . println ( "<STR_LIT>" + this . inputs . size ( ) ) ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { ready = false ; if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; iwv [ index ] = <NUM_LIT:0.0> ; iv [ index ] = <NUM_LIT:0> ; } else { iwv [ index ] = theInput . sourceValue ( ) ; iv [ index ] = ( int ) theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + iwv [ index ] ) ; } index ++ ; } if ( ! ready ) return ; this . value = this . interpolate ( iwv , iv , numInputs ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + this . value ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } private double interpolate ( double [ ] index_and_weights , int [ ] indices , int interpDimension ) { int select ; double weight ; double a ; double b ; double value ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . myName + "<STR_LIT>" + interpDimension ) ; } select = indices . length - interpDimension ; if ( indices [ select ] >= ( this . functionTableDef . dim ( select ) - <NUM_LIT:1> ) ) { indices [ select ] -- ; weight = <NUM_LIT:1.0> ; if ( verbose ) System . out . println ( "<STR_LIT>" + interpDimension ) ; } else weight = index_and_weights [ select ] - ( double ) indices [ select ] ; if ( verbose ) System . out . println ( "<STR_LIT>" + interpDimension + "<STR_LIT>" + select + "<STR_LIT>" + indices [ select ] + "<STR_LIT>" + weight ) ; if ( interpDimension == <NUM_LIT:1> ) { a = this . functionTableDef . getPt ( indices ) ; indices [ select ] ++ ; b = this . functionTableDef . getPt ( indices ) ; indices [ select ] -- ; } else { a = this . interpolate ( index_and_weights , indices , interpDimension - <NUM_LIT:1> ) ; indices [ select ] ++ ; b = this . interpolate ( index_and_weights , indices , interpDimension - <NUM_LIT:1> ) ; indices [ select ] -- ; } value = a + ( b - a ) * weight ; if ( verbose ) System . out . println ( "<STR_LIT>" + a + "<STR_LIT:U+0020andU+0020>" + b + "<STR_LIT>" + value ) ; return value ; } public String getDescription ( ) { return description . replaceAll ( System . getProperty ( "<STR_LIT>" ) , "<STR_LIT:U+0020>" ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; import java . util . Iterator ; import java . io . IOException ; import java . io . Writer ; abstract public class Block { Model ourModel ; String myName ; String myType ; NameList nameList ; private ArrayList < String > inVarIDs ; SignalArrayList inputs ; protected String outVarID ; private Signal output ; protected int resultsCycleCount ; double value ; boolean verboseFlag ; protected boolean selectedFlag ; Object mask ; public Block ( ) { this . ourModel = null ; this . myName = null ; this . myType = "<STR_LIT>" ; this . nameList = null ; this . output = null ; this . inVarIDs = new ArrayList < String > ( <NUM_LIT:1> ) ; this . inputs = new SignalArrayList ( <NUM_LIT:1> ) ; this . resultsCycleCount = - <NUM_LIT:1> ; this . value = Double . NaN ; this . verboseFlag = false ; this . selectedFlag = true ; this . mask = null ; } public Block ( Model m ) { this ( ) ; this . ourModel = m ; m . add ( this ) ; } public Block ( String blockName , String blockType , int numInputs , Model m ) { this ( ) ; this . ourModel = m ; this . myName = blockName ; this . myType = blockType ; this . inVarIDs = new ArrayList < String > ( numInputs ) ; this . inputs = new SignalArrayList ( numInputs ) ; m . add ( this ) ; } public Block ( Block b ) { this ( ) ; this . ourModel = b . getModel ( ) ; this . myName = b . getName ( ) ; this . myType = b . getType ( ) ; this . nameList = b . nameList ; this . inVarIDs = b . inVarIDs ; this . inputs = b . inputs ; this . outVarID = b . outVarID ; this . output = b . output ; } protected double getValue ( ) { return this . value ; } public boolean isReady ( ) { return ourModel . getCycleCounter ( ) == this . resultsCycleCount ; } public boolean allInputsConnected ( ) { boolean answer = true ; Iterator < Signal > it = this . getInputIterator ( ) ; while ( it . hasNext ( ) && answer ) { answer = answer && ( it . next ( ) != null ) ; } return answer ; } public boolean outputConnected ( ) { return ( this . output != null ) ; } public boolean allInputsReady ( ) { boolean allReady = true ; Iterator < Signal > sigIt = this . getInputIterator ( ) ; while ( sigIt . hasNext ( ) ) try { allReady = allReady && sigIt . next ( ) . sourceReady ( ) ; } catch ( DAVEException e ) { System . err . println ( e . getMessage ( ) ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } return allReady ; } public void makeVerbose ( ) { this . verboseFlag = true ; } public void silence ( ) { this . verboseFlag = false ; } public boolean isVerbose ( ) { return this . verboseFlag ; } public void select ( ) { selectedFlag = true ; } public void selectWithAncestors ( ) { this . select ( ) ; Iterator < Signal > sigIt = this . getInputIterator ( ) ; while ( sigIt . hasNext ( ) ) { Signal sig = sigIt . next ( ) ; Block ancestor = sig . getSource ( ) ; if ( ancestor != null ) ancestor . selectWithAncestors ( ) ; } } public void deselect ( ) { selectedFlag = false ; } public boolean isSelected ( ) { return selectedFlag ; } public void setMask ( Object o ) { this . mask = o ; } public Object getMask ( ) { return this . mask ; } public int addInput ( Signal inSignal ) { int portIndex ; inputs . add ( inSignal ) ; portIndex = inputs . indexOf ( inSignal ) ; while ( inVarIDs . size ( ) <= portIndex ) inVarIDs . add ( inSignal . getName ( ) ) ; String existingID = inVarIDs . get ( portIndex ) ; if ( existingID . equals ( "<STR_LIT>" ) ) inVarIDs . set ( portIndex , inSignal . getVarID ( ) ) ; return portIndex + <NUM_LIT:1> ; } public void addInput ( Signal inSignal , int portNum ) { int portIndex = portNum - <NUM_LIT:1> ; while ( inputs . size ( ) <= portIndex ) inputs . add ( inSignal ) ; inputs . set ( portIndex , inSignal ) ; while ( inVarIDs . size ( ) <= portIndex ) inVarIDs . add ( "<STR_LIT>" ) ; String existingID = inVarIDs . get ( portIndex ) ; if ( existingID . equals ( "<STR_LIT>" ) ) inVarIDs . set ( portIndex , inSignal . getVarID ( ) ) ; } public void addVarID ( int portNum , String varID ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + varID + "<STR_LIT>" + portNum + "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; int portIndex = portNum - <NUM_LIT:1> ; if ( portNum < <NUM_LIT:1> ) System . err . println ( "<STR_LIT>" + getName ( ) + "<STR_LIT>" + varID + "<STR_LIT>" + portNum + "<STR_LIT>" ) ; else { while ( inVarIDs . size ( ) <= portIndex ) inVarIDs . add ( "<STR_LIT>" ) ; inVarIDs . set ( portIndex , varID ) ; while ( inputs . size ( ) <= portIndex ) inputs . add ( null ) ; inputs . set ( portIndex , null ) ; } } public void replaceInput ( Signal oldSignal , Signal newSignal ) { while ( inputs . contains ( oldSignal ) ) { int oldSignalIndex = inputs . indexOf ( oldSignal ) ; if ( oldSignalIndex >= <NUM_LIT:0> ) { inputs . remove ( oldSignalIndex ) ; inputs . add ( oldSignalIndex , newSignal ) ; } } } public void addOutput ( Signal outSignal ) throws DAVEException { String newVarID = outSignal . getVarID ( ) ; if ( this . outVarID == null ) this . outVarID = newVarID ; else if ( ! this . outVarID . equals ( newVarID ) ) throw new DAVEException ( "<STR_LIT>" + newVarID + "<STR_LIT>" + this . outVarID + "<STR_LIT>" ) ; this . output = outSignal ; outSignal . addSource ( this , <NUM_LIT:1> ) ; } public void addOutput ( String outVarID ) { this . outVarID = outVarID ; } protected void addInput ( Block blk , int inPort ) { Signal sig ; if ( blk . outputConnected ( ) ) { sig = blk . output ; } else { sig = new Signal ( blk . getName ( ) , this . ourModel ) ; sig . setDerivedFlag ( ) ; try { blk . addOutput ( sig ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + blk . getName ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } sig . addSink ( this , inPort ) ; } } protected void addConstInput ( String constantValue , int inPort ) { Block constBlock = new BlockMathConstant ( constantValue , ourModel ) ; this . addInput ( constBlock , inPort ) ; Signal derivedConst = constBlock . getOutput ( ) ; derivedConst . setDerivedFlag ( ) ; } public Model getModel ( ) { return this . ourModel ; } public String getName ( ) { return this . myName ; } public String getType ( ) { return this . myType ; } public String getVarID ( int portNum ) { return inVarIDs . get ( portNum - <NUM_LIT:1> ) ; } public Iterator < Signal > getInputIterator ( ) { return this . inputs . iterator ( ) ; } public Signal getInput ( int index ) { return inputs . get ( index ) ; } public Signal getOutput ( ) { return this . output ; } public Iterator < String > getVarIDIterator ( ) { return this . inVarIDs . iterator ( ) ; } public String getOutputVarID ( ) { return this . outVarID ; } public void setNameList ( NameList newNameList ) { this . nameList = newNameList ; this . setName ( this . getName ( ) ) ; } protected void setName ( String newName ) { if ( this . nameList != null ) this . myName = this . nameList . addUnique ( newName ) ; else this . myName = newName ; } public void renameOutVarID ( ) { this . outVarID = this . output . getVarID ( ) ; } public void renameInVarID ( Integer portNum ) { Signal input = this . inputs . get ( portNum - <NUM_LIT:1> ) ; String newVarID = input . myVarID ; this . inVarIDs . set ( portNum - <NUM_LIT:1> , newVarID ) ; } public int numInputs ( ) { if ( this . inputs != null ) return this . inputs . size ( ) ; else return <NUM_LIT:0> ; } public int numVarIDs ( ) { return this . inVarIDs . size ( ) ; } protected boolean hookUpInput ( int port ) throws DAVEException { String signalVarID = inVarIDs . get ( port - <NUM_LIT:1> ) ; Signal theSignal = ourModel . getSignals ( ) . findByID ( signalVarID ) ; if ( theSignal != null ) { theSignal . addSink ( this , port ) ; return true ; } else { throw new DAVEException ( "<STR_LIT>" + signalVarID + "<STR_LIT>" + port + "<STR_LIT>" + getName ( ) + "<STR_LIT>" ) ; } } protected void hookUpInputs ( ) { int portCount = <NUM_LIT:0> ; Iterator < String > iVarIDIterator = this . inVarIDs . iterator ( ) ; while ( iVarIDIterator . hasNext ( ) ) { String signalVarID = iVarIDIterator . next ( ) ; Signal theSignal = ourModel . getSignals ( ) . findByID ( signalVarID ) ; if ( theSignal != null ) { theSignal . addSink ( this , portCount + <NUM_LIT:1> ) ; portCount ++ ; } else { System . err . println ( "<STR_LIT>" + signalVarID + "<STR_LIT>" ) ; } } } public void hookUp ( ) throws DAVEException { Iterator < Signal > it ; int i ; boolean result ; Signal s ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; it = this . getInputIterator ( ) ; i = <NUM_LIT:1> ; while ( it . hasNext ( ) ) { s = it . next ( ) ; if ( s == null ) { result = hookUpInput ( i ) ; if ( ! result ) { String inputSignalVarID = inVarIDs . get ( i - <NUM_LIT:1> ) ; throw new DAVEException ( "<STR_LIT>" + inputSignalVarID + "<STR_LIT>" ) ; } } i ++ ; } s = this . getOutput ( ) ; if ( s == null ) { if ( this . outVarID == null ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; s = ourModel . getSignals ( ) . findByID ( this . outVarID ) ; if ( s == null ) throw new DAVEException ( "<STR_LIT>" + this . outVarID + "<STR_LIT>" ) ; this . addOutput ( s ) ; } } public boolean verifyInputs ( ) { boolean error = false ; if ( inVarIDs . size ( ) < inputs . size ( ) ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } if ( inVarIDs . size ( ) > inputs . size ( ) ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } Iterator < Signal > ii = this . getInputIterator ( ) ; int i = <NUM_LIT:1> ; while ( ii . hasNext ( ) ) { Signal s = ii . next ( ) ; if ( s == null ) { try { error = error || ! this . hookUpInput ( i ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } i ++ ; } } return error ; } public boolean verifyOutputs ( ) { Signal s = this . getOutput ( ) ; if ( s == null ) { String theOutVarID = this . getOutputVarID ( ) ; if ( theOutVarID == null ) return false ; else { s = ourModel . getSignals ( ) . findByID ( theOutVarID ) ; try { this . addOutput ( s ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + theOutVarID + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } } } return ( s == null ) ; } public CodeAndVarNames genCode ( ) { return new CodeAndVarNames ( wrapComment ( "<STR_LIT>" + "<STR_LIT>" + outVarID + "<STR_LIT>" + this . myType + "<STR_LIT:\">" ) ) ; } public String indent ( ) { String indent = "<STR_LIT>" ; int dialect = ourModel . getCodeDialect ( ) ; switch ( dialect ) { case Model . DT_ANSI_C : indent = "<STR_LIT:U+0020U+0020>" ; break ; case Model . DT_FORTRAN : indent = "<STR_LIT>" ; break ; } return indent ; } public String wrapComment ( String comment ) { String wrappedComment = "<STR_LIT>" ; int dialect = ourModel . getCodeDialect ( ) ; switch ( dialect ) { case Model . DT_ANSI_C : wrappedComment = "<STR_LIT>" + comment + "<STR_LIT>" ; break ; case Model . DT_FORTRAN : wrappedComment = "<STR_LIT>" + comment ; break ; } wrappedComment += "<STR_LIT:n>" ; return wrappedComment ; } public String errorComment ( String errMsg ) { return this . wrapComment ( "<STR_LIT>" + errMsg ) ; } public String endLine ( ) { String lineEnd = "<STR_LIT:n>" ; if ( ourModel . getCodeDialect ( ) == Model . DT_ANSI_C ) lineEnd = "<STR_LIT>" ; return lineEnd ; } public String beginIf ( String condition ) { String ifStart = "<STR_LIT>" ; int dialect = ourModel . getCodeDialect ( ) ; switch ( dialect ) { case Model . DT_ANSI_C : ifStart = indent ( ) + "<STR_LIT>" + condition + "<STR_LIT>" ; break ; case Model . DT_FORTRAN : ifStart = indent ( ) + "<STR_LIT>" + condition + "<STR_LIT>" ; break ; } return ifStart ; } public String endIf ( ) { String ifEnd = "<STR_LIT>" ; int dialect = ourModel . getCodeDialect ( ) ; switch ( dialect ) { case Model . DT_ANSI_C : ifEnd = indent ( ) + "<STR_LIT>" ; break ; case Model . DT_FORTRAN : ifEnd = indent ( ) + "<STR_LIT>" ; break ; } return ifEnd ; } public void describeSelf ( Writer writer ) throws IOException { int numInputs = inputs . size ( ) ; int numOutputs = <NUM_LIT:0> ; if ( this . output != null ) numOutputs = <NUM_LIT:1> ; writer . write ( "<STR_LIT>" + myName + "<STR_LIT>" ) ; switch ( numInputs ) { case <NUM_LIT:0> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:1> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:2> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:3> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:4> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:5> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:6> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:7> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:8> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:9> : writer . write ( "<STR_LIT>" ) ; break ; default : writer . write ( numInputs + "<STR_LIT>" ) ; } if ( numInputs > <NUM_LIT:0> ) { Iterator < Signal > sigIt = this . getInputIterator ( ) ; while ( sigIt . hasNext ( ) ) { Signal sig = sigIt . next ( ) ; if ( sig != null ) { String theName = sig . getName ( ) ; if ( theName == null ) writer . write ( "<STR_LIT>" ) ; else writer . write ( theName ) ; } if ( sigIt . hasNext ( ) ) writer . write ( "<STR_LIT:U+002CU+0020>" ) ; } writer . write ( "<STR_LIT>" ) ; } switch ( numOutputs ) { case <NUM_LIT:0> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:1> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:2> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:3> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:4> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:5> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:6> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:7> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:8> : writer . write ( "<STR_LIT>" ) ; break ; case <NUM_LIT:9> : writer . write ( "<STR_LIT>" ) ; break ; default : writer . write ( numOutputs + "<STR_LIT:U+0020(>" ) ; } if ( numOutputs > <NUM_LIT:0> ) { Signal sig = this . getOutput ( ) ; if ( sig != null ) { String theName = sig . getName ( ) ; if ( theName == null ) writer . write ( "<STR_LIT>" ) ; else writer . write ( theName ) ; } writer . write ( "<STR_LIT>" ) ; } writer . write ( "<STR_LIT>" + this . value + "<STR_LIT:]>" ) ; } abstract public void update ( ) throws DAVEException ; } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; public class BlockLimiter extends Block { String units ; Double lowerLim ; Double upperLim ; boolean hasLowerLim ; boolean hasUpperLim ; public BlockLimiter ( Signal sourceSignal , Model m , double lowerLimit , double upperLimit ) { super ( sourceSignal . getName ( ) + "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> , m ) ; this . units = sourceSignal . getUnits ( ) ; lowerLim = lowerLimit ; upperLim = upperLimit ; if ( lowerLim > upperLim ) { Double temp = lowerLim ; lowerLim = upperLim ; upperLim = temp ; } hasLowerLim = ! lowerLim . isInfinite ( ) ; hasUpperLim = ! upperLim . isInfinite ( ) ; sourceSignal . addSink ( this , <NUM_LIT:1> ) ; } @ Override public double getValue ( ) { return this . value ; } public String getUnits ( ) { return this . units ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; String rel ; Signal input ; Signal outputSig = this . getOutput ( ) ; if ( outputSig != null ) if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } input = inputs . get ( <NUM_LIT:0> ) ; int dialect = ourModel . getCodeDialect ( ) ; cvn . append ( input . genCode ( ) ) ; if ( this . hasLowerLimit ( ) ) { cvn . appendCode ( endLine ( ) ) ; rel = "<STR_LIT>" ; if ( dialect == Model . DT_FORTRAN ) rel = "<STR_LIT>" ; cvn . appendCode ( beginIf ( outVarID + rel + lowerLim . toString ( ) ) ) ; cvn . appendCode ( indent ( ) + "<STR_LIT:U+0020U+0020>" + outVarID + "<STR_LIT:U+0020=U+0020>" + lowerLim . toString ( ) ) ; cvn . appendCode ( endLine ( ) ) ; cvn . appendCode ( endIf ( ) ) ; } if ( this . hasUpperLimit ( ) ) { if ( ! this . hasLowerLimit ( ) ) cvn . appendCode ( endLine ( ) ) ; rel = "<STR_LIT>" ; if ( dialect == Model . DT_FORTRAN ) rel = "<STR_LIT>" ; cvn . appendCode ( beginIf ( outVarID + rel + upperLim . toString ( ) ) ) ; cvn . appendCode ( indent ( ) + "<STR_LIT:U+0020U+0020>" + outVarID + "<STR_LIT:U+0020=U+0020>" + upperLim . toString ( ) ) ; cvn . appendCode ( endLine ( ) ) ; cvn . appendCode ( endIf ( ) ) ; } if ( outputSig != null ) if ( ! outputSig . isDerived ( ) ) if ( ! this . hasLowerLimit ( ) && ! this . hasUpperLimit ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT:U+0020(>" + units + "<STR_LIT>" + "<STR_LIT>" + lowerLim + "<STR_LIT>" + upperLim + "<STR_LIT:.>" ) ; } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( this . inputs . size ( ) > <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; Signal theInput = this . inputs . get ( <NUM_LIT:0> ) ; if ( ! theInput . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } double inputValue = theInput . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue ) ; this . resultsCycleCount = ourModel . getCycleCounter ( ) ; this . value = inputValue ; if ( hasLowerLim ) if ( this . value < lowerLim ) this . value = lowerLim ; if ( hasUpperLim ) if ( this . value > upperLim ) this . value = upperLim ; } public boolean hasLowerLimit ( ) { return hasLowerLim ; } public boolean hasUpperLimit ( ) { return hasUpperLim ; } public double getLowerLimit ( ) { return lowerLim . doubleValue ( ) ; } public double getUpperLimit ( ) { return upperLim . doubleValue ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import com . sun . org . apache . xerces . internal . util . XMLCatalogResolver ; import java . io . * ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . logging . Level ; import java . util . logging . Logger ; import org . jdom . Document ; import org . jdom . Element ; import org . jdom . JDOMException ; import org . jdom . Namespace ; import org . jdom . input . SAXBuilder ; public class DAVE { String myVersion ; Model m ; Namespace ns ; int argNum ; String base_uri ; String args [ ] ; String inputFileName ; String listFileName ; String stubName ; boolean makeListing ; boolean createInternalValues ; boolean evaluate ; boolean verboseFlag ; boolean genStatsFlag ; boolean noProcessingRequired ; boolean helpRequested ; int varDefCount ; int bpDefCount ; int gtDefCount ; int functionCount ; int checkCaseCount ; InputStream _inputStream ; long parseStartTime ; long parseStopTime ; Element root ; CheckData checkcases ; private static final int exit_success = <NUM_LIT:0> ; private static final int exit_failure = <NUM_LIT:1> ; public DAVE ( ) { this . makeListing = false ; this . createInternalValues = false ; this . evaluate = false ; this . verboseFlag = false ; this . genStatsFlag = false ; this . noProcessingRequired = false ; this . helpRequested = false ; this . checkCaseCount = <NUM_LIT:0> ; this . m = new Model ( <NUM_LIT:20> , <NUM_LIT:20> ) ; String date = "<STR_LIT>" ; this . myVersion = "<STR_LIT>" + date + "<STR_LIT:)>" ; } public DAVE ( String args [ ] ) { this ( ) ; this . parseOptions ( args ) ; if ( this . verboseFlag ) { m . makeVerbose ( ) ; } if ( this . helpRequested ) { this . printHelp ( ) ; } } public void makeVerbose ( ) { this . verboseFlag = true ; this . m . makeVerbose ( ) ; } public void silence ( ) { this . verboseFlag = false ; this . m . silence ( ) ; } public boolean isVerbose ( ) { return this . verboseFlag ; } public String getVersion ( ) { return this . myVersion ; } public boolean hasCheckcases ( ) { return this . checkcases != null ; } public CheckData getCheckcaseData ( ) { return this . checkcases ; } public void setInputFileName ( String fn ) { this . inputFileName = fn ; this . stubName = DAVE . toStubName ( fn ) ; } public String getInputFileName ( ) { return this . inputFileName ; } public String getStubName ( ) { return this . stubName ; } public Model getModel ( ) { return this . m ; } ; public void setGenStatsFlag ( ) { this . genStatsFlag = true ; } public boolean getGenStatsFlag ( ) { return this . genStatsFlag ; } public void setArgs ( String args [ ] ) { this . args = args ; } public String [ ] getArgs ( ) { return this . args ; } public int numCmdLineSwitches ( ) { int index ; int count = <NUM_LIT:0> ; for ( index = <NUM_LIT:0> ; index < this . args . length ; index ++ ) { if ( this . args [ index ] . startsWith ( "<STR_LIT:->" ) ) { count ++ ; } } return count ; } public boolean verify ( ) { boolean result = true ; int goodCases = <NUM_LIT:0> ; if ( checkcases == null ) { return true ; } ArrayList < StaticShot > shots = checkcases . getStaticShots ( ) ; Iterator < StaticShot > shit = shots . iterator ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + shots . size ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( shit . hasNext ( ) ) { StaticShot shot = shit . next ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + shot . getName ( ) + "<STR_LIT:'>" ) ; System . out . println ( "<STR_LIT>" ) ; } try { VectorInfoArrayList inputVec = m . getInputVector ( ) ; shot . loadInputVector ( inputVec ) ; m . cycle ( ) ; VectorInfoArrayList outputVec = m . getOutputVector ( ) ; if ( outputVec == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( exit_failure ) ; } boolean matched = shot . checkOutputs ( outputVec ) ; if ( ! matched ) { System . err . println ( "<STR_LIT>" + shot . getName ( ) + "<STR_LIT>" ) ; result = false ; } else { goodCases ++ ; if ( this . createInternalValues ) { String checkCaseName = this . stubName + "<STR_LIT:_>" + toFileName ( shot . getName ( ) ) + "<STR_LIT>" ; FileOutputStream fos = new FileOutputStream ( checkCaseName ) ; PrintWriter pw = new PrintWriter ( fos ) ; m . generateInternalValues ( pw ) ; pw . flush ( ) ; fos . close ( ) ; } } } catch ( Exception e ) { System . err . println ( "<STR_LIT>" ) ; System . err . println ( e . getMessage ( ) ) ; System . exit ( exit_failure ) ; } } System . out . println ( "<STR_LIT>" + goodCases + "<STR_LIT>" + shots . size ( ) + "<STR_LIT>" ) ; if ( this . createInternalValues ) { System . out . println ( "<STR_LIT>" ) ; } return result ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void parseVariableDefs ( ) { Signal dummySig ; List < Element > variableList = root . getChildren ( "<STR_LIT>" , this . ns ) ; if ( variableList . size ( ) > <NUM_LIT:0> ) { Iterator < Element > variableIterator = variableList . iterator ( ) ; this . varDefCount = variableList . size ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + varDefCount + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( variableIterator . hasNext ( ) ) { dummySig = new Signal ( variableIterator . next ( ) , m ) ; } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void parseTableDefs ( ) { FuncTable dummyFuncTable ; List < Element > gtdList = root . getChildren ( "<STR_LIT>" , this . ns ) ; if ( gtdList . size ( ) > <NUM_LIT:0> ) { Iterator gtdi = gtdList . iterator ( ) ; this . gtDefCount = gtdList . size ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + gtDefCount + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( gtdi . hasNext ( ) ) { try { dummyFuncTable = new FuncTable ( ( Element ) gtdi . next ( ) , m ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( exit_failure ) ; } } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void parseBreakpointDefs ( ) { BreakpointSet ignored ; List < Element > bpList = root . getChildren ( "<STR_LIT>" , this . ns ) ; if ( bpList . size ( ) > <NUM_LIT:0> ) { Iterator bpIt = bpList . iterator ( ) ; this . bpDefCount = bpList . size ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + bpDefCount + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( bpIt . hasNext ( ) ) { try { ignored = new BreakpointSet ( ( Element ) bpIt . next ( ) , m ) ; } catch ( Exception e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( exit_failure ) ; } } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void parseFunctions ( ) { BlockFuncTable ignored ; List < Element > functionList = root . getChildren ( "<STR_LIT>" , this . ns ) ; if ( functionList . size ( ) > <NUM_LIT:0> ) { Iterator functionIterator = functionList . iterator ( ) ; this . functionCount = functionList . size ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + functionCount + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( functionIterator . hasNext ( ) ) { try { ignored = new BlockFuncTable ( ( Element ) functionIterator . next ( ) , m ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( exit_failure ) ; } } } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public void parseCheckCases ( ) { Element checkData = root . getChild ( "<STR_LIT>" , this . ns ) ; if ( checkData != null ) { this . checkcases = new CheckData ( checkData . getChildren ( "<STR_LIT>" , this . ns ) ) ; this . checkCaseCount = this . checkcases . count ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + checkCaseCount + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } } } public boolean parseFile ( ) throws IOException { File f = new File ( this . inputFileName ) ; String fullURI = f . toURI ( ) . toString ( ) ; this . base_uri = fullURI ; this . m . setName ( this . stubName ) ; this . parseStartTime = System . currentTimeMillis ( ) ; Document doc = load ( ) ; root = doc . getRootElement ( ) ; this . ns = root . getNamespace ( ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" + this . ns . getURI ( ) + "<STR_LIT>" ) ; } parseVariableDefs ( ) ; parseBreakpointDefs ( ) ; parseTableDefs ( ) ; parseFunctions ( ) ; m . wireBlocks ( ) ; m . hookUpIO ( ) ; parseCheckCases ( ) ; this . parseStopTime = System . currentTimeMillis ( ) ; boolean result = m . verifyIntegrity ( ) ; try { m . initialize ( ) ; } catch ( DAVEException ex ) { Logger . getLogger ( DAVE . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } return result ; } public Document load ( ) throws IOException { Document doc = null ; XMLCatalogResolver cr = null ; String directory_uri = this . base_uri . substring ( <NUM_LIT:0> , this . base_uri . lastIndexOf ( '<CHAR_LIT:/>' ) ) ; String errorLine = "<STR_LIT>" ; boolean tryValidationFlag = true ; int numberOfFailures = <NUM_LIT:0> ; boolean success = false ; while ( numberOfFailures < <NUM_LIT:2> && ! success ) { success = true ; errorLine = "<STR_LIT>" ; try { _inputStream = new FileInputStream ( this . inputFileName ) ; assert ( _inputStream != null ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" + this . inputFileName + "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } try { SAXBuilder builder = new SAXBuilder ( tryValidationFlag ) ; builder . setFeature ( "<STR_LIT>" , false ) ; if ( tryValidationFlag ) { String [ ] catalogs ; String xml_catalog_files = System . getenv ( "<STR_LIT>" ) ; if ( xml_catalog_files == null ) { xml_catalog_files = System . getProperty ( "<STR_LIT>" ) ; } if ( xml_catalog_files != null ) { catalogs = new String [ ] { xml_catalog_files , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } else { catalogs = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; } cr = new XMLCatalogResolver ( catalogs ) ; } else { cr = null ; } builder . setEntityResolver ( cr ) ; doc = builder . build ( _inputStream , directory_uri ) ; } catch ( java . io . FileNotFoundException e ) { errorLine = errorLine + e . getMessage ( ) ; numberOfFailures ++ ; success = false ; } catch ( java . net . UnknownHostException e ) { errorLine = errorLine + "<STR_LIT>" ; numberOfFailures ++ ; success = false ; } catch ( java . net . ConnectException e ) { errorLine = errorLine + "<STR_LIT>" ; numberOfFailures ++ ; success = false ; } catch ( java . io . IOException e ) { errorLine = errorLine + "<STR_LIT>" ; numberOfFailures ++ ; success = false ; } catch ( JDOMException e ) { errorLine = errorLine + "<STR_LIT:n>" + e . getMessage ( ) ; numberOfFailures ++ ; success = false ; } if ( numberOfFailures == <NUM_LIT:1> && ! success ) { System . err . println ( errorLine ) ; System . err . println ( "<STR_LIT>" ) ; tryValidationFlag = false ; _inputStream . close ( ) ; } } if ( ! success && numberOfFailures >= <NUM_LIT:2> ) { _inputStream . close ( ) ; System . err . println ( errorLine ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( - <NUM_LIT:1> ) ; } if ( success ) { System . out . println ( "<STR_LIT>" + this . inputFileName + "<STR_LIT>" ) ; org . jdom . DocType dt = doc . getDocType ( ) ; switch ( numberOfFailures ) { case <NUM_LIT:0> : System . out . print ( "<STR_LIT>" ) ; String catalogURI = cr . resolvePublic ( dt . getPublicID ( ) , dt . getSystemID ( ) ) ; if ( catalogURI == null ) { System . out . print ( dt . getSystemID ( ) ) ; } else { System . out . print ( catalogURI ) ; } System . out . println ( "<STR_LIT>" ) ; break ; case <NUM_LIT:1> : System . out . println ( "<STR_LIT>" ) ; } } return doc ; } public void describeSelf ( ) { try { TreeFileWriter writer = new TreeFileWriter ( this . listFileName ) ; writer . describe ( m ) ; writer . close ( ) ; } catch ( IOException e ) { return ; } } public void reportStats ( ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + this . varDefCount ) ; System . out . println ( "<STR_LIT>" + this . bpDefCount ) ; System . out . println ( "<STR_LIT>" + this . gtDefCount ) ; System . out . println ( "<STR_LIT>" + this . functionCount ) ; if ( this . checkCaseCount > <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + this . checkCaseCount ) ; } System . out . println ( ) ; System . out . println ( "<STR_LIT>" + ( this . parseStopTime - this . parseStartTime ) / <NUM_LIT> + "<STR_LIT>" ) ; System . out . println ( ) ; m . reportStats ( ) ; } static String toStubName ( String inString ) { File F = new File ( inString ) ; String name = F . getName ( ) ; StringBuilder buf = new StringBuilder ( name ) ; String stubName ; stubName = null ; int dotIndex = buf . length ( ) ; while ( dotIndex > <NUM_LIT:0> ) { dotIndex -- ; if ( buf . charAt ( dotIndex ) == '<CHAR_LIT:.>' ) { break ; } } if ( dotIndex > <NUM_LIT:0> ) { stubName = buf . substring ( <NUM_LIT:0> , dotIndex ) ; } return stubName ; } static String toFileName ( String inString ) { int limit = <NUM_LIT:32> ; StringBuilder buf = new StringBuilder ( inString ) ; StringWriter fileName = new StringWriter ( limit ) ; for ( int i = <NUM_LIT:0> ; ( i < buf . length ( ) ) && ( fileName . getBuffer ( ) . length ( ) < limit ) ; i ++ ) { char c = buf . charAt ( i ) ; switch ( c ) { case '<CHAR_LIT:.>' : case '<CHAR_LIT:U+002C>' : case '<CHAR_LIT:;>' : case '<CHAR_LIT::>' : case '<STR_LIT>' : case '<CHAR_LIT:">' : case '<CHAR_LIT:(>' : case '<CHAR_LIT:)>' : case '<CHAR_LIT:[>' : case '<CHAR_LIT:]>' : case '<CHAR_LIT>' : case '<CHAR_LIT:}>' : break ; case '<CHAR_LIT:U+0020>' : case '<STR_LIT:\t>' : fileName . write ( '<CHAR_LIT:_>' ) ; break ; default : fileName . write ( c ) ; } } return fileName . toString ( ) ; } public int loadInputs ( VectorInfoArrayList inVec ) throws IOException { int tokenType ; FileReader frin = new FileReader ( FileDescriptor . in ) ; StreamTokenizer st = new StreamTokenizer ( frin ) ; st . parseNumbers ( ) ; st . eolIsSignificant ( true ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; Iterator < VectorInfo > in = inVec . iterator ( ) ; while ( in . hasNext ( ) ) { boolean blankLine = false ; VectorInfo inVal = in . next ( ) ; System . out . print ( "<STR_LIT>" + inVal . getName ( ) + "<STR_LIT:U+0020(>" + inVal . getUnits ( ) + "<STR_LIT>" + inVal . getValue ( ) + "<STR_LIT>" ) ; do { tokenType = st . nextToken ( ) ; if ( tokenType == StreamTokenizer . TT_EOF ) { return - <NUM_LIT:1> ; } if ( tokenType == StreamTokenizer . TT_EOL ) { blankLine = true ; break ; } } while ( tokenType != StreamTokenizer . TT_NUMBER ) ; if ( ! blankLine ) { try { inVal . setValue ( st . nval ) ; } catch ( NumberFormatException e ) { } do { tokenType = st . nextToken ( ) ; if ( tokenType == StreamTokenizer . TT_EOF ) { return - <NUM_LIT:1> ; } } while ( tokenType != StreamTokenizer . TT_EOL ) ; } } return <NUM_LIT:0> ; } public void listOutputs ( VectorInfoArrayList outVec ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; Iterator < VectorInfo > it = outVec . iterator ( ) ; while ( it . hasNext ( ) ) { VectorInfo vi = it . next ( ) ; System . out . print ( "<STR_LIT:U+0020U+0020>" + vi . getName ( ) + "<STR_LIT:U+0020=U+0020>" + vi . getValue ( ) ) ; if ( vi . getUnits ( ) . length ( ) > <NUM_LIT:0> ) { System . out . println ( "<STR_LIT:U+0020(>" + vi . getUnits ( ) + "<STR_LIT:)>" ) ; } else { System . out . println ( ) ; } } System . out . println ( ) ; } protected boolean matchOptionArgs ( String uniqueOptionStart , String fullOptionString ) { boolean matched = false ; int index ; for ( index = <NUM_LIT:0> ; index < this . args . length ; index ++ ) { if ( this . args [ index ] . startsWith ( "<STR_LIT:-->" ) ) { if ( this . args [ index ] . startsWith ( "<STR_LIT:-->" + fullOptionString ) ) { matched = true ; this . argNum = index ; } } if ( this . args [ index ] . startsWith ( "<STR_LIT:->" ) ) { if ( this . args [ index ] . startsWith ( "<STR_LIT:->" + uniqueOptionStart ) ) { matched = true ; this . argNum = index ; } } } return matched ; } private void printHelp ( ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } private void parseOptions ( String inArgs [ ] ) { String exampleUse = "<STR_LIT>" ; int numArgs = inArgs . length ; if ( numArgs < <NUM_LIT:1> ) { System . out . println ( exampleUse ) ; System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . setArgs ( inArgs ) ; this . inputFileName = this . args [ numArgs - <NUM_LIT:1> ] ; if ( this . inputFileName . startsWith ( "<STR_LIT:->" ) ) { numArgs ++ ; } else { this . stubName = DAVE . toStubName ( this . inputFileName ) ; this . listFileName = this . stubName + "<STR_LIT>" ; } if ( numArgs > <NUM_LIT:1> ) { int parsedArgs = <NUM_LIT:0> ; if ( matchOptionArgs ( "<STR_LIT:c>" , "<STR_LIT:count>" ) ) { this . genStatsFlag = true ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT:d>" , "<STR_LIT>" ) ) { this . verboseFlag = true ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT:e>" , "<STR_LIT>" ) ) { this . evaluate = true ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT:i>" , "<STR_LIT>" ) ) { this . createInternalValues = true ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT>" , "<STR_LIT:list>" ) ) { this . makeListing = true ; if ( numArgs > ( this . argNum + <NUM_LIT:2> ) ) { if ( ! this . args [ this . argNum + <NUM_LIT:1> ] . startsWith ( "<STR_LIT:->" ) ) { this . listFileName = this . args [ this . argNum + <NUM_LIT:1> ] ; } } parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT>" , "<STR_LIT:version>" ) ) { this . noProcessingRequired = true ; System . out . println ( "<STR_LIT>" + getVersion ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } if ( matchOptionArgs ( "<STR_LIT>" , "<STR_LIT>" ) ) { this . noProcessingRequired = true ; this . helpRequested = true ; parsedArgs ++ ; } int numSwitches = this . numCmdLineSwitches ( ) ; if ( parsedArgs < numSwitches ) { System . err . print ( "<STR_LIT>" ) ; if ( numSwitches == <NUM_LIT:1> ) { System . err . println ( "<STR_LIT>" + this . args [ this . argNum ] + "<STR_LIT>" ) ; } else if ( numSwitches == <NUM_LIT:2> ) { System . err . println ( "<STR_LIT>" ) ; } else { System . err . println ( "<STR_LIT>" + numSwitches + "<STR_LIT>" ) ; } System . err . println ( exampleUse ) ; System . exit ( <NUM_LIT:0> ) ; } } } public static void main ( String args [ ] ) { boolean success = false ; DAVE dave = new DAVE ( args ) ; if ( dave . noProcessingRequired ) { System . exit ( exit_success ) ; } try { success = dave . parseFile ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } if ( ! success ) { System . exit ( exit_failure ) ; } if ( dave . checkcases != null ) { if ( ! dave . verify ( ) ) { System . exit ( exit_failure ) ; } } if ( dave . genStatsFlag ) { dave . reportStats ( ) ; } if ( dave . makeListing ) { dave . describeSelf ( ) ; } if ( dave . evaluate ) { while ( true ) { try { VectorInfoArrayList inputVec = dave . m . getInputVector ( ) ; int eof = dave . loadInputs ( inputVec ) ; if ( eof == - <NUM_LIT:1> ) { System . out . println ( ) ; System . exit ( exit_success ) ; } dave . m . cycle ( ) ; VectorInfoArrayList outputVec = dave . m . getOutputVector ( ) ; if ( outputVec == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( exit_failure ) ; } dave . listOutputs ( outputVec ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; } } } } } </s>
<s> package gov . nasa . daveml . dave ; </s>
<s> package gov . nasa . daveml . dave ; import java . util . HashMap ; import java . util . Iterator ; import java . util . ListIterator ; import java . util . Map ; import java . util . Set ; import java . io . PrintWriter ; import java . io . StringWriter ; import java . util . ArrayList ; public class Model { protected String ourName ; SignalArrayList signals ; BlockArrayList blocks ; Map < String , BreakpointSet > breakpointSets ; Map < String , FuncTable > tables ; Map < String , BlockBP > bpBlocks ; BlockArrayList executeOrder ; BlockArrayList inputBlocks ; BlockArrayList outputBlocks ; VectorInfoArrayList inputVec ; VectorInfoArrayList outputVec ; String dataFormat ; boolean initialized ; boolean verbose ; int cycleCounter ; int codeDialect ; public static final int DT_FORTRAN = <NUM_LIT:0> ; public static final int DT_ANSI_C = <NUM_LIT:1> ; private static final int exit_success = <NUM_LIT:0> ; private static final int exit_failure = <NUM_LIT:1> ; private static String defaultDataFormat = "<STR_LIT>" ; public Model ( int numBlocks , int numSignals ) { this . signals = new SignalArrayList ( numSignals ) ; this . blocks = new BlockArrayList ( numBlocks ) ; this . breakpointSets = new HashMap < String , BreakpointSet > ( ) ; this . tables = new HashMap < String , FuncTable > ( ) ; this . bpBlocks = new HashMap < String , BlockBP > ( ) ; this . executeOrder = new BlockArrayList ( numBlocks ) ; this . inputBlocks = new BlockArrayList ( numBlocks ) ; this . outputBlocks = new BlockArrayList ( numBlocks ) ; this . initialized = false ; this . verbose = false ; this . cycleCounter = <NUM_LIT:0> ; this . ourName = "<STR_LIT>" ; this . codeDialect = DT_ANSI_C ; this . dataFormat = defaultDataFormat ; } public Model ( ) { this ( <NUM_LIT:20> , <NUM_LIT:20> ) ; } public void setName ( String theName ) { this . ourName = theName ; } public String getName ( ) { return this . ourName ; } public int getCycleCounter ( ) { return this . cycleCounter ; } public void resetCycleCounter ( ) { this . cycleCounter = <NUM_LIT:0> ; } public void incrementCycleCounter ( ) { this . cycleCounter ++ ; } public void makeVerbose ( ) { this . verbose = true ; if ( signals != null ) { Iterator < ? > it = signals . iterator ( ) ; while ( it . hasNext ( ) ) { Signal s = ( Signal ) it . next ( ) ; s . makeVerbose ( ) ; } } if ( blocks != null ) { Iterator < ? > it = blocks . iterator ( ) ; while ( it . hasNext ( ) ) { Block b = ( Block ) it . next ( ) ; b . makeVerbose ( ) ; } } } public void silence ( ) { this . verbose = false ; if ( signals != null ) { Iterator < ? > it = signals . iterator ( ) ; while ( it . hasNext ( ) ) { Signal s = ( Signal ) it . next ( ) ; s . silence ( ) ; } } if ( blocks != null ) { Iterator < ? > it = blocks . iterator ( ) ; while ( it . hasNext ( ) ) { Block b = ( Block ) it . next ( ) ; b . silence ( ) ; } } } public boolean isVerbose ( ) { return this . verbose ; } public void clearSelections ( ) { Iterator < Block > blkIt = this . blocks . iterator ( ) ; while ( blkIt . hasNext ( ) ) { Block blk = blkIt . next ( ) ; blk . deselect ( ) ; } } public boolean selectOutputByName ( String varName ) { boolean found = false ; Iterator < Block > blkIt = this . outputBlocks . iterator ( ) ; while ( blkIt . hasNext ( ) ) { Block blk = blkIt . next ( ) ; if ( blk . numInputs ( ) > <NUM_LIT:0> ) { Signal inputSig = blk . getInput ( <NUM_LIT:0> ) ; if ( inputSig . myName . equals ( varName ) ) { found = true ; blk . selectWithAncestors ( ) ; break ; } } } return found ; } public SignalArrayList getSignals ( ) { return signals ; } public BlockArrayList getBlocks ( ) { return blocks ; } public int getNumInputBlocks ( ) { return inputBlocks . size ( ) ; } public BlockArrayList getInputBlocks ( ) { return inputBlocks ; } public int getNumOutputBlocks ( ) { return outputBlocks . size ( ) ; } public BlockArrayList getOutputBlocks ( ) { return outputBlocks ; } public int getCodeDialect ( ) { return codeDialect ; } public void setCodeDialect ( int dialect ) { codeDialect = dialect ; } public void add ( Block newBlock ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" + newBlock . getType ( ) + "<STR_LIT>" + newBlock . getName ( ) + "<STR_LIT>" ) ; newBlock . makeVerbose ( ) ; } blocks . add ( newBlock ) ; if ( newBlock instanceof BlockInput ) { inputBlocks . add ( newBlock ) ; if ( this . verbose ) System . out . println ( "<STR_LIT>" + inputBlocks . size ( ) ) ; } if ( newBlock instanceof BlockOutput ) outputBlocks . add ( newBlock ) ; } public void add ( Signal newSignal ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" + newSignal . getName ( ) + "<STR_LIT>" ) ; newSignal . makeVerbose ( ) ; } signals . add ( newSignal ) ; } public void register ( BreakpointSet newBPSet ) { int oldSize = <NUM_LIT:0> ; int setSize = <NUM_LIT:0> ; if ( this . verbose ) { System . out . println ( "<STR_LIT>" + newBPSet . getName ( ) + "<STR_LIT:U+0020(>" + newBPSet . getBPID ( ) + "<STR_LIT>" ) ; oldSize = breakpointSets . size ( ) ; } breakpointSets . put ( newBPSet . getBPID ( ) , newBPSet ) ; if ( this . verbose ) { String key = newBPSet . getBPID ( ) ; boolean success = breakpointSets . containsKey ( key ) ; setSize = breakpointSets . size ( ) ; System . out . println ( "<STR_LIT>" + setSize ) ; if ( success && ( setSize > oldSize ) ) System . out . println ( "<STR_LIT>" + key + "<STR_LIT:'>" ) ; else System . out . println ( "<STR_LIT>" ) ; } } public BreakpointSet getBPSetByID ( String bpID ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" + bpID + "<STR_LIT:'>" ) ; } if ( this . breakpointSets . containsKey ( bpID ) ) { return breakpointSets . get ( bpID ) ; } else { System . err . println ( "<STR_LIT>" + bpID + "<STR_LIT>" ) ; System . exit ( exit_failure ) ; } return null ; } public void register ( BlockBP newBPBlock ) { int oldSize = <NUM_LIT:0> ; int setSize = <NUM_LIT:0> ; String key = newBPBlock . getName ( ) ; if ( this . verbose ) { System . out . println ( "<STR_LIT>" + key + "<STR_LIT>" ) ; oldSize = bpBlocks . size ( ) ; } bpBlocks . put ( key , newBPBlock ) ; if ( this . verbose ) { boolean success = bpBlocks . containsKey ( key ) ; setSize = bpBlocks . size ( ) ; System . out . println ( "<STR_LIT>" + setSize ) ; if ( success && ( setSize > oldSize ) ) System . out . println ( "<STR_LIT>" + key + "<STR_LIT:'>" ) ; else System . out . println ( "<STR_LIT>" ) ; } } public BlockBP getBPBlockByID ( String bpID ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" + bpID + "<STR_LIT:'>" ) ; } if ( bpBlocks . containsKey ( bpID ) ) { return bpBlocks . get ( bpID ) ; } else { System . err . println ( "<STR_LIT>" + bpID + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } return null ; } public void register ( FuncTable newTable ) { int oldSize = <NUM_LIT:0> ; int setSize = <NUM_LIT:0> ; String key = newTable . getGTID ( ) ; if ( key == null ) { key = newTable . getName ( ) + "<STR_LIT>" ; } if ( this . verbose ) { System . out . println ( "<STR_LIT>" + newTable . getName ( ) + "<STR_LIT:U+0020(>" + key + "<STR_LIT>" ) ; oldSize = tables . size ( ) ; } tables . put ( key , newTable ) ; if ( this . verbose ) { boolean success = tables . containsKey ( key ) ; setSize = tables . size ( ) ; System . out . println ( "<STR_LIT>" + setSize ) ; if ( success && ( setSize > oldSize ) ) System . out . println ( "<STR_LIT>" + key + "<STR_LIT:'>" ) ; else System . out . println ( "<STR_LIT>" ) ; } } public FuncTable getTableByID ( String gtID ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" + gtID + "<STR_LIT:'>" ) ; } if ( tables . containsKey ( gtID ) ) { return tables . get ( gtID ) ; } else { System . err . println ( "<STR_LIT>" + gtID + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } return null ; } public int getNumBlocks ( ) { return blocks . size ( ) ; } public int getNumSignals ( ) { return signals . size ( ) ; } public int getNumTables ( ) { return tables . size ( ) ; } public void wireBlocks ( ) { Iterator < Block > it = blocks . iterator ( ) ; int numBlocks = blocks . size ( ) ; if ( numBlocks > <NUM_LIT:0> && this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + numBlocks + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( it . hasNext ( ) ) { Block b = it . next ( ) ; try { b . hookUp ( ) ; } catch ( DAVEException e ) { System . err . println ( e . getMessage ( ) ) ; System . err . println ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } } } public void hookUpIO ( ) { Signal theSignal ; Iterator < Signal > it ; ArrayList < Signal > modifiedSignals = new ArrayList < Signal > ( <NUM_LIT:0> ) ; it = this . signals . iterator ( ) ; Block ignored ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( it . hasNext ( ) ) { theSignal = it . next ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theSignal . getName ( ) + "<STR_LIT:'>" ) ; if ( ! theSignal . hasSource ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" ) ; if ( theSignal . hasIC ( ) && ! ( theSignal . isInput ( ) || theSignal . isControl ( ) || theSignal . isDisturbance ( ) ) ) { Block b = new BlockMathConstant ( theSignal . getIC ( ) , this ) ; try { b . addOutput ( theSignal ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } } else { ignored = new BlockInput ( theSignal , this ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" ) ; } } if ( theSignal . isLimited ( ) ) setUpLimiterFor ( theSignal , modifiedSignals ) ; if ( ! theSignal . hasDest ( ) || theSignal . isOutput ( ) ) ignored = new BlockOutput ( theSignal , this ) ; } it = modifiedSignals . iterator ( ) ; while ( it . hasNext ( ) ) { this . add ( it . next ( ) ) ; } } public void setUpLimiterFor ( Signal theSignal , ArrayList < Signal > modifiedSignals ) { Block ignored ; Signal limitedSignal = new Signal ( theSignal ) ; boolean OK = modifiedSignals . add ( limitedSignal ) ; assert ( OK ) ; limitedSignal . setDerivedFlag ( ) ; BlockArrayList origDests = ( BlockArrayList ) theSignal . getDests ( ) . clone ( ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) ArrayList < Integer > origPorts = ( ArrayList < Integer > ) theSignal . getDestPortNumbers ( ) . clone ( ) ; String origName = theSignal . getName ( ) ; String origVarID = theSignal . getVarID ( ) ; theSignal . setName ( theSignal . getName ( ) + "<STR_LIT>" ) ; theSignal . setVarID ( theSignal . getVarID ( ) + "<STR_LIT>" ) ; theSignal . removeDestBlocks ( ) ; theSignal . getSource ( ) . renameOutVarID ( ) ; BlockLimiter limiter = new BlockLimiter ( theSignal , this , theSignal . getLowerLimit ( ) , theSignal . getUpperLimit ( ) ) ; Iterator < Block > it = origDests . iterator ( ) ; while ( it . hasNext ( ) ) { Block b = it . next ( ) ; b . replaceInput ( theSignal , limitedSignal ) ; } try { limiter . addOutput ( limitedSignal ) ; } catch ( DAVEException ex ) { System . err . println ( "<STR_LIT>" + origName ) ; theSignal . dests = origDests ; theSignal . destPorts = origPorts ; theSignal . setName ( origName ) ; theSignal . setVarID ( origVarID ) ; } theSignal . clearIsOutputFlag ( ) ; theSignal . setLowerLimit ( Double . NEGATIVE_INFINITY ) ; theSignal . setUpperLimit ( Double . POSITIVE_INFINITY ) ; if ( ! limitedSignal . hasDest ( ) || limitedSignal . isOutput ( ) ) ignored = new BlockOutput ( limitedSignal , this ) ; return ; } public boolean verifyIntegrity ( ) { boolean missing ; boolean OK ; OK = true ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } Iterator < Block > blockIterator = this . getBlocks ( ) . iterator ( ) ; while ( blockIterator . hasNext ( ) ) { Block b = blockIterator . next ( ) ; missing = b . verifyInputs ( ) ; if ( missing ) { System . err . println ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; OK = false ; } missing = b . verifyOutputs ( ) ; if ( missing ) { System . err . println ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; OK = false ; } } Iterator < Signal > signalIterator = this . getSignals ( ) . iterator ( ) ; while ( signalIterator . hasNext ( ) ) { Signal s = signalIterator . next ( ) ; missing = ! s . hasSource ( ) ; if ( missing ) { System . err . println ( "<STR_LIT>" + s . getName ( ) + "<STR_LIT>" ) ; OK = false ; } missing = ! s . hasDest ( ) ; if ( missing ) { System . err . println ( "<STR_LIT>" + s . getName ( ) + "<STR_LIT>" ) ; OK = false ; } } return OK ; } public void generateInternalValues ( PrintWriter out ) { Iterator < ? > it = this . signals . iterator ( ) ; if ( it != null ) if ( it . hasNext ( ) ) { out . println ( "<STR_LIT>" ) ; while ( it . hasNext ( ) ) { Signal s = ( Signal ) it . next ( ) ; if ( ! s . isDerived ( ) ) { out . print ( "<STR_LIT>" ) ; out . print ( s . getVarID ( ) ) ; out . print ( "<STR_LIT>" ) ; try { out . print ( s . sourceValue ( ) ) ; } catch ( DAVEException e ) { System . err . println ( e . getMessage ( ) ) ; System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } out . print ( "<STR_LIT>" ) ; out . println ( ) ; } } out . println ( "<STR_LIT>" ) ; } } public void initialize ( ) throws DAVEException { if ( ! this . initialized ) { StringWriter strwriter = null ; if ( this . isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; System . out . println ( ) ; strwriter = new StringWriter ( ) ; if ( strwriter == null ) System . err . println ( "<STR_LIT>" ) ; } BlockArrayList blks = ( BlockArrayList ) blocks . clone ( ) ; ListIterator < Block > candidates ; Iterator < Block > blockIterator ; Block b ; boolean progress = true ; int blocksNotReady ; int oldBlocksNotReady = Integer . MAX_VALUE ; while ( ! blks . isEmpty ( ) && progress ) { blocksNotReady = <NUM_LIT:0> ; blockIterator = blks . iterator ( ) ; if ( this . verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + blks . size ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } while ( blockIterator . hasNext ( ) ) { b = blockIterator . next ( ) ; if ( ! b . isReady ( ) ) try { blocksNotReady ++ ; b . update ( ) ; } catch ( DAVEException e ) { System . out . print ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . out . println ( "<STR_LIT>" ) ; } catch ( RuntimeException e ) { System . out . print ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( e . getMessage ( ) + "<STR_LIT>" ) ; throw e ; } } if ( this . verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } candidates = blks . listIterator ( ) ; while ( candidates . hasNext ( ) ) { b = candidates . next ( ) ; if ( this . verbose ) { System . out . print ( "<STR_LIT>" + b . getName ( ) + "<STR_LIT>" ) ; } if ( b . isReady ( ) ) { if ( this . verbose ) { System . out . println ( "<STR_LIT>" ) ; } executeOrder . add ( b ) ; candidates . remove ( ) ; } else { if ( this . verbose ) System . out . println ( "<STR_LIT>" ) ; } } progress = blocksNotReady < oldBlocksNotReady ; oldBlocksNotReady = blocksNotReady ; } String errorMsg = "<STR_LIT>" ; if ( ! blks . isEmpty ( ) ) { errorMsg = "<STR_LIT>" ; errorMsg = errorMsg + blks . size ( ) + "<STR_LIT>" ; throw new DAVEException ( errorMsg ) ; } this . initialized = true ; if ( this . verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } try { int i = <NUM_LIT:1> ; blockIterator = executeOrder . iterator ( ) ; while ( blockIterator . hasNext ( ) ) { b = blockIterator . next ( ) ; if ( this . verbose ) { strwriter . write ( i + "<STR_LIT:U+0020>" ) ; b . describeSelf ( strwriter ) ; strwriter . write ( "<STR_LIT:n>" ) ; } i ++ ; } if ( this . verbose ) System . out . print ( strwriter . toString ( ) ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; System . exit ( exit_failure ) ; } if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } } } public VectorInfoArrayList getOutputVector ( ) throws DAVEException { if ( this . outputVec == null ) { this . outputVec = new VectorInfoArrayList ( ) ; Iterator < ? > outBlks = this . outputBlocks . iterator ( ) ; while ( outBlks . hasNext ( ) ) { Block theBlk = ( Block ) outBlks . next ( ) ; if ( theBlk == null ) throw new DAVEException ( "<STR_LIT>" ) ; if ( ! ( theBlk instanceof BlockOutput ) ) throw new DAVEException ( "<STR_LIT>" ) ; String theName = theBlk . getName ( ) ; String theUnits = ( ( BlockOutput ) theBlk ) . getUnits ( ) ; double theValue = theBlk . getValue ( ) ; VectorInfo vi = new VectorInfo ( theName , theUnits , theBlk , false ) ; vi . setValue ( theValue ) ; this . outputVec . add ( vi ) ; } } return this . outputVec ; } public VectorInfoArrayList getInputVector ( ) throws DAVEException { if ( this . inputVec == null ) { this . inputVec = new VectorInfoArrayList ( ) ; Iterator < ? > inBlks = this . inputBlocks . iterator ( ) ; while ( inBlks . hasNext ( ) ) { Block theBlk = ( Block ) inBlks . next ( ) ; if ( theBlk == null ) throw new DAVEException ( "<STR_LIT>" ) ; if ( ! ( theBlk instanceof BlockInput ) ) throw new DAVEException ( "<STR_LIT>" ) ; String inName = theBlk . getName ( ) ; String inUnits = ( ( BlockInput ) theBlk ) . getUnits ( ) ; VectorInfo vi = new VectorInfo ( inName , inUnits , theBlk , true ) ; this . inputVec . add ( vi ) ; } } return this . inputVec ; } public void cycle ( ) throws DAVEException { if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; System . out . println ( "<STR_LIT>" ) ; } if ( this . inputVec == null ) throw new DAVEException ( "<STR_LIT>" ) ; if ( this . inputVec . size ( ) != inputBlocks . size ( ) ) throw new DAVEException ( "<STR_LIT>" + inputVec . size ( ) + "<STR_LIT>" + inputBlocks . size ( ) ) ; Iterator < VectorInfo > inp = this . inputVec . iterator ( ) ; while ( inp . hasNext ( ) ) { VectorInfo vi = inp . next ( ) ; if ( vi == null ) throw new DAVEException ( "<STR_LIT>" ) ; BlockInput theBlk = vi . getSink ( ) ; double theValue = vi . getValue ( ) ; theBlk . setInputValue ( theValue ) ; } if ( ! this . initialized ) try { if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } this . initialize ( ) ; } catch ( Exception e ) { System . err . println ( e . getMessage ( ) ) ; System . exit ( exit_failure ) ; } else { Iterator < ? > theBlocks = executeOrder . iterator ( ) ; while ( theBlocks . hasNext ( ) ) { Block theBlock = ( Block ) theBlocks . next ( ) ; theBlock . update ( ) ; } } if ( this . outputVec == null ) { this . outputVec = new VectorInfoArrayList ( ) ; if ( this . outputVec == null ) throw new DAVEException ( "<STR_LIT>" ) ; Iterator < ? > outBlks = this . outputBlocks . iterator ( ) ; while ( outBlks . hasNext ( ) ) { Block theBlk = ( Block ) outBlks . next ( ) ; if ( theBlk == null ) throw new DAVEException ( "<STR_LIT>" ) ; if ( ! ( theBlk instanceof BlockOutput ) ) throw new DAVEException ( "<STR_LIT>" ) ; String theName = theBlk . getName ( ) ; String theUnits = ( ( BlockOutput ) theBlk ) . getUnits ( ) ; double theValue = theBlk . getValue ( ) ; VectorInfo vi = new VectorInfo ( theName , theUnits , theBlk , false ) ; if ( vi == null ) throw new DAVEException ( "<STR_LIT>" ) ; vi . setValue ( theValue ) ; this . outputVec . add ( vi ) ; } } else { if ( this . outputBlocks . size ( ) != this . outputVec . size ( ) ) throw new DAVEException ( "<STR_LIT>" ) ; Iterator < ? > outBlks = this . outputBlocks . iterator ( ) ; Iterator < ? > outVI = this . outputVec . iterator ( ) ; while ( outBlks . hasNext ( ) ) { BlockOutput theBlk = ( BlockOutput ) outBlks . next ( ) ; VectorInfo vi = ( VectorInfo ) outVI . next ( ) ; double theValue = theBlk . getValue ( ) ; vi . setValue ( theValue ) ; } } } public void reportStats ( ) { int total = <NUM_LIT:0> ; if ( ! tables . isEmpty ( ) ) { Set < String > tableKeySet = tables . keySet ( ) ; Iterator < String > tableKeyIt = tableKeySet . iterator ( ) ; while ( tableKeyIt . hasNext ( ) ) { String tableKey = tableKeyIt . next ( ) ; FuncTable theTable = this . tables . get ( tableKey ) ; total = total + theTable . size ( ) ; } } System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + this . tables . size ( ) ) ; System . out . println ( "<STR_LIT>" + this . breakpointSets . size ( ) ) ; System . out . println ( "<STR_LIT>" + total ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . signals . size ( ) ) ; System . out . println ( "<STR_LIT>" + this . blocks . size ( ) ) ; System . out . println ( "<STR_LIT>" + this . inputBlocks . size ( ) ) ; System . out . println ( "<STR_LIT>" + this . outputBlocks . size ( ) ) ; } public BlockArrayList getSortedBlocks ( ) throws DAVEException { if ( executeOrder == null ) { throw new DAVEException ( "<STR_LIT>" ) ; } return executeOrder ; } public BlockArrayList getSelectedBlocks ( ) throws DAVEException { BlockArrayList sortedBlocks = getSortedBlocks ( ) ; BlockArrayList selectedBlocks = new BlockArrayList ( ) ; Iterator < Block > blkIt = sortedBlocks . iterator ( ) ; while ( blkIt . hasNext ( ) ) { Block blk = blkIt . next ( ) ; if ( blk . isSelected ( ) ) selectedBlocks . add ( blk ) ; } return selectedBlocks ; } public Block getBlockByOutputVarID ( String theVarID ) { Block theBlock = null ; Signal theSignal = signals . findByID ( theVarID ) ; if ( theSignal != null ) { theBlock = theSignal . getSource ( ) ; } return theBlock ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . FileWriter ; import java . util . List ; import java . util . Iterator ; public class BlockMathFunctionExtension extends BlockMathFunction { private static final int ATAN2 = <NUM_LIT:11> ; private static String DAVEML_EXT_URL = "<STR_LIT>" ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathFunctionExtension ( Element applyElement , Model m ) { super ( m ) ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element csymbol = ikid . next ( ) ; if ( csymbol == null ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } String csName = csymbol . getName ( ) ; if ( csName == null ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } if ( ! csName . equals ( "<STR_LIT>" ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + csName ) ; System . exit ( <NUM_LIT:0> ) ; } int csSize = csymbol . getContentSize ( ) ; if ( csSize != <NUM_LIT:1> ) { System . err . println ( "<STR_LIT>" + csSize + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } String defURL = csymbol . getAttributeValue ( "<STR_LIT>" ) ; if ( defURL == null ) { System . err . println ( "<STR_LIT>" ) ; } if ( ! defURL . startsWith ( DAVEML_EXT_URL ) ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } String encoding = csymbol . getAttributeValue ( "<STR_LIT>" ) ; if ( encoding == null ) { System . err . println ( "<STR_LIT>" ) ; } if ( ! encoding . equals ( "<STR_LIT:text>" ) ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . funcType = csymbol . getTextTrim ( ) ; if ( this . funcType == null ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . setName ( this . funcType + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( this . funcType . equals ( "<STR_LIT>" ) ) { if ( defURL != null ) if ( ! defURL . equals ( DAVEML_EXT_URL + "<STR_LIT:#>" + this . funcType ) ) System . err . println ( "<STR_LIT>" ) ; this . op = ATAN2 ; this . myType = "<STR_LIT>" ; } else { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + this . funcType ) ; System . exit ( <NUM_LIT:0> ) ; } this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } public void setFunction ( String functionType ) throws DAVEException { if ( functionType != this . funcType ) super . setFunction ( functionType ) ; } public void describeSelf ( FileWriter writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } public void update ( ) throws DAVEException { int requiredNumInputs ; Iterator < Signal > theInputs ; Signal theInput ; double [ ] theInputValue ; int index ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . myType + "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myType + "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; requiredNumInputs = <NUM_LIT:1> ; if ( this . op > <NUM_LIT:9> ) requiredNumInputs = <NUM_LIT:2> ; if ( this . inputs . size ( ) > requiredNumInputs ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; index = <NUM_LIT:0> ; theInputValue = new double [ <NUM_LIT:2> ] ; theInputs = this . inputs . iterator ( ) ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { theInputValue [ index ] = theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + theInputValue [ index ] ) ; } index ++ ; } this . value = Double . NaN ; switch ( this . op ) { case ATAN2 : this . value = Math . atan2 ( theInputValue [ <NUM_LIT:0> ] , theInputValue [ <NUM_LIT:1> ] ) ; break ; } if ( this . value == Double . NaN ) throw new DAVEException ( "<STR_LIT>" + this . funcType + "<STR_LIT>" + this . getName ( ) ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . Collection ; import java . util . ArrayList ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class VectorInfoArrayList extends ArrayList < VectorInfo > { public VectorInfoArrayList ( ) { super ( ) ; } public VectorInfoArrayList ( int initialCapacity ) { super ( initialCapacity ) ; } public VectorInfoArrayList ( Collection < VectorInfo > c ) { super ( c ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; public class BlockMathConstant extends BlockMath { String stringValue ; public BlockMathConstant ( String constantValue , Model m ) { super ( "<STR_LIT>" + m . getNumBlocks ( ) , "<STR_LIT>" , m ) ; this . setValue ( constantValue ) ; } public double getValueAsDouble ( ) { return this . value ; } public String getValueAsString ( ) { return this . stringValue ; } public final void setValue ( String newValue ) { this . stringValue = newValue ; try { this . value = Double . parseDouble ( stringValue ) ; } catch ( java . lang . NumberFormatException e ) { System . err . println ( "<STR_LIT>" + newValue + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } } public void setValue ( Double newValue ) { this . value = newValue ; this . stringValue = newValue . toString ( ) ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } cvn . appendCode ( this . getValueAsString ( ) ) ; if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) > <NUM_LIT:0> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } @ Override public boolean isReady ( ) { return true ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathMinmax extends BlockMath { private static final int UNK = <NUM_LIT:0> ; private static final int MIN = <NUM_LIT:1> ; private static final int MAX = <NUM_LIT:2> ; String funcType ; int op ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathMinmax ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; this . funcType = null ; this . op = UNK ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; try { this . setFunction ( first . getName ( ) ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + first . getName ( ) ) ; } String blockType = first . getName ( ) ; this . setName ( blockType + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( blockType . equals ( "<STR_LIT>" ) || blockType . equals ( "<STR_LIT>" ) || blockType . equals ( "<STR_LIT>" ) || blockType . equals ( "<STR_LIT>" ) ) { this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } else { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + blockType ) ; } } private void setFunction ( String functionType ) throws DAVEException { this . funcType = functionType ; this . setName ( funcType + "<STR_LIT:_>" + this . ourModel . getNumBlocks ( ) ) ; if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = MIN ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = MAX ; this . myType = "<STR_LIT>" ; } else throw new DAVEException ( "<STR_LIT>" + this . funcType + "<STR_LIT>" ) ; } public String getFuncType ( ) { return funcType ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } public void update ( ) throws DAVEException { Iterator < Signal > theInputs ; double [ ] inputVals ; Signal theInput ; int index ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } theInputs = this . inputs . iterator ( ) ; inputVals = new double [ this . inputs . size ( ) ] ; index = <NUM_LIT:0> ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { inputVals [ index ] = theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + inputVals [ index ] ) ; } index ++ ; } this . value = <NUM_LIT:0.0> ; switch ( this . op ) { case MIN : this . value = Double . POSITIVE_INFINITY ; break ; case MAX : this . value = Double . NEGATIVE_INFINITY ; break ; } for ( int i = <NUM_LIT:0> ; i < inputVals . length ; i ++ ) { switch ( this . op ) { case MIN : this . value = Math . min ( this . value , inputVals [ i ] ) ; break ; case MAX : this . value = Math . max ( this . value , inputVals [ i ] ) ; break ; } } if ( this . value == Double . NaN ) throw new DAVEException ( "<STR_LIT>" + this . funcType + "<STR_LIT>" + this . getName ( ) ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathAbs extends BlockMath { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathAbs ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; this . setName ( first . getName ( ) + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( ! first . getName ( ) . equals ( "<STR_LIT>" ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; } else { if ( kids . size ( ) > <NUM_LIT:2> ) System . err . println ( "<STR_LIT>" + ( kids . size ( ) - <NUM_LIT:1> ) ) ; else this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( this . inputs . size ( ) > <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; Signal theInput = this . inputs . get ( <NUM_LIT:0> ) ; if ( ! theInput . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } double inputValue = theInput . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; this . value = Math . abs ( inputValue ) ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Signal input ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } input = inputs . get ( <NUM_LIT:0> ) ; String op = "<STR_LIT>" ; if ( ourModel . getCodeDialect ( ) == Model . DT_FORTRAN ) op = "<STR_LIT>" ; cvn . appendCode ( op + "<STR_LIT>" ) ; cvn . append ( input . genCode ( ) ) ; cvn . appendCode ( "<STR_LIT>" ) ; if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . util . List ; import java . util . Iterator ; abstract public class BlockMath extends Block { public BlockMath ( ) { super ( ) ; } public BlockMath ( Model m ) { super ( m ) ; } public BlockMath ( String blockName , String blockType , Model m ) { super ( blockName , blockType , <NUM_LIT:1> , m ) ; } public BlockMath ( String blockName , String blockType , int numInputs , Model m ) { super ( blockName , blockType , numInputs , m ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public static BlockMath factory ( Element applyElement , Model m ) { List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; String theType = first . getName ( ) ; if ( theType . equals ( "<STR_LIT>" ) ) return new BlockMathAbs ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) ) return new BlockMathRelation ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) ) return new BlockMathMinus ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) ) return new BlockMathSwitch ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) ) return new BlockMathSum ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) ) return new BlockMathProduct ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) ) return new BlockMathMinmax ( applyElement , m ) ; if ( theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) || theType . equals ( "<STR_LIT>" ) ) try { return new BlockMathFunction ( applyElement , m ) ; } catch ( DAVEException e ) { System . err . println ( "<STR_LIT>" + theType + "<STR_LIT>" ) ; System . exit ( - <NUM_LIT:1> ) ; } if ( theType . equals ( "<STR_LIT>" ) ) return new BlockMathFunctionExtension ( applyElement , m ) ; System . err . println ( "<STR_LIT>" + theType + "<STR_LIT>" ) ; return null ; } public void genInputsFromApply ( Iterator < Element > ikid , int inputPortNumber ) { int i = inputPortNumber ; while ( ikid . hasNext ( ) ) { Element in = ikid . next ( ) ; String name = in . getName ( ) ; if ( name . equals ( "<STR_LIT>" ) ) { String varID = in . getTextTrim ( ) ; this . addVarID ( i , varID ) ; } else if ( name . equals ( "<STR_LIT>" ) ) { String constantValue = in . getTextTrim ( ) ; this . addConstInput ( constantValue , i ) ; } else if ( name . equals ( "<STR_LIT>" ) ) { this . addVarID ( i , "<STR_LIT>" ) ; Signal s = new Signal ( in , ourModel ) ; if ( s != null ) { s . addSink ( this , i ) ; s . setDerivedFlag ( ) ; } else System . err . println ( "<STR_LIT>" ) ; } else { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + in . getName ( ) ) ; } i ++ ; } } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathRelation extends BlockMath { private static final int UNK = <NUM_LIT:0> ; private static final int LT = <NUM_LIT:1> ; private static final int LEQ = <NUM_LIT:2> ; private static final int EQ = <NUM_LIT:3> ; private static final int GEQ = <NUM_LIT:4> ; private static final int GT = <NUM_LIT:5> ; private static final int NEQ = <NUM_LIT:6> ; String relationOp ; int relation ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathRelation ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; this . relation = UNK ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; this . relationOp = first . getName ( ) ; this . setName ( this . relationOp + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( ! validateRelation ( ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + this . relationOp ) ; } else { if ( kids . size ( ) != <NUM_LIT:3> ) System . err . println ( "<STR_LIT>" + ( kids . size ( ) - <NUM_LIT:1> ) ) ; else this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } } protected final boolean validateRelation ( ) { this . relation = UNK ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = LT ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = LEQ ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = EQ ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = GEQ ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = GT ; if ( this . relationOp . equals ( "<STR_LIT>" ) ) this . relation = NEQ ; return ( this . relation != UNK ) ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } if ( inputs == null ) { cvn . appendCode ( errorComment ( "<STR_LIT>" ) ) ; return cvn ; } if ( inputs . size ( ) < <NUM_LIT:2> ) { cvn . appendCode ( errorComment ( "<STR_LIT>" + "<STR_LIT>" ) ) ; return cvn ; } Signal arg1 = inputs . get ( <NUM_LIT:0> ) ; if ( arg1 == null ) { cvn . appendCode ( errorComment ( "<STR_LIT>" ) ) ; return cvn ; } Signal arg2 = inputs . get ( <NUM_LIT:1> ) ; if ( arg2 == null ) { cvn . appendCode ( errorComment ( "<STR_LIT>" ) ) ; return cvn ; } cvn . append ( arg1 . genCode ( ) ) ; int dialect = ourModel . getCodeDialect ( ) ; switch ( dialect ) { case Model . DT_ANSI_C : switch ( relation ) { case LT : cvn . appendCode ( "<STR_LIT>" ) ; break ; case LEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case EQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case GEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case GT : cvn . appendCode ( "<STR_LIT>" ) ; break ; case NEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; } break ; case Model . DT_FORTRAN : switch ( relation ) { case LT : cvn . appendCode ( "<STR_LIT>" ) ; break ; case LEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case EQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case GEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; case GT : cvn . appendCode ( "<STR_LIT>" ) ; break ; case NEQ : cvn . appendCode ( "<STR_LIT>" ) ; break ; } break ; } cvn . append ( arg2 . genCode ( ) ) ; if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( this . endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } public void setRelationOp ( String relationString ) throws DAVEException { this . relationOp = relationString . toLowerCase ( ) ; if ( ! this . validateRelation ( ) ) { throw new DAVEException ( "<STR_LIT>" + relationString ) ; } } public String getRelationOp ( ) { return this . relationOp ; } @ Override public void update ( ) throws DAVEException { int numInputs ; Iterator < Signal > theInputs ; Signal theInput ; double [ ] theInputValue ; int index = <NUM_LIT:0> ; int requiredInputs = <NUM_LIT:2> ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } numInputs = this . inputs . size ( ) ; if ( numInputs != requiredInputs ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + requiredInputs + "<STR_LIT:.>" ) ; theInputValue = new double [ requiredInputs ] ; theInputs = this . inputs . iterator ( ) ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { theInputValue [ index ] = theInput . sourceValue ( ) ; } index ++ ; } this . value = Double . NaN ; switch ( this . relation ) { case LT : if ( theInputValue [ <NUM_LIT:0> ] < theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; case LEQ : if ( theInputValue [ <NUM_LIT:0> ] <= theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; case EQ : if ( theInputValue [ <NUM_LIT:0> ] == theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; case GEQ : if ( theInputValue [ <NUM_LIT:0> ] >= theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; case GT : if ( theInputValue [ <NUM_LIT:0> ] > theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; case NEQ : if ( theInputValue [ <NUM_LIT:0> ] != theInputValue [ <NUM_LIT:1> ] ) this . value = <NUM_LIT:1.0> ; else this . value = <NUM_LIT:0.0> ; break ; } if ( this . value == Double . NaN ) throw new DAVEException ( "<STR_LIT>" + this . relationOp + "<STR_LIT>" + this . getName ( ) ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; import java . text . DecimalFormat ; import java . text . NumberFormat ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . jdom . Element ; import org . jdom . Namespace ; public class FuncTable { ArrayList < String > bpIDs ; ArrayList < Double > functionValues ; int [ ] myDimensions ; String description ; String tableName ; String gtID ; Model myModel ; boolean verbose ; BlockArrayList users ; Namespace ns ; public FuncTable ( Model m ) { this . bpIDs = new ArrayList < String > ( <NUM_LIT:5> ) ; this . functionValues = null ; this . myDimensions = null ; this . description = "<STR_LIT>" ; this . tableName = "<STR_LIT>" ; this . gtID = "<STR_LIT>" ; this . ns = null ; this . myModel = m ; this . verbose = false ; this . users = new BlockArrayList ( <NUM_LIT:5> ) ; } public FuncTable ( String gtid , Element gtd , Model m ) throws IOException { this ( m ) ; if ( gtd . getAttributeValue ( "<STR_LIT:name>" ) != null ) this . tableName = gtd . getAttributeValue ( "<STR_LIT:name>" ) ; this . gtID = gtid ; Element parent = gtd . getParentElement ( ) ; if ( parent != null ) this . ns = gtd . getParentElement ( ) . getNamespace ( ) ; Element descrip = gtd . getChild ( "<STR_LIT:description>" , this . ns ) ; if ( descrip != null ) this . description = descrip . getTextTrim ( ) ; Element table = gtd . getChild ( "<STR_LIT>" , this . ns ) ; this . functionValues = ParseText . toList ( table . getTextTrim ( ) ) ; this . parseBPIDsFromTableDef ( gtd ) ; m . register ( this ) ; } public FuncTable ( Element gtd , Model m ) throws IOException { this ( gtd . getAttributeValue ( "<STR_LIT>" ) , gtd , m ) ; } public FuncTable ( String tableID , String tableName , String tableValues , String description , int ndim , Model m ) { this ( m ) ; this . gtID = tableID ; this . tableName = tableName ; this . description = description ; this . myDimensions = new int [ ndim ] ; this . verbose = false ; try { this . functionValues = ParseText . toList ( tableValues ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" + this . tableName + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } m . register ( this ) ; } public void register ( BlockFuncTable userBFT ) { this . users . add ( userBFT ) ; } public boolean isVerbose ( ) { return this . verbose ; } public void makeVerbose ( ) { this . verbose = true ; } public void silence ( ) { this . verbose = false ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) protected void parseBPIDsFromTableDef ( Element gtd ) { Element breakpointRefs = gtd . getChild ( "<STR_LIT>" , this . ns ) ; if ( breakpointRefs == null ) breakpointRefs = gtd . getChild ( "<STR_LIT>" ) ; if ( breakpointRefs != null ) { List < Element > bpRefs = breakpointRefs . getChildren ( "<STR_LIT>" , this . ns ) ; if ( bpRefs == null ) bpRefs = breakpointRefs . getChildren ( "<STR_LIT>" ) ; Iterator < Element > bpRefIterator = bpRefs . iterator ( ) ; while ( bpRefIterator . hasNext ( ) ) { Element bpRefElement = bpRefIterator . next ( ) ; String bpName = bpRefElement . getAttributeValue ( "<STR_LIT>" ) ; this . bpIDs . add ( bpName ) ; } } this . setDimensions ( ) ; } public void addBPID ( int portNum , String bpID ) { while ( bpIDs . size ( ) < portNum ) bpIDs . add ( "<STR_LIT>" ) ; bpIDs . set ( portNum - <NUM_LIT:1> , bpID ) ; } public Iterator < String > getBPIterator ( ) { return bpIDs . iterator ( ) ; } public String getBPID ( int portNum ) { int portIndex = portNum - <NUM_LIT:1> ; return bpIDs . get ( portIndex ) ; } public String getName ( ) { return this . tableName ; } public String getGTID ( ) { return this . gtID ; } protected void setDimensions ( ) { this . myDimensions = new int [ bpIDs . size ( ) ] ; int i = <NUM_LIT:0> ; Iterator < String > bpit = this . bpIDs . iterator ( ) ; while ( bpit . hasNext ( ) ) { String bpID = bpit . next ( ) ; BreakpointSet bps = this . myModel . getBPSetByID ( bpID ) ; if ( bps == null ) { System . err . println ( "<STR_LIT>" + bpID ) ; System . exit ( <NUM_LIT:0> ) ; } this . myDimensions [ i ] = bps . length ( ) ; i ++ ; } } public int size ( ) { if ( this . functionValues == null ) return <NUM_LIT:0> ; return this . functionValues . size ( ) ; } public int numDim ( ) { if ( myDimensions == null ) return <NUM_LIT:0> ; return this . myDimensions . length ; } public int dim ( int theAxis ) { return this . myDimensions [ theAxis ] ; } public int [ ] getDimensions ( ) { return this . myDimensions ; } public ArrayList < Double > getValues ( ) { return this . functionValues ; } protected int printTable ( Writer writer , ArrayList < Double > table , int [ ] dims , int startIndex ) throws IOException { int offset ; int i ; String newline = System . getProperty ( "<STR_LIT>" ) ; DecimalFormat form = new DecimalFormat ( myModel . dataFormat ) ; switch ( dims . length ) { case <NUM_LIT:0> : return <NUM_LIT:0> ; case <NUM_LIT:1> : for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { Double theValue = table . get ( i + startIndex ) ; String valueStr = form . format ( theValue ) ; writer . write ( valueStr ) ; if ( i < dims [ <NUM_LIT:0> ] - <NUM_LIT:1> ) writer . write ( "<STR_LIT:U+002CU+0020>" ) ; } return i ; case <NUM_LIT:2> : for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { int [ ] newDims = new int [ <NUM_LIT:1> ] ; newDims [ <NUM_LIT:0> ] = dims [ <NUM_LIT:1> ] ; offset = printTable ( writer , table , newDims , startIndex ) ; if ( i < dims [ <NUM_LIT:0> ] - <NUM_LIT:1> ) writer . write ( "<STR_LIT:U+002CU+0020>" ) ; writer . write ( newline ) ; startIndex = startIndex + offset ; } return startIndex ; default : for ( i = <NUM_LIT:0> ; i < dims [ <NUM_LIT:0> ] ; i ++ ) { int [ ] newDims = new int [ <NUM_LIT:1> ] ; newDims [ <NUM_LIT:0> ] = dims [ <NUM_LIT:1> ] ; offset = printTable ( writer , table , newDims , startIndex ) ; if ( i < dims [ <NUM_LIT:0> ] - <NUM_LIT:1> ) writer . write ( "<STR_LIT:U+002CU+0020>" ) ; writer . write ( newline ) ; startIndex = startIndex + offset ; } return startIndex ; } } public void printTable ( Writer writer ) throws IOException { printTable ( writer , this . functionValues , this . myDimensions , <NUM_LIT:0> ) ; } public double getPt ( int [ ] indices ) { int mult = <NUM_LIT:1> ; int offset = <NUM_LIT:0> ; int i ; if ( verbose ) { System . out . print ( "<STR_LIT>" + this . tableName + "<STR_LIT:[>" ) ; for ( i = <NUM_LIT:0> ; i < indices . length ; i ++ ) { System . out . print ( "<STR_LIT:U+0020>" + indices [ i ] ) ; if ( i < indices . length - <NUM_LIT:1> ) System . out . print ( "<STR_LIT:U+002C>" ) ; } System . out . println ( "<STR_LIT>" ) ; } for ( i = indices . length - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { if ( verbose ) System . out . println ( "<STR_LIT>" + i ) ; offset += indices [ i ] * mult ; mult *= this . myDimensions [ i ] ; if ( verbose ) System . out . println ( "<STR_LIT>" + offset + "<STR_LIT>" + mult ) ; } Double value = functionValues . get ( offset ) ; double val = value . doubleValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + val ) ; return val ; } public String getDescription ( ) { return this . description ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import org . jdom . Namespace ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathSwitch extends BlockMath { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathSwitch ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; Namespace mathml = Namespace . getNamespace ( "<STR_LIT>" , "<STR_LIT>" ) ; Element piecewise = applyElement . getChild ( "<STR_LIT>" , mathml ) ; if ( piecewise == null ) { piecewise = applyElement . getChild ( "<STR_LIT>" ) ; } if ( piecewise == null ) { List < Element > elist = applyElement . getChildren ( ) ; Iterator < Element > elisti = elist . iterator ( ) ; Element el = elisti . next ( ) ; System . err . println ( "<STR_LIT>" + "<STR_LIT>" + el . getQualifiedName ( ) + "<STR_LIT>" ) ; } else { this . setName ( "<STR_LIT>" + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; List < Element > kids = piecewise . getChildren ( ) ; if ( kids . size ( ) < <NUM_LIT:2> ) { System . err . println ( "<STR_LIT>" + kids . size ( ) + "<STR_LIT>" ) ; } else { List < Element > pieces = piecewise . getChildren ( "<STR_LIT>" , mathml ) ; Element otherwise = piecewise . getChild ( "<STR_LIT>" , mathml ) ; if ( pieces . isEmpty ( ) ) { pieces = piecewise . getChildren ( "<STR_LIT>" ) ; } if ( pieces . isEmpty ( ) ) { System . err . println ( "<STR_LIT>" ) ; return ; } if ( otherwise == null ) { otherwise = piecewise . getChild ( "<STR_LIT>" ) ; } if ( otherwise == null ) { System . err . println ( "<STR_LIT>" ) ; return ; } Element piece = pieces . get ( <NUM_LIT:0> ) ; List < Element > pieceChildren = piece . getChildren ( ) ; if ( pieceChildren . size ( ) != <NUM_LIT:2> ) { System . err . println ( "<STR_LIT>" + pieces . size ( ) + "<STR_LIT>" ) ; return ; } List < Element > other = otherwise . getChildren ( ) ; if ( other . size ( ) != <NUM_LIT:1> ) { System . err . println ( "<STR_LIT>" + other . size ( ) + "<STR_LIT>" ) ; return ; } this . genInputsFromApply ( pieceChildren . iterator ( ) , <NUM_LIT:1> ) ; if ( pieces . size ( ) <= <NUM_LIT:1> ) { this . genInputsFromApply ( other . iterator ( ) , <NUM_LIT:3> ) ; } else { boolean childRemoved = this . removeFirstPiece ( piecewise ) ; if ( ! childRemoved ) { throw new AssertionError ( "<STR_LIT>" + "<STR_LIT>" + this . getName ( ) ) ; } BlockMathSwitch bms = new BlockMathSwitch ( applyElement , m ) ; this . addInput ( bms , <NUM_LIT:3> ) ; } } } } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Iterator < Signal > inputSig = inputs . iterator ( ) ; Signal outputSig = this . getOutput ( ) ; if ( inputs == null ) { cvn . appendCode ( this . errorComment ( "<STR_LIT>" ) ) ; return cvn ; } if ( inputs . size ( ) < <NUM_LIT:3> ) { cvn . appendCode ( this . errorComment ( "<STR_LIT>" + "<STR_LIT>" ) ) ; return cvn ; } Signal defaultInput = inputs . get ( <NUM_LIT:2> ) ; boolean defaultInputIsConst = defaultInput . source . getType ( ) . equals ( "<STR_LIT>" ) ; if ( defaultInput . isDerived ( ) && defaultInputIsConst ) { defaultInput . clearDerivedFlag ( ) ; } cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; if ( defaultInput . isDefined ( ) ) { cvn . appendCode ( defaultInput . getVarID ( ) ) ; } else { cvn . append ( defaultInput . genCode ( ) ) ; } cvn . appendCode ( endLine ( ) ) ; CodeAndVarNames ifCvn = inputs . get ( <NUM_LIT:1> ) . genCode ( ) ; cvn . addVarName ( ifCvn . getVarName ( <NUM_LIT:0> ) ) ; cvn . appendCode ( this . beginIf ( ifCvn . getCode ( ) ) ) ; cvn . appendCode ( indent ( ) + "<STR_LIT:U+0020U+0020>" + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . append ( inputs . get ( <NUM_LIT:0> ) . genCode ( ) ) ; cvn . appendCode ( this . endLine ( ) ) ; cvn . appendCode ( this . endIf ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { int numInputs ; Iterator < Signal > theInputs ; Signal theInput ; double [ ] theInputValue ; int index = <NUM_LIT:0> ; int requiredInputs = <NUM_LIT:3> ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } numInputs = this . inputs . size ( ) ; if ( numInputs != requiredInputs ) { throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + requiredInputs + "<STR_LIT:.>" ) ; } theInputValue = new double [ requiredInputs ] ; theInputs = this . inputs . iterator ( ) ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) { System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; } return ; } else { theInputValue [ index ] = theInput . sourceValue ( ) ; } index ++ ; } this . value = theInputValue [ <NUM_LIT:2> ] ; if ( Math . abs ( theInputValue [ <NUM_LIT:1> ] ) > <NUM_LIT> ) { this . value = theInputValue [ <NUM_LIT:0> ] ; } resultsCycleCount = ourModel . getCycleCounter ( ) ; } private boolean removeFirstPiece ( Element piecewise ) { List kids = piecewise . getChildren ( ) ; Iterator it = kids . iterator ( ) ; boolean foundPiece = false ; boolean removedPiece = false ; while ( ( ! foundPiece ) && ( it . hasNext ( ) ) ) { Element el = ( Element ) it . next ( ) ; foundPiece = ( el . getName ( ) == null ? "<STR_LIT>" == null : el . getName ( ) . equals ( "<STR_LIT>" ) ) ; } if ( foundPiece ) { it . remove ( ) ; } return foundPiece ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; public class BlockOutput extends Block { String units ; public BlockOutput ( Signal sourceSignal , Model m ) { super ( sourceSignal . getName ( ) , "<STR_LIT>" , <NUM_LIT:1> , m ) ; this . units = sourceSignal . getUnits ( ) ; sourceSignal . addSink ( this , <NUM_LIT:1> ) ; } @ Override public double getValue ( ) { return this . value ; } public String getUnits ( ) { return this . units ; } public int getSeqNumber ( ) { BlockArrayList outputs = this . ourModel . getOutputBlocks ( ) ; return outputs . indexOf ( this ) + <NUM_LIT:1> ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; cvn . appendCode ( this . wrapComment ( this . genComment ( ) ) ) ; cvn . addVarName ( this . getInput ( <NUM_LIT:0> ) . getVarID ( ) ) ; return cvn ; } private String genComment ( ) { String code = "<STR_LIT>" ; Signal theSignal = this . getInput ( <NUM_LIT:0> ) ; String inVarID = theSignal . getVarID ( ) ; if ( theSignal != null ) { code = code + inVarID ; if ( theSignal . isStdAIAA ( ) ) code = code + "<STR_LIT:U+0020(>" + theSignal . getName ( ) + "<STR_LIT:)>" ; code = code + "<STR_LIT>" ; if ( units . equalsIgnoreCase ( "<STR_LIT>" ) ) code = code + "<STR_LIT>" ; else code = code + "<STR_LIT>" + units + "<STR_LIT:'>" ; } return code ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT:U+0020(>" + units + "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( this . inputs . size ( ) > <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; Signal theInput = this . inputs . get ( <NUM_LIT:0> ) ; if ( ! theInput . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } double inputValue = theInput . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue ) ; this . resultsCycleCount = ourModel . getCycleCounter ( ) ; this . value = inputValue ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathFunction extends BlockMath { private static final int UNK = <NUM_LIT:0> ; private static final int SIN = <NUM_LIT:1> ; private static final int COS = <NUM_LIT:2> ; private static final int TAN = <NUM_LIT:3> ; private static final int ARCSIN = <NUM_LIT:4> ; private static final int ARCCOS = <NUM_LIT:5> ; private static final int ARCTAN = <NUM_LIT:6> ; private static final int FLOOR = <NUM_LIT:7> ; private static final int CEIL = <NUM_LIT:8> ; private static final int POW = <NUM_LIT:10> ; String funcType ; int op ; public BlockMathFunction ( ) { super ( ) ; this . funcType = null ; this . op = UNK ; } public BlockMathFunction ( Model m ) { super ( m ) ; this . funcType = null ; this . op = UNK ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathFunction ( Element applyElement , Model m ) throws DAVEException { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; this . op = UNK ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; this . setFunction ( first . getName ( ) ) ; this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } protected void setFunction ( String functionType ) throws DAVEException { this . funcType = functionType ; this . setName ( funcType + "<STR_LIT:_>" + this . ourModel . getNumBlocks ( ) ) ; if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = POW ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = SIN ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = COS ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = TAN ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = ARCSIN ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = ARCCOS ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = ARCTAN ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = FLOOR ; this . myType = "<STR_LIT>" ; } else if ( funcType . equals ( "<STR_LIT>" ) ) { this . op = CEIL ; this . myType = "<STR_LIT>" ; } else throw new DAVEException ( "<STR_LIT>" + this . funcType + "<STR_LIT>" ) ; } public String getFuncType ( ) { return funcType ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } public void update ( ) throws DAVEException { int requiredNumInputs ; Iterator < Signal > theInputs ; Signal theInput ; double [ ] theInputValue ; int index ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . myType + "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myType + "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; requiredNumInputs = <NUM_LIT:1> ; if ( this . op > <NUM_LIT:9> ) requiredNumInputs = <NUM_LIT:2> ; if ( this . inputs . size ( ) > requiredNumInputs ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; index = <NUM_LIT:0> ; theInputValue = new double [ <NUM_LIT:2> ] ; theInputs = this . inputs . iterator ( ) ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { theInputValue [ index ] = theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + theInputValue [ index ] ) ; } index ++ ; } this . value = Double . NaN ; switch ( this . op ) { case POW : this . value = Math . pow ( theInputValue [ <NUM_LIT:0> ] , theInputValue [ <NUM_LIT:1> ] ) ; break ; case SIN : this . value = Math . sin ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case COS : this . value = Math . cos ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case TAN : this . value = Math . tan ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case ARCSIN : this . value = Math . asin ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case ARCCOS : this . value = Math . acos ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case ARCTAN : this . value = Math . atan ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case FLOOR : this . value = Math . floor ( theInputValue [ <NUM_LIT:0> ] ) ; break ; case CEIL : this . value = Math . ceil ( theInputValue [ <NUM_LIT:0> ] ) ; break ; } if ( this . value == Double . NaN ) throw new DAVEException ( "<STR_LIT>" + this . funcType + "<STR_LIT>" + this . getName ( ) ) ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class DAVEException extends Exception { public DAVEException ( ) { super ( ) ; } public DAVEException ( String s ) { super ( s ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . * ; import java . util . ArrayList ; import java . util . Iterator ; public class ParseText { protected StreamTokenizer st ; protected boolean goodNumber ; public ParseText ( String inputData ) { StringReader sr = new StringReader ( inputData ) ; st = new StreamTokenizer ( sr ) ; st . resetSyntax ( ) ; st . whitespaceChars ( <NUM_LIT> , <NUM_LIT> ) ; st . whitespaceChars ( <NUM_LIT> , <NUM_LIT> ) ; st . wordChars ( <NUM_LIT> , <NUM_LIT> ) ; st . wordChars ( <NUM_LIT> , <NUM_LIT> ) ; st . wordChars ( <NUM_LIT> , <NUM_LIT> ) ; st . wordChars ( <NUM_LIT> , <NUM_LIT> ) ; st . wordChars ( <NUM_LIT> , <NUM_LIT> ) ; } public double next ( ) throws IOException { goodNumber = false ; double value = Double . NaN ; do { st . nextToken ( ) ; switch ( st . ttype ) { case StreamTokenizer . TT_NUMBER : value = st . nval ; goodNumber = true ; break ; case StreamTokenizer . TT_WORD : try { value = Double . parseDouble ( st . sval ) ; goodNumber = true ; } catch ( NumberFormatException e ) { goodNumber = false ; } break ; case StreamTokenizer . TT_EOL : break ; case StreamTokenizer . TT_EOF : break ; default : System . out . println ( "<STR_LIT>" + st . ttype ) ; } } while ( ( ! goodNumber ) && ( st . ttype != StreamTokenizer . TT_EOF ) ) ; return value ; } public boolean eof ( ) { return ( st . ttype == StreamTokenizer . TT_EOF ) ; } public boolean validNumber ( ) { return ( goodNumber && ( st . ttype != StreamTokenizer . TT_EOF ) ) ; } public ArrayList < Double > toList ( ) throws IOException { ArrayList < Double > al = new ArrayList < Double > ( <NUM_LIT:10> ) ; while ( ! this . eof ( ) ) { Double dbl = new Double ( this . next ( ) ) ; if ( this . validNumber ( ) ) al . add ( dbl ) ; } return al ; } static public ArrayList < Double > toList ( String values ) throws IOException { ParseText pt = new ParseText ( values ) ; return pt . toList ( ) ; } public static class Test { public static void main ( String [ ] args ) throws IOException { ParseText pt ; if ( args . length < <NUM_LIT:1> ) pt = new ParseText ( "<STR_LIT>" ) ; else pt = new ParseText ( args [ <NUM_LIT:0> ] ) ; ArrayList < Double > theList = pt . toList ( ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; System . out . print ( "<STR_LIT>" ) ; Iterator < Double > listIterator = theList . iterator ( ) ; while ( listIterator . hasNext ( ) ) { System . out . print ( listIterator . next ( ) ) ; if ( listIterator . hasNext ( ) ) System . out . print ( "<STR_LIT:U+002CU+0020>" ) ; } System . out . println ( "<STR_LIT:]>" ) ; } } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import org . jdom . Element ; public class CheckData { ArrayList < StaticShot > staticShots ; public CheckData ( List < Element > shots ) { staticShots = new ArrayList < StaticShot > ( <NUM_LIT:20> ) ; Iterator < Element > ssit = shots . iterator ( ) ; while ( ssit . hasNext ( ) ) staticShots . add ( new StaticShot ( ssit . next ( ) ) ) ; } public ArrayList < StaticShot > getStaticShots ( ) { return this . staticShots ; } public int count ( ) { return this . staticShots . size ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . FileWriter ; import java . util . Iterator ; import java . util . logging . Level ; import java . util . logging . Logger ; public class TreeFileWriter extends FileWriter { public TreeFileWriter ( String fileName ) throws IOException { super ( fileName ) ; } public void writeln ( String cbuf ) throws IOException { super . write ( cbuf + "<STR_LIT:n>" ) ; } public void writeln ( ) throws IOException { super . write ( "<STR_LIT:n>" ) ; } public void describe ( Model m ) throws IOException { this . writeln ( "<STR_LIT>" ) ; this . writeln ( ) ; this . writeln ( "<STR_LIT>" + m . getNumInputBlocks ( ) ) ; this . writeln ( ) ; int i = <NUM_LIT:1> ; Iterator < VectorInfo > inputIterator ; try { inputIterator = m . getInputVector ( ) . iterator ( ) ; while ( inputIterator . hasNext ( ) ) { VectorInfo input ; input = inputIterator . next ( ) ; this . write ( i + "<STR_LIT:U+0020>" ) ; this . write ( input . getName ( ) ) ; this . writeln ( "<STR_LIT:U+0020(>" + input . getUnits ( ) + "<STR_LIT:)>" ) ; i ++ ; } } catch ( DAVEException ex ) { this . writeln ( "<STR_LIT>" ) ; } this . writeln ( ) ; this . writeln ( "<STR_LIT>" + m . getNumOutputBlocks ( ) ) ; this . writeln ( ) ; i = <NUM_LIT:1> ; Iterator < VectorInfo > outputIterator ; try { outputIterator = m . getOutputVector ( ) . iterator ( ) ; while ( outputIterator . hasNext ( ) ) { VectorInfo output ; output = outputIterator . next ( ) ; this . write ( i + "<STR_LIT:U+0020>" ) ; this . write ( output . getName ( ) ) ; this . writeln ( "<STR_LIT:U+0020(>" + output . getUnits ( ) + "<STR_LIT:)>" ) ; i ++ ; } } catch ( DAVEException ex ) { this . writeln ( "<STR_LIT>" ) ; } this . writeln ( ) ; i = <NUM_LIT:1> ; this . writeln ( "<STR_LIT>" + m . getNumSignals ( ) ) ; this . writeln ( ) ; i = <NUM_LIT:1> ; Iterator < Signal > signalIterator = m . getSignals ( ) . iterator ( ) ; while ( signalIterator . hasNext ( ) ) { write ( i + "<STR_LIT:U+0020>" ) ; ( signalIterator . next ( ) ) . describeSelf ( ( FileWriter ) this ) ; this . writeln ( ) ; i ++ ; } this . writeln ( ) ; this . writeln ( "<STR_LIT>" + m . getNumBlocks ( ) ) ; this . writeln ( ) ; i = <NUM_LIT:1> ; Iterator < Block > blockIterator = m . getBlocks ( ) . iterator ( ) ; while ( blockIterator . hasNext ( ) ) { write ( i + "<STR_LIT:U+0020>" ) ; ( blockIterator . next ( ) ) . describeSelf ( ( FileWriter ) this ) ; this . writeln ( ) ; i ++ ; } } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; public class CodeAndVarNames { private String code ; private ArrayList < String > varName ; public CodeAndVarNames ( ) { code = "<STR_LIT>" ; varName = new ArrayList ( <NUM_LIT:5> ) ; } public CodeAndVarNames ( String theCode ) { code = theCode ; varName = new ArrayList ( <NUM_LIT:0> ) ; } public void append ( CodeAndVarNames arg ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; this . code += arg . code ; this . varName . addAll ( arg . varName ) ; } public void appendCode ( String string ) { this . code += string ; } public void prependCode ( String string ) { this . code = string + this . code ; } public void addVarName ( String varName ) { this . varName . add ( varName ) ; } public ArrayList < String > getVarNames ( ) { return varName ; } public String getVarName ( int i ) { return varName . get ( i ) ; } public String getCode ( ) { return code ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . Collection ; import java . util . ArrayList ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class BlockArrayList extends ArrayList < Block > { public BlockArrayList ( ) { super ( ) ; } public BlockArrayList ( int initialCapacity ) { super ( initialCapacity ) ; } public BlockArrayList ( Collection < Block > c ) { super ( c ) ; } } </s>
<s> package gov . nasa . daveml . dave ; public class VectorInfo { String signalName ; String myUnits ; boolean isInput ; Block source ; Block sink ; double value ; double tolerance ; public VectorInfo ( ) { this . signalName = "<STR_LIT>" ; this . myUnits = "<STR_LIT>" ; this . source = null ; this . sink = null ; this . value = Double . NaN ; this . tolerance = Double . NaN ; } public VectorInfo ( String signalName , String units , Block blk , boolean isInput ) { this ( ) ; this . signalName = signalName ; this . myUnits = units ; if ( isInput ) { this . isInput = true ; this . sink = blk ; this . source = null ; } else { this . isInput = false ; this . sink = null ; this . source = blk ; } } public void setUnits ( String theUnits ) { this . myUnits = theUnits ; } public void setValue ( double theValue ) { this . value = theValue ; } public void setValue ( String theValue ) { this . value = Double . parseDouble ( theValue ) ; } public void setTolerance ( double theValue ) { this . tolerance = theValue ; } public void setTolerance ( String theValue ) { this . tolerance = Double . parseDouble ( theValue ) ; } public String getName ( ) { return this . signalName ; } public String getUnits ( ) { return this . myUnits ; } public double getValue ( ) { return this . value ; } public double getTolerance ( ) { return this . tolerance ; } public boolean isInput ( ) { return this . isInput ; } public BlockOutput getSource ( ) { return ( BlockOutput ) this . source ; } public BlockInput getSink ( ) { return ( BlockInput ) this . sink ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . ArrayList ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class NameList extends ArrayList < String > { public NameList ( ) { super ( ) ; } public NameList ( int initialCapacity ) { super ( initialCapacity ) ; } public String fixName ( String s ) { return s ; } public boolean isUnique ( String s ) { return ( this . indexOf ( s ) == - <NUM_LIT:1> ) ; } public String addUnique ( String s ) { String name = this . fixName ( s ) ; if ( this . isUnique ( s ) ) super . add ( s ) ; else { int suffix = <NUM_LIT:1> ; while ( ! this . isUnique ( s + suffix ) ) suffix ++ ; name = s + suffix ; super . add ( name ) ; } return name ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathSum extends BlockMath { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathSum ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; List < Element > kids = applyElement . getChildren ( ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; String blockType = first . getName ( ) ; this . setName ( blockType + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( ! blockType . equals ( "<STR_LIT>" ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" + blockType ) ; } else { this . genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Iterator < Signal > inputSig = inputs . iterator ( ) ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } while ( inputSig . hasNext ( ) ) { Signal inSig = inputSig . next ( ) ; cvn . append ( inSig . genCode ( ) ) ; if ( inputSig . hasNext ( ) ) { cvn . appendCode ( "<STR_LIT>" ) ; } } if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { Iterator < Signal > theInputs ; double [ ] inputVals ; Signal theInput ; int index ; boolean verbose = this . isVerbose ( ) ; if ( verbose ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } theInputs = this . inputs . iterator ( ) ; inputVals = new double [ this . inputs . size ( ) ] ; index = <NUM_LIT:0> ; while ( theInputs . hasNext ( ) ) { theInput = theInputs . next ( ) ; if ( ! theInput . sourceReady ( ) ) { if ( verbose ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } else { inputVals [ index ] = theInput . sourceValue ( ) ; if ( verbose ) System . out . println ( "<STR_LIT>" + index + "<STR_LIT>" + inputVals [ index ] ) ; } index ++ ; } this . value = <NUM_LIT:0.0> ; for ( int i = <NUM_LIT:0> ; i < inputVals . length ; i ++ ) this . value += inputVals [ i ] ; resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . PrintStream ; import java . util . Iterator ; import java . util . List ; import org . jdom . Element ; import org . jdom . Namespace ; public class StaticShot { String scenario ; VectorInfoArrayList inputs ; VectorInfoArrayList outputs ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public StaticShot ( Element staticShot ) { this . scenario = staticShot . getAttributeValue ( "<STR_LIT:name>" ) ; Namespace ss_ns = staticShot . getNamespace ( ) ; Element checkInputs = staticShot . getChild ( "<STR_LIT>" , ss_ns ) ; if ( checkInputs == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } List < Element > theInputs = checkInputs . getChildren ( "<STR_LIT>" , ss_ns ) ; this . inputs = new VectorInfoArrayList ( theInputs . size ( ) ) ; Iterator < Element > itin = theInputs . iterator ( ) ; while ( itin . hasNext ( ) ) { Element theSignal = itin . next ( ) ; Element theUnitsElement = theSignal . getChild ( "<STR_LIT>" , ss_ns ) ; String theUnits = "<STR_LIT>" ; if ( theUnitsElement != null ) theUnits = theUnitsElement . getTextTrim ( ) ; Element theSignalName = theSignal . getChild ( "<STR_LIT>" , ss_ns ) ; if ( theSignalName == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } VectorInfo signal = new VectorInfo ( theSignalName . getTextTrim ( ) , theUnits , null , true ) ; Element theSignalValue = theSignal . getChild ( "<STR_LIT>" , ss_ns ) ; if ( theSignalValue == null ) { System . err . println ( "<STR_LIT>" + theSignalName . getTextTrim ( ) + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } signal . setValue ( theSignal . getChild ( "<STR_LIT>" , ss_ns ) . getTextTrim ( ) ) ; this . inputs . add ( signal ) ; } Element checkOutputs = staticShot . getChild ( "<STR_LIT>" , ss_ns ) ; if ( checkInputs == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } List theOutputs = checkOutputs . getChildren ( "<STR_LIT>" , ss_ns ) ; this . outputs = new VectorInfoArrayList ( theOutputs . size ( ) ) ; int outCount = <NUM_LIT:0> ; Iterator itout = theOutputs . iterator ( ) ; while ( itout . hasNext ( ) ) { outCount ++ ; Element theSignal = ( Element ) itout . next ( ) ; try { VectorInfo signal = new VectorInfo ( theSignal . getChild ( "<STR_LIT>" , ss_ns ) . getTextTrim ( ) , null , null , false ) ; signal . setValue ( theSignal . getChild ( "<STR_LIT>" , ss_ns ) . getTextTrim ( ) ) ; signal . setTolerance ( theSignal . getChild ( "<STR_LIT>" , ss_ns ) . getTextTrim ( ) ) ; Element units = theSignal . getChild ( "<STR_LIT>" , ss_ns ) ; if ( units == null ) signal . setUnits ( "<STR_LIT>" ) ; else signal . setUnits ( units . getTextTrim ( ) ) ; this . outputs . add ( signal ) ; } catch ( NullPointerException e ) { System . err . println ( "<STR_LIT>" + outCount + "<STR_LIT>" + this . scenario + "<STR_LIT>" ) ; } } } public String getName ( ) { return this . scenario ; } public VectorInfoArrayList getInputs ( ) { return this . inputs ; } public VectorInfoArrayList getOutputs ( ) { return this . outputs ; } public void loadInputVector ( VectorInfoArrayList inVec ) throws DAVEException { VectorInfo modelSig = null ; VectorInfo checkSig = null ; if ( inVec . size ( ) != this . inputs . size ( ) ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + this . inputs . size ( ) + "<STR_LIT>" + inVec . size ( ) + "<STR_LIT>" ) ; Iterator < VectorInfo > checkIt = this . inputs . iterator ( ) ; while ( checkIt . hasNext ( ) ) { checkSig = checkIt . next ( ) ; String sigName = checkSig . getName ( ) ; boolean matched = false ; Iterator < VectorInfo > modelIt = inVec . iterator ( ) ; while ( ! matched ) { if ( ! modelIt . hasNext ( ) ) throw new DAVEException ( "<STR_LIT>" + sigName + "<STR_LIT>" ) ; modelSig = modelIt . next ( ) ; if ( checkSig . getName ( ) . equals ( modelSig . getName ( ) ) ) matched = true ; } if ( ! checkSig . getUnits ( ) . equals ( modelSig . getUnits ( ) ) ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + sigName + "<STR_LIT>" + checkSig . getUnits ( ) + "<STR_LIT>" + modelSig . getUnits ( ) + "<STR_LIT>" ) ; if ( ! modelSig . isInput ( ) ) throw new DAVEException ( "<STR_LIT>" + modelSig . getName ( ) + "<STR_LIT>" ) ; modelSig . setValue ( checkSig . getValue ( ) ) ; } } public boolean checkOutputs ( VectorInfoArrayList outVec ) throws DAVEException { return checkOutputs ( outVec , System . out ) ; } public boolean checkOutputs ( VectorInfoArrayList outVec , PrintStream out ) throws DAVEException { boolean comparison = true ; VectorInfo modelSig = null ; VectorInfo checkSig = null ; if ( outVec . size ( ) < this . outputs . size ( ) ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + this . outputs . size ( ) + "<STR_LIT>" + outVec . size ( ) + "<STR_LIT>" ) ; Iterator < VectorInfo > checkIt = this . outputs . iterator ( ) ; while ( checkIt . hasNext ( ) ) { checkSig = checkIt . next ( ) ; String sigName = checkSig . getName ( ) ; boolean matched = false ; Iterator < VectorInfo > modelIt = outVec . iterator ( ) ; while ( ! matched ) { if ( ! modelIt . hasNext ( ) ) throw new DAVEException ( "<STR_LIT>" + sigName + "<STR_LIT>" ) ; modelSig = modelIt . next ( ) ; if ( checkSig . getName ( ) . equals ( modelSig . getName ( ) ) ) matched = true ; } if ( ! checkSig . getUnits ( ) . equals ( modelSig . getUnits ( ) ) ) throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + sigName + "<STR_LIT>" + checkSig . getUnits ( ) + "<STR_LIT>" + modelSig . getUnits ( ) + "<STR_LIT>" ) ; if ( modelSig . isInput ( ) ) throw new DAVEException ( "<STR_LIT>" + modelSig . getName ( ) + "<STR_LIT>" ) ; double actual = modelSig . getValue ( ) ; double expected = checkSig . getValue ( ) ; if ( Double . isNaN ( actual ) ) if ( ! Double . isNaN ( expected ) ) { comparison = false ; out . println ( ) ; out . println ( "<STR_LIT>" + sigName + "<STR_LIT>" ) ; } if ( Double . isNaN ( expected ) ) if ( ! Double . isNaN ( actual ) ) { comparison = false ; out . println ( ) ; out . println ( "<STR_LIT>" + sigName + "<STR_LIT>" + actual + "<STR_LIT:.>" ) ; } if ( Double . isNaN ( expected ) && Double . isNaN ( actual ) ) { } else { double diff = Math . abs ( actual - expected ) ; double tol = Math . abs ( checkSig . getTolerance ( ) ) ; if ( diff > tol ) { comparison = false ; out . println ( ) ; out . println ( "<STR_LIT>" + sigName + "<STR_LIT>" + expected ) ; out . println ( "<STR_LIT>" + actual + "<STR_LIT>" + diff ) ; out . println ( "<STR_LIT>" + tol + "<STR_LIT:.>" ) ; } } } return comparison ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . io . IOException ; import java . io . Writer ; import java . util . Iterator ; public class BlockBP extends Block { BreakpointSet bpSet ; public BlockBP ( String bpID , String ourName , Signal inSignal , Signal outSignal , Model m ) throws DAVEException { super ( ourName , "<STR_LIT>" , <NUM_LIT:1> , m ) ; this . bpSet = m . getBPSetByID ( bpID ) ; if ( this . bpSet == null ) { throw new DAVEException ( "<STR_LIT>" + bpID + "<STR_LIT>" ) ; } this . bpSet . register ( this ) ; m . register ( this ) ; inSignal . addSink ( this , <NUM_LIT:1> ) ; try { this . addOutput ( outSignal ) ; } catch ( Exception e ) { throw new DAVEException ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT>" + e . getMessage ( ) ) ; } } public String getBPID ( ) { return this . bpSet . getBPID ( ) ; } public void update ( ) throws DAVEException { Signal theInput ; double inputValue ; double bpValue ; double prevValue ; double frac = <NUM_LIT:0> ; int index = <NUM_LIT:0> ; if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } this . value = Double . NaN ; if ( this . inputs . size ( ) < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( this . inputs . size ( ) > <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; theInput = this . inputs . get ( <NUM_LIT:0> ) ; if ( theInput == null ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( ! theInput . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } inputValue = theInput . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue ) ; Iterator < Double > bpIt = this . bpSet . values ( ) . iterator ( ) ; if ( ! bpIt . hasNext ( ) ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; bpValue = ( bpIt . next ( ) ) . doubleValue ( ) ; prevValue = bpValue ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + prevValue ) ; if ( bpValue > inputValue ) { this . value = <NUM_LIT:0> ; frac = <NUM_LIT:0> ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue + "<STR_LIT>" + bpValue ) ; } else while ( bpIt . hasNext ( ) ) { bpValue = ( bpIt . next ( ) ) . doubleValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + bpValue + "<STR_LIT>" + prevValue ) ; if ( bpValue > inputValue ) { this . value = ( double ) index ; frac = ( inputValue - prevValue ) / ( bpValue - prevValue ) ; if ( this . isVerbose ( ) ) { System . out . println ( "<STR_LIT>" + bpValue + "<STR_LIT>" + index ) ; System . out . println ( "<STR_LIT>" + prevValue ) ; System . out . println ( "<STR_LIT>" + frac ) ; } break ; } else { index ++ ; prevValue = bpValue ; } } if ( bpValue <= inputValue ) { this . value = this . bpSet . length ( ) - <NUM_LIT:1> ; frac = <NUM_LIT:0> ; } resultsCycleCount = ourModel . getCycleCounter ( ) ; this . value = this . value + frac ; if ( isVerbose ( ) ) System . out . println ( "<STR_LIT>" + this . value ) ; } public int length ( ) { return this . bpSet . length ( ) ; } public BreakpointSet getBPset ( ) { return this . bpSet ; } public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" + this . length ( ) + "<STR_LIT>" ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import org . jdom . Element ; import java . io . IOException ; import java . io . Writer ; import java . util . List ; import java . util . Iterator ; public class BlockMathMinus extends BlockMath { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public BlockMathMinus ( Element applyElement , Model m ) { super ( "<STR_LIT>" , "<STR_LIT>" , m ) ; List < Element > kids = applyElement . getChildren ( ) ; if ( kids . size ( ) < <NUM_LIT:2> ) System . err . println ( "<STR_LIT>" ) ; if ( kids . size ( ) > <NUM_LIT:3> ) System . err . println ( "<STR_LIT>" ) ; Iterator < Element > ikid = kids . iterator ( ) ; Element first = ikid . next ( ) ; this . setName ( first . getName ( ) + "<STR_LIT:_>" + m . getNumBlocks ( ) ) ; if ( ! first . getName ( ) . equals ( "<STR_LIT>" ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; } else genInputsFromApply ( ikid , <NUM_LIT:1> ) ; } @ Override public CodeAndVarNames genCode ( ) { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; Signal input0 , input1 ; Signal outputSig = this . getOutput ( ) ; if ( ! outputSig . isDerived ( ) ) { cvn . appendCode ( indent ( ) + outVarID + "<STR_LIT:U+0020=U+0020>" ) ; cvn . addVarName ( outVarID ) ; } input0 = inputs . get ( <NUM_LIT:0> ) ; if ( inputs . size ( ) == <NUM_LIT:1> ) { cvn . appendCode ( "<STR_LIT:->" ) ; cvn . append ( input0 . genCode ( ) ) ; } else { input1 = inputs . get ( <NUM_LIT:1> ) ; cvn . append ( input0 . genCode ( ) ) ; cvn . appendCode ( "<STR_LIT:U+0020-U+0020>" ) ; cvn . append ( input1 . genCode ( ) ) ; } if ( ! outputSig . isDerived ( ) ) cvn . appendCode ( endLine ( ) ) ; return cvn ; } @ Override public void describeSelf ( Writer writer ) throws IOException { super . describeSelf ( writer ) ; writer . write ( "<STR_LIT>" ) ; } @ Override public void update ( ) throws DAVEException { if ( isVerbose ( ) ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + this . getName ( ) + "<STR_LIT:'>" ) ; } int numInputs = this . inputs . size ( ) ; if ( numInputs < <NUM_LIT:1> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( numInputs > <NUM_LIT:2> ) throw new DAVEException ( "<STR_LIT>" + this . myName + "<STR_LIT>" ) ; if ( numInputs == <NUM_LIT:1> ) { Signal theInput = this . inputs . get ( <NUM_LIT:0> ) ; if ( ! theInput . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + theInput . getName ( ) + "<STR_LIT>" ) ; return ; } double inputValue = theInput . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + inputValue ) ; this . value = - inputValue ; } else { Signal minuend = this . inputs . get ( <NUM_LIT:0> ) ; assert ( minuend != null ) ; if ( ! minuend . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + minuend . getName ( ) + "<STR_LIT>" ) ; return ; } Signal subtrahend = this . inputs . get ( <NUM_LIT:1> ) ; assert ( subtrahend != null ) ; if ( ! subtrahend . sourceReady ( ) ) { if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + subtrahend . getName ( ) + "<STR_LIT>" ) ; return ; } double minuendValue = minuend . sourceValue ( ) ; double subtrahendValue = subtrahend . sourceValue ( ) ; if ( this . isVerbose ( ) ) System . out . println ( "<STR_LIT>" + minuendValue + "<STR_LIT:;>" + "<STR_LIT>" + subtrahendValue ) ; this . value = minuendValue - subtrahendValue ; } resultsCycleCount = ourModel . getCycleCounter ( ) ; } } </s>
<s> package gov . nasa . daveml . dave ; import java . util . Collection ; import java . util . Iterator ; import java . util . ArrayList ; @ SuppressWarnings ( "<STR_LIT:serial>" ) public class SignalArrayList extends ArrayList < Signal > { public SignalArrayList ( ) { super ( ) ; } public SignalArrayList ( int initialCapacity ) { super ( initialCapacity ) ; } public SignalArrayList ( Collection < Signal > c ) { super ( c ) ; } public Signal findByID ( String ID ) { Iterator < Signal > signalIterator = this . iterator ( ) ; while ( signalIterator . hasNext ( ) ) { Signal theSignal = signalIterator . next ( ) ; if ( ID . equals ( theSignal . getVarID ( ) ) ) return theSignal ; } return null ; } @ Deprecated public SignalArrayList findDanglingFuncInputs ( ) { SignalArrayList funcInputs = new SignalArrayList ( this . size ( ) ) ; BlockArrayList bal ; Iterator < Block > i ; Iterator < Signal > signalIterator = this . iterator ( ) ; while ( signalIterator . hasNext ( ) ) { Signal s = signalIterator . next ( ) ; bal = s . getDests ( ) ; i = bal . iterator ( ) ; while ( i . hasNext ( ) ) { Block b = i . next ( ) ; if ( b instanceof BlockFuncTable ) { Block a = s . getSource ( ) ; if ( ! ( a instanceof BlockBP ) ) funcInputs . add ( s ) ; break ; } } } return funcInputs ; } } </s>
<s> package gov . nasa . daveml . dave2post ; import gov . nasa . daveml . dave . * ; import java . io . File ; import java . io . IOException ; import java . util . Iterator ; public class DAVE2POST extends DAVE { String tableFileName ; String sourceFileName ; public DAVE2POST ( ) { super ( ) ; } public DAVE2POST ( String [ ] args ) { this ( ) ; this . parseOptions ( args ) ; if ( this . isVerbose ( ) ) { this . getModel ( ) . makeVerbose ( ) ; } } @ Override public void setInputFileName ( String fn ) { super . setInputFileName ( fn ) ; this . tableFileName = this . getStubName ( ) + "<STR_LIT>" ; this . sourceFileName = this . getStubName ( ) + "<STR_LIT>" ; } private void parseOptions ( String inArgs [ ] ) { String exampleUse = "<STR_LIT>" ; int numArgs = inArgs . length ; this . setArgs ( inArgs ) ; if ( numArgs > <NUM_LIT:0> ) { int parsedArgs = <NUM_LIT:0> ; if ( this . matchOptionArgs ( "<STR_LIT:c>" , "<STR_LIT:count>" ) ) { this . setGenStatsFlag ( ) ; parsedArgs ++ ; } if ( this . matchOptionArgs ( "<STR_LIT:d>" , "<STR_LIT>" ) ) { this . makeVerbose ( ) ; parsedArgs ++ ; } if ( matchOptionArgs ( "<STR_LIT>" , "<STR_LIT:version>" ) ) { System . out . println ( "<STR_LIT>" + getVersion ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } if ( parsedArgs < ( numArgs - <NUM_LIT:1> ) ) { if ( numArgs == <NUM_LIT:2> ) { System . err . println ( "<STR_LIT>" + getArgs ( ) [ <NUM_LIT:2> ] + "<STR_LIT>" ) ; } else { System . err . println ( "<STR_LIT>" + ( numArgs - <NUM_LIT:1> ) + "<STR_LIT>" ) ; } System . err . println ( exampleUse ) ; System . exit ( <NUM_LIT:0> ) ; } } else { System . out . println ( exampleUse ) ; System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } this . setInputFileName ( inArgs [ numArgs - <NUM_LIT:1> ] ) ; } public void createModel ( ) throws IOException { Model theModel = this . getModel ( ) ; File file = new File ( this . getStubName ( ) ) ; String modelName = file . getName ( ) ; PostTableFileWriter tableWriter = new PostTableFileWriter ( theModel , this . tableFileName ) ; FEquationsFileWriter equationWriter = new FEquationsFileWriter ( theModel , this . sourceFileName ) ; equationWriter . writeFcode ( ) ; BlockArrayList blocks = theModel . getBlocks ( ) ; Iterator < Block > it = blocks . iterator ( ) ; while ( it . hasNext ( ) ) { Block blk = it . next ( ) ; if ( blk instanceof BlockFuncTable ) { BlockFuncTable bft = ( BlockFuncTable ) blk ; tableWriter . generateTableDescription ( bft ) ; } } tableWriter . close ( ) ; equationWriter . close ( ) ; } public static void main ( String args [ ] ) { boolean success = false ; DAVE2POST dave2post = new DAVE2POST ( args ) ; try { System . out . println ( "<STR_LIT>" ) ; success = dave2post . parseFile ( ) ; } catch ( Exception e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } System . out . println ( "<STR_LIT>" ) ; try { if ( dave2post . hasCheckcases ( ) ) { System . out . println ( "<STR_LIT>" ) ; if ( ! dave2post . verify ( ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } } } catch ( NoSuchMethodError e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } try { if ( dave2post . getGenStatsFlag ( ) ) { dave2post . reportStats ( ) ; } } catch ( NoSuchMethodError e ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } System . out . println ( "<STR_LIT>" ) ; try { dave2post . createModel ( ) ; } catch ( IOException e ) { return ; } System . out . println ( "<STR_LIT>" + dave2post . getStubName ( ) + "<STR_LIT:.>" ) ; } } </s>
<s> package gov . nasa . daveml . dave2post ; </s>
<s> package gov . nasa . daveml . dave2post ; import gov . nasa . daveml . dave . * ; import java . io . FileWriter ; import java . io . IOException ; class CEquationsFileWriter extends FileWriter { Model ourModel ; public CEquationsFileWriter ( Model theModel , String sourceFileName ) throws IOException { super ( sourceFileName ) ; ourModel = theModel ; } void generateTableCall ( BlockFuncTable bft ) { System . out . println ( "<STR_LIT>" ) ; } } </s>
<s> package gov . nasa . daveml . dave2post ; import gov . nasa . daveml . dave . * ; import java . io . FileWriter ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . logging . Level ; import java . util . logging . Logger ; class PostTableFileWriter extends FileWriter { int tableNumber , tableRefNumber ; Model ourModel ; String indent ; public PostTableFileWriter ( Model theModel , String tableFileName ) throws IOException { super ( tableFileName ) ; ourModel = theModel ; indent = "<STR_LIT>" ; } public void writeln ( String cbuf ) throws IOException { super . write ( cbuf + "<STR_LIT:n>" ) ; } void generateTableDescription ( BlockFuncTable bft ) { tableNumber = <NUM_LIT:0> ; tableRefNumber = <NUM_LIT:1> ; String outVarID = bft . getOutputVarID ( ) ; FuncTable ft = bft . getFunctionTableDef ( ) ; int [ ] dims = ft . getDimensions ( ) ; int numDims = dims . length ; String gtID = ft . getGTID ( ) ; try { writeln ( "<STR_LIT>" + "<STR_LIT:'>" + gtID + "<STR_LIT>" + numDims + "<STR_LIT:.>" ) ; } catch ( IOException ex ) { Logger . getLogger ( PostTableFileWriter . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } if ( numDims == <NUM_LIT:1> ) { this . writeMonoTable ( bft , <NUM_LIT:0> ) ; } else { int offset = <NUM_LIT:0> ; this . writeMultiTables ( bft , <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:1> ; i < dims [ numDims - <NUM_LIT:2> ] ; i ++ ) { offset = this . writeMonoTable ( bft , offset ) ; } } } private void writeMultiTables ( BlockFuncTable bft , int dimLevel ) { FuncTable ft = bft . getFunctionTableDef ( ) ; String outVarID = bft . getOutputVarID ( ) ; int [ ] dims = ft . getDimensions ( ) ; int numDims = dims . length ; if ( dimLevel >= ( numDims - <NUM_LIT:1> ) ) { return ; } else { String inVarID = bft . getVarID ( dimLevel + <NUM_LIT:1> ) ; String bpID = ft . getBPID ( dimLevel + <NUM_LIT:1> ) ; ArrayList < Double > bps = ourModel . getBPSetByID ( bpID ) . values ( ) ; Iterator < Double > bpIt = bps . iterator ( ) ; try { write ( "<STR_LIT:U+0020U+0020>" + outVarID + "<STR_LIT>" + outVarID + "<STR_LIT>" + inVarID ) ; writeln ( "<STR_LIT:U+002CU+0020>" + tableNumber ++ + "<STR_LIT>" ) ; } catch ( IOException ex ) { Logger . getLogger ( PostTableFileWriter . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } while ( bpIt . hasNext ( ) ) { double breakpointVal = bpIt . next ( ) ; try { writeln ( indent + breakpointVal + "<STR_LIT:U+002CU+0020>" + tableRefNumber ++ + "<STR_LIT:U+002C>" ) ; } catch ( IOException ex ) { Logger . getLogger ( PostTableFileWriter . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } writeMultiTables ( bft , dimLevel + <NUM_LIT:1> ) ; } } private int writeMonoTable ( BlockFuncTable bft , int offset ) { FuncTable ft = bft . getFunctionTableDef ( ) ; String outVarID = bft . getOutputVarID ( ) ; int [ ] dims = ft . getDimensions ( ) ; int numDims = dims . length ; String bpID = ft . getBPID ( numDims ) ; String inVarID = bft . getVarID ( numDims ) ; ArrayList < Double > bps = ourModel . getBPSetByID ( bpID ) . values ( ) ; ArrayList < Double > vals = ft . getValues ( ) ; try { write ( "<STR_LIT:U+0020U+0020>" + outVarID + "<STR_LIT>" + outVarID + "<STR_LIT>" + inVarID ) ; writeln ( "<STR_LIT:U+002CU+0020>" + tableNumber + "<STR_LIT>" ) ; } catch ( IOException ex ) { Logger . getLogger ( PostTableFileWriter . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } offset = this . generate1DTable ( bps , vals , offset ) ; tableNumber ++ ; return offset ; } private int generate1DTable ( ArrayList < Double > bps , ArrayList < Double > vals , int valOffset ) { int i = <NUM_LIT:0> ; if ( bps . size ( ) > ( vals . size ( ) - valOffset ) ) { System . err . println ( "<STR_LIT>" + ( vals . size ( ) - valOffset ) + "<STR_LIT>" + bps . size ( ) ) ; } else { for ( i = <NUM_LIT:0> ; i < bps . size ( ) ; i ++ ) { try { writeln ( indent + bps . get ( i ) + "<STR_LIT:U+002CU+0020>" + vals . get ( i + valOffset ) + "<STR_LIT:U+002C>" ) ; } catch ( IOException ex ) { Logger . getLogger ( PostTableFileWriter . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } } return valOffset + i ; } } </s>
<s> package gov . nasa . daveml . dave2post ; import gov . nasa . daveml . dave . * ; import java . io . FileWriter ; import java . io . IOException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . Iterator ; class FEquationsFileWriter extends FileWriter { Model ourModel ; String indent ; public FEquationsFileWriter ( Model theModel , String sourceFileName ) throws IOException { super ( sourceFileName ) ; ourModel = theModel ; indent = "<STR_LIT>" ; } public void writeln ( String cbuf ) throws IOException { super . write ( cbuf + "<STR_LIT:n>" ) ; } public void writeFcode ( ) throws IOException { CodeAndVarNames cvn = new CodeAndVarNames ( ) ; BlockArrayList sortedBlocks ; BlockArrayList outputBlocks = new BlockArrayList ( <NUM_LIT:10> ) ; Iterator < Block > blkIt ; Block blk ; String codeBody = "<STR_LIT>" ; String codeDeclarations = "<STR_LIT>" ; ourModel . setCodeDialect ( Model . DT_FORTRAN ) ; try { sortedBlocks = ourModel . getSortedBlocks ( ) ; if ( sortedBlocks . isEmpty ( ) ) { System . err . println ( "<STR_LIT>" + "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } blkIt = sortedBlocks . iterator ( ) ; while ( blkIt . hasNext ( ) ) { blk = blkIt . next ( ) ; boolean skip = false ; if ( blk instanceof BlockLimiter || blk instanceof BlockMathSwitch ) blk . getOutput ( ) . clearDerivedFlag ( ) ; Signal outSig = blk . getOutput ( ) ; if ( outSig != null ) if ( outSig . isDerived ( ) ) skip = true ; if ( blk instanceof BlockBP ) { } else if ( blk instanceof BlockOutput ) { outputBlocks . add ( blk ) ; } else if ( blk instanceof BlockFuncTable ) { cvn . appendCode ( this . generateTableCall ( ( BlockFuncTable ) blk ) ) ; } else { if ( ! skip ) cvn . append ( blk . genCode ( ) ) ; } } blkIt = outputBlocks . iterator ( ) ; while ( blkIt . hasNext ( ) ) { cvn . append ( blkIt . next ( ) . genCode ( ) ) ; codeBody = cvn . getCode ( ) ; } codeDeclarations = "<STR_LIT>" ; ArrayList < String > varNames = cvn . getVarNames ( ) ; ArrayList < String > uniqueNames = new ArrayList < String > ( new HashSet ( varNames ) ) ; Collections . sort ( uniqueNames , String . CASE_INSENSITIVE_ORDER ) ; Iterator < String > varIt = uniqueNames . iterator ( ) ; while ( varIt . hasNext ( ) ) { codeDeclarations += indent + "<STR_LIT>" + varIt . next ( ) + "<STR_LIT:n>" ; } write ( codeDeclarations ) ; write ( codeBody ) ; writeln ( indent + "<STR_LIT>" ) ; writeln ( indent + "<STR_LIT>" ) ; } catch ( DAVEException ex ) { System . err . println ( "<STR_LIT>" ) ; } } private String generateTableCall ( BlockFuncTable bft ) { String outVarID = bft . getOutputVarID ( ) ; return indent + outVarID + "<STR_LIT>" + outVarID + "<STR_LIT>" ; } } </s>
<s> package gov . nasa . daveml . sweeper ; import org . math . plot . Plot3DPanel ; import org . math . plot . render . Projection ; import javax . swing . JTable ; import java . util . Iterator ; import javax . swing . JTextField ; import gov . nasa . daveml . dave . DAVE ; import gov . nasa . daveml . dave . DAVEException ; import gov . nasa . daveml . dave . Model ; import gov . nasa . daveml . dave . VectorInfo ; import gov . nasa . daveml . dave . VectorInfoArrayList ; import java . io . File ; import java . io . IOException ; import java . util . ListIterator ; import java . util . logging . Level ; import java . util . logging . Logger ; import javax . swing . JFileChooser ; import static org . math . array . DoubleArray . * ; class DMLFilter extends javax . swing . filechooser . FileFilter { @ Override public boolean accept ( File file ) { return file . isDirectory ( ) || file . getAbsolutePath ( ) . endsWith ( "<STR_LIT>" ) || file . getAbsolutePath ( ) . endsWith ( "<STR_LIT>" ) ; } @ Override public String getDescription ( ) { return "<STR_LIT>" ; } } public class ModelSweeperUI extends javax . swing . JFrame { private static final long serialVersionUID = - <NUM_LIT> ; File inputFile ; VectorInfoArrayList inputVec ; VectorInfoArrayList outputVec ; Model model ; boolean plotReady ; int numPts ; int input1Selector ; int input2Selector ; int outputSelector ; InputTable inputTable ; InputTableJFrame inputTableJFrame ; Plot3DPanel plot ; int plotSurface ; Projection projection ; public ModelSweeperUI ( ) { inputFile = null ; inputTable = null ; inputVec = null ; outputVec = null ; model = null ; numPts = <NUM_LIT:10> ; plotReady = false ; plot = null ; inputTableJFrame = null ; initComponents ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { jPanel4 = new javax . swing . JPanel ( ) ; jPanel3 = new javax . swing . JPanel ( ) ; inputSignals = new javax . swing . JButton ( ) ; jSeparator4 = new javax . swing . JSeparator ( ) ; input1ComboBox = new javax . swing . JComboBox ( ) ; jLabel2 = new javax . swing . JLabel ( ) ; input1MinValTextField = new javax . swing . JTextField ( ) ; jLabel3 = new javax . swing . JLabel ( ) ; input1MaxValTextField = new javax . swing . JTextField ( ) ; input2ComboBox = new javax . swing . JComboBox ( ) ; jLabel7 = new javax . swing . JLabel ( ) ; input2MinValTextField = new javax . swing . JTextField ( ) ; jLabel8 = new javax . swing . JLabel ( ) ; input2MaxValTextField = new javax . swing . JTextField ( ) ; jSeparator5 = new javax . swing . JSeparator ( ) ; jPanel1 = new javax . swing . JPanel ( ) ; modelFileNameTextField = new javax . swing . JTextField ( ) ; browseButton = new javax . swing . JButton ( ) ; jPanel2 = new javax . swing . JPanel ( ) ; Coarser = new javax . swing . JButton ( ) ; Denser = new javax . swing . JButton ( ) ; jPanel5 = new javax . swing . JPanel ( ) ; plotFrame = new javax . swing . JInternalFrame ( ) ; outputSignalComboBox = new javax . swing . JComboBox ( ) ; setDefaultCloseOperation ( javax . swing . WindowConstants . EXIT_ON_CLOSE ) ; jPanel3 . setBorder ( javax . swing . BorderFactory . createTitledBorder ( "<STR_LIT>" ) ) ; inputSignals . setText ( "<STR_LIT>" ) ; inputSignals . setEnabled ( false ) ; inputSignals . setMaximumSize ( new java . awt . Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; inputSignals . setMinimumSize ( new java . awt . Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; inputSignals . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { inputSignalsActionPerformed ( evt ) ; } } ) ; input1ComboBox . setModel ( new javax . swing . DefaultComboBoxModel ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ) ; input1ComboBox . setEnabled ( false ) ; input1ComboBox . setPreferredSize ( new java . awt . Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; input1ComboBox . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input1ComboBoxActionPerformed ( evt ) ; } } ) ; jLabel2 . setText ( "<STR_LIT>" ) ; input1MinValTextField . setHorizontalAlignment ( javax . swing . JTextField . TRAILING ) ; input1MinValTextField . setText ( "<STR_LIT>" ) ; input1MinValTextField . setEnabled ( false ) ; input1MinValTextField . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input1MinValTextFieldActionPerformed ( evt ) ; } } ) ; input1MinValTextField . addInputMethodListener ( new java . awt . event . InputMethodListener ( ) { public void inputMethodTextChanged ( java . awt . event . InputMethodEvent evt ) { input1MinValTextFieldInputMethodTextChanged ( evt ) ; } public void caretPositionChanged ( java . awt . event . InputMethodEvent evt ) { } } ) ; jLabel3 . setText ( "<STR_LIT>" ) ; input1MaxValTextField . setHorizontalAlignment ( javax . swing . JTextField . TRAILING ) ; input1MaxValTextField . setText ( "<STR_LIT>" ) ; input1MaxValTextField . setEnabled ( false ) ; input1MaxValTextField . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input1MaxValTextFieldActionPerformed ( evt ) ; } } ) ; input2ComboBox . setModel ( new javax . swing . DefaultComboBoxModel ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:U+0020>" } ) ) ; input2ComboBox . setEnabled ( false ) ; input2ComboBox . setPreferredSize ( new java . awt . Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; input2ComboBox . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input2ComboBoxActionPerformed ( evt ) ; } } ) ; jLabel7 . setText ( "<STR_LIT>" ) ; input2MinValTextField . setHorizontalAlignment ( javax . swing . JTextField . TRAILING ) ; input2MinValTextField . setText ( "<STR_LIT>" ) ; input2MinValTextField . setEnabled ( false ) ; input2MinValTextField . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input2MinValTextFieldActionPerformed ( evt ) ; } } ) ; jLabel8 . setText ( "<STR_LIT>" ) ; input2MaxValTextField . setHorizontalAlignment ( javax . swing . JTextField . TRAILING ) ; input2MaxValTextField . setText ( "<STR_LIT>" ) ; input2MaxValTextField . setEnabled ( false ) ; input2MaxValTextField . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { input2MaxValTextFieldActionPerformed ( evt ) ; } } ) ; org . jdesktop . layout . GroupLayout jPanel3Layout = new org . jdesktop . layout . GroupLayout ( jPanel3 ) ; jPanel3 . setLayout ( jPanel3Layout ) ; jPanel3Layout . setHorizontalGroup ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel3Layout . createSequentialGroup ( ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel3Layout . createSequentialGroup ( ) . add ( <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . CENTER ) . add ( input1ComboBox , <NUM_LIT:0> , <NUM_LIT> , Short . MAX_VALUE ) . add ( input2ComboBox , <NUM_LIT:0> , <NUM_LIT> , Short . MAX_VALUE ) . add ( jSeparator4 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . add ( jSeparator5 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) ) ) . add ( jPanel3Layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jLabel2 ) . add ( jLabel7 ) ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( input1MinValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( input2MinValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jLabel3 ) . add ( jLabel8 ) ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( input1MaxValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( input2MaxValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) ) . add ( inputSignals , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . addContainerGap ( ) ) ) ; jPanel3Layout . linkSize ( new java . awt . Component [ ] { input1MaxValTextField , input1MinValTextField , input2MaxValTextField , input2MinValTextField } , org . jdesktop . layout . GroupLayout . HORIZONTAL ) ; jPanel3Layout . setVerticalGroup ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel3Layout . createSequentialGroup ( ) . add ( inputSignals , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> ) . add ( jSeparator4 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT:10> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . add ( input1ComboBox , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . UNRELATED ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . BASELINE ) . add ( jLabel2 ) . add ( input1MinValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( jLabel3 ) . add ( input1MaxValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . add ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) . add ( jSeparator5 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT:10> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . add ( input2ComboBox , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel3Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . BASELINE ) . add ( input2MinValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( jLabel8 ) . add ( input2MaxValTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( jLabel7 ) ) . addContainerGap ( org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) ; jPanel1 . setBorder ( javax . swing . BorderFactory . createTitledBorder ( "<STR_LIT>" ) ) ; modelFileNameTextField . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { modelFileNameTextFieldActionPerformed ( evt ) ; } } ) ; browseButton . setText ( "<STR_LIT>" ) ; browseButton . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { browseButtonActionPerformed ( evt ) ; } } ) ; org . jdesktop . layout . GroupLayout jPanel1Layout = new org . jdesktop . layout . GroupLayout ( jPanel1 ) ; jPanel1 . setLayout ( jPanel1Layout ) ; jPanel1Layout . setHorizontalGroup ( jPanel1Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel1Layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jPanel1Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( modelFileNameTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( browseButton ) ) . addContainerGap ( <NUM_LIT> , Short . MAX_VALUE ) ) ) ; jPanel1Layout . setVerticalGroup ( jPanel1Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel1Layout . createSequentialGroup ( ) . add ( modelFileNameTextField , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . UNRELATED ) . add ( browseButton ) ) ) ; jPanel2 . setBorder ( javax . swing . BorderFactory . createTitledBorder ( "<STR_LIT>" ) ) ; Coarser . setText ( "<STR_LIT>" ) ; Coarser . setEnabled ( false ) ; Coarser . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { CoarserActionPerformed ( evt ) ; } } ) ; Denser . setText ( "<STR_LIT>" ) ; Denser . setEnabled ( false ) ; Denser . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { DenserActionPerformed ( evt ) ; } } ) ; org . jdesktop . layout . GroupLayout jPanel2Layout = new org . jdesktop . layout . GroupLayout ( jPanel2 ) ; jPanel2 . setLayout ( jPanel2Layout ) ; jPanel2Layout . setHorizontalGroup ( jPanel2Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel2Layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( Denser ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED , <NUM_LIT:9> , Short . MAX_VALUE ) . add ( Coarser , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addContainerGap ( ) ) ) ; jPanel2Layout . linkSize ( new java . awt . Component [ ] { Coarser , Denser } , org . jdesktop . layout . GroupLayout . HORIZONTAL ) ; jPanel2Layout . setVerticalGroup ( jPanel2Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel2Layout . createSequentialGroup ( ) . add ( jPanel2Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . BASELINE ) . add ( Denser ) . add ( Coarser ) ) . addContainerGap ( <NUM_LIT:9> , Short . MAX_VALUE ) ) ) ; jPanel5 . setBorder ( javax . swing . BorderFactory . createTitledBorder ( "<STR_LIT>" ) ) ; plotFrame . setBorder ( javax . swing . BorderFactory . createEtchedBorder ( ) ) ; plotFrame . setPreferredSize ( new java . awt . Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; plotFrame . setVisible ( true ) ; org . jdesktop . layout . GroupLayout plotFrameLayout = new org . jdesktop . layout . GroupLayout ( plotFrame . getContentPane ( ) ) ; plotFrame . getContentPane ( ) . setLayout ( plotFrameLayout ) ; plotFrameLayout . setHorizontalGroup ( plotFrameLayout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( <NUM_LIT:0> , <NUM_LIT> , Short . MAX_VALUE ) ) ; plotFrameLayout . setVerticalGroup ( plotFrameLayout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( <NUM_LIT:0> , <NUM_LIT> , Short . MAX_VALUE ) ) ; outputSignalComboBox . setModel ( new javax . swing . DefaultComboBoxModel ( new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) ) ; outputSignalComboBox . setEnabled ( false ) ; outputSignalComboBox . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { outputSignalComboBoxActionPerformed ( evt ) ; } } ) ; org . jdesktop . layout . GroupLayout jPanel5Layout = new org . jdesktop . layout . GroupLayout ( jPanel5 ) ; jPanel5 . setLayout ( jPanel5Layout ) ; jPanel5Layout . setHorizontalGroup ( jPanel5Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel5Layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jPanel5Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( plotFrame , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . add ( outputSignalComboBox , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . addContainerGap ( ) ) ) ; jPanel5Layout . setVerticalGroup ( jPanel5Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel5Layout . createSequentialGroup ( ) . add ( outputSignalComboBox , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . UNRELATED ) . add ( plotFrame , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . addContainerGap ( ) ) ) ; org . jdesktop . layout . GroupLayout jPanel4Layout = new org . jdesktop . layout . GroupLayout ( jPanel4 ) ; jPanel4 . setLayout ( jPanel4Layout ) ; jPanel4Layout . setHorizontalGroup ( jPanel4Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel4Layout . createSequentialGroup ( ) . add ( jPanel4Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . TRAILING , false ) . add ( org . jdesktop . layout . GroupLayout . LEADING , jPanel2 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . add ( org . jdesktop . layout . GroupLayout . LEADING , jPanel1 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . add ( org . jdesktop . layout . GroupLayout . LEADING , jPanel3 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) ) . add ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . add ( jPanel5 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) . addContainerGap ( ) ) ) ; jPanel4Layout . setVerticalGroup ( jPanel4Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel4Layout . createSequentialGroup ( ) . add ( jPanel4Layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( jPanel4Layout . createSequentialGroup ( ) . add ( jPanel1 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel3 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . RELATED ) . add ( jPanel2 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . add ( jPanel5 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) ) . addContainerGap ( org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) ; org . jdesktop . layout . GroupLayout layout = new org . jdesktop . layout . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jPanel4 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jPanel4 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) ) ) ; pack ( ) ; } private void input1MinValTextFieldActionPerformed ( java . awt . event . ActionEvent evt ) { Double val = new Double ( input1MinValTextField . getText ( ) ) ; inputTable . setMinVal ( input1Selector , val ) ; System . out . println ( "<STR_LIT>" ) ; if ( plotReady ) doPlot ( ) ; } private void browseButtonActionPerformed ( java . awt . event . ActionEvent evt ) { final JFileChooser fc = new JFileChooser ( ) ; fc . setFileFilter ( new DMLFilter ( ) ) ; int returnVal = fc . showOpenDialog ( this ) ; if ( returnVal == JFileChooser . APPROVE_OPTION ) { inputFile = fc . getSelectedFile ( ) ; plotReady = false ; this . loadModel ( ) ; } } private void modelFileNameTextFieldActionPerformed ( java . awt . event . ActionEvent evt ) { } private void outputSignalComboBoxActionPerformed ( java . awt . event . ActionEvent evt ) { outputSelector = outputSignalComboBox . getSelectedIndex ( ) ; if ( plotReady ) doPlot ( ) ; } private void input1ComboBoxActionPerformed ( java . awt . event . ActionEvent evt ) { int sel = input1ComboBox . getSelectedIndex ( ) ; if ( ( sel > - <NUM_LIT:1> ) && ( sel != input2Selector ) ) { input1Selector = sel ; setMinMaxLabels ( input1MinValTextField , input1MaxValTextField , input1Selector ) ; if ( plotReady ) doPlot ( ) ; } } private void input2ComboBoxActionPerformed ( java . awt . event . ActionEvent evt ) { int sel = input2ComboBox . getSelectedIndex ( ) ; if ( ( sel > - <NUM_LIT:1> ) && ( sel != input1Selector ) ) { input2Selector = sel ; setMinMaxLabels ( input2MinValTextField , input2MaxValTextField , input2Selector ) ; if ( plotReady ) doPlot ( ) ; } } private void input1MaxValTextFieldActionPerformed ( java . awt . event . ActionEvent evt ) { Double val = new Double ( input1MaxValTextField . getText ( ) ) ; inputTable . setMaxVal ( input1Selector , val ) ; if ( plotReady ) doPlot ( ) ; } private void input2MinValTextFieldActionPerformed ( java . awt . event . ActionEvent evt ) { Double val = new Double ( input2MinValTextField . getText ( ) ) ; inputTable . setMinVal ( input2Selector , val ) ; if ( plotReady ) doPlot ( ) ; } private void input2MaxValTextFieldActionPerformed ( java . awt . event . ActionEvent evt ) { Double val = new Double ( input2MaxValTextField . getText ( ) ) ; inputTable . setMaxVal ( input2Selector , val ) ; if ( plotReady ) doPlot ( ) ; } private void DenserActionPerformed ( java . awt . event . ActionEvent evt ) { numPts = <NUM_LIT:2> * numPts ; if ( plotReady ) doPlot ( ) ; } private void CoarserActionPerformed ( java . awt . event . ActionEvent evt ) { numPts = numPts / <NUM_LIT:2> ; if ( numPts < <NUM_LIT:2> ) numPts = <NUM_LIT:2> ; if ( plotReady ) doPlot ( ) ; } private void inputSignalsActionPerformed ( java . awt . event . ActionEvent evt ) { if ( inputTable != null ) { if ( inputTableJFrame == null ) { inputTableJFrame = new InputTableJFrame ( ) ; } if ( inputTableJFrame != null ) { JTable theTable = inputTableJFrame . getTable ( ) ; theTable . setModel ( inputTable ) ; inputTable . setJFrame ( inputTableJFrame ) ; inputTableJFrame . setVisible ( true ) ; } } } private void input1MinValTextFieldInputMethodTextChanged ( java . awt . event . InputMethodEvent evt ) { System . out . println ( "<STR_LIT>" ) ; } private void doPlot ( ) { double xmin = inputTable . getMinVal ( input1Selector ) ; double xmax = inputTable . getMaxVal ( input1Selector ) ; double delx = ( xmax - xmin ) / numPts ; double ymin = inputTable . getMinVal ( input2Selector ) ; double ymax = inputTable . getMaxVal ( input2Selector ) ; double dely = ( ymax - ymin ) / numPts ; double [ ] x = { xmin , xmax } ; if ( delx > <NUM_LIT:0> ) { x = increment ( xmin , delx , xmax ) ; } double [ ] y = { ymin , ymax } ; if ( dely > <NUM_LIT:0> ) { y = increment ( ymin , dely , ymax ) ; } double [ ] [ ] z = sweepModel ( x , y , input1Selector , input2Selector , outputSelector , inputTable , model ) ; if ( plot == null ) { plot = new Plot3DPanel ( "<STR_LIT>" ) ; plot . setPlotToolBarOrientation ( "<STR_LIT>" ) ; plotFrame . setContentPane ( plot ) ; } else { plot . removePlot ( plotSurface ) ; } plot . setAxisLabel ( <NUM_LIT:0> , ( String ) input1ComboBox . getItemAt ( input1Selector ) ) ; plot . setAxisLabel ( <NUM_LIT:1> , ( String ) input2ComboBox . getItemAt ( input2Selector ) ) ; plot . setAxisLabel ( <NUM_LIT:2> , ( String ) outputSignalComboBox . getItemAt ( outputSelector ) ) ; plotSurface = plot . addGridPlot ( outputVec . get ( outputSelector ) . getName ( ) , x , y , z ) ; plotReady = true ; } private void loadModel ( ) { inputVec = null ; outputVec = null ; DAVE dave = new DAVE ( ) ; dave . setInputFileName ( inputFile . getAbsolutePath ( ) ) ; boolean keepGoing = true ; try { keepGoing = dave . parseFile ( ) ; } catch ( IOException ex ) { Logger . getLogger ( ModelSweeperUI . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; keepGoing = false ; } keepGoing = dave . verify ( ) ; if ( keepGoing ) { model = dave . getModel ( ) ; modelFileNameTextField . setText ( model . getName ( ) ) ; try { inputVec = model . getInputVector ( ) ; outputVec = model . getOutputVector ( ) ; keepGoing = true ; if ( inputVec == null ) { keepGoing = false ; } else if ( inputVec . isEmpty ( ) ) { keepGoing = false ; } if ( outputVec == null ) { keepGoing = false ; } else if ( outputVec . isEmpty ( ) ) { keepGoing = false ; } } catch ( DAVEException ex ) { Logger . getLogger ( ModelSweeperUI . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; keepGoing = false ; } } if ( keepGoing ) { inputTable = new InputTable ( dave , this ) ; clearAndLoadComboBox ( input1ComboBox , inputVec ) ; clearAndLoadComboBox ( input2ComboBox , inputVec ) ; clearAndLoadComboBox ( outputSignalComboBox , outputVec ) ; input1Selector = <NUM_LIT:0> ; input2Selector = <NUM_LIT:1> ; outputSelector = <NUM_LIT:0> ; input1ComboBox . setSelectedIndex ( input1Selector ) ; input2ComboBox . setSelectedIndex ( input2Selector ) ; outputSignalComboBox . setSelectedIndex ( outputSelector ) ; setMinMaxLabels ( input1MinValTextField , input1MaxValTextField , input1Selector ) ; setMinMaxLabels ( input2MinValTextField , input2MaxValTextField , input2Selector ) ; } if ( ! keepGoing ) { System . exit ( <NUM_LIT:0> ) ; } plotReady = true ; enableControls ( ) ; doPlot ( ) ; } private void enableControls ( ) { input1ComboBox . setEnabled ( true ) ; input2ComboBox . setEnabled ( true ) ; inputSignals . setEnabled ( true ) ; input1MinValTextField . setEnabled ( true ) ; input2MinValTextField . setEnabled ( true ) ; input1MaxValTextField . setEnabled ( true ) ; input2MaxValTextField . setEnabled ( true ) ; outputSignalComboBox . setEnabled ( true ) ; Coarser . setEnabled ( true ) ; Denser . setEnabled ( true ) ; } private void setMinMaxLabels ( JTextField minField , JTextField maxField , int inSel ) { Double val ; val = new Double ( inputTable . getMinVal ( inSel ) ) ; minField . setText ( val . toString ( ) ) ; val = new Double ( inputTable . getMaxVal ( inSel ) ) ; maxField . setText ( val . toString ( ) ) ; } private void clearAndLoadComboBox ( javax . swing . JComboBox comboBox , VectorInfoArrayList vec ) { for ( int i = comboBox . getItemCount ( ) - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { comboBox . removeItemAt ( i ) ; } ListIterator it = vec . listIterator ( ) ; int index = <NUM_LIT:0> ; while ( it . hasNext ( ) ) { VectorInfo signal = ( VectorInfo ) it . next ( ) ; String name = signal . getName ( ) ; String units = signal . getUnits ( ) ; if ( units . length ( ) > <NUM_LIT:0> ) { name = name + "<STR_LIT:_>" + units ; } comboBox . insertItemAt ( name , index ) ; index ++ ; } comboBox . setSelectedIndex ( <NUM_LIT:0> ) ; comboBox . setMaximumRowCount ( index ) ; } private static void dumpVec ( VectorInfoArrayList vec ) { System . out . println ( "<STR_LIT>" ) ; Iterator it = vec . iterator ( ) ; while ( it . hasNext ( ) ) { VectorInfo vi = ( VectorInfo ) it . next ( ) ; System . out . println ( "<STR_LIT>" + vi . getName ( ) + "<STR_LIT:U+0020=U+0020>" + vi . getValue ( ) ) ; } } void updateInputInfo ( int rowIndex ) { if ( rowIndex == input1Selector ) { setMinMaxLabels ( input1MinValTextField , input1MaxValTextField , rowIndex ) ; } if ( rowIndex == input2Selector ) { setMinMaxLabels ( input2MinValTextField , input2MaxValTextField , rowIndex ) ; } } public static double sweepModel ( double x , double y , int input1Selector , int input2Selector , int outputSelector , InputTable inputTable , Model model ) { VectorInfoArrayList inputVec = null ; VectorInfoArrayList outputVec = null ; try { inputVec = model . getInputVector ( ) ; outputVec = model . getOutputVector ( ) ; } catch ( DAVEException ex ) { Logger . getLogger ( ModelSweeperUI . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; System . exit ( <NUM_LIT:0> ) ; } inputTable . loadNominalValues ( inputVec ) ; VectorInfo input1 = inputVec . get ( input1Selector ) ; VectorInfo input2 = inputVec . get ( input2Selector ) ; input1 . setValue ( x ) ; input2 . setValue ( y ) ; inputVec . set ( input1Selector , input1 ) ; inputVec . set ( input2Selector , input2 ) ; try { model . cycle ( ) ; } catch ( DAVEException ex ) { Logger . getLogger ( ModelSweeperUI . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; System . exit ( <NUM_LIT:0> ) ; } VectorInfo output = outputVec . get ( outputSelector ) ; return output . getValue ( ) ; } public static double [ ] [ ] sweepModel ( double [ ] x , double [ ] y , int input1Selector , int input2Selector , int outputSelector , InputTable inputTable , Model model ) { double [ ] [ ] z = new double [ y . length ] [ x . length ] ; for ( int i = <NUM_LIT:0> ; i < x . length ; i ++ ) for ( int j = <NUM_LIT:0> ; j < y . length ; j ++ ) z [ j ] [ i ] = sweepModel ( x [ i ] , y [ j ] , input1Selector , input2Selector , outputSelector , inputTable , model ) ; return z ; } public static void main ( String args [ ] ) { java . awt . EventQueue . invokeLater ( new Runnable ( ) { public void run ( ) { new ModelSweeperUI ( ) . setVisible ( true ) ; } } ) ; } private javax . swing . JButton Coarser ; private javax . swing . JButton Denser ; private javax . swing . JButton browseButton ; private javax . swing . JComboBox input1ComboBox ; private javax . swing . JTextField input1MaxValTextField ; private javax . swing . JTextField input1MinValTextField ; private javax . swing . JComboBox input2ComboBox ; private javax . swing . JTextField input2MaxValTextField ; private javax . swing . JTextField input2MinValTextField ; private javax . swing . JButton inputSignals ; private javax . swing . JLabel jLabel2 ; private javax . swing . JLabel jLabel3 ; private javax . swing . JLabel jLabel7 ; private javax . swing . JLabel jLabel8 ; private javax . swing . JPanel jPanel1 ; private javax . swing . JPanel jPanel2 ; private javax . swing . JPanel jPanel3 ; private javax . swing . JPanel jPanel4 ; private javax . swing . JPanel jPanel5 ; private javax . swing . JSeparator jSeparator4 ; private javax . swing . JSeparator jSeparator5 ; private javax . swing . JTextField modelFileNameTextField ; private javax . swing . JComboBox outputSignalComboBox ; private javax . swing . JInternalFrame plotFrame ; } </s>
<s> package gov . nasa . daveml . sweeper ; import gov . nasa . daveml . dave . VectorInfo ; public class InputInfo { VectorInfo orig ; double min ; double max ; double nominal ; public InputInfo ( VectorInfo aVectorInfo ) { orig = aVectorInfo ; min = <NUM_LIT> ; max = <NUM_LIT> ; nominal = <NUM_LIT> ; } public String getName ( ) { return orig . getName ( ) ; } public String getUnits ( ) { return orig . getUnits ( ) ; } double getMin ( ) { return min ; } double getMax ( ) { return max ; } double getNominal ( ) { return nominal ; } void setMin ( double newMin ) { min = newMin ; } void setMax ( double newMax ) { max = newMax ; } void setMinMax ( double newVal ) { if ( newVal > max ) { max = newVal ; } if ( newVal < min ) { min = newVal ; } } void setNominal ( double newNominal ) { nominal = newNominal ; } void setNominal ( ) { nominal = <NUM_LIT> * ( min + max ) ; } } </s>
<s> package gov . nasa . daveml . sweeper ; </s>
<s> package gov . nasa . daveml . sweeper ; import gov . nasa . daveml . dave . CheckData ; import gov . nasa . daveml . dave . DAVE ; import gov . nasa . daveml . dave . DAVEException ; import gov . nasa . daveml . dave . Model ; import gov . nasa . daveml . dave . StaticShot ; import gov . nasa . daveml . dave . VectorInfo ; import gov . nasa . daveml . dave . VectorInfoArrayList ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . ListIterator ; import java . util . logging . Level ; import java . util . logging . Logger ; public class InputTableJFrame extends javax . swing . JFrame { private static final long serialVersionUID = - <NUM_LIT> ; public InputTableJFrame ( ) { initComponents ( ) ; } public javax . swing . JTable getTable ( ) { return jTable1 ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private void initComponents ( ) { jScrollPane1 = new javax . swing . JScrollPane ( ) ; jTable1 = new javax . swing . JTable ( ) ; jLabelModelName = new javax . swing . JLabel ( ) ; jOKButton = new javax . swing . JButton ( ) ; jTable1 . setModel ( new javax . swing . table . DefaultTableModel ( new Object [ ] [ ] { } , new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ) { private static final long serialVersionUID = - <NUM_LIT> ; Class [ ] types = new Class [ ] { java . lang . String . class , java . lang . String . class , java . lang . Double . class , java . lang . Double . class , java . lang . Double . class } ; boolean [ ] canEdit = new boolean [ ] { false , false , true , true , true } ; public Class getColumnClass ( int columnIndex ) { return types [ columnIndex ] ; } public boolean isCellEditable ( int rowIndex , int columnIndex ) { return canEdit [ columnIndex ] ; } } ) ; jTable1 . setColumnSelectionAllowed ( true ) ; jTable1 . setSelectionMode ( javax . swing . ListSelectionModel . SINGLE_SELECTION ) ; jTable1 . setShowGrid ( true ) ; jTable1 . getTableHeader ( ) . setReorderingAllowed ( false ) ; jScrollPane1 . setViewportView ( jTable1 ) ; jTable1 . getColumnModel ( ) . getSelectionModel ( ) . setSelectionMode ( javax . swing . ListSelectionModel . SINGLE_SELECTION ) ; jTable1 . getColumnModel ( ) . getColumn ( <NUM_LIT:1> ) . setPreferredWidth ( <NUM_LIT:5> ) ; jLabelModelName . setText ( "<STR_LIT>" ) ; jOKButton . setText ( "<STR_LIT:OK>" ) ; jOKButton . addActionListener ( new java . awt . event . ActionListener ( ) { public void actionPerformed ( java . awt . event . ActionEvent evt ) { jOKButtonActionPerformed ( evt ) ; } } ) ; org . jdesktop . layout . GroupLayout layout = new org . jdesktop . layout . GroupLayout ( getContentPane ( ) ) ; getContentPane ( ) . setLayout ( layout ) ; layout . setHorizontalGroup ( layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( org . jdesktop . layout . GroupLayout . TRAILING , layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . TRAILING ) . add ( jOKButton ) . add ( org . jdesktop . layout . GroupLayout . LEADING , jScrollPane1 , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) . add ( org . jdesktop . layout . GroupLayout . LEADING , jLabelModelName , org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , <NUM_LIT> , Short . MAX_VALUE ) ) . addContainerGap ( ) ) ) ; layout . setVerticalGroup ( layout . createParallelGroup ( org . jdesktop . layout . GroupLayout . LEADING ) . add ( layout . createSequentialGroup ( ) . addContainerGap ( ) . add ( jLabelModelName ) . addPreferredGap ( org . jdesktop . layout . LayoutStyle . UNRELATED ) . add ( jScrollPane1 , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE , <NUM_LIT> , org . jdesktop . layout . GroupLayout . PREFERRED_SIZE ) . add ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . add ( jOKButton ) . addContainerGap ( org . jdesktop . layout . GroupLayout . DEFAULT_SIZE , Short . MAX_VALUE ) ) ) ; pack ( ) ; } private void jOKButtonActionPerformed ( java . awt . event . ActionEvent evt ) { this . setVisible ( false ) ; } public static void main ( String args [ ] ) { java . awt . EventQueue . invokeLater ( new Runnable ( ) { public void run ( ) { new InputTableJFrame ( ) . setVisible ( true ) ; } } ) ; } private javax . swing . JLabel jLabelModelName ; private javax . swing . JButton jOKButton ; private javax . swing . JScrollPane jScrollPane1 ; private javax . swing . JTable jTable1 ; public void setModelName ( String name ) { jLabelModelName . setText ( name + "<STR_LIT>" ) ; } } </s>
<s> package gov . nasa . daveml . sweeper ; import gov . nasa . daveml . dave . CheckData ; import gov . nasa . daveml . dave . DAVE ; import gov . nasa . daveml . dave . DAVEException ; import gov . nasa . daveml . dave . Model ; import gov . nasa . daveml . dave . StaticShot ; import gov . nasa . daveml . dave . VectorInfo ; import gov . nasa . daveml . dave . VectorInfoArrayList ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . ListIterator ; import java . util . logging . Level ; import java . util . logging . Logger ; public class InputTable extends javax . swing . table . AbstractTableModel { private static final long serialVersionUID = - <NUM_LIT> ; Model m ; ArrayList < InputInfo > array ; InputTableJFrame parentJFrame ; ModelSweeperUI uiClass ; public InputTable ( DAVE d , ModelSweeperUI mainClass ) { parentJFrame = null ; uiClass = mainClass ; InputInfo modelInput ; VectorInfoArrayList vec = null ; m = d . getModel ( ) ; if ( m != null ) { try { vec = m . getInputVector ( ) ; } catch ( DAVEException ex ) { Logger . getLogger ( InputTableJFrame . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; vec = null ; } } if ( vec == null ) { System . exit ( <NUM_LIT:0> ) ; } array = new ArrayList < InputInfo > ( vec . size ( ) ) ; ListIterator it = vec . listIterator ( ) ; int index = <NUM_LIT:0> ; while ( it . hasNext ( ) ) { VectorInfo signal = ( VectorInfo ) it . next ( ) ; array . add ( new InputInfo ( signal ) ) ; } if ( d . hasCheckcases ( ) ) { setMaxMinToInf ( ) ; CheckData cd = d . getCheckcaseData ( ) ; ArrayList < StaticShot > ssArray = cd . getStaticShots ( ) ; Iterator ssIt = ssArray . iterator ( ) ; while ( ssIt . hasNext ( ) ) { StaticShot ss = ( StaticShot ) ssIt . next ( ) ; VectorInfoArrayList ssInputVectorInfo = ss . getInputs ( ) ; Iterator inputIt = ssInputVectorInfo . iterator ( ) ; while ( inputIt . hasNext ( ) ) { VectorInfo ccSignal = ( VectorInfo ) inputIt . next ( ) ; String inputName = ccSignal . getName ( ) ; double inputValue = ccSignal . getValue ( ) ; boolean matched = false ; Iterator sigIt = array . iterator ( ) ; modelInput = null ; while ( sigIt . hasNext ( ) ) { modelInput = ( InputInfo ) sigIt . next ( ) ; if ( modelInput . getName ( ) == null ? inputName == null : modelInput . getName ( ) . equals ( inputName ) ) { matched = true ; break ; } } if ( matched ) { modelInput . setMinMax ( inputValue ) ; } } } Iterator sigIt = array . iterator ( ) ; while ( sigIt . hasNext ( ) ) { modelInput = ( InputInfo ) sigIt . next ( ) ; modelInput . setNominal ( ) ; } } } private void setMaxMinToInf ( ) { Iterator it = array . iterator ( ) ; while ( it . hasNext ( ) ) { InputInfo input = ( InputInfo ) it . next ( ) ; input . setMax ( Double . NEGATIVE_INFINITY ) ; input . setMin ( Double . POSITIVE_INFINITY ) ; } } public double getMinVal ( int offset ) { InputInfo input = array . get ( offset ) ; return input . getMin ( ) ; } public double getMaxVal ( int offset ) { InputInfo input = array . get ( offset ) ; return input . getMax ( ) ; } public double getNomVal ( int offset ) { InputInfo input = array . get ( offset ) ; return input . getNominal ( ) ; } public void setMinVal ( int offset , double minVal ) { InputInfo input = array . get ( offset ) ; input . setMin ( minVal ) ; } public void setMaxVal ( int offset , double maxVal ) { InputInfo input = array . get ( offset ) ; input . setMax ( maxVal ) ; } public void setNomVal ( int offset , double nomVal ) { InputInfo input = array . get ( offset ) ; input . setNominal ( nomVal ) ; } public void loadNominalValues ( VectorInfoArrayList inputVec ) { Iterator it = inputVec . iterator ( ) ; int i = <NUM_LIT:0> ; while ( it . hasNext ( ) ) { VectorInfo vi = ( VectorInfo ) it . next ( ) ; vi . setValue ( this . getNomVal ( i ) ) ; i ++ ; } } public String getName ( int offset ) { InputInfo input = array . get ( offset ) ; return input . getName ( ) ; } public String getUnits ( int offset ) { InputInfo input = array . get ( offset ) ; return input . getUnits ( ) ; } public int getRowCount ( ) { return array . size ( ) ; } public int getColumnCount ( ) { return <NUM_LIT:5> ; } @ Override public boolean isCellEditable ( int rowIndex , int columnIndex ) { if ( columnIndex > <NUM_LIT:1> ) return true ; return false ; } public Object getValueAt ( int rowIndex , int columnIndex ) { String answer = "<STR_LIT>" ; switch ( columnIndex ) { case <NUM_LIT:0> : answer = getName ( rowIndex ) ; break ; case <NUM_LIT:1> : answer = getUnits ( rowIndex ) ; break ; case <NUM_LIT:2> : answer = new Double ( getNomVal ( rowIndex ) ) . toString ( ) ; break ; case <NUM_LIT:3> : answer = new Double ( getMinVal ( rowIndex ) ) . toString ( ) ; break ; case <NUM_LIT:4> : answer = new Double ( getMaxVal ( rowIndex ) ) . toString ( ) ; break ; } return answer ; } @ Override public String getColumnName ( int columnIndex ) { String answer = "<STR_LIT>" ; switch ( columnIndex ) { case <NUM_LIT:0> : answer = "<STR_LIT>" ; break ; case <NUM_LIT:1> : answer = "<STR_LIT>" ; break ; case <NUM_LIT:2> : answer = "<STR_LIT>" ; break ; case <NUM_LIT:3> : answer = "<STR_LIT>" ; break ; case <NUM_LIT:4> : answer = "<STR_LIT>" ; break ; } return answer ; } @ Override public void setValueAt ( Object aValue , int rowIndex , int columnIndex ) { double val = Double . parseDouble ( ( String ) aValue ) ; switch ( columnIndex ) { case <NUM_LIT:2> : setNomVal ( rowIndex , val ) ; break ; case <NUM_LIT:3> : setMinVal ( rowIndex , val ) ; break ; case <NUM_LIT:4> : setMaxVal ( rowIndex , val ) ; break ; } uiClass . updateInputInfo ( rowIndex ) ; } void setJFrame ( InputTableJFrame inputTableJFrame ) { parentJFrame = inputTableJFrame ; parentJFrame . setModelName ( m . getName ( ) ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . bookmark ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . common . AppClient . PearlClient ; import com . broceliand . pearlbar . chrome . client . popup . * ; import com . broceliand . pearlbar . chrome . client . popup . PopupControl . PopupUIs ; import com . google . gwt . core . client . * ; import com . google . gwt . user . client . Window . Navigator ; public class BookmarkState { private static UserTrees userTrees ; private static final String HAS_RUN_FIRST_TIME_KEY = "<STR_LIT>" ; private static final String HAS_AUTH_FIRST_TIME_KEY = "<STR_LIT>" ; static void init ( ) { WebContent . bookmarklet = true ; WebContent . cookieEnabled = Navigator . isCookieEnabled ( ) ; WebContent . onIpad = Navigator . getUserAgent ( ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ; exports ( ) ; userTrees = UserTrees . init ( ) ; UserTrees . refreshTrees ( false ) ; checkFirstRun ( ) ; } static void setUserTrees ( JavaScriptObject jsut ) { UserTrees ut = new UserTrees ( jsut ) ; boolean hasChanged = userTrees . hasChanged ( ut ) ; userTrees = ut ; if ( hasChanged || UserTrees . getInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY ) == null ) { if ( userTrees . getStatus ( ) == UserTrees . LOADED ) { onPopupRefresh ( true ) ; } PopupControl . onUserTreesChanged ( ) ; } } static void resizeScrollablePanel ( ) { PopupControl . onResize ( ) ; } static JavaScriptObject getUserTreesData ( ) { return userTrees . getData ( ) ; } private static native String getUserTreesString ( ) ; static void reveal ( String treeId , String assoId , int tabId , String url ) { String hash = AppClient . buildRevealHash ( userTrees , treeId , assoId ) ; if ( WebContent . isInPearltrees ( url ) ) { if ( hash != null ) { navigateTo ( WebContent . getUnanchoredUrl ( url ) + '<CHAR_LIT>' + hash ) ; } return ; } navigateTo ( WebContent . getPearltreesUrl ( ) + ( hash == null ? "<STR_LIT>" : '<CHAR_LIT>' + hash ) ) ; } static void goToAccountSync ( int tabId , String url ) { if ( WebContent . isInPearltrees ( url ) ) { navigateTo ( WebContent . getUnanchoredUrl ( url ) + "<STR_LIT>" ) ; return ; } navigateTo ( WebContent . getPearltreesUrl ( ) + "<STR_LIT>" ) ; } private static native void navigateTo ( String toUrl ) ; private static void openCreateAccount ( ) { navigateTo ( WebContent . getPearltreesUrl ( ) ) ; } static void pearlContent ( int tab , String url , String title , final String treeId , String parentTreeId , String newTreeName ) { AppClient . pearlContent ( url , title , treeId , parentTreeId , newTreeName , new PearlClient ( ) { @ Override public boolean resetRevealed ( ) { return false ; } @ Override public void onError ( String msg ) { Alerts . alert ( msg ) ; if ( WebContent . onIpad ) { Alerts . closeWindow ( ) ; } } @ Override public void onPearled ( String newTreeId ) { if ( newTreeId != null ) { PopupControl . changeUI ( PopupUIs . TreeCreated ) ; } else { PopupControl . changeUI ( PopupUIs . Pearled ) ; } } } ) ; } public static void onPopupRefresh ( boolean login ) { if ( UserTrees . getInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY ) == null ) { if ( login ) { UserTrees . setInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY , "<STR_LIT:1>" ) ; return ; } } } public static void checkFirstRun ( ) { if ( UserTrees . getInLocalStorage ( HAS_RUN_FIRST_TIME_KEY ) == null ) { UserTrees . setInLocalStorage ( HAS_RUN_FIRST_TIME_KEY , "<STR_LIT:1>" ) ; } } static void onCredentials ( String c ) { if ( c . equals ( PopupElements . credentials ) ) { return ; } PopupElements . credentials = c ; PopupControl . onUserTreesChanged ( ) ; } private static native void exports ( ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . bookmark ; import com . broceliand . pearlbar . chrome . client . popup . * ; import com . google . gwt . core . client . * ; public class BookmarkMain implements EntryPoint { @ Override public void onModuleLoad ( ) { BookmarkState . init ( ) ; PopupControl . onModuleLoad ( ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; import com . google . gwt . http . client . * ; public class AppClient { public static interface PearlClient { boolean resetRevealed ( ) ; void onError ( String msg ) ; void onPearled ( String newTreeId ) ; } public static void pearlContent ( String url , String title , String treeId , String parentTreeId , String newTreeName , final PearlClient client ) { String service = WebContent . getCollectorUrl ( ) + "<STR_LIT>" ; url = url . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) ; String requestData = "<STR_LIT>" + URL . encodeComponent ( url ) + "<STR_LIT>" + URL . encodeComponent ( title ) ; if ( treeId != null ) { requestData += "<STR_LIT>" + treeId ; } else { requestData += "<STR_LIT>" ; requestData += "<STR_LIT>" + URL . encodeComponent ( newTreeName ) ; requestData += "<STR_LIT>" + parentTreeId ; } if ( client . resetRevealed ( ) ) { requestData += "<STR_LIT>" ; } RequestBuilder builder = new RequestBuilder ( RequestBuilder . POST , service ) ; builder . setHeader ( "<STR_LIT>" , "<STR_LIT>" ) ; try { builder . sendRequest ( requestData , new RequestCallback ( ) { @ Override public void onError ( Request request , Throwable exception ) { client . onError ( Alerts . getUserMessage ( exception ) ) ; } @ Override public void onResponseReceived ( Request request , Response response ) { if ( response . getStatusCode ( ) == Response . SC_OK ) { if ( "<STR_LIT:0>" . equals ( response . getText ( ) ) ) { client . onPearled ( null ) ; } else if ( "<STR_LIT:2>" . equals ( response . getText ( ) ) ) { client . onError ( "<STR_LIT>" ) ; } else if ( "<STR_LIT:3>" . equals ( response . getText ( ) ) ) { client . onError ( "<STR_LIT>" ) ; } else if ( "<STR_LIT:4>" . equals ( response . getText ( ) ) ) { client . onError ( "<STR_LIT>" ) ; } else if ( response . getText ( ) . startsWith ( "<STR_LIT>" ) ) { client . onPearled ( response . getText ( ) . substring ( <NUM_LIT:2> ) ) ; } else { client . onError ( Alerts . getUserMessageForInvalid ( ) ) ; } } else { client . onError ( Alerts . getUserMessage ( response . getStatusCode ( ) ) ) ; } } } ) ; } catch ( Exception e ) { client . onError ( Alerts . getUserMessage ( e ) ) ; } } public static String buildRevealHash ( UserTrees userTrees , String treeId , String assoId ) { if ( userTrees . getTreeId ( UserTrees . DROPZONE_INDEX ) . equals ( treeId ) ) { return null ; } String hash = "<STR_LIT>" ; hash += "<STR_LIT>" + userTrees . getUserId ( ) ; hash += "<STR_LIT>" + treeId ; hash += "<STR_LIT>" + treeId ; if ( ! assoId . isEmpty ( ) ) { hash += "<STR_LIT>" + assoId ; } return hash ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . event . shared . * ; import com . google . gwt . user . client . ui . * ; public class TreeListItem extends FlowPanel implements InsertPanel { public HandlerRegistration addClickHandler ( ClickHandler handler ) { return addDomHandler ( handler , ClickEvent . getType ( ) ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; public class WebContent { public static boolean bookmarklet ; public static boolean onIpad ; public static boolean cookieEnabled ; public enum PearltreesState { Normal , Tunnel , GetStarted , Settings , BookmarkletTunnel } public static boolean isInPearltrees ( String url ) { return url != null && url . startsWith ( getPearltreesUrl ( ) ) ; } public static PearltreesState getPearltreesState ( String url ) { if ( ! isInPearltrees ( url ) ) { return null ; } if ( url . indexOf ( "<STR_LIT>" ) >= <NUM_LIT:0> ) { return PearltreesState . BookmarkletTunnel ; } int anchor = getAnchorStart ( url ) ; if ( anchor < <NUM_LIT:0> ) { return null ; } if ( url . indexOf ( "<STR_LIT>" , anchor ) >= <NUM_LIT:0> ) { return PearltreesState . Settings ; } if ( url . indexOf ( "<STR_LIT>" , anchor ) >= <NUM_LIT:0> ) { return PearltreesState . Tunnel ; } if ( url . indexOf ( "<STR_LIT>" , anchor ) >= <NUM_LIT:0> ) { return PearltreesState . GetStarted ; } return null ; } public static String getUnanchoredUrl ( String url ) { int anchor = getAnchorStart ( url ) ; return anchor < <NUM_LIT:0> ? url : url . substring ( <NUM_LIT:0> , anchor ) ; } public static String getCurrentTree ( String ptUrl ) { int anchor = getAnchorStart ( ptUrl ) ; String param = parseAnchorParam ( ptUrl , anchor , "<STR_LIT>" ) ; if ( param != null ) { return param ; } return parseAnchorParam ( ptUrl , anchor , "<STR_LIT>" ) ; } private static String parseAnchorParam ( String ptUrl , int anchor , String start ) { if ( anchor < <NUM_LIT:0> ) { return null ; } int i = ptUrl . indexOf ( start , anchor ) ; if ( i < <NUM_LIT:0> ) { return null ; } i += start . length ( ) ; int pos = i ; for ( ; i < ptUrl . length ( ) ; i ++ ) { char c = ptUrl . charAt ( i ) ; if ( c < '<CHAR_LIT:0>' || c > '<CHAR_LIT:9>' ) { break ; } } return pos == i ? null : ptUrl . substring ( pos , i ) ; } private static int getAnchorStart ( String url ) { return url . indexOf ( '<CHAR_LIT>' ) ; } public static boolean isWebUrl ( String url ) { return url != null && ( url . startsWith ( "<STR_LIT:http://>" ) || url . startsWith ( "<STR_LIT>" ) ) ; } public static native void openInNewTab ( String href ) ; public static native String getPearltreesUrl ( ) ; public static native String getCDNLocations ( ) ; public static native String getCollectorUrl ( ) ; private static native void navigateTo ( int tabId , String toUrl ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; import java . util . * ; import com . google . gwt . core . client . * ; import com . google . gwt . http . client . * ; public class UserTrees { public static final int NOT_LOADED = <NUM_LIT:0> ; public static final int LOADED = <NUM_LIT:1> ; public static final int LOGOUT = <NUM_LIT:2> ; public static final int ERROR = <NUM_LIT:3> ; public static final int DROPZONE_INDEX = <NUM_LIT:0> ; public static final int ROOTTREE_INDEX = <NUM_LIT:1> ; private static final int MAX_PEARLS = <NUM_LIT:100> ; private static final String USER_TREE_STORED = "<STR_LIT>" ; private final JavaScriptObject data ; public UserTrees ( JavaScriptObject d ) { data = d ; } public JavaScriptObject getData ( ) { return data ; } public int getStatus ( ) { return getStatus ( data ) ; } public String getMessage ( ) { return getMessage ( data ) ; } private static native int getStatus ( JavaScriptObject data ) ; private static native String getMessage ( JavaScriptObject data ) ; public String getUserId ( ) { return getUserId ( data ) ; } private static native String getUserId ( JavaScriptObject data ) ; public int getTreeCount ( ) { return getTreeCount ( data ) ; } private static native int getTreeCount ( JavaScriptObject data ) ; private static native JavaScriptObject getTree ( JavaScriptObject data , int i ) ; public String getTreeId ( int i ) { return getTreeId ( getTree ( data , i ) ) ; } private static native String getTreeId ( JavaScriptObject tree ) ; public String getTreeTitle ( int i ) { return getTreeTitle ( getTree ( data , i ) ) ; } private static native String getTreeTitle ( JavaScriptObject tree ) ; public String getTreeAssoId ( int i ) { return getTreeAssoId ( getTree ( data , i ) ) ; } private static native String getTreeAssoId ( JavaScriptObject tree ) ; public String getTreeAvatarHash ( int i ) { return getTreeAvatarHash ( getTree ( data , i ) ) ; } private static native String getTreeAvatarHash ( JavaScriptObject tree ) ; public boolean isTeam ( int i ) { JavaScriptObject tree = getTree ( data , i ) ; return getTreeAssoId ( tree ) . equals ( getTreeId ( tree ) ) ; } public int getTreeDepth ( int i ) { return Integer . parseInt ( getTreeDepth ( getTree ( data , i ) ) ) ; } private static native String getTreeDepth ( JavaScriptObject tree ) ; public int getTreeCollapsed ( int i ) { String collapsedTree = getTreeCollapsed ( getTree ( data , i ) ) ; if ( collapsedTree != null && ! collapsedTree . equals ( "<STR_LIT>" ) ) { return Integer . parseInt ( collapsedTree ) ; } return <NUM_LIT:0> ; } private static native String getTreeCollapsed ( JavaScriptObject tree ) ; public void setTreeCollapsed ( int i , int collapsed ) { setTreeCollapsed ( getTree ( data , i ) , collapsed ) ; } private static native void setTreeCollapsed ( JavaScriptObject tree , int collapsed ) ; public boolean isTreeFull ( int i ) { return Integer . parseInt ( getTreePearlCount ( getTree ( data , i ) ) ) >= MAX_PEARLS ; } private static native String getTreePearlCount ( JavaScriptObject tree ) ; public static native void backgroundRefreshTrees ( boolean force ) ; public static native JavaScriptObject getUserTreesData ( ) ; UserTrees ( JavaScriptObject d , int status , String msg ) { data = d == null ? makeData ( ) : d ; setStatus ( data , status , msg ) ; } private static native JavaScriptObject makeData ( ) ; private static native void setStatus ( JavaScriptObject data , int status , String msg ) ; private static native void exports ( ) ; static boolean requestTreesRunning = false ; static Date lastRequestTreesReceived = new Date ( <NUM_LIT:0> ) ; public static UserTrees init ( ) { UserTrees ut ; String textStored = getInLocalStorage ( USER_TREE_STORED ) ; exports ( ) ; if ( textStored != null && ! "<STR_LIT>" . equals ( textStored ) ) { ut = new UserTrees ( parseJson ( textStored ) , LOADED , "<STR_LIT>" ) ; return ut ; } ut = new UserTrees ( null , NOT_LOADED , "<STR_LIT>" ) ; return ut ; } public static void refreshTrees ( boolean force ) { if ( requestTreesRunning ) { return ; } if ( ! force && new Date ( ) . getTime ( ) - lastRequestTreesReceived . getTime ( ) < <NUM_LIT> ) { return ; } requestTrees ( ) ; } private static void requestTrees ( ) { requestTreesRunning = true ; String service = WebContent . getCollectorUrl ( ) + "<STR_LIT>" ; RequestBuilder builder = new RequestBuilder ( RequestBuilder . GET , service ) ; try { builder . sendRequest ( null , new RequestCallback ( ) { @ Override public void onError ( Request request , Throwable exception ) { requestTreesRunning = false ; UserTrees ut = new UserTrees ( null , ERROR , Alerts . getUserMessage ( exception ) ) ; lastRequestTreesReceived = new Date ( ) ; setUserTrees ( ut . getData ( ) ) ; } @ Override public void onResponseReceived ( Request request , Response response ) { requestTreesRunning = false ; setUserTrees ( onTreesReceived ( response . getStatusCode ( ) , response . getText ( ) ) . getData ( ) ) ; } } ) ; } catch ( Exception e ) { requestTreesRunning = false ; UserTrees ut = new UserTrees ( null , ERROR , Alerts . getUserMessage ( e ) ) ; setUserTrees ( ut . getData ( ) ) ; } } public static UserTrees onTreesReceived ( int statusCode , String text ) { UserTrees ut ; if ( statusCode == Response . SC_OK ) { if ( text . startsWith ( "<STR_LIT>" ) && text . endsWith ( "<STR_LIT>" ) ) { ut = new UserTrees ( parseJson ( text ) , LOADED , "<STR_LIT>" ) ; setInLocalStorage ( USER_TREE_STORED , text ) ; if ( ut . getTreeCount ( ) < <NUM_LIT:2> ) { ut = new UserTrees ( null , ERROR , Alerts . getUserMessageForMalformed ( ) ) ; } } else { ut = new UserTrees ( null , ERROR , Alerts . getUserMessageForInvalid ( ) ) ; } } else if ( statusCode == Response . SC_SEE_OTHER ) { ut = new UserTrees ( null , LOGOUT , Alerts . getUserMessage ( statusCode ) ) ; } else { ut = new UserTrees ( null , ERROR , Alerts . getUserMessage ( statusCode ) ) ; } lastRequestTreesReceived = new Date ( ) ; return ut ; } public void updateTreeCollapsed ( ArrayList < Integer > treesToClose , ArrayList < Integer > treesToOpen ) { String service = WebContent . getCollectorUrl ( ) + "<STR_LIT>" ; String requestData = "<STR_LIT>" ; for ( int index : treesToClose ) { setTreeCollapsed ( index , <NUM_LIT:1> ) ; requestData += "<STR_LIT>" + getTreeId ( index ) + "<STR_LIT>" ; } for ( int index : treesToOpen ) { setTreeCollapsed ( index , <NUM_LIT:0> ) ; requestData += "<STR_LIT>" + getTreeId ( index ) + "<STR_LIT>" ; } requestData = requestData . substring ( <NUM_LIT:0> , requestData . length ( ) - <NUM_LIT:1> ) ; requestData += "<STR_LIT>" ; RequestBuilder builder = new RequestBuilder ( RequestBuilder . POST , service ) ; try { builder . sendRequest ( requestData , new RequestCallback ( ) { @ Override public void onResponseReceived ( Request request , Response response ) { setInLocalStorage ( USER_TREE_STORED , stringify ( getData ( ) ) ) ; } @ Override public void onError ( Request request , Throwable exception ) { } } ) ; } catch ( Exception e ) { } } static native String stringify ( JavaScriptObject jsut ) ; static native void setUserTrees ( JavaScriptObject jsut ) ; static native JavaScriptObject parseJson ( String json ) ; public static native String getInLocalStorage ( String key ) ; public static native void setInLocalStorage ( String key , String value ) ; public boolean hasChanged ( UserTrees n ) { if ( getStatus ( ) != n . getStatus ( ) ) { return true ; } if ( ! getMessage ( ) . equals ( n . getMessage ( ) ) ) { return true ; } if ( getStatus ( ) != LOADED ) { return false ; } int i = getTreeCount ( ) ; if ( i != n . getTreeCount ( ) ) { return true ; } for ( ; i -- > <NUM_LIT:0> ; ) { if ( ! getTreeId ( i ) . equals ( n . getTreeId ( i ) ) ) { return true ; } if ( ! getTreeAssoId ( i ) . equals ( n . getTreeAssoId ( i ) ) ) { return true ; } if ( ! getTreeTitle ( i ) . equals ( n . getTreeTitle ( i ) ) ) { return true ; } if ( getTreeDepth ( i ) != n . getTreeDepth ( i ) ) { return true ; } if ( isTreeFull ( i ) != n . isTreeFull ( i ) ) { return true ; } } return false ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; import java . util . * ; public class TreeNode { private TreeListItem treeListItem ; private TreeNode parent ; private ArrayList < TreeNode > children ; public TreeNode ( TreeNode parent ) { super ( ) ; this . parent = parent ; } public TreeListItem getTreeListItem ( ) { return treeListItem ; } public void setTreeListItem ( TreeListItem treeListItem ) { this . treeListItem = treeListItem ; } public TreeNode getParent ( ) { return parent ; } public void setParent ( TreeNode parent ) { this . parent = parent ; } public ArrayList < TreeNode > getChildren ( ) { return children ; } public void addChild ( TreeNode child ) { if ( children == null ) { children = new ArrayList < TreeNode > ( ) ; } children . add ( child ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . common ; import com . google . gwt . core . client . * ; import com . google . gwt . http . client . * ; import com . google . gwt . user . client . * ; public class Alerts { public static void alert ( String arg ) { Window . alert ( arg ) ; } public static native void log ( String arg ) ; public static native void closeWindow ( ) ; public static native int getTabId ( JavaScriptObject tab ) ; public static String getUserMessage ( Throwable e ) { return getUserMessage ( <NUM_LIT:0> ) ; } public static String getUserMessage ( int statusCode ) { if ( statusCode == Response . SC_SERVICE_UNAVAILABLE ) { return "<STR_LIT>" ; } if ( statusCode == Response . SC_SEE_OTHER ) { return "<STR_LIT>" ; } return "<STR_LIT>" ; } public static String getUserMessageForInvalid ( ) { return "<STR_LIT>" ; } public static String getUserMessageForMalformed ( ) { return "<STR_LIT>" ; } public static native void setButtonIcon ( boolean forceGo , boolean startAnim ) ; public static String escapeHtml ( String maybeHtml ) { final Element div = DOM . createDiv ( ) ; DOM . setInnerText ( div , maybeHtml ) ; return DOM . getInnerHTML ( div ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . background ; import java . util . * ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . google . gwt . core . client . * ; public class BrowserTab { private static final Map < Integer , BrowserTab > tabs = new LinkedHashMap < Integer , BrowserTab > ( ) ; private int id ; private Date creation ; private String url ; static void init ( ) { exports ( ) ; } private static BrowserTab getById ( Integer id ) { BrowserTab t = tabs . get ( id ) ; if ( t == null ) { t = new BrowserTab ( ) ; t . id = id ; t . creation = new Date ( ) ; tabs . put ( id , t ) ; } return t ; } static BrowserTab getPearltreesTab ( ) { for ( BrowserTab t : tabs . values ( ) ) { if ( WebContent . isInPearltrees ( t . getUrl ( ) ) ) { return t ; } } return null ; } int getId ( ) { return id ; } String getUrl ( ) { return url ; } static void onRemoved ( int tabId ) { tabs . remove ( tabId ) ; } static void setCurrentTab ( boolean isSelection , int tabId , String url , JavaScriptObject tab ) { BrowserTab t = getById ( tabId ) ; t . url = url ; AppState . isWebUrl = WebContent . isWebUrl ( url ) ; AppState . isInPearltrees = AppState . isWebUrl && WebContent . isInPearltrees ( url ) ; MainButton . setIcon ( false , false ) ; if ( isSelection && AppState . isInPearltrees && AppState . getSelectedTree ( ) != null && AppState . lastPearled != null && t . creation . before ( AppState . lastPearled ) ) { AppState . reveal ( AppState . getSelectedTree ( ) , AppState . getSelectedAsso ( ) , tabId , url ) ; } else if ( AppState . isInPearltrees ) { String tree = WebContent . getCurrentTree ( url ) ; if ( tree != null ) { AppState . setSelectedTree ( tree , "<STR_LIT>" ) ; } } } private static native void exports ( ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . background ; import com . google . gwt . core . client . * ; public class BackgroundMain implements EntryPoint { @ Override public void onModuleLoad ( ) { AppState . init ( ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . background ; import com . google . gwt . user . client . * ; public class MainButton { private static boolean go = false ; private static int animPhase = <NUM_LIT:0> ; private static String currentIcon = null ; static void init ( ) { exports ( ) ; } static void nextPhase ( ) { animPhase ++ ; switch ( animPhase ) { case <NUM_LIT:1> : case <NUM_LIT:7> : setIcon ( "<STR_LIT>" ) ; break ; case <NUM_LIT:2> : case <NUM_LIT:6> : setIcon ( "<STR_LIT>" ) ; break ; case <NUM_LIT:3> : case <NUM_LIT:5> : setIcon ( "<STR_LIT>" ) ; break ; case <NUM_LIT:4> : setIcon ( "<STR_LIT>" ) ; break ; default : animPhase = <NUM_LIT:0> ; } if ( animPhase == <NUM_LIT:0> ) { setIcon ( go , false ) ; } else { Timer t = new Timer ( ) { @ Override public void run ( ) { nextPhase ( ) ; } } ; t . schedule ( <NUM_LIT> ) ; } } static void setIcon ( boolean forceGo , boolean startAnim ) { go = forceGo ; if ( animPhase == <NUM_LIT:0> ) { if ( startAnim ) { nextPhase ( ) ; } else { setIcon ( forceGo || ! AppState . isPearlable ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; } } } private static void setIcon ( String name ) { if ( ! name . equals ( currentIcon ) ) { setBrowserActionIcon ( "<STR_LIT>" + name + "<STR_LIT>" ) ; currentIcon = name ; } } private static native void setBrowserActionIcon ( String iconPath ) ; private static native void exports ( ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . background ; import java . util . * ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . common . AppClient . PearlClient ; import com . google . gwt . core . client . * ; public class AppState { private static final String HAS_RUN_FIRST_TIME_KEY = "<STR_LIT>" ; private static final String HAS_AUTH_FIRST_TIME_KEY = "<STR_LIT>" ; private static UserTrees userTrees ; static Date lastPearled = null ; static boolean hasRevealed = false ; private static String selectedTree = null ; private static String selectedAsso = null ; static boolean isWebUrl ; static boolean isInPearltrees ; static void init ( ) { exports ( ) ; BrowserTab . init ( ) ; MainButton . init ( ) ; userTrees = UserTrees . init ( ) ; UserTrees . refreshTrees ( false ) ; checkFirstRun ( ) ; } static void setUserTrees ( JavaScriptObject jsut ) { UserTrees ut = new UserTrees ( jsut ) ; boolean hasChanged = userTrees . hasChanged ( ut ) ; userTrees = ut ; if ( hasChanged || getInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY ) == null ) { if ( userTrees . getStatus ( ) == UserTrees . LOADED ) { onPopupRefresh ( true ) ; } onUserTreesChanged ( ) ; } } private static native void onUserTreesChanged ( ) ; static JavaScriptObject getUserTreesData ( ) { return userTrees . getData ( ) ; } static String getSelectedTree ( ) { return selectedTree ; } static String getSelectedAsso ( ) { return selectedAsso ; } static void setSelectedTree ( String id , String assoId ) { selectedTree = id ; selectedAsso = assoId ; } static void openInNewTab ( String href ) { hasRevealed |= WebContent . isInPearltrees ( href ) ; createTab ( href ) ; } static void reveal ( String treeId , String assoId , int tabId , String url ) { hasRevealed = true ; lastPearled = null ; String hash = AppClient . buildRevealHash ( userTrees , treeId , assoId ) ; if ( WebContent . isInPearltrees ( url ) ) { if ( hash != null ) { navigateTo ( tabId , WebContent . getUnanchoredUrl ( url ) + '<CHAR_LIT>' + hash ) ; } return ; } BrowserTab t = BrowserTab . getPearltreesTab ( ) ; if ( t == null ) { createTab ( WebContent . getPearltreesUrl ( ) + ( hash == null ? "<STR_LIT>" : '<CHAR_LIT>' + hash ) ) ; return ; } navigateTo ( t . getId ( ) , hash == null ? null : WebContent . getUnanchoredUrl ( t . getUrl ( ) ) + '<CHAR_LIT>' + hash ) ; } static void goToAccountSync ( int tabId , String url ) { if ( WebContent . isInPearltrees ( url ) ) { navigateTo ( tabId , WebContent . getUnanchoredUrl ( url ) + "<STR_LIT>" ) ; return ; } BrowserTab t = BrowserTab . getPearltreesTab ( ) ; if ( t == null ) { createTab ( WebContent . getPearltreesUrl ( ) + "<STR_LIT>" ) ; return ; } navigateTo ( t . getId ( ) , WebContent . getUnanchoredUrl ( t . getUrl ( ) ) + "<STR_LIT>" ) ; } private static native void navigateTo ( int tabId , String toUrl ) ; private static native void createTab ( String toUrl ) ; static void pearlContent ( int tab , String url , String title , String treeId , String parentTreeId , String newTreeName ) { lastPearled = new Date ( ) ; AppClient . pearlContent ( url , title , treeId , parentTreeId , newTreeName , new PearlClient ( ) { @ Override public boolean resetRevealed ( ) { if ( hasRevealed ) { hasRevealed = false ; return true ; } return false ; } @ Override public void onError ( String msg ) { Alerts . alert ( msg ) ; } @ Override public void onPearled ( String newTreeId ) { if ( newTreeId != null ) { setSelectedTree ( newTreeId , "<STR_LIT>" ) ; UserTrees . refreshTrees ( true ) ; } } } ) ; } static boolean isPearlable ( ) { return isWebUrl && ! isInPearltrees ; } private static native String getInLocalStorage ( String key ) ; private static native void setInLocalStorage ( String key , String value ) ; static void onPopupRefresh ( boolean login ) { if ( getInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY ) == null ) { if ( login ) { setInLocalStorage ( HAS_AUTH_FIRST_TIME_KEY , "<STR_LIT:1>" ) ; return ; } } } private static void checkFirstRun ( ) { if ( getInLocalStorage ( HAS_RUN_FIRST_TIME_KEY ) == null ) { setInLocalStorage ( HAS_RUN_FIRST_TIME_KEY , "<STR_LIT:1>" ) ; openCreateAccount ( ) ; } } private static void openCreateAccount ( ) { AppState . createTab ( WebContent . getPearltreesUrl ( ) + "<STR_LIT>" ) ; } private static native void exports ( ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import java . util . * ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . common . WebContent . * ; import com . google . gwt . event . logical . shared . * ; import com . google . gwt . user . client . * ; import com . google . gwt . user . client . ui . * ; public class PopupControl { private static UserTrees userTrees ; public static boolean panelScrollableExist ; public static int height ; public static int width ; private static PopupUIs currentUI = PopupUIs . Loading ; public static enum PopupUIs { Error , Loading , Login , LoginFailed , LoginSuccessfull , InTunnel , InSettings , InBookmarkletTunnel , TreeList , NewTree , ChooseParent , Pearled , PearledDirectly , TreeCreated , BackToList } public static void newScroll ( String id ) { setNewScroll ( id ) ; } public static void refreshScroll ( ) { refresh ( ) ; } public static void onModuleLoad ( ) { Window . addCloseHandler ( new CloseHandler < Window > ( ) { @ Override public void onClose ( CloseEvent < Window > event ) { Alerts . setButtonIcon ( false , false ) ; } } ) ; exports ( ) ; userTrees = new UserTrees ( UserTrees . getUserTreesData ( ) ) ; UserTrees . backgroundRefreshTrees ( true ) ; if ( ! WebContent . onIpad ) { retrieveSize ( ) ; } else { retrieveSizeForIpad ( ) ; } if ( WebContent . bookmarklet ) { getFirstDetails ( ) ; PearltreesState s = WebContent . getPearltreesState ( TreeListUI . currentUrl ) ; if ( s == PearltreesState . Settings ) { PopupControl . changeUI ( PopupUIs . InSettings ) ; return ; } else if ( s == PearltreesState . Tunnel || s == PearltreesState . GetStarted ) { PopupControl . changeUI ( PopupUIs . InTunnel ) ; return ; } else if ( s == PearltreesState . BookmarkletTunnel ) { PopupControl . changeUI ( PopupUIs . InBookmarkletTunnel ) ; return ; } } makeUI ( false ) ; } public static void changeUI ( PopupUIs ui ) { changeUI ( ui , false ) ; } public static void changeUI ( PopupUIs ui , boolean dueToTreesChange ) { cleanUI ( ) ; currentUI = ui ; makeUI ( dueToTreesChange ) ; } private static void cleanUI ( ) { RootPanel . get ( ) . clear ( ) ; } public static void onResize ( ) { boolean noGoBackBar = ( TreeListUI . chooseParent || TreeListUI . goDirectly ) ; resize ( noGoBackBar , PopupControl . panelScrollableExist ) ; } private static void makeUI ( boolean dueToTreesChange ) { if ( currentUI == PopupUIs . InTunnel || currentUI == PopupUIs . InSettings || currentUI == PopupUIs . InBookmarkletTunnel ) { InactiveUI . init ( RootPanel . get ( ) , currentUI ) ; return ; } if ( currentUI == PopupUIs . Pearled && TreeListUI . PearledDirect ) { PearledUI . init ( RootPanel . get ( ) , false , TreeListUI . isPearlable ) ; return ; } switch ( userTrees . getStatus ( ) ) { case UserTrees . NOT_LOADED : currentUI = PopupUIs . Loading ; if ( WebContent . onIpad ) { LoadingUI . init ( RootPanel . get ( ) , userTrees ) ; } break ; case UserTrees . LOADED : onPopupRefresh ( true ) ; switch ( currentUI ) { case NewTree : NewTreeUI . init ( RootPanel . get ( ) ) ; break ; case TreeCreated : if ( WebContent . bookmarklet ) { PearledUI . init ( RootPanel . get ( ) , true , TreeListUI . isPearlable ) ; } else { TreeCreatedUI . init ( RootPanel . get ( ) ) ; } break ; case Pearled : PearledUI . init ( RootPanel . get ( ) , false , TreeListUI . isPearlable ) ; break ; case ChooseParent : TreeListUI . chooseParent = true ; TreeListUI . init ( RootPanel . get ( ) , userTrees ) ; break ; default : TreeListUI . chooseParent = false ; currentUI = PopupUIs . TreeList ; TreeListUI . init ( RootPanel . get ( ) , userTrees ) ; } break ; case UserTrees . LOGOUT : if ( dueToTreesChange ) { onPopupRefresh ( false ) ; } if ( currentUI == PopupUIs . LoginFailed ) { LoginFailedUI . init ( RootPanel . get ( ) ) ; } else if ( currentUI == PopupUIs . LoginSuccessfull && WebContent . onIpad ) { LoadingUI . init ( RootPanel . get ( ) , userTrees ) ; } else { if ( ! WebContent . cookieEnabled && WebContent . onIpad ) { currentUI = PopupUIs . Error ; ErrorUI . init ( RootPanel . get ( ) , userTrees ) ; } else { currentUI = PopupUIs . Login ; LoginUI . init ( RootPanel . get ( ) , userTrees ) ; } } break ; default : currentUI = PopupUIs . Error ; ErrorUI . init ( RootPanel . get ( ) , userTrees ) ; } } public static void onUserTreesChanged ( ) { userTrees = new UserTrees ( UserTrees . getUserTreesData ( ) ) ; if ( userTrees . getStatus ( ) == UserTrees . LOADED ) { switch ( currentUI ) { case NewTree : case TreeCreated : case Pearled : case InTunnel : case InSettings : return ; case TreeList : case ChooseParent : if ( TreeListUI . isClosing ) { return ; } break ; } } changeUI ( currentUI , true ) ; } static void onViewCreated ( ) { Iterator < Widget > it = RootPanel . get ( ) . iterator ( ) ; if ( it . hasNext ( ) ) { it . next ( ) ; while ( it . hasNext ( ) ) { it . next ( ) ; it . remove ( ) ; } } Alerts . setButtonIcon ( currentUI == PopupUIs . TreeList && TreeListUI . isGoMode ( ) , false ) ; } public static void onFirstDetails ( String url , String title ) { TreeListUI . currentUrl = url ; TreeListUI . currentTitle = title ; } public static native void getFirstDetails ( ) ; static void onSize ( int h , int w ) { if ( ! WebContent . onIpad ) { RootPanel . get ( ) . setHeight ( h + "<STR_LIT>" ) ; if ( WebContent . bookmarklet ) { RootPanel . get ( ) . setWidth ( "<STR_LIT>" ) ; } else { RootPanel . get ( ) . setWidth ( w + "<STR_LIT>" ) ; } height = h ; width = w ; } } public static native void setNewScroll ( String id ) ; private static native void refresh ( ) ; private static native void onPopupRefresh ( boolean login ) ; private static native void retrieveSize ( ) ; public static native void resize ( boolean noGoBackBar , boolean panelScrollableExist ) ; private static native void retrieveSizeForIpad ( ) ; private static native void exports ( ) ; } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . popup . PopupControl . PopupUIs ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . http . client . * ; import com . google . gwt . user . client . ui . * ; public class LoginUI { private static boolean frozen ; private static String fieldUser = "<STR_LIT>" ; private static String fieldPass = "<STR_LIT>" ; static void init ( Panel parent , UserTrees userTrees ) { frozen = false ; FlowPanel panel = new FlowPanel ( ) ; parent . add ( panel ) ; PopupElements . createCredentials ( panel , userTrees ) ; FlowPanel line = new FlowPanel ( ) ; panel . add ( line ) ; Label userLbl = PopupElements . createLabel ( ) ; userLbl . setText ( "<STR_LIT:username>" ) ; userLbl . addStyleDependentName ( PopupElements . STYLE_PADDING ) ; userLbl . addStyleDependentName ( PopupElements . STYLE_LOGIN ) ; FlowPanel userPanel = new FlowPanel ( ) ; userPanel . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_INPUT ) ; PopupElements . setMarginBottom ( userPanel , <NUM_LIT:15> ) ; Label passLbl = PopupElements . createLabel ( ) ; passLbl . setText ( "<STR_LIT:password>" ) ; passLbl . addStyleDependentName ( PopupElements . STYLE_PADDING ) ; passLbl . addStyleDependentName ( PopupElements . STYLE_LOGIN ) ; FlowPanel passPanel = new FlowPanel ( ) ; passPanel . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_INPUT ) ; PopupElements . setMarginBottom ( passPanel , <NUM_LIT:15> ) ; FlowPanel buttons = new FlowPanel ( ) ; final TextBox userBox = PopupElements . createTextBox ( ) ; userPanel . add ( userBox ) ; userBox . setMaxLength ( <NUM_LIT> ) ; userBox . setText ( fieldUser ) ; userBox . setFocus ( true ) ; final PasswordTextBox passBox = PopupElements . createPasswordTextBox ( ) ; passPanel . add ( passBox ) ; passBox . setMaxLength ( <NUM_LIT> ) ; passBox . setText ( fieldPass ) ; passBox . setTabIndex ( <NUM_LIT:1> ) ; if ( ! WebContent . onIpad ) { line . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_TEXT ) ; line . addStyleDependentName ( PopupElements . STYLE_PADDING ) ; InlineLabel l1 = PopupElements . createInlineLabel ( ) ; line . add ( l1 ) ; l1 . setText ( "<STR_LIT>" ) ; l1 . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; InlineLabel create = PopupElements . createInlineLabel ( ) ; line . add ( create ) ; create . setText ( "<STR_LIT>" ) ; create . addStyleDependentName ( PopupElements . STYLE_LINK ) ; create . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { LoginFailedUI . goCreate ( ) ; } } ) ; InlineLabel l2 = PopupElements . createInlineLabel ( ) ; line . add ( l2 ) ; l2 . setText ( "<STR_LIT>" ) ; l2 . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; PopupElements . setMarginBottom ( line , <NUM_LIT> ) ; Label login = PopupElements . createLabel ( ) ; panel . add ( login ) ; login . setText ( "<STR_LIT>" ) ; login . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; login . addStyleDependentName ( PopupElements . STYLE_PADDING ) ; PopupElements . setMarginBottom ( login , <NUM_LIT:10> ) ; panel . add ( userLbl ) ; panel . add ( userPanel ) ; panel . add ( passLbl ) ; panel . add ( passPanel ) ; panel . add ( buttons ) ; Label ok = PopupElements . createLabel ( ) ; buttons . add ( ok ) ; ok . setText ( "<STR_LIT>" ) ; ok . addStyleDependentName ( PopupElements . STYLE_LINKBLACK ) ; ok . addStyleDependentName ( PopupElements . STYLE_RIGHT ) ; ok . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { onValidate ( userBox . getText ( ) , passBox . getText ( ) ) ; } } ) ; } else { PopupElements . createDescription ( panel , line , false , "<STR_LIT>" , false ) ; userBox . addStyleDependentName ( PopupElements . STYLE_LOGIN ) ; passBox . addStyleDependentName ( PopupElements . STYLE_LOGIN ) ; FlowPanel wrapp = new FlowPanel ( ) ; panel . add ( wrapp ) ; wrapp . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_LOGIN_IPAD ) ; wrapp . add ( userLbl ) ; wrapp . add ( userPanel ) ; wrapp . add ( passLbl ) ; wrapp . add ( passPanel ) ; HTML ok = PopupElements . createHtml ( ) ; ok . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_NEWTREE_BUTTONS_IPAD ) ; ok . addStyleDependentName ( PopupElements . STYLE_LOGIN ) ; ok . setHTML ( PopupElements . OK ) ; wrapp . add ( ok ) ; ok . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { onValidate ( userBox . getText ( ) , passBox . getText ( ) ) ; } } ) ; } userBox . addKeyDownHandler ( new KeyDownHandler ( ) { @ Override public void onKeyDown ( KeyDownEvent event ) { if ( event . getNativeKeyCode ( ) == <NUM_LIT> || event . getNativeKeyCode ( ) == <NUM_LIT:9> ) { event . preventDefault ( ) ; passBox . setFocus ( true ) ; } } } ) ; passBox . addKeyDownHandler ( new KeyDownHandler ( ) { @ Override public void onKeyDown ( KeyDownEvent event ) { if ( event . getNativeKeyCode ( ) == <NUM_LIT> ) { onValidate ( userBox . getText ( ) , passBox . getText ( ) ) ; } else if ( event . getNativeKeyCode ( ) == <NUM_LIT:9> && event . isShiftKeyDown ( ) ) { event . preventDefault ( ) ; userBox . setFocus ( true ) ; } } } ) ; PopupControl . onViewCreated ( ) ; } static void onValidate ( String user , String pass ) { if ( frozen ) { return ; } if ( user . isEmpty ( ) || pass . isEmpty ( ) ) { return ; } fieldUser = user ; fieldPass = pass ; frozen = true ; sendLogin ( fieldUser , fieldPass ) ; } static void loginError ( String msg ) { failedLogin ( ) ; } static void successfulLogin ( ) { if ( WebContent . onIpad ) { PopupControl . changeUI ( PopupUIs . LoginSuccessfull ) ; PopupControl . onModuleLoad ( ) ; } else { UserTrees . backgroundRefreshTrees ( true ) ; } } static void failedLogin ( ) { PopupControl . changeUI ( PopupUIs . LoginFailed ) ; } static void sendLogin ( String fieldUser , String fieldPass ) { String service = WebContent . getCollectorUrl ( ) + "<STR_LIT>" ; String requestData = "<STR_LIT>" + URL . encodeComponent ( fieldUser ) + "<STR_LIT>" + URL . encodeComponent ( fieldPass ) ; RequestBuilder builder = new RequestBuilder ( RequestBuilder . POST , service ) ; builder . setHeader ( "<STR_LIT>" , "<STR_LIT>" ) ; try { builder . sendRequest ( requestData , new RequestCallback ( ) { @ Override public void onError ( Request request , Throwable exception ) { loginError ( Alerts . getUserMessage ( exception ) ) ; } @ Override public void onResponseReceived ( Request request , Response response ) { if ( response . getStatusCode ( ) == Response . SC_OK ) { if ( response . getText ( ) . equals ( "<STR_LIT:0>" ) ) { successfulLogin ( ) ; } else if ( response . getText ( ) . equals ( "<STR_LIT:1>" ) ) { failedLogin ( ) ; } else { loginError ( Alerts . getUserMessageForMalformed ( ) ) ; } } else { loginError ( Alerts . getUserMessage ( response . getStatusCode ( ) ) ) ; } } } ) ; } catch ( Exception e ) { loginError ( Alerts . getUserMessage ( e ) ) ; } } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . user . client . * ; import com . google . gwt . user . client . ui . * ; public class ErrorUI { static void init ( Panel parent , UserTrees userTrees ) { if ( ! WebContent . onIpad ) { FlowPanel panel = new FlowPanel ( ) ; FocusPanel focus = new FocusPanel ( panel ) ; parent . add ( focus ) ; focus . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_FOCUS ) ; focus . setFocus ( true ) ; Label title = PopupElements . createLabel ( ) ; panel . add ( title ) ; title . setText ( "<STR_LIT>" ) ; title . addStyleDependentName ( PopupElements . STYLE_BLUEBOLD ) ; PopupElements . setMarginBottom ( title , <NUM_LIT:20> ) ; Label message = PopupElements . createLabel ( ) ; panel . add ( message ) ; message . setText ( userTrees . getMessage ( ) ) ; message . addStyleDependentName ( PopupElements . STYLE_ERROR ) ; PopupElements . setMarginBottom ( message , <NUM_LIT:20> ) ; FlowPanel buttons = new FlowPanel ( ) ; panel . add ( buttons ) ; Label ok = PopupElements . createLabel ( ) ; buttons . add ( ok ) ; ok . setText ( "<STR_LIT>" ) ; ok . addStyleDependentName ( PopupElements . STYLE_LINK ) ; ok . addStyleDependentName ( PopupElements . STYLE_RIGHT ) ; focus . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { Alerts . closeWindow ( ) ; } } ) ; focus . addKeyPressHandler ( new KeyPressHandler ( ) { @ Override public void onKeyPress ( KeyPressEvent event ) { Alerts . closeWindow ( ) ; } } ) ; focus . addBlurHandler ( new BlurHandler ( ) { @ Override public void onBlur ( BlurEvent event ) { Alerts . closeWindow ( ) ; } } ) ; } else { PopupControl . panelScrollableExist = false ; parent . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_NONSCROLLABLE ) ; DOM . setElementAttribute ( parent . getElement ( ) , "<STR_LIT:id>" , "<STR_LIT>" ) ; FlowPanel description = new FlowPanel ( ) ; PopupElements . createDescription ( parent , description , false , userTrees . getMessage ( ) , false ) ; FlowPanel panelError = new FlowPanel ( ) ; parent . add ( panelError ) ; if ( ( "<STR_LIT>" ) . equals ( userTrees . getMessage ( ) ) ) { HTML errorBox = PopupElements . createHtml ( ) ; errorBox . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_CENTERED ) ; errorBox . setHTML ( PopupElements . COOKIES ) ; } FlowPanel scroller = new FlowPanel ( ) ; panelError . add ( scroller ) ; DOM . setElementAttribute ( panelError . getElement ( ) , "<STR_LIT:id>" , "<STR_LIT>" ) ; DOM . setElementAttribute ( scroller . getElement ( ) , "<STR_LIT:id>" , "<STR_LIT>" ) ; PopupControl . onResize ( ) ; PopupElements . createGoBackToApp ( parent , true ) ; } PopupControl . onViewCreated ( ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . popup . PopupControl . PopupUIs ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . user . client . ui . * ; public class NewTreeUI { static String newTreeTitle ; static void init ( Panel parent ) { PopupControl . panelScrollableExist = false ; FlowPanel panel = new FlowPanel ( ) ; parent . add ( panel ) ; if ( WebContent . onIpad ) { panel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; } FlowPanel description = new FlowPanel ( ) ; panel . add ( description ) ; HTML header = PopupElements . createHtml ( ) ; panel . add ( header ) ; if ( ! WebContent . onIpad ) { header . setHTML ( PopupElements . DOWN_TRIANGLE + "<STR_LIT>" ) ; header . addStyleDependentName ( PopupElements . STYLE_LINK ) ; PopupElements . setMarginBottom ( header , <NUM_LIT:5> ) ; } else { PopupElements . createDescription ( panel , description , false , "<STR_LIT>" , false ) ; Label backToList = PopupElements . createLabel ( ) ; description . add ( backToList ) ; backToList . setText ( "<STR_LIT>" ) ; backToList . addStyleDependentName ( PopupElements . STYLE_TREETITLE ) ; backToList . addStyleDependentName ( PopupElements . STYLE_BACKTOLIST ) ; backToList . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onBackToList ( ) ; } } ) ; } FlowPanel newTreePanel = new FlowPanel ( ) ; newTreePanel . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_INPUT ) ; final TextBox name = PopupElements . createTextBox ( ) ; name . setMaxLength ( <NUM_LIT> ) ; name . addStyleDependentName ( PopupElements . STYLE_NEWFIELD ) ; name . addStyleDependentName ( PopupElements . STYLE_INPUTBOX_DEFAULT ) ; name . addFocusHandler ( new FocusHandler ( ) { @ Override public void onFocus ( FocusEvent event ) { if ( "<STR_LIT>" . equals ( name . getText ( ) ) ) { name . setText ( "<STR_LIT>" ) ; name . removeStyleDependentName ( PopupElements . STYLE_INPUTBOX_DEFAULT ) ; } } } ) ; if ( WebContent . onIpad ) { FlowPanel newTreePanelBox = new FlowPanel ( ) ; newTreePanelBox . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_INPUTBOX_IPAD ) ; panel . add ( newTreePanelBox ) ; newTreePanel . addStyleDependentName ( PopupElements . STYLE_INPUT_IPAD ) ; newTreePanelBox . add ( newTreePanel ) ; name . setText ( "<STR_LIT>" ) ; newTreePanel . add ( name ) ; HTML ok = PopupElements . createHtml ( ) ; ok . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_NEWTREE_BUTTONS_IPAD ) ; ok . setHTML ( PopupElements . OK ) ; newTreePanelBox . add ( ok ) ; ok . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { onValidate ( name ) ; } } ) ; } else { panel . add ( newTreePanel ) ; newTreePanel . add ( name ) ; } name . addKeyPressHandler ( new KeyPressHandler ( ) { @ Override public void onKeyPress ( KeyPressEvent event ) { if ( event . getCharCode ( ) == <NUM_LIT> ) { onValidate ( name ) ; } } } ) ; header . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { onValidate ( name ) ; } } ) ; PopupElements . setMarginBottom ( header , <NUM_LIT:5> ) ; if ( ! WebContent . onIpad ) { FlowPanel buttons = new FlowPanel ( ) ; panel . add ( buttons ) ; Label cancel = PopupElements . createLabel ( ) ; newTreePanel . add ( cancel ) ; cancel . setText ( "<STR_LIT>" ) ; cancel . addStyleDependentName ( PopupElements . STYLE_THINLINK ) ; cancel . addStyleDependentName ( PopupElements . STYLE_LEFT ) ; cancel . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { Alerts . closeWindow ( ) ; } } ) ; Label ok = PopupElements . createLabel ( ) ; buttons . add ( ok ) ; ok . setText ( "<STR_LIT>" ) ; ok . addStyleDependentName ( PopupElements . STYLE_LINK ) ; ok . addStyleDependentName ( PopupElements . STYLE_RIGHT ) ; ok . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { onValidate ( name ) ; } } ) ; } if ( ! WebContent . onIpad ) { name . setFocus ( true ) ; } PopupControl . onViewCreated ( ) ; } static void onValidate ( TextBox name ) { newTreeTitle = name . getText ( ) . trim ( ) ; if ( newTreeTitle . isEmpty ( ) ) { if ( WebContent . onIpad ) { name . setText ( "<STR_LIT>" ) ; name . addStyleDependentName ( PopupElements . STYLE_INPUTBOX_DEFAULT ) ; } return ; } PopupControl . changeUI ( PopupUIs . ChooseParent ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . popup . PopupControl . * ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . user . client . * ; import com . google . gwt . user . client . ui . * ; public class LoginFailedUI { static void init ( Panel parent ) { FlowPanel panel = new FlowPanel ( ) ; parent . add ( panel ) ; InlineLabel l2 = PopupElements . createInlineLabel ( ) ; l2 . setText ( "<STR_LIT>" ) ; l2 . addStyleDependentName ( PopupElements . STYLE_NOPADDINGRIGHT ) ; InlineLabel log = PopupElements . createInlineLabel ( ) ; log . setText ( "<STR_LIT>" ) ; log . addStyleDependentName ( PopupElements . STYLE_LINK ) ; log . addStyleDependentName ( PopupElements . STYLE_NOPADDINGLEFT ) ; log . addStyleDependentName ( PopupElements . STYLE_NOPADDINGRIGHT ) ; log . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { PopupControl . changeUI ( PopupUIs . Login ) ; } } ) ; InlineLabel l3 = PopupElements . createInlineLabel ( ) ; l3 . setText ( "<STR_LIT>" ) ; l3 . addStyleDependentName ( PopupElements . STYLE_NOPADDINGLEFT ) ; l3 . addStyleDependentName ( PopupElements . STYLE_NOPADDINGRIGHT ) ; InlineLabel create = PopupElements . createInlineLabel ( ) ; create . setText ( "<STR_LIT>" ) ; create . addStyleDependentName ( PopupElements . STYLE_LINK ) ; create . addStyleDependentName ( PopupElements . STYLE_NOPADDINGLEFT ) ; create . addStyleDependentName ( PopupElements . STYLE_NOPADDINGRIGHT ) ; create . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { goCreate ( ) ; } } ) ; if ( ! WebContent . onIpad ) { Label l1 = PopupElements . createLabel ( ) ; panel . add ( l1 ) ; l1 . setText ( "<STR_LIT>" ) ; l1 . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; PopupElements . setMarginBottom ( l1 , <NUM_LIT:15> ) ; l2 . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; panel . add ( l2 ) ; panel . add ( log ) ; l3 . addStyleDependentName ( PopupElements . STYLE_BOLD ) ; panel . add ( l3 ) ; panel . add ( create ) ; } else { FlowPanel line = new FlowPanel ( ) ; panel . add ( line ) ; PopupElements . createDescription ( panel , line , false , "<STR_LIT>" , false ) ; FlowPanel wrapp = new FlowPanel ( ) ; panel . add ( wrapp ) ; wrapp . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_LOGIN_IPAD ) ; wrapp . addStyleDependentName ( PopupElements . STYLE_GREY ) ; wrapp . add ( l2 ) ; wrapp . add ( log ) ; wrapp . add ( l3 ) ; wrapp . add ( create ) ; } PopupControl . onViewCreated ( ) ; } static void goCreate ( ) { if ( ! WebContent . onIpad ) { WebContent . openInNewTab ( WebContent . getCollectorUrl ( ) + "<STR_LIT>" ) ; Alerts . closeWindow ( ) ; } else { TreeListUI . goBackToPT ( null ) ; Timer t = new Timer ( ) { @ Override public void run ( ) { Alerts . closeWindow ( ) ; } } ; t . schedule ( <NUM_LIT:1000> ) ; PopupControl . onViewCreated ( ) ; } } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . broceliand . pearlbar . chrome . client . popup . PopupControl . * ; import com . google . gwt . dom . client . Style . * ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . user . client . * ; import com . google . gwt . user . client . ui . * ; public class PopupElements { static final String RIGHT_TRIANGLE ; static final String DOWN_TRIANGLE ; static final String AVATAR_CACHE ; static final String PUZZLE ; static final String DROPZONE ; static final String NEW_PEARLTREE ; static final String DESCRIPTION ; static final String GOBACK ; static final String OK ; static final String TEXTBOX ; static final String LOADINGMESSAGE ; static final String BUTTON_GO_TO_APP ; static final String COOKIES ; static final String PEARLED ; static final String PRELOADED_PEARLED ; static final String PRIMARY_STYLE_TEXT = "<STR_LIT>" ; static final String PRIMARY_STYLE_AVATARBOX = "<STR_LIT>" ; static final String PRIMARY_STYLE_TEXTBOX = "<STR_LIT>" ; static final String PRIMARY_STYLE_INPUT = "<STR_LIT>" ; static final String PRIMARY_STYLE_INDENTBLOCK = "<STR_LIT>" ; static final String PRIMARY_STYLE_FOCUS = "<STR_LIT>" ; static final String PRIMARY_STYLE_TREELIST = "<STR_LIT>" ; static final String PRIMARY_STYLE_TREENODEPANEL = "<STR_LIT>" ; static final String PRIMARY_STYLE_CHILDRENPANEL = "<STR_LIT>" ; static final String PRIMARY_STYLE_FLOATWRAPPER = "<STR_LIT>" ; static final String PRIMARY_STYLE_DESCRIPTION = "<STR_LIT>" ; static final String PRIMARY_STYLE_NEWPEARLTREE = "<STR_LIT>" ; static final String PRIMARY_STYLE_NONSCROLLABLE = "<STR_LIT>" ; static final String PRIMARY_STYLE_SCROLLABLE = "<STR_LIT>" ; static final String PRIMARY_STYLE_NEWTREE_BUTTONS_IPAD = "<STR_LIT>" ; static final String PRIMARY_STYLE_INPUTBOX_IPAD = "<STR_LIT>" ; static final String PRIMARY_STYLE_LOGIN_IPAD = "<STR_LIT>" ; static final String PRIMARY_STYLE_INVISIBLE = "<STR_LIT>" ; static final String PRIMARY_STYLE_CENTERED = "<STR_LIT>" ; static final String PRIMARY_STYLE_PEARLED_IPAD = "<STR_LIT>" ; static final String STYLE_GREY = "<STR_LIT>" ; static final String STYLE_REALLY_UNDER_MESSAGE = "<STR_LIT>" ; static final String STYLE_UNDER_MESSAGE = "<STR_LIT>" ; static final String STYLE_DESCRIPTION_UP = "<STR_LIT>" ; static final String STYLE_DESCRIPTION_DOWN = "<STR_LIT>" ; static final String STYLE_LIST_REVEALED = "<STR_LIT>" ; static final String STYLE_LIST_COLLAPSED = "<STR_LIT>" ; static final String STYLE_PADDING = "<STR_LIT>" ; static final String STYLE_SPECIAL_PADDING = "<STR_LIT>" ; static final String STYLE_NEW_PEARLTREE = "<STR_LIT>" ; static final String STYLE_NOPADDINGLEFT = "<STR_LIT>" ; static final String STYLE_NOPADDINGRIGHT = "<STR_LIT>" ; static final String STYLE_ITEM = "<STR_LIT>" ; static final String STYLE_ESCAPE = "<STR_LIT>" ; static final String STYLE_BACKTOLIST = "<STR_LIT>" ; static final String STYLE_SELECTABLE = "<STR_LIT>" ; static final String STYLE_SELECTBOX_IPAD = "<STR_LIT>" ; static final String STYLE_SELECTED = "<STR_LIT>" ; static final String STYLE_SELECTED_TIMER = "<STR_LIT>" ; static final String STYLE_INACTIVE = "<STR_LIT>" ; static final String STYLE_FULL = "<STR_LIT>" ; static final String STYLE_LINK = "<STR_LIT>" ; static final String STYLE_THINLINK = "<STR_LIT>" ; static final String STYLE_BOLD = "<STR_LIT>" ; static final String STYLE_BLUEBOLD = "<STR_LIT>" ; static final String STYLE_BLUEHOVER = "<STR_LIT>" ; static final String STYLE_LINKBLACK = "<STR_LIT>" ; static final String STYLE_LEFT = "<STR_LIT>" ; static final String STYLE_RIGHT = "<STR_LIT>" ; static final String STYLE_ERROR = "<STR_LIT:error>" ; static final String STYLE_LOGIN = "<STR_LIT>" ; static final String STYLE_NEWFIELD = "<STR_LIT>" ; static final String STYLE_INPUT_IPAD = "<STR_LIT>" ; static final String STYLE_TREETITLE = "<STR_LIT>" ; static final String STYLE_TREEAVATAR = "<STR_LIT>" ; static final String STYLE_DEPTH = "<STR_LIT>" ; static final String STYLE_ARROW = "<STR_LIT>" ; static final String STYLE_NOARROW = "<STR_LIT>" ; static final String STYLE_ARROW_HIGHLIGHT = "<STR_LIT>" ; static final String STYLE_COLLAPSED = "<STR_LIT>" ; static final String STYLE_HUGE = "<STR_LIT>" ; static final String STYLE_SMALL = "<STR_LIT>" ; static final String STYLE_MARGIN = "<STR_LIT>" ; static final String STYLE_FOCUS_IPAD = "<STR_LIT>" ; static final String STYLE_INPUTBOX_DEFAULT = "<STR_LIT:default>" ; static { RIGHT_TRIANGLE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; DOWN_TRIANGLE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; AVATAR_CACHE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; PUZZLE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; DROPZONE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; NEW_PEARLTREE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; DESCRIPTION = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; GOBACK = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; OK = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; TEXTBOX = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; LOADINGMESSAGE = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; BUTTON_GO_TO_APP = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; COOKIES = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; PEARLED = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; PRELOADED_PEARLED = "<STR_LIT>" + getUrl ( "<STR_LIT>" ) + "<STR_LIT>" ; } public static String credentials = "<STR_LIT>" ; static HTML createHtml ( ) { HTML item = new HTML ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXT ) ; return item ; } static Label createLabel ( ) { Label item = new Label ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXT ) ; return item ; } static InlineLabel createInlineLabel ( ) { InlineLabel item = new InlineLabel ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXT ) ; return item ; } static InlineHTML createInlineHTML ( ) { InlineHTML item = new InlineHTML ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXT ) ; return item ; } static TextBox createTextBox ( ) { TextBox item = new TextBox ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXTBOX ) ; if ( WebContent . onIpad ) { item . getElement ( ) . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; item . getElement ( ) . setAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; } return item ; } static PasswordTextBox createPasswordTextBox ( ) { PasswordTextBox item = new PasswordTextBox ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_TEXTBOX ) ; return item ; } static TreeListItem createTreeListItem ( ) { TreeListItem panel = new TreeListItem ( ) ; panel . setStylePrimaryName ( PRIMARY_STYLE_TEXT ) ; return panel ; } static Label createIndentBlock ( ) { Label item = new Label ( ) ; item . setStylePrimaryName ( PRIMARY_STYLE_INDENTBLOCK ) ; return item ; } static void createGoAccount ( Panel panel , boolean active ) { if ( WebContent . onIpad ) { return ; } HTML item = createHtml ( ) ; panel . add ( item ) ; item . setHTML ( RIGHT_TRIANGLE + "<STR_LIT>" ) ; if ( active ) { item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onGoAccount ( ) ; } } ) ; } item . addStyleDependentName ( active ? STYLE_LINK : STYLE_INACTIVE ) ; setMarginBottom ( item , <NUM_LIT:10> ) ; } static void createConnectAccount ( Panel panel ) { if ( WebContent . onIpad ) { return ; } HTML item = createHtml ( ) ; panel . add ( item ) ; item . setHTML ( RIGHT_TRIANGLE + "<STR_LIT>" ) ; item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onGoToSyncAccount ( ) ; } } ) ; item . addStyleDependentName ( STYLE_LINK ) ; setMarginBottom ( item , <NUM_LIT:10> ) ; } static void createSwitchMode ( Panel panel , boolean active , boolean currentIsGoDirectly ) { if ( WebContent . onIpad ) { return ; } HTML item = createHtml ( ) ; panel . add ( item ) ; item . setHTML ( currentIsGoDirectly ? RIGHT_TRIANGLE + "<STR_LIT>" : RIGHT_TRIANGLE + "<STR_LIT>" ) ; if ( active ) { item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onSwichModeClicked ( ) ; } } ) ; } item . addStyleDependentName ( active ? STYLE_LINK : STYLE_INACTIVE ) ; setMarginBottom ( item , <NUM_LIT:10> ) ; } static void createAvatar ( Panel panel ) { InlineHTML item = new InlineHTML ( ) ; panel . add ( item ) ; item . setHTML ( AVATAR_CACHE ) ; } static void createDescription ( Panel panel , final FlowPanel description , boolean active , String label , final boolean begin ) { description . setStylePrimaryName ( PRIMARY_STYLE_DESCRIPTION ) ; description . addStyleDependentName ( STYLE_DESCRIPTION_UP ) ; panel . add ( description ) ; HTML descriptionBox = createHtml ( ) ; descriptionBox . setHTML ( DESCRIPTION ) ; descriptionBox . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_AVATARBOX ) ; descriptionBox . addStyleDependentName ( PopupElements . STYLE_SPECIAL_PADDING ) ; description . add ( descriptionBox ) ; Label item = createLabel ( ) ; description . add ( item ) ; item . setText ( label ) ; item . addStyleDependentName ( STYLE_TREETITLE ) ; item . addStyleDependentName ( STYLE_ITEM ) ; if ( active ) { descriptionBox . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { if ( begin ) { description . addStyleDependentName ( PopupElements . STYLE_SELECTED_TIMER ) ; TreeListUI . onClickedDirectly ( ) ; } else { TreeListUI . onDefaultItemClicked ( ) ; } } } ) ; item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { if ( begin ) { description . addStyleDependentName ( PopupElements . STYLE_SELECTED_TIMER ) ; TreeListUI . onClickedDirectly ( ) ; } else { TreeListUI . onDefaultItemClicked ( ) ; } } } ) ; } } static void createGoBackToApp ( Panel panel , boolean active ) { FlowPanel goBack = new FlowPanel ( ) ; goBack . setStylePrimaryName ( PRIMARY_STYLE_DESCRIPTION ) ; goBack . addStyleDependentName ( STYLE_DESCRIPTION_DOWN ) ; panel . add ( goBack ) ; HTML goBackBox = createHtml ( ) ; goBackBox . setHTML ( GOBACK ) ; goBackBox . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_AVATARBOX ) ; goBackBox . addStyleDependentName ( PopupElements . STYLE_SPECIAL_PADDING ) ; goBack . add ( goBackBox ) ; Label item = createLabel ( ) ; goBack . add ( item ) ; item . setText ( "<STR_LIT>" ) ; item . addStyleDependentName ( STYLE_TREETITLE ) ; item . addStyleDependentName ( STYLE_ITEM ) ; Label escape = createLabel ( ) ; goBack . add ( escape ) ; escape . setText ( "<STR_LIT>" ) ; escape . addStyleDependentName ( STYLE_TREETITLE ) ; escape . addStyleDependentName ( STYLE_ESCAPE ) ; HTML preload = createHtml ( ) ; preload . setHTML ( PRELOADED_PEARLED ) ; goBack . add ( preload ) ; if ( active ) { goBackBox . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onSwichModeClicked ( ) ; } } ) ; item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onSwichModeClicked ( ) ; } } ) ; escape . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onEscapeItemClicked ( ) ; } } ) ; } } static void createDirectAction ( Panel panel , boolean active , boolean currentIsGoDirectly ) { HTML item = createHtml ( ) ; panel . add ( item ) ; item . setHTML ( currentIsGoDirectly ? DOWN_TRIANGLE + "<STR_LIT>" : DOWN_TRIANGLE + "<STR_LIT>" ) ; item . addStyleDependentName ( active ? STYLE_LINK : STYLE_INACTIVE ) ; if ( active ) { item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { TreeListUI . onDefaultItemClicked ( ) ; } } ) ; } setMarginBottom ( item , <NUM_LIT:5> ) ; } static void createNewPearltree ( Panel panel , boolean active ) { final Label item = createLabel ( ) ; final FlowPanel description = new FlowPanel ( ) ; item . setText ( "<STR_LIT>" ) ; if ( WebContent . onIpad ) { description . setStylePrimaryName ( PRIMARY_STYLE_NEWPEARLTREE ) ; panel . add ( description ) ; HTML newPearltreeBox = PopupElements . createHtml ( ) ; newPearltreeBox . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_AVATARBOX ) ; newPearltreeBox . addStyleDependentName ( PopupElements . STYLE_SPECIAL_PADDING ) ; newPearltreeBox . setHTML ( NEW_PEARLTREE ) ; description . add ( newPearltreeBox ) ; description . add ( item ) ; } else { panel . add ( item ) ; } if ( ! WebContent . onIpad ) { item . addStyleDependentName ( STYLE_SELECTABLE ) ; item . addStyleDependentName ( STYLE_BOLD ) ; item . addStyleDependentName ( STYLE_PADDING ) ; } item . addStyleDependentName ( STYLE_SELECTABLE ) ; item . addStyleDependentName ( STYLE_ITEM ) ; if ( active ) { item . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { if ( WebContent . onIpad ) { description . addStyleDependentName ( STYLE_SELECTED_TIMER ) ; Timer t = new Timer ( ) { @ Override public void run ( ) { DOM . removeElementAttribute ( TreeListUI . panelInside . getElement ( ) , "<STR_LIT:id>" ) ; PopupControl . changeUI ( PopupUIs . NewTree ) ; } } ; t . schedule ( <NUM_LIT> ) ; } else { PopupControl . changeUI ( PopupUIs . NewTree ) ; } } } ) ; } else { item . addStyleDependentName ( STYLE_INACTIVE ) ; } } static void setMarginBottom ( Widget w , double px ) { w . getElement ( ) . getStyle ( ) . setMarginBottom ( px , Unit . PX ) ; } static void setMarginTop ( Widget w , double px ) { w . getElement ( ) . getStyle ( ) . setMarginTop ( px , Unit . PX ) ; } private static native String getUrl ( String file ) ; static void createCredentials ( Panel panel , UserTrees userTrees ) { if ( credentials . isEmpty ( ) ) { return ; } int n = <NUM_LIT:0> ; Label l = null ; String [ ] c = credentials . split ( "<STR_LIT::>" ) ; for ( int i = <NUM_LIT:1> ; i < c . length ; i += <NUM_LIT:2> ) { final String user = c [ i - <NUM_LIT:1> ] . trim ( ) ; if ( userTrees . getStatus ( ) == UserTrees . LOADED && user . equals ( userTrees . getTreeTitle ( UserTrees . ROOTTREE_INDEX ) ) ) { continue ; } final String pass = c [ i ] . trim ( ) ; l = PopupElements . createLabel ( ) ; panel . add ( l ) ; l . setText ( "<STR_LIT>" + user ) ; l . addStyleDependentName ( STYLE_LINK ) ; l . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { LoginUI . sendLogin ( user , pass ) ; } } ) ; n ++ ; } if ( n != <NUM_LIT:0> ) { setMarginBottom ( l , <NUM_LIT:10> ) ; } } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . google . gwt . core . client . * ; public class PopupMain implements EntryPoint { @ Override public void onModuleLoad ( ) { PopupControl . onModuleLoad ( ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . event . shared . * ; import com . google . gwt . user . client . * ; import com . google . gwt . user . client . ui . * ; public class PearledUI { private static HandlerRegistration clickListener ; private static HandlerRegistration keyPressListener ; private static HandlerRegistration blurListener ; static void init ( Panel parent , boolean hasCreatedNewTree , boolean isPearlable ) { PopupControl . panelScrollableExist = false ; FlowPanel panel = new FlowPanel ( ) ; FocusPanel focus = new FocusPanel ( panel ) ; parent . add ( focus ) ; focus . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_FOCUS ) ; if ( WebContent . onIpad ) { focus . addStyleDependentName ( PopupElements . STYLE_FOCUS_IPAD ) ; } focus . setFocus ( true ) ; String text ; if ( hasCreatedNewTree ) { if ( WebContent . onIpad ) { text = "<STR_LIT>" ; } else { text = "<STR_LIT>" ; } } else if ( ! isPearlable ) { text = "<STR_LIT>" ; } else { text = "<STR_LIT>" ; } if ( ! WebContent . onIpad ) { Label label = PopupElements . createLabel ( ) ; label . setText ( text ) ; label . addStyleDependentName ( PopupElements . STYLE_HUGE ) ; panel . add ( label ) ; } else { HTML message = PopupElements . createHtml ( ) ; message . setHTML ( text ) ; message . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_PEARLED_IPAD ) ; panel . add ( message ) ; HTML logo = PopupElements . createHtml ( ) ; logo . setHTML ( PopupElements . PEARLED ) ; logo . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_PEARLED_IPAD ) ; if ( hasCreatedNewTree ) { logo . addStyleDependentName ( PopupElements . STYLE_REALLY_UNDER_MESSAGE ) ; } else { logo . addStyleDependentName ( PopupElements . STYLE_UNDER_MESSAGE ) ; } panel . add ( logo ) ; } clickListener = focus . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { closeWindow ( ) ; } } ) ; keyPressListener = focus . addKeyPressHandler ( new KeyPressHandler ( ) { @ Override public void onKeyPress ( KeyPressEvent event ) { closeWindow ( ) ; } } ) ; blurListener = focus . addBlurHandler ( new BlurHandler ( ) { @ Override public void onBlur ( BlurEvent event ) { closeWindow ( ) ; } } ) ; Timer t = new Timer ( ) { @ Override public void run ( ) { closeWindow ( ) ; } } ; t . schedule ( <NUM_LIT:1000> ) ; PopupControl . onViewCreated ( ) ; } public static final void closeWindow ( ) { if ( clickListener != null ) { clickListener . removeHandler ( ) ; } if ( keyPressListener != null ) { keyPressListener . removeHandler ( ) ; } if ( blurListener != null ) { blurListener . removeHandler ( ) ; } Alerts . closeWindow ( ) ; } } </s>
<s> package com . broceliand . pearlbar . chrome . client . popup ; import com . broceliand . pearlbar . chrome . client . common . * ; import com . google . gwt . event . dom . client . * ; import com . google . gwt . user . client . ui . * ; public class TreeCreatedUI { static void init ( Panel parent ) { FlowPanel panel = new FlowPanel ( ) ; FocusPanel focus = new FocusPanel ( panel ) ; parent . add ( focus ) ; focus . setStylePrimaryName ( PopupElements . PRIMARY_STYLE_FOCUS ) ; focus . setFocus ( true ) ; HTML header = PopupElements . createHtml ( ) ; panel . add ( header ) ; header . setHTML ( PopupElements . DOWN_TRIANGLE + "<STR_LIT>" ) ; header . addStyleDependentName ( PopupElements . STYLE_BLUEBOLD ) ; PopupElements . setMarginBottom ( header , <NUM_LIT:20> ) ; FlowPanel buttons = new FlowPanel ( ) ; panel . add ( buttons ) ; Label ok = PopupElements . createLabel ( ) ; buttons . add ( ok ) ; ok . setText ( "<STR_LIT>" ) ; ok . addStyleDependentName ( PopupElements . STYLE_LINK ) ; ok . addStyleDependentName ( PopupElements . STYLE_RIGHT ) ; focus . addClickHandler ( new ClickHandler ( ) { @ Override public void onClick ( ClickEvent event ) { Alerts . closeWindow ( ) ; } } ) ; focus . addKeyPressHandler ( new KeyPressHandler ( ) { @ Override public void onKeyPress ( KeyPressEvent event ) { Alerts . closeWindow ( ) ; } } ) ; focus . addBlurHandler ( new BlurHandler ( ) { @ Override public void onBlur ( BlurEvent event ) { Alerts . closeWindow ( ) ; } } ) ; PopupControl . onViewCreated ( ) ; } } </s>