java

regex backreferences in IntelliJ

Hi, I want to use IntelliJ's find-and-replace feature to perform the following transformation: // Replace this model.put('foo', 'bar') // With this model['foo'] = bar I've tried the following: Text to find: model.put\((.*),(.*)\) Replace with: model\[\\1\] = \\2 But Intellij doesn't seem to recognise \\1 and \\2 as backreferences. ...

Count Frequency in a Randomly Generated List of Numbers

I generated 100 random numbers from 0-9, i am supposed to count how many times each number appears. Storing it in an array of 10 integers and count it. heres what i have so far, i cant figure out the count part Random r = new Random(); int[] integers = new int[100]; for (int i=0; i<integers.length; i++) { integers[i] = (r...

How do I change the address used by a CXF Web Service to one different than the one specified in the wsdl file?

I've got it working when I get the wsdl based on configuration, but I'd like to just tell it to use a specific address for the service call and use a local copy of the wsdl. MyWebService serviceDefinition = new MyWebService(new URL(wsdlLocation)); service = serviceDefinition.getMyWebServicePort(); Does anyone know the best practice fo...

Deployment time checklist

Hi there, If you were to create a checklist of things you needed to do before you deploy a typical jee webapp that makes use of servlets, ejbs, o/r mapping, relational databases, etc what would be on it? Like any sort of time out properties and settings, pool sizes, jndi related properties, etc. that are crucial at production deployment...

Servlet request.getParameters non english character help!

Heya guys, I'm in desperate need of help. I have a Java servlet that is accessed by a HTTP Get URL with eight parameters in it. The problem is that the parameters are not exclusive to English. Any other language can be in those parameters, like Hebrew, for example. Now, when I send the data - either from the class that is supposed to...

Limiting/controlling the users ability to print in Java.

I am looking to right an application that limits the number of times a user can print something, its there anything in Java that will allow me to control the printing dialogue to this aim? Im going to look into these: http://www.wildcrest.com/Software/J2PrinterWorks/documentation/J2Printer14.html http://www.softframeworks.com/products/...

c# enums: can they take members and functions like java enums?

hello, in java it is possible to give an enum a constructor as well as member variables and functions. i was wondering if something like this is possible in c# enums as well. if so, how? thanks a lot! ...

Designing a better API?

What are the best practices and patterns to be followed for designing APIs? How to achieve implementation hiding the best way (C++/Java)? Designing APIs which are generic in nature? Any reference books/links which guide with neat examples to beginners? ...

Shifted text in swing app on OS X

Hi I have a little java+swing app. Until now it worked OK, on OS X and on windows. But recenly a user has noticed that on his OS X (version unknown yet, nor the java version) that all texts in the GUI are shifted up and cut (as you can see on the screenshot). And HTML link is shifted down and cut. All those elements are JLabels. Th...

How to implement StringBuilder.replace(String, String) in terms of String?

String contains a bunch of useful methods such as String.replace(CharSequence, CharSequence) that are completely missing from StringBuilder. Is there a reason why? Is there an easy way to implement these methods without the huge overhead of invoking StringBuilder.toString() which copies the string every time? ...

Clean namespace handling with dom4j

Hi, We are using dom4j 1.6.1, to parse XML comming from somewhere. Sometime, the balise have mention of the namespace ( eg : ) and sometime not ( ). And it's make call of Element.selectSingleNode(String s ) fails. For now we have 3 solutions, and we are not happy with them 1 - Remove all namespace occurence before doing anything wi...

What Are Binding Generators For?

A friend raised this on Twitter: @name_removed doesn't understand why binding generators seem to think writing pages of XML is vastly superior to writing pages of C++... Having never encountered binding generators before, I decided to look them up. Seems pretty self-explanatory, convert C++ classes to XML format. But now I need someone ...

How do I return List<String> from a method where I sent to put(Object) into a map (got example)

I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public void set(KEY key, Object value) { values.put(key, value); } private Object getObj(KEY key) { return values.get(key) == null ? key.getDefaultValue() : values.get(key); } public List<E> getList(KEY key) { return (List<E>) getObj(key); } ...

Smart Card Query

Hi I need to know what kind of Java Smart Card to buy and where I can get some from? What are the factors i should consider while choosing a card / vendor? Thanks ...

JAXB XJC code generation - ObjectFactory class is incomplete

Hello I generate Java classes from my XSD schema file using XJC command line tool. The ObjectFactory class generates incomplete content. It generates creation methods without JAXBElement<Type> createType decoration. What may be the reason of this? Regards Dominik ...

Algorithm for calculating the power set

Hi! I just discovered an algorithm for finding the power set. I googled after solutions, but found none that worked any good, so I figured out one myself. But I wonder what algorithm it is, because I cannot find it on the net or in any books. I mean, does it have a name? I hardly think I'm the inventor of it. But compared to the algorit...

Java Unicode variable names

I got into an interesting discussion in a forum where we discussed the naming of variables. Conventions aside, I noticed that it is legal for a variable to have the name of a Unicode character, for example the following is legal: int \u1234; However, if I for example gave it the name #, it produces an error. According to Sun's tutori...

Adding image to email via Java mail

Code is below: MimeMessage mail = new MimeMessage(session); mail.setFrom(from); MimeMultipart multipart = new MimeMultipart("related"); MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(bodyText, "text/html"); multipart.addBodyPart(htmlPart); MimeBodyPart imgPart=new MimeBodyPart(); String path = "/ivr/imagelogos/accentu...

JUNG (Java Graph): How to prevent Vertex- and Edge-Labels from overlapping?

I'm currently using Jung to draw graphs (I really mean graphs not charts!). The problem: Vertex and Edge Labels are overlapping with the Vertexes and the Edges. This leads into strange looking graphs: the "produces" label is overlapping with the vertex and the "60" edge-label is also overlapping with the vertex. Are there any possib...

How do I count the number of 100 Continues the server sent me?

I am using Apache Commons HttpClient 3.1, and I found that HttpURLConnection from Sun drops the 100 Continues from the stream. So therefore I don't seem able to get the 100 Continue as they are apparently dropped by Sun's code. I am unable to move forward to HttpClient 4.0 as that would require many changes to already existing code so ...