
-----------------------------------
copthesaint
Thu Oct 15, 2009 1:50 pm

Instance Class
-----------------------------------
This is my completly remade holder class. Ive spent the last two weeks workin on it. I havn't gotten to test it yet, but It does compile.
Please comment on my class, and everything is commented.

 /**
  *Instance Class
  *2.0
  *Christian Olienick Plourde
  *
  *Description: A unique class That allows you to create values
  *and destroy them. With this you can make flexable arrays,
  *two dimentional arrays with differents lengths, and remove
  *parts of arrays.
  * _____________________________________________________
  *|Holds Values whitout having to declair variables     
  *|_____________________________________________________
  *|Removal Methods: removeIntParts, removeDoubleParts,  
  *|removeInt, removeDouble                              
  *|                                                     
  *|Creation Methods: newInt, newDouble, newIntArray,    
  *|newDoubleArray, extendIntArray,extendDoubleArray                                       
  *|                                                     
  *|Modifying Methods: setInt, setDouble, setIntArray,   
  *|setDoubleArray, setArrayIntArray, setArrayDoubleArray
  *|                                                     
  *|Return Methods: returnInt, returnDouble,             
  *|returnIntArray, returnDoubleArray, returnIntArrayPart
  *|returnDoubleArrayPart                                
  *|_____________________________________________________
 */

-----------------------------------
DemonWasp
Thu Oct 15, 2009 5:46 pm

RE:Instance Class
-----------------------------------
Again, not to discourage you, but this is almost entirely duplicated effort. The JVM provides you with built-in classes for all of these requirements, all of which are faster than your implementation (and tested!). See 
List ints = new ArrayList();
ints.add ( 5 );

List doubles = new ArrayList();
doubles.add ( 3.1415 );


Removing elements from these lists:

ints.remove ( 0 );  // Removes the 0th element, without leaving empty spaces.
doubles.remove ( 10 ); // Removes the 11th element, without leaving empty spaces.


Mapping from "some string" to ( some object, integer or double or float or... )

Map = new HashMap();
map.put ( "twelve", 12 );
System.out.println ( map.get ( "twelve" ) );  // this will output 12.

// You can substitute the name of any class for "Integer" in the above to store arbitrary objects.


You also still have the drawback that I need to change your source to use the class adequately in my code (here, I'm referring to maxValues = 100, which is commented with "change to fit how many values you want to hold"). Worse, I may not know that information myself!

-----------------------------------
copthesaint
Thu Oct 15, 2009 6:32 pm

Re: Instance Class
-----------------------------------

Removing elements from these lists:

ints.remove ( 0 );  // Removes the 0th element, without leaving empty spaces.
doubles.remove ( 10 ); // Removes the 11th element, without leaving empty spaces.



First of all mine doesn't leave empty Spaces also :) Look at the Trim method I made.


Mapping from "some string" to ( some object, integer or double or float or... )

Map = new HashMap();
map.put ( "twelve", 12 );
System.out.println ( map.get ( "twelve" ) );  // this will output 12.

// You can substitute the name of any class for "Integer" in the above to store arbitrary objects.



Second My class does the same, but allows you to choose how many values to return, and if it's an array of just by it's self, and once
I have perfected the class for ints and doubles "or close enough :p", I'll add char and boolean and String. So on and so on.


Storing variable-length "arrays" of integers or doubles (note that you never need to manually extend anything): 


Yea lol I know, but you do need to extend the length with my class. If you don't, it will just keep running but it won't set the value.


Again, not to discourage you, but this is almost entirely duplicated effort. The JVM provides you with built-in classes for all of these requirements, all of which are faster than your implementation (and tested!). See java.util.List and java.util.Map


Lol If you try to discourage me, I'll just ignore you anyways ;p. I am still working on my class aswell ;p and by the time I'm done, It will be very useful.
Also FYI, I'm not copying it :) I just think of everything tha could be useful.

-----------------------------------
DemonWasp
Fri Oct 16, 2009 8:38 am

Re: Instance Class
-----------------------------------

First of all mine doesn't leave empty Spaces also :) Look at the Trim method I made.


That was my point. I did read your code, and I did see the comment that noted that it did not leave empty spaces. I was pointing out that the behaviour of a List is exactly the same.


Second My class does the same, but allows you to choose how many values to return, and if it's an array of just by it's self, and once
I have perfected the class for ints and doubles "or close enough :p", I'll add char and boolean and String. So on and so on.


Returning a sub-portion of a List:

List myList = new ArrayList();
// some code that adds values to myList would go here...
List subListing = myList.subList ( start, end );



Yea lol I know, but you do need to extend the length with my class. If you don't, it will just keep running but it won't set the value.


That sounds like poor behaviour. If something fails, you need to throw an Exception or otherwise report an error. It's up to the caller whether the error should be ignored or dealt with somehow.


My point with this is that unless you're specifically doing this to learn about algorithms, I don't see the point. The implementations you have posted are a good first attempt, but aren't going to stand up to what you can do with the classes provided by the JVM. If you are attempting to learn about algorithms, of course, go right ahead.

One final suggestion: [url=http://java.sun.com/docs/books/tutorial/java/generics/index.html]learn about generics, because they'll make your code way, way simpler, easier to correct, and more generally useful. Instead of having to write code for ints, code for Strings, code for doubles, you can write code for "whatevers" and your class will magically work with anything from ints to ExtremelyComplexObjects.

-----------------------------------
copthesaint
Thu Sep 30, 2010 6:47 pm

RE:Instance Class
-----------------------------------
Not trying to bother anyone by bumping this... lol But DemonWasp, do you mine posting a simple example of generics? :p I kinda abandoned working on it for a long while :D but now that I have grade 12 programing class soon, I want to get even further ahead of the game! :). If anyone else has a relatively simple and also Very complex Uses of generics "helps me learn looking though code faster" Then it would be really appreciated if you posted it.

-----------------------------------
[Gandalf]
Fri Oct 01, 2010 9:14 am

RE:Instance Class
-----------------------------------
He posted a link to the official Java tutorial on generics in his last post:
http://java.sun.com/docs/books/tutorial/java/generics/index.html

There are plenty of relatively simple examples on how to use generics there.  If you have a more specific question, create a new thread in the help section. :)

-----------------------------------
wtd
Fri Oct 01, 2010 4:58 pm

RE:Instance Class
-----------------------------------
The [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java]Introduction to Java deals specifically with [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java#Generics]generics.

-----------------------------------
copthesaint
Sat Oct 02, 2010 2:13 pm

RE:Instance Class
-----------------------------------
I know, however I was wondering if I could just get some examples from  someone because I hate reading :D. If no one has examples however I will look for myself then :/.
