Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2008, 04:19 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
[SOLVED] CharSequence interface
Can we do this?
Code:
private static TreeMap<Integer,java.lang.CharSequence>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2008, 05:14 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
What happens when you try to compile it? Let the compiler give you the answer.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-10-2008, 05:49 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
yes, I know about that
Quote:
Originally Posted by Norm View Post
What happens when you try to compile it? Let the compiler give you the answer.
Not to dissuade you, a CharacterSequence is an interface. Those work in ways I do not understand yet. I will wait on a more advanced answer.

In general, what they are trying to do is KISS, but the way they get used suggests relying soley on compiler is not a sufficient study. I will test anyway, as you direct, after I get some more advanced answers.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-10-2008, 07:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 5,075
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
For me that's fine. Because Charsequence is a valid mapped value for TreeMap.

I don't know how far my answer is valuable to you.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-10-2008, 05:50 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
a great help
Quote:
Originally Posted by Eranga View Post
...I don't know how far my answer is valuable to you.
sounds like it should work in other words. I will do a test like Norm directs, I just wanted someone else's opinon on the matter and am greatly appreciative.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-10-2008, 06:50 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Here's a Q&D implementation of the CharSequence class. It just needs some real guts to the various required methods, but should compile and give you a real object to satisfy the compiler with the TreeMap constructor.

