• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can you sort a class of arrays/collection?

 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basically what I mean is this.

A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate. I.E., if items are stacked behind each other those should be printed first, and then the ones behind it etc. He says that we need to get all of the Z's and place them in sorted order. So if item 1-5 and 8-10 are Z0 then will be placed into the array before 6-7 if they were Z1. They say that we should put them in an array as #'s and sort by the Z until we fill out array of lets say 100 items; however they said that the face #'s will be lost.


So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string... I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face[i].z can I do an array sort based on z?

Or maybe another type of collection based on a class?


Any help would be appreciated, thanks,

~JO

EDIT: It seems like a map might be the way to go, but I'm not sure...
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure you can sort arrays and lists. If you look at the Java API: which is found here you will find a class called Arrays. Arrays has a method called sort(T[] a, Comparator<? super T> c) which does what you want. What you have to do is provide a Comparator, which would look at the Face's z value and compare to determine if if should be before or after another Face. To read up more on Comparators look at the Object Ordering Tutorial: found here
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if you have a List, then the class Collections (also seen in the API mentioned above) does the same sort of work.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shortly, you want to arrange items in order to some property? am i missing something?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate. I.E., if items are stacked behind each other those should be printed first, and then the ones behind it etc. He says that we need to get all of the Z's and place them in sorted order. So if item 1-5 and 8-10 are Z0 then will be placed into the array before 6-7 if they were Z1. They say that we should put them in an array as #'s and sort by the Z until we fill out array of lets say 100 items; however they said that the face #'s will be lost.

So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string... I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?


Jay,

The basic answer to your question is: Yes. There are collections and classes in Java that allow you to sort things pretty much any way you like, the main ordering class being Comparator (java.util.Comparator).

To be honest, I have no idea what all this "Z" business is about. Perhaps it's part of your class and it makes sense to you, or it's some Physics or Chemical standard that I know nothing about, but you've explained it badly.

Tell us what you're trying to sort (or, I suspect, group), in simple terms, and I think we'll be able to help you better.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate. I.E., if items are stacked behind each other those should be printed first, and then the ones behind it etc. He says that we need to get all of the Z's and place them in sorted order. So if item 1-5 and 8-10 are Z0 then will be placed into the array before 6-7 if they were Z1. They say that we should put them in an array as #'s and sort by the Z until we fill out array of lets say 100 items; however they said that the face #'s will be lost.

So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string... I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?


Jay,

The basic answer to your question is: Yes. There are collections and classes in Java that allow you to sort things pretty much any way you like, the main ordering class being Comparator (java.util.Comparator).

To be honest, I have no idea what all this "Z" business is about. Perhaps it's part of your class and it makes sense to you, or it's some Physics or Chemical standard that I know nothing about, but you've explained it badly.

Tell us what you're trying to sort (or, I suspect, group), in simple terms, and I think we'll be able to help you better.

Winston



Sorry, what I meant was the z order, meaning the depth of items, aka if I had one item placed on top of another it would be based on the depth of the item. So lets say item 1 is 3" and item 2(which is in front of item 1) is another 3" which would be a total of 6." These items would be stacked... Lets say item 3 is 1" in it's own place, and item 4 is 5" in it's own spot. The item order would be item 3, 1,4,2. 1",3",5",6"

The "z" is just a # that is being looked at to see what is what. As everyone has said the Comparator looks good, I actually was looking at that before I left to swim, so I'm glad that it's something I can use.

So basically using the info above, if I had Face[1].z, Face[2].z, Face[3].z,Face[4].z I'd want them sorted as Face[3].z, Face[1].z, Face[4].z,Face[2].z


 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string...


Probably a bad idea. Strings make poor substitutes for numbers.

I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?


Yes.

