HighDots Forums  

Trying to create a meaningful data structure in Java, got problem.

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Trying to create a meaningful data structure in Java, got problem. in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dr.Tulip
 
Posts: n/a

Default Trying to create a meaningful data structure in Java, got problem. - 03-17-2005 , 03:38 PM






Hi there,

I tried to create a meaningful data structure in JavaScript, and I didn't
seem to be able to find the right syntax or perhaps this is not supported:

The only thing I can come up with is not nice but it's working:

EX:

sqldata = new Array(1..n);

or

MaxElement = 12;

sqldata = new Array(Array(1..n1), Array(1..n2), MaxElement) ;

So to subscribe/view MaxElement, I have to do something like this:

sqldata[2]

Instead of:
sqldata.MaxElement


Using enum is not accepted in Javascript. Any one knows a different way I
can try? Using a Class didn't seem to work neither.


Thanks for your suggestion.




Reply With Quote
  #2  
Old   
Aaron Gray
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 03-21-2005 , 11:52 AM






This is what you are probably after.

Prototypical constructor :-

function anObject( a, b, c)
{
this.a = a
this.b = b
this.c = c
}

Call constructor :-

var x = new anObject( 1,2,3)

Get sub object :-

var y = x.a

Hope this helps,

Aaron




Reply With Quote
  #3  
Old   
Aaron Gray
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 03-23-2005 , 03:57 PM



Quote:
: function anObject( a, b, c)
: {
: this.a = a
: this.b = b
: this.c = c
: }
Thanks Aaron, I tried this method before but I missed using the "this."
It's
very important.

Yes it works great.
Hi,

Heres some more tips...

You can also do object oriented programming using the same prototypical
constructor technique :-

function anObject
{
this.aMember = 0;
this.aMethod = function ()
{
++aMember;
}
}

There is also an "open object" 'with' statement, which works something like
this :-

with x
{
a = 3
b = 2
c = 1
}

It does not need the 'this' statement

A variation on the for statement :-

for ( y in x)
{ ... y ... }

This iterates through object members.

But that does not work on Array's, use the normal C for statement form for
iterating arrays :-

var anArray = new Array(10);

for( i = 0; i < 10; ++i)
{ ... anArray[i] = i; ... }

All in all JavaScript is quite powerful

Have fun,

Aaron




Reply With Quote
  #4  
Old   
Aaron Gray
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 03-24-2005 , 10:32 AM



The dreaded Northwind database rearing its ugly head again. Took me a while
to workout what you are upto The animated eclipse gif confused me thought
you maybe generating that in Java but then saw the URL.

So you can query ADO using ISAPI, I see.

Interesting,

Aaron





Reply With Quote
  #5  
Old   
Tom Mountney
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 07-16-2005 , 08:10 PM



Don't know if you have a solution yet...

From my experience using a class is the way to define a data structure.

Here is a simple example (nothing fancy for sure - certainly needs
improvement especially managing the vector declaration) that creates 3 data
structures and adds them to a vector. Then it searches the vector for a
match.

import java.util.*;

/**
* vec.java
*/
public class vec {

Vector x = new Vector();

public vec(){
//add some data structures to the vector
abc aBC = new abc();
aBC.name = "Me";
aBC.place = "Here";
x.add(aBC);
abc xYZ = new abc();
xYZ.name = "Too Much";
xYZ.place = "Much";
x.add(xYZ);
abc dEF = new abc();
dEF.name = "Far Out";
dEF.place = "There";
x.add(dEF);

//clean up a little
aBC = null;
xYZ = null;
dEF = null;

/* get a value from the vector...*/
abc z = getItem("Me");
if (z != null) {
System.out.println(z.name + " " + z.place);
} else {
System.out.println("No Match");
}
z = null;

/* get a value from the vector - doesn't exist!!...*/
abc y = getItem("Mee");
if (y != null){
System.out.println(z.name + " " + z.place);
}else{
System.out.println("No Match");
}
}

public abc getItem(String c){
int i;
abc d = null;

for (i = 0; i < x.size();i++){
d = (abc)x.get(i);
if (d.name.equals(c)){
break;
}
}

if (i == x.size()) {
//didn't find match
d = null; // d would have value of last element of vector so
null it
}
return d;
}

// The data structure
private class abc {

String name = new String();
String place = new String();

}


public static void main(String[] args) {

vec y = new vec();
}
}

"Dr.Tulip" <Dr.Tulip (AT) hotmail (DOT) com> wrote

Quote:
Hi there,

I tried to create a meaningful data structure in JavaScript, and I didn't
seem to be able to find the right syntax or perhaps this is not supported:

The only thing I can come up with is not nice but it's working:

EX:

sqldata = new Array(1..n);

or

MaxElement = 12;

sqldata = new Array(Array(1..n1), Array(1..n2), MaxElement) ;

So to subscribe/view MaxElement, I have to do something like this:

sqldata[2]

Instead of:
sqldata.MaxElement


