How to implement HashMap in GWT? - gwt

I have some amount of messages which are coming to my client from the server.
Every messages have an unique key which is possible to be duplicated in messages I have already received.
Which collection can I use in GWT to avoid duplication?
HashMap seems not to be a case for GWT. Is there any other way to organize it?

You can use the standard java.util.HashMap in GWT without problems. Be sure you haven't accidentally imported the com.google.gwt.dev.util.collect.HashMap. It happened to me several times while using Eclipse's Organize imports feature..

For questions like this, you should take a look at the GWT JRE Emulation Reference. It contains the java classes of the Java runtime library that can be automatically translated by GWT. The link points to the JRE ER for GWT 1.6. to show you that HashMap wasn't just included in the latest version. (The JRE ER for the latest version can be found here)

As xor_eq points you should check the GWT JRE Emulation Reference Check the link to the latest version (or the version that you're running). The support for for HashMap was added to GWT sometime ago (in 2.0 I think), so you should have no problem.

Related

Netbeans + Codename One - Avoid importing packages or classes not suitable for CN1

I'm using Netbeans IDE. It's quite annoying and it's a cause of errors the import of Java packages and/or classes that are not provided by Codename One. (Codename One use its own implementation of a subset of Java8 and it cannot support the full Java API).
For example, sometimes Netbeans imports automatically wrong packages (such as "java.awt.BorderLayout" instead of "com.codename1.ui.layouts.BorderLayout"), other times it shows me methods and Javadocs that are not available in Codename One.
Is it possible to force Netbeans to show me only packages, classes, methods and javadocs that are supported by Codename One? It could be useful to avoid errors.
We'd love to but unfortunately the only way NetBeans allows you to do that is if you build your own Java language package. That's what some other plugins like NBAndroid did AFAIK but when we implemented the plugin we didn't want to create something too complex.
If NetBeans supported a "bootclasspath" option for the JDK it would have solved everything. It does have support for plugging in an alternative JDK which can be a micro-profile but because we don't comply with the micro-profile spec I'm not sure if that will work.
At times, NetBeans suggests to import more than one package from the drop-down list. When you check carefully before pressing ENTER this might avoid importing the wrong package.
I use NetBeans for quite a while with CN1 and faced the same problem at the beginning.

GWT and JScience

In my GWT application, I made a control to display/edit a numerical value with an associated unit (for example to convert meters <-> feet).
How could I use the JScience library (jsr-275 implementation) in the client part ?
I try to add it to my project but it didn't compile:
No source code is available for type java.text.ParsePosition
Thanks for your help.
This is not a problem with the JScience library as such.
GWT compiles java to javascript and as such needs access to the java source code. Also, not all of the JDK classes are available in the GWT emulation library, and ParsePosition (indeed all of java.text.*) is one of them...
It is not clear from your stacktrace excerpt whether you have used ParsePosition directly or it is the JScience library that does, but either way you will have to rewrite your code to not use that class on the client side (if possible) or perform the conversion on the server side, where the GWT JRE restrictions do not apply.
Have a look at JRE Emulation Reference for a complete overview of what's available to you.
Cheers and good luck,

What's the different between these opencv libs that have the very similar name ? Which should I put into project libraries?

I am on Linux(Ubuntu) with OpenCV 2.4 installed. I am try to use Eclipse to create an opencv project. When I build the project, I got collect2: ld returned 1 exit status error which I guess is caused by missing libs. Then I put libraries in this project, but I find every lib has three very similar brothers, like:
libopencv_highgui.so
libopencv_highgui.so.2.4
libopencv_highgui.so.2.4.0
So, which one should I add to project libraries? And what's the different between them?
Best Regards.
libopencv_highgui.so and libopencv_highgui.so.2.4 are probably symbolic links to libopencv_highgui.so.2.4.0.
Libraries frequently do this so that software that needs to link against specific versions can while keeping the generic library also exposed.
This is mainly useful when a program to be linked against a major or minor version of a library. Consider if a legacy application needed to link against version 1.2 of libopencv_highgui. The program couldn't link against libopencv_highgui.so because that's not guaranteed to be the correct version. However, the program could link against libopencv_highgui.so.1.2. libopencv_highgui.so.1.2 may be a symbolic link to libopencv_highgui.so.1.2.3, but that would be ok since the third number usually means a minor bug fix that won't break compatibility.
So this brings up which file you should link against. This really depends. Unless you need to depend on some bug or quirk of a specific minor revision, I would definitely avoid linking against the 2.4.0 one. That ties your program specifically to version 2.4.0. When 2.4.1 gets released (or trickles down your distro's package manager), it probably won't break your program.
If you link against libopencv_highgui.so and then 2.5 is installed as the main lib (and then libopencv_highgui.so links to libopencv_highgui.so.2.5.0), there is a chance that your program will not link correctly since the second number does sometimes mean compatibility changes.
So in short, if it's a personal project, just link to whatever you want. libopencv_highgui.so is probably safe if it's personal. If it's going to be distributed, figure out what versions of the library your code will link properly against and then use the vaguest one possible. For example, if your code works with 2.2, 2.3 and 2.4, you should go ahead and link to libopencv_highgui.so. If it only works specifically with 2.4.0, you should link with libopencv_highgui.so.2.4.0. If it will work with any sub revision of 2.4, you should go with libopencv_highgui.so.2.4.
Basically you have to make a choice about what you think will link properly on the most people's setups.
I think I make some mistake here. What I need is these libraries, But when I add them into project libraries. YOU SHOULD USE THESE NAMES, for the library I mentioned in the question, we should add opencv_highgui in to eclipse libraries dependency but libopencv_highgui.so.2.4. For the future use, I write these stuff here.

Problems with GWT 2.4

I compiled the version in svn tagged as gwt2.4rc. Now there are a
couple of more libraries than I had the last time. Are the any
instructions on which library is needed for what? I tried it with only
the standard libraries (servlet, servlet-deps, user) but I get the
following error when a requestfactory call is made:
java.lang.NoSuchMethodError:
com.google.gwt.core.client.impl.WeakMapping.setWeak(Ljava/lang/
Object;Ljava/lang/String;Ljava/lang/Object;)
I tried declaring the requestfactory-client and requestfactory-server
jars as dependencies, but i doesn't help. I am using maven to manage
my dependencies.
I would go back to 2.4 beta, but I need the drag&drop features that
were introduced later.
Does anybody has an idea what could be wrong? or any hints how i can
dig deeper into this? I spend a lot of time trying to figure this out
but without any success :(
Do I need to provide more information?
Regards,
arne
Are you sure you deployed the 2.4-rc1 gwt-servlet.jar in your war/WEB-INF/lib ? Also, make sure you override the SDK for the gwt-maven-plugin: http://mojo.codehaus.org/gwt-maven-plugin/user-guide/using-different-gwt-sdk-version.html
That being said:
when using Maven, you shouldn't use gwt-servlet-deps but instead reference org.json:json and javax.validation:validation-api
requestfactory-server can be used instead of gwt-servlet if you only use RequestFactory on the server-side (no GWT-RPC, no SafeHtml, no RegExp, etc.); requestfactory-client is to be used for Java clients (such as Android), not the case here.

Can you integrate Java 1.6 classes into Eclipse Blackberry project?

I am using the latest IDE for eclipse and have attached the blackberry 5.0 sim. i am a new bb developer and i was wondering if there is any way of integrating java 1.6 classes (or any 3rd party jars) within the blackberry project without getting an error similar to the following:
org.apache.axis2.util.Utils$3: Warning!: Duplicate method only differs by return type: run
org.apache.axis2.jaxws.util.WSDL4JWrapper: Warning!: Duplicate method only differs by return type: getFirstPortBinding
C:\Program Files\Eclipse\axis\axis2-1.5.1\lib\axis2-transport-http-1.5.1.jar(org/apache/axis2/transport/http/ApplicationXMLFormatter.class): Error!: Duplicate definition for 'org.apache.axis2.transport.http.ApplicationXMLFormatter' found in: org.apache.axis2.transport.http.ApplicationXMLFormatter
I know why i am getting this error (because of duplicate definitions for the same class)....but am i really stuck just sticking to "net.rim" classes within my project? if i wanted to use the "asList()" method, can i not do that because that's outside of the RIM classes?
I am really just hoping that i can integrate outside jars into my blackberry project without getting "duplicate" warnings and error messages.
All source code and external libraries used in your BlackBerry app must conform to J2ME which you can think of as a subset of the Java SDKs. J2ME is quite limited - for example there are no Collections classes in J2ME (just the older Vector, etc.). The language level used by the compiler is Java 1.3.
So in a nutshell - you're going to have a hard time porting over third-party libraries unless they were specifically designed to run in a J2ME environment.
You can't uses the JDK 6, you need the JDK 5.
You can integrate third parties jars except if you want:
I/O
Swing
In those cases you need to uses the Blackberry API.