| upper_bound / lower_bound for java.util.TreeMap? |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- From Midlet to Database - the missing linkHi, I'm developing a j2me application. I want to send information inserted
into a set of textfileds in a MIDlet to a table in a database. I have
already developed the MIDlet graphically i.e. without the necessary
connection code. I don't know what the next step is. I've done a lot of
research about servlets, but most of it seems to involve web browsers and
HTML - whihch I won't be using. I have tomcat runing succesfuly and mysql
installed correctly. So I would appreciate if anyone could advise me what I
require to update a table in the database from entries made into a MIDlet.
Thanks!
- 3
- Eclipse + Tomcat + Clearcase = FrustrationHoping someone out there has done this:
My environment: Eclipse 2.1, Windows XP, Clearcase 5.0,
Tomcat 4.1.24, Rational plug-in 2.1.13, Tomcat plug-in 2.1,
JDK 1.4.
I am trying to run a webapp from a directory in a VOB. Ideally,
multiple webapps in the same Eclipse project, located in different
directories. I want servlet code to come from the project build
tree so I can modify it without making a WAR and have the changes
immediately picked up by Tomcat. I've seen this work before.
Problems:
1) I can't add the project to Tomcat's classpath from Window ->
Preferences -> Tomcat, because the Xerces version in the project
causes Tomcat to fail on startup with
java.lang.ClassNotFoundException:
org.apache.catalina.core.StandardServer.
2) I've installed the DevLoader as described in the plug-in
instructions. No help there. If I mark the project as a
Tomcat project (in Project -> Properties -> Tomcat), Tomcat fails
to start with the same exception, whether or not I add additional
classes to the DevLoader classpath. If I don't mark the project
as a Tomcat project, Tomcat doesn't know about the webapp.
3) I tried creating a separate project for each webapp to
isolate the Tomcat settings; no good. Eclipse says: "invalid
project description: x:/vobs/foo and x:/vobs/foo overlap."
Which is absolutely correct... and utterly useless. Can
I can have only one Eclipse project per VOB?? (Separate views for
each webapp might make Eclipse happy, but then the webapp views
won't see the classes built in the main project view.)
Suggestions greatly appreciated.
Regards / thanks,
Jonathan
- 4
- Code for combined searchCan any one help me by telling how to implement a code for combined
search .My problem is I want to search database using cominatio search
for eg: I want to search by user as well as date in one go .What should
I do?
Any suggestions?
- 4
- JNI and threadsHi,
I will ask a somewhat vague question because I'm working with three
different technologies at once and I first want to get a feel of where the
error is before I give full details.
I have a native methd myNativeMethod() and the following code:
myNativeMethod();
myNativeMethod();
new Thread() {
public void run() { myNativeMethod();}
}.start();
The methods works the first two times (or any N times) but then reliably
fails when called from another thread - an object (global to the native
functions) which used to return non-null now returns null.
So my vague general question is this: from the JNI perspective, what is
different about a method called from the main thread compared to a method
called from a different thread? (This does not appear to be a
synchronization problem.)
Very many thanks in advance!
Aaron Fude
- 6
- How to format text input/output?People, is it possible to control command prompt text output in Java as it
is in C? I mean, cam I print a line, them erase that line and repreint it
in the same line?
Thanks,
Scirious.
- 6
- Java Mail exception.Hi,
i am new to javamail and am having problems getting a simple example
working.
the following snippet of code compiles ok....
MimeMessage msg = new MimeMessage(session);
.... but throws the exception printed below.
Exception in thread "main" java.lang.NoClassDefFoundError:
javax/activation/DataSource
i'm confused because i couldnt find any reference to a javax.activation
package in any docs.
any help appreciated!
Alan
- 6
- methodHi
Im currently trying to write a method that will analyse an array and sum
the entire array and also sum the difference between the elements.
Any help would be most appriciated.
- 8
- THX harald and roedyOnce again Roedy you helped me, thanks. Thanks to you too Harald.
In my experiments I did decide to override JComponent, although I did look
at JWindow too.
-frl
- 9
- Problems with resizeble JOptionPane/JDialogI created a popup with JOptionPane, it works fine except I can NOT
resize the popup window.
Here are the codes:
JPanel myPanel = new JPanel();
JOptionPane.showConfirmDialog(null, myPanel,
"Dialog",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE, null));
Again this works fine except I can NOT resize the popup window
I need to resize the popup dialog window!
I changed in different way
Here are the codes:
JPanel myPanel = new JPanel();
JOptionPane optionPane = new JOptionPane(myPanel, // Object message
JOptionPane.PLAIN_MESSAGE, // messageType
JOptionPane.OK_CANCEL_OPTION); // optionType
JDialog dialog = new JDialog(new JFrame("Chart Manager"),
"Set Chart Properties",
false);
dialog.setContentPane(optionPane);
Now I can resize the popup dialog window
But the new problem come up. When I changed (resize) the
popup dialog window to SMALLER, those OK, Cancel buttons
are gone (disappear)! Order for me see those OK, Cancel
buttons, I need to resize the popup dialog window back to
ORIGAINL size or BIGGER.
Can anyone out there help me make a popup dialog window
resizeble AND keep the OK, Cancel buttons visible in ALL
time?
Thank Q very much in advance!
- 10
- Java 3D 1.4.0-build5Java 3D 1.4.0-build5 has been released. You can read the announcement at:
http://www.javadesktop.org/forums/thread.jspa?threadID=14293&tstart=0
- 10
- vectors an synchronizing....Hello together (at such a sunny day:)
I have a question about multithreading!
I want to make a variable count of threads using an (self-implemented)
dbhander-class.
But I don't want to work with 'synchronized', because of the
performance...
So, when I add a new jdbc-connection in a vector for every new thread,
and all threads work with its own connection, but in the same vector!
Do I have problems with synchronizing?
If I work with the same connection from different threads, YES! (<- I
think)
But only with the same vector????
thanks in advance....
Nullstring
- 10
- internationalization in swingHello!
I think the problem is not in reading data into the String, but during
showing String content
To localize problem set String value directly (String roundTrip =
"\u0424:..\u043b") and try to show it content (there are several methods of
doing this).
Good luck!
Gennadiy
"Vladimir" <email***@***.com> wrote in message
news:email***@***.com...
> I have XML file in UTF8 which includes some portions of text in russian
and
> hebrew.
> To show the text in the table I use converter:
>
> byte[] = utf8Bytes = original.getBytes();
> String roundTrip = new String(utf8Bytes, "UTF8");
>
> The problem is that: some of the russian and hebrew letters are shown like
a
> square with ? question mar aside.
> I tried numerous JDK versions the most letters are shown with 1.4.1_03.
> When I open this file in XML-SPY or in WordPad the text shown perfect.
>
> Please help!
>
>
>
>
- 10
- infinite recursionThis method is supposed to return an array of shorts which represent
all of the possibilities for a given sudoku square (where each value
is a not-masked bitset with element + 1 equalling position). So far,
it gets stuck in an infinite recursion. Where is the inifinite
recursion in this method and how do I fix it?
short[] allOptions(short val) {
Vector<Short> cc = new Vector<Short>(0);
Iterator<Short> it;
short[] rv;
//check which numbers are available
short i;
for (i = 0; i < 9; ++i)
//bitmask check (1 == unavailable, 0 == available)
if (((1 << i) & val) == 0)
//available, add number to cc
cc.add(cc.size(), (short)(i + 1));
//create return array
rv = new short[cc.size()];
it = cc.iterator();
i = 0;
while (it.hasNext())
rv[i++] = it.next();
return rv;
}
- 11
- peculiar JMF portability problemsDear JMF wizards:
I'm having a serious portability problem
between Solaris and Windows. A simple program
together with platform and Java version info
is below. I have two questions which I would
be much obliged if you can help answer. First,
what is going on under Windows that causes
the JMF to think it took more than 96 hours
to realize the player as opposed to about a
second on Solaris running the same class file?
Is there any work-around available? This is
really amazing (and really annoying)!
Second, when I ran the JMF's exe installer
on the Windows machine under my user account
and in my user-controlled space, I could not
run this program in spite of setting all my
shell vars as the Readme file instructs. But,
when I asked a System Administrator to do the
install, the program ran fine (except for the
above mentioned Time problem). This will be
a serious drawback to my user community if an
Administrator has to be found to run the
install on every Windows machine they want
to run my app on. Is there any work-around for
a regular Windows user to run this install
and not get Access Denied and ClassNotFound
(on classes in the JMF's lib) errors?
TIA. Example program and results follow.
// file: Test.java
import java.io.*;
import java.net.*;
import javax.media.*;
public class Test implements ControllerListener
{
Player player = null;
public Test (String file)
{
try
{
URL url = new URL (file);
MediaLocator ml = new MediaLocator (url);
if ((player = Manager.createPlayer (ml)) == null)
throw new NoPlayerException ("player");
player.addControllerListener (this);
player.realize ();
}
catch (Exception e)
{
e.printStackTrace ();
}
}
public void controllerUpdate (ControllerEvent event)
{
if (event.getSource ().equals (null))
return;
System.out.println ("\nnew event: " + event.toString ());
if (event.getSource ().equals (player))
{
synchronized (player)
{
try
{
if (event instanceof RealizeCompleteEvent)
{
System.out.println ("\ncurrent Time offset: " +
player.getTimeBase ().getTime ().getSeconds ());
player.setTimeBase (null);
System.out.println ("after setting to null: " +
player.getTimeBase ().getTime ().getSeconds ());
player.start ();
}
else if (event instanceof StartEvent)
{
System.out.println ("\nexiting");
System.exit (0);
}
}
catch (Exception e)
{
e.printStackTrace ();
}
}
}
}
public static void main (String args[])
{
new Test (args[0]);
}
}
/*
on Solaris:
% uname -ir
5.8 SUNW,Sun-Blade-100
% java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
% wc -c jmf*sh
4778152 jmf-2_1_1a-solsparc.sh
% java Test file:///home/data/movie.mpg
new event: javax.media.TransitionEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,previous=Unrealized,current=Realizing,target=Realized]
new event: javax.media.DurationUpdateEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,duration=javax.media.Time@10a2d64
new event: javax.media.RealizeCompleteEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,previous=Realizing,current=Realized,target=Realized]
current Time offset: 1.8250000000000002
after setting to null: 1.8290000000000002
new event: javax.media.TransitionEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,previous=Realized,current=Prefetching,target=Started]
new event: javax.media.PrefetchCompleteEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,previous=Prefetching,current=Prefetched,target=Started]
new event: javax.media.StartEvent[source=com.sun.media.content.video.mpeg.Handler@f99ff5,previous=Prefetched,current=Started,target=Started,mediaTime=javax.media.Time@a31e1b,timeBaseTime=javax.media.Time@10da5eb]
exiting
=================
on PC:
from Control Panel -> General:
System: Microsoft Windows 2000, 5.00.2195, Service Pack 3
Computer: Intel(R) Pentium, (R) 4 CPU 1.70 GHz, AT/AT COMPATIBLE,
523,696 KB RAM
C:\> java -version
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
C:\> dir /b jmf*.exe
jmf-2_1_1a-win.exe
1 File(s) 5,251,218 bytes
C:\> java Test file:\\data\movie.mpg
new event: javax.media.DurationUpdateEvent[source=com.sun.media.content.video.mpeg.Handler@46f579,duration=javax.media.Time@aaa1e
new event: javax.media.RealizeCompleteEvent[source=com.sun.media.content.video.mpeg.Handler@46f579,previous=Realizing,current=Realized,target=Realized]
current Time offset: 346248.34
after setting to null: 346248.341
new event: javax.media.TransitionEvent[source=com.sun.media.content.video.mpeg.Handler@46f579,previous=Realized,current=Prefetching,target=Started]
new event: javax.media.PrefetchCompleteEvent[source=com.sun.media.content.video.mpeg.Handler@46f579,previous=Prefetching,current=Prefetched,target=Started]
new event: javax.media.StartEvent[source=com.sun.media.content.video.mpeg.Handler@46f579,previous=Prefetched,current=Started,target=Started,mediaTime=javax.media.Time@31b4c3,timeBaseTime=javax.media.Time@52906a]
exiting
*/
- 15
- image.getScaledInstance() bug?this example works fine with SCALE_REPLICATE or without PixelGrabber.
With PixelGrabber and SCALE_AREA_AVERAGING it produces really strange
results.
Is it a known bug?
public static void main(String[] args) throws IOException {
//change to your favorite jpeg image
String s = "Portrait.jpg";
final Image image = Toolkit.getDefaultToolkit().createImage(s);
//ensure image loaded
/*ImageIcon icon = */new ImageIcon(image);
final int width = image.getWidth(null);
final int height = image.getHeight(null);
//****<grab pixels>*****************************
int[] pixels = new int[width * height];
PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height,
pixels, 0, width);
try {
pg.grabPixels();
}
catch (InterruptedException e) {
return;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
throw new RuntimeException("can't fetch pixels");
}
//***</grab pixels>*****************************
//with SCALE_REPLICATE everithing work fine
final Image img = image.getScaledInstance(w, h,
Image.SCALE_AREA_AVERAGING);
//ensure image loaded
new ImageIcon(img);
JFrame frame = new JFrame();
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, this);
g.drawImage(img, 0, 0, this);
}
public Dimension getPreferredSize() {
return new Dimension(width, height);
}
};
frame.getContentPane().add(new JScrollPane(panel));
frame.pack();
frame.show();
}
--
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
| Author |
Message |
Sylvain

