Search in object array

I am working on a program in which one of the problems is to search an object array to allow a user to edit an item in the array. I have examples on how to do linear and binary searches, but they are all simple strings of numeric data. How do I apply this algorithm to a more complex array?I have a class file called Application that contains my constructor, and my get & set methods for creating the objects in the array. And I have a driver class to allow a user to view the array, add items to it , and edit items in it.
This is an example of my declaration of the initial items:
Application inventory[] = new Application[100];
  inventory[0] = new Application("Jumpstart Toddlers", 14.99, 500);
  inventory[1] = new Application("Norton Antivirus 2003", 49.99, 1200);
  etc....
I would like to set it up so that the user is prompted for the name of the software item they would like to edit, the array is searched using a method which returns the index the name was found in.

Sounds like a homework assignment to me but...
Appliction apps[] = new Application[100];
...Add Items to the apps array...
String software_to_search_for = .. user entered
data....
for (int i = 0; i < apps.length; ++i)
if
f
(apps.getSoftware().equalsIgnoreCase(software_to_sea
ch_for))
edit(apps[i], software_to_search_for);
public void edit(Application app, String newName)
// You can do anything here
app.setName(newName);
} // edit
True enough, this is an assignment. But..These assignments were given to us without all the necessary tools. They are set up by the dept. and we have to finish them even if the instructor does not finish covering all the relevant material.In this case, we have not covered the equalsIgnoreCase(something obviously necessary for my problem). Now that I know what I am looking for, I have found it in my book and can apply it to my code appropriately. I was not necessarily looking for code, just the tools I need for my own design. This is something that the Computer dept. allows for in that they have assistants in the open labs that will help in this manner. Problem is, everyone has been out for Thanksgiving since Tues. Please dont feel as though you assisted someone in cheating!! I can assure you, that is not the case here. Thank you for your help.

