Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
It is possible to do expression evolution comparison using string in java.
Say if I have list of rules :
create AND [table OR view] AND as AND select
[insert OR delete] AND table
Assume that OR group is always within the square brackets []
I would like do a pattern match (similar to the database GRANT permissions)
I want to block the following commands :
create table something as select * from test => should be blocked (from condition 1)
create view something as select ***** => should be blocked (from condition 1)
insert into table => should be blocked (from condition 2)
delete table => should be blocked (from condition 2)
select * from test => allowed as it doesn't match the rule pattern
In general I want to build something similar to block/grant permission on database queries.
Is there any Java library for expression evaluation matching in Java?
You can make use of the below two simple regex
1.create (table|view).*?as select .*
2.(insert|delete)?.*table
You can test it in https://regex101.com/ and let me know if you find any issue.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am looking for Opensource Java library which could help me in expanding all the possible values out of Numeric Regex, for example: if I give a range 1234[7-9] as input, it should output 12347,12348, 12349, similarly taking care of 123[4-6][7-9], which would translate to 12347, 12357, 12367 so on. Instead of reinventing wheel I would like to know if there are any libraries which could do this. This is only for Numeric regex with defined range.
I have once tried out Xeger which was good enough for such simple expressions similar to yours above. You will also need automaton jar package, that you can download as a library in order to use Xeger.
Example how to use:
String regex = "123[4-6][7-9]";
Xeger generator = new Xeger(regex);
Set<String> generated = new HashSet<>();
for (int i = 0; i < 100; i++) {
generated.add(generator.generate());
}
System.out.println(generated);
//[12367, 12348, 12359, 12349, 12357, 12368, 12369, 12347, 12358]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a clojure IDE that can help autocomplete a Java object method?
For example:
(def my-temp-file (java.io.File/createTempFile "filename" ".txt"))
then i want to input:
(.deleteOnExit my-temp-file)
how can i :
(. my-temp-file delet|"cursor here") ;; how can i get auto-complate del* methods
or
(.delet|"cursor here" my-temp-file) ;; how can i get auto-complate del* methods
...
just now, I tried intellij14.1.4 + cursive0.1.60, it's wonderful.
i tried to auto-complate from "delete" to " deleteOnExist"
Situation 1 ,This is ok:
Situation 2 ,this canot work :
How can I get the "deleteOnExist" autocomplete in Situation 2? please help
Cursive Clojure, an IntelliJ plugin has excellent Java interop that can do this for you.
The problem with your example is that def does not automatically add the :tag metadata based on the type of its initialiser. You can see this as follows:
Connecting to local IDE...
Clojure 1.7.0
(import java.io.File)
=> java.io.File
(def temp-file (File/createTempFile "filename" ".txt"))
=> #'user/temp-file
temp-file
=> #object[java.io.File 0x6c8b97fd "/var/folders/x1/9k18lcbn4qnfs4pptm0dm8fm0000gn/T/filename8344242261832815384.txt"]
(meta #'temp-file)
=> {:line 1, :column 1, :file "NO_SOURCE_PATH", :name temp-file, :ns #object[clojure.lang.Namespace 0x548b68c5 "user"]}
So your example will work in cases like the following:
(let [temp-file (File/createTempFile "filename" ".txt")]
(temp-file .dele|))
Where | represents the caret. It will also work if you manually add the tag to your def, like:
(def ^File temp-file (File/createTempFile "filename" ".txt"))
Since you put the tag emacs, you can try cider with ac-cider. However, I found this combo a bit error-prone in terms of auto-completion precision. The suggested options can be methods from other classes.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Write the Java code for an arbitrary expression evaluator (supporting _, -, *, /). The - and / operator only works on two operands, the others can have any number or operands. The / operator will additionally check that there is no 0 in the second operand. If it does, then it will throw a BadArithmeticException.
Write the code using the Composite pattern. Also write a client class that will create objects and calculate expressions to demonstrate the use of the composite pattern. The common method in the composite hierarchy is called eval. Here is the signature for eval.
public int eval() throws BadArithmeticException { ...
Not really sure where to begin here. Any help would be appreciated.
This isn't really a question but I can offer a suggestion at least. I would start by trying to write your exception so that you understand what you should be doing. You can find this in the Oracle docs here:
http://docs.oracle.com/javase/tutorial/essential/exceptions/creating.html
If you know that you can't divide by 0, think about what kinds of expressions a user (or you) could input that would cause a BadArithmeticException.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a use case where values my function accepts could be of type:-
1. mailto:abc#abc.com
2. tel:3402904323
3. http(s)://www.google.com
4. www.google.com
5. //www.google.com
6. /content/abc/def/index
7. javascript:;
8. blank
9. #
10. http(s)://www.google.com/index.html#abc
11. http(s)://www.google.com/index.html
All these are to be treated as valid and i have to create a URL out of them for e.g. for input 6 i would need to append (.html). For 7th i might need to escapeHtml and rest could be returned as is.
Is there a standard java API to do this or any standard logic i could put into doing this.
Please help.
Use String#matches with the the following regular expressions, respectively.
(?i)mailto:[a-z0-9]{1,}[.a-z0-9]*#[a-z0-9]{1,}[.a-z0-9].[a-z0-9]{2,}
tel:[0-9]{10}
http[s]{0,}://
www\.[a-z0-9\-]{1,}\.com
//www\.[a-z0-9\-]{1,}\.com
/content/([a-z0-9\.\-]{1,}/*)*
nice try
[^\w\W]*
#
http[s]*://[a-z0-9-]{1,}\.[a-z0-9-]{1,}\.com/([a-z0-9-_%\?\=]{1,}/)*[a-zA-Z0-9_-]{1,}\.html#[a-zA-Z_\-\.]{1,}
http[s]*://[a-z0-9-]{1,}\.[a-z0-9-]{1,}\.com/([a-z0-9-_%\?\=]{1,}/)*[a-zA-Z0-9_-]{1,}\.html[a-zA-Z_\-\.]{1,}
Here is an example of using a regular expression, in this case it will return a boolean value (it matches or it doesn't match)
public static void main(String[] args)
{
String pattern = "http[s]*://[a-z0-9-]{1,}\\.[a-z0-9-]{1,}\\.com/([a-z0-9-_%\\?\\=]{1,}/)*[a-zA-Z0-9_-]{1,}\\.html#[a-zA-Z_\\-\\.]{1,}";
String string = "http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#matches-java.lang.String-";
/*
* This will print the boolean literal true or false
*/
System.out.println( string.matches(pattern) );
}
Just try to create a java.net.URI with the string. If there is a syntax error you will get a URISyntaxException. All the above pass provided that "http(s)" really means "http" and "https" separately. If you need to restrict the scheme to what is shown above, just get the scheme and look it up in a table, and fail it if isn't there.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a way in java we can convert an expression (xml or any other) to logical operations.
for example I have a property
prop01=Achivment:APPCom,done&&TODO:getforecast,!done;Achivement done
is there a way I convert it to java code like
Map userData = getUserData();
Map achivements = userData.get("achivements");
Map TODOs = userData.get("TODOs");
String achiv = achivements.get("APPCom");
String todo = TODOs.get("getforecast");
if(achiv == "done" && todo != "done")
system.out.println("Achivement done"); // part after ; in expression
any third party available for this kind of task?
I don't think this can be done with any third party library directly. You may need to use some library like Antlr to write a translator to translate from your expression to your Java code.