Evaluate a string containing a constant name
Hi,
how can I evaluate a string containing a constant name
such as
String a= " Integer.MAX_INT";
thx a lot,
tiz
Er...no. Integer.MAX_INT is an int, and you can't call methods on primitive types. :-)
What you might need to do is check for these constants and set the values yourself. Otherwise you'll have a load of difficulty parsing strings and what-not.
Similar Messages
-
Evalutate a string containing a numeric expression
I need a function which would evaluate a string containing numbers and operators like "1+1" and return 2. The function should take into account precedence and all arithmetic and logical operators
Thanks
MitaWhy don't you use the JDK compiler APIs (com.sun.javac.Main class) to compile on the fly a class implementing this interface:
public interface Evaluator {
public double evaluate() {
return xxx;
where xxx is your expression?
Obviously, you build this class' source at runtime when you get the expression as input, and after you compile it you load it with Class.ForName(), instanciate it with newIstance() and the call the "evaluate" method.
The advantage of this approach is that you can use "automagically" every expression available in java language. And with some extra effort of text-processing, even the Math functions!!!
Giorgio Maone -
Obtain string of IN variable name in PL/SQL
Hi,
Odd question. Is there a way to access an IN variable's object name in a procedure?
eg.
procedure (var1 IN VARCHAR2(6),
var2 IN VARCHAR2(6),
var3 IN VARCHAR2(6))
IS....You run this procedure and pass in parameters of:
var1 => 'abcdef',
var2 => 'defghi',
var3 => 'ghikjl';
In the code, I want to access the number in the string of the +variable name: var1+
In a naive sense,
num_of_in_var := substr(var1, 4,1) would be what i was hoping to achieve, but,
var1 is set to 'abcdef' so,
num_of_in_var := substr(var1, 4,1) would return 'd'.
Any thoughts?
Thanks
Edited by: chris001 on Nov 20, 2012 1:16 PMHere's an example of how (what you want to do using a procedure or function), can be done using a ADT/UDT (Advance/User Defined Type) in Oracle.
This approach will not work for standard procedures and functions as this type of dynamic referencing of the code unit/object to itself, is not possible.
SQL> create or replace type TSomeObject as object(
2 name varchar2(10),
3 id integer,
4 day date,
5
6 member function PropertyByNumber( n integer ) return varchar2
7 );
8 /
Type created.
SQL>
SQL> create or replace type body TSomeObject as
2
3 member function PropertyByNumber( n integer ) return varchar2 is
4 PLSQL_PROP_GET constant varchar2(1000) :=
5 'declare
6 obj TSomeObject;
7 begin
8 obj := :1;
9 :2 := to_char( obj.#PROPERTY# );
10 end;';
11
12 type TStrings is table of varchar2(30);
13 property TStrings;
14 dynamicBlock varchar2(1000);
15 res varchar2(4000);
16 begin
17 select
18 a.attr_name bulk collect into property
19 from user_type_attrs a
20 where a.type_name = 'TSOMEOBJECT'
21 order by
22 a.attr_no;
23
24 dynamicBlock := replace( PLSQL_PROP_GET, '#PROPERTY#', property(n) );
25 execute immediate dynamicBlock
26 using in self,
27 out res;
28
29 return( res );
30 end;
31
32 end;
33 /
Type body created.
SQL>
SQL> declare
2 obj TSomeObject;
3 begin
4 obj := new TSomeObject( 'John Doe', 123, trunc(sysdate) );
5
6 for i in 1..3 loop
7 dbms_output.put_line( 'property '||i||'='||obj.PropertyByNumber(i) );
8 end loop;
9 end;
10 /
property 1=John Doe
property 2=123
property 3=2012/11/23 00:00:00
PL/SQL procedure successfully completed.
SQL> Simplistic example (the PropertyByNumber could be a static class method defined in the abstract parent class) - and one that requires the object to essentially duplicate itself via a bind variable call to dynamic code. Not really the best of approaches, but demonstrates the flexibility (to do even interestingly weird stuff) in PL/SQL. -
Hi,
I have a string that contains a logical expression, for example String str="(true | false) & true".
I want to evaluate this expression just like if it was a boolean.
So I would like to write
if (str) { int test=0; }But this piece of code is wrong. I need a function "eval" that evaluate the expression contained in str, so that I can write
if (eval(str)) { int test=0; }How can I do ? Thank you for your answersNever worked with it yet, but have a look at the javax.script package (since java 1.6).
Piet -
When String instances in Constant Pool will be GC'ed?
Hi all,
I'm involved in an application development; where we are storing numerous string objects into multiple HashMaps. Since the string objects created/placed in HashMap may have duplicate values; we're calling String::intern() method to make use of String Constant Pool feature in Java. But, my concern is - When the Constant String instance will be removed from Pool? Is it follow the same behaviour that if no references are presentm it is eligible for GC; i.e., removal of an instance from all HashMaps?
Please help.
Thanks & regards,
R Kaja MohideenEJP wrote:
How do you figure?Doesn't say so in the Javadoc. It talks about another pool ...You're taking "A pool of strings, initially empty, is maintained privately by the class String." as meaning it's not "the constant pool"? I wouldn't interpret it that way. And based on the JVM spec, I don't see anything saying the intern()ed Strings go to a different pool than "the constant pool". And if it is a separate pool, then what does go into "the constant pool"?
http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#22972
"A runtime constant pool is a per-class or per-interface runtime representation of the constant_pool table in a class file (§4.4). It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time. "
"Each runtime constant pool is allocated from the Java virtual machine's method area (§3.5.4)."
http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6656
"The Java virtual machine has a method area that is shared among all Java virtual machine threads. [...] It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors [...]"
http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#73272
"The Java virtual machine maintains a per-type constant pool (§3.5.5),"
"A string literal (§2.3) is derived from a CONSTANT_String_info structure (§4.4.3) in the binary representation of a class or interface. The CONSTANT_String_info structure gives the sequence of Unicode characters constituting the string literal.
The Java programming language requires that identical string literals (that is, literals that contain the same sequence of characters) must refer to the same instance of class String. In addition, if the method String.intern is called on any string, the result is a reference to the same class instance that would be returned if that string appeared as a literal. Thus,
("a" + "b" + "c").intern() == "abc"
must have the value true.
To derive a string literal, the Java virtual machine examines the sequence of characters given by the CONSTANT_String_info structure.
If the method String.intern has previously been called on an instance of class String containing a sequence of Unicode characters identical to that given by the CONSTANT_String_info structure, then the result of string literal derivation is a reference to that same instance of class String.
Otherwise, a new instance of class String is created containing the sequence of Unicode characters given by the CONSTANT_String_info structure; that class instance is the result of string literal derivation. Finally, the intern method of the new String instance is invoked."
Edited by: jverd on Jan 23, 2012 8:09 AM -
Code to check whether a given string contains alphanumeric
Can anyone post the Code to check whether a given string contains only alphanumeric and no special characters
<Rule name='isAlphaNumericString'>
<RuleArgument name='testStr'/>
<block>
<defvar name='counter'>
<i>0</i>
</defvar>
<defvar name='splitString'>
<while>
<lt>
<ref>counter</ref>
<length>
<ref>testStr</ref>
</length>
</lt>
<append name='splitList'>
<substr>
<ref>testStr</ref>
<ref>counter</ref>
<i>1</i>
</substr>
</append>
<set name='counter'>
<add>
<ref>counter</ref>
<i>1</i>
</add>
</set>
</while>
<ref>splitList</ref>
</defvar>
<containsAll>
<list>
<s>A</s>
<s>B</s>
<s>C</s>
<s>D</s>
<s>E</s>
<s>F</s>
<s>G</s>
<s>H</s>
<s>I</s>
<s>J</s>
<s>K</s>
<s>L</s>
<s>M</s>
<s>N</s>
<s>O</s>
<s>P</s>
<s>Q</s>
<s>R</s>
<s>S</s>
<s>T</s>
<s>U</s>
<s>V</s>
<s>W</s>
<s>X</s>
<s>Y</s>
<s>Z</s>
<s>a</s>
<s>b</s>
<s>c</s>
<s>d</s>
<s>e</s>
<s>f</s>
<s>g</s>
<s>h</s>
<s>i</s>
<s>j</s>
<s>k</s>
<s>l</s>
<s>m</s>
<s>n</s>
<s>o</s>
<s>p</s>
<s>q</s>
<s>r</s>
<s>s</s>
<s>t</s>
<s>u</s>
<s>v</s>
<s>w</s>
<s>x</s>
<s>y</s>
<s>z</s>
<s>0</s>
<s>1</s>
<s>2</s>
<s>3</s>
<s>4</s>
<s>5</s>
<s>6</s>
<s>7</s>
<s>8</s>
<s>9</s>
</list>
<ref>splitString</ref>
</containsAll>
</block>
</Rule>
It Retruns 1 if it contains only alphanumeric otherwise 0 -
Construct a string containing a command
Hi experts
please help me
Is there a way to dynamically construct code, such as:
I'd like to write a method that receives as input a string identifying a node name, and use it as follows:
wdcontext.current<InputNodeName>Element.get<AttributeName><do whatever I want>
OR
Is there a way to construct a string containing a command, and then execute it?
Such as: If I construct the following in a string by concatenating different parts of the string: wdcontext.current<InputNodeName>Element.get<AtributeName>.<do whatever I want>
Can I then pass the resulting string to some function that actually executes it?Hi,
Unfortunately - there is no way to construct the command dynamically so that the command will execute. The parameters that are part of teh command may be dynamic (using Super classes and method overloading).
However, in case you want to write a single method that does all the function calling then what you need to do is:
1.) Make a context attribute that will hold some code (1,2,3 or A,B,C etc)
2.) Create the method that will read this attribute.
3.) After reading the attribute write a switch case or an if statement that will run your command.
Of course for this you will need to know all the required commands at design time.
Thanks.
p256960 -
How to find out whether the String contains chinese characters
I need to check if the string contains chinese characters in Java. Does anyone know how to do it? thx.
Since Java strings contain UNICODE code points, check the content against the relevant page here - http://www.unicode.org/charts/ .
-
How to parse a string containing xml data
Hi,
Is it possible to parse a string containing xml data into a array list?
my string contains xml data as <blood_group>
<choice id ='1' value='A +ve'/>
<choice id ='2' value='B +ve'/>
<choice id ='3' value='O +ve'/>
</blood_group>how can i get "value" into array list?There are lot of Java XML parsing API's available, e.g. JAXP, DOM4J, JXPath, etc.
Of course you can also write it yourself. Look which methods the String API offers you, e.g. substring and *indexOf. -
How to use string as a column name
Hello,
I have a fn getField() that returns a column delimited string - amt1,amt2 . I want to use this string as the column name in a second query on table MASTER_AMT and get the values for amt1 and amt2...so when i try....
select getField( 'NPC_NOYTG' ) FROM MASTER_AMT
WHERE ACTI_CODE = 'NPOR';
the o/p i get is...
GETFIELD('NPC_NOYTG')
AMT1,AMT2,AMT3
instead of...
AMT1 AMT2
500 0
that i require.
Any ideas on how to convert the string returned to a column name?
Thanks very much
rgdsTry this ....
In SQL*PLUS
SQL> var ref_c refcursor
--- Then type the follwing at SQL prompt
declare
cursor cur is
select column_name
from user_tab_columns a,
(select upper(getField( 'NPC_NOYTG')) fld FROM MASTER_AMT
WHERE ACTI_CODE = 'NPOR') col_lst
WHERE
instr(chr(44) || col_lst.fld || chr(44),chr(44) || a.COLUMN_NAME || chr(44) ) > 0
AND table_name = 'MASTER_AMT';
v_str varchar2(1000):= ' ';
begin
for c in cur loop
v_str := v_str || c.column_name || ',' ;
end loop;
v_str := substr(v_str,1,len(v_str)-1);
open :ref_c for
'select ' || v_str || ' from master_amt';
end;
--- after executing the above block, type the following at SQL prompt
SQL > print ref_c
Please let me know if this works for you. This should for any number of columns returned by the function.
Shakti
(http://www.impact-sol.com)
(Developers of Guggi Oracle) -
Best way to split a single string containing 2 words into word1 and word2
Whats the best way to take a string containing 2 words and split it into 2 strings ?
eg. "red ferrari"
string1 "red"
string2 "ferrari"If your list is always going to have exactly two words, then yes. Otherwise it depends on your requierments.
-
Hi,
I am developing windows store 8.1 app. I need to perform unit testing of my app . When I add the project (to be tested) to unit test
library project by using Add reference I am getting these errors:
Error
5
The .winmd file 'Microsoft.Advertising.WinRT.UI.winmd' contains duplicate type names. Type 'Microsoft.Advertising.WinRT.UI.AdControl'
is already registered with the in-process server 'CLRHost.dll'.
UnitTestLibrary
Error
6
The .winmd file 'Microsoft.Advertising.WinRT.UI.winmd' contains duplicate type names. Type 'Microsoft.Advertising.WinRT.UI.AdSettingsFlyout'
is already registered with the in-process server 'CLRHost.dll'.
UnitTestLibrary
Error
7
The .winmd file 'Microsoft.Advertising.WinRT.UI.winmd' contains duplicate type names. Type
I found a blog here . I tried it but i coudn't see the xml file in this path C:\Program
Files (x86)\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\MSAdvertisingXaml\6.1\SDKManifest.xml
I found the file in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\MSAdvertisingXaml\8.1 . But when i tried to update it is displaying an access denied messageHi Alok,
Thank you for posting in MSDN forum.
Based on your issue, to check if the issue is related to the specified unit test or the VS IDE issue. I suggest you can refer the following document to re-create a simple new unit test with windows store app and then add the windows store app as reference
to the Unit test project check this issue.
https://msdn.microsoft.com/en-us/library/windows/apps/jj159318.aspx
(1)If you did not get same error message in the new unit test project, I doubt that maybe you did not reference the windows store app successfully. So please refer the above document to reference it again check this issue.
If you still could not reference successfully, please share me the mainly code for the windows store and unit test project.
Or you could share me your solution include the reference project and unit test project.
You could upload your sample to the OneDrive and then copy link here.
(2) If you get same error message in the new unit test, I suggest you could try to repair or re-install the VS IDE and then check this issue again.
Hope it help you!
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Execute a string containing a PL/SQL block
Hi,
I would like to build a string containing a PL/SQL block and execute it dynamically. Is there way to do this.
Note - The reason I want to this is because, based on certain table data dictionary views the declaration section of the PL/SQL block that I am building might vary
I tried to use EXECUTE IMMEDIATE, it didn't work, pls let me know if I am missing something.
DECLARE
v_str VARCHAR2(1000);
BEGIN
v_str := 'BEGIN NULL; END';
EXECUTE IMMEDIATE v_str;
END;
/Hi,
Just happened to find it. EXECUTE IMMEDIATE can be used, the bug with my code was I didn't have a ; after the END statement. Corrected code is below, thanks for your time
DECLARE
v_str VARCHAR2(1000);
BEGIN
v_str := 'BEGIN NULL; END;';
EXECUTE IMMEDIATE v_str;
END;
/ -
Quick string question finding if a string contains a character
hello peeps
is there a quick way of checking if a string contains a specific character
e.g.
myString="test:test";
myString.contains(":");
would be true
any ideas on a quick way of doing itis there a contains() method in 1.4.2? i couldnt see
it in the docsNo there isn't. But the 1.5 has a contains(CharSequence s) method. -
Table SMOXHEAD contains no BDOC name
Hi all,
As we are crosschecking data in RSA3 for the datasource 0CRM_CONFIRM_I giving like infosource/Infoobject need to be maintained.
Later we come to know that the datasource 0CRM_CONFIRM_I was not maintained in BWA5 tcode.
I have given this datasouce in BWA1 and clicked on check button,its takes me to next screen giving error like " Table SMOXHEAD contains no BDOC name" .
Can any one explain me how to solve this problem?
and also if want to create BDOC for theis datasource how can we do it?(Please explain it in step by step)
Your help will be appreciated
Regards,
Praveena.Have you see this thread
Re: Data source 0CRM_MKTELM5_ATTR is not active in Quality system
Maybe you are looking for
-
When I send an email it says that it is sent, but it never gets to the recipient. I am using multiple email addresses to check this and have looked in spam and all folders and the message is just not actually going through. I can log in to web-mail a
-
Unable to create portal desktop
Hi All, I just installed a NW Portal 7.0, AIX 5.3 OS, DB6 The installation went fine and the portal was working fine. Now I tried to make a new portal desktop, but I get a 'Portal Runtime'error message on the editor screen. Below is the default trace
-
On some websites, when I click on the left arrow or use the backspace key, the browser doesn't return to the parent URL. Looking at the list of currently-accessed URLs, the current URL is duplicated in the stack, so hitting back or left arrow just br
-
Is there anything similar to 1Password for the PC? I'd like to keep encrypted passwords on my iPhone. Ideally, if they could fill into webpage logins and such that'd be great, too. I've heard/read about the webapp, but I don't really trust that, and
-
Queries about Enterprise Comp.Management
Hi Experts, 1/ Client system is on EHP-7 but when i check the Enterprise Compensation Management Section under Performance Management i could not find the Nod. How to activate the ECM component in EHP-7, somewhere i read it is standard functionality