Sorry, what I meant was the z order, meaning the depth of items, aka if I had one item placed on top of another it would be based on the depth of the item. So lets say item 1 is 3" and item 2(which is in front of item 1) is another 3" which would be a total of 6." These items would be stacked... Lets say item 3 is 1" in it's own place, and item 4 is 5" in it's own spot. The item order would be item 3, 1,4,2. 1",3",5",6"


And this is where you lose me. If you sort purely based on the depth, then the order (from what you described above) would be 3, 1, 2, 4 (1", 3", 3", 5"), unless your method has some way of "knowing" that items are stacked. Furthermore, if they are 'stacked', wouldn't you want to treat them as a single item?

Is this some kind of packing algorithm? Because that's what it sounds like.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string...


Probably a bad idea. Strings make poor substitutes for numbers.

I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?


Yes.

Sorry, what I meant was the z order, meaning the depth of items, aka if I had one item placed on top of another it would be based on the depth of the item. So lets say item 1 is 3" and item 2(which is in front of item 1) is another 3" which would be a total of 6." These items would be stacked... Lets say item 3 is 1" in it's own place, and item 4 is 5" in it's own spot. The item order would be item 3, 1,4,2. 1",3",5",6"


And this is where you lose me. If you sort purely based on the depth, then the order (from what you described above) would be 3, 1, 2, 4 (1", 3", 3", 5"), unless your method has some way of "knowing" that items are stacked. Furthermore, if they are 'stacked', wouldn't you want to treat them as a single item?

Is this some kind of packing algorithm? Because that's what it sounds like.

Winston



1. He basically wanted to use the string with the data, he uses VB6, which is very limited on a lot of things, I'm trying to get him over to Java, but since his program is 25 years old and was coded in VB he is trying to maintain it until i have done enough when he can switch over.

2. Okay

3. Basically he wants the items to be sorted based on the depth from the initial Z = 0, which would be the backboard. the items would be displayed in this order so that the ones with the lowest Depth/Z-Order would be printed first, and then the ones in front will be printed last. This is so when we move an item it will move the one with the highest Z-Order I.E., if we had Item 1 with 3" and Item 2 on top of it with 3" the total would be 6" and it would be the one we grab when we try to move the item from the position.

Unless there is another way to figure out which item is on top of another, I haven't really thought too much into it/research on it... I'll check out the bin tho, but this is also for items that aren't the same, I.E., if I have 1 item that intersects ontop of another item just a little bit, I want to be able to grab that first item, not the back item(s).
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:1. He basically wanted to use the string with the data, he uses VB6, which is very limited on a lot of things,


Yes, but you're writing this in Java, not in VB; and in Java, Strings that are used instead of a more appropriate type (such as int or Integer) are EVIL.
That doesn't stop you from accepting Strings as input, but convert them to an appropriate type as quickly as possible.
Otherwise you'll end up with a VB program written in "pseudo-Java". Bleccch!.

Unless there is another way to figure out which item is on top of another, I haven't really thought too much into it/research on it...


Then I definitely would. You should probably find out how the current program does it, but it seems like a mighty odd set-up to me. That would suggest that each piece of inventory (or whatever it is) "knows" its own position on a shelf, which would further suggest that it has to be updated each time it's 'moved'.

It's possible that a rudimentary algorithm could be implemented as a Stack (see java.util.Stack) or Deque, where the top item is simply pop()ed off, but again, it seems a bit odd. You might want to think about a Shelf class (if that's in fact what you're trying to model), but it definitely sounds like you need to get more detail about the procedure before you continue.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:1. He basically wanted to use the string with the data, he uses VB6, which is very limited on a lot of things,


Yes, but you're writing this in Java, not in VB; and in Java, Strings that are used instead of a more appropriate type (such as int or Integer) are EVIL.
That doesn't stop you from accepting Strings as input, but convert them to an appropriate type as quickly as possible.
Otherwise you'll end up with a VB program written in "pseudo-Java". Bleccch!.

Unless there is another way to figure out which item is on top of another, I haven't really thought too much into it/research on it...


