Quantcast

anonymous classes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

anonymous classes

Dennis Jarvis
I'd rather not write a DSL for a Java-based agent framework (GORITE) that I am working with - I'm hoping that Scala can remove much of the grubbiness from the goal specifications, which make use of anonymous classes as shown below:

class Cell extends Performer {

<snip>

    public Cell( String name ) {

        super( name );

        addGoal( new SequenceGoal( MAKE_BATCH, new Goal [] {
        new Goal ( PROCESS_PERCEPT ) {
            @Override
            public States execute( Data d ) {
                Order o = (Order) d.getValue( PERCEPT );
                d.setValue( ORDER, o );
                return Goal.States.PASSED;
            }
        },
        new Goal ( MAKE_METERBOXES0 ) {
            @Override
            public States execute( Data d ) {
                int n = ((Order) d.getValue( ORDER )).required;
                if ( TimeTrigger.isPending( d, "deadline", n*1000 ) )
                    return Goal.States.BLOCKED;
                n = ((Order) d.getValue( ORDER )).required;
                System.err.println(
                    "cell: made "+n+" meterboxes at "+timeStamp() );
                return Goal.States.PASSED;
            }
        },
                                   }));

        addGoal( new Plan( ABORT ) {
            // This goal tells the executor to relinquish its
            // thread as soon as possible. The goal also returns
            // STOPPED so as to "force" focus change, which in
            // this case leads to the execution finishing without
            // pursuing any other goal whatsoever.
            public Goal.States execute(Data d) {
                System.err.println("cell: abort");
                Executor.getDefaultExecutor().stop( true );
                return Goal.States.STOPPED;
            }
        });

 
 <snip>
}

Two questions:
1. SequenceGoal expects an array of (anonymous) goal instances as its second construction argument. How do you do this in Scala?
2. Are there any tricks in Scala to reduce the noise factor in the above code? 

Regards, Dennis

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...