How to sort a object vector by its integer item ?

hi everybody,
[there were few topics on this in the forum, but nothing could solve my problem yet. so, please instruct me]
I have to sort a vector which contains objects, where each object represents, different data types of values,
ex: {obj1, obj2, obj3, ....}
obj1---->{String name, int ID, String[] departments}
i have to sort this vector at three times, once by name, then by ID and then by departments.
Leaving name and department , first i want to sort the ID of each object and then re-arrange the order of objects in the array according to new order.
what i did was, copied the vector all objects' ID values to an integer array then i sorted it using selection sort. but now i want to re-arrange the vector, but i still can't. please guide.
here is the sort i did, and the
int[] ID = new int[mintomaxID.size()];
          for(int i=0;i<mintomaxID.size();i++)
               ObjectStore_initialData obj_id = (ObjectStore_initialData)mintomaxID.elementAt(i);
               ID[i] = obj_id.getID();
          System.out.println("Before sorting array");
          for(int i=0;i<ID.length;i++)
               System.out.println(ID);     
          System.out.println();
          int i, j, m, mi;
for (i = 0; i < ID.length - 1; i++) {
/* find the minimum */
mi = i;
for (j = i+1; j < ID.length; j++) {
if (ID[j] < ID[mi]) {
mi = j;
m = ID[mi];
/* move elements to the right */
for (j = mi; j > i; j--) {
ID[j] = ID[j-1];
ID[i] = m;
System.out.println("After sorting array");
for(int y=0;y<ID.length;y++)
               System.out.println(ID[y]);     
//*****here is where i need to re-arrange the entire vector by ID.
I do understand this is some sort of database sort type of a question. but there's no database. it's simply i just want to sort the vector.
Thank you.

hi camickr,
thank you for the detailed reply. but i still don't understand somethings. i tried to read the API and look for the collections.
i have ObjectStore_initialData class (similar to person class), so do i still have to do a comparable class out of this class ? please simplify that.
public class ObjectStore_initialData
     String NAME;
     int ID;
     String[] DPART;     
     public ObjectStore_initialData(String name, int id, String[] departments)
          NAME=name;
          ID=id;
          DPART = departments;
public String getName()//----
          return NAME;
public String getID()//----
          return ID;
public String getDpart()//----
          return DPART;
/*next class is the interface to collect the values from the user and put all of them at once in a vector*/
//this class is to sort the vector by ID
public class sorter
   public sorter()
   public static void sortbyID(Vector mintomaxID)
         int[] ID = new int[mintomaxID.size()];
          for(int i=0;i<mintomaxID.size();i++)
               ObjectStore_initialData obj_id = (ObjectStore_initialData)mintomaxID.elementAt(i);
               ID[i] = obj_id.getID();
          System.out.println("Before sorting array");
          for(int i=0;i<ID.length;i++)
               System.out.println(ID);     
          System.out.println();
          int i, j, m, mi;
for (i = 0; i >< ID.length - 1; i++) {
/* find the minimum */
mi = i;
for (j = i+1; j < ID.length; j++) {
if (ID[j] < ID[mi]) {
mi = j;
m = ID[mi];
/* move elements to the right */
for (j = mi; j > i; j--) {
ID[j] = ID[j-1];
ID[i] = m;
System.out.println("After sorting array");
for(int y=0;y<ID.length;y++)
               System.out.println(ID[y]);     
//*****here is where i need to re-arrange the entire vector by ID.
/*new comparable class */
public class ObjectStore_initialData implements Comparable
     String NAME;
     int ID;
     String[] DPART;     
     public ObjectStore_initialData(String name, int id, String[] departments)
          NAME=name;
          ID=id;
          DPART = departments;
public String getName()//----
          return NAME;
public String getID()//----
          return ID;
public String getDpart()//----
          return DPART;
static class IDComparator implements Comparator
          public int compare(Object o1, Object o2)
               ObjectStore_initialData p1 = (ObjectStore_initialData )o1;
               ObjectStore_initialData p2 = (ObjectStore_initialData )o2;
               return p1.getID() - p2.getID();
/*how can i put the vector here to sort? */
public sorter()
public static void sortbyID(Vector mintomaxID)
int[] ID = new int[mintomaxID.size()];
          for(int i=0;i<mintomaxID.size();i++)
               ObjectStore_initialData obj_id = (ObjectStore_initialData)mintomaxID.elementAt(i);
               ID[i] = obj_id.getID();
          System.out.println("Before sorting array");
          for(int i=0;i<ID.length;i++)
               System.out.println(ID[i]);     
          System.out.println();
          int i, j, m, mi;
for (i = 0; i >< ID.length - 1; i++) {
/* find the minimum */
mi = i;
for (j = i+1; j < ID.length; j++) {
if (ID[j] < ID[mi]) {
mi = j;
m = ID[mi];
/* move elements to the right */
for (j = mi; j > i; j--) {
ID[j] = ID[j-1];
ID[i] = m;
System.out.println("After sorting array");
for(int y=0;y<ID.length;y++)
               System.out.println(ID[y]);     
/* using collections to sort*/
Collections.sort(mintomaxID, new IDComparator());
and to check the new order i wanted to print the vector to command line.
still it doesn't do anything.
the url you mentioned is good as i see. but how can i implement that in my class ? please instruct and simplify. i know i just repeated the code, i didn't understand to do a comparable class in collections for this class. Please explain where i'm head to and where's my misleading point here.
Thank you.
Message was edited by:
ArchiEnger.711

Similar Messages

  • How to attach an object back to its source in a master page?

    Hello,
    on a content page I can access objects from the assigned master page using the Ctrl+Shift+LeftClick combination. By doing so I detach many attributes of this object from the master page specifications. How to reset an object and attach it back to the source object of the master page?
    If you are a PowerPoint user, the option reapply slide layout may be familiar to you (this function resets all format overrides to the master settings). I am looking for a similar function in InDesign.

    I really looking for a way to change the position of the second and third text boxes relative to other items on the page.
    An overriden master page item will still respond to its master's position if its position on the page after overriding hasn't been changed. So, you can have the "directions" box on the master page, override it, add text, and as long as you don't move its x, y position in the process of adding text, it can be moved via the master page in the future. The key is not to move it in the editing process.
    Same goes for other attributes. If the fill color is red, you can change it to gray from its master later, as long as you don't change the page item's fill to pink in between.
    It's also possible to match a changed page item's attributes to its master via scripting.
    So for example if you had a 3" text box on the master and there was 100 pages with the text box, and in the editing process 50 had their width changed to varying widths and later you decided you needed a 4"width— a simple script could loop through all the pages and reset the changed widths to match the master's new 4" width.

  • How to sort view object in backing bean

    Hello all ,
    I want to dispaly read only table in sortable way depending on one of attribute value.
    in backing bean I am trying to execute query by executeQuery method but it didn't work
    I have put column sort property to true but it does not work..
    please help me..
    I am using Jdevloper 11.1.1.2.0
    If any one required more details please post

    Hi,
    One way to achieve this is, add a method in your vo which does something like this
      public void customSortBy(String columnName){
      this.setOrderByClause(columnName);
      this.executeQuery();
      }Expose this method as client interface and add it to your pagedef as method binding.
    Once you are done, you can execute method from backing bean by passing the sorting parameter according to your need.
    -Arun

  • HT201412 My 4s is not picking up phone signal I do not no how to sort this out I have tried resetting it and its not working still I do receive messages and can send them but can not call as it just says call fail

    My 4s is not picking up phone signal I do not no how to sort this out I have tried resetting it and its not working still I do receive messages and can send them but can not call as it just says call fail

    Try resseting the network settings in settings>general then go to reset a the bottom.
    Then reset NETWORK settings.

  • I have a I MAC i bought in 2004 and I am having all sorts of problems.  How can I restore my computer to its original form?

    How can I restore my computer to its original form or update my operating system?

    vincenzofromhenderson wrote:
    How can I restore my computer to its original form?
    See Erasing disks securely 
    Start up from your install disc, go to Disk Utility and select the disk and click erase - to securely erase data click Security Options and Erase Free Space which will entirely wipe your disk, overwriting it with zeros so that no data is recoverable.
    Restoring your computer’s software

  • How to find an object from its ID in Integration Repository

    When trying to import a package, I get an error
    "Internal error when importing object 553afdf1-c83d-11d9-871d-0007e9102256....
    I have tried to find the object using the Object->Find... menu item, but selecting Object ID in the attributes field and entering this string does not return any hits.
    Am I doing this right, or is there another way to find the object?
    Kind Regards,
    Tony.

    I am using PI7.0, If i get your question very well: I think there is no option to get an object with Id, all options are:
    Name,Changed on, Changed by,... etc.
    Pls check again.
    BR,
    Alok

  • How do i convert a vector to a treeset?

    Hi
    I have a vector of objects which i need to pass to a new treeset.
    How an I do it?
    class ......
    TreeSet ts = new TreeSet(theBranch.getVideoTable());
    Class branch {
    public Vector getVideoTable() {
    // return the reference to the Vector holding the branch videos
    }

    Do you want to do something like
    Comparator c = new Comparator( ){
       // implement the methods
       // compare and equals
    TreeSet t = TreeSet(c) ;
    t.addAll( yourVector ) ;and for Comparator
    public int compare(Object o1,
                       Object o2)Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

  • How to call request object of IPortalComponent in KM Scheduler application

    Hi
    We are reading RFC Table data using JCO Connection Pool(JCOClientPoolEntry. Please find the below teo line code.If we put this code in KM Scheduler application then its throwing error for the request objecct of IPortalComponenetRequest.
    IJCOClientPoolEntry jcoPoolEntry = null;
    jcoPoolEntry = clientService.getJCOClientPoolEntry(sysId, request);
    Can you please let me know how to use request object of IPortalComponent in KM Scheduler application?
    Thanks,
    Susmita

    Hello GopalY,
    In my experience its not possible to call OLE object in Webui. Maybe customer 3 party application will be supply some web service to handle credit card payments. I think this is the simple way to access 3party application.
    Regards,
    Zafer,

  • How to sort web app items based on few fields of it on search result page?

    I have a web app and its search. The search results are on multiple pages means it has pagination. My client's requirement is to have a feature which will sort results based on some web app items. for example we have a field price so when user select the price it needs to sort from high to low. Any one have idea how to do it?

    I have just been playing around with this for something else, all you need to do is duplicate your price field into the weighting field and it will automatically sort from High to low for you.
    Cheers
    Duncan

  • How to cast an Object into a specific type (Integer/String) at runtime

    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    Example:
    public class TestCode {
         public static Object func1()
    Integer i = new Integer(10); //or String str = new String("abc");
    Object temp= i; //or Object temp= str;
    return temp;
         public static void func2(Integer param1)
              //Performing some stuff
         public static void main(String args[])
         Object obj = func1();
    //cast obj into Integer at run time
         func2(Integer);
    Description:
    In example, func1() will be called first which will return an object. Returned object refer to an Integer object or an String object. Now at run time, I want to cast this object to the class its referring to (Integer or String).
    For e.g., if returned object is referring to Integer then cast that object into Integer and call func2() by passing Integer object.

    GDS123 wrote:
    Problem:
    How to cast an Object into a specific type (Integer/String) at runtime, where type is not known at compile time.
    There is only one way to have an object of an unknown type at compile time. That is to create the object's class at runtime using a classloader. Typically a URLClassloader.
    Look into
    Class.ForName(String)

  • How to set a object value bound to a session to JavaScript variable

    In a JSP, I store an object value in a HttpSession and I also write a Javascript function to display something on the screen. I need to use the Javascript function to display the object value which is stored in the session. How to set the object value to variable of the JavaScript function. Thanks.

    I write a class JavaScriptHelper to convert the object value to variable of the JavaScript;
    1.get the data to a javabean from database;
    2.convert the data to variable of the JavaScript as a String ;
    3.store the object in a HttpSession or Httprequest ;
    4.use in Jsp get the String (variable of the JavaScript )
    YourBean bean = (YourBean) request.getAttribute("model");
         if (bean != null) out.println(bean .getJsCode())
    convert function,(this is only for the matrix):
    public static String formatJsCode(Vector vector) {
    String sJsCode = "";
    //get js head
    sJsCode = getJsHeader();
    //define js array;
    sJsCode += "var data=new Array();\n";
    Vector v = null;
    String sTemp = "", sLine = "";
    for (int i = 0; i < vector.size(); i++) {
    v = (Vector) vector.get(i);
    sLine = "";
    for (int j = 0; j < v.size(); j++) {
    sTemp = (String) v.get(j);
    //replace " to \"
    sTemp = sTemp.replaceAll("\"", "\\\\\\\"");
    //escape Html Tag
    //sTemp = StringUtil.escapeHTMLTags(sTemp);
    //replace \r\n to <br>
    sTemp = sTemp.replaceAll("\r\n", "<br>");
    if (j != 0)
    sLine += ",";
    sLine += "\"" + sTemp + "\"";
    sJsCode += "data[" + i + "]=new Array(" + sLine + ");\n";
    //get js foot
    sJsCode += getJsFooter();
    return sJsCode;
    public static String getJsHeader(){
    return "<script language=\"JavaScript\">";
    public static String getJsFooter(){
    return "</script>";
    }

  • How to set a Object value by JDI

    How to set a Object value using JDI?
    For example:
    class User{
      private String name;
      private String id;
    set and get method;
    public static void main(String[] args) throws Exception {
            VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
            List<AttachingConnector> connectors = vmm.attachingConnectors();
            SocketAttachingConnector sac = null;
            for (AttachingConnector ac : connectors) {
                if (ac instanceof SocketAttachingConnector) {
                    sac = (SocketAttachingConnector) ac;
                    break;
            if (sac == null) {
                System.out.println("JDI error");
                return;
            Map<String, Connector.Argument> arguments = sac.defaultArguments();
            Connector.Argument hostArg = arguments.get("hostname");
            Connector.Argument portArg = arguments.get("port");
            hostArg.setValue(HOST);
            portArg.setValue(String.valueOf(PORT));
            vmMachine = sac.attach(arguments);
            List<ReferenceType> classesByName = vmMachine.classesByName(CLSNAME);
            if (classesByName == null || classesByName.size() == 0) {
                System.out.println("No class found");
                return;
            ReferenceType rt = classesByName.get(0);
            List<Method> methodsByName = rt.methodsByName(METHODNAME);
            if (methodsByName == null || methodsByName.size() == 0) {
                System.out.println("No method found");
                return;
            Method method = methodsByName.get(0);
    I will connect to server and monitor the remote server JVM , There is a object of User, I want to change its value by the Java Debugger Interface by client.
    so how to set its value by the client, and I can not got the User bean at client.
    I know the basic type filed value changed as follows:
    Value newValue = vmMachine.mirrorOf("change var value");// this field is a string.
    stackFrame.thisObject().setValue(field, newValue);
    But a Object , how can I change its value.
    Thanks Advanced.

    ObjectReference.setValue() is the method for chaining the value of an Object's field. First you need to find the specific Object you want to change, though.
    /Staffan

  • How to Sort JTable data using Multiple fields (Date, time and string)

    I have to fill the JTable data with some date, time and string values. for example my table data looks like this:
    "1998/12/14","15:14:38","Unicorn1","row1"
    "1998/12/14","15:14:39","Unicorn2","row2"
    "1998/12/14","15:14:40","Unicorn4","row3"
    "1998/12/17","12:14:12","Unicorn4","row6"
    Now the Sorted Table should be in the following way:
    "1998/12/17","12:14:12","Unicorn4","row6"
    "1998/12/14","15:14:40","Unicorn4","row3"
    "1998/12/14","15:14:39","Unicorn2","row2"
    "1998/12/14","15:14:38","Unicorn1","row1"
    ie First Date field should be sorted, if 2 date fields are same then sort based on time. if date and time fields are same then need to be sorted on String field.
    So if any one worked on this please throw some light on how to proceed. I know how to sort based on single column.
    But now i need to sort on multiple columns.So what is code change in the Comparater class.
    Thanks in advance.. This is urgent....

    I think your Schedule objects should implement Comparable. Then you can sort your linked list using the Collections.sort() method without passing in a Comparator.class Schedule(Date date, String class) implements Comparable
      public void compareTo(Object obj)
        Schedule other = (Schedule)obj;
        return date.getTime() - other.getDate().getTime();
    }

  • How to UnLock the object in Integration Repository of XI.

    Hi Experts, when i try to edit the object in IR, i am getting following message.
    Object Message Mapping EmpResponce_MM | urn:pas.com/neh currently being edited by user 9SGRANDHI.
    Note: it is saying my ID itself, i logged off and logged in, still its showing same mesage, how to unlock the object in Integration Repository of XI.
    please help me out.
    thanks
    siva

    Hi,
    Go to Home page of XI,there u will have Administrator,select it and click on localobjects.There u will have IR and ID in that select lockoverview and remove ur lock.
    this authorization will be given to basis guys check u have it or not.
    Regards,
    Phani
    Reward points if helpful

  • How to create a object for IPageItemControlData?

    how to create a object for IPageItemControlData?

    From the header comment you'll see that IPageItemControlData is an Interface of PageItemWidget. That must've been an InDesign 1.0 or 1.5 feature predating kPageItemBoss, because except for the same comment even in InDesign 2.0 SDK the only further reference is a copy in the comment of its sibbling IFrameControlData which was removed with InDesign CS.
    The IID and kPageItemControlDataImpl are probably only around because deep under the hood there must be some kind of conversion provider waiting to do its job on a very old document.
    I guess the closest in today's functionality will be IHierarchy.
    Dirk

Maybe you are looking for