Similar Messages

  • Searching through an array of objects

    Hi, I am currently working on an assignment where I have to create a class called Persons with data fields of Name(String),age(int),income(int).
    All the values including the string values for name and values for income and age are all randomly generated and are stored in an array of objects of class "Persons".
    The array size is user specified.
    What I must attempt to implement now is to make a search feature that lets the user search through the array of objects for a particular name.
    I'm having some bad luck trying to implement this feature.
    If anyone can help me, I would greatly appreciate that!
    Cheers.

    Hi, Thank you for the prompt reply.
    I do not yet know HOW to start this,I mean I know how to search for individual characters in an element of an array, but to search for whole strings I am quite unsure.
    public class Persons
        //data fields
        private String name;
        private int age;
        private int income;
        //Constructor for Class Persons
        public Person(String[] name,int[] age,int[] income)
              String[] tempName = name;
              int[] tempAge = age;
              int[] itempIncome = income;
        //Instance method for returning some basic values about personal data
        public void toString(Persons ofChoice)
            System.out.println("Persons Data");
            System.out.println("Name: " + ofIntrest.name);
            System.out.println("Age: " + ofIntrest.age);
            System.out.println("Income: $" + ofIntrest.income);
    }This is my Persons class code, but I am quite stumped how to search for whole strings at the time being.

  • Object Array problem in Websphere WebServices

    Hi,
    Can someone help me out with a situation that I am stuck with in WebServices.
    I have a WebService which returns a DTO which has a getter and setter for an array of another type of DTO object.
    Sample:-
    public class MyDTO extends AnotherDTO implements Serializable {
    private InnerDTO qcDtoList[] = new InnerDTO[0];
    public MyDTO() {
    public InnerDTO[] getQcDtoList() {
    return qcDtoList;
    public void setQcDtoList(InnerDTO[] resEDXDTOs) {
    qcDtoList = resEDXDTOs;
    But when I generate the WSDL for the webservice using WSAD 5.1 that uses the above DTO, the server side generated skeleton file looks like:-
    public class MyDTO extends AnotherDTO implements java.io.Serializable {
    private InnerDTO[] qcDtoList;
    public MyDTO() {
    public InnerDTO[] getQcDtoList() {
    return qcDtoList;
    public void setQcDtoList(InnerDTO[] qcDtoList) {
    this.qcDtoList = qcDtoList;
    As you can see from above, my initialization info is not available in the generated skeleton. I also tried putting the initialization in the constructor, with no effect.
    What could be the reason for this? And is it possible to initialize my InnerDTO without losing it in the generated skeleton?
    I simply want to initialize the object array.
    If I need to modify my WSDL, what additional annotations should I add on the WSDL to get the desired effect?
    I use WSAD's (Websphere Studio App Developer) IBM Websphere Webservices protocol and the JDK version is 1.3.1 and WSAD version is 5.1.
    I would really appreciate if you can throw light on this?
    Thanx and Regds,
    Prashanth.

    Thank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
    PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
    v_categories IN ARCHIVE.integer_aat,
    rs OUT RSType)
    AS
    /* PURPOSE: Return Search Results for the Category and Keyword Provided
    VARIABLES:
    v_categories = Document Categories array entered
    v_term = Keyword entered
    rs = Result Set
    TYPE tbl_integer IS TABLE OF INTEGER;
    tbl_cat tbl_integer;
    BEGIN
    FOR i IN 1 .. v_categories.COUNT
    LOOP
    tbl_cat.EXTEND(1);
    tbl_cat(i) := v_categories(i);
    END LOOP;
    OPEN rs FOR
    SELECT A.ID,
    B.CATEGORY,
    A.FILENAME,
    A.DISPLAY_NAME,
    A.COMMENTS
    FROM TBL_ARCHIVE_DOCUMENTS A,
    TBL_ARCHIVE_DOC_CAT B,
    TBL_ARCHIVE_DOC_KEYWORDS C
    WHERE A.ID = B.ID
    AND A.ID = C.ID
    AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
    AND C.KEYWORD = v_term
    ORDER BY A.ID;
    END SEL_SEARCH_RESULTS;

  • Search in an array of cluster

    Hi!
    Is there a smart way to search in an array of clusters.
    For example: You have an array of a cluster with a digital control and a string control.
    And you want to search for a specific value in the digital control.
    What is the best way to that?
    Is there a way, instead of a foor-loop and unbundle, like search 1-D array where you can ignore the string value.
    If I use the search function I need to specify both the numeric and the string, but I'm only intrested in the numeric.

    If you are always wanting to search this array based on the value of one particular value in the cluster, something you can do is when creating the cluster array, create two arrays that relate to each other on an element-by-element basis.
    One array contains the values that you are going to want to search. The other array contains a cluster with all the other values. Searching the "key" array gives you an index that you can use to index the correct element from the other data array.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Returning an Object Array

    I am unable to figure out the way in which I can return an object
    array from a cpp file to java. Is there any obvious error which you can spot in
    my CPP file?
    When I try to return a single object in the native function,
    it works fine but when I try to extend it and return an array of the object, it
    throws an error.
    Please find below the details
    h1. Java Class
    public class Flight {
    public String ID;
    public class InterfaceClass {
    private native Flight[] GetFlights();
    public static void main(String[] args)
    Flight[] objFlight = new
    InterfaceClass().GetFlights();
    System.+out+.println(objFlight[0].ID);
    static {
    System.+loadLibrary+("main");
    h1. CPP File
    JNIEXPORT jobjectArray JNICALL Java_InterfaceClass_GetFlights(JNIEnv env, jobject obj)
    //1. ACCESSING THE FLIGHT CLASS
    jclass cls_Flight = env->FindClass("LFlight;");
    //2. CONSTRUCTOR FOR FLIGHT CLASS
    jmethodID mid_Flight = env->GetMethodID(cls_Flight,"<init>", "()V");
    //3. CREATING AN OBJECT OF THE FLIGHT CLASS
    jobject objFlight = env->NewObject(cls_Flight, mid_Flight);
    //4. ACCESSING THE FLIGHT's "ID" FIELD
    jfieldID fid_ID = env->GetFieldID(cls_Flight, "ID","Ljava/lang/String;");
    //5. SETTING THE VALUE TO THE FLIGHT's "ID" FIELD
    env->SetObjectField(objFlight,fid_ID, env->NewStringUTF("ABC"));
    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");
    if(cls_Flight_Array == NULL)
    printf("Error-1");
    //7. CREATING A NEW FLIGHT ARRAY OF SIZE 1 jobjectArray arrFlightArray = env->NewObjectArray(1,cls_Flight_Array,NULL);
    if(arrFlightArray == NULL)
    printf("Error-2");
    //8. INSERTING A FLIGHT BJECT TO THE ARRAY
    env->SetObjectArrayElement(arrFlightArray,0,objFlight);
    return arrFlightArray;
    h1. Error
    # A fatal error has been detected by the Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION
    (0xc0000005) at pc=0x6d9068d8, pid=1804, tid=3836
    # JRE version: 6.0_18-b07
    # Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode, sharing
    windows-x86
    # Problematic frame:
    # V [jvm.dll+0x1068d8]
    # An error report file with more information is saved as:
    # C:\Users\Amrish\Workspace\JNI Test\bin\hs_err_pid1804.log
    # If you would like to submit a bug report, please visit:
    http://java.sun.com/webapps/bugreport/crash.jsp
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM

    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");The argument to NewObjectArray is the +element+ class of the array you're about to create, not the +array+ class itself.

  • Java Null Pointer Exception when assigning a value to an Object Array

    I am working on a webservice where the request can contain a dynamic array of SingleOwnerRequestNodeDetail objects. I need to read these objects in and sort them according to an orderNbr that is contained in the object.
    I am attempting to read these object into a Comparable class and sort them. I am having problems when I try to insert the objects into my object array ComparableBO[]. I get the following error: Exception during processing: java.lang.NullPointerException
    Any assistance would be greatly appreciated.
    Here's my class:
    public class ComparatorBO  implements Comparable {
         private SingleOwnerRequestNodeDetail nodeDetailInfo;
         private int orderNbr;
         public SingleOwnerRequestNodeDetail getNodeDetailInfo() {
              return nodeDetailInfo;
         public void setNodeDetailInfo(SingleOwnerRequestNodeDetail nodeDetailInfo) {
              this.nodeDetailInfo = nodeDetailInfo;
         public int getOrderNbr() {
              return Integer.parseInt(nodeDetailInfo.getSingleOwnerRequestOrderNbr());
         public void setOrderNbr (int orderNbr) {
              this.orderNbr = orderNbr;
         public int compareTo(Object anotherNodeDetailInfo)throws ClassCastException {
              if (!(anotherNodeDetailInfo instanceof ComparatorBO))
                   throw new ClassCastException ("An single owner request node detail object is expected");
              int anotherNodeDetailOrderNbr = ((ComparatorBO)anotherNodeDetailInfo).getOrderNbr();
              return this.orderNbr - anotherNodeDetailOrderNbr;
    }Here's the code where I read in the objects and attempt to place them in the comparableBO[]
    ComparatorBO[] comparatorBOArray = null;
    comparatorBOArray = new ComparatorBO[requestInfo.length];
              for (int i=0; i < requestInfo.length; i++)
                   SingleOwnerRequestNodeDetail nodes = new SingleOwnerRequestNodeDetail();
                   ComparatorBO comparatorBO = new ComparatorBO();
                   nodes.setSingleOwnerRequestNodeID(requestInfo.getSingleOwnerRequestNodeID());
                   nodes.setSingleOwnerRequestNodeType(requestInfo[i].getSingleOwnerRequestNodeType());
                   nodes.setSingleOwnerRequestOpCode(requestInfo[i].getSingleOwnerRequestOpCode());
                   nodes.setSingleOwnerRequestOrderNbr(requestInfo[i].getSingleOwnerRequestOrderNbr());
                   comparatorBO.setNodeDetailInfo(nodes);                         
                   *comparatorBOArray[i].setNodeDetailInfo(comparatorBO.getNodeDetailInfo());*
                   comparatorBOArray[i].setOrderNbr(Integer.parseInt(nodes.getSingleOwnerRequestOrderNbr()));

    imadeveloper wrote:
    I am working on a webservice where the request can contain a dynamic array of SingleOwnerRequestNodeDetail objects. I need to read these objects in and sort them according to an orderNbr that is contained in the object.
    I am attempting to read these object into a Comparable class and sort them. I am having problems when I try to insert the objects into my object array ComparableBO[]. I get the following error: Exception during processing: java.lang.NullPointerException
    Any assistance would be greatly appreciated.
    Here's my class:
    public class ComparatorBO  implements Comparable {
         private SingleOwnerRequestNodeDetail nodeDetailInfo;
         private int orderNbr;
         public SingleOwnerRequestNodeDetail getNodeDetailInfo() {
              return nodeDetailInfo;
         public void setNodeDetailInfo(SingleOwnerRequestNodeDetail nodeDetailInfo) {
              this.nodeDetailInfo = nodeDetailInfo;
         public int getOrderNbr() {
              return Integer.parseInt(nodeDetailInfo.getSingleOwnerRequestOrderNbr());
         public void setOrderNbr (int orderNbr) {
              this.orderNbr = orderNbr;
         public int compareTo(Object anotherNodeDetailInfo)throws ClassCastException {
              if (!(anotherNodeDetailInfo instanceof ComparatorBO))
                   throw new ClassCastException ("An single owner request node detail object is expected");
              int anotherNodeDetailOrderNbr = ((ComparatorBO)anotherNodeDetailInfo).getOrderNbr();
              return this.orderNbr - anotherNodeDetailOrderNbr;
    }Here's the code where I read in the objects and attempt to place them in the comparableBO[]
    ComparatorBO[] comparatorBOArray = null;
    comparatorBOArray = new ComparatorBO[requestInfo.length];
              for (int i=0; i < requestInfo.length; i++)
                   SingleOwnerRequestNodeDetail nodes = new SingleOwnerRequestNodeDetail();
                   ComparatorBO comparatorBO = new ComparatorBO();
                   nodes.setSingleOwnerRequestNodeID(requestInfo.getSingleOwnerRequestNodeID());
                   nodes.setSingleOwnerRequestNodeType(requestInfo[i].getSingleOwnerRequestNodeType());
                   nodes.setSingleOwnerRequestOpCode(requestInfo[i].getSingleOwnerRequestOpCode());
                   nodes.setSingleOwnerRequestOrderNbr(requestInfo[i].getSingleOwnerRequestOrderNbr());
                   comparatorBO.setNodeDetailInfo(nodes);                         
                   *comparatorBOArray[i].setNodeDetailInfo(comparatorBO.getNodeDetailInfo());*
                   comparatorBOArray[i].setOrderNbr(Integer.parseInt(nodes.getSingleOwnerRequestOrderNbr()));
    Well normally when someone wont tell me what line the error occured in I copy paste their code into my compiler and find out. But you have other classes which you have not shown us so I cannot help you.
    Incase you missed my point, please tell us where the error occured!

  • Calling a method that returns an object Array

    Hello.
    During a JNICALL , I wish to call a method which returns an object array.
    ie my java class has a method of the form
    public MyObject[] getSomeObjects(String aString){
    MyObject[] theObjects=new MyObject[10];
    return theObjects
    Is there an equivalent to (env)->CallObjectMethod(...
    which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
    Thanks,
    Neil

    I believe an array oj jobjects is also a jobject. You can then cast it to another class.

  • Search API for searching Business Objects in SAP R/3

    Hi All,
    As per my requirement i need to search Business Objects from a third party application by writing some java code.
    I know only JCO which is useful for to establish a connection from Java to SAP Server and execute the RFC's or BAPI's which are reside in SAP Server.
    Can any one help me, it is possible or not to search Business Objects in SAP for example Master Data( Like Employee, Vendor, Customer-) or Transactional Data ( like Sales Order, Purchase Order--), in case if it is possible any Search API is there to use on SAP System and what are the Prerequisites and the Feasibilty.
    Its urgent---PLZ help me how to resolve this issue
    Thanks in ADV
    Regds
    Rajesh

    Hi,
    Good evening and greetings,
    Please go through the following link
    http://help.sap.com/saphelp_erp2004/helpdata/en/0d/afb8f627878b4fa71ac79508f2358a/frameset.htm
    Please reward points if found useful
    Thanking you
    With kindest regards
    Ramesh Padmanabhan

  • Trouble writing to object array

    Hi I did a semester of java 2 years ago and I'm trying to remember what I knew so please bear with me...
    I am extracting data from an xml file and then writing that information to an object array called files containing 4 string and 1 array. This files array is in turn an element in another object array containing 400 files arrays called records.
    It appeared to be working but when I want it to print out which ever record I have selected it only prints out the last record! It seems to be overwriting each files array with the next?
    Another problem I can only print out an element of the array not the entire thing?
    Please help have spent weeks on this
    Here is the code:
    Object[] Records = new Object[400];
    Object files[] = new Object[5];
    NodeList records = doc.getElementsByTagName("record");
    for( int i = 0; i < records.getLength();i++)
    Element record = (Element) records.item(i);
    NodeList headers = record.getElementsByTagName("header");
    Element header = (Element) headers.item(0);
    NodeList ids = header.getElementsByTagName("identifier");
    for(int j = 0; j < ids.getLength(); j++){
    Element id = (Element) ids.item(j);
    String ID = getText(id);
    files[0] = ID;
    NodeList metadatas = record.getElementsByTagName("metadata");
    Element metadata = (Element) metadatas.item(0);
    NodeList citeseers = metadata.getElementsByTagName("oai_citeseer:oai_citeseer");
    Element citeseer = (Element) citeseers.item(0);
    NodeList titles = citeseer.getElementsByTagName("dc:title");
    for(int k = 0; k < titles.getLength(); k++){
    Element title = (Element) titles.item(k);
    String TITLE = getText(title);
    files[1] = TITLE;
    NodeList subjects = citeseer.getElementsByTagName("dc:subject");
    for(int m = 0; m < subjects.getLength(); m++){
    Element subject = (Element) subjects.item(m);
    String SUBJECT = getText(subject);
    files[2] = SUBJECT;
    NodeList descriptions = citeseer.getElementsByTagName("dc:description");
    for(int n = 0; n < descriptions.getLength(); n++){
    Element description = (Element) descriptions.item(n);
    String DESCRIPTION = getText(description);
    files[3] = DESCRIPTION;
    String[] Names = new String[20];
    NodeList authors = citeseer.getElementsByTagName("oai_citeseer:author");
    for(int l = 0; l < authors.getLength(); l++){
    Element author = (Element) authors.item(l);
    Names[l] = author.getAttribute("name");
    files[4] = Names;
    System.out.println("The id is "+files[0]);
    System.out.println("The title is "+ files[1]);
    System.out.println("The Subject is "+ files[2]);
    System.out.println("The Description is "+ files[3]);
    for(int q=0; q < authors.getLength(); q++){
    System.out.println("The Names are "+ ((String[])files[4])[q]);
    //Records[i] = files;
    System.out.println(((Object[])Records[0])[0]);

    I'm afraid I'm not going to make you a millionaire but I feel so relieved at the moment that if I had a million I'd give it to you!!Yeah, I know you won't make me a millionaire, but I can dream... :)
    thanks for all your helpYou are welcome. Do you understand why you needed to move the creation of the "files" array.

  • 2D Object Array Problem

    Hey Guys,
    I am trying to append or add another set of data to my object array but with no success. What I need is later on in my code I want to add new data to the rows array.
    Any advise would be gratefully appreciated. Here is my code:
    Object[][] rows =
        { { "AOLX", new Integer(10), new Double(12.1), OrderLocation.BUY, OrderStatus.RECIEVED }, {
          "ORCLX", new Integer(55), new Double(34.56), OrderLocation.BUY, OrderStatus.RECIEVED }, {
          "CSCOX", new Integer(100), new Double(5.6), OrderLocation.SELL, OrderStatus.PROCESSING }, {
          "NXTLX", new Integer(200), new Double(7.8), OrderLocation.BUY, OrderStatus.PROCESSING }, {
          "DELLX", new Integer(30), new Double(9.11), OrderLocation.SELL, OrderStatus.CANCELLED }
      };Edited by: onlynew4now on Aug 6, 2009 5:29 AM

    You got a severe case of Object denial.
    I'd start with writing a class like this:
    public class Order {
      private String name;
      private int amount;
      private BigDecimal cost;
      private OrderLocation location;
      private OrderStatus status;
      public Order(String name, int amount, BigDecimal cost, OrderLocation location, OrderStatus status) {
        this.name = name;
        this.amount = amount;
        this.cost = cost;
        this.location = location;
        this.status = status;
      public Order(String name, int amount, String cost, OrderLocation location, OrderStatus status) {
        this(name, amount, new BigDecimal(cost), location, status);
    // add getters and if necessary setters
    }Then your code can look like this:
    Order[] rows = {
      new Order("AOLX", 10, "12.1", OrderLocation.BUY, OrderStatus.RECIEVED),
      new Order("ORCLX", 55, "34.56", OrderLocation.BUY, OrderStatus.RECIEVED),
      new Order("CSCOX", 100, "5.6", OrderLocation.SELL, OrderStatus.PROCESSING),
      new Order("NXTLX", 200, "7.8", OrderLocation.BUY, OrderStatus.PROCESSING),
      new Order("DELLX", 30, "9.11", OrderLocation.SELL, OrderStatus.CANCELLED);
    };

  • Object array

    what do i have to do to create and object array in a class of other class. i tried to created an object of that class first and the create the array by the compiler complains that there is a problem. here is the code.
    classJTBar---------------------------------------------------
    ackage JTShapes;
    import java.awt.*;
    public class JTBar extends JTFilledRectangle{
         int height=20; int length=0;//i will use the inheritated methods
         public JTBar(){//contructor that will be called on creating object
    setHeight(20);//method of class JTRectangle
    setWidth(0);//method of class JTRectangle
         public void setLengh (int x){
              length = x;
         public void incLengh(int y){
              length = length+y;
    }//end class     
    User class
    port JTShapes.*;
    import JTUtils.*;
    import javax.swing.*;
    public class User extends JTUser{
         public void begin(){
    JTBar jtbarobject= new JTBar();
         JTBar[] arrayObj= new JTBar[8];
         String[] weekDay= {"Monday", "Tuesday", "Wednesday", "Thuersday",
         "Friday", "Saturday", "Sunday"};

    You don't have to do this:
    String[] weekDay = new String[]{"Monday", "Tuesday", "Wednesday", "Thuersday", "Friday", "Saturday", "Sunday"};
    This works fine:
    String[] weekDay= {"Monday", "Tuesday", "Wednesday", "Thuersday", "Friday", "Saturday", "Sunday"};
    What kind of Exception are you getting? I'm guessing you're getting a NullPointerException?
    Looks like you're declaring your array correctly, but you are not initializing it:
    JTBar[] arrayObj= new JTBar[8];
    for (int i = 0; i < arrayObj.length; i++) {
    arrayObj[i] = new JTBar();
    }

  • Object Array --- Collection

    Is there any way to directly convert and object Array to a Collection object. Basically i need to create a ArrayList from Object Array. The ArrayList has a constructor and also provides a method addAll() that accept Collection as parameter. So the problem becomes , how to convert Object Array to collection. As per my understanding all arrays should be essentially Collection Interface subclass.
    So why am i not able to cast?
    What is wrong in calling Object Array a sub class of Collection?
    // OrderLineItem[] is the object array that i wish to have as ArrayList
    // This code generates error -
    //"ErpOrder.java": Error #: 364 : cannot cast gal.ERP.OrderLineItem[] to java.util.Collection
      public void setLineItems( OrderLineItem[] arrOrderLineItem ) {
        m_arrLineItems = new ArrayList((Collection)arrOrderLineItem);
      }Is there no way except iterating through the array and adding individual Objects to ArrayList?

    By "Object array" do you mean an Array class, or do you mean an Object[]? They are different. The Array class wraps an Object[] and provides useful methods to manipulate it.
    There is no such thing as a Collection object, per say. "Collection" is an interface implemented by many objects such as LinkedList, Vector, ArrayList, HashSet, and TreeSet.
    The Collection interface is designed to be an interface to any object that can keep a mutable list of other Objects, check to see if an Object is in that list, and iterate through all Objects in the list.
    As far as resources go, I suggest the API reference at http://java.sun.com/j2se/1.4.1/docs/api/index.html.

  • Object Array Data Provider Refresh Possible bug

    Hello
    I am having a problem with Object Array Data Provider in terms that the table's data is not changed corectly after a request as expected, but after two requests.
    Steps to reproduce the bug:
    0. Create a new Visual Web project, call it 'test'.
    Set 'Bundled Tomcat ' or 'Sun 9' as deploy target server.
    Edit 'Page1' of the project.
    1. Create an Entity class, simple class that has only getters and setters with a few fields (lets say 'id' and 'name').
    2. In the SessionBean1 that is generated by the framework create an array of Entity class named 'entityArr', and getters and setters for this field.
    3. Add a new Array Object Data Provider on the page and set in its properties as array the array created in the previous step 'entityArr (SessionBean1)'.
    4. Add a new table component, and set as data provider the provider created in step 3.
    In the Table's Layout map the fields from the Entity class, and set whatever compnents you desire for each component's type or leave the default ones (Static Text).
    5. Add a 'property change trigger component' on the page. I called it like this because I tried the following :
    5.1 A text field and a button to submit the text value
    5.2 A Calendar component with autosubmit
    5.3 A DropDown with autosubmit.
    6. On the property change trigger component created at step 5 set a value_changed method that changes the the array that should be displayed by the table.
    For Example, for a DropDown component, you will have a method like this :
    public void dropDown1_processValueChange(ValueChangeEvent event) {
    String idStr = (String) event.getNewValue();
    System.out.println("Entity id :"+idStr);
    if(idStr .equals("item1")) {
    fillSessionBean1(true);
    else {
    fillSessionBean1(false);
    getSessionBean1().setItemName(idStr);
    private void fillSessionBean1(boolean fillValues) {
    Entity[] values ;
    if(fillValues) {
    values = new Entity[4];
    for ( int i=0;i<values.length; i++) {
    Entity entity = new Entity();
    entity.setDescription("Description "+i);
    entity.setName("Name "+i);
    entity.setId(i) ;
    values[i] = entity;
    else {
    //values = new Entity[0];
    values = null;
    getSessionBean1().setEntityArr(values);
    7. When running the program, if the selected is Item1, the table does not show the array set if on this branch.
    I am using :
    Netbeans 5.5 build 20061017100,
    Visual Web Pack 070104_2,
    Ent.Pack 20061212
    jdk 1.6.0
    Operating Systems : Both Linux Suse10 and Windows.
    If anyone has a solution for this please let me know.

    OK
    While no one responded, I had to think for myself.
    There is a bug in the code generated by netbeans or there is nowhere specified that if you attach an array to a data provider you will have to notify by hand the data provider that the array has changed.
    You will have to put this line that is generated in init function in your valuechanged functions :
    objectArrayDataProvider1.setArray((java.lang.Object[])getValue("#{SessionBean1.entityArr}"));
    I think this aproach is a little bit wrong, even it works.
    I believe the data provider should be notified the array has been changed.
    There could be a much more simple aproaches :
    1. In the code generated by netbeans, if you attach an array to a data provider the data provider will be notified after any set(Object[])
    2. The data provider could have a function so you will ne anle to attach to the data provider an Object (the session bean, in my case) and the name of the function that retrieves the array (in my case, 'getEntityArr') .
    The code generated by netbeans could add this function easily.
    Maybe there are any other better aproaches, and I might be wrong.
    It's good that it works.

  • Problem when using object array as parameter of server-side event

    Hi Friends,
        I had defined an event in component interface of Component A, with object array as its parameter. but when I define event-handler for this event in Component B, the type of parameter in generated event-handler method is just the class itself instead of an array.
       It's a bug or array parameter is not support by server-side event in WD4J?
       Thanks in advanced.

    I think you are trying to do the editing of parameter from the java editor.
    Do it via the controller editer. Go the methods tab. Select the actionhandler.
    In the parameter section edit the paramter. Change the dimensions here.
    Regards,
    Ashwani Kr Sharma

  • Any Search API  to search Business Objects in SAPR/3 Server

    Hi All,
    As per my requirement i need to search Business Objects from a third party application by writing some java code.
    I know only JCO which is useful for to establish a connection from Java to SAP Server and execute the RFC's or BAPI's which are reside in SAP Server.
    Can any one help me, it is possible or not to search Business Objects in SAP for example Master Data( Like Employee, Vendor, Customer-) or Transactional Data ( like Sales Order, Purchase Order--), in case if it is possible any Search API is there to use on SAP System and what are the Prerequisites and the Feasibilty.
    Its urgent---PLZ provide ur suggestions
    Thanks in ADV
    Regds
    Phanikumar

    Phanikumar,
    Perhaps you can check
    http://help.sap.com/saphelp_nw2004s/helpdata/en/95/92bd4244e6b611e10000000a155106/frameset.htm
    James

Maybe you are looking for