| Storing and parsing variable length strings |
|
 |
Index ‹ java-programmer
|
- Previous
- 4
- Core Java ( JAVA 2.0), J2EE, XML, Swing,XSL Opening in Chennai 3+YearsHi All,
We are looking Software Engineer for my MNC Client in
chennai.. L&T info, HCL, Virtusa, EDS
Skill: Core Java ( JAVA 2.0), J2EE, XML, Swing,XSL
Exp 3 to 6 Years
Work Location: Chennai
>> SE, TL, PL openings
If you are looking for a good opening Please send the
resume to email***@***.com
Please send me the following information for a faster
Processing
Name:
Contact NO:
Cell:
Landline:
Current company:
Current Location:
Current Salary:
Expected Salary:
Notice Period with Present Employer:
Total IT Experience:
Relevant Experience:
Key Skills:
Domain Worked:
Are you willing to relocate to chennai
Regards
Latha HR Solutions
Chennai
- 6
- Non Asian Whore Mature Mummy Just few link on some movies...
All just for you...
Download
>>>>> http://download-video.12w.net
>>>>> http://world-sex.urllogs.com
>>>>> http://video-sex.12w.net
CLICK FREE DOWNLOAD VIDEO PORN...
L
I
C
K
T
O
W
A
T
C
H
V
I
D
E
O
P
O
R
N
D
O
W
N
L
O
A
D
F
R
E
E
.
.
.
W
E
L
C
O
M
T
O
M
O
V
I
E
S
P
O
R
N
D
O
W
N
L
O
A
D
.
.
.
- 6
- 7
- doubtsin javaHelloo
I am a newer one to java. just started to study it. I am getting so
many doubts in the language. I don have any previous knowledge in
progamming.
I would like to know more about JAVA and its applications in the real
world.
Where can I find jobs after studyig it??? From where will I get
practice programs in it???
Thanks in advance
Deepa
- 7
- 7
- Save gif file from the URLHello,
I just want to save on disc a gif file taken from the internet (i.e.
save as logo.gif the image
http://www.google.com/intl/us_ALL/images/logo.gif ). Is it possible
without much effort (I have read about the extra & not free libraries
but I hope there is a simple way to do so (just read bytes and write
bytes - no modification).
Regards. Marko
- 7
- how to get the content from an URL?Hi people,
I have write some code that outputs the content of an URL in
System.out,
which is really trivial using the following code:
URL url=new URL("http://www.some-url.com");
URLConnection c=url.openConnection();
BufferedReader is=new BufferedReader(new
InputStreamReader(c.getInputStream()));
String line;
while ((line=is.readLine())!=null) {
System.out.println("line: "+line);
}
But, some URLs have javascript code embedded that redirects the page
or refills
it in some way when it's automatically run by the browser. I want to
have the HTML code after executing that javascript code, exactly as
you can get it from your internet browser's "view source-code", not as
I'am getting it by now.
The cuestion is...
there is ANY workaround to this issue? some way to run javascripted
pages from
java? some way to deliver it to a web browser, or something nicer?
thanks to everyone,
hernan rancati, cesare.
- 7
- USB support for Java (Win32)Does anybody know any win32 usb library for java that I can use to
communicate with device. Application will communicate with device
using USB in the same way as RS232 - for control and management.
Thanks,
Dimitry
- 7
- Paint methodI'm still new to Java, so this may be a pretty pathetic question.
Anyway, I have a paint method in an applet that paints something and
then when a certain button is pushed it needs to draw more (rectangles
and strings to be precise). However, the paint method is above, and
the scope of 'g' does not extend into the actionPerformed method. Can
'Graphics g' be declared outside the paint method, and if not is there
a way to make it work, while rewriting as little as possible?
- 7
- One class in several filesHello
Is possible make one class in several files ?
I would like do this for organization reason.
Thanks in advice
GG
- 8
- java & CGII am a programming student attempting a quoting system (similar to what
geico does) for my job. I've written a program that is executable from
the command prompt that returns the expected values, but I need it to
work with a webpage.
I want the user to be able to input data, the program process it, and
then display the results. I've found code that uses "POST" to get the
data to a program, but how does the program process it and how do I get
it back into another web page? I've searched the web but I'm having
difficulty finding answers.
Thanks in advance to anyone who can help.
- 9
- 10
- On Java and C++On 28 Apr 2006 00:59:19 -0700, "al pacino" <email***@***.com>
wrote, quoted or indirectly quoted someone who said :
>improve your programming skills and what better tool to do that than
>using c++.
You might find the work of W. Edwards Deming interesting. He was the
man who taught the art of quality control to the Japanese.
He argues there is no point in exhorting people to be better. You
have to change the environment so they naturally and without
additional effort produce better results.
C++ allows well made programs but does little to insist on or even
encourage them. The beautiful quality remains a theoretical goal
rarely achieved. It is a bit like an impressive high wire act.
You can see the effect. If you look over C++ code you will see a huge
range of quality. If you look at Java code it is much more uniform.
The artisan in you yearns for the sporadic brilliance, but the manager
prefers the uniformity.
As a programmer you see the effect. In Java, a higher percentage of
trouble is caught at compile time. Once you have the compiler happy,
usually the code works. Because of the null pointer checks, enforced
initialisation and subscript checks, if a program works at all there
is a higher probability it is working correctly than the equivalent
C++ program. That means a poor programmer who writes buggy code has a
bigger safety net with Java to watch over him to catch these errors.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
- 12
- open source poker codeHi,
Bit of a long shot I imagine, but has anyone tried to use:
http://sourceforge.net/projects/pokersource/
They promise some sort of java wrapper in the readme, but all I have
found is c code.
I guess there's a chance to use JNI to call the c stuff but I suffer
from a very rare and extreme form of laziness that prevents this (and I
can't understand the code!).
cheers
Andy
- 14
- Seaching word in text file using JAVA.Hello,
I have a problem on seaching word in text file using JAVA.
Below are the sample code i have written for searching word honda,
1990 and imran.I also want to save word honda in static string name
classtring. For first line i use this java code to save word honda in
classtring and its working well. I have a problem to save second line
1990 and imran.
The technique i use is searching until "=" and save word after "=".Can
anyone give the idea and java code.
Thank you...
------------java code ------------------
content = f.readLine();
// find class name
StringTokenizer s = new StringTokenizer (content,"=");
while (s.hasMoreTokens())
{
String string_val = s.nextToken();
if (string_val.trim().equals("classname".trim()))
{
classString=s.nextToken();
}
}
------- data text file -------------
name_car = honda
year = 1990
owner = imran
|
| Author |
Message |
dterzis

|
Posted: 2005-9-3 8:51:00 |
Top |
java-programmer, Storing and parsing variable length strings
Hi folks...
I have an application which needs to store variable-length strings (up
to 24 characters long) that must then be matched according to prefix.
That is, whenever a prefix is given, the application has to be able to
retrieve all stored strings that start with this prefix. Conversely,
the program has to be able to store strings in such a way, so that
prefix-based retrieving is fast and accurate (i.e., all relative
strings are located and retrieved). Doing this linearly is obviously
slow and inefficient.
So, what is the best way of implementing this functionality in J2SE 1.4
or later? Or, if there is no ready (preprogrammed) way of doing it
properly in the standard distribution, are you aware of any open source
implementation (e.g., tree or something similar)?
Thanks,
Dimitris
|
| |
|
| |
 |
HGA03630

|
Posted: 2005-9-3 9:08:00 |
Top |
java-programmer >> Storing and parsing variable length strings
HashMap
|
| |
|
| |
 |
Ian Pilcher

|
Posted: 2005-9-3 9:31:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
> HashMap
>
The OP needs to find all of the strings that start with a "prefix", so
so he effectively needs to find objects within a range of values.
Depending on where the data comes from, a TreeSet or a sorted array
would be better.
--
========================================================================
Ian Pilcher email***@***.com
========================================================================
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-9-3 9:35:00 |
Top |
java-programmer >> Storing and parsing variable length strings
On 2 Sep 2005 17:50:33 -0700, email***@***.com wrote or quoted :
>So, what is the best way of implementing this functionality in J2SE 1.4
>or later? Or, if there is no ready (preprogrammed) way of doing it
>properly in the standard distribution, are you aware of any open source
>implementation (e.g., tree or something similar)?
Since you do direct access with the prefix, and have perfect spelling
of the prefixes, you would start with a HashMap of with prefixes as
keys. They map to a collection of Strings, (possibly with the prefixes
chopped off to conserve space.)
What sort of Collection? You might use ArrayList or HashSet or even
simple arrays of exactly the correct size (small fast but not fast for
update since you must create a new array to add an elt).
if your strings use some reduced character set, you might encode them
with byte[] to make them more compact.
For fast access, you could convert the 3-char prefix to a numerical
index 0..17,575 a=0, b=1 ... and do a direct index lookup to get your
collection.
There may be a fair bit of overhead with all those objects. If you
need to reduce the ram footprint, you can consider combining the
24-char strings into a single byte array in toto or per prefix using a
marker separator characters. Don't worry about this until you prove a
need for optimisation.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-9-3 9:39:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
>
> I have an application which needs to store variable-length strings (up
> to 24 characters long) that must then be matched according to prefix.
> That is, whenever a prefix is given, the application has to be able to
> retrieve all stored strings that start with this prefix. Conversely,
> the program has to be able to store strings in such a way, so that
> prefix-based retrieving is fast and accurate (i.e., all relative
> strings are located and retrieved). Doing this linearly is obviously
> slow and inefficient.
I've not done anything like this, but that wont stop me commenting.
A SortedSet with natural ordering looks like what you need. Find the
tailSet after (inclusive) the prefix. Iterate until you find a string
that doesn't have the prefix.
class PrefixMatcher {
private static final String[] EMPTY_STRING = new String[0];
private final SortedSet<String> set;
public PrefixMatcher(Collection<String> strings) {
this.set = new java.util.TreeSet(strings);
}
public String[] startsWith(String prefix) {
Iterator<String> tailIter = set.tailSet(prefix).iterator();
// A bit of optimisation for a potentially common case
// of no matches.
// Start by testing the first, if exists.
if (!tailIter.hasNext()) {
return EMPTY_STRING;
}
String first = tailIter.next();
if (!first.startsWith(prefix)) {
return EMPTY_STRING;
}
// At least one found, loop for the rest.
List<String> found = new java.util.ArrayList<String>();
found.add(first);
while (tailIter.hasNext()) {
String string = tailIter.next();
if (!string.startsWith(prefix)) {
break;
}
found.add(string);
}
return found.toArray(EMPTY_STRING);
}
Alternatively, you could 'increment' the prefix and find the bounded subSet.
public String[] startsWith(String prefix) {
return set.subSet(
prefix,
increment(prefix)
).toArray(EMPTY_STRING);
}
private static String increment(String string) {
final int len = string.length();
final char last = len==0 ? '\uffff' : string.charAt(len-1);
return
last=='\uffff' ? (
string+'\u0000'
) : (
string.substring(0, len-1) + (char)(last+1)
);
}
}
}
(Usual disclaimer.)
If you want non-exact matching rules (say case insensitive), then you
can supply a comparator.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-9-3 10:24:00 |
Top |
java-programmer >> Storing and parsing variable length strings
Thomas Hawtin wrote:
>
> public String[] startsWith(String prefix) {
> return set.subSet(
> prefix,
> increment(prefix)
> ).toArray(EMPTY_STRING);
> }
> private static String increment(String string) {
> final int len = string.length();
> final char last = len==0 ? '\uffff' : string.charAt(len-1);
> return
> last=='\uffff' ? (
> string+'\u0000'
> ) : (
> string.substring(0, len-1) + (char)(last+1)
> );
> }
Argh. That's wrong. What you need is what I originally decided to write
but changed my mind (it's late). When the last character is \uffff
(which probably isn't a valid character anyway), you need to increment
the character preceeding. If the string is all -1, then you need to
either use tailSet or a nulls last sorting comparator.
> }
> }
>
> (Usual disclaimer.)
Using arrays and java.util.Arrays would probably be faster if set didn't
change. Or use an array backed SortedSet implementation.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Wibble

|
Posted: 2005-9-3 10:25:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
> Hi folks...
>
> I have an application which needs to store variable-length strings (up
> to 24 characters long) that must then be matched according to prefix.
> That is, whenever a prefix is given, the application has to be able to
> retrieve all stored strings that start with this prefix. Conversely,
> the program has to be able to store strings in such a way, so that
> prefix-based retrieving is fast and accurate (i.e., all relative
> strings are located and retrieved). Doing this linearly is obviously
> slow and inefficient.
>
> So, what is the best way of implementing this functionality in J2SE 1.4
> or later? Or, if there is no ready (preprogrammed) way of doing it
> properly in the standard distribution, are you aware of any open source
> implementation (e.g., tree or something similar)?
>
> Thanks,
>
> Dimitris
>
Do you know all the strings a priori? Is it a large number of strings?
If you know all the strings up front, you can just keep them in a sorted
array and use binary search.
If there arent that many strings but you dont know them up front, you
can store them in 24 hash maps, each with the first n of 24 characters
as the hash key and a list of strings as the value.
A string trie would work too, but you'd have to find or build it.
If you have alot of strings, and don't know the complete set up front,
consider a database.
|
| |
|
| |
 |
Dilton McGowan II

|
Posted: 2005-9-3 10:46:00 |
Top |
java-programmer >> Storing and parsing variable length strings
<email***@***.com> wrote in message
news:email***@***.com...
> Hi folks...
>
> I have an application which needs to store variable-length strings (up
> to 24 characters long) that must then be matched according to prefix.
> That is, whenever a prefix is given, the application has to be able to
> retrieve all stored strings that start with this prefix. Conversely,
> the program has to be able to store strings in such a way, so that
> prefix-based retrieving is fast and accurate (i.e., all relative
> strings are located and retrieved). Doing this linearly is obviously
> slow and inefficient.
>
> So, what is the best way of implementing this functionality in J2SE 1.4
> or later? Or, if there is no ready (preprogrammed) way of doing it
> properly in the standard distribution, are you aware of any open source
> implementation (e.g., tree or something similar)?
>
> Thanks,
>
> Dimitris
>
Use a database with an index on the field of interest; either a local
database like Derby or server based one like DB2, this is what they're
designed for and excel at.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-9-3 11:12:00 |
Top |
java-programmer >> Storing and parsing variable length strings
On Sat, 03 Sep 2005 01:35:09 GMT, Roedy Green
<email***@***.com> wrote or quoted :
>Since you do direct access with the prefix, and have perfect spelling
>of the prefixes, you would start with a HashMap of with prefixes as
>keys. They map to a collection of Strings, (possibly with the prefixes
>chopped off to conserve space.)
another approach would be to build the structure using ArrayLists,
then when it is complete, convert it to use plain arrays, then
serialise the thing so you can bring it back easily.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-9-3 11:15:00 |
Top |
java-programmer >> Storing and parsing variable length strings
On Fri, 02 Sep 2005 20:31:20 -0500, Ian Pilcher
<email***@***.com> wrote or quoted :
>The OP needs to find all of the strings that start with a "prefix", so
>so he effectively needs to find objects within a range of values.
>Depending on where the data comes from, a TreeSet or a sorted array
>would be better.
He does not need a sort to do that. All he need do is chop off the
first three chars and use that as a HashMap style key.
He might consider using a sort first to help speed the building of the
list of strings attached to each prefix.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-9-3 11:26:00 |
Top |
java-programmer >> Storing and parsing variable length strings
On Fri, 2 Sep 2005 19:45:30 -0700, "Dilton McGowan II"
<email***@***.com> wrote or quoted :
>Use a database with an index on the field of interest; either a local
>database like Derby or server based one like DB2, this is what they're
>designed for and excel at.
It is fascinating seeing the variety of responses. Each person brings
a different set of assumptions.
It is quite possible all you need is an array of strings and a loop if
the problem set is small enough.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-9-3 12:11:00 |
Top |
java-programmer >> Storing and parsing variable length strings
Roedy Green wrote:
> On Fri, 02 Sep 2005 20:31:20 -0500, Ian
>
> He does not need a sort to do that. All he need do is chop off the
> first three chars and use that as a HashMap style key.
>
> He might consider using a sort first to help speed the building of the
> list of strings attached to each prefix.
Depends on the data.
If he was sorting through tens of thousands of Java method names, he
might find performance for get and set methods lacking. Alternatively
looking for "it" would take 65536 look up. "@" would take, er, lots.
It's like Mozilla trying to lookup up a URL. You type 'h' for http or
'w' for www or anything else, and it takes a few minutes to respond.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Jim Janney

|
Posted: 2005-9-3 12:43:00 |
Top |
java-programmer >> Storing and parsing variable length strings
Roedy Green <email***@***.com> writes:
> On Fri, 02 Sep 2005 20:31:20 -0500, Ian Pilcher
> <email***@***.com> wrote or quoted :
>
>>The OP needs to find all of the strings that start with a "prefix", so
>>so he effectively needs to find objects within a range of values.
>>Depending on where the data comes from, a TreeSet or a sorted array
>>would be better.
>
> He does not need a sort to do that. All he need do is chop off the
> first three chars and use that as a HashMap style key.
Except that he doesn't say that the prefixes are all three characters
long. Sorting into order gives you O(log(n)) searches for prefixes of
any length.
--
Jim Janney
|
| |
|
| |
 |
Roedy Green

|
Posted: 2005-9-3 13:01:00 |
Top |
java-programmer >> Storing and parsing variable length strings
On Fri, 02 Sep 2005 22:43:01 -0600, Jim Janney
<email***@***.com> wrote or quoted :
>Except that he doesn't say that the prefixes are all three characters
>long. Sorting into order gives you O(log(n)) searches for prefixes of
>any length.
On re-reading his request in the light of your observation I think he
means by prefix that he wants to do lookup by any of the first N chars
of the string, not that there is some single definable prefix, like a
telephone exchange prefix, for each string.
In that case, he wants a TreeMap which lets you look up by approximate
key and scan forward till you find one that does not begin with the
prefix string you want.
Another implementation is to sort the strings alphabetically and
search for what you want with binary search. see
http://mindprod.com/jgloss/binarysearch.html
IRRC Tremaps don't allow duplicate keys. If you have duplicate keys,
that is another problem to solve, which I won't concern myself with
yet.
The other question of interest is once you look up this string what do
you do? What sort of object do you need to process? JUST an array of
strings with the same lead chars? In that case you would need only a
TreeSet not a TreeMap.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
|
| |
|
| |
 |
Lasse Reichstein Nielsen

|
Posted: 2005-9-3 18:49:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com writes:
> I have an application which needs to store variable-length strings (up
> to 24 characters long) that must then be matched according to prefix.
> That is, whenever a prefix is given, the application has to be able to
> retrieve all stored strings that start with this prefix.
This sounds like a job for a Trie data strcuture.
<URL:http://en.wikipedia.org/wiki/Trie?
A Google search found this implementation:
<URL:http://software.topcoder.com/catalog/c_component.jsp?comp=6601809&ver=1>
I don't know anything about it except what is written on that page :)
/L
--
Lasse Reichstein Nielsen - email***@***.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
|
| |
|
| |
 |
Googmeister

|
Posted: 2005-9-3 19:38:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
> Hi folks...
>
> I have an application which needs to store variable-length strings (up
> to 24 characters long) that must then be matched according to prefix.
> That is, whenever a prefix is given, the application has to be able to
> retrieve all stored strings that start with this prefix. Conversely,
> the program has to be able to store strings in such a way, so that
> prefix-based retrieving is fast and accurate (i.e., all relative
> strings are located and retrieved). Doing this linearly is obviously
> slow and inefficient.
>
> So, what is the best way of implementing this functionality in J2SE 1.4
> or later? Or, if there is no ready (preprogrammed) way of doing it
> properly in the standard distribution, are you aware of any open source
> implementation (e.g., tree or something similar)?
If efficiency is crucial (time and space), use a trie, e.g., a ternary
search trie (TST). Its more flexible than a binary search tree
(e.g., supports prefix matches) and can be faster than hashing.
It can also be more space efficient that storing the strings in a
sorted array. Whether you are in need of such an optimized
solution depends on your application.
|
| |
|
| |
 |
dterzis

|
Posted: 2005-9-4 0:54:00 |
Top |
java-programmer >> Storing and parsing variable length strings
Hi folks...
First of all, thanks very much for all the ideas and suggestions. Much
appreciated!
Allow me to provide a bit more information, based on your comments thus
far.
- The strings used act as variable-length prefixes to stored objects.
- The set of strings that act as key to the stored objects is not known
beforehand. It is supposed to grow and be dynamically updated (i.e.,
sort of a dictionary or a routing table).
- The data structure must be able to retrieve all objects with a common
string prefix (e.g., all objects indexed by "Hi", "High", "Highland",
if the prefix were "Hi").
- Once a more generic prefix is received, the application needs to
substitute all the existing ones with the more generic (this being some
sort of aggregation).
- The size of storage required is rather medium scale, i.e. up to tens
of thousands of objects.
- Performance has to be high - i.e., no more than N*log(N) for any
operation.
By the looks of it, a Trie seems the best solution, but I will need to
develop one. Based on the above, do you believe I could get away with a
Java Collection, e.g. a TreeMap?
Thanks,
Dimitris
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-9-4 2:53:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
>
> - The size of storage required is rather medium scale, i.e. up to tens
> of thousands of objects.
>
> - Performance has to be high - i.e., no more than N*log(N) for any
> operation.
>
> By the looks of it, a Trie seems the best solution, but I will need to
> develop one. Based on the above, do you believe I could get away with a
> Java Collection, e.g. a TreeMap?
TreeMap will give you O(log n) performance - n (tens of thousands) times
better than apparently required.
O(n log n) is actually quite high. 30,000 * log2 30,000 is around
450,000. Multiply that by a nice constant and you get a lot of cycles.
But even a linear search is only O(n). n operations over a set of n
taking O(n log n) is more reasonable.
Binary search on arrays could be faster and have a lower memory
overhead. It would take some work to make arrays work efficiently with
insertion, but perhaps not as much as a Trie implementation.
Tries are going to be much more work, and quite possibly end up slower.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Wibble

|
Posted: 2005-9-4 3:16:00 |
Top |
java-programmer >> Storing and parsing variable length strings
email***@***.com wrote:
> Hi folks...
>
> First of all, thanks very much for all the ideas and suggestions. Much
> appreciated!
>
> Allow me to provide a bit more information, based on your comments thus
> far.
>
> - The strings used act as variable-length prefixes to stored objects.
>
> - The set of strings that act as key to the stored objects is not known
> beforehand. It is supposed to grow and be dynamically updated (i.e.,
> sort of a dictionary or a routing table).
>
> - The data structure must be able to retrieve all objects with a common
> string prefix (e.g., all objects indexed by "Hi", "High", "Highland",
> if the prefix were "Hi").
>
> - Once a more generic prefix is received, the application needs to
> substitute all the existing ones with the more generic (this being some
> sort of aggregation).
>
> - The size of storage required is rather medium scale, i.e. up to tens
> of thousands of objects.
>
> - Performance has to be high - i.e., no more than N*log(N) for any
> operation.
>
> By the looks of it, a Trie seems the best solution, but I will need to
> develop one. Based on the above, do you believe I could get away with a
> Java Collection, e.g. a TreeMap?
>
> Thanks,
>
> Dimitris
>
A TreeMap and a trie are pretty different. A TreeMap is a sorted
collection and and the tailMap() method could be used to find the
first the first string with a prefix. I think for you're app,
TreeMap is simpler and probably just as good as a trie.
|
| |
|
| |
 |
Googmeister

|
Posted: 2005-9-4 3:51:00 |
Top |
java-programmer >> Storing and parsing variable length strings
> By the looks of it, a Trie seems the best solution, but I will need to
> develop one. Based on the above, do you believe I could get away with a
> Java Collection, e.g. a TreeMap?
I was among those who proposed a trie for large problems. But given
the type of problem you describe, a balanced binary search tree
(TreeMap) will be plenty fast enough here.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- How to compute a regex match against an object's parameter by name?Consider that you want to do a regex match on the contents of an
attribute of that object. Say, for example, the contents of:
SomeObjectInstance.x
All is well unless you don't know ahead of time that "x" is the
attribute that the user will search against. Suppose that the object
can have any attribute name, and even all those possibilities aren't
known at compile time. The user can/will select this attribute, as well
as the regex pattern.
So the trick is how to apply the match against "x" in this case with
only "x" as a string passed to the method?
// this doesn't work!
public boolean isRegexMatch(String p, String m, SomeObject o, String
attribute){
Pattern pat = Pattern.compile(p);
Matcher mat = pat.matcher(o."attribute"); <--- doesn't work, obviously
return (mat.find());
}
The above would be nice, but as expected-it doesn't work.
So the question is, how to make the method functional without knowing
what it will be passed for "attribute"?
TIA!
BogusException
- 2
- I miss my preprocessor!There's one thing I really used the C/C++ preprocessor for, and that is
compile-time control of debugging statements.
in it's simplest form:
----------------------------------------------
// comment out this line to disable debugs
#define DEBUG 1
#ifdef DEBUG
# define dbg(msg) printf(msg)
#else
# define dbg(msg)
#endif
void main(int argc, char argv[][])
{
dbg("Some sorta message\n");
}
----------------------------------------------
This system had evolved to a very powerful mechanism for
enabling/disabling/removing debug statements from my code. The beauty of it
is that debugging code can be removed
entirely from released code, without removing from the source. (I like
leaving it in the source because it provides a sort of ancillary
documentation). The only shortcoming was the lack of variable macro
parameters in C/C++.
The nearest I could come up with in java is:
----------------------------------------------
class xxx
{
private static final boolean DEBUG=true; // set to false to turn
off debugging
void dbg(String msg)
{
if (DEBUG) // this gets optimized out
System.out.print(msg);
}
public static void main( String[] args )
{
if (DEBUG) dbg("Some sorta message\n");
}
} // xxx
----------------------------------------------
While this does seem to work, it relies on the compiler to implicitly
optimize the code out. Not that I don't trust the compiler, but how can I
prove it?
From an aesthetic point of view, the "if (DEBUG)" part seems to clutter up
the source.
And it leaves a stub for dbg() in the code.
My point is, what options are available to reproduce the desired mechanism?
(Don't give me anything from java 1.5/5.0; I can't use it till it is
officially released, and the major ide manufactures endorse it).
regards,
Dar7yl (the 7 is silent)
- 3
- Basic FreeBSD Java/Tomcat questionsHello, all=2E I'm an old hand with Java but relatively inexperienced with=
FreeBSD, and I've never run Java there until the last few days=2E I had a=
few things I was wondering about=2E I can't find these things in the
archives, and don't know where else to look=2E Some of my questions might=
betray my lack of FreeBSD knowledge =2E=2E=2E
My preferences:
1=2E Avoid customization to the extent possible -- I don't really want to=
spend much energy being an admin -- even if my configuration is not
optimally flexible, or whatever=2E This means I'd prefer to use packages
from 5=2E4-RELEASE as opposed to ports, etc=2E
2=2E Not to have to build full JDK (with web start, plugins, etc=2E) --
building minimal took days as it was=2E
3=2E Simplest system possible, fewest installs possible, ease of
administration/use=2E
Here's what I've done so far:
1=2E Installed FreeBSD 5=2E4-RELEASE (minimal distribution set only)
2=2E Built jdk-minimal-1=2E4=2E2p7 from source on test machine=2E Seemed=
to go
fine=2E Created package using pkg=5Fcreate -b =2E=2E=2E
3=2E Installed jdk-minimal-1=2E4=2E2p7 as package=2E java -version works=
; haven't
tried much else, except =2E=2E=2E
4=2E jakarta-tomcat-5=2E0=2E30 as package WITHOUT its dependencies (i=2Ee=
=2E,
pkg=5Fadd -r from my own server, which does not have the fonts stuff on it=
)=2E=20
Besides emitting the predicatable complaints about missing dependencies,
the pkg=5Fadd command emits a warning saying the jdk package is required a=
nd
I have jdk-minimal=2E
5=2E Tomcat post-install
cp conf/server-minimal=2Exml=2Esample to conf/server=2Exml
cp conf/web=2Exml=2Esample to conf/web=2Exml
chown www conf/*=2Exml
/usr/local/etc/rc=2Ed/020* start
What happens:
It works, so far as I can tell=2E This means that I've gone to the home
page, not tested extensively=2E The 'balancer' webapp doesn't initialize
correctly (fails with NoClassDefFoundError on
org=2Eapache=2Ecommons=2Edigester=2EDigester) but I'm not too worried abou=
t that
since I don't know exactly what it's for and I haven't read any docs yet=2E=
Questions:
1=2E Why does Tomcat depend on all the font stuff=3F Can I safely run wi=
thout
it=3F
2=2E Same question with the jdk vs=2E jdk-minimal issue=2E
3=2E What are the limitations of tomcat50ctl=3F I've seen some messages =
in
the archives saying I'll need to change my /usr/local/etc/rc=2Ed script if=
I
want to do things like command-line arguments to Tomcat, etc=2E
Comments:
I'm really pleased (as I've worked through these issues) about how smart=20=
the packaging system is (e=2Eg=2E, not deleting files if they've been chan=
ged)=2E
Not sure to what extent credit is due FreeBSD developers and to what exten=
t
credit is due to people on this list, but take whatever you're entitled to=
=2E
:)
Special praise for the jdk14 port -- for such a complex build, I'm shocked=
how well it worked for me, particularly since I know very little about mak=
e=2E
Cheers,
-- David=2E
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web=2Ecom/ =2E
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 4
- Reading an array of byte with special delimiter....help me!!Hi guys,
i've developed a java application that has in input a txt file with a
standard format
string string string
string double double
string double double
and stores it into an array of byte with a fixed format,
that is
byte(whitespace)byte(whitespace)byte(;)byte(whitespace)byte(whitespace)byte(;)byte(whitespace)byte(whitespace)byte(;)
that mean introducing byte whitespace value and byte ; value to
separate different columns and different rows.
Now i have to develop inverse routine,that has to read the array of
byte and rebuild its original format.
Can you help me with some idea ord code?
I'm inexepert...please help me with clear suggest...
I post you my routine that converts txt file into an array of byte
P.S.In my txt file number of columns and rows change for each file,what
is standard is a firtst headline that is an array of string and others
row with the same format string array of doubles....
[code]public byte[] getBytes(){
byte middlerow=' ';
byte endrow=';';
Vector temp=new Vector(10000000);
int i=0;
String g=null;
Riga r;
Double val[];
while(i<intest.length){
//copio tutto nell'array di byte
byte []bytes = intest[i].getBytes();
// memorizza in byte un elemento del vettore alla volta
for( Byte aByte : bytes ) {
temp.addElement( aByte );
}
temp.addElement( Byte.valueOf( middlerow ) );
i++;
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for(int l=0;l<rows.size()-1;l++){
r=(Riga)rows.get(l);
g=r.getgeneid();
temp.addElement(g.getBytes());
temp.addElement(Byte.valueOf(middlerow));
val=r.getvalues();
for(int e=0;e<=val.length-1;e++){
temp.addElement(Byte.valueOf(val[e].byteValue()));
//val[e].byteValue() fa il casting double in byte
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));
}
byte [] b=new byte[temp.size()];
for (int k=0;i<temp.size();i++){
b[k]=(((Byte)temp.elementAt(k)).byteValue());
}
return b;
}[/code]
Thanks for your help...
- 5
- problems with TCPMONHi,
I'm using axis 1.2-RC3 and eclipse 3.01RC. When i run tcpmon from
command line
>java -cp org.apache.axis.utils.tcpmon
i use the panel for setting me as listener on port 8083 while tomcat is
on port 8080.
The problem is that when the client comunicate with server i dont have
2 SOAP messages but the tcpmon loops infinite on an error message.
I cant post you the output because tcpmon goes in infinite loop and its
impossible to copy text.
However i have set the axis path appropriately and i have added it to
classpath and classpath to path so i can call tcpmon with java org.....
I have also the needed jars (expecially) axis.jar included in axis
server (on tomcat) and imported in eclipse project.
Thank you in advance!
- 6
- java.net SocketPermissionHi,
I am getting the SocketPermission deny error when I trying to run my
applet on the net. When I was running stand along, embed in the frame,
on my local PC, it was no problem. Help!!!
eric
- 7
- recognizing java processesHow would you recognize a java process (as java process) in runtime
from outside the JVM? (win32)
is there a nicer way than monitorizing DLL loads in order to detect
the jvm.dll/javai.dll load?
- 8
- Java Applet in Mac FireFox sets multiple DIFFERENT cookiesI've been fighting with this one for a couple days. I'm getting two
(different) cookie headers being set.
Quick Background:
- Using a TurboGears web application.
- Embedding an Applet to assist in file uploads (JUpload).
- Applet uploads the files and sends the data to a secure URL.
- A session ID preserves the user's login information so they don't
get a 403 or have to login again.
- Works totally fine in everything EXCEPT FireFox on a Mac (Safari
works fine, as well as FireFox in Windows)
Using Ethereal to look at the HTTP header, there are two "Cookies"
values being set. The one that I set, and some other random one which
I have NO idea where it is coming from. As follows:
POST /import/upload HTTP/1.1
Cookies: tg-visit=2k842fgj237dfkvh232c32hdh3832
Content-length: 123541
<blah blah blah other headers>
Cookies: tg-visit=743jk82hfg94520fng62j8233jfg826
The first tg-visit value (the session id) is correct. The second one
which is the last header being set, is some other id being set. In
Safari the tg-visit value is the same on both lines and it works fine.
Other browsers properly only sets a single line. Firefox on a Mac
gives me two different values, and I have NO idea why.
Code to follow:
<APPLET CODE="foo.bar.myApplet" ARCHIVE="/static/myApplet.jar"
WIDTH="450" HEIGHT="320">');
<PARAM name="type" value="application/x-java-applet;version=1.4" /
>');
<PARAM name="scriptable" value="true" />
<PARAM name="postURL" value="${postUrl}" />
<PARAM name="redirectURL" value="${redirectUrl}" />
<PARAM name="tgVisitValue" value="tg-visit=${tgVisitValue}" />
</APPLET>
I have also tried to use the MAYSCRIPT attribute, but that doesn't
really help.
Using TurboGears which fills in the ${tgVisitValue} properly (which
works fine).
myApplet.java
this.mycookies = this.getParameter("tgVisitValue",
DEFAULT_COOKIE_STRING);
if (this.mycookies == DEFAULT_COOKIE_STRING) {
try
{
JSObject window = JSObject.getWindow(this );
JSObject document =
(JSObject)window.getMember( "document" );
String cookies =
(String)window.eval("self.document.cookie");
if (cookies.equals("undefined")) // we're IE
cookies = (String)document.getMember("cookie");
// NAOMI
// get all the unexpired cookies
// this.mycookies = (String) document.getMember( "cookie" );
}
catch ( Exception e )
{
this.mycookies = "nocookie=0";
}
}
This grabs the cookie value properly, so I don't think there are any
problems there. The code that does all the HTTP magic is here:
try{
String boundary = "-----------------------------" +
getRandomString();
url = new URL(uploadURL);
// Setting up the connection for upload.
urlConn = url.openConnection();
urlConn.setRequestProperty("Cookie", this.mycookies);
urlConn.setDoInput (true);
urlConn.setDoOutput (true);
urlConn.setUseCaches (false);
urlConn.setRequestProperty("Content-length", ""+totalFilesLength);
urlConn.setRequestProperty("Content-Type",
"multipart/form-data; boundary=" +
boundary.substring(2,
boundary.length()));
String CRLF = "\r\n";
urlConn.connect();
// Retrieve OutputStream For upload (Post).
dOut = new DataOutputStream(urlConn.getOutputStream());
// Actual Uploading part.
StringBuffer sb;
File f;
uploadedLength = 0;
for(int i=0; i < aTotalFiles.length && !stop; i++){
f = aTotalFiles[i];
sb = new StringBuffer();
// Line 1.
sb.append(boundary);sb.append(CRLF);
// Line 2.
sb.append("Content-Disposition: form-data; name=
\"File");sb.append(i);
sb.append("\"; filename=\"");sb.append(f.toString());
sb.append("\"");sb.append(CRLF);
// Line 3 & Empty Line 4.
sb.append("Content-Type: application/octet-stream");
sb.append("Content-Length: " + f.length());
sb.append(CRLF);sb.append(CRLF);
dOut.writeBytes(sb.toString());
uploadFileStream(f,dOut);
dOut.writeBytes(CRLF);
}
// Telling the Server we have Finished.
dOut.writeBytes(boundary);
dOut.writeBytes("--");
dOut.writeBytes(CRLF);
dOut.flush ();
if(!stop) progress.setString("File(s) uploaded. Wait for server
response!");
bInp = new BufferedReader(new
InputStreamReader(urlConn.getInputStream ()));
Any ideas?
- 9
- The solutions are very OS specific.Hi Mark Thornton,
You wrote,
" The rough equivalent to an HDC is
a java.awt.Graphics object,
extended ( since Java 1.2 ) to java.awt.Graphics2D.
These are used for drawing to screens, printers
or into a BufferedImage. "
That's quit impressive,
But my bank simulation currently requires Excel,
which precludes Linux.
Also, if I ever moved my simulations to Direct Draw 7,
or even Direct 3D 9 ( instead of the GDI )
once again I'd be forced to use C++,
as DD7's interaction with MS windows is very tricky
and very OS specific.
For example,
Windows' taskbar hoards it's mouse messages.
The taskbar also turns on the system cursor,
which blocks VRAM-to-VRAM blts.
The solutions are very OS specific.
Would the bankers pay for that ? I doubt it.
- 10
- J2ME interview questionshey all,
i am wondering if u ca give me j2me interview questions link or u can
advice me regarding that.
Thanks!
- 11
- to whom it may concern
"pcbutts1" <email***@***.com> wrote in message
news:4e23e9d12ed44ede9a25a80dde27d810@erollscom...
>
> You don't, by any chance, have a tape recorder?
>
No. But I do own a shovel. I also own several high powered rifles and I'm
very proficient in using them. Capisce?
- 12
- Problem with table nameHi!
I have a problem to access tables in an Informix Database. Table names
are something like that :
informix.pv_tvvte
When I try a "SELECT informix.pv_tvvte.numero_vente FROM
informix.pv_tvvte WHERE informix.pv_tvvte.numero_vente=#value#", (I use
ibatis and spring) I get a syntax error exception (SQLException "Bad SQL
Grammar").
If I replace dot with "_" in the name, I get a "Table Not Found" Exception.
How could I escape the dot in the tables names ?
TIA
Arnaud
- 13
- Is it possible to design Audio CD player by using Java only?Never tried it myself, but have you looked at java media api. i am thinking
if reading file from the cd in a normal way (binary stream) and then
feeding it to media api can do the job....!!!
Good luck anyways :-)
"MiLF" <email***@***.com> wrote in message
news:bdesn5$rki$email***@***.com...
> I am not expecting how fancy the CD player will be, but basic function is
> enough.
>
>
- 14
- Capture keystrokeHi,
I have a command line java program and I am trying to capture a keypress
from the user to say pause or stop the program. The only way I can get
this to work at the moment is to read in a key but the program waits for
the user to press return. I don't want this. I want to read the keypress
asynchronously without the user hitting return.
Anybody give me some pointers to how to do this?
Thanks in advance
Brian
- 15
- JBoss 3.2.2 security
Hello,
I'm developing EJB based system on JBoss. The system consists of
two parts: the set of EJB's, mainly Entity Beans which are interfaces
to DB and servlet which is used as user interface. As the interface to
entity beans i'm using statefull session bean. Every call from servlet
have to pass throught it.
To authenticate users I'm using DatabaseServerLoginModule. Users are
able to login, but then they try again to execute eny method from
session bean the server throws exception
Authentication exception, principal=null
What am i doing wrong ?? Should I store the users principal or
it is stored in session context ?
Cheers,
--
Marcin Krasowski mkrasowski (at) zagiel (dot) com (dot) pl
To iterate is human, to recurse divine.
L. Peter Deutsch
|
|
|