Then I definitely would. You should probably find out how the current program does it, but it seems like a mighty odd set-up to me. That would suggest that each piece of inventory (or whatever it is) "knows" its own position on a shelf, which would further suggest that it has to be updated each time it's 'moved'.

It's possible that a rudimentary algorithm could be implemented as a Stack (see java.util.Stack) or Deque, where the top item is simply pop()ed off, but again, it seems a bit odd. You might want to think about a Shelf class (if that's in fact what you're trying to model), but it definitely sounds like you need to get more detail about the procedure before you continue.

Winston



1. Yup I know, I keep telling him that Java has way more stuff than VB does, but he was just able to think up tons of algorithms to fit VB, sadly his knowledge is far superior to that of the limited VB Language...

2. Well a stack wouldn't work because some items can overlap which would mean I would need a billion possible stacks if that were to ever happen. This method seems okay, but I think it could be better. As you said it would have to sort itself each and every time which can be a hassle, but there has to be a way to know when something is put ontop of another... Personally I just wanted to give each a #. 0 would be the first, and if any section overlapped the one that was dragged over would be 1,2,3 etc....

For example some things are meant to stay in the back they will stay there, and if one is meant to stay behind another item set it will... I personally don't like it and think if you drag something ontop of another it should stay there, but that's not what's supposed to happen since it's going to be in 3D space.
 
Sheriff
Posts: 28372
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been reading this thread and I have the feeling that something is missing. And that something is, you haven't said what you want to sort. For example you started out by saying

A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate.



Notice how you didn't say what you wanted to sort?

So let's talk about that. What do you want to sort? Do you have objects of an Item class which have a Z property? Or what?
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I've been reading this thread and I have the feeling that something is missing. And that something is, you haven't said what you want to sort. For example you started out by saying

A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate.



Notice how you didn't say what you wanted to sort?

So let's talk about that. What do you want to sort? Do you have objects of an Item class which have a Z property? Or what?



I thought I mentioned it but I will try and explain better, sorry Paul.


I have A class called "Face" with multiple properties, one of which is the depth of the object which would be it's Z-Order(Z coordinate). This is used to sort the items when I read them in and put them out onto the screen. Sometimes some are stacked so they need to be stacked in the right way, so we are using the Z-coordinate to do this. What I am looking for is to be able to sort my array based on the Z, which would be a method, or a field in my Face class. Sometimes things have to stay in the back no matter what, and sometimes items have to stay in the front no matter what. There are lots of things that are weird, so we figured this would be the best solution; having things sorted by their position, so that they will be read and printed out in the order of the array.

I would do I assume

I'm not sure what exactly I would compare. I was looking at a tutorial that was comparing strings. The parameters were String s1, and String s2, and it seemed that was all that was needed to compare each... Would I just make new Instances of my Face class? i.e., "Face face1" and do "Face face2?"
 
Paul Clapham
Sheriff
Posts: 28372
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's all completely wrong.

Well, not completely wrong. The part where you create a Comparator is right. But you don't call the comparator yourself, you just pass it to the Arrays.sort() method and let the sorting call the comparator. Why don't you have a look at this tutorial which explains it a lot more professionally than I could?
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:No, that's all completely wrong.

Well, not completely wrong. The part where you create a Comparator is right. But you don't call the comparator yourself, you just pass it to the Arrays.sort() method and let the sorting call the comparator. Why don't you have a look at this tutorial which explains it a lot more professionally than I could?



Okay, so it'skind of like this tutorial I was looking at

http://www.cs.fsu.edu/~myers/cop3252/notes/sorting.html

You need to to make your own compare method, and return the value then?




Why exactly is it returning 1 minus the other?

So we couldn't just compare like the code I tried to produce? Are there special instances that we need to make a method and return something, vs just doing the code like I did it? Is it because it's an interface?

Thanks for the help, much appreciated,

