java

Access Map<Enum, Object> in JSTL

I have: public enum MyEnum{ One, Two, Three } From controller, I put in the model: HashMap<MyEnum, Long> map = new HashMap<MyEnum, Long>(); map.put(MyEnum.One, 1L); mav.addObject( "map", map); How do I in my JSTL access the object in the map for key enum MyEnum.One, in a neat way? ${map['One']} //does not seem to work... nor ...

Given a classpath resource, is there a way to get the java.io.File object that has/contains it?

If I have a resource on a classpath, I can both load it as stream fine, and there is even a URL representation of it. Unfortunately some implementations of the Url do not implement lastModified correctly. What I would like is to take a path to something in the classpath, and then resolve it to a file that it is in on disk - if it in a j...

Java - Is it possible to print text that can be edited by the user (for console programs)

Say I allow the user to edit something, like the phone number in an Address Book (actually, that's exactly what I'm doing). Is there something that I can add to println that will allow me to insert a variable to display as fully editable text? The assignment that I'm doing this for doesn't actually call for this, but I think it would be ...

how to create a counter in a dr java program

//Neel Patel //Friday October 9th, 2009 /*This is a quiz program that will ask the user 10 questions. the user will answer * these questions and will be scored out of 10.*/ class Quiz { public static void main (String args[]) { //Instructions System.out.println("instructions"); System.out.println(" "); System.out.println("1. You...

Java Regexp: UNGREEDY flag

Hi, I'd like to port a generic text processing tool, Texy!, from PHP to Java. This tool does ungreedy matching everywhere, using preg_match_all("/.../U"). So I am looking for a library, which has some UNGREEDY flag. I know I could use the .*? syntax, but there are really many regular expressions I would have to overwrite, and check th...

how to reset the interactions window in dr java?

this is the code that i am working on... i would like to know how to reset the interactions window after every question is asked so that the window is clear for the next question to be shown to the user but i do not want the Score to be reset either so that i can display the score at the end. iam looking for the correct syntax and code ...

Immutability of Strings in Java

Consider the following example. String str = new String(); str = "Hello"; System.out.println(str); //Prints Hello str = "Help!"; System.out.println(str); //Prints Help! Now, in Java, String objects are immutable. Then how come the object 'str' can be assigned value "Help!". Isn't this contradicting the immutability of strings in ...

Understanding Java Byte Code

Often I am stuck with a java class file with no source and I am trying to understand the problem I have at hand. Note a decompiler is useful but not sufficient in all situation... I have two question What tools are available to view java byte code (preferably available from the linux command line ) What are good references to get fam...

C# RSA with no padding

I'm busy trying to port Java code that looks like this Cipher rsa = Cipher.getInstance("RSA/ECB/nopadding"); rsa.init(Cipher.DECRYPT_MODE, RSAPrivateKey); decryptedData = rsa.doFinal(data, 0, 128); to C#, but as it seems the RSACryptoServiceProvider, forces you to either use OEAP or PKCS1 padding. I know no padding isn't s...

Java: Data structure for caching computation result?

I have an expensive computation, the result of which I'd like to cache. Is there some way to make a map with two keys? I'm thinking of something like Map<(Thing1, Thing2), Integer>. Then I could check: if (! cache.contains(thing1, thing2)) { return computeResult(); } else { return cache.getValue(thing1, thing2); } pseudocode. But...

Java file construction - why am I getting different results?

I've just stumbled on a weird scenario and am wondering if anyone can explain this behaviour. Case 1: File base = new File(""); System.out.println(base.getAbsolutePath()); System.out.println(base.isDirectory()); System.out.println(base.canRead()); Result: C:\workspace-sss\Commons false false Case 2: File base = new File("C:/works...

Hibernate with ZK

Does anyone have any experience on getting Hibernate working with ZK? Thanks Edit: Sorry to clarify what I am looking for: I am looking for anyone that has experience doing this, maybe they can clarify is it easy? I have never used Hibernate before. In addition can anyone provide any resources focussed around this issue? ...

Java: Trouble with TreeSet and LinkedList

I have an unsorted linked list. To sort it, I thought I'd put the values into a TreeSet with a comparator supplied, then return those values as a new linked list. Yet, it fails. Comparator: public class SortSpeciesByCommonName implements Comparator<Species> { /** * a negative integer, zero, or a positive integer as the first ...

Navigation into GridView does not trigger OnItemSelectedListener

I have a layout that looks like this (some attributes removed for brevity) <RelativeLayout> <ImageButton android:id="@+id/button" android:nextFocusRight="@+id/gridview"/> <GridView android:id="@+id/gridview" /> </RelativeLayout> When I navigate using the DPAD from the button to the gridview, the On...

Parsing Ambiguous Dates in Java

Is there any way in Java to guess the date format when it is not explicitly defined? For example a user types in 11Mar09 or 11-09-2009 or 11/09/2009 or 11-09 what is the best way of parsing this to a Date object without either a bunch of try catch or raising an error? ...

Is there a Java equivalent of frexp?

Is there a Java equivalent of the C / C++ function called frexp? If you aren't familiar, frexp is defined by Wikipedia to "break floating-point number down into mantissa and exponent." I am looking for an implementation with both speed and accuracy but I would rather have the accuracy if I could only choose one. This is the code sampl...

Performance of Arrays.asList

What is the cost of using Arrays.asList to convert static object arrays? Assuming that the object array has N items is it just an O(N) algorithm, where all of the items are copied by reference or is it merely a facade where the original array is put behind a List facade? ...

How to insert values result set into hashmap without iterating in Java 1.4?

I want to validate a value against values retrieved from a result set's first column. I have to do the same validation operation approximately 1000 times. So, I want to decrease the time complexity of this comparison from O(n) to constant. Is there some function through which I can put all of the values of result set's column into a ...

assertArrayEquals(Object[] o1, Object[] o2) cannot be found

My setup: Netbeans 6.7 Java6 JUnit 4.5 added as the Test libraries When I try to pass in two class arrays (cast as Object[]) I get the error "cannot find symbol" and my test case will not compile. I do not have an issue with the other assert statements, and as I said I am using the JUnit 4.5 libraries. Does anyone have a clu...

stretch(overflow if data exceeds) a textfield in jasper reports

I have a textfield above subreport in detail section, the textfield doesn't stretch if data overflow due to the subreport, If i remove the subreport it works as expected. What should i do to stretch the textfield. this is my detail section:- ...