Some of you have probably already discovered this pattern but I am
sometimes slow to figure things out. I have been muddling along for years complaining that NetRexx rules forced me to put my filters in child classes with code following my main program code and often far from where the filter is being used. But while I was writing a tool for another project just now I discovered a technique that allows the filter to be placed near the code using it. Kinda simple but just in case anyone else is looking for a way to do this in NetRexx, here is a sample showing how: ------------------------------------------------------------------------------------------------------------------------------------------------------------- /* filtertest - a sample program to display filenames matching any of a list of types - demonstrates an in-line FilenameFilter usage: java filtertest directory-name filetypes example: java filtertest \backups png gif zip */ class filtertest implements FilenameFilter properties static filter="" -- file type filter list method accept(filedir=File,filename=String) returns boolean -- this method implements the FilenameFilter interface return filter.pos(Rexx(filename).substr(Rexx(filename).lastpos('.')+1))>0 method main($cmdin1=String[]) static;arg=Rexx($cmdin1) parse arg directory filter loop filename over File(directory).list(filtertest()) -- note passing of an instance of this class to java.io.File so it will call our filter method which cannot be static say "found file ==>"filename end ------------------------------------------------------------------------------------------------------------------------------------------------------------- (Since the filter code is in an instance, it could actually be a select calling static or instance filters in various parts of the program if multiple filters are needed.) Hope this is not obvious to everyone else! Maybe it could be added to the repository examples if it is useful for beginners... -- Kermit _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
No, me too. I have always put the filenamefilters in separate classes. Will add it to the examples.
René. On 2 nov. 2012, at 12:07, Kermit Kiser <[hidden email]> wrote: > Some of you have probably already discovered this pattern but I am sometimes slow to figure things out. I have been muddling along for years complaining that NetRexx rules forced me to put my filters in child classes with code following my main program code and often far from where the filter is being used. But while I was writing a tool for another project just now I discovered a technique that allows the filter to be placed near the code using it. Kinda simple but just in case anyone else is looking for a way to do this in NetRexx, here is a sample showing how: > > ------------------------------------------------------------------------------------------------------------------------------------------------------------- > /* > filtertest - a sample program to display filenames matching any of a list of types - demonstrates an in-line FilenameFilter > > usage: java filtertest directory-name filetypes > example: java filtertest \backups png gif zip > */ > > class filtertest implements FilenameFilter > > properties static > > filter="" -- file type filter list > > method accept(filedir=File,filename=String) returns boolean -- this method implements the FilenameFilter interface > return filter.pos(Rexx(filename).substr(Rexx(filename).lastpos('.')+1))>0 > > method main($cmdin1=String[]) static;arg=Rexx($cmdin1) > > parse arg directory filter > > loop filename over File(directory).list(filtertest()) -- note passing of an instance of this class to java.io.File so it will call our filter method which cannot be static > say "found file ==>"filename > end > ------------------------------------------------------------------------------------------------------------------------------------------------------------- > > (Since the filter code is in an instance, it could actually be a select calling static or instance filters in various parts of the program if multiple filters are needed.) > > Hope this is not obvious to everyone else! Maybe it could be added to the repository examples if it is useful for beginners... > > -- Kermit > > _______________________________________________ > Ibm-netrexx mailing list > [hidden email] > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ > _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Kermit Kiser
This is much more rudimentary, but it works: /*NetRexx */ options replace comments java crossref savelog symbols verbose4 trace1 logo -- package BJCP /************************************* This copy of q and a is hopelessly lost in trying to be executable from the frontend and standalone. logic flow: load the table from the selected file build the window with the randomly chossen question and up to 5 possible answers **************************************/ --import java.awt.List import java.io.Reader import java.io.BufferedReader import java.text. -- Needed for the SimpleDateFormat class import java.util. -- Needed for integer math import netrexx.lang.Rexx import java.awt. import java.awt.event. import javax.swing. import java.awt.TextComponent -- import org.netrexx.runtime.compatibility -- the above import is thanks to Thomas Schneider -- this is our main class class QandAgui Properties inheritable static -- some vars for the whole class nbrFrames = 0 question1 = Rexx[199] answerX = Rexx[199,5] RorW = Rexx[199,5] ans_done = int[199] ans_wrong = int[199] ans_done_counter = int 0 ans_wrong_counte = int 0 rightones = int 0 wrongones = int 0 try_cnt = int 0 numOfQuestion = int 5 ansDoneTableFile = rexx Random_Int = int 0 My_Int = rexx response1 = Rexx fileName = Rexx NameForScores = Rexx -- bufferIn = Rexx start = rexx savedWidth = int 0 savedHeight = int 0 savedX = int 0 savedY = int 0 Debug_Level = int 50 method main(s=String[]) static if Debug_Level > 3 then trace results -- if question1[0] == null then do loop label PickFile Until response1.upper = "M" | response1.upper = "T" | response1.upper = "A" | response1.upper = "C" say say 'Enter a "T" for the true and false questions.' say say 'Enter a "M" for the multiple choice questions.' say say 'Enter a "A" for the questions on which styles may have diacetyl and DMS.' say say 'Enter a "C" for the questions on the color range for each substyle.' response1=ask end PickFile fs = string fs = System.getProperty("file.separator"); if response1.upper = "T" then fileName='txt_files' || fs || 'TandF.txt' if response1.upper = "M" then fileName='txt_files' || fs || 'QandA.txt' if response1.upper = "A" then fileName='txt_files' || fs || 'Appropriate-Flavors.txt' if response1.upper = "C" then fileName='txt_files' || fs || 'color-multiple-choice.txt' numOfQuestion = LoadTable(fileName) end QandAgui(numOfQuestion) -- -- Method LoadTable(aFileName = Rexx) static SIGNALS IOException returns int --, FileNotFoundException trace var start trace results /* Open and check the files */ NameForScores = aFileName do bufferIn=BufferedReader(FileReader(afileName)) say 'Processing infile.' catch Z=IOException --, X=FileNotFoundException say '# error opening file' Z.getMessage -- say '# File not found.' X.getMessage -- return inhandle end /* The processing loop to load our table from the txt file. ***/ loop numOfQuestion = 0 by 1 line = bufferIn.readLine -- get next line as Rexx string if line=null then leave numOfQuestion -- normal end of file parse line 'Q1 ' question_in question1[numOfQuestion] = question_in line = bufferIn.readLine -- get next line as Rexx string if line=null then leave numOfQuestion -- normal end of file parse line - A1 '<>' answer_in1 '<>' - A2 '<>' answer_in2 '<>' - A3 '<>' answer_in3 '<>' - A4 '<>' answer_in4 '<>' - A5 '<>' answer_in5 '<>' . ; answerX[numOfQuestion,0] = answer_in1 answerX[numOfQuestion,1] = answer_in2 answerX[numOfQuestion,2] = answer_in3 answerX[numOfQuestion,3] = answer_in4 answerX[numOfQuestion,4] = answer_in5 RorW[numOfQuestion,0] = A1 RorW[numOfQuestion,1] = A2 RorW[numOfQuestion,2] = A3 RorW[numOfQuestion,3] = A4 RorW[numOfQuestion,4] = A5 end numOfQuestion numOfQuestion = numOfQuestion - 1 fs = string fs = System.getProperty("file.separator"); ansDoneTableFile = 'donesofar' || fs || aFileName do bufferIn=BufferedReader(FileReader(ansDoneTableFile)) say 'Processing infile.' catch Z=IOException --, X=FileNotFoundException say '# error opening file' Z.getMessage -- say '# File not found.' X.getMessage -- return inhandle end QandAgui.rightones = 0 QandAgui.wrongones = 0 loop mySubscript = 0 by 1 lineIn = bufferIn.readLine -- get next line as Rexx string if lineIn = null then leave mySubscript -- normal end of file parse lineIn ans_done_counter "<>" ans_wrong_counter QandAgui.ans_done[mySubscript] = ans_done_counter QandAgui.ans_wrong[mySubscript] = ans_wrong_counter if QandAgui.ans_done[mySubscript] == 1 then rightones = rightones + 1 if QandAgui.ans_wrong[mySubscript] > 1 then wrongones = wrongones + QandAgui.ans_wrong[mySubscript] end mySubscript reset() return numOfQuestion method QandAgui(total_lines = int) if Debug_Level > 3 then trace results trace var rightones total_lines say try_cnt "<-- try_cnt. total lines ---> " total_lines rightones -- Check to see if we have tried every possible card in the deck. Exit if so. Random_Int = GetRand(total_lines) -- -- don't rebuild the entire frame, just update the fields in it wherever it has been placed and leave it there. this_question='Question' Random_Int || ')' question1[Random_Int] abf=AboutFrame(this_question,answerX[Random_Int,0],RorW[Random_Int,0],answerX[Random_Int,1],RorW[Random_Int,1],answerX[Random_Int,2],RorW[Random_Int,2],answerX[Random_Int,3],RorW[Random_Int,3],answerX[Random_Int,4],RorW[Random_Int,4],try_cnt) abf.Set_Question(this_question) abf.Set_Pos_Answer(answerX[Random_Int,0],RorW[Random_Int,0]) abf.Set_Pos_Answer(answerX[Random_Int,1],RorW[Random_Int,1]) abf.Set_Pos_Answer(answerX[Random_Int,2],RorW[Random_Int,2]) abf.Set_Pos_Answer(answerX[Random_Int,3],RorW[Random_Int,3]) abf.Set_Pos_Answer(answerX[Random_Int,4],RorW[Random_Int,4]) -- put some instruction in the title, like if this is true or false or multiple choide. abf.SetTitle('Beer judging training. Multiple choice. Click on your selection till you get it right.' NameForScores) /* Set a title */ -- abf.SelectQuestion(0) /* Select first Question */ abf.LabelRight.setText('Correct: ' QandAgui.rightones ' of ' QandAgui.numOfQuestion) abf.LabelWrong.setText(' Wrong: ' QandAgui.wrongones) if (QandAgui.rightones + QandAgui.wrongones) > 0 then abf.LabelPercent.setText(' Percent: ' (100 * QandAgui.rightones / (QandAgui.rightones + QandAgui.wrongones))) abf.ShowAbout() /* Show it */ method reset() public static returns Rexx start = System.currenttimemillis return start method elapsed() public static returns Rexx current=System.currenttimemillis numeric digits 16 delta = current - start delta=delta/1000 numeric digits 9 delta=delta.format(NULL,3) return delta method GetRand(total_lines = int) returns int static trace results trace var scanCount total_lines My_Int qNumber scanCount = int 0 My_int = (total_lines*Math.random()) % 1 -- %1 make result to integer loop label findundone while ans_done[My_Int] = 1 if My_Int < total_lines then My_Int = My_Int + 1 if My_Int >= total_lines then My_Int = 0 scanCount = scanCount + 1 if QandAgui.rightones > total_lines | scanCount > total_lines then do Line_Out = 'Correct: ' QandAgui.rightones ' of ' QandAgui.numOfQuestion ' Wrong: ' QandAgui.wrongones - ' Percent: ' (100 * QandAgui.rightones / (QandAgui.rightones + QandAgui.wrongones)) %1 --JOptionPane.showMessageDialog(null, "All questions have been answered, exiting...") -- revertAllAnswersToUnseen() -- JOptionPane.showMessageDialog(null, "Files updated, exiting...") AboutActionClass.WriteAndLeave(Line_Out) -- AboutActionClass.objOfClassAboutFrame.dispose() AboutActionClass.PbtRevertToZeros() exit end end findundone -- ans_done[My_Int] = 1 -- we are incrementing the ans+done table in the check of the answer. RETURN My_Int -- method DisplayScore -- class AboutFrame extends Frame trace var nbrFrames TxtWho List_Question TxtAppl LabelRight LabelWrong - LabelPercent myint questions Possible_Answer Possible_AnswerL win Debug_Level Properties inheritable -- nbrFrames = 0 TxtWho = TextArea(' ',400,999,TextArea.SCROLLBARS_NONE) List_Question = java.awt.List(5) -- define a List Box TxtAppl = Label -- declare read-only text PbtCncl1 = Button('Exit the quiz') -- define a push button PbtRevertToZeros = Button('Reset all scores') -- define a push button LabelRight = Label(' Correct: 0') -- define a LabelWrong = Label(' Wrong: 0') -- define a LabelPercent = Label(' Percent: 0') -- define a myint = int 1 -- declare number of questions questions = int -- declare number of questions Possible_Answer = String[] -- declare this array Possible_AnswerL = String[] win = Frame Debug_Level = int 50 Method AboutFrame(Here_Question = String, - Here_answer1 = String, - Here_RW1 = String, - Here_answer2 = String, - Here_RW2 = String, - Here_answer3 = String, - Here_RW3 = String, - Here_answer4 = String, - Here_RW4 = String, - Here_answer5 = String, - Here_RW5 = String, - Total_trys = int) - public If Debug_Level > 5 then trace results myint = Total_trys say myint "=" Total_trys -- if QandAgui.nbrFrames > 10 then exit -- As our class is a frame extension, we should not call Frame() -- else we'd create yet another frame -- win = JFrame("About") -- should not be coded win = this -- "win" is nicer than "this" -- We can call the parent class to set a frame title. super.SetTitle(Here_Question) -- define default frame title Possible_Answer = String[5] -- create this array Possible_AnswerL = String[5] -- create this array questions = -1 -- no questions defined yet -- To close the window from the system menu work with WindowListener anObject = AboutFrameController() -- Create this object -- Because "we" are a frame, no need to write "win.add" -- but it may be clearer for some readers. win.addWindowListener(anObject) -- To be able to react to end-user frame events pbtCncl1.addActionListener(AboutActionClass(this,'pbtCncl1') ) PbtRevertToZeros.addActionListener(AboutActionClass(this,'PbtRevertToZeros') ) List_Question.addActionListener(AboutActionClass(this,'List_Question') ) List_Question.addItemListener(AboutActionClass(this,'List_Question') ) -- add the visible objects to the frame TxtAppl = Label('The application has been written by') TxtWho.setEditable(0) -- make this area read only win.add("North" , TxtAppl) -- add these objects to the frame win.add("West" , List_Question) win.add("Center" , TxtWho) p = Panel() -- Host the button in a "panel" to keep it small win.add("South" , p) -- add the "panel" to the frame p.add(PbtCncl1) -- place the button in the "panel" p.add(PbtRevertToZeros) -- place the button in the "panel" p.add(LabelRight) -- place the button in the "panel" p.add(LabelWrong) -- place the button in the "panel" p.add(LabelPercent) -- place the button in the "panel" -- use some colors hYell = color(255,255,128) -- define a color object TxtAppl.setBackground(color.white) -- color of application text setBackground(color.white) -- color of our frame pbtCncl1.setBackground(color.lightGray) -- color of our button pbtRevertToZeros.setBackground(color.lightGray) -- color of our button List_Question.setBackground(hYell) -- color of our LISTBOX TxtWho.setBackground(hYell) -- color of our text area if QandAgui.nbrFrames == 0 then do -- only do this for the very first frame ----- calculate a good place for our frame --------------- -- setSize(1100,200) -- define size of window. -- offset = (NbrFrames-1) *10 -- don't place all at same place -- d = getToolkit().getScreenSize() -- get size of the screen -- s = getSize() -- get size of our frame -- SetLocation( (d.width - s.width) %6 + offset, - -- (d.height - s.height)%6 + offset ) -- Get the size of the screen dim = Dimension -- windowSize = Dimension dim = Toolkit.getDefaultToolkit().getScreenSize() -- windowSize = win.getSize(); -- setSize(1100,200) -- define size of window. -- setSize( -- Determine the new location of the window w = int dim.width * 0.75 h = int dim.height/4 setSize(w,h) x = int (dim.width-w)/2; y = 0 --int (dim.height-h) / 2; -- Move the window win.setLocation(x, y) end if QandAgui.nbrFrames > 0 then do -- only do this for frames after the very first frame setSize(QandAgui.savedWidth, QandAgui.savedHeight) win.setLocation(QandAgui.savedX, QandAgui.savedY) end QandAgui.nbrFrames = QandAgui.nbrFrames + 1 Method SetTitle(t = String) -- Define title of the window super.setTitle(t) -- Must be preceeded by "super" else we -- call ourselves Method Set_Question(t = String) -- Define the title of the window TxtAppl.setText(t) Method Set_Pos_Answer(My_Answer = String,Descript = String) questions = questions+1 -- add an element to the questions list box List_Question.add(My_Answer) Possible_Answer[questions] = Descript -- add his description to array -- say questions My_Answer Descript Method Set_Pos_Answer(My_Answer = String,Descript = String,DescLong = String) questions = questions+1 List_Question.add(My_Answer) Possible_Answer[questions] = Descript Possible_AnswerL[questions] = DescLong Method SelectQuestion(ix = int) if ix<= questions then List_Question.select(ix) Method ShowAbout() -- this.pack - makes the screen huge!! -- As "we" the object are in fact a frame, no need to code this.setVisible(1) -- setVisible(1) --------- This class handles events on the frame itself ---------- class AboutFrameController extends WindowAdapter method windowClosing(e = WindowEvent) Say 'Closed by system menu' exit --------- This class handles Action Events with objects in the frame class AboutActionClass implements ActionListener,ItemListener Properties inheritable objOfClassAboutFrame = AboutFrame -- objOfClassAboutFrame is an object of class AboutFrame myEventName = String -- a string is passed and available in the class int_I = int 0 xCoordinate = int 0 yCoordinate = int 0 Line_Out = String Properties inheritable static MyAppend = boolean 1 Line_Bld = Rexx Sortable_Date = String Debug_Level = int 6 -- Constructor method AboutActionClass(x = AboutFrame, anEvent = String) if Debug_Level > 3 then trace results objOfClassAboutFrame = x myEventName = String anEvent method actionPerformed(e = ActionEvent) if Debug_Level > 3 then trace results Say 'Event happened for:' myEventName Select when myEventName = 'pbtCncl1' then do Say 'Closed by Cancel button' if (QandAgui.rightones + QandAgui.wrongones) > 0 then do Line_Out = 'Correct: ' QandAgui.rightones ' of ' QandAgui.numOfQuestion ' Wrong: ' QandAgui.wrongones - 'Percent: ' (100 * QandAgui.rightones / (QandAgui.rightones + QandAgui.wrongones)) %1 end else Line_Out = 'Exiting' WriteAndLeave(Line_Out) objOfClassAboutFrame.dispose() end when myEventName = 'PbtRevertToZeros' then do Say 'Resetting the scores to zeros' Line_Out = 'Resetting the scores to zeros' PbtRevertToZeros() Return end when myEventName = 'List_Question' then do -- double click in List Box -- Beware: testing if ..[] = '' is dangerous, it may yield a -- null pointer exception. So test for "null" ix = objOfClassAboutFrame.List_Question.getSelectedIndex() -- Get the selected line t = '' if objOfClassAboutFrame.Possible_AnswerL[ix] <> null then if objOfClassAboutFrame.Possible_AnswerL[ix] <> '' then t = objOfClassAboutFrame.Possible_AnswerL[ix] if t<>'' then do objOfClassAboutFrame.TxtWho.setForeground(color.black) objOfClassAboutFrame.TxtWho.setText(t) end else do objOfClassAboutFrame.TxtWho.setForeground(color.red) objOfClassAboutFrame.TxtWho.setText('More information about' - objOfClassAboutFrame.List_Question.getSelectedItem()- 'is not available') end end Otherwise Say 'Problem:' myEventName 'is unknown' end method itemStateChanged(e = ItemEvent) if Debug_Level > 3 then trace results trace var rightones -- Apparently we warp to this point when the answer item is clicked. QandAgui.try_cnt = QandAgui.try_cnt + 1 ix = objOfClassAboutFrame.List_Question.getSelectedIndex() -- Get the selected line -if any if objOfClassAboutFrame.Possible_Answer[ix] = 'Right' then do QandAgui.ans_done[QandAgui.Random_Int] = 1 QandAgui.rightones = QandAgui.rightones + 1 SetTextOfScoreLine() JOptionPane.showMessageDialog(objOfClassAboutFrame, "Correct!!") --\n" - this stuff is actually a bit redundant with the scores in the bottom line of the frame. -- 'Correct: ' QandAgui.rightones ' of ' QandAgui.numOfQuestion - -- ' Wrong: ' QandAgui.wrongones - -- ' Percent: ' (100 * QandAgui.rightones / (QandAgui.rightones + QandAgui.wrongones)) - -- ) -- here we need to capture and save the location and dimensions of the frame dim = Dimension dim = objOfClassAboutFrame.getSize() QandAgui.savedWidth = dim.width QandAgui.savedHeight = dim.height myPoint = Point myPoint = objOfClassAboutFrame.getLocation() QandAgui.savedX = myPoint.x QandAgui.savedY = myPoint.y objOfClassAboutFrame.dispose() QandAgui(QandAgui.numOfQuestion) end else if objOfClassAboutFrame.Possible_Answer[ix] = 'Wrong' then do -- increment the counter wrongones QandAgui.ans_wrong[QandAgui.Random_Int] = QandAgui.ans_wrong[QandAgui.Random_Int] + 1 QandAgui.wrongones = QandAgui.wrongones + 1 SetTextOfScoreLine() end else do say "Found a line in the .txt file that is not formatted correctly." say objOfClassAboutFrame.List_Question -- exit -- don't exit, maybe some other area of the frame was clicked. end objOfClassAboutFrame.TxtWho.setForeground(color.black) if ix >= 0 then objOfClassAboutFrame.TxtWho.setText(objOfClassAboutFrame.Possible_Answer[ix]) method SetTextOfScoreLine objOfClassAboutFrame.LabelRight.setText('Correct: ' QandAgui.rightones ' of ' QandAgui.numOfQuestion) objOfClassAboutFrame.labelWrong.setText(' Wrong: ' QandAgui.wrongones) if QandAgui.rightones + QandAgui.wrongones > 0 then objOfClassAboutFrame.LabelPercent.setText('Percent: ' (100 * QandAgui.rightones / (QandAgui.rightones + QandAgui.wrongones))) method WriteAndLeave(OutPut1) static if Debug_Level > 3 then trace results do output = 'BJCPquiz_scores.txt' outFile = FileWriter(output, MyAppend) -- output file BOOLEAN flag means append dest = PrintWriter(outFile) -- to printer f = SimpleDateFormat("yy/MM/dd HH:mm" ) -- Formats hours:minutes:seconds Sortable_Date = f.format(Date()) Line_Bld = QandAgui.NameForScores Sortable_Date (QandAgui.elapsed() / 60 %1) "Minutes Completed:" QandAgui.try_cnt " " OutPut1 || "% correct." dest.println(Line_Bld) dest.close() -- close files catch IOException say 'I/O Exception.' end do output = QandAgui.ansDoneTableFile outFile = FileWriter(output, 0) -- output file BOOLEAN flag means append dest = PrintWriter(outFile) -- to printer -- copy the table of correctly answered question numbers out to disk loop label writeAns_doneTable qNumber = 0 to QandAgui.numOfQuestion dest.println(QandAgui.ans_done[qNumber] "<>" QandAgui.ans_wrong[qNumber]) end writeAns_DoneTable dest.close() -- close files catch IOException say 'I/O Exception with the' output '.' end JOptionPane.showMessageDialog(null, "Files updated, exiting...") method PbtRevertToZeros static trace results QandAgui.rightones = 0 QandAgui.wrongones = 0 -- SetTextOfScoreLine() do output = QandAgui.ansDoneTableFile outFile = FileWriter(output, 0) -- output file BOOLEAN flag means append dest = PrintWriter(outFile) -- to printer -- set all the flags in the file back to 0 = question has not been asked yet. loop label writeAns_doneTable qNumber = 0 to QandAgui.numOfQuestion dest.println("0 <> 0") QandAgui.ans_done[qNumber] = 0 QandAgui.ans_wrong[qNumber] = 0 end writeAns_DoneTable dest.close() -- close files catch IOException say 'I/O Exception with the' output '.' end Kenneth Klein
Some of you have probably already discovered this pattern but I am sometimes slow to figure things out. I have been muddling along for years complaining that NetRexx rules forced me to put my filters in child classes with code following my main program code and often far from where the filter is being used. But while I was writing a tool for another project just now I discovered a technique that allows the filter to be placed near the code using it. Kinda simple but just in case anyone else is looking for a way to do this in NetRexx, here is a sample showing how: ------------------------------------------------------------------------------------------------------------------------------------------------------------- /* filtertest - a sample program to display filenames matching any of a list of types - demonstrates an in-line FilenameFilter usage: java filtertest directory-name filetypes example: java filtertest \backups png gif zip */ class filtertest implements FilenameFilter properties static filter="" -- file type filter list method accept(filedir=File,filename=String) returns boolean -- this method implements the FilenameFilter interface return filter.pos(Rexx(filename).substr(Rexx(filename).lastpos('.')+1))>0 method main($cmdin1=String[]) static;arg=Rexx($cmdin1) parse arg directory filter loop filename over File(directory).list(filtertest()) -- note passing of an instance of this class to java.io.File so it will call our filter method which cannot be static say "found file ==>"filename end ------------------------------------------------------------------------------------------------------------------------------------------------------------- (Since the filter code is in an instance, it could actually be a select calling static or instance filters in various parts of the program if multiple filters are needed.) Hope this is not obvious to everyone else! Maybe it could be added to the repository examples if it is useful for beginners... -- Kermit _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |