How to create a generic stack (whose elements can be of any data types) ???

How do you define a "Stack" class that takes the Data type as its constructor argument ,and creates a new instance of that stack type ??? e.g. Stack("double") should create a stack of doubles ,and so on...
     Putting it in another way, how do you go about defining a Stack ,if you are not sure what data types will be pushed into it at runtime ??? Making a Stack of Objects doesn't seem the appropriate choice since, in that case also, you won't be sure of which of the "parseInt(),paresDouble(),Integer(),Double() etc." functions to retrieve the value.

Write your own stack class which delegates push and pop calls to an internal instance of the java.util.Stack. In addition the class has an attribute of type Class. When the push method is invoked the object in the argument will be tested whether it is an instance of the class stored in the type attribute. If not an IllegalArgumentException should be thrown.
Here is the minimal code for such a type-save stack (the main method shows its usage):
import java.util.Stack;
public class TypeSaveStack {
    private Stack _stack = new Stack();
    private Class _type;
    public TypeSaveStack(Class type) {
        _type = type;
    public void push(Object element) {
        if (_type.isInstance(element)) {
            _stack.push(element);
        } else {
            throw new IllegalArgumentException(element
                              + " is not an instance of " + _type);
    public Object pop() {
        return _stack.pop();
    public static void main(String[] args) {
        TypeSaveStack doubleStack = new TypeSaveStack(Double.class);
        doubleStack.push(new Double(Math.PI));
        System.out.println(doubleStack.pop());
        try {
            doubleStack.push("foo");
        } catch (Exception e) {
            System.out.println(e);
}

Similar Messages

  • How to create a business partner whose BP category is person in crm portal?

    How to create a business partner whose BP category is person in crm portal.When I use Partner and account management>Partner function in portal,I create a new partner,the partner category is default organization,can not change.
    But I what to create a partner with the partner category person,how can I do it?
    Is there any other special function to ceate a BP in portal matching the function  with T code Bup1(create BP)in sap gui?
    By the way,I have the whole privileges in portal and crm.
    thanks

    Hello,
    Standard CRM PC UI application offers three options when you push 'New' button: 'Person', 'Organization' and 'Group' (combobox appears). In your case, 'Person' should be selected.
    p.s. If you don't see combobox mentioned above, it could be security issue.
    Kirill

  • How to create objects in stack

    I am working on Weblogic 10 and JDK 1.5. In Java the objects are always created in heap. Can anybody tell me how to create objects in stack?

    SKMoharana wrote:
    i need objects to be allocated in stack as my application should respond in real time (time predictable).I heard this is possible in Mustang.If I am understanding you correctly, allocating objects on the stack will not help you, and creating objects on the heap will not hurt you.
    It is provably impossible to create a truly time predictable application (in any language), so what you're really looking to do is create a program that responds acceptably quickly for an acceptable percentage of the time. For this you can create benchmarks like "responds in 250 milliseconds or less 99.5% of the time".
    To this end, you could create a prototype program that creates the objects you wish on the heap, and see if there actually is a problem. Don't fall into the trap of premature optimization.
    Even if you do discover that your object creation IS the problem, heap allocation is not the problem. Take a look at this article. It takes ten machine instructions, less than 1 millisecond, to allocate an object.
    Your performance problems are most likely in the object initialization (look for long loops or deep recursions), the display (if this is a GUI application), or your network connection (if this is a web application).

  • How to create the generic extractors in sap R/3?,pabitra

    Hi,
         How to create the generic extractors in sap R/3?
    Though it comes under cross application and the types of generic extractors are functional module ,db view,infoset query etc.Do u think the g.e can be built of one of the is types.plz tell correctly
    Advance thanks
    regards
    pabitra

    Hi,
    this is for DB view ,
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ed06446011d189700000e8322d00/frameset.htm
    this is for infoset query,
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/cb43b2455611d189710000e8322d00/frameset.htm
    Good day,
    regards
    Arun

  • How to Create a Generic Delta Datasource

    Hi All,
    I have created a extractor thru RSO2 using a table.
    The table consist of a time field which i set it to the timestamp field. After initlializing the delta upload successfully, when i run delta upload, no data has been uploaded even having made changes to some of the records.
    Why is it so? Kindly advise.
    Does the timestamp field have to be a datetime field or it can be any field of any data type?
    Thanks in advance.

    Hello Bill,
    I have checked RSA7 and my datasource has the status of green. I have set the upper level to <b>900secs</b>. After the init load, i waited for more than <b>900secs</b> before i do another load but it still comes out as 0 records. Is there anything else i need to do?
    I'd like to clarify one thing, is the timestamp field's data type suppose to be a decimal of length 15 field? Mine is currently a <b>DEC15</b> field which is also a packed field. When i used <b>F1</b> at the generic delta screen, it told me that the timestamp field should be a <b>dec15</b> field. Is it correct?
    Thanks, Bill!
    Message was edited by: Shunhui Chua

  • How to create automatic creation of BP from customer and vendor master data

    Hi gurus,
    can any one tell how to create automatic creation of BP from customer and vendor master data.
    Please give me the steps.
    Thanks
    Sasikanth.

    HI,
    Goto SPRO\ Cross application components \ Master data synchronization \ Synchronization control.
    Assign account groups of customer and vendors to respective BP grouping. This setting is enough to create BP in background while creating customer / vendor. But the fields groups are very much important, ensure mandatory fields should be sync.
    rgds,
    Srini

  • How to create a ABAP report off of SRM box for live data?

    How to create a ABAP report off of SRM box for live data?
    Thanks in advance.
    York.

    you can try infoset query:
    STEP - A:
    1. Go to T Code RSQ02 and give the InfoSet name & select CREATE.
    2. Provide the Name(Description) and Data Source i.e. for eg here i take "DIRECT READ OF TABLE" = /BIC/AODS100. Then CONTINUE.
    3. Select what to Include in the 3 options available with the POPUP, here "INCLUDE ALL TABLE FIELDS". Then Check the fields and click GENERATE(one RED and WHITE round icon).
    4. Now provide the PACKAGE for the INFOSET. Come Back(F3).
    STEP - B: optional(If u want to create a new user group)
    1. Select ENVIRONMENT -> USER GROUPS. Provide the User Group name and CREATE.
    2. Provide Description and SAVE.
    3. Provide PACKAGE and SAVE. Come Back (F3) to the Initial Screen.
    4. Click Role/User Group Assignment. Select Newly Created User Group or an existing one. Then SAVE (CTRL + S). F3.
    STEP - C:
    1. Select ENVIRONMENT -> Queries. Provide the query name and CREATE.
    2. Select the INFOSET u have created and assigned the user group.
    3. Provide the Title and Select BASIC LIST. There you have to select (check) the fields you want to display, SAVE and then TEST. It will ask for Variant, just CONTINUE.

  • How to create Short Lived process?..can neone pls help...

    How to create Short Lived process?..can neone pls help...

    Hi,
    Login into workbench. Click on Help->Workbench start page.
    Lot of helps are there you can go through them. They will be helpful.
    But it seems you are new to livecycle, so it will difficult to start through help. Either you can take help of any of your team member who is expert in livecycle or some training you should attend.
    Thanks

  • How a sales order for a MTO sku can always have required date populated bas

    Hi,
    how a sales order for a MTO sku can always have required date populated based on full lead time ?
    Thanks,
    Raja

    Hi,
    If you run MRP against sale order by tcode MD50, system will generate planned order.
    System will generate basic or lead time scheduling depends on MRP run parameter selected in initial screen of MRP run.
    If you select lead time scheduling, system will time from routing and thus generate scheduled start date & finish date.
    If your requirement date say 10/08/08. Lead time 10 days. So system create scheduled start date on 01/08/08 during MRP run.
    Regards,
    Dharma

  • ITunes is saying that I have over 4.78 GB under the category of "other", making it so my iPhone 4 can't add any data (music, apps, pictures, etc.). I'm currently using only 1.3 GB of storage on my iPhone, and the rest is "other". How do I fix this?

    iTunes is saying that I have over 4.78 GB under the category of "other", making it so my iPhone 4 can't add any data (music, apps, pictures, etc.). I'm currently using only 1.3 GB of storage on my iPhone, and the rest is "other". How do I fix this?

    Not if you sync your contact to itunes using the program provide i.e outlook..etc

  • Define a SAML Attribute whose value is not in any data store

    I attempting to define a SAML Attribute in Sun OpenSSO Ent 8.x, whose value is not in any data store. I need to assign static text. The SP requires a unique value for all assertions under the same company. This is their method to help ensure an employee and assertion are for the correct data. For example,
    <saml:Attribute Name="AccountID">
    <saml:AttributeValue>ref-193749900</saml:AttributeValue>
    </saml:Attribute>
    I have not found a way with the OpenSSO admin portal. Any assistance would be appreciated.
    Thanks.

    Any response to this? I have the same need.

  • How can I get network data type

    how can I get network data type: ip, gatway, sub mask, and DNS on the Mac. windwos system and so go on and put cmd ipconfig / all adiquirr how can this data in mac book pro XOS.
    thanks,
    Marcello

    Select  ▹ System Preferences ▹ Network ▹ Advanced ▹ TCP/IP.

  • How do i airprint from safari...can't see any icon

    How do i airprint from safari...can't see any icon or any mechanism, mail is ok though.
    Thanks

    AirPrint is a feature built into the iOS. If the app that you are working in or using has the boxed curved arrow icon at the top - should allow you to print. However, in order to use AirPrint, you must have one of the AirPrint compatible printers.
    The printers with this feature are listed on this web site.
    http://www.apple.com/ipad/features/airprint.html
    If you do not own one of these printers, there are a number of third party apps that will allow you to print using your current printer. You may need to download a helper app on your computer and leave your computer turned on in order to use them.

  • How to create a group of cost element

    Hi,
    i want to integrate a group of cost element in KP06, but i don't know how to create it.
    please what is the transaction to do that ?
    Regards.

    Hello,
    To create the Group of Cost Element
    Go to transection code KAH1 Give any name or number to your cost element group then make the proper standerd hirerchey as you need or simply click on the cost elemt and add all cost element which you want to make a group.
    Hope it will solve you probem,
    Regards
    Ravi

  • How to create a Generic Object Services for a standard tcode.

    Hi,
    We have a requirement where we are depreciating the assets (standard transaction ABAA) using a custom BDC program. We need to maintain a history (called audit trail) for the particular asset that has been depreciated using this program. For this audit train we have been asked to use "Generic Object Services" in transaction code ABAA.
    Unfortunately, Generic object services are not available in this transaction code. Can you please suggest me how to create "Generic Object Services" for a particular standard transaction code. Also, we have show the details of custom workflow that follows the approval process in order to depreciate the asset. how to show this workflow details using Generic Services. This is a very critical issue, any help will be very help ful.
    Please let me know should you require more information on this topic.
    Thanks,
    Ashish

    Instead of copyg the std fm to z, do the following,
    1. Go to se37 open FM VIEW_KURGV in display mode.
    2. Click on the spiral icon on the top.
    3. Then in menu go edit->enhancment options -> show implicit enhancement
    4. """""""""""""""""""""" kind of lines will appear in the cde, just rt click on the line at the place u want to insert the code and select
         enhancement implementation create.
    5. Give apropriate name for thi , it will inset a n place to write your code.
    This is an std sap methodology and is supported in upgradde also.

Maybe you are looking for

  • Photo gallery image size

    Hi. Is it possible to adjust the photo gallery module's code in a way that makes the image that gets displayed on selecting the thumbnail image display no larger than the browser? I have a client that's uploaded image that are pretty large and would

  • HOW TO CHANGE COLOR ON LITTLE SUB TITLE BAR UNDER THE HEADING?

    Hi, I was successfully able to change the background color on the templates headed, but that little bar under it, that displays the links to your other pages within the site did not change with it, and I have tried everything but have not been succes

  • SSIS Import is showing multiple Excels

    Hi There, When am trying to import data from spreadsheet to SQL Table is is giving me different excel names other than the one I wan to import. This is first time am seeing, please check below screenshot and suggest what to do. AM going to clean all

  • Second Last Measure

    I am using the following set with a KPI to return the latest CH4 measure value for each Well: This set returns the current CH4 value for all Wells and current date. I now need to be able to return the second last measure values for all wells for a KP

  • DataConnection: Webservice returning array

    Hello, I try to get an alternative to the SOAP call working: I have a webservice that returns the content of a row in a database in an array of strings. This works fine as long as I use the SOAP call to access and execute the service. However, we run