~JO
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:I have A class called "Face" with multiple properties, one of which is the depth of the object which would be it's Z-Order(Z coordinate). This is used to sort the items when I read them in and put them out onto the screen. Sometimes some are stacked so they need to be stacked in the right way, so we are using the Z-coordinate to do this.


Perhaps it's just your terminology, but to me "stacking" is putting things on top of each other (which you actually mentioned above), and that, surely, would be a Y-axis value (if Z is depth).
It also bothers me a bit that the algorithm seems to rely on Items "knowing" their position. Are these items individually identifiable (eg, with a barcode), so that you can find them and update them? It seems we're still missing an awful lot of useful information.

What I am looking for is to be able to sort my array based on the Z, which would be a method, or a field in my Face class. Sometimes things have to stay in the back no matter what, and sometimes items have to stay in the front no matter what. There are lots of things that are weird, so we figured this would be the best solution; having things sorted by their position, so that they will be read and printed out in the order of the array.


Fine, but if it truly is a 3D "position", then 3 coordinates are going to be involved, not just one (and I'm not so sure that your values aren't dimensions, or lengths, rather then coordinates). Java already has a 2D coordinate class called Point (java.awt.Point), which is already mutable; but its implementation is horrible, so I'm not sure I'd advise it. It might give you some pointers to defining your own 3D one though, perhaps with Comparators for length, height and width.

I'm not sure what exactly I would compare. I was looking at a tutorial that was comparing strings.


Well DON'T. Everything you've said so far indicates that those z coordinates are numbers, so make them numbers.

As to the (v1 - v2) business, it's simply a standard method for returning a positive value if v1 > v2, a negative value if v1 < v2, and 0 if they're equal, which is exactly the contract for Comparator.compare(). [Edit] I should perhaps add that it only works when v1 and v2 are both guaranteed to be >= 0 (as with a String length), or <= 0.

But as Paul said, we really need to know a bit more about what these things are and a better description of what you're trying to do. Is this inventory? Is it a shelf stacking algorithm, or for stock picking?

Enquiring minds want to know.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:I have A class called "Face" with multiple properties, one of which is the depth of the object which would be it's Z-Order(Z coordinate). This is used to sort the items when I read them in and put them out onto the screen. Sometimes some are stacked so they need to be stacked in the right way, so we are using the Z-coordinate to do this.


Perhaps it's just your terminology, but to me "stacking" is putting things on top of each other (which you actually mentioned above), and that, surely, would be a Y-axis value (if Z is depth).
It also bothers me a bit that the algorithm seems to rely on Items "knowing" their position. Are these items individually identifiable (eg, with a barcode), so that you can find them and update them? It seems we're still missing an awful lot of useful information.

What I am looking for is to be able to sort my array based on the Z, which would be a method, or a field in my Face class. Sometimes things have to stay in the back no matter what, and sometimes items have to stay in the front no matter what. There are lots of things that are weird, so we figured this would be the best solution; having things sorted by their position, so that they will be read and printed out in the order of the array.


Fine, but if it truly is a 3D "position", then 3 coordinates are going to be involved, not just one (and I'm not so sure that your values aren't dimensions, or lengths, rather then coordinates). Java already has a 2D coordinate class called Point (java.awt.Point), which is already mutable; but its implementation is horrible, so I'm not sure I'd advise it. It might give you some pointers to defining your own 3D one though, perhaps with Comparators for length, height and width.

I'm not sure what exactly I would compare. I was looking at a tutorial that was comparing strings.


Well DON'T. Everything you've said so far indicates that those z coordinates are numbers, so make them numbers.

As to the (v1 - v2) business, it's simply a standard method for returning a positive value if v1 > v2, a negative value if v1 < v2, and 0 if they're equal, which is exactly the contract for Comparator.compare(). [Edit] I should perhaps add that it only works when v1 and v2 are both guaranteed to be >= 0 (as with a String length), or <= 0.

