Help on Object (casting)

hi there :) ...
Let us assume the following line:
Operation op = new Intersection( new Union ( new Set(A ), new Set(B)),
new Union ( new Set(C ), new Set(D)));
Let us also assume that there exist Operation, Union, Intersection and Set classes. Then, as you can see, the previous line defines an Operation object, op, which consists of a conjunction of disjunctions.
Right, what I am wondering is how one can be able to define an create objects via String Sentences like the following example:
Operation setOperation;
setOperation = new SetSentence(" new Intersection( new Union ( new Set(A ), new Set(B)),
new Union ( new Set(C ), new Set(D))); ");
This is similar to Sql Statements on Java, such statements are defined and created via String sentences, so how one can do that?
Thank you in advance for your help
Jose

Operation op = new Intersection( new Union ( new Set(A), new Set(B)),
new Union ( new Set(C ), new Set(D))); Basically, given a String, you want to 'transform' or 'compile' that String into a sequence of your
predefined operations, like Union, Set, Intersection etc. right? If so, you can define a simple
'set-language'; the expression above can be represented by the String -- "(A+B)*(C+D)" where
the '+' operator represents the Union operationand the '*' operator represents the Intersection
operation. The identifiers A, B, C and D represent their corresponding 'Set(...)' operations.
Parsing an infix expression like the above is not very difficult, but it can be simplified even further.
The above expression can be written in postfix format as follows -- "A B + C D + *". As you can
see, no precedence rules nor parentheses are needed anymore. This String can be parsed
from left to right, using an operand stack --
A: push a new Set(A) on the stack
B: push a new Set(B) on the stack
+: pop two elements x and y from the stack and create a new Union(x, y), push it back on the stack
C: push a new Set(C) on the stack
D: push a new Set(D) on the stack
+: pop two elements x and y from the stack and create a new Union(x, y), push it back on the stack
*: pop two elements x and y from the stack and create a new Intersection(x, y); push it back on the stack,
When the entire string has been parsed (and evaluated as above), the top (and single) element on
the stack is the result of the expression. If, during evaluation, not enough elements are present on
the stack or, after evaluation, the stack doesn't contain one single element, the String contained a
syntax error.
kind regards,
Jos

