Filtering immutable/unmodifiable collections

Hi,
I need a general purpose collection filter:
Given a collection, return another collection that excludes certain members of the first collection. Additionally I'd prefer that the new collection retains other attributes of the original (e.g. Comparator if SortedSet etc).
I considered cloning the given collection and then removing undesired elements. Is there a clean way to do this?
In jakarta commons I notice something that comes close (http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java), however it modifies the original collection.
     * Filter the collection by applying a Predicate to each element. If the
     * predicate returns false, remove the element.
     * <p>
     * If the input collection or predicate is null, there is no change made.
     * @param collection  the collection to get the input from, may be null
     * @param predicate  the predicate to use as a filter, may be null
    public static void filter(Collection collection, Predicate predicate) {
        if (collection != null && predicate != null) {
            for (Iterator it = collection.iterator(); it.hasNext();) {
                if (predicate.evaluate(it.next()) == false) {
                    it.remove();

copy constructors. I can't remember the last time I
made a class I wrote cloneable.Me neither :) However, I frequently use existing clone() methods in the collections framework (e.g. Vector.clone() etc.)
Is there a reason you need a completely generic
method
to do this? (other than the appeal of writing
beautiful code).I'm writing a utility. I don't want to build in restrictions if I can help it.
Do you actually have an application that requires
this
functionality where you actually use every collection
type?Not sure I get your drift ... The client application currently uses Vector(legacy), ArrayList, HashSet, TreeSet and LinkedHashSet (no LinkedList yet). So there aren't too many implmentations at all. However, I'd like the filter method to be general (see above).
And .clone() won't work for some reason?Can I clone/copy without code like:
if(collection instanceof <particular-collection-implementation>) {
}which I'm trying to avoid (for reasons above) ?

Similar Messages

  • Better filtering for smart collections - by number of keywords

    There is a nice feature for smart collections that allow filtering keywords by "are empty" and "aren't empty"
    I would like to filter keywords by X number of keywords.
    It's great to have a collection that tells me that there are no keywords but if I add only one keyword I then have to find the image by that keyword.
    As a work flow this doesn't work great. I want to start with images with no keywords, then work through images with 1 keyword and 2 etc. To continue the process you would also need to remove the images from the smart collection (like remove from collection for standard collections) being able to remove the image from collection of has only 3 keywords should apply also to has 4 keywords etc. This way if you have an image that only needs 1 keyword you don't have to remove the image from every progressively higher amount of keyword collections.

    Great, you are going to make me move my lazy behind and find it for you, aren't you? You owe me...
    One Song From Each Artist in Playlist
    http://www.dougscripts.com/itunes/scripts/scripts06.php?page=1#onesongfromeach
    or
    http://tinyurl.com/2etkj4
    Actually now that I read the description more carefully, I am not sure if that works out of the same library or if it instead works out of other playlists.
    Patrick

  • Filtering with Smart Collection

    In a next version of LR (2.2 or 3.0) I would love see the collections window improved.
    When I select two Smart Collections (by Ctrl-clicking) in the menu, LR comes up with all photos that appear in one or both of the collections I selected. When I select one Smart Collection and one normal Collection it displays only the photos that appear in both collections. This is how I want SC's to work as well!
    Am I the only one who wants this to change?

    Depends upon who you ask.
    There are are those of us who believe items should propagate through a stack and others who do not. There are also some who think that component images (HDRs, Panos, etc) where multiple images are used to make a final, behave one way and other stacks behave another.

  • "read through" unmodifiable Collections

    I'm seeking clarification on the following clause extracted from the Collections.unmodifiableSet() JavaDoc (1.5): 'Query operations on the returned set "read through" to the specified set'.
    Does "read through" mean/imply that using the following definitions
    private Set d_rwSet = new HashSet();
    private Set d_roSet = Collections.unmodifiableSet(d_rwSet);Any subsequent change to d_rwSet will be automatically reflected in d_roSet?
    Thanks ... Matt

    Any subsequent change to d_rwSet will be
    automatically reflected in d_roSet?Yes that's correct.
    Kaj

  • Cisco Works - Campus Data Collection

    Cisco Works - Common Services 3.0.3, Campus Manager 4.0.3, RME 4.0.3
    I have devices that are "discovered" via Device Discovery, but do not show up in Campus Data Collection. The devices that do not show up, are "reachable" in Device Discovery. I thought all devices in Discovery that are reachable, were sent to Data Collection? I have no filters in Data Collection. It should allow anything.
    Any ideas why Data Collection is not importing those devices?

    you could watch the Discrepancy reports on Campus Manager, maybe it could help you, it would be a duplicate hostname or IP address.
    it happened to me and it was because i had a duplicate hostname

  • Sorting compressed from uncompressed PSD/PSB files in Bridge/smart collections?

    Is there any info (metadata or something) one could use to sort uncompressed from compressed PSD/PSB files in Bridge?
    Something that could be used in filters for smart collections would be nice.
    Ty in advance.

    Thanks for the quick reply, CP
    FYI, the file is a photographic panorama based on several .CR2 photos taken in July, 2012 and processed in CS5's camera RAW/Photoshop.  Beyond the metadata, here are no fonts or text in the file.
    1.  I changed Maximize ...File Capability from "Never" to "Always" and the flattened file saved and loaded OK, though I can't figure why given Adobe's description of this option. "If you work with PSD and PSB files in older versions of Photoshop or applications that don’t support layers, you can add a flattened version of the image to the saved file...".  The file saved in this manner is ~8% larger and is not my preference as a routine since I've TB's of photo files.  By the way, out of thousands of .psd/.psb files, the one being discussed is the first to give me the error.
    2.  I've tried saving/reloading the file on another computer with Win XP Sp3/CS5...again with Maximize Capability OFF.  Same problem.  Turn ON Maximize Capability and it works.  As with the Win 8 machine, Bridge could neither create a thumbnail or read Metadata.
    3.  I've purged the Bridge Cache, made sure there were no old PS page files, reset PS preferences, and disabled my 2 plugins with no change in the problem.  Windows and Adobe progs are all updated.  Saving to a different HDD has no effect.
    The problem occurs on 2 computers (Win XP/Win 8), two versioins of Photoshop (CS5/CS6), and "Maximize" On/Off togles the problem.  My guess it is a bug in PSD processing routines.
    If I can't find a fix, will keep with Maximize ON and deal with the larger files that result...the cost of insurance, I suppose.
    Thanks again

  • Search or Smart Collection based on Camera Calibration profile?

    Is there a way to do this?

    Well, DevMeta is the slowest for doing initial metadata aquisition, but then is the fastest to use, since it harnesses Lightroom's native lib filter & smart collection mechanisms. It keeps develop metadata up to date in the background, ready for lib filters and smart collections.
    AnyFilter aquires metadata on demand, but does it fairly quickly, so if you only use develop metadata on special occasions, and don't care if access is via native lib filtering or smart collections, it may be preferrable to DevMeta.
    Jeffrey Friedl makes some of the most polished plugins of any author I know, but I'm not very familiar with Data Explorer - I'm sure it's great..
    Doesn't take long to try 'em out though .
    Have fun,
    Rob

  • Shortcut to display all photos no filters

    I'd love to have a shortcut to be able to switch to all catalog photos with filters turned off.
    AFAIK, currently it is only possible to get there by switching to 'All photos' in the left panel and pressing Ctrl/Cmd + L. This takes at least three actions: opening filmstrip or left panel, selecting all photos and turning the filter off.
    It would be very useful if there is a keyword shortcut to do this!

    I'd prefer to have a column in the filter preset for the folder or collection this filter applies to. This would make it pretty close to functionally equivalent to a smart collection, which is fine by me. Custom filters and smart collections ought to be the same kind of animal, both are for helping organize photos.
    The only difference I can see between filters and smart collections would be where you find them -- one is found in the custom filter drop down and the other is found in the smart collection folder collection.
    Also, when specifying a folder, one should be able to indicate if sub-folders are to be included.

  • Quick Collection misbehaving

    We recently had a thread on this. I had it misbehave several times today. I like to use quick collection because it's easy to do it (B key) and then move them to the collection I want them to be in. Several times today when I clicked on Quick Collection it was obviously not what I'd put in there. Another time it might have been what I put in there, but they wouldn't copy to my collection (or any other). I don't want to spend a lot of time trying to figure out what went wrong, but I spent a lot of time today with all images in a folder selected in order to write out and read in metadata. It appeared that if I had all images in a folder selected, Quick Collection was likely to cause a problem. If I went back to where I was and selected one file, for example, I could access Quick Collection correctly.
    Does that fit with what anyone else who has been having trouble has experienced?

    I've seen similar behavior and found that the trick for me was to turn off all filters on Quick Collection -- everything works fine with the all filters off.

  • Is there a way in LR to tell what color space a photo is stored in?

    I have a lot of 16 bit Tiff files in my Lightroom library.  I am looking for an easy way to determine what color space has been assigned to them.  The only way I know to find out is to open them in Photoshop.  Does Lightroom have a way to tell me?  That seems like a pretty basic capability for a high level photo software program like Lightroom, but I can't find it.  Does the Tiff file still have the original RGB numbers that the RAW file had, or have they been changed to suite the color space used?  If the original numbers are still there, then maybe the assigned color space does not matter, and I can change it if I want? I am Using Lightroom 5.5 on a windows 7 64 system.

    In Lr5 - yes, well: sorta..
    No display on right under Metadata, nor in lib filters, but smart collections have rule - see 'Color -> Source Color Profile'. Unfortunately, you need to know ahead of time what to look for, but still: it's better than nothing..
    For example:
    will round up all photos with Adobe RGB profile.
    And you can have another with 'contains sRGB' ...
    ~R.

  • How to make Focus Mode appear in Metadata

    The metadata panel in Lr 5.4 shows all the camera information from my Nikon D7100 with the exception of focus mode.  I know that the focus mode data is collected, because I see it when I open a photo file in Nikon View NX 2.  Is there a way to get it to show up in Lightroom?

    Marvin H wrote:
    Is there a way to get it to show up in Lightroom?
    If you just want to view it (on a per photo basis), consider Jeffrey Friedl's Metadata Viewer plugin.
    If you want to use in lib filters or smart collections, my ExifMeta plugin is the only one I know of.
    (internet search for plugin name and author's name if you have it will reveal in short order)
    Rob

  • Please send me exiftool output for your camera (xml format).

    I am writing a metadata plugin that incorporates at least some of the metadata from raw files that Adobe "missed" - this metadata will be displayed in the right-hand panel in the Library module, and be available for Library Filtering and Smart Collections.
    Some examples of non-camera-specific metadata:
         - Exposure Compensation/Bias
         - Flash Setup
         - Bits Per Sample (e.g. 12 or 14).
    Some examples of Nikon(D300)-specific metadata:
         - Active D-Lighting
         - Focus Distance
         - Hyperfocal Distance.
         - Depth Of Field
         - VR setting.
    I am going to make it configurable so users can select just which metadata they want - to keep it lean. This selection will include elimination of metadata that would only be present for cameras they do not own.
    I will be offering this plugin free of charge, but I need information.
    For those of you so inclined, here's how:
    1. Windows: download Phil Harvey's exiftool(-k).exe and rename it exiftool.exe.
    1. Mac: download the .dmg file instead and install.
    2. execute exiftool -X {some-raw-file} > {CameraMfr-CameraModel}.exif.xml in a command shell / terminal window.
    3. Send me the xml file - anyway you can - one way: http://www.robcole.com/Rob/ContactMe - and send as attachment using your emailer.
    Make sure I can figure out which camera company and camera model the information corresponds to.
    Thanks,
    Rob

    areohbee wrote:
    Hey TK (hope you don't mind the informality),
    Not at all.
    I hope it is OK to respond to this post; that it will still leave the other one editable.
    Actually, if you send me a raw I can use it to test before releasing - the raw itself is actually required now to test - not the exif output.
    OK, will do when I'm on a better connection (in less then 24 hours). Hope that's OK.
    areohbee wrote:
    PS - My uncle likes Pentax.
    Your uncle is one cool dude. And you didn't have to dig down too deep in your family tree to find find someone with an acquired taste for photographic equipment.

  • What is the point of the "Library"?

    I've been using Aperture for about two months now, having migrated my iPhoto library. Some things I love, some things infuriate me. Right now, I'm confused by the purpose of the "Library" in the Projects pane.
    Unless I'm missing something, the Library seems to be nothing more then an unmodifiable collection of Smart Albums. You can't delete these, you can't add new ones in there, and you can't modify the existing ones.
    In my mind, something called the "Library" should be the top-level container of all content managed by the application. Aperture doesn't seem to follow that paradigm, though.
    So, am I missing something, or is the "Library" as generally useless as I've described?
    PowerBook G4   Mac OS X (10.4.8)  

    The library is the top level container. What is confusing is that it is not shown as such (the projects are not "in" it). But then it would make little visual sense to have a single container in the projects pane -- what else would be in it?
    If you select the library and import then a new project is the library is created for you. So the library icon is really a proxy for the whole pane.

  • "No Parking" symbol in elements 9 Organizer thumbnail

    I filtered my photo collection for images of a particular person. The result was 2 images of the person concerned, both tagged correctly, and over 100 images of a totally unrelated event with no metadata or tags relating to the person I had searched/filtered for. The thumbnails of these images were marked with a tiny "No Parking" symbol at the upper right of the thumbnail. What does this symbol mean ?

    Thank you for this answer. This behaviour of the Organizer defies (my) logic. Why on earth does the Organizer show me items that do not match my tag selection ? The point of tagging and selecting images by tag should be to allow filtering of the images in the database and suppress items that do not match without my having to additionally select "Hide items that do not match"  as an Option. Or have I misunderstood something here ?
    Paddy
    P.S  When I click on Options it shows me "Show results that do not match (9261)". When I click on that the unwanted thumbnails that do not match disappear, i.e. exactly the opposite of what the menu option promises. If I then click on "Hide results that do not match (9261)" it shows me the thumbnails that do not match. The toggle seems to be working in a sense opposite to the correct/expected one. P.

  • Export works not correct in LR5.3; ignore image size.

    BUG: The export works not correct in LR5.3 When the field  "Dont enlarge" are activated Lightroom ingnores the settings of image sizing and export the pictures in original size. Where can fix it?

    Another option, if you're not into using plugins (Exportant) to fix:
    Export in 2 groups - those needing resizing and those that do not (e.g. using lib-filters or smart-collections):
    * Export those needing resizing normally (but with "don't enlarge" unchecked).
    * Export those not needing resizing without resizing.
    I mean, re-installing Lr5.2 may be a fine-enough work-around, but so ya know: Lr5.4 is likely to be out soon, with problem fixed...
    PS - Get Lr5.2 here:
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Windows
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Macintosh
    Rob

Maybe you are looking for

  • How to install SAP netweaver on windows XP / 2003 server

    hi all, i am new to SAP and trying to install SAP netweaver at my home PC. Appreciate if i could get the 'step by step installation guide' from this forum.. Please send it to [email protected] looking forward.. Rasul

  • How to use bind parameter in view object

    in my view object has parameter as below where :organization_id IS NULL :organization_id parameter get value from LOV I can run the page but it show following error : oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL

  • How to Clear if material received without PO

    Dear All, I have received materials without PO, Now I wanted to clear those without creating POs. For this I am using 501 (GR without PO) mvmt type to do the MIGO, Now my question is how can I do Invoice to vendor for this material. Please suggest...

  • Extension of BAPI's

    Baseline Information: -- We are running SAP ECC v6. -- We have added two new columns to the Equipment Master database, on the EQUI table.  These columns are entitled GUIDNO and Z_GISGRID.  These columns were added to the EQUI table within the SAP-del

  • Doubt on Sub routines

    Hi friends, I am using perform statement like perfrom get_data using gi_data changing gi_output. in the form of get_data i need to change gi_data but while coming out of form i need the gi_data to have the same value as i had before. Is using is not