But as Paul said, we really need to know a bit more about what these things are and a better description of what you're trying to do. Is this inventory? Is it a shelf stacking algorithm, or for stock picking?

Enquiring minds want to know.

Winston



1. Yeah stacking one in front of the other. If you look at an actual 3D chart then I would assume it would be the Y(as Z does up and down), but we are looking at it as a front view X,Y and the Z is just the Depth. I'm not too fond of it either, but it seems this is what is needed to do. Some things need to stay in the back, lets say a sign, and somethings need to stay in front lets say a door. where items will be placed in back of the door. These items all have UPC, SKU, etc codes, to identify each, but they don't change. The only position the items need to know is if one is behind or in front of another. I personally didn't think it mattered, but sometimes things have to always stay in back, or in front.

Basically if one item is dragged over another it will ask to be put into a stack, when that happened the one on top will have to be identified as such, and the one behind it will be identified as the one behind it. Originally the one in back was to always stay in the back, so if you moved it left and right it would stay behind the one, but I personally think that's stupid and people will want to drag items over one another, not have to worry about items staying behind each other.

2. I guess we could call it a "3D position" even though we aren't looking at it in 3D( for now). I know about Point, and I use to it grab each rectangle, or use the rectangle.contains, but that only works for the front most item right? Noob question, but I've heard the term before, but what exactly does "Mutable" mean? 3D point might be interesting, but height and width doesn't really affect it, just what happens when 1 item crosses over another.

3. No you don't :p... I was just checking out tutorials, couldn't really find anything on using a class's method or field, I know I wouldn't use Strings :P.

It's a shelf stocking algorithm to show that some items, when the file is read, will put the data behind or in front of what is needed. Also when adding from a list that if the item is supposed to go in back, it will stay there, and if it's supposed to go in front, it will also stay there.

Sorry if I'm not being more specific, I'm not sure what else I need to add...
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Phew. A lot to answer here:

Jay Orsaw wrote:1. Yeah stacking one in front of the other.


OK, well might I suggest you come up with another term, particularly if your algorithm has to deal with height (which it sounds like it does) - 'blocking' or 'covering' seem like possibilities.

If you look at an actual 3D chart then I would assume it would be the Y(as Z does up and down), but we are looking at it as a front view X,Y and the Z is just the Depth. I'm not too fond of it either, but it seems this is what is needed to do.


Actually, if I was looking at a 3D chart of a stock shelf, I'd expect it to be projected from the front, so z seems perfectly reasonable to me for depth.

Some things need to stay in the back, lets say a sign, and somethings need to stay in front lets say a door.


??? So you're including everything? To me, a sign would be part of the backboard, wouldn't it? Or is it part of your inventory? It certainly doesn't seem like you'd have much depth to worry about. And you've really lost me with a door, unless this is DIY stuff.

These items all have UPC, SKU, etc codes, to identify each, but they don't change.


Well, thank God for small mercies.

The only position the items need to know is if one is behind or in front of another. I personally didn't think it mattered, but sometimes things have to always stay in back, or in front.


And this seems to me an important fact. What are the rules for those?

Basically if one item is dragged over another it will ask to be put into a stack


Again, I suspect, another important action. What do you mean by "dragged over"?

when that happened the one on top will have to be identified as such


And now you're using 'on top', which suggests that this is not simply a "front-to-back" algorithm.

Originally the one in back was to always stay in the back, so if you moved it left and right it would stay behind the one, but I personally think that's stupid and people will want to drag items over one another, not have to worry about items staying behind each other.


Sorry, you've totally lost me here.

Sorry if I'm not being more specific, I'm not sure what else I need to add...


I think you need to describe what it is you're trying to do. Right now, all we have is a bunch of terminology that is difficult to follow to an implementation that we (or at least I) don't understand.

