How to sort a Vector that stores a particular object type, by an attribute?

Hi guys,
i need help on this problem that i'm having. i have a vector that stores a particular object type, and i would like to sort the elements in that vector alphabetically, by comparing the attribute contained in that element. here's the code:
Class that creates the object
public class Patient {
private String patientName, nameOfParent, phoneNumber;
private GregorianCalendar dateOfBirth;
private char sex;
private MedicalHistory medHistory;
public Patient (String patientName, String nameOfParent, String phoneNumber, GregorianCalendar dateOfBirth, char sex) {
this.patientName = patientName;
this.nameOfParent = nameOfParent;
this.phoneNumber = phoneNumber;
this.dateOfBirth = dateOfBirth;
this.sex = sex;
this.medHistory = new MedicalHistory();
Class that creates the Vector.
public class PatientDatabase {
private Vector <Patient> patientDB = new Vector <Patient> ();
private DateFunction date = new DateFunction();
public PatientDatabase () throws IOException{
String textLine;
BufferedReader console = new BufferedReader(new FileReader("patient.txt"));
while ((textLine = console.readLine()) != null) {
StringTokenizer inReader = new StringTokenizer(textLine,"\t");
if(inReader.countTokens() != 7)
throw new IOException("Invalid Input Format");
else {
String patientName = inReader.nextToken();
String nameOfParent = inReader.nextToken();
String phoneNum = inReader.nextToken();
int birthYear = Integer.parseInt(inReader.nextToken());
int birthMonth = Integer.parseInt(inReader.nextToken());
int birthDay = Integer.parseInt(inReader.nextToken());
char sex = inReader.nextToken().charAt(0);
GregorianCalendar dateOfBirth = new GregorianCalendar(birthYear, birthMonth, birthDay);
Patient newPatient = new Patient(patientName, nameOfParent, phoneNum, dateOfBirth, sex);
patientDB.addElement(newPatient);
console.close();
*note that the constructor actually reads a file and tokenizes each element to an attribute, and each attribute is passed through the constructor of the Patient class to instantiate the object.  it then stores the object into the vector as an element.
based on this, i would like to sort the vector according to the object's patientName attribute, alphabetically. can anyone out there help me on this?
i have read most of the threads posted on this forum regarding similar issues, but i don't really understand on how the concept works and how would the Comparable be used to compare the patientName attributes.
Thanks for your help, guys!

Are you sure that you will always sort for the patient's name throughout the application? If not, you should consider using Comparators rather than implement Comparable. For the latter, one usually should ensure that the compare() method is consistent with equals(). As for health applications it is likely that there are patients having the same name, reducing compare to the patient's name is hazardous.
Both, Comparator and Comparable are explained in Sun's Tutorial.

Similar Messages

  • How to include the ordinary program in the BOR object type program

    Hi Guys, while i am trying to include a program in the BOR object type program. It is showing the following error:
    "Statement 'INCLUDE Z_ERC_SEARCH_VALOFACT_MACRO .' is not permitted in BOR".
    then, i tried to add  "<" and ">" to enclose it, but it wants the access key to create it.   anyone knows how to add the ordinary program in the BOR object type program.

    It's correct that we CAN'T insert our INCLUDES in BOR program. We CAN only use TYPE-POOLS there. So you can create Type Group with TYPES, CONSTANTS and DEFINE statements, and then use them in BOR programs.
    Using DEFINE you can construct MACROs with parameters and call your code there. It's limited, and not the easiest way, but some things can be achieved this way. Also forget about using Code Patterns while editing Type Group.
    Note: Use TYPE-POOLS statement after INCLUDE statement in BOR program .
    Best regards,
    Tomas.

  • Track the qeries that accessed a particular object during a time period

    HI,
    I have a list of objects on my schema and i need to track the list of sql queries by different users that accessed by object during this time period.
    i haven't enabled any auditing yet.
    is there any way i can get that list of queries and their schemas that accessed those particular objects during a particular time period.
    Can someone guide me please.
    Thanks in advance.
    Philip.

    Too bad you don't have a version number. Oracle functionality changes from version to version and in some versions you can do this and in some you can not.
    Look here for one way to accomplish the task:
    http://www.psoug.org/reference/dbms_fga.html
    Here for another:
    http://www.psoug.org/reference/audit_vault.html
    Here for another:
    http://www.psoug.org/reference/dbms_logmnr.html
    Consider posting more information when asking questions in the future.

  • How can I sort a collection of array with different object types in it ?

    Hi all,
    I have a collection of ArrayList; each array contains, at the first position, the same object type.
    I'd like sorting the collection by the name contained in the object at the first position of each array.
    Any suggestion ?
    Cheers.
    Stefano

    so you have a collection of a collection?
    My guess is that:
    You could subclass the arraylist and override it's compareTo method (I think that it implements comparable already but if not, go ahead and implement that interface).
    Or you could wrap your arraylist in another class that implements comparable.
    The key in my mind is correctly coding your compareTo method to look at the name in the first item of the arraylists. This should be doable and not too difficult.
    Correction: after reviewing the ArrayList api, I see that it doesn't implement the Comparable interface. You will have to make any class that either inherits arraylist or contains arraylist implement the comparable interface.
    One last thing: This question would probably have been better off in the java forum and not the Swing forum since it doesn't really involve Swing.
    Good luck!
    Edited by: petes1234 on Nov 19, 2007 6:17 AM

  • Invoking stored procedure that returns array(oracle object type) as output

    Hi,
    We have stored procedures which returns arrays(oracle type) as an output, can anyone shed some light on how to map those arrays using JPA annotations? I tried using jdbcTypeName but i was getting wrong type or argument error, your help is very much appreciated. Below is the code snippet.
    JPA Class:
    import java.io.Serializable;
    import java.sql.Array;
    import java.util.List;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import org.eclipse.persistence.annotations.Direction;
    import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
    import org.eclipse.persistence.annotations.StoredProcedureParameter;
    * The persistent class for the MessagePublish database table.
    @Entity
    @NamedStoredProcedureQuery(name="GetTeamMembersDetails",
         procedureName="team_emp_maintenance_pkg.get_user_team_roles",
         resultClass=TeamMembersDetails.class,
         returnsResultSet=true,
         parameters={  
         @StoredProcedureParameter(queryParameter="userId",name="I_USER_ID",direction=Direction.IN,type=Long.class),
         @StoredProcedureParameter(queryParameter="employeeId",name="I_EMPLOYEEID",direction=Direction.IN,type=Long.class),
         @StoredProcedureParameter(queryParameter="TEAMMEMBERSDETAILSOT",name="O_TEAM_ROLES",direction=Direction.OUT,jdbcTypeName="OBJ_TEAM_ROLES"),
         @StoredProcedureParameter(queryParameter="debugMode",name="I_DEBUGMODE",direction=Direction.IN,type=Long.class)
    public class TeamMembersDetails implements Serializable {
         private static final long serialVersionUID = 1L;
    @Id
         private long userId;
         private List<TeamMembersDetailsOT> teamMembersDetailsOT;
         public void setTeamMembersDetailsOT(List<TeamMembersDetailsOT> teamMembersDetailsOT) {
              this.teamMembersDetailsOT = teamMembersDetailsOT;
         public List<TeamMembersDetailsOT> getTeamMembersDetailsOT() {
              return teamMembersDetailsOT;
    Procedure
    PROCEDURE get_user_team_roles (
    i_user_id IN ue_user.user_id%TYPE
    , o_team_roles OUT OBJ_TEAM_ROLES_ARRAY
    , i_debugmode IN NUMBER :=0)
    AS
    OBJ_TEAM_ROLES_ARRAY contains create or replace TYPE OBJ_TEAM_ROLES_ARRAY AS TABLE OF OBJ_TEAM_ROLES;
    TeamMembersDetailsOT contains the same attributes defined in the OBJ_TEAM_ROLES.

    A few things.
    You are not using a JDBC Array type in your procedure, you are using a PLSQL TABLE type. An Array type would be a VARRAY in Oracle. EclipseLink supports both VARRAY and TABLE types, but TABLE types are more complex as Oracle JDBC does not support them, they must be wrapped in a corresponding VARRAY type. I assume your OBJ_TEAM_ROLES is also not an OBJECT TYPE but a PLSQL RECORD type, this has the same issue.
    Your procedure does not return a result set, so "returnsResultSet=true" should be "returnsResultSet=false".
    In general I would recommend you change your stored procedure to just return a select from a table using an OUT CURSOR, that is the easiest way to return data from an Oracle stored procedure.
    If you must use the PLSQL types, then you will need to create wrapper VARRAY and OBJECT TYPEs. In EclipseLink you must use a PLSQLStoredProcedureCall to access these using the code API, there is not annotation support. Or you could create your own wrapper stored procedure that converts the PLSQL types to OBJECT TYPEs, and call the wrapper stored procedure.
    To map to Oracle VARRAY and OBJECT TYPEs the JDBC Array and Struct types are used, these are supported using EclipseLink ObjectRelationalDataTypeDescriptor and mappings. These must be defined through the code API, as there is currently no annotation support.
    I could not find any good examples or doc on this, your best source of example is the EclipseLink test cases in SVN,
    http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/plsql/
    http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/customsqlstoredprocedures/
    James : http://www.eclipselink.org

  • How to findout the Function module for a particular object

    Hello friends,
       Related to my thread, there was one thread in the forum,to find out the function module for a particular object.I tried the solution provided my our experts but couldn't got the results.Thats why i am putting this thread again.
      I want to find out the function modules used for the particular object, i.e. Production order.
       solution i tried is, first go to T.C SE37, then in function module field put the object name like Production order and enter, than it will show another screen, there also put object name in function module field and than press enter, it will show all the function modules available for that object.
        So could you guys help me out to find out where i am wrong in the process of finding out the function module for a particular object.
                           Plz don't bother abt the point.Helpful answers will definitely get awarded.
                                Thanking you guys for your valuable support till now and hoping to get in future too.

    Dear
    When the problem is solved please give points too. Otherwise why people will help others, give time and share their valuable knowledge. This will build up self confidence.
    If not solved and closing, then mention the difficulties what u exactly looking for. Simpy closing is not enough because who ever is providing solution will not able to know the real problem.
    How to give points I believe u already know that and need not explain.
    I had seen many times this problem with others too. Even if the problem is totally resolved they give 2 in stead of 10.
    Edited by: BNR on Sep 21, 2008 6:10 PM

  • How to give authorization for create and change particular Condition Type

    Hi...
       In my requirement is , Only one user can be authorized to create and change a particular condition type 'ZABC' in vk11 and vk12 .
    For remaining condition type can be used as in normal .
    How to do this ? How to give authorization for a particular user for particular condition type ?
    Plz guide me ..
    Thanks in advance .
    Deepa .

    Hi Deepa ,
    u can check A.Object V_KOND_VEA, in user profile u can assign condition type or tables.
    have a word with ur basis guy , so he can help u in better way.
    aand also ref FM SD_COND_AUTH_CHECK
    Regards
    Prabhu

  • How to sort a sortingTable based on a particular column available in it?

    Hi,
    I am using the sortingTable as follows:
    <Field name='WorkItemTable'>
    <Display class='SortingTable'>
    <Property name='linkEnable' value='true'/>
    <Property name='sortEnable' value='true'/>
    <Property name='columns'>
    <List>
    <String>PROCESS</String>
    <String>DESCRIPTION</String>
    <String>DATE</String>
    </List>
    </Property>
    </Display>
    I need to sort the table's value with respect to 'Date' column available in the sorting table.
    I have used the following property tag under sortingTable.
    <property name='sortEnable' value='true'/>
    But i need to point this sorting functionality to date column..
    Can someone help me to get the solution... Thanks in advance..
    Regards,
    babu

    Hi,
    I am using IdM 7.1 and I observed that default sorting table used by idm for e.g at server task page, doesn't sort on date basis.
    ~Ketan

  • How can i find  out field for a particular component type

    hi,
    how can i find out for particular component name is belongs to this field.....that means REF_DOC_NO componemt is belongs to xblnr field ..../.if we know only component type ...how to find the field...
    plz tell me
    thanks&regards,
    kalyan

    keep the cursor on component
    press F1
    select technical information
    you will find the field name and table or structure name
    regards
    sateesh

  • How do I update a Nested Table of inherited Object Types?

    Does anyone know why the following line (commented out) doesn't work and what I can do? Is there some way to cast the column I am trying to update? I think I am going crazy....
    create or replace type person_ot as object (name varchar2(10)) not final;
    create or replace type student_ot under person_ot (s_num number) not final;
    create type person_tt as table of person_ot;
    declare
    lv_person_list person_tt;
    lv_sql varchar2(1000);
    ref_cur sys_refcursor;
    begin
    lv_sql:= 'select new student_ot(''fred'', 100) from dual
    union all
    select new student_ot(''sally'', 200) from dual';
    open ref_cur for lv_sql;
    fetch ref_cur bulk collect into lv_person_list;
    close ref_cur;
    dbms_output.put_line(lv_person_list.count);
    for i in lv_person_list.first..lv_person_list.last loop
    lv_person_list(i).name := initcap(lv_person_list(i).name ); -- This works!
    lv_person_list(i).s_num := 9999;  Why doesn't this line work and how can I update the column s_num ??? :-(
    end loop;
    end;
    /

    Hi Tubby - You are right...It would make sense to create the Type as type of student_ot. Only problem is I am trying to keep it generic. I will include full listing to show what I am doing...
    create or replace type person_ot as object (name varchar2(10)) not final;
    create or replace type student_ot under person_ot (s_num number) not final;
    create type person_tt as table of person_ot;
    create table persons of person_ot;
    declare
    lv_person_list person_tt;
    lv_sql varchar2(1000);
    ref_cur sys_refcursor;
    begin
    lv_sql:= 'select new student_ot(''fred'', 100) from dual
    union all
    select new student_ot(''sally'', 200) from dual';
    open ref_cur for lv_sql;
    fetch ref_cur bulk collect into lv_person_list;
    close ref_cur;
    for i in lv_person_list.first..lv_person_list.last loop
    lv_person_list(i).name := initcap(lv_person_list(i).name );
    lv_person_list(i).s_num := 9999;*                             Why doesn't this line work?? :-(
    end loop;
    forall i in lv_person_list.first..lv_person_list.last
    insert into persons values lv_person_list(i);
    end;
    /

  • How to find the corresponding programs for a particular condition type

    Hi experts,
    I have one condition type( KSCHL ).
    I need to find the programs where this condition type is used.
    Thanks in Advance.

    Dear Nagireddy,
    You have to go further by using where-use list option(Arrow Direction Icon) from SE11 or from SE38 editor. Then the system will show you the places where the condition type KSCHL is being used.
    Thanks & Regards,
    Dinesh

  • How to attach an img activity to a particular object in your transport

    hi all
    i am new to sap and need your help !
    i have a customizing transport request to which i have a particular object. i need to attach an img note/img activity to this object in the TR.
    the img activity i need to attach in also existing in the tcode spro.
    pls advise
    mridula

    You're welcome!
    As a follow-up, the formula type is 'Element Skip' and for a formula to only process in January, it might do something like this:
    /* Use of DB item 'PAY_PROC_PERIOD_END_DATE' to secure current month assumes the
    DB item is available to formula type 'Element Skip' - it should be as 'Element Skip' has context
    on PAYROLL_ACTION_ID which the DB item needs.
    If not then a suitable pl/sql function will be needed instead */
    DEFAULT FOR PAY_PROC_PERIOD_END_DATE IS '31-DEC-4712' (date)
    curr_month = TO_CHAR(PAY_PROC_PERIOD_END_DATE,'MON')
    IF curr_month = 'JAN' THEN
    (Skip_flag = 'N')
    ELSE
    (Skip_flag = 'Y')
    RETURN Skip_flag
    NB this is untested and of course carries no warranty of its suitability etc etc so please test thoroughly in a safe environment!
    Hope it helps
    Clive

  • How do i use Vectors?

    Hi,
    I am getting a list of documents information from the db and to display them into html tables.The problem is how can i use Vectors to store the information so that i can list them using for loop?
    String sql = "SELECT * FROM Document";
              System.out.println("manageUser.jsp sql: "+sql);
              ResultSet rs = db.ExecuteSQL(sql);
              if(rs.next()){
              name = rs.getString("Name");
                   System.out.println("manageUser.jsp Name: "+name);
                   title     = rs.getString("Title");
                   System.out.println("manageUser.jsp Title: "+title);
                   date     = rs.getString("DateEntry");
                   System.out.println("manageUser.jsp Date: "+date);
                   path     = rs.getString("Path");
                   System.out.println("manageUser.jsp Path: "+path);
                   docTypeNo     = rs.getString("DocumentType");
                   System.out.println("manageUser.jsp docTypeNo: "+docTypeNo);
                   comment = rs.getString("Comment");
                   System.out.println("manageUser.jsp Comment: "+comment);
    }

    I'd load the values into a data structure and put those into the page scope for the JSP to pick up.
    You can create a List of Maps, one Map per row, where each Map has the column name as the key and the SELECT result as the value. That'll let you iterate through to display the values in an HTML table in your JSP. - MOD

  • How to sort video by file name in Event Library?

    How to sort? so that I many all clips sorted by name and can drag them all to my project to create quick movie that has correct date and time sequence, as the file name.
    Thanks!

    I cannot figure out how to sort the clips either....

  • How to sort a collection by two componets/Attributes

    Hello All,
    Scenario:
    I have a result table view with columns Contact Person Number, Central Block flag and Last name. At the instance of BP confirmation in IC this result table(result view displays the contact persons associated with the account id during the BP cofirmation) is filled in a sorted order based on the Contact Person Number.
    Requirement:
    Sort the result table by Central block flag followed by Contact Last Name.Hence how to sort the collection of the result table view based on two attributes Central Block and Last Name?
    Looking forward for your support.
    Regards,
    Harish P M

    Hello Harish,
    Good question. The framework doesn't seem to support this. When i needed this functionality, i had to create my own implementation of collection. You can inherit from CL_CRM_BOL_ENTITY_COL and overwrite several methods which do the sorting. Check the class CL_CRM_IPM_RAA_BOL_COL.
    Best Regards,
    Yevgen

Maybe you are looking for

  • Apple ID to App purchase, how many?

    Ok...So currently with our elementary school we have 50 iPads in use. Since it is an elementary level the students DO NOT have their own Apple ID's for use with the iPads and we have all 50 iPads hooked into the same account regarding the app store a

  • Albums not showing up in Internet Explorer?

    I have created and published my website through iWeb. It displays well in a few browsers but there are issues in IE. In IE you cannot access the albums. It doesn't show they are active when the mouse goes over them and do not even function in IE. Als

  • How to create a "dummy" layer to link other layers to the dummy.

    Here is my problem: I have a bunch of Layers, I want to behave the same way (here scaling, but I had also rotation before). My approach (as used formerly with my 3D applications) is to create a "dummy" layer, where the channnels of the other layers a

  • Editing two pieces of video simultaneously in iMovie.

    Hi, I'm editing a music video. I have my audio in the bottom of the 3 bars in iMovie. The top one is the one for the video but I don't seem to be able to get any more video footage up along side it so I can synch it up with the track. I don't want to

  • Lync 2010 Recurring meetings don't work post-migration when 2010 server is shut down

    I've got an interesting issue here. I completed my Lync Server 2010 -> 2013 migration about 6 months ago, and everything has been going fine as far as I can tell. I left one of the servers up and running in the 2010 pool for a while. I finally decide