Multiple object creation in a loop

I want to create lots of objects in a loop, but I cannot figure out how to substitute an array into the code. So, I was hoping to use Rectangle rect[i] instead of Rectangle rectOne, where i is my counter. Assuming this is a reasonable method, where can I track down the syntax?
Rectangle rectOne = new Rectangle(originOne, 100, 200);
Rectangle rectTwo = new Rectangle(50, 100);

Something still isn't quite right. I made up some simpler code to get to the answer, if it is helpful, the actual code is below. This code is supposed to read a text file and pull in tab delimited data. At the commented line, it breaks, expecting a semi but finding 'aa'. I can get this to work if I don't use an array (so, 'aa' is overwritten each time the loop runs, instead of aa[i] which would contain all of the values). Unfortunately, I have to refer back to the individual Nodes ('aa') in later code and can't if the values have been overwritten. I'm trying to keep my code simple, if I'm not asking the question correctly, or if you need more information, please let me know.
void setup() {
  String[] lines;
  lines = loadStrings("Product Migration.txt");
  for (int i = 1; i < lines.length; i++) {
    String[] pieces = split(lines, '\t');
Node[] aa = new Node[5];
for (int j = 0; j < pieces.length; j++) {
String[] tempArray = new String[lines.length];
Node aa[i] = new Node(this, pieces[j], j * 75 + border, i * 50); // code breaks in compiler here.
net.addNode(aa);
Edited by: LouisvilleLIP on Jun 11, 2008 4:40 AM
Edited by: LouisvilleLIP on Jun 11, 2008 4:41 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • While Loop - Object Creation

    Hello,
    I have a question on object creation and while loops. Have a look at the following code snippet:
    while(true)
           Object obj = new Object();
           // Pass off obj to a new thread
           Thread job = new Thread(new ObjectHandler(obj));
           job.start();
    }My question is, do I have to wait until the newly created Thread is finished with the Object obj before I can create a new Object called obj in the while loop?
    Also does anyone have any documentation on this sort of thing?
    Thanks,
    Tony.

    Jaxie wrote:
    I'm still not sure you get what I'm on about, you might want to read up on java methods and pass by value.I think we know how it works. Most of us have been programming in Java for serveral years.
    >
    When you pass an object to a method in java you pass it a copy of a reference to that object. Leading on from that, before an object is eligible for garbage collection in java, all references to that object must be dropped.
    So with all that in place, my question was, is the creation of an object in a while loop dependent on previous objects of the same name? Objects don't have names. Have we mentioned that before?
    You have a reference, larry that is referencing an unnamed object. You can also create other references that reference the same object. The thread will have one reference. You can then make larry reference another object. That will not change anything in the thread. It will still reference the old object, and that object will not be claimed by the gc until that thread stops referencing it.
    So the second time we go through the loop below, do we have to wait until larry has been garbage collected, before a new larry can be created?Read the articles/tutorials and what I have written above. What do you think?
    Do also note that the GC isn't executed synchronously.

  • Multiple objects, multiple domains, for-loops the problem?

    Hi,
    I've based a small amount of Powershell code off the code I've found here: http://halfloaded.com/blog/powershell-using-posh-to-search-across-multiple-domains-in-forest/
    Ideally what I'm aiming for is for it to find the current forest, enumerate the domains, and then for each domain to search for a specific user. If it finds the user it should then do something, for now just clear a value extensionAttribute8.
    What I suspect is happening is it finds the users but then tries to modify them while attached to the current domain, which is child1.
    Domain structure:
     - Root
       - child1
       - child2
    cls
    $objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
    $DomainList = @($objForest.Domains | Select-Object Name)
    $Domains = $DomainList | foreach {$_.Name}
    foreach($Domain in ($Domains))
    $ADsPath = [ADSI]"LDAP://$Domain"
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)
    $objSearcher.Filter = "SamAccountName=testuser"
    $objSearcher.SearchScope = "Subtree"
    $colResults = $objSearcher.FindAll()
    foreach ($objResult in $colResults)
    $userDomain = $objResult.GetDirectoryEntry()
    Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    It errors with
    Set-ADUser : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.
    At line:17 char:9
    + Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (CN=testuser,C...pny,DC=co,DC=uk:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.,Microsoft.ActiveDirectory.Management.Comman
    ds.SetADUser
    Set-ADUser : Cannot find an object with identity: 'CN=testuser,CN=Users,DC=child2,DC=root,DC=company,DC=co,DC=uk' under: 'DC=child1,DC=root,DC=company,DC=co,DC=uk'.
    At line:17 char:9
    + Set-ADUser $userDomain.DistinguishedName[0] -clear extensionAttribute8
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (CN=dttestuser,C...ita,DC=co,DC=uk:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'CN=dttestuser,CN=Users,DC=its,DC=ad,DC=capita,DC=co,DC=uk' under: 'DC=central,DC=ad,DC=capita,DC=co,DC=uk'.,Microsoft.ActiveDirectory.Management
    .Commands.SetADUser
    Please help!

    cls
    Import-Module ActiveDirectory
    Foreach ($Domain in (Get-ADForest).Domains)
    #Performing Search Operation per Domain
    $Objects = Get-ADObject -LDAPFilter "SamAccountName=dttestuser" -Server $Domain -Properties extensionAttribute8
    Foreach ($Object in $Objects)
    Set-ADUser $Object -clear extensionAttribute8
    If anyone could tell me why removing the loop:
    Foreach ($Object in $Objects)
    And saying
    Set-ADUser $Objects -clear extensionAttribute8
    Errors I'd be interested. $objects only finds 1 object so having the loop makes no sense but it does seem to stop it error'ing!

  • Multiple objects created in loop

    How do I create multiple objects for the same class with a loop
    I can hard code the names in but I want to allocate names from an array as the names
    ie
    BankAccount Acct(NameArray[0]) = new BankAccount();
    to get
    AcctFred.method();
    and access this in a loop
    I know if can be done but how??
    Regards, Cat

    Another variation:
       String[] names = { "Peter", "John", "Suzie" };
       // Creates the accounts and stores them in the hash table
       HashTable hAccounts = new HashTable();
       for (int i = 0; i < names.length; i++) {
          BankAccount account = new BankAccount(names);
    hAccounts.put(names[i], account);
    // Retrieves an account by its name
    Account account = (Account)hAccounts.get("John");
    Hope this helped,
    Regards.

  • Error message "multiple objects found"

    Hi,
    I run into a new issue and durig role creation of design-time-roles. I get since a few days the message
    "test:testrole.hdbrole": multiple objects found
    my simplified role: (worked out before hundred times)
    test::test
    extends role test::testrole
    The role exists as design-time-object (one entry in "_SYS_REPO"."ACTIVE_OBJECT" and also only one entry in "SYS"."ROLES")
    Other roles can be granted as as usual - just a bunch of them make trouble.
    I dropped the roles (afterwards 0 entries in the mentioned tables) ... when activating testrole.hdbrole it says no object found - as expected. created the role again and the message appears again. Pretty weird.
    Did one of you had the same issue and solved it?
    Thanks for your answers in advance!
    Regards,
    Marcus
    P.S: Running HANA SP7 Rev 72 (DB+Studio+Client)

    Hi Mika
    Can you check your  : HKLM\SOFTWARE\Microsoft\Office\xxxx\Outlook\InstallRoot\Path
    For each key under HKLM\SOFTWARE\Microsoft\Office, apparently HKLM\SOFTWARE\Microsoft\Office\xxxx\Outlook\InstallRoot\Path has a "Outlook.exe" file at the location.
              If more than 1 file paths are found, then it appears that multiple versions of the outlook are installed.
    You might want to re install office if more thaqn one appears

  • Object Services - How to loop at a table ' osreftab ' ?

    Hi Object Services Gurus,
    I'm try to transform a table selected via object services (transaction service) to a table with type VRM_VALUES (the one necessary to fill selection screen listbox parameters).
    So, i have a table with type 'osreftab' and i need to loop it accessing the attributes of its lines (which i just know at runtime). How can i proceed with this? Below is what i'm trying..
    * (This is a method of a global class which pretends to transform a variable 'osreftab' into a variable 'vrm_values').
    DATA: l_wa_value TYPE VRM_VALUE,
               l_i_values TYPE VRM_VALUES.
    DATA: l_o_tax_code TYPE OSREF.
    * im_tax_codes type is osreftab
    LOOP AT im_tax_codes INTO l_o_tax_code.
    *l_wa_value-KEY = l_o_tax_code->?
    *l_wa_value-text = l_o_tax_code->?
      APPEND l_wa_value TO l_i_values.
    ENDLOOP.

    You can't cast b/w data reference which l_tax is and object reference which l_o_tax_code is.
    osref is a generic object type and you store a reference to some object in it, right? So the question is: what kind of object you store there? Please note - this must be an object reference , not data reference .
    i.e
    "here goes some class
    class zcl_spfli definition.
    endclass.
    class zcl_spfli implementation.
    endclass.
    "here is an OBJECT REFERENCE for it, (so I refer to a class) i.e persistent object to table SPFLI
    data oref_spfli type ref to zcl_spfli.
    "but here I have a DATA REFERENCE (so I refer to some data object) i.e DDIC structure SPFLI
    data dref_spfli type ref to spfli.
    So my OSREF can hold only oref_spfli but it not intended for dref_spfli . That's why you get this syntax error. Once you have stored reference to zcl_spfli in osref then you will be able to dereference it and access this object's attributes.
    data: osref type osref.
    create object osref_spfli.
    osref = osref_spfli.
    "now osref holds reference to object, you can deference it
    oref_spfli ?= osref.
    osref_spfli->some_attribute = ....
    OSREFTAB is just a table whose line is of type OSREF (so can hold multiple object references - one in each line).
    Regards
    Marcin

  • Can Multiple Objects be copied into Sales Order??????

    Hi,
    I have created three charecteristics and assigned to a class of class type 001. In the classification view of material master for each material i assigned the class.This assignment is done for calling the object at sales order level.
    I am able to find the multiple objects for single characteristics in sales order but multiple objects are not copied into sales order..only single object is copied into sales order...when i try to copy multiple objects system is throwing warning message as "You can only copy one object in this mode".... Is it possible to copy multiple objects ?? Any answers will be highly appreciated.
    Ramagiri.

    Hi,
    But what's the purpose behind that.Material Class 001 is just only for information purpose only to search the materials with help of class and characterstic.
    If your material is configuable one then you have to use Class type 200 - Material (Configurable Objects) and for the same you have maintain the characterstic value during sales order creation.
    Regards,
    Dhaval

  • Adding multiple objects

    Hi.
    I'm trying to add multiple objects to my universe, but i'm not sure how to do it. What i was thinking was to create a for loop and create the object within it.The z value refers to the z vector point.The code is below.I'm new to java 3D so if anyone could help me, that would be great.
    Thanks
    Sharon.      
    for (float z = 0f; z < 20f; z = z + 2){
              Cylinder cylinder = new Cylinder( 0.8f,10f );
              Color3f col = new Color3f(8f, .15f, .15f);
              ColoringAttributes ca = new ColoringAttributes (col,ColoringAttributes.NICEST);
              app.setColoringAttributes(ca);
              cylinder.setAppearance(app);
              Transform3D transform = new Transform3D();
              Vector3f vector = new Vector3f(0f, 0f, z);
              transform.setTranslation(vector);
              tg.setTransform(transform);
              tg.addChild( cylinder );
              bg.addChild( tg );
    }

    Hi.
    I have two programs, BGroup.java, which creates a rotating sphere and coloring attributes etc. and some1Canvas3D.java which creates a canvas and simple universe and panel with buttons and works on the BGroup.java program by adding it as a branchgraph to the simple universe "simpleU.addBranchGraph(new BGroup());". what i'd like to do is that if one of the buttons in some1Canvas3D.java is pressed then i want to decrease/increase the radius size of the sphere in BGroup.java. and see this within the canvas.
    I'm not sure how this will work.
    If anyone has any ideas how to do this, that'd be great.
    The code for the two programs is below . i'm quite new to Java3D so i hope it makes sense.
    Thanks for you help.
    Sharon
    /********BGroup.java****************
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.image.TextureLoader;
    public class BGroup extends BranchGroup
    public BGroup()
    /*create the transformGroup and set the capability to write.needed for rotation*/
    TransformGroup someGroup = new TransformGroup();
    someGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    //add the transform group to the branchgroup
    this.addChild(someGroup);
    //create the sphere and add it to the scene
    Sphere mysphere = new Sphere(0.5f);
    someGroup.addChild(mysphere);
    // Create a light that shines for 100m from the origin
    Color3f light1Color = new Color3f(7f, 2.6f, 4.1f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    Vector3f light1Direction = new Vector3f(9.0f, -7.0f, 5.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    someGroup.addChild(light1);
    Transform3D yAxis = new Transform3D();
         Alpha rotationAlpha = new Alpha(-1, 4000);
         RotationInterpolator rotator =
         new RotationInterpolator(rotationAlpha, someGroup, yAxis,
                        0.0f, (float) Math.PI*2.0f);
         rotator.setSchedulingBounds(bounds);
         someGroup.addChild(rotator);
    this.compile();
    *********************some1Canvas3D.java******************/
    import java.awt.*;
    import java.awt.GraphicsConfiguration;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.event.WindowAdapter;
    public class some1Canvas3D extends Applet {
    private Button go = new Button ("Forward");
    private Button go2 = new Button ("Left");
    private Button go3 = new Button ("Right");
    private Button go4 = new Button ("Back");
    private Button go5 = new Button ("Do it for me !!!");
    public void init()
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c1 = new Canvas3D(config);
    c1.setSize(256,256);
    add("Center", c1);
    SimpleUniverse simpleU = new SimpleUniverse(c1);
    simpleU.getViewingPlatform().setNominalViewingTransform();
    simpleU.addBranchGraph(new BGroup());
    Panel p = new Panel();
    p.add(go);
    p.add(go2);
    p.add(go3);
    p.add(go4);
    p.setBackground(Color.blue);
    p.setForeground(Color.red);
    add("North",p);
    Panel p2 = new Panel();
    p2.add(go5);
    p2.setBackground(Color.blue);
    p2.setForeground(Color.red);
    add("South",p2);
    public void start() {
    public void destroy() {
    public void run() {
    //Explains what happens when the Mouse is clicked on the Applet
    public void actionPerformed(ActionEvent e) {
         if (e.getSource()==go ) {
    /*when this button is pressed i want to be able to decrease the radius size of the sphere in BGroup.java*/
    public static void main(String []args)
    System.out.println("Program Started");
    new MainFrame(new some1Canvas3D(), 750,500);
    Thanks again.
    Sharon.

  • Java Object Creation

    A general question about how can Java object creation with an average amount of data retrieval is considered as a reasonable.
    For example if I am clicking on a link in a web application...to paint that page, I think, about 4-5 java object with an average data retrieval of 20 rows wud be considered as appropriate. Any other thoghts or any other parameters to take into consideration?

    If you are concerned about object creation speed, you probably shouldn't. Even my laptop PC can create and garbage collect some 12 million objects per second (10,000,000 objects takes about 800 milliseconds). Test program below; remember to run with "java -server" to get the faster optimizing compiler. For laughs, write an equivalent C++ program that does new&delete in a similar loop.
    public class CreateObject
        public static void main(String args[])
         throws Exception
         for (int m = 0; m < 5; m++)
             doit();
        static void doit()
         long start = System.currentTimeMillis();
         for (int n = 0; n < 10 * 1000 * 1000; n++) {
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
             new CreateObject();
         long end = System.currentTimeMillis();
         System.out.println((end - start) + " ms");
    }

  • Multiple objects to have the same rollover state at the same time (but link to different pages)

    Hi,
    I have a mac
    I would like to know how i can have multiple images with the same rollover states - but which show up at the same time on more than one image, (but each item to have its own linking property applied to it)?
    see image below: i want both box 'A' to pop with the same rollover state even if I'm hovering on just one of the boxes. But i want each of the boxes to link to different pages in my website.
    Ive tried grouping the images and moving them to their own layer, but the rollovers aren't 'linking' together on multiple objects
    help!
    thanks

    It's not, but you don't need that to achieve the behavior you've described. A1, a trigger, will have the states and hyperlink you desire. On rollover it will show its rollover state and will show its target container which will be directly on top of A2. It will look like a rollover state for A2. Repeat this for A2, B1 and B2 and I believe you achieve the behavior you've described. It's just a different way of approaching the problem (that happens to fit the tools available in Muse).

  • How do I create multiple objects during runtime?

    I don't know how to create multiple objects during runtime, here's my problem:
    I get a String as input. Then I create an object called newobject. I put the object in a hashtable with the above string as key.
    Then comes the problem, in order to create a new object, I have to rerun the same class, which uses the same name (newobject) to create a 2nd object. Now my hashtable doesn't reference to my 1st object anymore...
    Is there anyway I can fill up the hashtable with different objects, and make each key point to each object it was supposed to?
    For those who want to see a bit of the program:
    public class PlayBalloon{
    public Hashtable ht = new Hashtable();
    for(){
    Balloon pB = newBalloon;
    newBalloon=new Balloon(pB);
    ht.put("Some input from user", newBalloon);
    for(){
    ht.get(s).draw;<= s=string, draw=own meth. in Balloon
    }

    I think i can see the problem that you are having. You have, in effect, duplicate keys in your hashtable - ie, two strings used as keys with the same name.
    The way that a hashtable works is as follows...
    When you ask for a value that is mapped to a key it will go through the table and return the first occurence it finds of the key you asked for. It does this by using the equals() method of whatever object the key is (in your case it is a String).
    If you cant use different Strings for your keys in your hashtable then i would consider writing an ObjectNameKey class which contains the String value that you are trying to put in the hashtable and an occurrence number/index or something to make it unique. Remember to override the equals method in your ObjectNameKey object or else the hash lookup will not work. For example
    class ObjectNameKey {
        private String name;
        private int occurence;
        public ObjectNameKey(String name, int occ) {
            this.name = name;
            this.occurence = occ;
        public String getName() {
            return name;
        public String getOccur() {
            return occurence;
        public boolean equals(Object o) {
            if (!(o instanceof ObjectNameKey)) {
                return false;
            ObjectNameKey onk = (ObjectNameKey)o;
            if (onk.getName().equals(name) && onk.getOccur() == occurence) return true;
            return false;

  • Multiple Invoice Creation

    Hi All,
    I want to create Multiple Invoice Creation through BAPI or FM. For this invoice PO is the Reference.
    As per requirement i have multiple PO in container, at one shot i want to create invoice realted PO as the reference.
    Thanks
    Amit

    hi,
    I am trying in another way - creating one proforma invoice for multiple deliveries. and with that proforma invoice trying to create excise invoice.
    But i am facing problem in creating proforma with multiple deliveries because of DIFFERENT NUMBER RANGE IN HEADER (delivery)AT FOREIGN TRADE --- UNDER ORGANIZATION --- NUMBER OF FOREIGN TRADE DATA - ( which is internally assigned by the system)
    If i can get where this number is assign my problem is solved
    K.S.Rao

  • How to show object creation in UML

    How to show object creation in UML

    In a sequence diagram, it's a line (with arrow) pointing to the new object and the <creates> or <new> tag as mentioned above.
    | obj 1  |
         |
         |    <creates>     ----------
         | -------------->  | obj 2  |
         |                  ----------or----------
    | obj 1  |
         |
         |      <new>       ----------
         | -------------->  | obj 2  |
         |                  ----------

  • Using Multiple Object Types in a FIM Managed Criteria Distribution Group

    Is it possible to use multiple object types in a criteria based distribution group. So when building your criteria filter, "Select (object type) that match (all/any) of the following condiftions". Currently you can only choose 1 object type and
    I want to be able to choose object type "user" and a custom object type I create for my contacts 

    You can create main condition as "any" and later add two sub-conditions - one that object in set "All People" and other sub-condition that object in set "All Contacts" or "All Groups".
    If you found my post helpful, please give it a Helpful vote. If it answered your question, remember to mark it as an Answer.

  • Error while doing multiple object updation from EP ! object lock error

    HI all,
    I am doing multiple  object updation using a standard RFC(BAPI_PROJECT_MAINTAIN). The RFC i am calling from Enterprise portal. I am sending data to RFC one by one. But the error i am getting is object is locked by user so data can't be save.
    Though i am using Lock and unlock method before and after calling RFC the project lock error comes up.
    What might be the reason
    regards
    sandeep

    Hi Sandeep,
    Is the RFC you use for locking in the same model as the bapi BAPI_PROJECT_MAINTAIN? If it is not then you are using two connections for communication with the sap R/3 backend.
    You can do 2 things.
    1. You could add the RFCs for locking in the same model as the BAPI_PROJECT_MAINTAIN
    2. Instead of adding the RFCs in one model synchronize the connections the models use as follows:
    IWDDynamicRFCModel model1 = (IWDDynamicRFCModel) WDModelFactory.getModelInstance(Model1.class);
    IWDDynamicRFCModel model2 = (IWDDynamicRFCModel) WDModelFactory.getModelInstance(Model2.class);
    model1.setConnectionProvider(model2);
    You can do this in the wdDoInit. This will make sure both models use the same connection but closing a connection will close both at the same time.
    The same problem applies to commit/rollback functionality.
    Regards,
    Jeschael

Maybe you are looking for