Vectors with multiple types of objects

Ok, this is what i need. I have a main class, EquationVector, and i have four smaller classes, MathPrimitive, which is abstract and all of the following classes extend, Number which just holds numbers, Operator which takes care of what type it is and what to do, and Variable, which knows its value, its coef and its power. I use the MathPrimitive class because all of the other classes need to have a common getType() method, plus it holds static values for all the possible types. What i need is some sort of storage method that is dynamically resizeable, and can handle multiple types of objects. I tried vector, but it doesnt work, even when i cast. I want to be able to do something to the effect of
myArray.elementAt(index).getOperatorType()
and be able to get the operator type if its an operator, but at the same time be able to do
myArray.elementAt(index).getCoef()
and be able to get the coeficient if its a variable. I'm not sure if this is actually possible, so if anybody has any good ideas i would be really apreciative. Thank you.

Vector will absolutely work, as will ArrayList
You just better make sure you know what kind of objects are at what slots in the vector.
opType = ((MathPrimitive) myArray.elementAt(index)).getOperatorType();
If you don't know what type of object is at a particular slot you can always use
Object o = myArray.elementAt(index);
if (o instanceof MathPrimitive)
else
....

Similar Messages

  • FecthAccounts on resources with multiple types of accounts

    Hello,
    I'm customizing the rename user form so I can modify some account attributes that are related to
    accountId and rename them in a propper way. For getting all account attributes on all resources I set
    fetchAccounts form property to true but only attributes on resources whose identity template is
    simple - It's not a resource with multiple types of accounts - are retrieved.
    The attributes of the resource with a setup of multiple types of accounts are not retrieved with fecthAccounts
    set to true. Has that happened to you ?
    Any clue ?
    Thanks,
    Pablo C.

    You can use Correlation Id for this Purpose. Producer should set Correlation id while posting the message and Consumer can check for Correlation id while dequeue.
    I did have this requirement before and used correlation id for it.
    http://sriworks.wordpress.com/2009/10/22/conditional-dequeue-mq-adapter/
    Or Just Accept Opaque Payload and tweak in BPEL Process using TranslateFromNative function.

  • How to create multiple TYPES of objects from one menu?

    Q: How can I create a single class to create objects of multiple 'object classes' in a way that is not a huge switch statement?
    Explaination:
    Let's say that I have an application that I am building, that manages five hundred object types. A properly-built object subclassing tree is created, and I want to be able to create objects of any 'leaf node' of this subclassing tree using a single 'objectCreate()' method in a 'factory object'. The purpos of this method will be to create an instance of the correct object, pass a handle to a few collections for properly sorting and storing these objects in groups.
    Usually, one could create a switch in this function, testing for the type of object that the user wants to create from the menu. But in the case of having hundreds of possible object choices, this becomes harder and harder code to maintain (let alone performance).
    Any suggestions?

    But if my menu has:
    1. German Shepard
    2. Doberman Pinscher
    3. Malamut
    4. Persian Long-hair
    5. Siamese
    6. Tabby
    And my object class tree goes:
                                  [ Animal ]
                 [ Cat ]                              [ Dog ]
      [ various breeds ]                         [ various breeds ]How do I code the menu class to respond to the input, so that it runs the correct [breed] object's constructor?
    The line:
    Animal choice = new xxxxxxxx();
    I can't use a variable to replace 'xxxxxxxx' in run-time, but having a ton of choices in code sounds/looks unreasonable.
    if (choice == "Doberman Pinscher")
    Animal choice = new doberman();
    else if (choice == "Tabby")
    Animal choice = new tabby();
    Do you see what I am trying to avoid? I am not experienced enough to instantly realize how to avoid the latter, and instead, do a single instantiation command for the correct constructor.

  • Referencing another class with multiple types.

    Here's my code:
    import java.io.*;
    import java.util.Scanner;
    class CH3_13
        public static void main ( String args[] )
            Scanner input = new Scanner( System.in );
         // Invoice MyInvoice = new Invoice();
         /* myInvoice.displayInvoice();*/   }   
    class Invoice
    {   private String partNumber;
        private String partDescription;
        int quantity;
        double pricePerItem;
        public Invoice( String pNumber, String description, int qNumber, double price)
            partNumber = pNumber;
            partDescription = description;
            setQuantity( qNumber );
            setPricePerItem ( price );   }
          public void setPartNumber ( String pNumber )
          {   partNumber = pNumber;   }
          public String getPartNumber ()
          {   return partNumber;   }
          public void setPartDescription ( String description )
          {   partDescription = description;   }
          public String getPartDescription ()
          {   return partDescription;   }
          public void setQuantity ( int qNumber )
          {   quantity = ( qNumber < 0 ) ? 0 : qNumber;   }
          public int getQuantity ()
          {   return quantity;   }
          public void setPricePerItem ( double price )
          {   pricePerItem = ( price < 0.0) ? 0.0 : price;   }
          public double getPricePerItem ()
          {   return pricePerItem;   }
          public double getInvoiceAmount()
          {   return getQuantity() * getPricePerItem();   }
           public void displayInvoice ()
          {   System.out.println("The part number is" + getPartNumber() );
              System.out.println("The part description is" + getPartDescription() );
              System.out.println("The quantity number is" + getQuantity() );
              System.out.println("The price per item is" + getPricePerItem() );
              System.out.println("The invoice amount is" + getInvoiceAmount() );   }          
    }The problem is.. I cannot use the line:
    // Invoice MyInvoice = new Invoice(); (it's commented out for that reason)
    ... because it seems I cannot reference it because the Invoice class has multiple types defined in it. As this is the case, is there anyway, I'd be able to get that line to compile?

    I am not sure of this is what you are looking for but I would definitely suggest some real refactoring here. First of all the part no. name description donot belong to the invoice class so they need to go into a different class named part no. Secondly you need to identify the relationship which I would say would be has a relationship between invoice and part. A many to many relationship. SInce its many to many I would guess it would need to be biderectional associaition.
    However if we have a defined no. of parts in the inventory I would suggest using the reference objects, by predefining them and loading them into memory to ensure that if every time an invoice has a part, a new part object is not created.

  • "Get All Descendents" Method with multiple "Type" inputs

    Hi,
    Is there any way, so that I can specify multiple "Type" to Get All Descendents Method invoke node.
    For example if I need to get all descendents of "Folder" and "VI" type.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

    Try "(VI,Folder)" and post back please
    No help..!!
    @ tst
    Call it twice.
    That option I had figured out, but I need the references of All Descendents (Folders and VIs) in the order of they appear in the project.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Building Binary Searh Tree with multiple types (hint hint Generics?)

    I have built binary search trees before and even wanted to build a B+ tree for primary indexes but my Professor suggested limiting to BST.
    My question is can I build a BST with a generic type parameterized code using Comparable and Generics to help me insert numeric and non-numeric (String) type nodes using the requirement that anything less than the root go left, greater than or equal to the root go right. There will be no duplicates.
    This is definitely new territory for me so any help is appreciated.

    Always Learning wrote:
    I have a Comparable<Object> x I would like to compareTo(Some other Comparable<Object>) but I know I am going about this all wrong.
    Essentially I want to be able to compare String lexicographically or integers/floats in order to properly insert them into a binary search tree and I wanted to use the Java language constructs of the Comparable interface and possibly generics to do it.
    This would result in a simple String1.compareTo(String2) or int1.compareTo(int2) etc.So it sounds like you actually have a Comparable<T>; or possibly a Comparable<String>, where all your types are first converted to Strings (however, in the case of ints, that probably means adding leading '0's).
    The generics tutorial suggests that you use Comparable<? super T> in cases of arbitrarily comparable items; however, I think you first need to decide how your comparisons are going to be done. For example, how does a String compare to an Integer in your scenario?
    Winston

  • How to create View Object with Multiple Updatable Entity Objects

    I want both the entities in the view object to support creating new rows but when i give create insert it allows to insert only on the parent and not the child. I found this link
    http://docs.oracle.com/cd/E21043_01/web.1111/b31974/bcadvvo.htm#CEGCAJCI which overrides the exiting classes. but i would like to do it declarative . Is there any other way to do it?
    I am using Jdeveloper 11g version 2.
    Thanks in advance,
    Rakesh

    But when i tried to add a new row it showed this error
    oracle.jbo.AttrValException: JBO-27014: Attribute LookupTypeId1 in FoundationModuleAM.VikLookupTypeBaseVO is required.
         at oracle.jbo.server.JboMandatoryAttributesValidator.validate(JboMandatoryAttributesValidator.java:224)
         at oracle.jbo.server.EntityDefImpl.validate(EntityDefImpl.java:3095)
         at oracle.jbo.server.EntityCache.validate(EntityCache.java:3599)
         at oracle.jbo.server.EntityImpl.validateEntity(EntityImpl.java:2285)
         at oracle.jbo.server.EntityImpl.validate(EntityImpl.java:2464)
         at oracle.jbo.server.DBTransactionImpl.validate(DBTransactionImpl.java:4515)
         at oracle.insurance.viking.foundation.model.common.VikingDBTransactionImpl.validate(VikingDBTransactionImpl.java:46)
         at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2008)
         at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2352)
         at oracle.insurance.viking.foundation.model.common.VikingDBTransactionImpl.commit(VikingDBTransactionImpl.java:37)
         at oracle.adf.model.bc4j.DCJboDataControl.commitTransaction(DCJboDataControl.java:1590)
         at oracle.adf.model.binding.DCDataControl.callCommitTransaction(DCDataControl.java:1415)
         at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1428)
         at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:2169)
         at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:731)
         at oracle.jbo.uicli.jui.JUActionBinding.actionPerformed(JUActionBinding.java:193)
         at oracle.jbo.uicli.controls.JUNavigationBar.doAction(JUNavigationBar.java:412)
         at oracle.jbo.jbotester.NavigationBar.doAction(NavigationBar.java:112)
         at oracle.jbo.uicli.controls.JUNavigationBar$NavButton.actionPerformed(JUNavigationBar.java:118)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
         at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
         at java.awt.Component.processMouseEvent(Component.java:6289)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
         at java.awt.Component.processEvent(Component.java:6054)
         at java.awt.Container.processEvent(Container.java:2041)
         at java.awt.Component.dispatchEventImpl(Component.java:4652)
         at java.awt.Container.dispatchEventImpl(Container.java:2099)
         at java.awt.Component.dispatchEvent(Component.java:4482)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
         at java.awt.Container.dispatchEventImpl(Container.java:2085)
         at java.awt.Window.dispatchEventImpl(Window.java:2478)
         at java.awt.Component.dispatchEvent(Component.java:4482)
         at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
         at java.awt.EventQueue.access$000(EventQueue.java:85)
         at java.awt.EventQueue$1.run(EventQueue.java:603)
         at java.awt.EventQueue$1.run(EventQueue.java:601)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
         at java.awt.EventQueue$2.run(EventQueue.java:617)
         at java.awt.EventQueue$2.run(EventQueue.java:615)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  • Burning CDs with multiple types of files

    How do you burn iTunes songs and pdf documents to the same disk?

    This would be done on My MacBook, not a Nano.  Haha

  • Implementing a view Object with Multiple Updateable Dependent Entity Objects

    Hello,
         I want to implement view object with multiple updateable entity object,
         i have refered this link its good https://forums.oracle.com/thread/63721
         here they have explained with 2 table,
         but when we have more then 5 tables and each table have Primary keys , Foreign key , Sequence and  trigger created on it. Then whats steps should i want to fallow.
         if possible some please provide the link or some one help me out how to do this .
         thanks in advance
         cheers

    Has the Advanced View Object Techniques been referred?

  • Maintain performance while working with multiple shape layers (~50 )

    Hey guys, I've been working on some projects lately where I need to animate a lot of shape layers cascading, arraying, with various animation properties. When I get to the point of using 30-60 or so shape layers, and they're all doing some kind of scale, position, etc. animations, my computer slows to a complete crawl. This then forces me into using a single shape layer and the repeater functions. These can work well sometimes, and don't hamstring the flexibility too much, UNTIL you need to incorporate varying colors. At that point, I usually switch my shape layers to masks and place a layer below with varying colors as needed. The shape animations then reveal those colors, but this doesn't work for a complex object that in itself requires many colors. Sooo...
    What kind of workflows do you all have for working with multiple semi-complex objects at once? I figure I must be missing something, because this has gotten really limiting. Is everyone just working with 256GB of RAM?
    FYI, my computer specs are:
    2 x 2.66 GHz 6-Core Intel Xeon
    32 GB 1333 MHz DDR3 ECC
    ATI Radeon HD 5870 1024 MB
    OS X 10.9.4 (13E28)
    Thanks!!

    Pre-comping can speed up your previews if you are using disk cache, but nothing will speed up  your first ram preview or a ram preview after a keyframe change except a better optimized system. All it takes to slow things down is one effect or a footage file that causes AE to start consuming memory and processor power.
    As a test I just created a gradient filled rectangle, added rotation keyframes, duplicated the layer so I have 64 copies on my Mac Mini and tried a ram preview compared with the same comp with only 1 layer. Almost no difference in the time it took to preview 10 seconds. Threw in a scale transform for all layers and again, not much difference between one shape layer and 64. To make things much harder I change the rectangle to a Polystar and animated everything in the Polystart transform properties, set up a composition with 128 duplicates and a comp with one layer. 2.5 seconds for a ram preview at quarter rez for a single layer, 10 seconds for a ram preview for 128 layers. That's more than acceptable to me for a two year old Mac Mini with 16 gb of ram. Increasing the zoom factor to 50% with Resolution set to Auto doubled the ram preview time which was still acceptable.
    This makes me wonder what else is going on in your composition. Any effects or other things going on? Have you optimized your system for maximum performance? There are links with suggestions for doing that all over this site as well as the Adobe recommendations found here: Optimizing After Effects Performance

  • 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.

  • Object with multiple states and slider in folio are rasterized, settings seem correct.

    I am having trouble keeping An object with multiple text states from being rasterized, as well as a slider that is also rastering.
    I have read that you are supposed to set the folio and article up to be .pdf and that the slider should have the vector option chosen.
    I haven't found anything for the multi state object to for these settings.
    What happens is when I output the folio to Adobe Content Viewer, only the text in those items is rasterized. All other text is crisp. Tested on both iPad Mini and iPad Retina and the both are blurry.
    Is there a way to force the vector option? It seems even with the correct options selected it is still rastering the test in interactive elements.
    Thanks!

    Here is the MSO with the folio.
    Here is the Slider with folio overlays panel.

  • Flex services with multiple return types

    Hello,
    We are creating a webapplication with flex and php.
    Everything is working very good, until we got to the library part of the application.
    Every service so far had only 1 return type (eg: User, Group, ...)
    Now for the library we want to return a ArrayCollection of different types of objects. To be more specific the LibraryService should return a ArrayCollection containing Folder and File objects.
    But how to configure this in Flex (Flash Builder 4 (standard))?
    So far it converts every object to the type Object, i would really like it to be Folder or File
    The only solution we can think of right now is to create a new object Library that will contain 2 ArrayCollections, one of type Folder and one of type File. This could work ofcourse, but I wonder if there is a better solution for this OR that i can configure multiple return types for a service.
    Any ideas/advice is greatly appreciated.

    Normally if you are using Blazeds(Java stuff, i'm sure there should be something similar for php), you can map java objects to that of the AS objects, when you get the data back you are actually seeing the object which is a Folder or a File object rather than just a Object.

  • Spiral/Vortex with Multiple Objects

    Hi, all
    I'm trying to replicate this image from Shutterstock with multiple objects to create this spiral vortex.
    http://image.shutterstock.com/display_pic_with_logo/849265/101051014/stock-vector-card-sui t-hearts-diamonds-spades-and-clubs-playing-cards-op-art-vector-illustration-101051014.jpg
    I looked up tutorials like this: http://vectorguru.com/tutorials/how-to-distribute-objects-along-spiral.html
    Where I can put say the hearts on one spiral.
    But, the image seems to be multiple spirals in a uniform and equidistant manner. I would like to know how to go about making a "vortex" with multiple objects very similar if not the same to this fashion.
    Please advise.
    Thanks!

    Hi lotrismylife,
    I was able to get a similar effect using the following steps:
    Create a pattern brush of the 4 symbols next to each other (that way you can distribute them easily around the circle).
    Start with the outermost circle, and apply the new pattern brush to it's stroke.
    Expand the circle
    Object > Transform > Transform Each (CTRL + ALT + SHIFT + D)
    Set the horizontal & vertical scale to be smaller than 100% (you must experiment with this, depending on how big the gaps between circles must be)
    Set the rotation angle (depending on how much each circle must rotate)
    Click on Copy
    Now continually press CTRL D - this will continue to create a copy of the outermost circle that is x % smaller, and x degrees rotated.
    End result:

  • Large array of objects/multiple types in an array

    I've been working on a program over the last several months, and I am bothered because I am using an two-dimensional array containing multiple types. A visual representation is as follows:
    ______label1 label2 label3
    label 1 Int Int Int
    label 2 Int Int Int
    label 3 Int Int Int
    The labels are strings, Int represents a numeric value representing a relationship between labelx and labely. Ultimately with the dataset I'm working with, there are hundreds of rows and columns. To complicate matters, I've been putting summary data (e.g. an average) at the end of each row and column to sort the whole thing.
    Because this data structure mirrors the ultimate output--a matrix in text file--it is appealing. But it also violates the rule of only having one datatype in an array. Currently it is declared as Object[][], which gives me the flexibility I need. I can think of other solutions, but they are not as intuitive and seem needlessly complex.
    Any thoughts?
    Thanks.

    I'd be thinking of writing a class that represents the data (labels, values and calculated summaries). Perhaps using one of the already existing implementations of TableModel.
    Because this data structure mirrors the ultimate output--a matrix in text file--it is appealing. Perhaps the appeal is deceptive. Outputting the data to a file is, presumably, only one of the things you are going to do with it. The methods of a class written to represent this data can model the actual behaviour of the data, something beyond the capacities of the jack-of-all-trades array.
    But it also violates the rule of only having one datatype in an array. Currently it is declared as Object[][], which gives me the flexibility I need. Of course I have no idea of the flexibility you need. (Or what imposes this constraint.) But I would consider it more flexible if I were able to change the actual implementation later - without affecting the code that uses this data. For instance if the data were to grow truely huge I might want to obtain it from a database and never have the whole thing in memory at once (whether as an array or any other way). Or I could desire the data to be obtained from sources on the internet via a URL. Or I could learn more about Collections and end up considering their utility methods of such great value that the array based implementation should give way.
    ---Edited by: pbrockway2 on Apr 20, 2008 1:07 PM
    The point is that a MyTableModel type (especially if it were an interface) would enable users of the data to keep on doing whatever they needed to with the data (including saving it to file). While the actual implemention could change: double array one day, Lists the next, a database after that, user interaction via a JTable...
    I can think of other solutions, but they are not as intuitive and seem needlessly complex.Try them, compare them.
    Bear in mind that one's intuitions and needs are apt to change.

Maybe you are looking for