473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic iteration over collection of files

3
Hi
Let's assume that I have collection of files. That collection of files my vary in future, there might be .class .xml .config etc. I would like to do some task for every of mentioned files. For example for .xml I would like to parse that file, for .config I would like to browse for some properties etc. My goal is to have that open for future changes without modifying previously created methods. My ideal solution is to add new methods (classes) for comming new types of file.


public List getListFiles(ZipEntry entry) {
.............
return listFiles;
}

public void doSthWithFiles(List<File> listFiles) {
//here is my issue. I don't want to change that method
every time new file extension is comming. I would like
to do that by adding new method (class) without midifying that
method
}

Kind Regards
najort
Feb 5 '08 #1
2 1293
JosAH
11,448 Expert 8TB
Hi
Let's assume that I have collection of files. That collection of files my vary in future, there might be .class .xml .config etc. I would like to do some task for every of mentioned files. For example for .xml I would like to parse that file, for .config I would like to browse for some properties etc. My goal is to have that open for future changes without modifying previously created methods. My ideal solution is to add new methods (classes) for comming new types of file.


public List getListFiles(ZipEntry entry) {
.............
return listFiles;
}

public void doSthWithFiles(List<File> listFiles) {
//here is my issue. I don't want to change that method
every time new file extension is comming. I would like
to do that by adding new method (class) without midifying that
method
}

Kind Regards
najort
How about a factory that delivers 'Tasks' given the file extensions. A 'Task' would
be an interface:

Expand|Select|Wrap|Line Numbers
  1. public interface Task {
  2.    public void process(File file);
  3. }
  4.  
The factory itself could consult a .properties file like this:

Expand|Select|Wrap|Line Numbers
  1. xml   = com.utils.XmlProcessor
  2. txt   = com.utils.TextProcessor
  3. # etc.
  4.  
Given the extension of the file the factory obtains the name of the corresponding
class (Class.forName(name).newInstance()) and returns it as a Task; voila, you
can add new classes for new file extensions. All you have to do is write the class
and list it in the .properties file.

kind regards,

Jos
Feb 5 '08 #2
najort
3
Great Thanks
This is the solution I was waiting for.
Very quick and good.
Thanks again
Feb 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
1
by: SAN CAZIANO | last post by:
I have create a dynamic html table by adding some rows where I have to put some value in an input field and now how can I get all value of all row ??? I try this but it doesn' work button...
2
by: Harry | last post by:
Hello, I have a composite WebControl that I'm dynamically instantiating at runtime using Reflection. When I create a new instance of my control I immediately iterate through it's child control...
1
by: philin007 | last post by:
Hi , I am having a page where leave is applied. - In this page 1 new rows is created dynamically everytime the 'Add row' button is pressed - Each row has a begin date text field and beside it a...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
9
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? ...
3
by: tokcy | last post by:
Hi, I have created dynamic row with text box i.e. initialy i have only one text box and add button when i clicked on add button it create another text box. and i want to append the values of...
1
by: aashishn86 | last post by:
i create dynamic rows using this function : function addRow() { var tbl = document.getElementById('applications'); var lastRow = tbl.rows.length; var iteration = lastRow; var row =...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.