Using FileName Filter is an Advantage ?

Hi all,
Assume there are two versions of program , let me tell you the objective of the program.
Objective : To list the directory and select the files based on the given criteria.
Version 1:
Step 1: get the files list by using File.listFiles()
Step 2. Loop through the list and select the files based on the criteria.
Step 3: Process the selected files.
Version 2:
Step 1 : Get the files using File.listFiles(Filter)(embed the selection criteria inside the filter class).
Step 2 : Process the selected files.
My assumption is Version 2 will run faster than Version 1:
Guys could you please tell me whether my assumption is right ?

There's no reason to think the Filter method will run any faster. In fact, it might be a tiny, imperceptible bit slower, since it will probably have an extra level of method calling. Note that this theoretical minuscule speed difference is NOT a reason to choose one over the other.
The reason to use the Filter method is for encapsulation and separation of responsibility. The Filter is a way to encapsulate the selection criteria, and confine that responsibility to a class whose job is precisely that. This lets you change which files you'll process without changing the processing loop. The filter can come from somewhere completely separate from the processing loop.
For example:
public class FileUtil {
  public static getSumOfFileSizes(File directory, FileNameFilter filter) {
    File[] files = directory.listFiles(filter);
    long size = 0L;
    for (File file : files) {
      size += file.length();
    return size;
}Now if I want to know the total sizes of all the .jpg files and all the .gif files in the directory, I just do
long jpgSizes = FileUtil.getSumOfFileSizes(directory, new FileNameFilter() {
  public boolean accept(File directory, String name) {
    return name.endsWith(".jpg");
long gifSizes = FileUtil.getSumOfFileSizes(directory, new FileNameFilter() {
  public boolean accept(File directory, String name) {
    return name.endsWith(".gif");
  }});Note that I only write the size summing code once, and I never change it. I could of course define a FileFilter, say EndsWithFileFilter that I just pass the extension to look for, rather than have those separate anonymous inner classes. The point is that the processing code is completely independent of the file selection code.

Similar Messages

  • Smart Folder Bug: Iphoto fails to match using 'filename' filter

    Hi, this issue has popped up here:
    http://discussions.apple.com/message.jspa?messageID=6008267
    and here:
    http://www.mac-forums.com/forums/showthread.php?t=22401
    though I've yet to find an answer.
    Briefly, the problem:
    When using a smart album with a 'filename' filter, iphoto fails to produce a match when it should. Interestingly, I have some of my photo's included from their current location (simply a folder structure on my mac) and others imported directly into iphoto, so are directly in the library. Now, those photo's that are included from their current location are correctly indexed, and the smart folder provides correct matches (e.g. all filenames that contain '.jpg'). However, none of the photo's that reside in iphoto's own library are present with the example filter above.
    I'm not sure how much this topic has been bashed, but this is definitely an iphoto issue, and an irritating one! (Yep, I've rebuilt the library too)
    Thoughts?

    Tom
    Thoughts?
    Here's one:
    I have some of my photo's included from their current location (simply a folder structure on my mac) and others imported directly into iphoto, so are directly in the library.
    Running a mixed library, where iPhoto is managing some of the files and you are managing the others, is a recipe for data loss. When there's complexity in managing the data, mistakes will occur.
    That said: this could be a damaged db file.
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.
    Regards
    TD

  • Batch processing with filename filter

    Hi guys,
    Does anyone have any idea how to run a specific action in batch along with a filename filter?
    My problem is I have a folder with subfolders ie...  0001, 0002, 0003, 0004 etc   all these folders have approx 100 jpg files with the same filenames in each.
    a sample of my images are: landscape-oraange.jpg , landscape-blue.jpg , landscape-red.jpg , portrait-orange.jpg etc etc
    I was wonder of a way to just run the specific batch action on filenames containing a certain word, for instance to apply to all files containing the word "landscape" and exclude all other files.
    I cannot copy all files under the subfolders to a seperate folder and run this way... as all filenames are the exact same as the other folders.
    Does anyone have any advise?
    Thanks again guys,   Jamie.

    This might provide not quite what you are looking for but something similar.
    Insert the correct Action and Set names in the line
    app.doAction("Action 3", "Set 1")
    and change the variable theIdentifier to the name part you want to use as a criterium.
    This would work only if there are no spaces in the names by the way.
    // 2012, use it at your own risk;
    #target photoshop
    // select folder;
    var theFolder = Folder.selectDialog ("select folder");
    if (theFolder) {
    // define the name part to look for;
    var theIdentifier = "Untitled";
    var theFiles = theFolder.getFiles(new RegExp(theIdentifier+"\\S*.(jpg|tif|eps|psd)$", "i"));
    // work through the files;
    for (var m = 0; m < theFiles.length; m++) {
    // open image;
    var theImage = app.open(theFiles[m]);
    // perform action;
    app.doAction("Action 3", "Set 1")

  • How to use one Filter Pane to multiple Dataproviders

    Hi Experts.
    i have checked the threads on this but i did not get correct solution.
    we have issue in using single Filter pane web item in WAD for three different dataproviders ( three dataproviders have same free charecteristics and variable) charecteristics in row and keyfigures are different.
    thanks in advance.
    Regards
    Raj.

    Hi Gill,
    Thanks for your Quick responce.
    when we use the single filter pane, filter conditions are working for only first dataprovider (since data binding is to dataprovider 1. in affterted dataproviders i selected dataprovider 2 and 3, but filter pane is not active for other two dataproviders in tabs.
    thanks in advance.
    Any inputs please....
    Regards,
    Raj.
    Edited by: Rajsapbi on Apr 6, 2009 9:22 AM

  • IP Characteristic Relationship used via Filter for derivation in Query

    Hello Experts,
    hopefully you can help me with following issue:
    Currency is an Attribute from Company. I created a Characteristic Relationsship to derive Currency from Company
    Afterwards I created an Aggregation Level with fields
    Currency, Company, Material, Amount, Quantity, Unit.
    On this Aggregation Level I defined a Filter with Company which will be filled from a Variable (Replacement Path, Query, single value).
    I use this Filter in a Ready-Input Query and defined it like follows:
    Rows: Amount and Quantity (restricted to TO)
    Column: Material and Currency
    The field currency should be filled automatically with Currency from Company but it did't. Due to this the Query is not ready input.
    I know that it can be filled via User Exit but this is my last solution if nothing else is working. A Variable with Replacementh path and filled by Attribute of Company does not solve my issue.
    Thank you in advance for any help.
    Kind Regards
    Doris

    Hello,
    thank you all for your answers. I used Workpackages for my issue. I picked it upfrom the "How to Use workpackages to control Locking in BI Integrated Planning".
    With this solution I can fill the currency with Replacmenth Path from Attribute Company.
    This is the first time that I worked with Workpackages for Authorization and I can recomend it because you don't need an User Exit.
    Kind Regards
    Doris

  • Use of filter to JSF faces servlet

    Hi
    I have a JSF application which is secured by a custom security framework (similar to SITE MINDER). The security framework after authentication passes the authenticated user name within a in-memory session cookie.
    The entire user information like his group and access restrictions (field / UI compoonent level) resides in the application database
    I have used a filter to JSF Faces servlet to retrieve the user information from the database and storing in session.
    Is this use of filter a good approach?

    I would fetch such information only once and store it in a simple session scoped bean after a successful login, but I am weird for wanting to do things in a simple way.
    A filter can work to validate if the user is still "logged in" (IE. his/her session didn't expire), but since this is JSF you could also use a phase listener for such a purpose.

  • Replacement Path variable cannot be used in filter

    After creating a variable of type replacement path with query I get the error message:
    Errors: Variable ... cannot be used in 'Filter' 'Default Values'; remove
    Does anyone know what is causing this message and how to prevent it?
    Thanks.
    Regards,
    József.

    Thanks for your response Bhargava,
    Your answer did help me find the solution. When using a replacement path variable with query, you can only use the variable in the Characteristic Restrictions part of the Filters (not in the Default Values).
    The characteristic itself can still be used for navigation.
    p.s. Found that when copying a query some links to structures, like restricted key-figures, are kept in the metadata repository, even after removing them from the query. This can also cause error messages.
    Regards,
    József.

  • Framemaker uses $filename for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen?

    Framemaker uses <$filename> for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen? In compiling our books it would be helpful to not have this extension appear as it then requires us to create extra files without them.

    See: System Variables

  • I want to use a filter liquifi and the nex pafe open whit a black screen in state of a picture that i select

    i'm not a good one in english i'm flemish so do it letter by letter please .
    if i want to use the filter liquifi open's a new page wat's normaly yes , but in stade of my picture i get a black screen  whats going wrong ?

    Does turning off »Use Graphics Processor« in the Performance Preferences and restarting Photoshop have any bearing on the issue?

  • Where to locate and how to use the filter thershould to binarized image

    Good morning friends. I am using
    Labview with VDM and let me know where to locate and how to use the
    filter thershould. Also that parameters used to binarized image captured
    via webcam and display it in black and white.
    Thank you very
    much.

    Is the image that you are getting a RGB one? Use color plane extraction and then use a binary threshold to convert it into a binary image. You can also directly use a color threshold and convert a rgb (color) image to a binary image.

  • Using a filter in RUN Allocation

    Does anyone know how to use a filter in the WHAT, WHERE clauses in RUN Allocation?
    I need to use something like WHERE=%STAT_ACCTS% AND [GROUP]<>"PL" but it dosen't work.
    On the contrary, is there a way to get the basemembers of a parent ID based on a filter?
    I could also use something like *XDIM_MEMBERSET ACCOUNT =BAS(STACCTS) AND [GROUP]<>"PL" but XDIM_MEMBERSET does not support conditions.
    Thanks in advance for help!

    Thanks for the replies... but my problem is still not solved... if either of the following could work that would solve this:
    a) have my xdim_memberset set to only those products which meet the condition [LEVEL]="seg" and are the bas members of the product i pick from the hierarchy. For this i would need a select statement which works like:
    *SELECT(%SKU%,[ID],"PRODUCT","[PARENTH1]=%PRODUCT_SET% AND [LEVEL]='SEG' ")
    OR
    b) a way to create a variable using xdim_filter that i can use anywhere else in my code
    c) put a condition in the WHERE clause of the allocation script so i could use something like:
    DIM PRODUCT WHAT=something; WHERE=BAS(%PRODUCT_SET%) AND [LEVEL]="SEG";
    but none of the above options are working

  • List of the Files in a Directory based on Filename filter

    Hi,
    Do any one has an idea about fileName filter Usage.
    Ex: in UNIX: $ ls -l *.java gives the list of the java files in the directory.
    To acheive this we FilenameFilter. please let me know if anyone has any idea about this.
    Regard's
    Kartheek

    All of the answers to these questions, and more, are a mouse-click away. You can't develop a Java application without referring to the core Java API javadoc:
    http://java.sun.com/j2se/1.4.2/docs/api/index.html
    Your current task is to find the following classes and methods, and make sure you understand what they do:
    java.io.File :: list(FilenameFilter filter)
    java.io.FilenameFilter :: accept(File dir, String name)
    java.lang.String :: endsWith(String s)
    Once you get done with those, I'm sure there's a lot more you'll want to look up.
    Good luck.

  • Unable to create content properly in UCM 11G using validateStandard filter

    Hi All,
        We have used validateStandard filter to assign content id with 16 digits in UCM 10G and it worked well, we deployed this component in UCM 11G but it is not working properly. When we click on Check In button content is getting created and displaying  Check_In Confirmation with 16 digit Content ID, upon clicking on Content Info it is displaying the complete info page. When we try to search the content it is not displaying in search results, also when tried to export it using Archiver it is not creating batch file. When we see logs in View Server out put it is displaying
    Unable to lock content with dDocName: 6322932684534064
    File to be removed: D:/oracle/ucm/cs/oracle/ucm/cs/vault/~temp/6322932684534064_meta.htm
    Below is the code and its corresponding log after check In is performed
    trace("=====Set 16 digit random number as ContentId=====");
                 String contId = databinder.getLocal("dDocName");
                 trace("=====value of contId====="+ contId);
            if("".equals(contId))
            //trace("=====Inside ContentId generetion=====");
            int maxdigits = 16;
            StringBuilder result = new StringBuilder();
            Random r = new Random();
            for (int i = 0; i<maxdigits; i++)
            result.append(r.nextInt(10));
            databinder.putLocal("dDocName", result.toString());
            trace("=====Generated ContentId is====="+ result.toString());
    View Server O/P:
    =====Set 16 digit random number as ContentId=====
    =====value of contId=====001885
    =====Generated ContentId is=====6322932684534064
    >(internal)/6 07.08 15:09:28.273 IdcServer-968 Unable to lock content with dDocName: 6322932684534064
    >(internal)/6 07.08 15:09:29.476 IdcServer-968 File to be removed: D:/oracle/ucm/cs/oracle/ucm/cs/vault/~temp/6322932684534064_meta.htm
    Thanks,
    Ashok

    Its a bug. References BUG:16231709 - OBIA7964:ERROR WHILE CREATING DATA WAREHOUSE TABLES USING DAC 11G
    So far the workaround is to use one Container Name at a time when creating the Warehouse.
    If helps mark and update back

  • Use Of Filter and Drill Down  By Option in Context Menu

    Hi,
    We are  on  BI  7.0 patch 14.0
    I have the Filter and Drill Down by option checked in the context menu Web item in WAD . However when I preview on the Web what happens is that the characteristic that I am using the filter and  drill down on shows up horizontally as opposed to in a column.
    For eg: If I have the following data initially
    01/01/2007     250
    02/01/2007    500.
    I keep my cursor on 01/01/2007 and do a filter and drill down by 0calqtr then what I see now is
    01/2007    02/2007 03/2007 04/2007
    instead of
    01/2007
    02/2007
    03/2007
    04/2007.
    Each CalQtr will have a key figure Value beside it in the horizontal mode.
    This happens only when I pick the characteristic on the Graph. On the Web Item Analysis it works fine. Has anyone faced this issue before. This worked fine when it was WAD 3.5. This affects the presentation of the graph. For Objects that have not been migrated the result still shows fine.

    Hi,
    We are  on  BI  7.0 patch 14.0
    I have the Filter and Drill Down by option checked in the context menu Web item in WAD . However when I preview on the Web what happens is that the characteristic that I am using the filter and  drill down on shows up horizontally as opposed to in a column.
    For eg: If I have the following data initially
    01/01/2007     250
    02/01/2007    500.
    I keep my cursor on 01/01/2007 and do a filter and drill down by 0calqtr then what I see now is
    01/2007    02/2007 03/2007 04/2007
    instead of
    01/2007
    02/2007
    03/2007
    04/2007.
    Each CalQtr will have a key figure Value beside it in the horizontal mode.
    This happens only when I pick the characteristic on the Graph. On the Web Item Analysis it works fine. Has anyone faced this issue before. This worked fine when it was WAD 3.5. This affects the presentation of the graph. For Objects that have not been migrated the result still shows fine.

  • Content Query not producing results when using [Me] filter

    Hi
    I'm using a Content Query web part and I'm trying to show the most recent document modified by each site user by applying it across the site collection and using the Filter, Modified By [_Hidden] equals [Me]. However, this doesn't seem to work for any user
    - the web part is always blank. I have tried different combinations such changing equals to contains, and using the Modified By field etc - nothing gives me the correct results. If I instead take the [Me] out and instead use the "people chooser"
    and set to a specific person then I seem to get the results I would expect - however I cannot hard code a given user.
    Does anyone know how to use [Me] correctly?
    Thanks

    Hi  sjb500,
    According to your description, please take steps as below to meet your demand:
    With the page layout open in Design view, double-click the Content Query Web Part.
    In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
    In the Source section, click Show items from all sites in this site collection.
    In List Type section, in the Show items from this list type, click Document Library.
    In the Content Type section, in the Show items of this content type group list, click Document
    Content Types.
    In the Content Type section, in the Show items of this content type list, click Document.
    In the Additional Filters section, under Show Items When, click Modified By [_Hidden] in
    the first box, click Is Equal To in the second box, and then click [Me].
    In the Content Query Web Part dialog box, click the plus sign (+) next to Presentation to expand it.
    In the Grouping and Sorting section, in the Sort items by list, click Modified
    and Select Show items in descending order.
    Click OK.
    Reference:http://office.microsoft.com/en-us/sharepoint-designer-help/display-data-from-multiple-lists-with-the-content-query-web-part-HA010174134.aspx
    [Me] is a variable that stands for the user who is currently viewing the page that contains the Content Query Web Part in the browser.
    Here is some scenarios using [Me] in Content Query Web Part:
    http://social.technet.microsoft.com/Forums/en-US/346ffbe6-d7ba-467e-b7f5-6d6e289677a1/user-tasks-web-part
    Please inform me freely if you have any questions.
    Thanks

Maybe you are looking for

  • Do I have a corrupted file?

    Working on client project last night, all is well. Today projects loads very slowly, no playback/extreme lag (up to 90 seconds for a clip to play for about 1 second) - have not changed anything on the computer other than disconnect one external hard

  • Cp5 - Bug? Editing backgrounds in external editor causes Cp5 to freeze

    Has anyone experienced this problem. From the library, I select a background graphic and select Edit With PaintDotNet (should not matter which editor is used) Make appropriate changes to graphic Save graphic Exit graphic editor Adobe Captivate goes '

  • Business Intelligence (BI)

    Will business intelligence (BI) serve a customer as well during today's leaner times? Please share the information, your answer is valuable: you can also share the information on my usergroup "SAP Success Stories" in Linkedin. Click to follow this li

  • Moving music from I-pod to a new computer.

    My old computer crashed with my all my music. My question is this: I now have a new computer and have I-tunes on it but I am trying to get all my old music off my I-pod to my new computer. Is this possible & if so how would I go about doing it. Right

  • Msi gt680,gt683,gt780 or DX s SATA2-SATA 3(for HDD AND SSD)

    I have a question for these laptops which one them has sata 3 port for high  speed SSD ? And had anyone tried that ?