Inheritance & Sorting Question

Hi guys,
I have created an abstract class Element and then three subclasses; Person, Sportsman and Date. The Person class has the fields such as name, surname, DOB ... The Sportsman class is extended Person class with some more fields and Date naturally has days, months and years. My task is to write a class Sort, which contains a few sorting methods (i.e. quicksort) and is able to sort any Element object.
My original idea was to create an abstract method sort. For that method to work, I have to consider three parameters; an instance field the sort will be performed on, a type of sorting algorithm to use and an order of sorting (ascending/descending). The problem I stumbled upon is how to tell the method which instance variable to use; it could be done with a switch statement, but it seems so rough and, well, ugly.
So I'm just wondering if there is a simpler way to do this. Also, if you have a better idea on how to get started with this, please let me know. (I'm not asking for the code, just for the opinion).
Thanks,
Ted

Thank you both for a quick response.
However, I forgot to mention that the sorting should be done without any help of Java library. Also, the main problem I have seems to be on how to "tell" a method which instance field I have chosen.
Example:
Suppose sort(Element e) is an abstract method. I want to sort all the given surnames in the class Person using quicksort in descending order. The method I had in mind should be something like this:
sort(Element, String, int, int)and the call for the metod with the given arguments would be:
sort(e, surname, 1, -1) {
   Person p;
   if (e instanceof Person) {
      p = (Person)e;
   // rest of the code
}But since the argument surname was a String, how to tell a method sort that the field surname was actually chosen?
If my plan does not makes sense, do tell.
Thanks.

Similar Messages

  • Sorting question over state...

    Hi there,
    Anyone know where you amend the over state / hover of an option in a sorting question ???
    Been looking in the object style manager but can't find it in there...
    Thanks in advance...

    You are talking about the partially transparent grey bar that appears when hovering over an answer in the Sequence type of questions. There is no style that can be customized AFAIK. It is not even changing with the included themes. Same is valid for the connecting lines in matching questions that are always black, color cannot be changed for them neither. It is a pity, would recommend you enter a feature request to be able to customize the color of both the hover bar and those lines.
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    Lilybiri

  • Sorting question xsl

    hi,
    I am sorting a list by category, but now I know that one of the categories should go to the bottom of the list when displayed.
    I tried concatenating some value to it so it would go to the bottom, but it's not working correctly. Any other ideas to achieve this?
    mhoran

    You are talking about the partially transparent grey bar that appears when hovering over an answer in the Sequence type of questions. There is no style that can be customized AFAIK. It is not even changing with the included themes. Same is valid for the connecting lines in matching questions that are always black, color cannot be changed for them neither. It is a pity, would recommend you enter a feature request to be able to customize the color of both the hover bar and those lines.
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    Lilybiri

  • Playlist name sorting question

    First off, sorry if this has been discussed before, I couldn't find it anywhere.
    My question is, is there any way to sort my playlists via a "Sort Name" option or something so that a playlist starting with 'the' (for example, "The Letter Black") will be sorted, in the case of the example, under 'L' instead of 'T'? Thanks in advance.
    Blessings.

    Sorry, there are no controls about the sort order of playlists. They go folders, smart playlists, and regular playlists, with a lexical sort in each.
    However, you don't need to create playlists for individual artists and albums. You can easily get to them by the column browser. To turn it on, click View > Column Browser > Show. Then type "lett" in the search bar and you will be right there.

  • Collections.sort question

    Hi,
    This is my question. I have the following classes
    class A {
         int num = 1;
    class B extends A implements Comparable<B>{
       int count = 0;
       public int compareTo(B b) {
            return count - b.getCount;  
      public void setCount(int count) {
            this.count = count;
      public int getCount() {
             return count;
    }After i put the a couple of the B classes (after setting count) in a LinkedList of type A, i get a problem trying to sort them. The compiler gives me a variable Collections error on the Collections.sort
    Any ideas on how to solve this would be appreciated.
    Thanks

    Are you talking about this A* algorithm? (I've never heard of it before.)
    http://en.wikipedia.org/wiki/A-star_search_algorithm
    The code you have with the "instanceof" test might work. Not sure what the goal is, or how the algorithm works (I didn't read the above link in detail), so I can't say for sure whether it will "work" for what you are doing. Once you sort the "B" objects, what do you need to do with that sublist (i.e., with the bList in your code)?
    I've never used generics, so I don't know much about them. Is it possible to make "A" Comparable, giving a dummy implementation to compareTo (i.e., maybe even just make it always return '0' [all values are equal]), and then have "B" implement Comparable such that B's compareTo will override A's version? I don't know if it is possible (or even desirable)--just a thought.

  • Address book field sort question

    Does anyone know how I can set upp my City field so I can sort by city? When I call customers for appointments I would like to sort by city so I can group all my calls together. Presently I group it in with Last name which does not work well if I want to do a mailing.
    Note to Palm; Why wouldn't Palm have set City field seperately so you can sort by city?
    Post relates to: Tungsten E2

    McAfee will warn you about anything sometimes lol. I've downloaded about 10 different programs and no viruses yet, so you shouldn't need worry. There should be some sort of advanced search tool on that site. You can also try using google. I do apologize the device does not come with that search method natively. I hope you find what you are looking for though through add ons.
    Let me know if you have any further questions and have a nice day.
    Post relates to: Treo 800w (Sprint)

  • Last sorting question Itunes!?

    Hi there,
    I haven't really found the answer i was looking for in this support community. Hopefully someone has the right answer for me. Sorry for the image being Dutch, but i will explain in English.
    The thing i want to do is:
    1. Being able to see a various artists album in one group (1 coverflow). This i know how to do, on the left side of the image you'll see.
    Naam = name or title if you like
    Artiest = artist
    Album-artiest = album artist (by keeping this in format of Various Artists, this keeps the album ''together'' as one cover)
    Album = Album
    On the right side
    Naamsortering = name sorting (obvious blank, since there are multiple titles in this album, otherwise it sorts no more on the artist which i prefer instead of                          title order)
    Artiestsortering = Artistsort (here i copied the artistname, so in the artist list it sort there on alfabetical order) Doesn't work btw see part 2 of my question.
    Albumartiest-sortering = (here again i copied the artistname, so when you view a album it sorts the tracks on artist order, i like that!)
    Albumsortering = albumsort (this is for sorting the album between other albums on alfabetical order)
    So i think i got this end covered. Now for part two.
    2. Search on my Apple TV within artist for example: ''Ultravox'' (see picture above).
    The problem i'm having here is that this artist ''Ultravox'' couldn't be found by the search query of my Apple TV. Why is that? I stated that the Artist is named ''Ultravox'', but never the less it can't be found unless i change the album-artist field into ''Ultravox''. But this looses the keeping the album ''together'' as one cover.
    So could anyone tell me if its possible to maintain the various artist album and still be able to search for an artist in this album on a Apple tv?
    Already many thanks in advance for your time and help

    Ah, that's the same fix as I describe in One album, still too many covers. I've no idea why iTunes does this one either. Funnily enough it seems to happen sometimes when I rename an existing album which is properly grouped so I know the values must be consistent because I've only just changed them, and did so all at the same time.
    tt2

  • Guide Sorting Question

    I just switched to FIOS and couldn't find an answer to this question.
    I noticed that I can select all of the Action movies or Comedies, etc on a particular day, but it doesn't show the time they are showing. I'd like to be able to sort by a theme at the current time and later. Is this possible?
    Thanks

    Hi,
    There is no real good way to do what you want to do.  You can go to menu> search> interest and that will give you shows coming on in the future.  A great way to search is by using your PC and going to www.verizon.com/fiostvcentral and you can do all sorts of searches in there.
    Thanks,
    Frank_VZ
    Frank
    CET/Social Media
    Notice: Content posted by Verizon employees is meant to be informational and does not supersede or change the Verizon Forums User Guidelines or Terms or Service, or your Customer Agreement Terms and Conditions or Plan.

  • Sorting questions; albums together within genres?

    Hi!
    I have some questions concerning the way iTunes sorts my Library.
    I'd like it to sort the classical section on composer, instead of artist. My library is sorted on Genre primary, and perhaps it's impossible to sort only one genre on Genre-Composer-Album . If so, I'll accept that.
    However, this next one should be possible in some way:
    How do I get iTunes to keep tha different albums sorted together in Soundtrack genre? For instance, the Buffy Ultimate Album keeps getting mixed up with Lock Stock and Two smoking barrells album, despite that I've checked "part of a collection" and entered specific CD track numbers for every one of the tracks. I even tried entering "Buffy ultimate soundtrack" into the Grouping field. What does that one do if not keep them together?
    Help please...

    How do I get iTunes to keep tha different albums sorted together in Soundtrack genre?
    I would really like to know the same thing!!!! I have a lot of movies and B'Way soundtracks that I would like to peruse by album title. It seems the ipod only lets me browse by song and I agree, they all get jumbled together.
    I am now in the process of dragging them all into a soundtracks playlist, which is a little better because at least the songs stay in the right order. I would love to be able to drag the album title into the playlist and then go onto the next song list screen from there.
    I am going to suggest it on the feedback page.
    I hope someone can shed some light on what can be done about this.

  • Inheritance architecture question

    Hello,
    I've an architecture question.
    We have different types of users in our system, normal users, company "users", and some others.
    In theory they all extend the normal user. But I've read alot about performance issues using join based inheritance mapping.
    How would you suggest to design this?
    Expected are around 15k normal users, a few hundred company users, and even a few hundred of each other user type.
    Inheritance mapping? Which type?
    No inheritance and append all attributes to one class (and leave these not used by the user-type null)?
    Other ways?
    thanks
    Dirk

    sorry dude, but there is only one way you are going to answer your question: research it. And that means try it out. Create a simple prototype setup where you have your inheritance structure and generate 15k of user data in it - then see what the performance is like with some simple test cases. Your prototype could be promoted to be the basis of the end product if the results or satisfying. If you know what you are doing this should only be a couple of hours of work - very much worth your time because it is going to potentially save you many refactoring hours later on.
    You may also want to experiment with different persistence providers by the way (Hibernate, Toplink, Eclipselink, etc.) - each have their own way to implement the same spec, it may well be that one is more optimal than the other for your specific problem domain.
    Remember: you are looking for a solution where the performance is acceptable - don't waste your time trying to find the solution that has the BEST performance.

  • Sequence sorting question

    Is there a way to sort sequences in the project by panel by the creation date of the clip from which each derives.
    That is, I import a bunch of clips, create subclips from them as sequences (giving them new names),  and put them in a bin.  Now I want to sort that bin by the time at which the original clips were shot.  Is this possible?
    Thanks,
    -mike

    Here's the problem.
    For starters, subclips aren't sequences, so you can't create a subclip "as a sequence".  You can create a subclip and then create a sequence for that subclip, but they are inherently two different things.
    Secondly, the subclip inherits the same date as the clip it came from, so...I don't know if that messes with what you want here.  But sequences don't get dates at all, so that will affect what you want if you do in deed have sequences for each subclip.
    And finally, the ability to sort by date columns was purposefully disabled by Adobe for CC, so if you're on that version, then whatever you're trying to sort, you won't be able to.
    Please let Adobe know you want full sorting abilities returned, ASAP. 
    https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Library sorting question

    I hate that all of my albums are split up when sorted by genre . I have tried 'Album artist' and 'Part of a compilation.'
    All I ask for is how can I sort by Genre, Album, then Track and not Genre, artist, then album?
    -Thanks, Nick
    home built AMD 4200+   Windows XP Pro   Nvidia 6800, 37Gb Raptor, 21" Samsung 204B

    Hi, Nick.
    Have you activated the iTunes Browser display panel?
    If not go to the iTunes View menu > Show Browser option.
    Then go to the iTunes Edit menu > Preferences > Advanced tab > General sub-tab and select Show genre when browsing.
    Now you can select a genre in the Browser and sort the contents of your iTunes Library for that genre by clicking on the Album column heading.
    Is that what you're looking for?

  • Stacked Bar Chart with Multiple Series Sort Question

    Hi,
    Apex version 4.1.1
    I have a stacked bar chart with three separate series, one showing customer effort, another showing project effort and the third showing other effort, summarized by calendar week. The x-axis of the chart is the calendar "week of" date, and the y-axis has a bar for each of the three series. Not every type of effort occurs every week.
    When AnyChart renders the chart, the order of entries on the x-axis seems to be dependent both on which series are present in a given week as well as the "week of" date. Weeks with all three series sort in order by calendar date, followed by weeks where just the 2nd & 3rd series are present, followed by weeks where just the 3rd series is present. See this [url http://tinypic.com/r/b9zdt/6] picture of the chart  noting the "week of" dates. Note that the months go Sep-Oct-Nov-Aug-Oct.
    Is there a way to force AnyChart to sort the x-axis in chronological order regardless of whether there is data for all three series for a given week? I have looked through the AnyChart XML reference but cannot find a way to do this.
    Incidentally, I can solve the sorting problem by combining all three series into a single query:
    select
      null as link,
      week_of as label,
      sum(customer_effort) as "Customer Effort",
      sum(project_effort) as "Project Effort",
      sum(other_effort) as "Training, Admin and Other Effort"
    from ...But if I do this, I cannot figure out how to have each bar on a given week link to a different detail page, e.g., if I click on a bar representing customer effort I want to link to one page, but if I click on a bar representing project effort, I want to link to a different page. I have had a look at the [url http://apex.oracle.com/pls/apex/f?p=36648:59:1570983160946101::NO:::] chart examples  posted on apex.oracle.com, but cannot figure out how to apply to multiple series in a single query.
    Thanks,
    Mike

    Thanks, Jeff. I did try this but for whatever reason it doesn't make a difference. I think it is because if there's no data for a given series for a certain week, there is no entry in the data set that is sent to AnyChart.
    I was able to get around the issue by "filling in" the missing weeks from each data series. To generate the list of "Week Of" dates for a given date range, I used this code:
    select
         trunc (each_day) as week_of,
         0 as effort
    from (
         select
              (to_date(:p920_start_date,:app_date_format) + 2 - to_char(to_date(:p920_start_date,:app_date_format),'D') - 1) + level each_day
         from dual
         connect by level <= to_date(:p920_end_date,:app_date_format) - to_date(:p920_start_date,:app_date_format) + 1
    where
         to_char (each_day, 'D') = '2'This creates an effort entry of 0 for each week within the date range; I use the Monday date of a week as the "Week Of" date. I then union this with my actual data and summarize by week and viola, I get the weeks in order. This also has the benefit of showing a week for which there are no entries in any of the three series.
    Thanks for taking a look at this.
    Mike

  • Complex string pattern match/sort question for mapping data - Exchange Enable mailbox use case

    Hi,  Im trying to do a runbook to Enable mailbox for a user.  Our Exchange Admin uses a rule/formula to allocate the mailbox database based on users first name and this is what I am having difficulty replicating in Orchestrator to add the correct
    data in the Database property of Enable Mailbox activity.
    The Rule exchange uses, takes up to the first 3 chars of forename and based on an alphabetic sort, it will allocate to a particular mailbox db (we have a quite large Exchange Org with 20k users so hes tried to allocate about 500 users per mailboxDB).  so
    for example User Forename A-ALI = DB1, ALL-ANG = DB2, ANH-ANY=DB3,AO-BER=DB4 etc etc.
    So I was hoping someone could advise of some string comparison activities native in Orchestrator or maybe done as last resort in powershell (as I'm not great in powershell) to provide a map of the published data for forname to appropriate mailbox matrix.
    Any help on this would be much appreciated...
    Cheers

    You could use the built in Mid function [Mid(‘Return subset from this string’,1,3)] to get the first three letters of their name and honestly I would send
    this to the Run .Net Script activity using powershell myself and do a select case to get it to publish to the database the name of the database server.
    I am all for using  built in activities to do things in Orchestrator but you are going to quickly find that you need to have good powershell scripting skills to extend the tools beyond the capabilities of the built in activities.
    Vaughn

  • SmartAlbum Sort Question

    I'm having an issue with SmartAlbums (iPhoto 5... was in iPhoto 4, too), that is primarily related to film photos I get digitized by the store. On trips, I use 2 cameras - one color and one b&w. When I get the prints and photo cds back, the images on the cds will be the development date, not the date I took the photos, which makes sense as the stores don't know when we took the pictures. (no issue with digital camera as it date/time stamps each picture and they import in the chronological order)
    So, when I import into iPhoto, I try to sort them, and see that they only seem to sort based on date, not time of day within date.
    I use the batch update and change the dates to be the photographed date and the time to be in chronological sequence. Though the Info for each picture will show that they then have the correclty updated chronological sequence, SmartAlbums don't look to use the time stamp when sorting, as the pictures
    Sequnce should be, based on batch updated date and time stamp
    Color picture 1 12/01/06 12:00:10
    Color picture 2 12/01/06 12:00:20
    B&W picture 1 12/01/06 12:00:30
    B&W picture 2 12/01/06 12:00:40
    B&W picture 3 12/01/06 12:00:50
    Color picture 3 12/01/06 12:01:00
    The sequence won't necessarily show this way.
    Does anybody know if iPhoto and/or SmartAlbums are supposed to sort by time within date, too?
    If not, I suppose I'll send this to Apple as a needed enhancement. If the sort should work, do you have any insights into what I'm doing wrong?
    Thanks,
    Mike
    P.S. The ideal solution I try is to drag and drop sort pictures into the correct order in a regular (non-Smart) Album, and batch update the pictures from the first one to the last. The SmartAlbum will only get them to the right date.

    hi,
    Try this.
    Use sy-tabix instead of sy-index.
    For syntax of READ, check
    http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm
    Regards,
    Anirban

Maybe you are looking for