• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Removing Duplicate Objects from Combined Arrays?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Removing Duplicate Objects from Combined Arrays?


  • Subject: Removing Duplicate Objects from Combined Arrays?
  • From: Janice Cheung <email@hidden>
  • Date: Wed, 20 Oct 2004 14:31:05 -0400

        Greetings!

        I have a question concerning removing duplicate objects from two (combined) arrays:

        I have the following code to combine two arrays (flattened relationships), select
        the Unique Set of objects, and then do a sortOrdering to list these objects in alphabetical
        (ascending) order.  Please view below:

        public NSArray getAllDepartments() {
         NSArray a = (NSArray)storedValueForKey("affiliations_department");
         NSArray b = (NSArray)storedValueForKey("deptAdmins_department");
    
           if (a == null && b ==null)
            return NSArray.EmptyArray;
       
            NSMutableSet ms = new NSMutableSet();
            ms.addObjectsFromArray(a);
            ms.addObjectsFromArray(b);
            NSArray originalListWithDuplicates = ms.allObjects();
            NSSet uniqueingSet=new NSSet(originalListWithDuplicates);
            NSArray newListWithoutDuplicates=uniqueingSet.allObjects();
     
            EOSortOrdering ordering1 = new EOSortOrdering("departmentName", EOSortOrdering.CompareAscending);
            NSMutableArray sortOrdering = new NSMutableArray();
            sortOrdering.addObject(ordering1);
            return EOSortOrdering.sortedArrayUsingKeyOrderArray(newListWithoutDuplicates, sortOrdering);
        }

   
    Basically, "affiliations_department" and "deptAdmins_department" are two flattened relationships in
       the Person object class.  I was hoping that the code authored by James O'Loughlin on Duplicate Objects

       http://wocode.com/cgi-bin/WebObjects/WOCode.woa/2/wa/ShareCodeItem?itemId=334&wosid=NLBn8lO0hpPmSvpCCgeqR0
   
       would work, but I've deduced that I'm something in the implementation, as duplicate objects are appearing here,
       there, and everywhere!  I have been tinkering with this code, to no avail. 

       Am I inappropriately manipulating these flattened relationship NSArrays? 

       Any advice or guidance would be greatly appreciated!

       Thanks for your help!

       Best regards,
       Janice

       P.S.  I initially attempted to add the Project Wonder ERX framework to my application in XCode, (to remove duplicates) .. but
               I came across some inexplicable (and downright intimidating) compilation errors, so I temporarily fled that fear of
               the unknown to return to my current (and yes, equally sad) state of befuddlement.

               Thanks for helping me!
      

      
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Removing Duplicate Objects from Combined Arrays?
      • From: Kaj Hejer <email@hidden>
    • Re: Removing Duplicate Objects from Combined Arrays?
      • From: David Aspinall <email@hidden>
  • Prev by Date: Re: DB2 Support
  • Next by Date: Databse connection keep alive
  • Previous by thread: Re: DB2 Support
  • Next by thread: Re: Removing Duplicate Objects from Combined Arrays?
  • Index(es):
    • Date
    • Thread