Most packing algorithms assume:
(a) Some uniformity in the things you're trying to pack.
(b) Some method of selection (eg, "topmost; furthest forward").
(c) Some sort of "box" that fits around the items being stocked (a bit like the 'rectangle' that fits around a GUI item, but in 3D). If you know that, you can find the "centre", which makes working out (b) a lot easier.
But from what you've described so far, your "items" include all sorts of things like signs and doors.

Simple explanation please. And explain the process, NOT the implementation. Some idea of what these items are would also be useful. I've spent more than 15 years on inventory systems, so I suspect I could help; but your explanation isn't helping. Once again: back up, and explain the basic process.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:Phew. A lot to answer here:

OK, well might I suggest you come up with another term, particularly if your algorithm has to deal with height (which it sounds like it does) - 'blocking' or 'covering' seem like possibilities.


I guess I'll use dragged over, or over....

Actually, if I was looking at a 3D chart of a stock shelf, I'd expect it to be projected from the front, so z seems perfectly reasonable to me for depth.


yup

??? So you're including everything? To me, a sign would be part of the backboard, wouldn't it? Or is it part of your inventory? It certainly doesn't seem like you'd have much depth to worry about. And you've really lost me with a door, unless this is DIY stuff.


Yup, everything... Some things have to stay in the back, some in the front.. Like a freezer door, you would put the items behind it, and yest it's DIY for the people trying to create it.

Well, thank God for small mercies.





And this seems to me an important fact. What are the rules for those?


Like I said signs, doors, etc, they will be handled later.


Again, I suspect, another important action. What do you mean by "dragged over"?



The way we thought to order the Z-Order would be only if one item was dragged over the first item, and it would ask if the items want to be stacked, or else it would put it back it it's original spot. Once you click yes to stack the first item would be the first item behind it, with a Z-Order of lets say 3, and in front of it will be the next item with a Z-order of lets say 5....


And now you're using 'on top', which suggests that this is not simply a "front-to-back" algorithm.



Sorry there is no top, if I say that I mean front.


Sorry, you've totally lost me here.



Nvm this part it has nothing to do with anything anymore.

Sorry if I'm not being more specific, I'm not sure what else I need to add...


I think you need to describe what it is you're trying to do. Right now, all we have is a bunch of terminology that is difficult to follow to an implementation that we (or at least I) don't understand.

Most packing algorithms assume:
(a) Some uniformity in the things you're trying to pack.
(b) Some method of selection (eg, "topmost; furthest forward").
(c) Some sort of "box" that fits around the items being stocked (a bit like the 'rectangle' that fits around a GUI item, but in 3D). If you know that, you can find the "centre", which makes working out (b) a lot easier.
But from what you've described so far, your "items" include all sorts of things like signs and doors.

Simple explanation please. And explain the process, NOT the implementation. Some idea of what these items are would also be useful. I've spent more than 15 years on inventory systems, so I suspect I could help; but your explanation isn't helping. Once again: back up, and explain the basic process.

Winston




Idk why, but I guess my explanation still makes no sense.... What would you do if you had 2 items 1 behind the other? How would you identify them? Make sure that you're grabbing the front most item? Print them out in onto a plan, in some order that the back most item is the back most, to the item in the front most etc? These items can be anything, cereal box, soup can, etc. If one crosses over the other it's in the same area and needs to be dealt with as such, imo, or else you could be grabbing the one behind the front one.

In the end though this isn't really why I made this post, but any help is appreciated... Maybe I am doing this wrong, and I want the best possible way to do this... Originally I just wanted to figure out how to work the Comparator....

Maybe i will print out a picture...
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:Idk why, but I guess my explanation still makes no sense.... What would you do if you had 2 items 1 behind the other? How would you identify them? Make sure that you're grabbing the front most item?


As I said above, I'd probably implement it as a Stack or LIFO queue of some kind, push()ing Items in and pop()ing them out; although a linked list might work just as well. The nice thing about that is that Items don't need to know anything about "where" they are; it's inherent in their position in the Stack.

The problem seems to be in all the other rules you have, which I'm still not clear about, like Items being 'above' others and this 'crossing over' business.

