java

How to add a child object to a parent with App Engine?

I have two classes in an owned one-to-many relationship. The parent is Map, and the child is POI (point of interest). I am trying to add a POI to an existing Map, but I get an exception when I try to persist my changes. Here are the two classes: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Map { @Primar...

java and python equivalent of php's foreach($array as $key => $value)

EDIT: Amazingly, newacct's answer has accumulated 12 points in the four hours since I posted my question. This, despite its being incorrect. As alternatives to php's associative array, newacct offers Java's HashMap and Python's dictionary, neither of which preserves key order. cmcg provided a correct answer for the Java version. That is...

How to I output org.w3c.dom.Element to string format in java?

I have an org.w3c.dom.Element object passed into my method. I need to see the whole xml string including its childnodes (the whole object graph). I am looking for a method that can convert the Element into xml format string that I can system.out.println on. Just println on the element object won't work because toString won't output the...

manipulate current time in unit testing?

Is there any way to manipulate the current time in a jUnit 4.5 test? I have the following method which I'd like to have a unit test for public String getLastWeek() { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("Europe/Stockholm")); c.setFirstDayOfWeek(GregorianCalendar.MONDAY); c.add(GregorianCalendar.WEEK_OF...

Migrate old J++ project to Eclipse?

I've got my hands on an old Microsoft J++ project that uses some old Microsoft-specific things from the Microsoft Java Virtual Machine (now deprecated and unsupported). It uses additional things from the old Microsoft Java Development Kit, which I can't find anywhere on the web. It seems the best route forward is to migrate this project...

input text, input password, radiobutton, checkbox, textarea etc in java

Where can I find information like how to make input text, input password, radiobutton, checkbox and textarea in a software made with java? ...

Hibernate Object Identity Question

In java persistence with hibernate, gavin suggests that we use business key for equality comparison. Business keys can not only involve multiple field comparisons, but there is no guarantee that the "perfect" business key's semantics will not change in future. We live in non ideal world and business requirements and laws change very freq...

Picking my next graphics engine (Java vs. C#)

Requirements I am developing a music game that requires access to the audio line-in and classes to help me analyze a MIDI file (playing the MIDI is NOT necessary for me). Secondly, I need a graphics engine that allows easy and quick development (within reason). The game's focus is not cutting edge graphics - think along the lines of Aud...

Old Version of SuperWaba

Hello, I was searching for the old versions of SuperWaba, but i can't found anyone on internet, because the newer versions of SuperWaba are commercial, but the old versions are free, then if someone have the SuperWaba SDK free version on archive, please post it here. Thanks! ...

What am I missing to get a PHP ScriptEngine in Java

I try to get a PHP ScriptEngine from the ScriptEngineManager, but getEngineByName("php") returns null. The following unit test works, if I replace "php" with "javascript", but it fails for "php". import static org.junit.Assert.*; import org.junit.Test; import javax.script.*; public class ScriptEngineTest { @Test public void exe...

Difference between Abstract and Generic code

Hi, What's the difference between the word "Abstract" and "Generic" code in case of Java? Are both mean the same? ...

Simplest way to implement backend server for multiplayer JavaScript game? (COMET/longpolling)

I've been writing a game in JavaScript, and it's time to make it multiplayer. I would like to use AJAX long-polling to get the current game state, as well as implement the lobby. The server just needs to perform basic functions, like store the gamestate in the mysql database, retrieve the gamestate, and format the scoreboard. I think...

How should i "build" things now I've implemented polymorphism? (Java, sim game)

Hi all. I'm working on a small java game which is a sort of clone of the 1995 game Theme Hospital. I've recently been working on the GUI and the Level structure now I have the path finding and grid working. My current way of "building stuff" consists of one room and one reception desk, and it works ok so far, but I need to implement a wa...

Draw transparent arcs, not images, in J2ME?

Hi all, I've been happily coding an opensource game for fun, but i just realized that Graphics.setColor() doesn't understand 0xAARRGGBB... I want to get a more and more transparent colour, in which I'd draw some arcs (discs). My goal was to make them shine though each other like in this image: http://kenai.com/projects/xplode (the logo ...

Resizing JPanel to prepare for printing without removing it from its original position

In my program I frequently need to print various JComponents (generally JPanels) and I like them to be full-page. The way I do it now is by using the following code: g2d.scale(pf.getImageableWidth()/componentToPrint.getWidth(), pf.getImageableHeight()/componentToPrint.getHeight()); but this often stretches or otherwise deforms whatev...

Is it possible to shortcut a regular expression into matching?

I have a few regular expressions which are run against very long strings. However, the only part of the string which concerns the RE is near the beginning. Most of the REs are similar to: \\s+?(\\w+?).* The REs capture a few groups near the start, and don't care what the rest of the string is. For performance reasons, is there a way t...

Maven2 Dependencies and Native Libraries

I have a Java project which I've used Maven2 and the assembly plugin to help with compiling and packaging, theres quite a few dependencies so its quite a nightmare to manage especially since im quite new to Maven. Anyway, Im using a Java library which has an accompanying native Windows library (DLL) and im trying to work out how to spec...

Implementing Unowned relationship Google App Engine

My question is more of a best practices question on how to implement unowned relationships with Google App Engine. I am using JDO to do my persistence and like recommended in the google docs I'm persisting my list of unowned relationships like so: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class User implements...

render complex org chart similar javascript/flash/java graphic library

i am looking for javascript/flash/java graphic lib. that able to render nicely a very complex relationship where one node is relate to another node etc. for example a--> b---> c b--> d,e,f any recommandation library? ...

How can I read a hard drive's factory serial number from a Java program?

I want to read a hard disk's factory serial number, not the volume serial number from a Aava program or C or C++ if this isn't possible in Java. ...