|
Posted: 2005-2-7 21:48:00 |
Top |
java-programmer, upper_bound / lower_bound for java.util.TreeMap?
Dear all,
I have to convert some c++ STL code using extensively the function
upper_bound and lower_bound of STL's map<>.
As I am quite new to Java Collection (I am trying to use the 1.5 generics)
I am a bit confused, because no method return iterator for example...
Could somebody give me a first hint for getting something similar to
upper/lower_bound with java collections? Is there a workaround or a third
party library doing it that I missed while googling?
Thank you very much in advance,
Sylvain
|
| |
|
| |
 |
Sylvain

|
Posted: 2005-2-15 16:53:00 |
Top |
java-programmer >> upper_bound / lower_bound for java.util.TreeMap?
> I have to convert some c++ STL code using extensively the function
> upper_bound and lower_bound of STL's map<>.
Well, finally I found some hints myself:
- in SortedMap/Set, headMap/Set(x).last() is essentially an
upper_bound(x), tailMap/Set(x).first() is essentially a lower_bound(x),
and it is possible to use subMap/Set to have an equal_range
- the source code for TreeMap/Set contains a lot of very interesting
private internal function in a not so confused way. Some of them are
directly upper_bound lower_bound and things like that. I think writing a
specialized class using this code could be a good idea to obtain a much
richer interface to the power of the red/black tree algorithm for eg.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- 2
- make not neededHello All, I notice the following: if I have A.java, B.java and C.java and
if A calls B and C (directly or indirectly) it suffices to 'javac A.java'
to get everything compiled as necessary, and so on.
Please confirm that this is generally true and supply references; I have not
been able to see this feature properly documented. Thanks in advance
Ivan.
- 3
- finalize() not guaranteed to be called -- ever According to:
http://www.unix.org.ua/orelly/java-ent/jnut/ch03_03.htm
that says in part:
The Java interpreter can exit without garbage collecting
all outstanding objects, so some finalizers may never be
invoked.
Is this still true in Java 1.4 and later?
- Paul
- 4
- 5
- Viruses in a java directory?I have just upgraded to Windows XP. Recently I ran my virus scanner (EZ
Trust Antivirus) and it said there were some viruses in 6 .zip files in
the C:\Windows\.jpi_cache\jar\1.0 directory.
They were all tagged as one of the following:
RunString.class - Java.Shinwow trojan.
Parser.class - Java.ByteVerify.exploit trojan.
Dummy.class - Java.ByteVerify.exploit trojan.
When I contacted the techs at my virus scanner site, they recommended
that I delete all files in the C:\windows\.jpi_cache\jar\1.0 directory.
My questions are:
1. Does Java store any important files in this directory?
2. Will it hurt anything to delete all the files in this directory?
3. Are there likely really trojans in these zip files?
Thanks in advance for your help.
- 6
- oracle leaving open cursors...On Thu, 25 Mar 2004 16:50:49 +0800, asaguden wrote
(in article <email***@***.com>):
> Hi,
> We have a database driven servlet/jsp application with Oracle as backend.
> We are using oracle classes12.zip driver for our jdbc connections.
>
> At runtime, our connection pool reports that there are no
> used connections, but there are usually appr. 600 open cursors.
>
> How can that be?
> What exactly is a cursor after I hav used it (gotten data from it)?
> What resources are these cursors holding?
>
>
> When is a cursor closed (in oracle), when I close the statement,
> when I close the connection, or do I always have to close the cursor(s)
> explicitely?
>
> I am puzzled...
>
> / Peter
it depends "how" you are using the cursor, if you are calling a pl/sql
routine that returns a cursor, then the cursor is going to stay open for the
duration that the connection is open, irrelevant of the fact that you have
closed the transfer protocol.
but to decide that i would need to see exactly what sql statment you are
executing.
if it is just a straight:
"select * from emp order by 1", then what you are doing will function
correctly.
BUT if it is
"?=returnacursor();"
where ? is a cursor tied to oracle.CURSOR in your java program.
& "returnacursor()" is a pl/sql subroutine that returns a cursor,then you
need to remember that if you have opened a cursor inside the pl/sql to pass
back to the java, then you may need a routine that closes the pl/sql cursor,
resident in the same pl/sql package.
- 7
- SQLfX Beta
Roedy Green wrote:
> On Thu, 23 Aug 2007 14:15:24 -0700, Lee Fesperman
> <email***@***.com> wrote, quoted or indirectly quoted someone
> who said :
>
> >I'm pleased to announce the beta availability of SQLfX (SQL for XML).
> >SQLfX is a brand new paradigm for database access to XML. It uses the
> >[often unrecognized] hierarchical operations built into SQL92 to bring
> >power and scalability to XML query and manipulation. SQLfX is a next
> >generation alternative to complex navigational facilities like XQuery,
> >XPath and XSLT.
>
> Could you talk a bit about that. I thought of SQL as rows and column,
> no hierarchy, no nesting, no point in XML.
Sure. A table in SQL does consist of rows and columns, but SQL tables
can be linked to each other, normally using Primary Key (PK) to
Foreign Key (FK) relationships. A PK to FK link can model a One to
Many (1:M) relationship. 1:M is a hierarchical link, used to create
nested tree structures like XML. Using self-references and recursive
operators, SQL can nest hierarchical trees inside a single table. PK
to FK links can also be used for more complex 'network' structures.
Conceptually, one can model an XML element as a SQL table with XML
attributes as SQL columns and model nested elements as linked tables.
When done physically, this is known as shredding an XML document.
SQLfX leverages this conceptual view and the hierarchical operators
already in Standard SQL to provide a powerful and intuitive interface
for querying and transforming XML. In the beta, SQLfx does use
physical shredding of XML. In the next phase, SQLfX will implement a
high-performance alternative to shredding. This is a change to
internal implementations and doesn't affect the external interface or
language.
- 8
- Printer Tracking DotsAndrew Thompson wrote:
> John W. Kennedy wrote:
>>>> * Or 'save the trees' and do without those damnable devices.
> ...
>>> "Treehugger" makes about as much sense as an insult as does "peacenik".
>> Well, one of the Shakespeare-denying loonies on
>> humanities.lit.authors.shakespeare claims to have taken to tree-hugging
>> in quite the wrong way....
>
> Is there such a thing as 'bad touching' with a tree?
Apparently....
--
John W. Kennedy
"...if you had to fall in love with someone who was evil, I can see why
it was her."
-- "Alias"
- 9
- 10
- Trouble with servlet connection to DBHi all.
Helping a friend with debugging a system delivered for a site he is
administrating and he is having the following problem with a
login-servlet:
Logging in goes fine usually until the time comes when the db-server
(msSQL) goes down or has to be restarted. Then the login-servlet stops
working. For it to start working again he restarts the whole
application server (Tomcat 5.x ?) I thought it sounded like the
program had some funky problem with its database connection and found
the following code snippet:
public static User login(DataSource dataSource,
String username,
String password){
Connection con = null;
CallableStatement stmt = null;
ResultSet rs = null;
User user1;
try{
con = dataSource.getConnection();
stmt = con.prepareCall("{call procedure_login(?,?) }");
stmt.setString(1, username);
stmt.setString(2, password);
rs = stmt.executeQuery();
}
etc.
}
The thing that made hiccup was that the method initing the connection
was STATIC wouldn't that pose a problem if the connection was lost and
tried to establish it again?
Or am I barking up the wrong tree?
Thanks
Christer
- 11
- close JFrame?How do I close a JFrame Window, other than calling system.exit(0) or
dispatchEvent()?
Thanks in advance,
Lem
- 12
- object creation timestampIs there an object creation timestamp that is accessible?
I have a continuous data input stream that I parse and put into a HashMap.
The key entry is a Long. The value entry is a Vector. After 5 seconds,
the data is out of date so I want to remove it from the HashMap. I would
like to test whether the Long object was created 5 or more seconds ago.
Any suggestions?
Thanks
---
Jeffrey Drew
President and Founder
Trading Metrics, Inc.
917-453-0302
- 13
- 14
- question code of javahi, i need your help, i wrote the below code in java and i hava some
problems
The compiler tells me :
class interface or enum expected
the code is
the mistake appears to the line import java.io.*;
public class Array{
int[] T;
int n;
/*constructor*/
public Array(int size ){
T=new int[size];
n=size;
}
/*add element into array*/
public void insert(int position,int elem){
T[position]=elem;
}
/*find minimum algorithm*/
public int findmin(){
int[] resultsArray=new int[2];
int min=T[0],index=0;
for (int i=1;i<n;i++){
if (T[i]<min){
min=T[i];
index=i;
}
}
resultsArray[0]=min;
resultsArray[1]=index;
return resultsArray;
}
}//end class
import java.io.*;
public class Findminimumapp{
/*====main method============*/
public static void main(String[] args) throws IOException {
int n=0;
int min=0;
int index=0;
String str=null;
/*construct new array object*/
System.out.print("give array size then press enter");
str=Utils.getString();
n=Integer.parseInt(str);
Array arrayObj=new Array(n);
/*read array*/
System.out.println("type"+n+"integers in separate lines");
System.out.println("==============");
for(int i=0;i<n;i++){
str=Utils.getString();
arrayObj.insert(i,Integer.parseInt(str));
}
//*printresults*/
min=arrayObj.findMin()[0];
index=arrayObj.findMin()[1];
System.out.println("minimum element in array is"+min);
System.out.println("minimum position is"+(index+1));
}//end main method
}//end class
- 15
- 64bit JVM - some help appreciatedI am drawing up the specifications for a machine to deploy a
potentially mem-grabbing application (might be up to the order of
several GB when doing batch processings), and am considering to go for
a 64bit JVM to circumvent the 2GB limit on linux.
I would really appreciate some answers to :
+ What is the JVM max memory limit for a 64bit JVM?
+ What is the practical limit that people are facing? (What's a
reasonable point beyond which java gc takes forever, or just too long)
I am deciding between Intel Xeon and AMD Opteron based servers. Does
anyone have comments on which is better?
Thanks.
|
|
|