Maybe i will print out a picture...


That might be a very good idea.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:Idk why, but I guess my explanation still makes no sense.... What would you do if you had 2 items 1 behind the other? How would you identify them? Make sure that you're grabbing the front most item?


As I said above, I'd probably implement it as a Stack or LIFO queue of some kind, push()ing Items in and pop()ing them out; although a linked list might work just as well. The nice thing about that is that Items don't need to know anything about "where" they are; it's inherent in their position in the Stack.

The problem seems to be in all the other rules you have, which I'm still not clear about, like Items being 'above' others and this 'crossing over' business.

Maybe i will print out a picture...


That might be a very good idea.

Winston



Well I still have to sort it, so how would I sort it based on a variable? I'm trying to find tutorials online to sorting classes and their elements using the Java.util.Arrays, but nothing really so far...

EDIT: Found this, thanks http://www.mkyong.com/java/java-object-sorting-example-comparable-and-comparator/
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:Well I still have to sort it, so how would I sort it based on a variable? I'm trying to find tutorials online to sorting classes and their elements using the Java.util.Arrays, but nothing really so far...


Here you go.

However, if you implemented a "Shelf" as an array of Stacks (rows?), the way you'd "sort" it (ie, get a list of its Items in either stacking or picking sequence) would consist of going through each row and pop()ing off an Item. The exact ordering (row-at-a-time or "front first") would dictate how you go through your rows.

But the main thing to remember: for each row, "picking order" is pop() sequence, "stacking order" is the reverse.
It's perhaps worth mentioning that a Deque (java.util.Deque) allows you to remove from either the front or the back, which makes things a bit easier.

Winston
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Some of the code I got from the example...

2 things.



The comparator only works when I use "super();" Now I have the Rectangle class(extended) and the serializable/comparator implemented. now what exactly is super doing? Is it calling all 3 classes?


Next for the compare code in my class



Why do I need to wouldn't be easier? They both run the same, and produce the same output.... I understand that it's casting compare to Face, but why if it's already an Instance of Face already....?
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For all of those who said my "Z-Order" didn't make any sense, or w/e other stuff, guess what I found....


http://docs.oracle.com/javase/7/docs/api/java/awt/doc-files/FocusSpec.html#ZOrder

http://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html


Exactly what I needed.......
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:For all of those who said my "Z-Order" didn't make any sense, or w/e other stuff, guess what I found...


And neither of those things have anything to do with what most of us (certainly me) assumed you meant. Why didn't you just tell us that this was a visual pane stacker in your first post?

Winston
 
author & internet detective
Posts: 42105
933
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you found the answer Jay!

I'm going to move this to our GUI forum. I think part of the confusion Winston (and others) had was that they didn't assume a context of AWT.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Jay Orsaw wrote:For all of those who said my "Z-Order" didn't make any sense, or w/e other stuff, guess what I found...


And neither of those things have anything to do with what most of us (certainly me) assumed you meant. Why didn't you just tell us that this was a visual pane stacker in your first post?

Winston




My q was clear, so was the answer, which was 100% was I asked.... I said they stacked, 1000 times. Yo wanted me to tell yo everything I was doing which didn't have any inpt or help at all. I even showed code I was sing to get help.....
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jay Orsaw wrote:My q was clear, so was the answer, which was 100% was I asked.... I said they stacked, 1000 times. Yo wanted me to tell yo everything I was doing which didn't have any inpt or help at all. I even showed code I was sing to get help.....


Which just goes to prove that code is nothing without context. If your question had been clear, you would have got your answer. Anyway, glad you did find it in the end.

Winston
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, for a deeper understanding of Comparator, Comparable and their differences you can check Difference between Comparator and Comparable in Java
 
Marshal
Posts: 80296
434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you write that tutorial yourself? As I said on your other thread, it isn't a good tutorial. Please don't post it again.
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic