alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (bug573.scala)

This example Scala source code file (bug573.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

after, before, before, dir, dir, dirx, linked, node, node, node0, node0

The Scala bug573.scala source code

package lampion.collections;

object DirX {
  abstract class Dir {
    def reverse : Dir;
  }
  object BEFORE extends Dir {
    def reverse = AFTER;
  }
  object AFTER  extends Dir {
    def reverse = BEFORE;
  }
}

import DirX._;

abstract class Linked {
  type Node <: Node0;
  
  abstract class Node0 {
    self: Node =>
    
  	var next : Node = _;
    var prev : Node = _;
    
    def get(dir : Dir) = if (dir == BEFORE) prev; else next;
    private def set(dir : Dir, node : Node) = 
      if (dir == BEFORE) prev = node; else next = node;

    def link(dir : Dir, node : Node) = {
      assert(get(dir) == null);
      assert(node.get(dir.reverse) == null);
      set(dir, node);
      node.set(dir.reverse, self);
    }

    
    def end(dir : Dir) : Node = {
      if (get(dir) == null) this;
      else get(dir).end(dir);
    }
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala bug573.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.