Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: I've a question for our local Java programmers.  (Read 2610 times)

eerr

  • Bay Watcher
    • View Profile
Re: I've a question for our local Java programmers.
« Reply #15 on: November 12, 2010, 04:57:00 am »

That works. Yet another question, I'm trying this at the moment (haven't compiled yet):

int[] keys = bankStore.keySet().toArray(); <- Seems like HashMaps only return Sets and I didn't find any Enum for it.
int slots = 0;
for (int key : keys) {
   slots = slots + slotsBlock(key); <- Should I "this.slotsBlock(key);" or is that fine? I've seem java sources with and without "this." for a class function.
}

Now, for the "for ( : ) {}" format, any way I can directly use it with <key, element> Collections (or any other collection for that matter)? The java tutorial says so, but doesn't give any example.
Quote
"or is that fine? I've seem java sources with and without "this." for a class function."

for the compiler recognizing 'xpow(5,T)'
'this.xpow(5,T)' is assumed.

Quote
"Now, for the "for ( : ) {}" format, any way I can directly use it with <key, element> Collections (or any other collection for that matter)? The java tutorial says so, but doesn't give any example."
Any Class which supports .toIterator() .iterator(), and also arrays.
Bear in mind that you won't have access to the variable i as in array which may be needed.

Quote
"non-static ID entry"
static serial UID is for different versions of your program. Eclipse insists on this for classes that implement serializable. If thats confusing you.

If you are writing objects to and from disk, I can't really know what structure you want, but a hashmap<ID,entry> may cover it?
importing and exporting would be, as far as I know, fragments of a file location. like \dataset2, or \maps\region5 or just statistics45


For java's data-holding objects, each has its own properties. They share alot of methods which aren't really implemented, don't get confused.
all the money is in a few methods at a time.

As for finding the right data type, can you quantify what you are looking for property-wise?

Arraylist is roughly similar to a vector.
HashMap is an instance of AbstractMap.
Quote
"I have a data set I need to manipulate,
it should have a non-static ID entry simply to be able to point at
a specific entry via an ingame command,
since the data itself can be very similar."

X implements serializable
serialID I;
data X;
int
int
double...

And then you serialize it, and write it to disk.
Everything inside has to be serializable too though!
All the basics types, arrays, and most(all?) the data objects implement serializable.
if you implement serializable, which requires a few methods that will
most probably be stubs, Then your class becomes serializable too!
And serializable is only a hop, skip and a jump onto the hard drive.
« Last Edit: November 12, 2010, 04:59:06 am by eerr »
Logged

Soulwynd

  • Bay Watcher
  • -_-
    • View Profile
Re: I've a question for our local Java programmers.
« Reply #16 on: November 12, 2010, 12:54:37 pm »

Writing/reading on the disk wont be hard, I will just use CSV format.

My next question is, since we don't (seem to) have explicit pointers in java, how is that handled? When a function receives an object, is it instanced or does it affect the object?

Here's a fictitious example:

public Randomclass R = new Randomclass();
R.variable = 10;
System.out.println(R.variable); //Prints 10
testFunc(R);
System.out.println(R.variable); //Will it print 10 or 20?
void testFunc(Randomclass a) {
   a.variable = 20;
}

I suppose I could just go ahead and test it, but curious to see if there's a way to pass the pointer or if it's always passed.
Logged

Mondark

  • Bay Watcher
    • View Profile
Re: I've a question for our local Java programmers.
« Reply #17 on: November 12, 2010, 01:09:21 pm »

In short, yes.  Objects (including arrays) are always passed by reference, and basic data types are always passed by value/copy.  In a sense, every reference to an object is a pointer.
Logged
Fefeshnelmargalip

Soulwynd

  • Bay Watcher
  • -_-
    • View Profile
Re: I've a question for our local Java programmers.
« Reply #18 on: November 12, 2010, 02:32:17 pm »

Thanks guys. That covers my java curiosities for now. I'm sure something else might come up soon. =p
Logged

eerr

  • Bay Watcher
    • View Profile
Re: I've a question for our local Java programmers.
« Reply #19 on: November 12, 2010, 04:09:31 pm »

Well, in that case, It may still be advantageous to override the implement and override the default serializer.
« Last Edit: November 12, 2010, 07:54:31 pm by eerr »
Logged
Pages: 1 [2]