Problems With Creating Group of Objects from a Collection

Hi, please kindly help.
I have a Collection. Its name is "activities". It is a collection of the Activity object with "color" as one of the attributes. I am writing a method and takes "activities" as a parameter (see below). The method is supposed to group "activities" by "color" and return a Collection called "activitiesGroups". And I have created an "activitiesGroup" (note: singular not plural) class with the getters and setters of all its attributes.
I first sorted the "activities" by color. So far so good. Thereafter, I am iterating through this sorted list. If activity.getColor().trim() is tested different, I know that a new group, i.e., activitiesGroup, should be created and I should code activitiesGroups.add( activitiesGroup );Problems are:
1. If I am at the first record of the sorted collection while iterating, I do not what to add a new group to the returned List activitiesGroups. I want to greate a new group only.
Because "colorString" is initialized as a blank, when I code activitiesGroups.add( activitiesGroup );, I depend on that I am not at the first record of the sorted collection by testing if colorString.length(); is not a zero. I do not think it is the correct way to do it.
What is the proper way of knowing I am at the first record of the sorted collection while iterating?
2. I have to sum up two of the attributes of the ActivitiesGroup object: increaseToValue and decreaseToValue. While iterating, I repeat for each record within a group:
aGroup.setIncreaseToValue( increase );
aGroup.setDecreaseToValue( decrease ); How do I avoid the repetition?
     private Comparator colorComparator;
     private List activitiesGroups;
     private ActivitiesGroup aGroup;
     private String colorString = "";
     private String nextColorString = "";
     private BigDecimal increase;
     private BigDecimal decrease;               
     public List groupingByColor( List activities ) {
          if ( activities == null) {
               return new ArrayList(0);
          if ( !activities.isEmpty() ) {
               Collections.sort( activities, colorComparator);  // It works.
               activitiesGroups = new ArrayList();
               Iterator it = activities.iterator();
               while ( it.hasNext() ) {
                    Activity activity = ( Activity )it.next();
                    nextColorString = activity.getColor().trim();                    
                    if ( !nextColorString.equalsIgnoreCase( colorString.trim() ) ) {
                         int length = colorString.length();
                         if ( length != 0 ) { activitiesGroups.add( aGroup ); } // Problem # 1
                         aGroup = new ActivitiesGroup();
                                                          aGroup.setColor( activity.getColor() );
                         increase = increase.add( activity.getIncreaseToValue() );
                         decrease = decrease.add( activity.getDecreaseToValue() );
                         aGroup.setIncreaseToValue( increase ); // Problem #2: repeated for every record in a group
                         aGroup.setDecreaseToValue( decrease ); // Problem #2: repeated for every record in a group
                    } else {
                        increase = increase.add( activity.getIncreaseToValue() );
                        decrease = decrease.add( activity.getDecreaseToValue() );
                        aGroup.setIncreaseToValue( increase ); // Problem #2: repeated for every record in a group
                        aGroup.setDecreaseToValue( decrease );      // Problem #2: repeated for every record in a group                         
                                                                colorString = nextColorString;
          return activitiesGroups;
     }

I first sorted the "activities" by color. So far so good. Thereafter, I am iterating through this sorted list. If activity.getColor().trim() is So in fact you are not dealing with an arbitrary Collection (as you stated in the first place), you are dealing with a List.
You should know that there is a way to do this just with an iterator on an arbitrary collection - without needing to sort your list, and do it in O(n) time.

Similar Messages

  • Problem with creating/viewing PDF's from InDesign CS3

    I have a problem with our PDF workflow and just cannot seem to resolve it.
    The problem is as follows: My coworker and I (both designers running CS3 on iMac's running 10.5.6 Leopard) work daily on producing documents and graphic layouts.
    Internally we can view and print PDF documents we create just fine with no troubles with the exception of our supervisor, who is running a mac with Tiger operating system. Our office environment is both Mac and PC. On may occasions he cannot print PDF's we create. Many times his prints will contain garbled characters, drop italics and formatting, replace fonts, or just print slowly.
    This problem is also happening to our editor who is offsite. This is a fairly serious problem for her, considering her job relies heavily on being able to view and open PDF files we create. She was able to send a PDF file which shows the garbled mess her printer spit out when she printed. Apparently there were pages upon pages of messy garbled text. When documents do print from her, they are usually very slow in printing, taking up to a minute or more to print each page.
    The sample of what she sent me is attached, and can also be found on my MobileMe iDisk at: http://public.me.com/rlcollier (document entitled Print Results.PDF)
    My question really to the community is obviously what might be causing these problems. Its very frustrating not being able to determine if its something we're doing ourselves thats causing some incompatability or corruption in these files, or if its the users systems themselves. I can say that Debra our editor has can have a garbled mess of a 4 page file from us, and then turn around and print a graphic heavy 90 page PDF with ease from Boeing. Our PDF's seem to be the only ones she struggles with. That being said, my inclination is that its something on our end.
    Any ideas of where to start looking? Any help at all would be greatly appreciated and welcomed. Thanks!

    I currently had our editor test printing of some of our files using both Foxit and Adobe Reader (as was suggested) in order to see if either made a difference in her printing ability and here is what she came back with:
    I tried to print out both these pdfs (David's is the one you reworked and Lisa's HESSM-3, both sent yesterday).
    With Adobe:  David's first page printed quickly, but it had errors (part of his pants didn't print, and there's an arbitrary shaded box in the text).  Page 2 didn't print--every time I tried it had a different "offending command" code.  Printing Lisa's HESSM  made it up to page 7 before problems showed up (stock photo only partially printed), and it stopped on page 8 (with the random "offending command" code).
    With Foxit:  Both David's and the HESSM pdfs printed completely and without error...but it took a long time.   David's 2 pages took about 3 to 4 minutes, and HESSM's 16 pages took close to 20 minutes.  The time is in the transfer of data to the printer; the physical printing  goes pretty quickly.
    I cant say that I believe email is the problem, although I cant rule it out. I've tested emailing vs. passing through our workgroup with my supervisor, and it does not make any difference in his ability (or lack of ability) to print our files. He was able to print to a different printer (an HP 4650 as opposed to a 4100) without troubles. He refuses to believe its a printer problem however because PDF files originating from our office are the only ones he has trouble with. Never has he had any trouble with a single PDF file produced from any other source. This is also the case for our editor who only has trouble with PDF files originating from either mine, or my coworkers systems.
    PS: I've attached both files that were referenced by our editor above for viewing/testing.

  • Problem with creating a new object

    It's my stupid simple code:
    class Readers {
         int i, a;
    public     Readers(int i, int a){
    public static void main(String[] args) {
    Readers[] d = new Readers[5];
    d[4] = new Readers(2,2);
    System.out.println(+d[4].i);
    Why do I get the answer 0, instead of 2?

    See the comments in your code:
    class Readers {
        int i, a; // the global variables 'i' and 'a' are both initialized with zero
        public Readers(int i, int a){
            // the local values 'i' and 'a' are lost: you don't do anything with them!
        public static void main(String[] args) {
            Readers[] d = new Readers[5];
            d[4] = new Readers(2,2);
            System.out.println(d[4].i);
    } // note that you don't need semi-colons after a '}'

  • Please help with creating a summary report from data collected in a fillable PDF form.

    I'm sure this has been asked before so I apologize in advance - I'm new to this forum and I'm not quite sure of which section I should be in. If I may just describe a certain scenario of something I am trying to create - could you please point me in the right direction?
    I'm looking to create a summary report/form to help me better organize my patients after each appointment. So data collected from other fillable forms I've created, will lead to the final page to print that will include selections from fillable text boxes or drop down lists, etc to basically summarize each encounter. It should go something like this:
    FORM 1:
    -pt chart #
    -pg age
    -purpose for visit
    -date of visit
    -diagnosis
    -prognosis
    -etc
    SUMMARY page
    On (-date of visit), patient (-pt chart #) arrived with complaint of (-purpose for visit)....
    The diagnosis was determined to be (-diagnosis), treatment to be performed is suggested to be (-treatment) with a (-prognosis) prognosis. Treatment was (accepted or not) and completed on... etc. etc... you get the idea
    Does anyone know how I can do this?
    Thank you all for your time and advice!

    I have downloaded Castor and got some good tutorials, but.......
    There is a problem, when I try to use the Marshaller to get an XML document the following error is reported:
    java.lang.NoClassDefFoundError: org/apache/xml/serialize/XMLSerializer
    I have scanned the Internet looking for a solution, some recommend including Xecers in the Classpath. I downloaded Xerces 2.7.1 and added it to as instructed but this did not work.
    Hope you can help

  • Problem with create universe on Business Objects XI 3.1 base on SAP Query

    Hello,
    I have a problem with create universe on Business Objects XI 3.1 base on SAP Query.
    The problem is hierarchy. Massage on Busines Objects is :
       OWBS_ELEMT__ISTKOSZT(cube ICPC01/BEX_ICOC01):Exception condition  "HIERARCHY NOT FOUND" raised.(WIS 10901) 
    Query in BEX run OK.
    Best regards.
    Ela.

    Hello,
    Thanks for response.
    When I run BEX QUERY, all works OK.
    All hierarchies was created and activated  on system BW.
    This situation appears after upgrade BW to SAP NetWeaver 7.3.
    Before upgrade I created universe without any problems.
    Regards Ela

  • Unable to create a Driver object from driver with Media type string CTC PHO

    Hi All,
    I am trying to develop a siebel cti adapter for avaya.
    I have loaded a custom dll into siebel server but it is throwing error "SBL-CSR-00500: Unable to create a Driver object from driver C:\Mydriver\cti.dll with Media-Type-String CTC Phone ".
    It has been long time without any progress.
    Please help
    Thanks
    Nishant

    Hi tomhowell,
    According to your description, my understanding is that you got an error when you created a site from a custom site template after migrading SharePoint 2010 to your server.
    Did you have the original solution file of the site template? Please re-deploy the solution to your SharePoint site, then create a site from the new site template, compare the result.
    Also use  SPDisposeCheck to indentify the memory leak:
    http://archive.msdn.microsoft.com/SPDisposeCheck
    http://www.fewlines4biju.com/2012/11/detected-use-of-sprequest-for.html
    Here are some similar posts for your reference:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/3a25eb86-8415-4053-b319-9dd84a1fd71f/detected-use-of-sprequest-for-previously-closed-spweb-object-please-close-spweb-objects-when-you?forum=sharepointdevelopmentprevious
    http://social.msdn.microsoft.com/Forums/en-US/50ce964f-94a6-4fda-abc0-caa34e7111f1/error-detected-use-of-sprequest-for-previously-closed-spweb-object-occurs-when-new-site-gallery
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Problem with creating site from another computer!

    Hi
    I have WebDB 2.2 and Oracle8i instaled on the same computer. I have a problem to create site from another computer. There is not any process when I try to create site. There is always 0%.
    But I have no problem with creating site on the origin computer.
    Does anybody know something about it?

    I am just not clear what to do once I have made changes and have published the new information.
    You shouldn't have to do anything. iWeb will save the information in the Domain.sites file. You can keep this file in a folder, or even on your desktop and iWeb will launch from a double-click on the file.

  • Problem with creating new user in portal = portlet is not visible

    Hi,
    I've got a problem with creating new users in portal. In the Administer tab of the builder is the user portlet not visible.
    How can I make this portlet visible?
    Please Help
    thank you...
    Gilbert

    Hi..my problem slightly similar.
    I created one new user, and didn't select anything from "Public Groups Assignment" and "Privilege Assignment" for him.
    I expect the user will be a public user.
    But, when he try to logged in the portal,
    He cannot see all the PORTLETS related to database values..
    All he can see just LINKS -that all in my portal right now beside the report from database that the user cannot see :)
    So, what did i do wrong?
    Plz Advise, and thanks.

  • Can I create a network object from CIDR format or do I need to use IP - netmask?

    Have a cisco ASA running ASA V 8.3
    Wondering what the correct syntax is or even if it is possible to create a network object from a list of IP's in CIDR format? 
    Typically just do this:
    Create network-object
    object-group network name
    network-object 1.2.3.0 255.255.255.0
    Would like to do this: 
    network-object 1.2.3.0/24
    thanks!

    Hi,
    As far as I know the ASA does not support entering a network/subnet mask in such format in any of its configurations.
    - Jouni

  • How to create a Document object from a string.

    If I use the following code, the input String cannot contain "\n", otherwise, it generates errors.
    in the following code, inputXMLString is a String object that has xml content.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(inputXMLString)));          How can I create a Document object from a string with "\n" in the string?
    Thanks.

    If I use the following code, the input String cannot
    contain "\n", otherwise, it generates errors.That's going to be a huge surprise to thousands of people who process XML containing newline characters every day without errors.
    Perhaps your newline characters are in the middle of element names, or something else that causes your XML to be not well-formed. I'm just guessing here, though, because you didn't say what errors you were getting.

  • Create internet explorer object from process ID

    Hi,
    I want to create a object for open instance of internet explorer and pass username and password to it.
    By using the below command I am getting the process object but how can we create internet explorer object from it so that I can access document elements.
    gps | ? {$_.mainwindowtitle -match 'Service'} | select name, mainwindowtitle
    Thanks
    Prasanna

    Hi Prasanna,
    If you means create IE object and signin automatically with username and password, the script below is for your reference:
    $username = "....."
    $password = "......"
    $ie = New-Object -com InternetExplorer.Application
    $ie.visible=$true
    $ie.navigate("https://login.live.com/")
    while($ie.ReadyState -ne 4) {start-sleep -m 100}
    $ie.document.getElementById("i0116").value= $username
    $ie.document.getElementById("i0118").value = $password
    $ie.document.getElementById("idSIButton9").click()
    start-sleep -m 100
    gps | ? {$_.mainwindowtitle -match 'Microsoft account'} | select name, mainwindowtitle
    The result like:
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Problem with creating chapter-markers

    Hi everyone,
    as the title already says it, I've got a problem with creating chapter markers in Quicktime Pro 7.6.4. There's something wrong with the font, displayed in Quicktime. The problem first appeared a few days ago. Before this, everything went fine and I don't have a clue what causes the problem.
    Please click HERE to see a screen-recording of the steps I do to create chapters:
    - convert the chapters into unformatted text and save it as Unicode (UTF-16) text file.
    - open it in Quicktime and everything (including the german umlauts) is displayed correct.
    - export it into a Text-file with description
    when I open the new text file in Quicktime, the fonts are displayed in asian letters, but when I view it in the Texteditor, the text is almost correct, BUT the umlauts are not ok. So I go on with...
    - correct the umlauts and save a new file as Unicode (UTF-16) again.
    After I open the new file in Quicktime, the text is completely gone. As the text file seems to be ok in the Texteditor, I guess there must be something wrong with Quicktime. I tried to reinstall Quicktime 7 from the "Mac OS X 10.6 Snow Leopard" Installation-Disc, but the problem persists.
    I' would appreciate any help...
    Thanks in advance and best regards,
    Michael

    I'm having the exact same issue. I have created my movie in IMovie 09 then under the "share " menu I sent the movie to iDVD. Everything looks fine on screen, but all I get on the final product is the movie.
    After digging deeper into the tutorials all they show is dragging a movie into the idvd shell, not sharing via imovie.
    Thus I'm currently attempting to create a quicktime movie then drag it into the IDVD shell. I think that way the chapter markers and everything should show up and burnt into the final project. I'm guessing the "share" option with the IDVD from iMovie doesn't work properly???

  • Problem with creating virtual column

    Hello,
    We've got problem with creating virtual column.
    There is table R_T that contain columns R_ID and L_ID, we would like to create virtual column RL_ID that contains sth like 'R_ID-L_ID' (R_ID, L_ID and RL_ID are varchars).
    According documentation we've tried:
    alter table R_T add column (RL_ID varchar2(60) generated always as (R_ID||'-'||L_ID) VIRTUAL)
    but getting
    ORA-00904: : invalid identifier
    00904.00000 - "%s: invalid identifier"
    Have no idea where is the problem.
    Table, columns names are little different but contains only capital letters A - Z and underscore "_".
    Has anyone idea?
    Thanks a lot.

    Strange...
    This does work for me :
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Connected as dev
    SQL>
    SQL> create table r_t (
      2   r_id varchar2(25),
      3   l_id varchar2(25)
      4  );
    Table created
    SQL> insert into r_t (r_id, l_id) values('R','L');
    1 row inserted
    SQL> alter table r_t add (rl_id varchar2(60) generated always as (r_id||'-'||l_id) virtual);
    Table altered
    SQL> select * from r_t;
    R_ID                      L_ID                      RL_ID
    R                         L                         R-L
    SQL>

  • Strange Problem with Code Groups / Codes

    Hey all, have a strange problem with Code Groups and Codes.
    Our data migration team accidentally loaded an early version of our catalog (code groups and codes) in to our 'Gold' configuration client. They then proceed to delete them all via transaction qs41. However, the code groups have been deleted, but not the codes.
    So, basically, no codes groups exist in table QPGR or QPGT but all the entries remain in QPCD with the assigment to code groups. The usage indicator is not set on the codes so why they did not get deleted with the codes groups is unknown.
    The issue that this is now causing us is that we can't recreate the codes groups with these codes assigned as the system thinks they already exist (via a check on table QPCD i would expect).
    Also, i have been unable to recreate what happened did in other clients... seems very strange.
    Any help appreciated.
    Cheers

    Ben,
    You could try SE11, and see if you can delete the records from there.. but I'm not hopeful...
    Otherwise you may need to write a quick ABAP program to delete the data base entries.
    PeteA

  • OneKey Recovery 6.0. Problem with back up operating system from recovery cd'ies

    Hello, i have problem with back up operating system from recovery cdies.
    When i acceped start button to backup partition system i get an alert "space not enough"
    I had linux before and i whant change it to windows back. i deleted all ext partitions. I have all unlocated space.I shouldnt have problems.
    Please help me

    I would use something like Partition Magic or Acronis Disk Director to first create a FAT32 partion for your C: Drive where your OS will go and be sure to leave 10GB or so unallocated for the secondary FAT32 Partition where your "factory image" will go. 
    You then create a Logical Drive with the unallocated space and make it hidden (PM or ADD will do this).   Install your OS (preferably Windows XP if you want less problems) and then after you have setup everything the way you want (drivers, applications, etc), then use Acronis True Image to create your "factory restore" image on the hidden partition and activate the Startup Recovery Manager.
    This is the way I do it and it works like a charm!

Maybe you are looking for

  • Organizer is extremely slow opening in PSE9

    Organizer is extremely slow opening in PSE9 , It take  about  5 min to open Organizer !!!! After the organizer work find I have reinstall PSE9 without success , any sugestions ?

  • Decimal space problem in Condition value of Import PO

    Dear All, In PO the condition value found to be 0.00. When the problem explored,we find only 2 decimal places appears for the value. If the value is 0.0021,it appears as 0.00 only due to decimal space given in KOMV(structure) against KWERT field is 2

  • Preinstalled songs cannot be played

    Hello All, Last night I've updated my Nokia 5800 firmware to the v20.0.012 but I am surprised to see that now I am unable to play the preinstalled songs available on my device... Can anyone let me know whats wrongs!!!!!!!!!!!! Regards, rohit

  • Where to write connection code?

    Hai, In Flex,where we have to write the stratus connection code? Is it outside the script or inside?

  • How can i open, edit, view .xfdl files

    I am trying to work on military files that are sent from Windows based products and are formatted as .xfdl.  How can I open, print or edit as neccessary?