java

How do I use a script's output in an Ant Conditional

I want to do something like the following <target name="complex-conditional"> <if> <exec command= "python some-python-script-that-returns-true-or-false-strings-to-stout.py/> <then> <echo message="I did sometheing" /> </then> <else> <echo message="I did something else" /> </else> </if> </target> How ...

php login system ?

What is the best way to make a user-login system using PHP? I want to use same login system to be called by another languages also like midp iphone java Desktop Flex I don't want to use cookies ...

How to parse a URI like this in Java

I'm trying to parse the following URI : http://translate.google.com/#zh-CN|en|你 but got this error message : java.net.URISyntaxException: Illegal character in fragment at index 34: http://translate.google.com/#zh-CN|en|你 at java.net.URI$Parser.fail(URI.java:2809) at java.net.URI$Parser.checkChars(URI.java:2982) ...

Image panel not repainted unless on system events

A friend of mine asked me to help him with Swing, and I reached a point where I can't solve an issue. So, first I have an ImagePanel public class ImagePanel extends JPanel { private Image img; public void setImage(String img) { setImage(new ImageIcon(img).getImage()); } public void setImage(Image img) { int width = t...

Java TreeMap containsKey invariably returning true?

I'm writing a Java program that's using the TreeMap interface, and I'm having a problem with containsKey. It is returning true even when I give containsKey something that I know for certain is not in the TreeMap. What could be the cause of this? Thanks so much in advance. -- Edit: I am writing a program that counts the occurrences o...

what kind of data structure do i need to implement a hashlist for storing coordinates?

i need to build a position manager class to tell me if a position is available. so i tried this : enter code here public class PositionManager { Hashtable currentPositions = new Hashtable(); void occupiedPosition(int x,int y){ this.currentPositions.put(new Integer("4"),new Integer("5")); this.currentPositions.put(new Int...

Creating a rectangle with vectors and points in java?

Hi, i have been given an assignment to create a class that defines 2 points. Then create a class that defines a vector. Then create a class that defines a rectangle (4 vectors). Prior to this assignment i was given the task to create a point and vector class to calculate the length of a vector. I had 100% marks on that assignment so i kn...

HttpClient and SSL

I know, there are many different questions and so many answers about this problem... But I can't understand... I have: ubuntu-9.10-desktop-amd64 + NetBeans6.7.1 installed "as is" from off. rep. I need connecting to some site over the HTTPS. For this I use Apache's HttpClient. From tutorial I read: "Once you have JSSE correctly installed,...

Are there any .NET/ JAVA free or opensource SPAM detectors that yield good results?

I am looking for a .NET/ JAVA free or opensource SPAM detectors accesible via an API that yield good results. I would consider paying for a good service that accomplishes this as well, but ideally, I would like to go open source. Does any one have any good experiences with any or recommendations? Ideally, I would get the text/markup to ...

Converting C++ Bit Pattern to Java

I am converting a C++ program to Java and got completely stuck in the following method which blew my mind. Would you be kind enough to explain what this method is doing? long TSBCA::GetSignedValue(const NDataString &value) { static NDataString s; s = value; long multiplier(1); size_t len(s.Len()); ...

Why is java.lang.ThreadLocal a map on Thread instead on the ThreadLocal?

Naively, I expected a ThreadLocal to be some kind of WeakHashMap of Thread to the value type. So I was a little puzzled when I learned that the values of a ThreadLocal is actually saved in a map in the Thread. Why was it done that way? I would expect that the resource leaks associated with ThreadLocal would not be there if the values are...

Limiting Thread Execution Processor Cycles in Java

Hey, I'm writing an AI-testing Framework for a competition. Participants submit a Bot class which matches a given Interface. Then all the bots play a turn-based game. On every turn, I want to do the following: For every bot B: start a thread that runs at most N cycles and does B.getNextMove() wait for all threads to complete Mak...

Java: Converting a char to a string

Hello all, I have just done this in eclipse: String firstInput = removeSpaces(myIn.readLine()); String first = new String(firstInput.charAt(0)); However, eclipse complains that: The constructor String(char) is undefined How do I convert a char to a string then?? Thanks EDIT I tried the substring method but it didn't work f...

Error while validating XML file with XSD

Hi, I have a xml file, let's call it test.xml and I have a schema for validation (schema.xsd). I'm also using the last version of TomCat. I was wondering what could cause the following errors : Error: URI=file:///C:/../Upload/test.xml Line=2: Document is invalid: no grammar found. Error: URI=file:///C:/../Upload/test.xml Line=2: Documen...

SpringLayout problem/challenge

SpringLayout is claimed to be very powerful. I tried to implement what I thought was a fairly simple layout using SpringLayout and I'm failing badly. Reduced to the minimum, I want 4 JButtons on my JFrame, side by side: *=====================* | +--+ +--+ +--+ +--+ | | |b1| |b2| |b3| |b4| | | +--+ +--+ +--+ +--+ | *====================...

Java ResourceBundle Performance

I am using a ResourceBundle and Locale to lookup property values. Quite simply, the code looks like this: public static String getPropertyValue(Locale locale, String resourceName, String key) { ResourceBundle resource = ResourceBundle.getBundle(resourceName, locale); return resource.getString(key); } My question is about p...

Best idiom for a decrementing loop

What's the best/preferred idiom for a decrementing for loop, and why? for(int idx=(len-1); idx>=0; idx--) {...} or for(int idx=(len-1); idx>-1; idx--) {...} or (based on sylvarking's answer, but using for to constrain the index scope) for(int idx=len; idx-->0; ) {...} Is one or the other more likely to trip up another developer?...

Are Socket's events queued in Flash?

I'm trying to implement a binary protocol between a flash application and a Custom Java Server using TCP/IP sockets, the protocol's messages are of variable length, so my idea is to add a field indicating the number of bytes I have to read before parsing a complete message, something like this: bytesToRead = socket.readInteger(); var bf...

How to have program wait for a button press in Java.

Now, I'm not sure if this is possible or even the best way to accomplish what I'm trying to do, but basically I'm creating a very simple simulation program with a very simple Swing GUI. After each round of the simulation, some buttons on the interface are enabled for the user to make changes and then the user can press the "continue" b...

How to connect to machine ip address & port via grails app

I'm running MacOS 10.6 with the default settings for my machine with Internet Sharing turned on. What needs to be configured to allow access to my machine's grails/jetty instance on a specific port? I can do 'http://localhost/' as well as 'http://192.x.x.x/' but if I were to set my grails app to run on a specific port, I can't access ...