Similar Messages

  • Object Casting

    hi ,i have a question for .Base on this example below , i need to understand some casting basic .I understand how premitives values widening rules works but not on object casting rules.
    Question 1.
    Okay ,base on the example below why 'c=(Test) a' will always give compile error while "a=b" does not .Let takes this example , b already extends A and should have information of A class while A only have it own .I know i was thinking another way round.Can any one help.
    Question 2.
    How to make " c = (Test) a to run without any problem ,as long as a is assign to a is ok.
    Question 3.
    I have a statement from Khalid book page 202 and i don't understand .
    First statement:=Conversion which preserve the inheritance is a relationship are allowed ,other conversion      require an explicit case or are illegal.
    Fecond statement:=There is no notion of promotion for reference values.
    Question 4.
    What is the benefit of using casting and when we need to use it .Can give a short example.??
    class A {int Athing = 1;}
    class B extends A {int Bthing = 2;}
    class Test extends A
    { int Cthing = 3;
    public static void main(String args[])
    A a = new A();
    B b = new B();
    Test c = new Test();
    //c = (Test) a; //runtime error
    a = b;

    Ron, does your mommy know you're here? Shoudn't you be out riding your bike or doing homework or watching X Men or something instead of interrupting the grown-ups?
    Wikey: The answer to your question is that you can always (and implicitly) cast to a subclass because the subclass is always a member of the class, but you can't always even explicitly cast to the parent or higher class. To give a concrete example, all Toyota Camries are cars, but not all cars are Toyota Camries. There are things you can do with a Toyota Camry that you can't do with all cars. In your code, if you had coded A a = new Test();, you woudn't have a runtime error.
    Doug

  • Guidelines to help center objects and text in pages

    Where are the guidelines to help centre objects and text in the new pages?

    well YMMV.  https://discussions.apple.com/thread/5472111?tstart=0
    You have to do it manually.  Also can be in the accomplished in the right hand column Format>Select your image>Arrange

  • F help for objects

    Hi all,
          can any body tell to get F4 help for object attributes in table controls.
      actually i got f4 help for object using SWO_DIALOG_OBJTYPE_VAL_REQUEST.
    like this i want function module to get f4 help for attributes.

    Hello,
    Please check the roles related to the below authorization object.
    Authorization Object  
    S_WFAR_OBJ          
    Value  
    NV          
    Value  
    VBRK          
    Value  
    YP3INVOICE          
    Value  
    03          
    archiving Related role will give you access to View the billing document in PDF.
    Thank you
    Regards
    Bala

  • Hi i just to want to know when we use object casting..

    sorry about this newbie question i ve already asked to my tutor but
    didn't get it...
    i just wonder what will happen if we cast object..
    i just can't imagin..coz im just bit slow on creative thinking...
    my currently writing code is like this..
    Integer nextCustID = new Integer("123456");
    Customer customer = new Customer(nextCustID, "Fred");
    customers.put("First", customer);
    customer = (Customer) customers.get("First");
    System.out.println(customer);i don't know about object casting...............................

    You don't cast objects. You just cast references - widening or narrowing their "scope" along the inheritance hierarchy.
    String s = new String("Hello");
    Object o = (Object) s; // Explicit cast not necessary, just for clarification
    String s = (String) o;While "hello" might appear as a String, then as an Object, then again as a String, it is always a String. Only the reference type to it changes.

  • Crazy!! Tree object Casting... Error

    I've created a Jtree, consisting of objects of type (String x, String y, String z), When i rename a leaf id like the first String "x" in the object to change accordingly and the rest to remain the same...
    I've used a TreeModelListener with the treeNodesChanged methods to listen for a rename and the below code to change it, But i keep getting the following:-
    java.lang.ClassCastException: java.lang.String
    // Code
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    MObject obj = (MObject) node.getUserObject(); //error
    node.setUserObject(new MObject (obj.x, obj.y, obj.z));
    the casting works perfectly in other sections of the code just not here. please help Thx

    pl. giv code for ur MObject and node creation

  • Object[] casting to String[] ERROR

    Hi! i have a LinkedBlockingQueue and by it's method .to Array() i want to cast it's type to String[] (it's initial is Object[])
    But i get a ClassCastException
    Help?

    An Object[] is not an String[] even if it only contains String objects: The content of the array does not define the type of the array, but the type of the array limits the possible types of the content.
    Look at the other .toArray() method that takes a parameter. If you put a String[] in, you get a String[] back out (you still have to cast, 'though, but then it will work).

  • Object Casting Issue

    This is Driving me Crazy!
    I have a method that Returns an Object
    Object myconfig = (Object)digester.parse("d:/siteconfig.xml");
    //Now, I always know in this case that the Object being returned
    //is always a "SiteConfig" object.
    //I know this for a fact I test that by doing object.GetClass().getName()
    //and I am looking at the debugger and it says that the object is a "SiteConfig" object
    //However for the life of me, I can not cast this object into a "SiteConifg" object even though it is. I get a ClassCastError Exception when I try to do..
    SiteConfig siteconifg = (SiteConfig)myconfig
    //Can anyone help me out?

    This is the stack trace...
    java.lang.ClassCastException
    at techone.groups.DigesterTest.doPost(DigesterTest.java:69)
    at techone.groups.DigesterTest.doGet(DigesterTest.java:34)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
    at java.lang.Thread.run(Thread.java:536)

  • Records and Objects, Cast for PL/SQL Type RECORD and SQL Type OBJECT

    Hi seniors:
    In my job, we have Oracle 10g, programming with Packages, the parameters are PL/SQL Types,
    Example:
    PACKAGE BODY NP_CONTROL_EQUIPMENT_PKG
    IS
    TYPE TR_EQUIPMENT_OPERATION IS RECORD(
    wn_npequipmentoperid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npequipmentoperid%TYPE,
    wv_npactiveservicenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npactiveservicenumber%TYPE,
    wv_npspecification ORDERS.NP_SPECIFICATION.npspecification%TYPE,
    wv_nptype ORDERS.NP_SPECIFICATION.nptype%TYPE,
    wn_nporderid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.nporderid%TYPE,
    wn_npguidenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npguidenumber%TYPE,
    wd_npdevolutionprogramdate CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npdevolutionprogramdate%TYPE
    TYPE TT_TR_EQUIPMENT_OPERATION_LST IS TABLE OF TR_EQUIPMENT_OPERATION INDEX BY BINARY_INTEGER;
    PROCEDURE SP_GET_EQUIPMENT_OPERATION_LST(
    an_npequipstatid IN CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npequipstatid%TYPE,
    at_equipment_operation_list OUT TT_TR_EQUIPMENT_OPERATION_LST,
    av_message OUT VARCHAR2
    IS
    BEGIN
    SELECT EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate
    BULK COLLECT INTO at_equipment_operation_list
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    EXCEPTION
    WHEN OTHERS THEN
    av_message := 'NP_CONTROL_EQUIPMENT_PKG.SP_GET_EQUIPMENT_OPERATION_LST: '||SQLERRM;
    END SP_GET_EQUIPMENT_OPERATION_LST;
    END;
    Procedures calls other procedures and passing parameters IN OUT defined that PL/SQL Types. The problem appears when the access is through Java. Java can't read PL/SQL Types because only read SQL Types (Types defined in SCHEMA):
    CREATE OR REPLACE
    TYPE TO_EQUIPMENT_OPERATION AS OBJECT (
    wn_npequipmentoperid NUMBER,
    wv_npactiveservicenumber VARCHAR2(15),
    wv_npspecification VARCHAR2(8),
    wv_nptype VARCHAR2(2),
    wn_nporderid NUMBER,
    wn_npguidenumber NUMBER,
    wd_npdevolutionprogramdate DATE
    CREATE OR REPLACE
    TYPE TT_EQUIPMENT_OPERATION_LST
    AS TABLE OF "CONTROL_EQUIPMENT"."TO_EQUIPMENT_OPERATION"
    Java can read this SQL Types. The problem is how cast OBJECT to RECORD, because I can't execute that:
    DECLARE
    wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
    BEGIN
    SELECT EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate
    BULK COLLECT INTO wt_operation_lst
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    END;
    and throws NOT ENOUGH VALUES, and I modified to:
    DECLARE
    wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
    BEGIN
    SELECT TO_EQUIPMENT_OPERATION(EO.npequipmentoperid,
    EO.npactiveservicenumber,
    S.npspecification,
    S.nptype,
    EO.nporderid,
    EO.npguidenumber,
    ES.npdevolutionprogramdate)
    BULK COLLECT INTO wt_operation_lst
    FROM NP_EQUIPMENT_OPERATIONS EO,
    NP_EQUIPMENT_STATUS ES,
    ORDERS.NP_ORDER O,
    ORDERS.NP_SPECIFICATION S
    WHERE EO.npequipstatid = ES.npequipstatid
    AND EO.nporderid = O.nporderid
    AND O.npspecificationid = S.npspecificationid
    AND EO.npequipstatid = an_npequipstatid;
    END;
    Worst is that I can't modify this procedure and PL/SQL Types will survive.
    I have create a copy that CAST RECORD to OBJECT and OBJECT to RECORD too.
    PROCEDURE SP_COPY_PLSQL_TO_SQL(
    an_npequipstatid IN NUMBER,
    at_dominio_lst OUT ORDERS.TT_EQUIPMENT_OPERATION_LST, --SQL Type
    av_message OUT VARCHAR2
    IS
    wt_dominio_lst CONTROL_EQUIPMENT.NP_CONTROL_EQUIPMENT_PKG.TT_TR_EQUIPMENT_OPERATION_LST; --PL/SQL Type
    BEGIN
    SP_GET_EQUIPMENT_OPERATION_LST(an_npequipstatid, wt_dominio_lst, av_message);
    IF av_message IS NULL THEN
    at_dominio_lst := ORDERS.TT_EQUIPMENT_OPERATION_LST(ORDERS.TO_EQUIPMENT_OPERATION('','','','','','',''));
    at_dominio_lst.EXTEND(wt_dominio_lst.COUNT - 1);
    FOR i IN 1..wt_dominio_lst.COUNT LOOP
    at_dominio_lst(i) := ORDERS.TO_EQUIPMENT_OPERATION(wt_dominio_lst(i).wn_npequipmentoperid,
    wt_dominio_lst(i).wv_npactiveservicenumber,
    wt_dominio_lst(i).wv_npspecification,
    wt_dominio_lst(i).wv_nptype,
    wt_dominio_lst(i).wn_nporderid,
    wt_dominio_lst(i).wn_npguidenumber,
    wt_dominio_lst(i).wd_npdevolutionprogramdate
    END LOOP;
    END IF;
    END;
    I would like that the CAST is direct. Somebody can help me?. Thank you so much!

    I am facing the same problem as u had...may I know how u solved ur probkem...
    thanks,
    kishore

  • PCH: Value help for Object ID

    Hi Experts,
    I have a question regarding Logical Database PCH.
    We know LDB PCH is OM based and we have  default "Object ID field " and "Reporting period field " at the selection screen.
    I have kept "Reporting period" as "Key date" 31.12.2010. I  wanted to select an Org unit from the "Org. Structure Search" at the ""Object ID field " value help . But I can see the "Org. Structure"  corresponding to  "Today's date" all the time.
    For eg: Org unit 1111111 was delimited on 01.01.2011.  I wanted to se the Org. structure for 31.12.2010. So I put the key date as 31.12.2010. Since the above org. unit is delimited on 01.01.2011, it was expected to see in the Org. Structure at the "Object ID" value help . But unfortunately, it is not displayed, since the Org. Structure is shown based on Toda's date.
    If anybody comes across such a scenario, please provide your inputs .
    Thanks in advance,

    There is a search component that can be used for this purpose.
    This is one function out of several. I don't have the complete implementation at hand but this will give you the first idea.
    CALL METHOD cl_crm_uiu_prod_tools_search=>eh_onclosepopup_return_product     
       EXPORTING       
          ir_search_popup = search_popup     
       CHANGING       
          cr_context_node = lv_target_node       
          cv_index        = gv_tableindex. 

  • Object casting: confusion in ABAP Objects: Complete Reference book

    Hi,
    During Object Assignments using casting, is a Type Test carried out during the syntax check or at runtime?
    A.5.2.2 (page 1008) of 'ABAP Objects: The Complete Reference' says about Widening Cast: "...you must check at runtime...". However on the next page under A.5.3.2 it says of Widening Cast in Data References: "The syntax check precludes...".
    A.5.4 (page 1010) concerns Assignments between Object Reference Variables, but makes no mention of whether checks are carried out by a syntax check or at runtime.
    Also nowhere does it mention when Type Tests for Narrow casting takes place. Can anyone clear my confusion please? Unfortunatly I don't know enough about this stuff to test by writing some code.
    Thanks.

    William,
    Your questions can be answered by the following rule for object references, which I found in the book "ABAP Objects" by Horst Keller and Sascha Krüger:
    "... that the static type of the target variable must be equal to or more general than the dynamic type of the source variable."
    Here "static type" means the type with which an object reference variable is declared. "Dynamic type" is the type that the object reference variable has at runtime. The dynamic type of an object reference is always more special than its static type, otherwise a runtime error occurs.
    With this rule all your questions can be answered:
    1. The Narrowing Cast is always checked during the syntax check. Example:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref1 = o_ref2.  
    Here the reference o_ref2 has a dynamic type "class_1" or a subclass of it, which is narrower than its static type "class_1", which is narrower than the static type "object" of the reference o_ref1. Therefore, the syntax check says that the assignment is OK.
    2. The Widening Cast is always checked at runtime and requires an assignment using the operator ?=. If you use the operator = in the assignment, a syntax error occurs. Therefore the following  example produces a syntax error (try it yourself):
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 = o_ref1.  
    The correction for this syntax error is:
    DATA o_ref1 TYPE REF TO object.
    DATA o_ref2 TYPE REF TO class_1.
    o_ref2 ?= o_ref1.
    Now the syntax check is satified, and the correctness of the widening cast is checked at runtime.
    Kind regards,
    Michael Kraemer
    Message was edited by: Michael Kraemer

  • WebDynpro Methods help for objects in ABAP editor

    Hi,
    is there a possibility to see the methods that can be used by an specific object?
    For example which methods I can use with the object wd_this.
    Thank You!

    You will need to drill into the underlying class to view its methods.
    http://help.sap.com/saphelp_nw04s/helpdata/en/35/447741b0d6157de10000000a155106/frameset.htm
    Regards,
    Rich Heilman

  • Need Help converting objects in a TreeMap to String

    This app counts the number of times a word occurs in a document. I used a HashMap to store the key and value. The I sorted them using TreeMap. Now I need to return the key (String) and value (Integer Object) so they may be print like this -- 'key: value'.
    Example:
    that: 3
    This mean the word 'that' appeared 3 times in the document. Below is my toString() method. TreeMap sorts everything for me but I cant return 'map' because it is not a String. So I iterated through each key and value in the map. But now I dont know how to put all the iterations into 1 String value. I would greatly appreciate any help. Code below.
    Thanks in advance.
    public String toString() {
    Object key = null;
    Object value = null;
    map = new TreeMap(map);
    Set getKeys = map.keySet();
    Iterator iterKeys = getKeys.iterator();
    while (iterKeys.hasNext()) {
    key = (String)iterKeys.next();
    value = map.get(key))
    return; // i need to return a String here
    } // end toString()
    } // end class

    I dont remember posting to the "new Java forum", but I might have. My browser locked up on me so I am not sure what happened. If I did please excuse my double post.
    Are you familar with a way to solve my problem?

  • Object Casting in a JSP

    When getting data from the usual HttpSession object, I understand how the following (for simplicity) hypothetical line of code works:
    AccountInfo someAccount = (AccountInfo) session.getAttribute( ... );
    Here, assume that "AccountInfo" is a bean i.e., implements serializable and has standad getters and setters. So far nothing special but wait... What about the following variation:
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    The surprising thing was that the someAccount object has its data populated with items from the list! Why do I say such silly things? Well the code that follows leads me to that conclusion:
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    this.doSomething(accInfo);
    It's not obvious to me when the getters and setters of accInfo were called?? Can someone provide an explanation? I was not aware of this mechanism. Should I get a new Java book?
    Thanks!

    EDITED VERSION OF THE ABOVE POST
    When getting data from the usual HttpSession object, I understand how the following hypothetical line of code works:
    AccountInfo someAccount = (AccountInfo) session.getAttribute( ... );
    Here, assume that "AccountInfo" is a bean i.e., implements serializable and has standad getters and setters. So far nothing special but wait... What about the following variation (I saw something like this in some code at work)
    AccountInfo someAccount = (AccountInfo) (List) session.getAttribute( ... );
    So its just two sequential casts, right? What surprised me, was that the someAccount bean has its data populated with items from the list! Can someone provide an explanation? I was not aware of this mechanism. Should I get a new Java book?
    Thanks

  • Int to Object casting

    This should be a simple question, I just cant seem to get it.
    I want to cast an int to an Object.
    // --- Does not work
    int num = 16;
    Object obj = num;
    // --- Does not work
    int num = 16;
    Object obj = (Object)num;
    // --- Does not work
    Object obj = (Object)16;
    Anyone know?

    You can't cast a primitive. You can do this for your problem:
    Integer intObject = new Integet(intPrimitive);Lee

Maybe you are looking for