Right way to use generics for cellular automatons?

Hi,
i've got a question about using generic types in combination with subclassing (which should be used in a cellular automaton),
In fact there are only 3 classes that are necessary to understand my problem:
- Cell (abstract)
- CellularAutomaton
- SubclassedCell (extends Cell)
These classeses work as follows:
A cellular automaton holds some cell's with respect to the order they were added. The cell itself holds some properties and the most important function in this small "framework". This function is "performCellAction(CellularAutomaton ca)". It retrieves the "neighbor" cells from the given parameter and calculates a new state using these neighbors.
The way i implemented this using generics is:
public class CellularAutomaton<T extends Cell>{
  private List<T> cells;
  public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
  public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
public abstract class Cell [
  public void performCellAction(CellularAutomaton<? extends Cell> ca) {}
public class SubclassedCell extends Cell {
  private String str;
  public void performCellAction(CellularAutomaton<? extends Cell> ca) {
    Cell left = ca.getLeftNeighbor();
    // PROBLEM:
    // How to call left.getStr() here???
    // How can i be sure that ca contains objects of class subclassedCell (or objects of subclasses of subclassedCell) ... and not objects of class cell or another subclasses cell
  public String getStr() {}
}In fact i found "something like a solution", which looks like this:
public class CellularAutomaton<T extends Cell>{
  private List<T> cells;
  public T getLeftNeighbor(T cell) { ... } // gets the left neighbor of the given cell
  public T getRightNeighbor(T cell) { ... } // gets the left neighbor of the given cell
  public void computer() {
    for (T cell: cells) {
      // compiler warning here!!
      cell.performCellAction(this);
public abstract class Cell<T extends Cell<?>> [
  public void performCellAction(CellularAutomaton<T> ca) {}
public class SubclassedCell extends Cell<SubclassedCell> {
  private String str;
  performCellAction(CellularAutomaton<SubclassedCell> ca) {
    SubclassedCell left = ca.getLeftNeighbor();
    left.getStr(); // works here
  public String getStr() {}
}However, even in this "working" solution i get a compiler warning at the method CellularAutomaton->computer():
The warning is Type safety: The method performCellAction(CellularAutomaton) belongs to the raw type Cell. References to generic type Cell<T> should be parametrized and Cell<T extends Cell<?>> also looks very uncommon to me.
Is there a betted way to achieve the goal to access left.getStr() in the performCellAction of the subclassed cell??
Regards,
Niko

I thought of that myself, but if i do this, i get the following error:
The method performCellAction(CellularAutomaton<capture#1-of ?>) in the type Cell<capture#1-of ?> is not applicable for the arguments (CellularAutomaton<T>)

Similar Messages

  • Is it a proper way to use queue for consumer/producer model?

    Hi all,
      I am following the example of consumer/producer model to use the queue to synchronize the following process: The producer is a loop to produce N numbers, I will put every generated number into an array and after every 5 numbers generated, I put the array into the queue and pass it to the consumer. I have to wait the consumer use up the data and it will then remove the element from queue so the producer will get a chance to produce another 5 numbers. Since I set the maximum size of the queue to be ONE, I expect the producer and consumer take turns to produce / consume all five numbers and pass the chance to the other. Here is my code
    when the case box is false, the code will be
    For the first 5 numbers, the produce will generate every thing right and put that into the array, and it will pass the array to the quere so the consumer will get a chance to loop over the array. I except the procude's loop will continue only when the queue is available (i.e. all elements are removed), but it seems that once the consumer start the loop the produce 's loop will continue (so the indicator x+1 and x+2 will show numbers changed). But it is not what I want, I know there must be something wrong but I can't tell what is it.
    Solved!
    Go to Solution.

    dragondriver wrote:
    As you said in 1, the sequency structure enforcing the execution order, that's why I put it there, in this example, to put the issue simple, I replace the complete code with number increase, in the real case, the first +1 and +2 must be executed in that order.
    Mikeporter mentioned:
    1. Get rid of all the sequence structures. None of them are doing anything but enforcing an execution order that would be the same without them.
    So even if you remove the sequence structure, there will be a fixed & defined execution order and that is because LabVIEW follows DATA FLOW MODEL.
    Data Flow Model (specifically in context of LabVIEW): A block diagram node executes when it receives all required inputs. When a node executes, it produces output data and passes the data to the next node in the dataflow path. The movement of data through the nodes determines the execution order of the VIs and functions on the block diagram (Click here for reference).
    Now in your code, just removing the sequence structure will not make sure that the execution order will gonna remain same but you need to do few very small modifications (like pass the error wire through For loop, before it goes to 'Dequeue Element' node).
    Coming to the main topic: is it a proper way to use queue for consumer/producer model?
    The model you're using (and calling it as consumer/producer model) is way too deviated from the original consumer/producer model model.
    dragondriver wrote:
    For the second one, yes, it is my fault to remove that while. I actually start from the example of Producer/Consumer design pattern template, but I didn't pay attention to the while loop in the consumer part.
    While loops (both Producer & Consumer) are the essential part of this architecture and can't be removed. You may want to start your code again using standard template.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

  • Is there any way to use a For Each Loop for each property of an User Defined Type?

    Is there any way to use a For Each Loop for each property of an User Defined Type? That would be very handy!
    Jorge Barbi Martins ([email protected])

    Alas, no, not in VBA.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Right way to use Web Apps on iPhone?

    I'm not sure I'm doing right way using Web Apps on my iPhone.
    Mostly I find the necessary Web Apps. on my Mac.
    And type the url address on iPhone.
    Then, if there is "view Web Apps" icon under the description of the Web apps, click to go and add it to home screen.
    Or if there is no "view Web Apps" icon, just click the url of the Web App name.
    Is this right way to add Web Apps I like?
    Thanks for help!

    When I find a web app I like in Safari I size the screen to what I want my homescreen icon to look like and click the + button. This adds a weblink icon to my homescreen making it easier to access than opening up safari and looking for a bookmarked page.

  • What if I didn't charge my mac all the way before using it for the first time?

    Okay, so I got my Macbook for Christmas this past year (Mid 2011 model) and of course I was screaming my head off with excitement.
    I powered it up, starting using it for a little bit, then plugged it in to keep it going. I didn't charge it all the way to 100%, I think I was using it for about three hours while it was plugged in and up for the first time. That night, however, it did charge all the way and I don't see any problems with my battery, but I wouldn't know if it was operating at full capacity if the capacity I've been using this whole time has been lowered.
    Thanks!

    Ahh.. okay?
    I was just curious because they all say to charge it fully for the first time.. didn't know if this did anything to the battery or not.

  • Best Way to Use iPhoto for Lectures?

    The old utility "iphotowebshare" turns itself off frequently under Mavericks, so I'm forced to look for a better way to do what once worked perfectly.
    Here's my situation:
    I've got a few hundred images in an iPhoto library that I have been using for class lectures.  These images are sorted into nice, discrete albums, each of which is named for a specific day's lecture.  Everything's so well organized in iPhoto, that the thought of moving everything somewhere else makes me cranky.
    Here's what used to work:
    Running in the background (accessed via System Preferences), "iphotowebshare" makes all these albums available via web interface.  I don't have to export the images.  I don't have to remember to click the right buttons to sync different applications.  I don't have multiple versions of my images floating around in different places.
    The only thing I've had to worry about is iPhoto.  I can reorganize, retitle, re-order, annotate, and otherwise mess with my iPhoto images right up to the second that I'm supposed to be in class.  Then I can walk away from my office and expect to find my images available in my classroom, just as I've most recently assembled them in iPhoto.
    "iphotowebshare" seems simply to make my iPhoto Library—as it is, and as it changes—available to a simple web page (that "iphotowebshare" itself builds and makes available on port 8080).
    Only problem, now, as I've mentioned, is that the "iphotowebshare" System Preference keeps turning itself off.
    So, reluctantly, I have to adopt a new method, and a couple of hours with Google has not turned up an alternative that does what "iphotowebshare" has been doing so nicely for years.
    I spent thirty minutes or so messing with the iPhoto-Flickr sync, but found that iPhoto is creating new, duplicate "synced" albums beside the albums I've already created.  Syncing between iPhoto and Flickr requires deliberate button clicking (I know: First World Problems. But I'm confident that I will forget to click the sync and then will find myself in class with an obsolete arrangement of images).
    Any advice?  Simpler the better.

    I'm aware that iphotowebshare is problematic and un-updated.  That is, in fact, the problem.  Because with iphotowebshare, iPhoto works perfectly well as a presentation tool in my circumstances.
    Because my circumstances haven't changed, even if software has, what I'm trying to find is something that does what iphotowebshare does (without intermittently shutting off) or that duplicates the same functionality (which is, basically, to put my iPhoto library on the web, live, without bothering me).
    A secondary app will require deliberate second and third steps, not to mention some extra care about how these images get made available online.
    Besides iPhoto is a "presentation tool" to the extent that it's designed to "present" one's images (via slide shows [with a soundtrack, no less] and printed books, if nothing else).  So, I'm pretty sure I'm not asking for an apple to be an orange, so to speak.  Especially since iphotowebshare has demonstrated iPhoto's functionality in this respect.

  • Correct way of using LayeredPane for animation

    Hi,
    before I post my questions some background info (it has become quite a long story sorry for that, you can skip to the bottom if you want):
    i'm not an expert java programmer so I appologize for any stupid questions or remarks.
    Currently i'm implementing a road traffic simulation. Cars drive over roads, intersections etc. To make the movements/animation look smooth i've used doublebuffering or page flipping (I'm not sure while I used the getBufferStrategy() from a JFrame: strategy = frame.getBufferStrategy(); )
    To add my own JButtons created from .png file I've switched off the RepaintManager by creating a NullRepaintManager. The simulation thread is responsible for calling the repaint function, which is done every few milliseconds after the positions of the cars are updated. These buttons are added to the ContentPane of the frame which is made non-opaque to make the roadnetwork and cars visible (*i don't understand this)
    Btw I've 'borrowed' these ideas from 'developing games in java ' from Brackeen: http://www.brackeen.com/javagamebook/
    The roadnetwork and cars are drawn on the a Graphics2D by calling: (Graphics2D)strategy.getDrawGraphics(); first I draw an image of the roadnetwork to clear the old vehicle positions and then the new positions of the cars are drawn. after that the screen/frame is updated: strategy.show();
    This all works fine.
    The problems start when I want to have a popup JPanel to appear on the screen after I clicked somewhere on the roadnetwork. According to Brackeen this can be done by initializing a JPanel and add it to the LayeredPane of the JFrame and make it visible when needed. This does not work while the JPanel never pop's up and I don't understand why not, because the demo from brackeen works fine. When I add this JPanel to the contentPane it does popup but the buttons are shifted to the right which is not what i want.
    Also I want to add a JMenuBar to the frame, i thought I could simply used: frame.tsetJMenuBar(menuBar);
    however the menubar shows up next to my custom JButtons....
    ====>My Questions:
    What is the correct way to draw smooth animations inJava without slowing down the whole program when quite a large area has to be draw... this seems to happen e.g. in the Java demos: ..\jfc\Java2D
    How can I popup JPanels or internalFrames ontop of the animation?? probably by using the LayeredPane?
    I also want to add a JMenuBar in the normal position.
    Sorry for the long text and questions... but I'm struggling for almost two month with this now (using an increadible number of java books) and haven't solved it yet.
    Any suggestions are welcome Thanks in advance!!
    Rens

    It gets the first address from the pxelinux.0, another one is usually handed down after it boots, but sometimes it reuses it again. 
    Usually what happens on a diskless system is it tries to use the dhcpcd lease from the last diskless workstation (or possibly reuses the same one it gets from pxelinux.0).  But it has enough logic built into that it looks for another unique address for the next diskless workstation. 
    Do you have your pxeclient.cfg/default appended options set correctly to be ip=::::::dhcp? 
    Of course from the diskless wiki:
    label archxx
    kernel archxx/boot/vmlinuz-linux
    append init=/usr/lib/systemd/systemd initrd=archxx/boot/initramfs-linux.img root=/dev/nfs rootfstype=nfs nfsroot=xx.xx.xx.xx:/srv/tftp/archxx,v3,rsize=16384,wsize=16384 ip=::::::dhcp

  • Is this the right way of using Enhancement spots?

    Hi fellow SDN people.
    We are implementing some changes to standard SAP IDOC:s using the new enhancement technique and I just wanted to check with you guys about our approach. Please look at the code below and comment on our solution. Is there a better way of doing this in general? Are we using the BAdI concept wrong?
    ENHANCEMENT 32  Z_IDOC_INPUT_STPPOD.    "active version
    * Data declarations
    DATA:
      con    TYPE REF TO zcl_ex__badi_input_stppod1,
      handle TYPE REF TO z_badi_input_stppod1,
      l_oref TYPE REF TO cx_root,
      e_text TYPE string.
    * Instantiate objects
    CREATE OBJECT con.
    GET BADI handle CONTEXT con.
    TRY.
    *   Call BAdI
        CALL BADI handle->create_pod
          CHANGING
            processing_protocol = t_prox[]
            idoc_contrl         = idoc_contrl
            idoc_data           = idoc_data[].
      CATCH cx_badi_not_implemented INTO l_oref.
        e_text = l_oref->get_text( ).
        MESSAGE e_text TYPE 'E'.
    ENDTRY.
    APPEND LINES OF t_prox TO t_prot.
    LOOP AT t_prot.
      IF t_prot-msgty = 'E'.
        f_stat = 2.
        EXIT.
      ENDIF.
      IF t_prot-msgty = 'W' OR
         t_prot-msgty = 'I'.
        f_stat = 1.
      ENDIF.
    ENDLOOP.
    ENDENHANCEMENT.
    <i></i>

    Hi nirre,
    That's right.....
    In general the thumb rule for this is:"
    The enhancement implementation should be complete, let me clear with this example:
    data:
    begin of xy_12_12,
    x12 type i,
    y12(2) type c,
    end of xy_12_12.
    now if i want to enhance the code via implementing the implicit enhancement spot, that implementation should be complete in itself.i.e
    begin of xy_12_12,
    x12 type i,
    y12(2) type c,
    >>
    data : e12 type i.
    <<<
    end of xy_12_12.
    Hope it will clear the concept.
    regrads,
    Amit

  • Advice/opinions on best way to use Flash for website

    Hi
    I am working on an animation in After Effects (dimensions 1000px x 350px) which will sit in the masthead area of a website. I intend to render from After Effects as a flv (or as uncompressed avi and then convert to flv) and then import this into a mc and export as a swf to be placed in the masthead. However, I would be grateful for some feedback/suggestions on a couple of points...
    My guess is that the final swf of flv will be about 9mb, which is quite hefty. I need the quality to be good and crisp. If you look at the excellent CS5 trailer on the adobe.com home page you will get an idea as to the quality I need. I'm guessing this is a fairly large file yet it plays great with hardly any pre-load. Any ideas how they achieve this? Using Media Server or streaming video isn't an option for me, only bog-standard progressive download.
    One thing I thought was to break the animation down into a number of swfs and load these one after another. It needs to be seamless. Would that work - any ideas?
    Ok,  hope this post isn't too rambling. I'm excited about the project, but I could do with some ideas as how best to get a good looking video or swf to play in the masthead without long preloads etc.
    Thanks in advance.

    It will probably be easier to manage if you make each section a moiveclip by itself,  That way you aren't always manipulating the main timeline to fit in or adjust for changes in each section.  You can either spread them out along the timeline, using frame comands to navigate to the different sections, or you can have them all in one frame and control navigation by controlling the visibility of each section.
    If the frame you mention is to be applied to each section, then having one on the main timeline to cover all would be easier to manage in most cases.

  • Best way to use `checkupdates' for status line

    Hey there,
    I want to have the number of packages for which there exist updates to be indicated in the status bar of dwm. (At the moment I create my status bar via a shell script, not via a C program. Most importantly the script displays at the moment the number of new emails and the date/time.)
    This was my first attempt (other functions and custom colors stripped):
    #!/bin/bash
    pkg(){
    nbr="$(checkupdates | wc -l)"
    echo -en "$nbr"
    xsetroot -name "... $(pkg) | $(date "+%d. %b %H:%M")"
    After the script has been executed it will be launched again after a sleep of two seconds. Now I wonder if it is considered good practice to execute `checkupdates' every few seconds. I guess it is not. What could be the downsides? Problems when invoking pacman in order to update?
    The other way I thought of was to check for updates only every hour via cron and redirecting the number of package updates into a temporary file and reading that file in the status script. But this has a major downside: After updating with pacman, the number of packages to be updated doesn't change until next invocation of the cronjob...
    How would you handle such a notification?
    Edit: Sorry wrong forum. Please move the topic. :-(
    Last edited by ball (2013-08-08 17:48:55)

    #!/bin/bash
    let loops=0
    while true; do
    [[ $(($loops % 150)) -eq 0 ]] && pkg=$(checkupdates | wc -l)
    [[ $(($loops % 30)) -eq 0 ]] && email=...
    xsetroot -name "$pkg | $email"
    loops++
    sleep 2
    done
    This will run checkupdates every 150 times through the loop (every 5 minutes) and do the mail check every 30 (every minute), but print out the latest result from each every time through the loop.  Obviously, the mail part has to be filled in with whatever you use.  This is just to show how to only update at certain intervals rather than wasting processing on something that may not be that dynamic.
    EDIT: for regular use I suppose their should be a check on "loops" to avoid overflow.  At the last line of the loop, for example, add
    [[ $loops -eq 4500 ]] && let loops=0
    Last edited by Trilby (2013-08-08 18:24:58)

  • Question: Best way to use MR for BOS - PIT flight

    Hi all, In august I'm flying to pittsburg from Boston and wanted some advice on making the most of my MR (or whether I should just save my MR for some other use). I've got ~57K MR to play with. Since The flight distance is <650 miles I was thinking avios would be the way to go if I could get a direct US airways flight. I know these exist from the US airways page, but when I search for it on the BA website nothing comes up...does this mean they can't be booked with avios? Do I have any other good options? Jetblue does the flight too, but for more around 16k points each way (and the MR:trueblue ratio is not even 1:1), and delta can do it with layovers for 10k each way. Am I missing anything? Thanks!

    njharlen wrote:
    Hi all, In august I'm flying to pittsburg from Boston and wanted some advice on making the most of my MR (or whether I should just save my MR for some other use). I've got ~57K MR to play with. Since The flight distance is <650 miles I was thinking avios would be the way to go if I could get a direct US airways flight. I know these exist from the US airways page, but when I search for it on the BA website nothing comes up...does this mean they can't be booked with avios? Do I have any other good options? Jetblue does the flight too, but for more around 16k points each way (and the MR:trueblue ratio is not even 1:1), and delta can do it with layovers for 10k each way. Am I missing anything? Thanks!One way?

  • Is there a way to use CC for both my desktop and laptop?

    I need to use CC on my laptop when traveling and then my desktop, when I return. Is there a way to do this without purchasing two subscriptions for the one 'me'?

    waynev29025540 wrote:
    I need to use CC on my laptop when traveling and then my desktop, when I return. Is there a way to do this without purchasing two subscriptions for the one 'me'?
    Assuming your subscription is still current, you are allowed to install Adobe products on two devices - namely a laptop and a desktop.
    Therefore, there is no need to buy two subscriptions.  Just download the Adobe CC cloud APP and sign in using your email address that you used to get the subscription.  The system will recognize you as soon as you are online and the software will be activated on your machines.
    Hope this helps.

  • Any way to use connection for Ethernet if wifi not available?

    Going to place where there is only wired connection. Is there any way I can connect to Internet from my iPad?

    I use a Virgin mobile MiFi which allows upto 5 wireless connections which is basically a Sprint data access for no contract $50.00 /month fee unlimited, lower prices for limited duration/packet charges.
    A major decision when purchasing iPad mini WiFi-only vs Cell enable locked to AT&amp;T (yes I know, but have an iPhone already with them).

  • Right way of using the Battery

    I have read these two links:
    http://www.apple.com/batteries/notebooks.html
    http://www.apple.com/batteries/
    I understand that this machine is meant for portability but I use it as a desktop replacement.
    I just notice that when I plug in the power adapter while using some intensive processes, even when the battery is fully charged, the battery health dropped by 2% after like 6 hours of usage.
    So should I pull out the battery and let the machine hook on to the power solely?

    If you remove the battery then it will drop to 50% CPU ... it's designed to draw power from BOTH the MagSafe supply and the battery under intensive conditions, that's quite normal.

  • Is there a way to use hyperlinks for phone numbers in keynote?

    Hey all,
    does anyone know if it is possibile to export phone numbers as hyperlinks in keynote (export format: pdf), so that my phone directly dials the number if I open the pdf and click on it. In other programs I can use "tel:+countrycodeandphonenumber" instead of the url in the hyperlink setup, but unfortunately that does not seem to work with keynote.
    Best,
    Hanna

    Keynote provides for hyperlinks to slides in the currently used presentation, other Keynote files, web pages and to launch a pre-addressed email message. All other hyperlinks are prevented. Not sure why you would want to use a slide presentation application for such a task during a slide show.

Maybe you are looking for

  • How do I connect my airport extreme to windows 8.1

    how do I connect my airport extreme to windows 8.1

  • Keeping all the songs on my IPOD

    Alright, do you have to have all the songs currently on your IPOD in your itunes music Library on your computer for them to stay on your ipod every time you update? HP   Windows XP  

  • Is it possible to save a copy of Form

    Whenever I open my custom bid form in Adobe Reader it gives me a warning message that says I will not be able to save data entered into the form and if I would like a copy of the Form I need to print it. Is it possible to save a copy of the form (and

  • Which is better: One or multiple iPhoto libraries?

    I recently had a huge scare with my HD crashing and losing about 3500 photos since I had last backed up in Sept 2010 (yes, I take 3000+ photos in 2 months Long story short, my huge iPhoto library was close to 400GBs, and with my iMac HD having only 5

  • Array concept in abap

    I want to know concept of table(array). i want to take name of 5 student from user and display on screen.how can i increment variable.