Code:
class Tester implements java.lang.CharSequence { public char charAt(int index){return 'a';} // Returns the char value at the specified index. public int length() {return 1;} // Returns the length of this character sequence. public CharSequence subSequence(int start, int end) { return this;} // Returns a new CharSequence that is a subsequence of this sequence. public String toString() {return "A";} // Returns a string containing the ch } // end class
Then to use the above:
Code:
private static TreeMap<Integer,java.lang.CharSequence> myTree; .... myTree = new TreeMap<Integer, CharSequence>(); myTree.put(new Integer(1), new Tester());

Last edited by Norm : 07-10-2008 at 06:57 PM.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-11-2008, 04:03 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
preliminary implementation of your template
Quote:
Originally Posted by Norm View Post
...It just needs some real guts to the various required methods,
We will be taking some heat on this as shop practices that are normative ( sorry ) even at the trade school level have been dropped about a decade ago from the contemporary instructional horizon because of everything having rubber bumpers in all the places except where they really need them.

This is close to the buffer I actually want to use in the TreeMap.

Code:
// A compiled representation of a regular expression. import java.util.regex.Pattern; // Matcher: An engine that performs match operations // on a character sequence by interpreting a Pattern. import java.util.regex.Matcher;// /** * Discussion of an opinion in a technical forum. * Reader assumes the risk under any rework, the * code here is known to be incomplete and has no * legitimate derivative use beyond further development. * If you read this far you are like us and need to join our forum. */ public class Buffer implements java.lang.CharSequence { private int POSITION; // internal - not Java Naming style conventions. private Pattern pattern; private Matcher matcher; // Use of all caps to denote something which // is not intended to change during Object use. private static Integer BUFFER_LIMIT; // The actual buffer. private char[] INTERNAL_BUFFER; // Public constructor for use. public Buffer() { // 4096 is enough line length this(new java.lang.Integer(4096)); } // Public constructor for use. public Buffer(Integer size) { // I think this looks for words .... this.pattern = new Pattern("\\w??"); // We use an Object type to avoid auto-boxing this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } // Public constructor for use. public Buffer(Integer size,Pattern searchPattern) { this.pattern = new Pattern(searchPattern); // We use an Object type to avoid auto-boxing // since that may generate hidden nulls. this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } public String insertString(String suppliedString) { // Hey kids, does your computer have registers? int index = suppliedString.length(); do { // Norm, this is a normal copy operation. // Repetive thus ..... // Register <- RAM { location source } // Register -> RAM { location destination } INTERNAL_BUFFER[--index] = suppliedString.charAt(index);// } while(index > 0x0000);// } // Returns the char value at the specified index. public Character charAt(int index) { // Need exception trapping and bounds checking. return new Character(INTERNAL_BUFFER[index]); } // Returns the length of this character sequence. public int length() { return POSITION; } // Returns a new CharSequence that is a subsequence of this sequence. public CharSequence subSequence(int start, int end) { // Replacing this pointer with a String because I don't // have all the buffer logic worked sufficiently well. // We could return the this pointer later. char[] temp = new char[end - start];//Bounds checking? int index = temp.length;// do { // Norm, this can be re-implemented as // a traditional for loop or while() ' // I do it this way because I understand the loop logic. temp[--index] = INTERNAL_BUFFER[index];// } while(index > 0x0000); // Return a string from their copy, not ours. return new String(temp);// } // Use our own subSequence to generate a distinct string public String toString() { return subSequence(0, POSITION); } } // end Buffer
The work here is first-draft prior to preliminary compiler pass.
What is Q&D? Mabye: Archaeologists to Demonstrate Ancient Brewing
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 07-11-2008, 04:30 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
build log .... we have work to do
Code:
Buffer.java:54: charAt(int) in Buffer cannot implement charAt(int) in java.lang.CharSequence; attempting to use incompatible return type found : java.lang.Character required: char public Character charAt(int index) Buffer.java:25: cannot find symbol symbol : constructor Pattern(java.lang.String) location: class java.util.regex.Pattern this.pattern = new Pattern("\\w??"); Buffer.java:33: cannot find symbol symbol : constructor Pattern(java.util.regex.Pattern) location: class java.util.regex.Pattern this.pattern = new Pattern(searchPattern); Buffer.java:86: incompatible types found : java.lang.CharSequence required: java.lang.String return subSequence(0, POSITION); 5 errors BUILD FAILED (total time: 2 seconds)
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 07-11-2008, 05:32 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Quick and Dirty.
Code:
// A compiled representation of a regular expression. import java.util.regex.Pattern; // Matcher: An engine that performs match operations // on a character sequence by interpreting a Pattern. import java.util.regex.Matcher;// /** * Discussion of an opinion in a technical forum. * Reader assumes the risk under any rework, the * code here is known to be incomplete and has no * legitimate derivative use beyond further development. * If you read this far you are like us and need to join our forum. */ public class Buffer implements java.lang.CharSequence { private int POSITION; // internal - not Java Naming style conventions. private Pattern pattern; private Matcher matcher; // Use of all caps to denote something which // is not intended to change during Object use. private static Integer BUFFER_LIMIT; // The actual buffer. private char[] INTERNAL_BUFFER; // Public constructor for use. public Buffer() { // 4096 is enough line length this(new java.lang.Integer(4096)); } // Public constructor for use. public Buffer(Integer size) { // I think this looks for words .... this.pattern = Pattern.compile/*new Pattern*/("\\w??"); // no Constructor // We use an Object type to avoid auto-boxing this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } // Public constructor for use. public Buffer(Integer size,Pattern searchPattern) { this.pattern = /*new Pattern*/(searchPattern); // We use an Object type to avoid auto-boxing // since that may generate hidden nulls. this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } public String insertString(String suppliedString) { // Hey kids, does your computer have registers? int index = suppliedString.length(); do { // Norm, this is a normal copy operation. // Repetive thus ..... // Register <- RAM { location source } // Register -> RAM { location destination } INTERNAL_BUFFER[--index] = suppliedString.charAt(index);// } while(index > 0x0000);// return "???"; } // Returns the char value at the specified index. public /*Character*/ char charAt(int index) // returns char not Char { // Need exception trapping and bounds checking. return new Character(INTERNAL_BUFFER[index]); } // Returns the length of this character sequence. public int length() { return POSITION; } // Returns a new CharSequence that is a subsequence of this sequence. public CharSequence subSequence(int start, int end) { // Replacing this pointer with a String because I don't // have all the buffer logic worked sufficiently well. // We could return the this pointer later. char[] temp = new char[end - start];//Bounds checking? int index = temp.length;// do { // Norm, this can be re-implemented as // a traditional for loop or while() ' // I do it this way because I understand the loop logic. temp[--index] = INTERNAL_BUFFER[index];// } while(index > 0x0000); // Return a string from their copy, not ours. return new String(temp);// } // Use our own subSequence to generate a distinct string public String toString() { // What to return ??? return "???"; // subSequence doesn't return a String // return subSequence(0, POSITION); //?? public CharSequence subSequence(int start, int end) } } // end Buffer

Last edited by Norm : 07-11-2008 at 05:44 AM.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 07-11-2008, 05:04 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
clean compile - ready for test harness
Quote:
Originally Posted by Norm View Post
Quick and Dirty.
Aw gee, thought it meant quality and delivered homebrew.

Code:
Tool completed successfully
Issues remain, and as well to design a test harness.
Additionally, we probably should work on implementing
matcher.find() which would be boolean find() return matcher.find();//

I reworked constructor to work towards this, see link to docs at constructor taking an Integer. I made several changes after getting one clean compile, did not do a second build.

Pattern.compile("\\w??"); is a static method and may be called directly at any point to get an instance of a Pattern. I have seen this approach in some remarkably skilled work. Google for "Why Johnny can't crypto" or ask me. These are called static factory methods in the cs literature. I found that using the design avoids several subtle constructor issues that are not apparent and have no ready approach visible when first encountered in studies.

I added one.

Code:
// A compiled representation of a regular expression. import java.util.regex.Pattern; // Matcher: An engine that performs match operations // on a character sequence by interpreting a Pattern. import java.util.regex.Matcher;// /** * Discussion of an opinion in a technical forum. * Reader assumes the risk under any rework, the * code here is known to be incomplete and has no * legitimate derivative use beyond further development. * If you read this far you are like us and need to join our forum. */ public class Buffer implements java.lang.CharSequence { // Member variables. private int POSITION; // internal - not Java Naming style conventions. private Pattern pattern; private Matcher matcher; // Should be final, that fixes buffer size. // Making buffer size a constructor parameter // and buffer size final brings some clumsy // constructor syntax or non-conformant approaches. private static Integer BUFFER_LIMIT; // The actual buffer. private char[] INTERNAL_BUFFER; // Public constructor for use. public Buffer() { // 4096 is enough line length this(new java.lang.Integer(4096)); } // Public constructor for use. public Buffer(Integer size) { // http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html this.pattern = Pattern.compile("\\w??"); // no Constructor needed. this.matcher = pattern.matcher(new String(INTERNAL_BUFFER)); // We use an Object type to avoid compiler working // in unanticipated optimizations that break our design. this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } // Public constructor for use. public Buffer(Integer size,String searchPattern) { this.pattern = Pattern.compile(searchPattern); this.matcher = pattern.matcher(new String(INTERNAL_BUFFER)); // We use an Object type to avoid auto-boxing // since that may generate hidden nulls. this.BUFFER_LIMIT = new java.lang.Integer(size);// this.INTERNAL_BUFFER = new char[BUFFER_LIMIT];// } // Static Factory method: public static Buffer getInstance() { return new Buffer(); } // Rework likely. public String insertString(String suppliedString) { // Hey kids, does your computer have registers? int index = suppliedString.length(); do { // Norm, this is a normal copy operation. // Repetive thus ..... // Register <- RAM { location source } // Register -> RAM { location destination } INTERNAL_BUFFER[--index] = suppliedString.charAt(index);// } while(index > 0x0000); // The contents of the character array are copied; // subsequent modification of the character array // does not affect the newly created string. We // should design test harness to insure the inversion // of the design contract spec'd by the String class // does or does not give the caller a reference to // our buffer. Probably correct, and if so renders // our initial design weak if used in a core loop: // Two copy operations for one copy operation. return new String(INTERNAL_BUFFER);// move to ...? } // Returns the char value at the specified index. public char charAt(int index) // returns char not Char { // Need exception trapping and bounds checking. char c = INTERNAL_BUFFER[index]; return c; } // Returns the length of this character sequence. public int length() { return POSITION; } // Returns a new CharSequence that is a subsequence of this sequence. public CharSequence subSequence(int start, int end) { // Replacing this pointer with a String because I don't // have all the buffer logic worked sufficiently well. // We could return the this pointer later. char[] temp = new char[end - start];//Bounds checking? int index = temp.length;// do { // Norm, this can be re-implemented as // a traditional for loop or while() ' // I do it this way because I understand the loop logic. temp[--index] = INTERNAL_BUFFER[index];// } while(index > 0x0000); // Return a string from their copy, not ours. return (CharSequence) new String(temp);// } // Use public String(char[] value) ? // There is an internal that is not published: // If the char[] has a size of 4096 but we have // only placed valid characters in some range 0 - ? // then does the string have a length of INTERNAL_BUFFER ? // If so, our fundamental design approach has to be rethunk. public String toString() { // We can probably do this: return new String(INTERNAL_BUFFER); } } // end Buffer
BTW: More on Collection FrameWork | Java Tips Blog
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan : 07-11-2008 at 05:15 PM.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 07-11-2008, 06:44 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Ques re do{} while():
What does your code do if String length = 0?

What is the purpose and use of the Buffer class? Why does it implement CharSequence?
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 07-11-2008, 10:49 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 880
Nicholas Jordan is on a distinguished road
read write area for session master
Quote:
Originally Posted by Norm View Post
Ques re do{} while():
What does your code do if String length = 0?
rework;
Code:
// First rework. public String insertString(String suppliedString) { if(suppliedString != null) { try { if(suppliedString.length() > 0x0000) { // Hey kids, does your computer have registers? POSITION = suppliedString.length(); int index = suppliedString.length(); do { // ....... INTERNAL_BUFFER[--index] = suppliedString.charAt(index);// } while(index > 0x0000); // ....... return new String(INTERNAL_BUFFER);// move to ...? } else { return suppliedString; } } catch(ArrayIndexOutOfBoundsException aobe) { // add import java.io.PrintWriter; // add import java.io.FIleWriter; PrintWriter pw = new PrintWriter(new FileWriter("error.log"));// pw.print(e.getMessage()); return new String(""); } } else { return new String("");// } }
Quote:
What is the purpose and use of the Buffer class? Why does it implement CharSequence?
Holds mutable character strings while someone makes up their mind, I am working on generating AES keys right now. Once I have a session key we also have crypto keys independentlyly of what we key on here. As well maybe even some client side js so client is not involved with weak password generation. We get a real crypto key, and a - I do not have a word for this that the cryptologists will not hit me on - a final Integer that is and always is the map key && session key for this transaction. We try to match that up in the logs using tools designed for that purpose. At some point, what customer decided would be shipped to a site with stronger skills in verification, but I keep a transaction log of everything I can think of. We have an immutable session key for the transaction, but a mutable buffer for a while. The point of the design is the mutable in the SessionMaster mutable dtata is a CharSequence, not the classes I see in the libraries.

Several approaches are available, what I want to do here is not unlike StringBuffer. It is just that I have several fields.Perhaps I may want to do zip code crossed to town and whatever comes within skills. The primary idea is that of only allocating one char[] per field so that scalability is not broken my multiple needless new String calls. Often the libs will introduce hidden gotchas, this core area will be fine toothed ~ no wiggle room.

See Dov Bulka, PhD: Efficient C++
ISBN:0201379503
Quote:
Dov Bulka has spent fifteen years in the trenches of software development delivering large-scale software products to market. He was the performance architect of the IBM Domino-Go Web server that has powered some of the biggest Web sites ever hosted on the Internet, including that of the 1996 Atlanta Olympics. He received his Ph.D. in computer science from Duke University.
Source: Efficient C++ (Dov Bulka, David Mayhew)

We probably should do a close() or a flush and close on the PrintWriter. Most closes flush first but I have seen it cheated here and there. Also, TreeMap in Java is a Red-Black tree. I actually use Hashtable but post as TreeMap to avoid unjust critical review by un-informed persons.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan : 07-13-2008 at 09:08 PM. Reason: add else to handle null pointer
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
An interface extending an interface(II) JavaForums Java Blogs 0 03-12-2008 05:00 PM
An interface extending an interface(I) JavaForums Java Blogs 0 03-12-2008 05:00 PM
Extract Interface (I) JavaForums Java Blogs 0 03-12-2008 12:40 AM
DERS Interface Floetic AWT / Swing 2 03-10-2008 12:46 AM
Interface extending Interface JavaForums Java Blogs 0 12-04-2007 03:20 PM


All times are GMT +3. The time now is 12:08 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org