comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * JNI Problem - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7003a5cdfa2f61b4 * Opening all links of a html page and saving the html pages - 4 messages, 4 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3965a89e63b8ab99 * Where do they go? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/13296f4262fb9757 * JAVA/ ORACLE/ CONTRACT/ FL - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c2089808879d1377 * Java program is not evaluating String value correctly... - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5d457b2bb465740e * Using reflection - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e55612b759c1004 * Javamail with TNEF parts - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ac08c28db6c8d339 * JTable/Model/JTextField focus problem - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c7cd3ebe3033c955 * Problems when generating classes from DTD - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cfee024510d8f879 * Another simple problem - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f3052e16ead05747 * Invoking 'diff' from java with piped input - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a587b43b3b207a9f * NoSuchMethodException when reflecting ServletContext as a parameter - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a447e67bb400d60c * Unique key and value - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3f78fd73e6d5dce7 * jfreechart: displaying values in pie chart as percentages - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5306e441484b2d4c * Can Java Programmer Learn C++ Quickly? - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c7a28aa864e41ec ============================================================================== TOPIC: JNI Problem http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7003a5cdfa2f61b4 ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 5:00 am From: [EMAIL PROTECTED] (vanDamschitz) We upgrade from JNI V1.1 to V1.4 and have the problem that some methodes could not be found in the object. Here some code: JAVA: public void setSomething(byte something[]) { this.something = something; } public byte[] getSomething() { return something; } C++: jMethodID = jniEnv->GetMethodID(jClass, "setSomething", "([B)V"); -> works jMethodID = jniEnv->GetMethodID(jClass, "getSomething", "()[B"); -> do not work with JNI V1.4 (worked with JNI V1.1) Please Help == 2 of 2 == Date: Fri, Dec 10 2004 2:05 pm From: "Chris Uppal" vanDamschitz wrote: > JAVA: > public void setSomething(byte something[]) { > this.something = something; > } > > public byte[] getSomething() { > return something; > } > > C++: > jMethodID = jniEnv->GetMethodID(jClass, "setSomething", "([B)V"); > -> works > > jMethodID = jniEnv->GetMethodID(jClass, "getSomething", "()[B"); > -> do not work with JNI V1.4 (worked with JNI V1.1) I can't see anything wrong with that, but of course it's not your real code. Nothing changed between 1.1 and 1.4 that should affect method lookup, so I think that it must be problem in your code somewhere. Possibly a bug that didn't show up with a 1.1 JVM but does with a 1.4 JVM. Another possibility is that jClass isn't pointing to the class you think it should be. BTW, have you tried -Xcheck:jni ? -- chris ============================================================================== TOPIC: Opening all links of a html page and saving the html pages http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3965a89e63b8ab99 ============================================================================== == 1 of 4 == Date: Fri, Dec 10 2004 5:15 am From: [EMAIL PROTECTED] (java_seek) I want to know how to open all the links of a html page and then, save those html pages. In other words, if a html page @ www.ndtv.com has 10 links, I would like to save the html pages (that are the target of these 10 links ) on to my computer. == 2 of 4 == Date: Fri, Dec 10 2004 3:27 pm From: Daniel Sjöblom java_seek wrote: > I want to know how to open all the links of a html page and then, save > those html pages. > In other words, if a html page @ www.ndtv.com has 10 links, I would > like to save the html pages (that are the target of these 10 links ) > on to my computer. wget. -- Daniel Sjöblom Remove _NOSPAM to reply by mail == 3 of 4 == Date: Fri, Dec 10 2004 6:26 am From: [EMAIL PROTECTED] I would suggest reading the HTML page through Java, parsing it to locate the links, and then reading each of those links. You could probably easily set up a recursive method to do it. == 4 of 4 == Date: Fri, Dec 10 2004 8:03 am From: "Tilman Bohn" On Fri, 10 Dec 2004 06:26:01 -0800, klynn4 wrote: > I would suggest reading the HTML page through Java, parsing it to > locate the links, and then reading each of those links. You could > probably easily set up a recursive method to do it. It would also be useful to write a Javascript interpreter along the way so one could pick up links that are being changed or inserted by JS. Cheers, Tilman -- `Boy, life takes a long time to live...' -- Steven Wright ============================================================================== TOPIC: Where do they go? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/13296f4262fb9757 ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 5:33 am From: "Paul Cager" Kieron Briggs wrote: > For the visually minded, here's a parable I use when explaining garbage > collection to people: > << snip >> > Kieron I think that was the best description of GC I've heard... So a java.lang.WeakReference must be exactly what it sounds like - a reference made out of something so weak that it cannot support the weight of an object. When the last "strong" reference is gone the weak reference breaks and the object falls to the floor. And a SoftReference must be like a cobweb. It is strong enough to support the object, but when the janitor thinks things are getting a bit too cluttered he gets a broom and sweeps all of the cobwebs away. And of course mark/sweep GC makes perfect sense now... == 2 of 2 == Date: Fri, Dec 10 2004 1:50 pm From: "Chris Uppal" Paul Cager wrote: > And of course mark/sweep GC makes perfect sense now... The janitor's name is Mark. -- chris ============================================================================== TOPIC: JAVA/ ORACLE/ CONTRACT/ FL http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c2089808879d1377 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 8:54 am From: "Tom Gugger" OMNI GROUP [EMAIL PROTECTED] 419-380-8853 J2EE/ JSP/ CONTRACT/ FL ORLANDO , FL EIGHT MONTHS Start Date: Jan 3, 2005 IMPORTANT: Contractor is required to provide laptop. REQUIRED SKILLS: - 2-3 Years of J2EE/JSP development experience - 5+ years of overall development experience - Developed JSP pages access the Oracle eBusiness Suite for a minimum of two Oracle eBusiness Suite implementations - Experience calling Oracle published API's and packets from JSP pages PREFERRED SKILLS: - Experience developing in PL/SQL - Experience working with Oracle TCA, AR and Credit Management data models ROLE: Lead J2EE Developer ADDITIONAL INFO: Position will develop 10-15 Custom JSP pages access Oracle eBusiness suite data. Several of the pages will be setup within the Oracle eBusiness suite but the majority of the pages will be used for external facing web functionality. The primary purpose is to allow customers to process Credit Applications online. This will require the ability to build JSP pages and call Oracle published API's with some PL/SQL programming needed as well. If interested and qualified, answer the five questions below. Email answers With a Resume to: [EMAIL PROTECTED] 1.. J2EE experience-------------yrs 2.. JSP experience---------------yrs 3.. Oracle experience-----------yrs 4.. Citizenship Status----------- 5.. Rate pr hr 1099-------------- 1099= You pay your expenses. Can be converted to W2= ============================================================================== TOPIC: Java program is not evaluating String value correctly... http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5d457b2bb465740e ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 6:15 am From: "Shelly" Just wanted to say thank you for the help. Worked great (I'm new at java so that stumpped me). Also, absolutely loved the "funnies" - made my day! Thanks to all of you and Happy Holidays! :) == 2 of 2 == Date: Fri, Dec 10 2004 11:01 am From: "jeffc" "Eric Sosman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > > > I think the problem is not that Java is evaluating String values incorrectly, > > the problem is that you're not comparing String values! Remember that every > > (object) variable is actually a reference, not the object itself. So you are > > asking if a reference to a String is equal to a literal string. Those are > > apples and oranges. As a newbie to the language myself, I'm a little surprised > > it even compiles, actually. I'm not quite sure why comparison of a reference > > value with a literal string would be allowed. > > The literal "WI" is itself a reference: it is a > reference to a two-character String object that gets > created behind the scenes, as it were, containing the > characters 'W' and 'I'. So the two things being > compared are two references, and the question being > asked is "Do these two refer to the same String object?" Ah, so if this had been some other sort of literal, like a primitive type 'c' or 3, then no object would have been created. Since it is a String literal, an object is created. Is there any other Java literal for which an actual object is created? ============================================================================== TOPIC: Using reflection http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e55612b759c1004 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 6:24 am From: [EMAIL PROTECTED] >You can create Objects without a no argument constructor useing > java.lang.reflect.Constructor objects. Very good point. ============================================================================== TOPIC: Javamail with TNEF parts http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ac08c28db6c8d339 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 6:27 am From: [EMAIL PROTECTED] > I have little experience with TNEF but seem to recall something > about there being a single TNEF attachment, and that the other > attachments are inside the TNEF attachment. Yep right, all the attachments are in a single TNEF attachment, the problem is I cant get at this attachment through Javamail. I should be seeing two parts, one part containing the text of the body of the email and the other part containing any formatting instructions along with all attachments grouped into a single TNEF attachment but I don't see this second part. ============================================================================== TOPIC: JTable/Model/JTextField focus problem http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c7cd3ebe3033c955 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 9:28 am From: "blue" Hello All (I posted this in the java.gui group also, but that group doesn't seem to be used much more than a couple times per day), I have a JTable with a DefaultTabelModel. I have applied my own focus listener (lost/gained) to a JTextField which I am using as the cell editor. My problem is this: If I use the mouse to actually click into a cell, the focus gained even will fire for my textfield and tabbing off the field will fire the focus lost event. However, if I tab between cells without using the mouse, the focus gained and focus lost event do not fire. Am I missing something? Thanks, Frank ============================================================================== TOPIC: Problems when generating classes from DTD http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cfee024510d8f879 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 3:54 pm From: "Jack Andersson" I'm using the code below to parse a DTD (which partly present below) and then generating corresponding classes. The problem I'm having now is that the generated classes seems to have the CompanyQuery as a subclass to CGDocument and all the others as subclasses to CGNode. However, my plan was to also have the CompanyResult as a subclass to CGDocument, but I can't understand what I'm doing wrong. Please note that the DTD is not present completely, because it is huge. Thus it may not possible to parse it directly. import java.io.File; import java.net.URL; import oracle.xml.parser.v2.DOMParser; import oracle.xml.parser.v2.DTD; import oracle.xml.parser.v2.XMLDocument; import oracle.xml.parser.XMLParser; import oracle.xml.classgen.*; public class SampleMain2 { public SampleMain2() { } public static void main (String args[]) { // PostCompanyQueryToTheca(); CreateReturnMetaData(); } public static void parseDTD () { dtdFile = "MyDtd.dtd"; String rootName = "CompanyQuery"; try { // Instantiate the parser DOMParser parser = new DOMParser(); //XMLParser parser = new oracle.xml.parser.v2.XMLParser(); XMLDocument doc = null; oracle.xml.parser.v2.DTD dtd_v2 = null; oracle.xml.parser.DTD dtd_v1 = null; oracle.xml.parser.XMLParser xmlParser = new XMLParser(); xmlParser.setErrorStream(System.out); xmlParser.setValidationMode(false); //xmlParser.parseDTD(fileToURL(dtdFile), rootName); dtd_v2 = new oracle.xml.parser.v2.DTD(); dtd_v1 = (oracle.xml.parser.DTD) xmlParser.getDoctype(); parser.setDebugMode(true); parser.setErrorStream(System.out); //parser.setSchemaValidationMode(false); //parser.setPreserveWhitespace(false); //parser.setValidationMode(false); parser.parseDTD(fileToURL(dtdFile), rootName); dtd_v2 = (DTD)parser.getDoctype(); String doctype_name = null; doctype_name = rootName; // generate the Java files... ClassGenerator generator = new ClassGenerator(); // set generate comments to true generator.setGenerateComments(true); // set output directory generator.setOutputDirectory(".\\src\\DTDClasses\\"); //generator.setOutputDirectory(".\\src\\"); // set validating mode to true generator.setValidationMode(true); // generate java src generator.generate(dtd_v2, doctype_name); } catch (Exception e) { System.out.println ("XML Class Generator: Error " + e.toString()); e.printStackTrace(); } } static public URL fileToURL(String sfile) { File file = new File(sfile); String path = file.getAbsolutePath(); String fSep = System.getProperty("file.separator"); if (fSep != null && fSep.length() == 1) path = path.replace(fSep.charAt(0), '/'); if (path.length() > 0 && path.charAt(0) != '/') path = '/' + path; try { return new URL("file", null, path); } catch (java.net.MalformedURLException e) { // According to the spec this could only happen if the file // protocol were not recognized. throw new Error("unexpected MalformedURLException"); } } } <?xml version="1.0" encoding="UTF-8"?> <!-- Fråga mot företag --> <!ELEMENT CompanyQuery EMPTY> <!ATTLIST CompanyQuery CompEmployee CDATA #IMPLIED> <!ATTLIST CompanyQuery Employee CDATA #IMPLIED> <!-- Anrop till sökmotor, slår samman frågor --> <!ELEMENT CompanyCompose (CompanyQuery+)> <!ATTLIST CompanyCompose CustomerId CDATA #REQUIRED> <!ATTLIST CompanyCompose Duplicates (YES | VATNO | CFARNR | NAME | NAMELOCALITY | NAMEADDRESS | TELEPHONE) "YES"> <!ATTLIST CompanyCompose SendRecords (NO|DIRECT|FILE) "NO"> <!ATTLIST CompanyCompose FromRecord CDATA #IMPLIED> <!ATTLIST CompanyCompose ToRecord CDATA #IMPLIED> <!ATTLIST CompanyCompose MaxRecords CDATA #IMPLIED> <!ATTLIST CompanyCompose ID (0 | 1) "0"> <!ATTLIST CompanyCompose VATNo (0 | 1) "0"> <!-- Svar från CompanyCompose --> <!ELEMENT CompanyResult (CompanyResultCount, CompanyResultColumns?, CompanyResultRecord*)> <!ATTLIST CompanyResult ReturnCode (OK|ERROR) "OK"> <!ATTLIST CompanyResult ErrorText CDATA #IMPLIED> <!ATTLIST CompanyResult DeliveryId CDATA #REQUIRED> <!ATTLIST CompanyResult FileName CDATA #REQUIRED> <!ATTLIST CompanyResult CustomerId CDATA #REQUIRED> <!-- Räknar antal poster --> <!ELEMENT CompanyResultCount EMPTY> <!ATTLIST CompanyResultCount Total CDATA #REQUIRED> <!ATTLIST CompanyResultCount FromRecord CDATA #REQUIRED> <!ATTLIST CompanyResultCount ToRecord CDATA #REQUIRED> <!ATTLIST CompanyResultCount WithTelephone CDATA #REQUIRED> <!ATTLIST CompanyResultCount WithTelefax CDATA #REQUIRED> <!-- Kolumner i utfilen --> <!ELEMENT CompanyResultColumns EMPTY> <!ATTLIST CompanyResultColumns ID (0 | 1) "0"> <!ATTLIST CompanyResultColumns VATNo (0 | 1) "0"> <!-- Resultatrecord --> <!ELEMENT CompanyResultRecord (ID?, VATNo?)> ============================================================================== TOPIC: Another simple problem http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f3052e16ead05747 ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 2:55 pm From: Joona I Palaste [EMAIL PROTECTED] scribbled the following: > The constructor name has to be the same as the class name. Which is something that has lately struck me as needless. Why not have a special keyword for constructors? Such as "new"? For example: public class Foobar { public new() { /* ... */ } public new(int foo, int bar) { /* ... */ } } There is no loss of information, because every constructor in the same class must have the same name anyway. -- /-- Joona Palaste ([EMAIL PROTECTED]) ------------- Finland --------\ \-------------------------------------------------------- rules! --------/ "Remember: There are only three kinds of people - those who can count and those who can't." - Vampyra == 2 of 2 == Date: Fri, Dec 10 2004 8:14 am From: Chris Smith Joona I Palaste <[EMAIL PROTECTED]> wrote: > Which is something that has lately struck me as needless. Why not have > a special keyword for constructors? Such as "new"? For example: > > public class Foobar { > public new() { > /* ... */ > } > public new(int foo, int bar) { > /* ... */ > } > } I certainly don't see a compelling argument against that syntax, and it would certainly avoid a couple newbie pitfalls. However, I don't see the kind of compelling interest that would result in a language change for it after the fact. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: Invoking 'diff' from java with piped input http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a587b43b3b207a9f ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 4:00 pm From: David Kensche > >>my first implementation used jrcs but this was prohibitively slow in >>patching. This is why I decided to try GNU diff/patch. But to be honest >>I thought about trying eclipse instead but I was sure, that eclipse >>uses diff and patch as provided by the cvs installation. But if there >>is a java implementation, I will try this, too. > > > Please share your experiences with all these different > difference implementations. I'd like to know how the Eclipse compare > algorithm compares to GNU diff and JRCS. To be honest I just tested my old implementation some more times and it seems that I have an error in it and _this_ is the reason why it does not work correctly. My problem with jrcs that I could not find a parser for the patch format, and also I am not able to understand the cryptic code. Consequently I had to wrap deltas and chunks by classes which create an (inefficient) XML representation so I could write an XML parser being agnostic about the semantics of the used variables. But somewhere therein has to be the error. I'll try to find it. Greetings, David ============================================================================== TOPIC: NoSuchMethodException when reflecting ServletContext as a parameter http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a447e67bb400d60c ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 3:10 pm From: natG Nicky wrote: > getDeclaredMethod only searches in the actual class of the object, but not > in the superclasses. > Are you sure about this? Anyhow, I tried with the same results. No go. Thanks, -nat == 2 of 2 == Date: Fri, Dec 10 2004 3:49 pm From: natG John C. Bollinger wrote: > natG wrote: > >> I am not new to reflection, but due to events, I feel new:). > After your elaborate response (thanks!) I see that I *am* new<g>. > Well, you've hit one of the more common reflection stumbling blocks: > matching reflected method signatures to method argument types. When a > method's formal argument type is a non-final class type, you cannot just > match the class of the argument to the method signature because the > reflective method lookup methods look for an *exact match*. Such a > match will not be achieved if the class of the argument is a proper > subtype of the formal type declared by the method. In particular, you > will *never* find a match when the formal argument type is an abstract > type (such as the ServletContext interface). Real new to me. Thanks. > Similar problems can apply to primitive arguments, too, because they can > be promoted according to method invocation conversion rules. (JLS 2ed, > section 5.3) I would never dream that some sort of subclassing might be applied to primitives, and I still don't really get it, but I'll google "JLS 2ed, section 5.3", over the weekend to study this. > If you don't know in advance the signature of the method you want to > invoke then for full generality you need to implement the method > resolution procedure specified in JLS(2ed) 15.12.2 - 15.12.4. The > compiler takes care of all that for you in standard method invocations, > but you have to deal with it yourself when you use reflection. Shall google this as well. Aye, you gave me good weekend homework! >> When passing a ServletContext as a parameter to the reflected method, >> it throws the NoSuchMethodException. > > > Because whatever the ServletContext implementation class happens to be, > it is definitely *not* javax.servlet.ServletContext. True. I even tried casting the object parameter with (ServletContext), to no avail. > >> Here is the exact simplified code that produces it. (Please excuse >> the extra Invoker class, I use it to test non-servlet related >> reflection.) > > > [edited for brevity:] > >> public class StaticMethodClass { > > > >> public static void methodA(ServletContext ctx, String s2){ >> System.out.print("Hello from methodA: ctx s2 . You passed "+ >> s2); >> System.out.println(" from ServletContext: " + ctx.toString()); >> } >> } > > > >> public class Invoker { >> >> Method m = null; >> >> public Invoker(String methodName, Object[] methodParameters){ >> runCustomMethod(methodName,methodParameters); >> } >> >> public void runCustomMethod(String methodName, Object[] >> methodParams){ >> Class c = StaticMethodClass.class; >> Method m = null; >> Class[] parameterTypes = null; >> if (methodParams!=null){ >> parameterTypes = new Class[methodParams.length]; >> for (int i=0;i<methodParams.length;i++){ >> parameterTypes[i] = methodParams[i].getClass(); >> } >> } >> try { >> m = c.getDeclaredMethod(methodName,parameterTypes); > > > You didn't say, but I can be pretty confident that the exception is > thrown during execution of the above method. The method is not found True. > because it is not there. To make this work reliably your invoker must > get the list of all methods of the class in question that have the > correct name, determine (according to JLS rules) which are both > "applicable" to the arguments and accessible to the invoking code, and > among those choose the "most specific" method. It is possible for there > to be no single most specific method, which is a compile-time error in > non-reflective code, but which you can handle however you want in your > own invoker. ... > >> new Invoker("methodA", new Object[]{ctx,s1}); //this does NOT. > > [does not work, that is.] You're subtle unrelated correction of my //comment has taught me more, much more, in general, and at an abstract level, than everything this thread topic is all about. Incredible. When I saw this correction, I realized I had quick, clear thinking professor mentoring me. I will post both lines below so that others understand. "new Invoker("methodA", new Object[]{s0,s1}); //this works ok." "new Invoker("methodA", new Object[]{ctx,s1}); //this does NOT." (Speaking at this level, can you please explain why you used [brackets] for the correction? (Sorry, if I off on a tangent.) ) > Do not be confused between the type of a > reference variable and the class of the object to which the variable > refers. They do not need to be the same. Even if the variable type is > a final class type, the variable value can still be null (and that will > cause your Invoker to throw a NullPointerException even though there may > be a suitable method it could invoke). There are many api methods that a null parameter is used by design. Can I then not call these reflectively? (Other than catching NPE.) > > John Bollinger > [EMAIL PROTECTED] Thank you, again. -nat ============================================================================== TOPIC: Unique key and value http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3f78fd73e6d5dce7 ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 3:28 pm From: "Bruce Lee" "Bruce Lee" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is it possible to have a hashtable that has both unique keys and unique > values (ie like a 2-columned database with both rows unique)? > > Thanks all for the feedback. "if memory is not an issue, you can use two sets and a hashset. the two sets keep keys/values for checking and the hashset keeps keys/values for access." I'm doing this at the moment although it's a bit wasteful. I'm using 2 TreeMaps. A mirror image of each other. eg. I want to add the key "ferrari" and the 'key' value "diablo" to the main list. Object ob1 = valuestree.get("diablo") if(ob1==null){ //doesn't exist as a value. Object ob2 = maintree.get("ferrari"); //check if no ferrari if(ob2==null) { // ok, not a key maintree.put("ferrari","diablo"); valuestree.put("diablo","ferrari"); } } } This works, but as I say it's seems a bit wasteful on memory. "Try looking at org.apache.commons.collections.BidiMap" " BugBear" Thanks I'll have look. == 2 of 2 == Date: Fri, Dec 10 2004 8:48 am From: Chris Smith Bruce Lee <[EMAIL PROTECTED]> wrote: > "if memory is not an issue, you can use two sets and a hashset. the two > sets keep keys/values for checking and the hashset keeps keys/values for > access." > > I'm doing this at the moment although it's a bit wasteful. I think it's less wasteful than you believe. If you look, for example, at a database in a similar situation, I believe you'd find something similar going on; there will be a separate index used for each unique field. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: jfreechart: displaying values in pie chart as percentages http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5306e441484b2d4c ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 7:59 am From: "Marc Dugger" Solution.... PiePlot plot = new PiePlot(<your pie dataset>); StandardPieItemLabelGenerator labels = new StandardPieItemLabelGenerator("{0} = {2}"); plot.setLabelGenerator(labels); JFreeChart chart = new JFreeChart(plot); chart.setTitle("<your chart title>"); ChartUtilities.saveChartAsJPEG(img, chart, 400, 300); ============================================================================== TOPIC: Can Java Programmer Learn C++ Quickly? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c7a28aa864e41ec ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 8:07 am From: "jeffc" "Rhino" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > However, the core Java statements are "borrowed" from C and C++ has often > been called "C with classes". It seems to me that it shouldn't take very > long to get up to speed on C++ if I am already fluent with Java and have at > least some knowledge of C. Then again, I understand that Java and C++ use > classes a bit differently; for instance C++ allows multiple inheritance > while Java allows only single inheritance but allows for multiple interfaces > as compensation. I'm not sure how long it would take to get fluent with > multiple inheritance after several years with Java. I really don't think that sort of thing is going to be your major problem. It's such an easy to understand abstract principle that you will easily be aware of the differences when designing/coding. I think the things that will cause you more problems are the nuts and bolts of normal programming, such as memory management, declarations vs definitions, references vs pointers, etc. Garbage collection is an easy concept to understand, but you can easily forget where you need to pay attention to who owns memory in C++. C++ is also just a trickier language syntactically. Basically, it's just plain easier to get into trouble I think. There is also a book called Java/C++ Cross Reference or something like that that might be of help. == 2 of 2 == Date: Fri, Dec 10 2004 8:08 am From: "jeffc" "Sudsy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Rhino wrote: > <snip> > > I'd be very curious to know how long it took people here who were fluent in > > Java to get fairly fluent in C++ if they started with approximately the same > > skills I have today. > > I taught myself the fundamentals in a weekend. Weird stuff like templates > took a bit longer. Granted, I had seen C++ many years ago but didn't like > it as it didn't FORCE you to use object orientation. I wasn't surprised > when Forester Research suggested that some 85% of "C++" was actually > procedural C. But there's nothing at all wrong with that necessarily. You say it like it's a bad thing. The fact of the matter is that a lot of people simply don't understand what parts of C++ (that are different from C) are OO, and which are simply basic C++. Even if programmers wanted to write procedural code, I think C++ would be a far better language to use. ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