Using enum is not accepted in Javascript. Any one knows a different way I
can try? Using a Class didn't seem to work neither.


Thanks for your suggestion.






Reply With Quote
  #6  
Old   
My Pet Programmer
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 12-20-2007 , 03:55 AM



Try this: Drop this function into your code somewhere.

Array.prototype.MaxElm =
function() {
return this[this.length-1];
}

Then do sqldata.MaxElm();, which will return the last element in the
array. In fact, any array in any page where you have that code.

~A!





Dr.Tulip took the time to say:
Quote:
Hi there,

I tried to create a meaningful data structure in JavaScript, and I didn't
seem to be able to find the right syntax or perhaps this is not supported:

The only thing I can come up with is not nice but it's working:

EX:

sqldata = new Array(1..n);

or

MaxElement = 12;

sqldata = new Array(Array(1..n1), Array(1..n2), MaxElement) ;

So to subscribe/view MaxElement, I have to do something like this:

sqldata[2]

Instead of:
sqldata.MaxElement


Using enum is not accepted in Javascript. Any one knows a different way I
can try? Using a Class didn't seem to work neither.


Thanks for your suggestion.




Reply With Quote
  #7  
Old   
Lew
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 12-20-2007 , 07:18 AM



Dr.Tulip took the time to say:
Quote:
Hi there,

I tried to create a meaningful data structure in JavaScript, and I didn't
seem to be able to find the right syntax or perhaps this is not
supported:
(top-posting corrected)

My Pet Programmer wrote:
Quote:
Try this: Drop this function into your code somewhere.

Array.prototype.MaxElm =
function() {
return this[this.length-1];
}

Then do sqldata.MaxElm();, which will return the last element in the
array. In fact, any array in any page where you have that code.
Why did you post this to a Java newsgroup, let alone one that is nearly unused?

--
Lew


Reply With Quote
  #8  
Old   
My Pet Programmer
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 12-20-2007 , 08:32 PM



I just replied to another message, and didn't realize the Java newsgroup
was cc'd. Apologies, won't happen again.

~A!

Lew took the time to say:
Quote:
Dr.Tulip took the time to say:
Hi there,

I tried to create a meaningful data structure in JavaScript, and I
didn't
seem to be able to find the right syntax or perhaps this is not
supported:

(top-posting corrected)

My Pet Programmer wrote:
Try this: Drop this function into your code somewhere.

Array.prototype.MaxElm =
function() {
return this[this.length-1];
}

Then do sqldata.MaxElm();, which will return the last element in the
array. In fact, any array in any page where you have that code.

Why did you post this to a Java newsgroup, let alone one that is nearly
unused?


Reply With Quote
  #9  
Old   
My Pet Programmer
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 12-21-2007 , 08:15 AM



My Pet Programmer took the time to say:
Quote:
I just replied to another message, and didn't realize the Java newsgroup
was cc'd. Apologies, won't happen again.

~A!

Lew took the time to say:
Dr.Tulip took the time to say:
Hi there,

I tried to create a meaningful data structure in JavaScript, and I
didn't
seem to be able to find the right syntax or perhaps this is not
supported:

(top-posting corrected)

My Pet Programmer wrote:
Try this: Drop this function into your code somewhere.

Array.prototype.MaxElm =
function() {
return this[this.length-1];
}

Then do sqldata.MaxElm();, which will return the last element in the
array. In fact, any array in any page where you have that code.

Why did you post this to a Java newsgroup, let alone one that is
nearly unused?

Just one last reply to let everyone know I'm sorry about the top
posting, haven't been here long.

~A!


Reply With Quote
  #10  
Old   
Lew
 
Posts: n/a

Default Re: Trying to create a meaningful data structure in Java, got problem. - 12-21-2007 , 09:50 AM



My Pet Programmer wrote:
Quote:
My Pet Programmer took the time to say:
I just replied to another message, and didn't realize the Java
newsgroup was cc'd. Apologies, won't happen again.

~A!

Lew took the time to say:
Dr.Tulip took the time to say:
Hi there,

I tried to create a meaningful data structure in JavaScript, and
I didn't
seem to be able to find the right syntax or perhaps this is not
supported:

(top-posting corrected)

My Pet Programmer wrote:
Try this: Drop this function into your code somewhere.

Array.prototype.MaxElm =
function() {
return this[this.length-1];
}

Then do sqldata.MaxElm();, which will return the last element in the
array. In fact, any array in any page where you have that code.

Why did you post this to a Java newsgroup, let alone one that is
nearly unused?

Just one last reply to let everyone know I'm sorry about the top
posting, haven't been here long.
Apologies aren't needed. You just aren't going to get a lot of useful
Javascript advice in a nearly-unused Java newsgroup. So no need to keep
posting superfluous apologies to a Java newsgroup when no one is accusing you
of doing anything wrong. Just go about getting the information you need from
the Javascript newsgroups.

--
Lew


Reply With Quote
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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.