📄 seqpattern.java
字号:
/*
* @<#>SeqPattern.java version 0.0.1, 1/1/2000
*
* THIS PROGRAM IS FREE SOFTWARE; YOU CAN DISTRIBUTED IT AND/OR
* MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE
* AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.
*
* THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE
* GNU GENERAL PUBLIC LICENSE FOR MORE DETAILS.
*
* Copyright (c) 2000 Wayne State University. All Rights Reserved.
*/
package naplet.itinerary;
import naplet.*;
/**
* <code>SeqPattern</code> class defines a primitive of sequential
* itinerary, along which naplet is passed.
*
* @version 0.0.1, 1/1/2000
* @author C. Xu
*/
public class SeqPattern extends CompositePattern {
public SeqPattern(ItineraryPattern[] itin) {
super(null, itin, null );
}
public SeqPattern(Checkable guard, ItineraryPattern[] itin ) {
super(guard, itin, null);
}
public SeqPattern(ItineraryPattern[] itin, Operable act) {
super(null, itin, act);
}
public SeqPattern(Checkable guard, ItineraryPattern[] itin, Operable act) {
super(guard, itin, act);
}
public SeqPattern(String[] hosts)
throws InvalidItineraryException {
super(null, hosts, null);
}
public SeqPattern(String[] hosts, Operable act)
throws InvalidItineraryException {
super(null, hosts, act);
}
public SeqPattern(Checkable guard, String[] hosts )
throws InvalidItineraryException {
super(guard, hosts, null);
}
public SeqPattern(Checkable guard, String[] hosts, Operable act)
throws InvalidItineraryException {
super(guard, hosts, act);
}
public void go( Naplet nap )
throws java.rmi.RemoteException, UnableDispatchException {
if (iter.hasNext()) {
ItineraryPattern next = iter.next();
// Conditional visit of the sequence
if (guard==null || guard.check(nap) ) {
nap.getItinerary().pushRoute( this );
nap.getItinerary().setRoute( next );
next.go(nap);
} else { // skip the sequence
ItineraryPattern itin = nap.getItinerary().popRoute();
if (itin==null) {
System.out.println("End of itinerary: SeqItineary");
} else {
nap.getItinerary().setRoute( itin );
itin.go(nap);
}
}
} else {
if (action!=null) {
action.operate( nap );
}
// Reset the iterator for repetition over the itineary
iter.reset();
ItineraryPattern itin = nap.getItinerary().popRoute();
if (itin==null) {
System.out.println("End of itinerary: SeqItineary");
} else {
nap.getItinerary().setRoute( itin );
itin.go(nap);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -