text
stringlengths
30
1.67M
<s> package edu . wpi . first . wpilibj . communication ; import com . sun . cldc . jna . Function ; import com . sun . cldc . jna . BlockingFunction ; import com . sun . cldc . jna . Pointer ; import com . sun . cldc . jna . NativeLibrary ; import com . sun . cldc . jna . Structure ; import com . sun . cldc . jna . TaskExecutor ; public final class FRCControl { private static final TaskExecutor taskExecutor = new TaskExecutor ( "<STR_LIT>" ) ; private static final BlockingFunction getCommonControlDataFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction getDynamicControlDataFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction setStatusDataFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction setErrorDataFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction setUserDsLcdDataFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction overrideIOConfigFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final BlockingFunction setNewDataSemFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static final Function observeUserProgramStartingFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; static { getCommonControlDataFn . setTaskExecutor ( taskExecutor ) ; getDynamicControlDataFn . setTaskExecutor ( taskExecutor ) ; setStatusDataFn . setTaskExecutor ( taskExecutor ) ; setErrorDataFn . setTaskExecutor ( taskExecutor ) ; setUserDsLcdDataFn . setTaskExecutor ( taskExecutor ) ; setNewDataSemFn . setTaskExecutor ( taskExecutor ) ; overrideIOConfigFn . setTaskExecutor ( taskExecutor ) ; } public static final int IO_CONFIG_DATA_SIZE = <NUM_LIT:32> ; public static final int USER_CONTROL_DATA_SIZE = <NUM_LIT> - IO_CONFIG_DATA_SIZE ; public static final int USER_STATUS_DATA_SIZE = <NUM_LIT> ; public static final int USER_DS_LCD_DATA_SIZE = <NUM_LIT> ; private FRCControl ( ) { } public static class CachedNativeBuffer { private Pointer buffer ; public Pointer getBufferSized ( int size ) { if ( buffer == null ) { buffer = new Pointer ( size ) ; } if ( size > buffer . getSize ( ) ) { buffer . free ( ) ; buffer = new Pointer ( size ) ; } return buffer ; } public void free ( ) { if ( buffer != null ) { buffer . free ( ) ; buffer = null ; } } } public static abstract class DynamicControlData extends Structure { } private static final CachedNativeBuffer controlDataCache = new CachedNativeBuffer ( ) ; private static final CachedNativeBuffer statusDataCacheHigh = new CachedNativeBuffer ( ) ; private static final CachedNativeBuffer statusDataCacheLow = new CachedNativeBuffer ( ) ; private static final CachedNativeBuffer ioConfigDataCache = new CachedNativeBuffer ( ) ; public static int getCommonControlData ( FRCCommonControlData data , int wait_ms ) { int res = getCommonControlDataFn . call2 ( data . getPointer ( ) , wait_ms ) ; if ( res == <NUM_LIT:0> ) { data . read ( ) ; } return res ; } public static int getDynamicControlData ( byte type , DynamicControlData dynamicData , int maxLength , int wait_ms ) { synchronized ( controlDataCache ) { dynamicData . write ( ) ; int res = getDynamicControlDataFn . call4 ( type , dynamicData . getPointer ( ) , maxLength , wait_ms ) ; if ( res == <NUM_LIT:0> ) dynamicData . read ( ) ; return res ; } } public static int overrideIOConfig ( DynamicControlData ioConfig , int wait_ms ) { synchronized ( ioConfigDataCache ) { ioConfig . write ( ) ; int res = overrideIOConfigFn . call2 ( ioConfig . getPointer ( ) , wait_ms ) ; if ( res == <NUM_LIT:0> ) ioConfig . read ( ) ; return res ; } } public static int setStatusData ( double battery , int dsDigitalOut , int updateNumber , byte [ ] userDataHigh , int userDataHighLength , byte [ ] userDataLow , int userDataLowLength , int wait_ms ) { synchronized ( statusDataCacheHigh ) { Pointer userDataPtrHigh = statusDataCacheHigh . getBufferSized ( userDataHighLength ) ; userDataPtrHigh . setBytes ( <NUM_LIT:0> , userDataHigh , <NUM_LIT:0> , userDataHighLength ) ; Pointer userDataPtrLow = statusDataCacheLow . getBufferSized ( userDataLowLength ) ; userDataPtrLow . setBytes ( <NUM_LIT:0> , userDataLow , <NUM_LIT:0> , userDataLowLength ) ; int res = setStatusDataFn . call8 ( Float . floatToIntBits ( ( float ) battery ) , dsDigitalOut , updateNumber , userDataPtrHigh . address ( ) . toUWord ( ) . toPrimitive ( ) , userDataHighLength , userDataPtrLow . address ( ) . toUWord ( ) . toPrimitive ( ) , userDataLowLength , wait_ms ) ; return res ; } } public static void setErrorData ( byte [ ] bytes , int length , int timeOut ) { Pointer textPtr = new Pointer ( bytes . length ) ; textPtr . setBytes ( <NUM_LIT:0> , bytes , <NUM_LIT:0> , bytes . length ) ; setErrorDataFn . call3 ( textPtr , length , timeOut ) ; textPtr . free ( ) ; } public static void setErrorData ( Pointer textPtr , int length , int timeOut ) { if ( length > textPtr . getSize ( ) ) { throw new IllegalArgumentException ( ) ; } setErrorDataFn . call3 ( textPtr , length , timeOut ) ; } public static void setUserDsLcdData ( byte [ ] bytes , int length , int timeOut ) { Pointer textPtr = new Pointer ( bytes . length ) ; textPtr . setBytes ( <NUM_LIT:0> , bytes , <NUM_LIT:0> , bytes . length ) ; setUserDsLcdDataFn . call3 ( textPtr , length , timeOut ) ; textPtr . free ( ) ; } public static void setNewDataSem ( Semaphore sem ) { if ( sem == null || sem . m_semaphore == null ) { throw new NullPointerException ( "<STR_LIT>" ) ; } setNewDataSemFn . call1 ( sem . m_semaphore ) ; } public static void observeUserProgramStarting ( ) { observeUserProgramStartingFn . call0 ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . communication ; import com . sun . cldc . jna . Function ; import com . sun . cldc . jna . NativeLibrary ; import com . sun . cldc . jna . Pointer ; import com . sun . squawk . platform . posix . LibCUtil ; public class Semaphore { Pointer m_semaphore ; public static final int WAIT_FOREVER = - <NUM_LIT:1> ; static final int SEM_Q_FIFO = <NUM_LIT:0x00> ; static final int SEM_Q_PRIORITY = <NUM_LIT> ; static final int SEM_DELETE_SAFE = <NUM_LIT> ; static final int SEM_INVERSION_SAFE = <NUM_LIT> ; static final int SEM_EVENTSEND_ERR_NOTIFY = <NUM_LIT> ; static final int SEM_INTERRUPTIBLE = <NUM_LIT> ; public static class Options { int value = <NUM_LIT:0> ; public void setPrioritySorted ( boolean priority ) { if ( priority ) value |= SEM_Q_PRIORITY ; else value &= ~ SEM_Q_PRIORITY ; } public void setDeleteSafe ( boolean delSafe ) { if ( delSafe ) value |= SEM_DELETE_SAFE ; else value &= ~ SEM_DELETE_SAFE ; } public void setInversionSafe ( boolean invSafe ) { if ( invSafe ) value |= SEM_INVERSION_SAFE ; else value &= ~ SEM_INVERSION_SAFE ; } public void setErrorNotify ( boolean errNot ) { if ( errNot ) value |= SEM_EVENTSEND_ERR_NOTIFY ; else value &= ~ SEM_EVENTSEND_ERR_NOTIFY ; } public void setInterruptable ( boolean intable ) { if ( intable ) value |= SEM_INTERRUPTIBLE ; else value &= ~ SEM_INTERRUPTIBLE ; } } private static Function semMCreateFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semBCreateFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semCCreateFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semDeleteFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semFlushFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semGiveFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semTakeFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private static Function semTakeBlockingFn = NativeLibrary . getDefaultInstance ( ) . getBlockingFunction ( "<STR_LIT>" ) ; private static Function semCloseFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; private void checkStatus ( int status ) throws SemaphoreException { if ( status != <NUM_LIT:0> ) { throw new SemaphoreException ( LibCUtil . errno ( ) ) ; } } public Semaphore ( Options options ) { m_semaphore = new Pointer ( semMCreateFn . call1 ( options . value ) , <NUM_LIT:0> ) ; } public Semaphore ( Options options , boolean initialState ) { m_semaphore = new Pointer ( semBCreateFn . call2 ( options . value , initialState ? <NUM_LIT:1> : <NUM_LIT:0> ) , <NUM_LIT:0> ) ; } public Semaphore ( Options options , int count ) { m_semaphore = new Pointer ( semCCreateFn . call2 ( options . value , count ) , <NUM_LIT:0> ) ; } public Pointer getPointer ( ) { return m_semaphore ; } public void flush ( ) throws SemaphoreException { checkStatus ( semFlushFn . call1 ( m_semaphore ) ) ; } public void give ( ) throws SemaphoreException { checkStatus ( semGiveFn . call1 ( m_semaphore ) ) ; } public void takeMillis ( int timeout ) throws SemaphoreException { checkStatus ( semTakeBlockingFn . call2 ( m_semaphore , timeout ) ) ; } public void takeForever ( ) throws SemaphoreException { takeMillis ( WAIT_FOREVER ) ; } public boolean tryTake ( ) throws SemaphoreException { int result = semTakeFn . call2 ( m_semaphore , <NUM_LIT:0> ) ; if ( result == <NUM_LIT:0> ) { return true ; } else { int errno = LibCUtil . errno ( ) ; if ( errno == SemaphoreException . S_objLib_OBJ_UNAVAILABLE ) { return false ; } else { throw new SemaphoreException ( errno ) ; } } } public void close ( ) throws SemaphoreException { checkStatus ( semCloseFn . call1 ( m_semaphore ) ) ; } public void free ( ) throws SemaphoreException { checkStatus ( semDeleteFn . call1 ( m_semaphore ) ) ; } } </s>
<s> package edu . wpi . first . wpilibj . communication ; import com . sun . cldc . jna . * ; public class AICalibration { private static final Function getLSBWeightFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; public static long getLSBWeight ( int aiSystemIndex , int channel ) { long lsbWeight = getLSBWeightFn . call3 ( aiSystemIndex , channel , Pointer . NULL ( ) ) & <NUM_LIT> ; return lsbWeight ; } private static final Function getOffsetFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; public static int getOffset ( int aiSystemIndex , int channel ) { int offset = getOffsetFn . call3 ( aiSystemIndex , channel , Pointer . NULL ( ) ) ; return offset ; } } </s>
<s> package edu . wpi . first . wpilibj . communication ; import com . sun . cldc . jna . Structure ; public final class FRCCommonControlData extends Structure { public static final short RESET_BIT = <NUM_LIT> ; public static final short ESTOP_BIT = <NUM_LIT> ; public static final short ENABLED_BIT = <NUM_LIT> ; public static final short AUTONOMOUS_BIT = <NUM_LIT> ; public static final short FMS_ATTATCHED = <NUM_LIT> ; public static final short RESYNCH = <NUM_LIT> ; public static final short CRIO_CHECK_SUM = <NUM_LIT> ; public static final short FPGA_CHECK_SUM = <NUM_LIT> ; public int packetIndex ; public short control ; public boolean enabled ( ) { return ( control & ENABLED_BIT ) == ENABLED_BIT ; } public boolean autonomous ( ) { return ( control & AUTONOMOUS_BIT ) == AUTONOMOUS_BIT ; } public short dsDigitalIn ; public int teamID ; public char dsID_Alliance ; public char dsID_Position ; public byte [ ] stick0Axes = new byte [ <NUM_LIT:6> ] ; public short stick0Buttons ; public byte [ ] stick1Axes = new byte [ <NUM_LIT:6> ] ; public short stick1Buttons ; public byte [ ] stick2Axes = new byte [ <NUM_LIT:6> ] ; public short stick2Buttons ; public byte [ ] stick3Axes = new byte [ <NUM_LIT:6> ] ; public short stick3Buttons ; public short analog1 ; public short analog2 ; public short analog3 ; public short analog4 ; public FRCCommonControlData ( ) { allocateMemory ( ) ; } protected void free ( ) { freeMemory ( ) ; } public void read ( ) { packetIndex = backingNativeMemory . getShort ( <NUM_LIT:0> ) & <NUM_LIT> ; control = ( short ) ( backingNativeMemory . getByte ( <NUM_LIT:2> ) & <NUM_LIT> ) ; dsDigitalIn = ( short ) ( backingNativeMemory . getByte ( <NUM_LIT:3> ) & <NUM_LIT> ) ; teamID = backingNativeMemory . getShort ( <NUM_LIT:4> ) & <NUM_LIT> ; dsID_Alliance = ( char ) backingNativeMemory . getByte ( <NUM_LIT:6> ) ; dsID_Position = ( char ) backingNativeMemory . getByte ( <NUM_LIT:7> ) ; backingNativeMemory . getBytes ( <NUM_LIT:8> , stick0Axes , <NUM_LIT:0> , <NUM_LIT:6> ) ; stick0Buttons = backingNativeMemory . getShort ( <NUM_LIT> ) ; backingNativeMemory . getBytes ( <NUM_LIT:16> , stick1Axes , <NUM_LIT:0> , <NUM_LIT:6> ) ; stick1Buttons = backingNativeMemory . getShort ( <NUM_LIT> ) ; backingNativeMemory . getBytes ( <NUM_LIT:24> , stick2Axes , <NUM_LIT:0> , <NUM_LIT:6> ) ; stick2Buttons = backingNativeMemory . getShort ( <NUM_LIT:30> ) ; backingNativeMemory . getBytes ( <NUM_LIT:32> , stick3Axes , <NUM_LIT:0> , <NUM_LIT:6> ) ; stick3Buttons = backingNativeMemory . getShort ( <NUM_LIT> ) ; analog1 = backingNativeMemory . getShort ( <NUM_LIT> ) ; analog2 = backingNativeMemory . getShort ( <NUM_LIT> ) ; analog3 = backingNativeMemory . getShort ( <NUM_LIT> ) ; analog4 = backingNativeMemory . getShort ( <NUM_LIT> ) ; } public void write ( ) { throw new IllegalStateException ( "<STR_LIT>" ) ; } public int size ( ) { return <NUM_LIT> ; } } </s>
<s> package edu . wpi . first . wpilibj . communication ; import com . sun . cldc . jna . * ; import com . sun . squawk . VM ; public class BumARioHandle { private static Function bumFn ; private static Function invalidateFn ; static { try { bumFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; invalidateFn = NativeLibrary . getDefaultInstance ( ) . getFunction ( "<STR_LIT>" ) ; } catch ( Exception e ) { bumFn = null ; invalidateFn = null ; throw new RuntimeException ( "<STR_LIT>" ) ; } } public static int bum ( int pStatus ) { return bumFn . call1 ( pStatus ) ; } static { invalidateFn . call0 ( ) ; VM . addShutdownHook ( new Thread ( new Runnable ( ) { public void run ( ) { invalidateFn . call0 ( ) ; } } ) ) ; } } </s>
<s> package edu . wpi . first . wpilibj . communication ; public class SemaphoreException extends Exception { public static final int M_semLib = <NUM_LIT> << <NUM_LIT:16> ; public static final int M_objLib = <NUM_LIT> << <NUM_LIT:16> ; public final static int S_objLib_OBJ_ID_ERROR = ( M_objLib | <NUM_LIT:1> ) ; public final static int S_objLib_OBJ_UNAVAILABLE = ( M_objLib | <NUM_LIT:2> ) ; public final static int S_objLib_OBJ_DELETED = ( M_objLib | <NUM_LIT:3> ) ; public final static int S_objLib_OBJ_TIMEOUT = ( M_objLib | <NUM_LIT:4> ) ; public final static int S_semLib_INVALID_STATE = ( M_semLib | <NUM_LIT> ) ; public final static int S_semLib_INVALID_OPTION = ( M_semLib | <NUM_LIT> ) ; public final static int S_semLib_INVALID_QUEUE_TYPE = ( M_semLib | <NUM_LIT> ) ; public final static int S_semLib_INVALID_OPERATION = ( M_semLib | <NUM_LIT> ) ; public final static int S_semLib_INVALID_INITIAL_COUNT = ( M_semLib | <NUM_LIT> ) ; public final static int S_semLib_COUNT_OVERFLOW = ( M_semLib | <NUM_LIT> ) ; public SemaphoreException ( int status ) { super ( lookUpCode ( status ) ) ; } private static String lookUpCode ( int status ) { switch ( status ) { case S_objLib_OBJ_ID_ERROR : return "<STR_LIT>" ; case S_objLib_OBJ_UNAVAILABLE : return "<STR_LIT>" ; case S_objLib_OBJ_DELETED : return "<STR_LIT>" ; case S_objLib_OBJ_TIMEOUT : return "<STR_LIT>" ; case S_semLib_INVALID_STATE : return "<STR_LIT>" ; case S_semLib_INVALID_OPTION : return "<STR_LIT>" ; case S_semLib_INVALID_QUEUE_TYPE : return "<STR_LIT>" ; case S_semLib_INVALID_OPERATION : return "<STR_LIT>" ; case S_semLib_INVALID_INITIAL_COUNT : return "<STR_LIT>" ; case S_semLib_COUNT_OVERFLOW : return "<STR_LIT>" ; default : return "<STR_LIT>" ; } } } </s>
<s> package edu . wpi . first . wpilibj . defaultCode ; import java . lang . * ; import edu . wpi . first . wpilibj . * ; public class MotorControl extends RobotDrive implements PIDOutput { Joystick joystick_ch1 ; CANJaguar frontleft ; CANJaguar frontright ; CANJaguar backleft ; CANJaguar backright ; public MotorControl ( CANJaguar frontleft , CANJaguar frontright , CANJaguar backleft , CANJaguar backright ) { super ( frontleft , backleft , frontright , backright ) ; joystick_ch1 = new Joystick ( <NUM_LIT:1> ) ; this . frontleft = frontleft ; this . frontright = frontright ; this . backleft = backleft ; this . backright = backright ; CANSetup ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; setMaxOutput ( <NUM_LIT> ) ; setInvertedMotor ( MotorType . kFrontLeft , true ) ; setInvertedMotor ( MotorType . kRearLeft , true ) ; } public void CANSetup ( int encoderCodesPerRev , double P , double I , double D ) { try { frontleft . configEncoderCodesPerRev ( encoderCodesPerRev ) ; frontright . configEncoderCodesPerRev ( encoderCodesPerRev ) ; backleft . configEncoderCodesPerRev ( encoderCodesPerRev ) ; backright . configEncoderCodesPerRev ( encoderCodesPerRev ) ; frontleft . setPID ( P , I , D ) ; frontright . setPID ( P , I , D ) ; backleft . setPID ( P , I , D ) ; backright . setPID ( P , I , D ) ; frontleft . enableControl ( ) ; frontright . enableControl ( ) ; backleft . enableControl ( ) ; backright . enableControl ( ) ; } catch ( Exception e ) { } } public void setPID ( double P , double I , double D ) { try { frontleft . setPID ( P , I , D ) ; frontright . setPID ( P , I , D ) ; backleft . setPID ( P , I , D ) ; backright . setPID ( P , I , D ) ; } catch ( Exception e ) { } } public void setPID ( ) { setPID ( DriverStation . getInstance ( ) . getAnalogIn ( <NUM_LIT:1> ) , DriverStation . getInstance ( ) . getAnalogIn ( <NUM_LIT:2> ) , DriverStation . getInstance ( ) . getAnalogIn ( <NUM_LIT:3> ) ) ; } public void pidWrite ( double gyroPIDoutput ) { try { frontleft . setX ( - deadZone ( <NUM_LIT> * joystick_ch1 . getRawAxis ( <NUM_LIT:2> ) , <NUM_LIT> ) + deadZone ( <NUM_LIT> * gyroPIDoutput , <NUM_LIT> ) ) ; frontright . setX ( - deadZone ( <NUM_LIT> * joystick_ch1 . getRawAxis ( <NUM_LIT:2> ) , <NUM_LIT> ) + deadZone ( <NUM_LIT> * gyroPIDoutput , <NUM_LIT> ) ) ; backleft . setX ( - deadZone ( <NUM_LIT> * joystick_ch1 . getRawAxis ( <NUM_LIT:2> ) , <NUM_LIT> ) + deadZone ( <NUM_LIT> * gyroPIDoutput , <NUM_LIT> ) ) ; backright . setX ( - deadZone ( <NUM_LIT> * joystick_ch1 . getRawAxis ( <NUM_LIT:2> ) , <NUM_LIT> ) + deadZone ( <NUM_LIT> * gyroPIDoutput , <NUM_LIT> ) ) ; } catch ( Exception e ) { } } private double deadZone ( double input , double deadzone ) { if ( Math . abs ( input ) < deadzone ) { return <NUM_LIT:0> ; } else { return input ; } } } </s>
<s> package edu . wpi . first . wpilibj . defaultCode ; import edu . wpi . first . wpilibj . AnalogChannel ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . CANJaguar ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . DigitalInput ; import edu . wpi . first . wpilibj . DigitalOutput ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Solenoid ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; public class DefaultRobotA1 extends IterativeRobot { RobotDrive m_robotDrive ; DriverStation ds ; CANJaguar frontLeftJag ; CANJaguar frontRightJag ; CANJaguar rearLeftJag ; CANJaguar rearRightJag ; CANJaguar boomRightJag ; CANJaguar boomLeftJag ; CANJaguar stickRightJag ; CANJaguar stickLeftJag ; int currentPreset = - <NUM_LIT:1> ; int presetStage = <NUM_LIT:0> ; DigitalOutput deployServo ; DigitalInput leftLineSensor ; DigitalInput middleLineSensor ; DigitalInput rightLineSensor ; int [ ] lastThreeLines = new int [ <NUM_LIT:3> ] ; int lineLoops = <NUM_LIT:0> ; boolean hitY = false ; boolean hasStopped = false ; int ignoreLines = <NUM_LIT:0> ; int m_dsPacketsReceivedInCurrentSecond ; Joystick m_rightStick ; static final int NUM_BUTTONS = <NUM_LIT:10> ; boolean [ ] m_buttons = new boolean [ NUM_BUTTONS ] ; static final int NUM_SOLENOIDS = <NUM_LIT:2> ; Solenoid [ ] m_solenoids = new Solenoid [ NUM_SOLENOIDS ] ; static final int UNINITIALIZED_DRIVE = <NUM_LIT:0> ; static final int ARCADE_DRIVE = <NUM_LIT:1> ; static final int TANK_DRIVE = <NUM_LIT:2> ; int m_driveMode ; boolean slow_drive = false ; int m_autoPeriodicLoops ; int m_disabledPeriodicLoops ; int m_telePeriodicLoops ; public DefaultRobotA1 ( ) { System . out . println ( "<STR_LIT>" ) ; ds = DriverStation . getInstance ( ) ; try { frontLeftJag = new CANJaguar ( <NUM_LIT:4> ) ; frontRightJag = new CANJaguar ( <NUM_LIT:5> ) ; rearLeftJag = new CANJaguar ( <NUM_LIT:3> ) ; rearRightJag = new CANJaguar ( <NUM_LIT:2> ) ; } catch ( Exception e ) { } m_robotDrive = new RobotDrive ( frontLeftJag , rearLeftJag , frontRightJag , rearRightJag ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontRight , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearRight , true ) ; deployServo = new DigitalOutput ( <NUM_LIT:1> ) ; leftLineSensor = new DigitalInput ( <NUM_LIT> ) ; middleLineSensor = new DigitalInput ( <NUM_LIT> ) ; rightLineSensor = new DigitalInput ( <NUM_LIT:12> ) ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_rightStick = new Joystick ( <NUM_LIT:1> ) ; int solenoidNum = <NUM_LIT:1> ; for ( solenoidNum = <NUM_LIT:0> ; solenoidNum < NUM_SOLENOIDS ; solenoidNum ++ ) { m_solenoids [ solenoidNum ] = new Solenoid ( solenoidNum + <NUM_LIT:1> ) ; } m_driveMode = ARCADE_DRIVE ; m_autoPeriodicLoops = <NUM_LIT:0> ; m_disabledPeriodicLoops = <NUM_LIT:0> ; m_telePeriodicLoops = <NUM_LIT:0> ; System . out . println ( "<STR_LIT>" ) ; } public void robotInit ( ) { System . out . println ( "<STR_LIT>" ) ; } public void disabledInit ( ) { m_disabledPeriodicLoops = <NUM_LIT:0> ; startSec = ( int ) ( Timer . getUsClock ( ) / <NUM_LIT> ) ; printSec = startSec + <NUM_LIT:1> ; } public void autonomousInit ( ) { m_autoPeriodicLoops = <NUM_LIT:0> ; } public void teleopInit ( ) { m_telePeriodicLoops = <NUM_LIT:0> ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_driveMode = TANK_DRIVE ; } static int printSec ; static int startSec ; public void disabledPeriodic ( ) { updateDashboard ( ) ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] = <NUM_LIT:0> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; lineLoops ++ ; Watchdog . getInstance ( ) . feed ( ) ; m_disabledPeriodicLoops ++ ; lineLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; ignoreLines = <NUM_LIT:0> ; } public void autonomousPeriodic ( ) { updateDashboard ( ) ; Watchdog . getInstance ( ) . feed ( ) ; m_autoPeriodicLoops ++ ; if ( ! hasStopped ) { boolean straightLine = ds . getDigitalIn ( <NUM_LIT:1> ) ; boolean goLeft = ds . getDigitalIn ( <NUM_LIT:2> ) && ! straightLine ; int lineReading = <NUM_LIT:0> ; lineReading += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lineReading += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lineReading += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; System . out . print ( "<STR_LIT>" + m_autoPeriodicLoops + "<STR_LIT>" + lineReading + "<STR_LIT>" ) ; double rightMotors = <NUM_LIT:0> ; double leftMotors = <NUM_LIT:0> ; switch ( lineReading ) { case <NUM_LIT:0> : if ( ! straightLine && ! hitY ) { if ( ! hitY ) { if ( goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } } } else { rightMotors = <NUM_LIT> * ( lastThreeLines [ <NUM_LIT:0> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:1> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:2> ] % <NUM_LIT:10> ) / <NUM_LIT> ; leftMotors = <NUM_LIT> * ( ( lastThreeLines [ <NUM_LIT:0> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:1> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:2> ] / <NUM_LIT:100> ) % <NUM_LIT:10> ) / <NUM_LIT> ; } break ; case <NUM_LIT:1> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:11> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:10> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:100> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : if ( straightLine || hitY ) { hasStopped = true ; System . out . print ( "<STR_LIT>" ) ; } else { if ( goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; } break ; case <NUM_LIT> : if ( ! straightLine ) { if ( goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; } break ; default : break ; } m_robotDrive . tankDrive ( - leftMotors , - rightMotors ) ; System . out . println ( "<STR_LIT>" + leftMotors + "<STR_LIT>" + rightMotors ) ; if ( lineReading > <NUM_LIT:0> ) lastThreeLines [ lineLoops % <NUM_LIT:3> ] = lineReading ; lineLoops ++ ; } else if ( ignoreLines > <NUM_LIT> ) { int lineReading = <NUM_LIT:0> ; lineReading += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lineReading += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lineReading += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; System . out . print ( "<STR_LIT>" + lineReading + "<STR_LIT>" ) ; double rightMotors = <NUM_LIT:0> ; double leftMotors = <NUM_LIT:0> ; switch ( lineReading ) { case <NUM_LIT:0> : leftMotors = <NUM_LIT:1> * ( lastThreeLines [ <NUM_LIT:0> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:1> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:2> ] % <NUM_LIT:10> ) / <NUM_LIT> ; rightMotors = <NUM_LIT:1> * ( ( lastThreeLines [ <NUM_LIT:0> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:1> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:2> ] / <NUM_LIT:100> ) % <NUM_LIT:10> ) / <NUM_LIT> ; break ; case <NUM_LIT:1> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:10> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:11> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:100> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; default : break ; } m_robotDrive . tankDrive ( - leftMotors , - rightMotors ) ; System . out . println ( "<STR_LIT>" + leftMotors + "<STR_LIT>" + rightMotors ) ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] = lineReading ; lineLoops ++ ; } else { ignoreLines ++ ; m_robotDrive . tankDrive ( <NUM_LIT> , - <NUM_LIT> ) ; System . out . println ( "<STR_LIT>" ) ; } } public void teleopPeriodic ( ) { lineLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; ignoreLines = <NUM_LIT:0> ; updateDashboard ( ) ; Watchdog . getInstance ( ) . feed ( ) ; m_telePeriodicLoops ++ ; m_dsPacketsReceivedInCurrentSecond ++ ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < NUM_BUTTONS ; buttonDex ++ ) { m_buttons [ buttonDex ] = m_rightStick . getRawButton ( buttonDex ) ; } m_robotDrive . arcadeDrive ( ( ( m_buttons [ <NUM_LIT:7> ] ) ? - <NUM_LIT:1> : <NUM_LIT:1> ) * m_rightStick . getRawAxis ( <NUM_LIT:2> ) , m_rightStick . getRawAxis ( <NUM_LIT:4> ) / <NUM_LIT:3> * <NUM_LIT:2> , false ) ; if ( currentPreset == - <NUM_LIT:1> ) { int presetButton = <NUM_LIT:0> ; for ( presetButton = <NUM_LIT:0> ; presetButton < NUM_BUTTONS ; presetButton ++ ) { if ( m_buttons [ presetButton ] ) break ; } currentPreset = presetButton ; } else { } } int GetLoopsPerSec ( ) { return <NUM_LIT:20> ; } void updateDashboard ( ) { Dashboard lowDashData = ds . getDashboardPackerLow ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:4> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { int module = <NUM_LIT:6> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addByte ( m_solenoids [ <NUM_LIT:0> ] . getAll ( ) ) ; lowDashData . commit ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . defaultCode ; import com . sun . squawk . util . MathUtils ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . CANJaguar ; import edu . wpi . first . wpilibj . Compressor ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . DigitalInput ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Servo ; import edu . wpi . first . wpilibj . Solenoid ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; public class DefaultRobot extends IterativeRobot { DriverStation ds ; boolean [ ] dsButtons = new boolean [ <NUM_LIT> ] ; RobotDrive m_robotDrive ; CANJaguar frontLeftJag ; CANJaguar frontRightJag ; CANJaguar rearLeftJag ; CANJaguar rearRightJag ; boolean arcadeDrive = true ; boolean override = true ; int lastArcadeButton = <NUM_LIT:0> ; int lastOverButton = <NUM_LIT:0> ; int lastGripperButton = <NUM_LIT:0> ; CANJaguar boomRightJag ; CANJaguar boomLeftJag ; CANJaguar stickRightJag ; CANJaguar stickLeftJag ; CANJaguar wristJag ; Compressor compressor ; int lastStartingButton = <NUM_LIT:0> ; Servo topLeftRoller ; Servo topRightRoller ; Servo bottomLeftRoller ; Servo bottomRightRoller ; DigitalInput gripperButton ; Solenoid gripperSolenoid ; double rollerValue = <NUM_LIT:0> ; double boomAngle = <NUM_LIT> ; double stickAngle = <NUM_LIT> ; double wristAngle = <NUM_LIT> ; double lastTargetHeight = <NUM_LIT:20> ; double lastTargetLength = <NUM_LIT:20> ; double lastTargetWrist = <NUM_LIT:0> ; double currentHeight = <NUM_LIT:20> ; double currentLength = <NUM_LIT:20> ; double targetLength = <NUM_LIT:20> ; double targetHeight = <NUM_LIT:20> ; double targetWrist = <NUM_LIT:0> ; double heightIncrement = <NUM_LIT:0> ; double lengthIncrement = <NUM_LIT:0> ; double wristIncrement = <NUM_LIT:0> ; int middlePeg = <NUM_LIT:0> ; int numIncrements = <NUM_LIT:1> ; int currentPreset = <NUM_LIT:10> ; int presetStage = <NUM_LIT:0> ; boolean boomHitTarget = false ; boolean stickHitTarget = false ; boolean wristHitTarget = false ; int boomStillBuffer = <NUM_LIT:0> ; int stickStillBuffer = <NUM_LIT:0> ; int wristStillBuffer = <NUM_LIT:0> ; boolean presetButton = false ; double lastWristPot = <NUM_LIT> ; int dT = <NUM_LIT:1> ; double integral = <NUM_LIT:0> ; double lastError = <NUM_LIT:0> ; Servo deployServo ; boolean deploy = false ; DigitalInput leftLineSensor ; DigitalInput middleLineSensor ; DigitalInput rightLineSensor ; int [ ] lastThreeLines = new int [ <NUM_LIT:3> ] ; int lineLoops = <NUM_LIT:0> ; boolean hitY = false ; boolean hasStopped = false ; int ignoreLines = <NUM_LIT:0> ; boolean doAutoArmStuff = false ; int yLoops = <NUM_LIT:0> ; int dropLoops = <NUM_LIT:0> ; boolean droppedTube = false ; int backwardsLoops = <NUM_LIT:0> ; int m_dsPacketsReceivedInCurrentSecond ; Joystick m_joystick ; static final int NUM_BUTTONS = <NUM_LIT:10> ; int [ ] m_buttons = new int [ NUM_BUTTONS ] ; int m_autoPeriodicLoops ; int m_disabledPeriodicLoops ; int m_telePeriodicLoops ; public DefaultRobot ( ) { System . out . println ( "<STR_LIT>" ) ; ds = DriverStation . getInstance ( ) ; try { frontLeftJag = new CANJaguar ( <NUM_LIT:4> ) ; frontRightJag = new CANJaguar ( <NUM_LIT:5> ) ; rearLeftJag = new CANJaguar ( <NUM_LIT:3> ) ; rearRightJag = new CANJaguar ( <NUM_LIT:2> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } m_robotDrive = new RobotDrive ( frontLeftJag , rearLeftJag , frontRightJag , rearRightJag ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontRight , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearRight , true ) ; try { boomRightJag = new CANJaguar ( <NUM_LIT:6> , CANJaguar . ControlMode . kPosition ) ; boomLeftJag = new CANJaguar ( <NUM_LIT:9> , CANJaguar . ControlMode . kPosition ) ; stickRightJag = new CANJaguar ( <NUM_LIT:7> , CANJaguar . ControlMode . kPosition ) ; stickLeftJag = new CANJaguar ( <NUM_LIT:8> , CANJaguar . ControlMode . kPosition ) ; wristJag = new CANJaguar ( <NUM_LIT:10> , CANJaguar . ControlMode . kPosition ) ; for ( int setThatMode = <NUM_LIT:0> ; setThatMode < <NUM_LIT:5> ; setThatMode ++ ) { boomRightJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; boomLeftJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; stickRightJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; stickLeftJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; wristJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; Thread . sleep ( <NUM_LIT:100> ) ; if ( boomRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && boomLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && stickLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && stickRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && wristJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition ) ; break ; } boomRightJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; boomLeftJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; stickRightJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; stickLeftJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; wristJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; for ( int setThatMode = <NUM_LIT:0> ; setThatMode < <NUM_LIT:5> ; setThatMode ++ ) { boomRightJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; boomLeftJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; stickRightJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; stickLeftJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; wristJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; Thread . sleep ( <NUM_LIT:100> ) ; if ( boomRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && boomLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && stickLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && stickRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && wristJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus ) break ; } } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } gripperSolenoid = new Solenoid ( <NUM_LIT:1> ) ; compressor = new Compressor ( <NUM_LIT:1> , <NUM_LIT:1> ) ; compressor . start ( ) ; topLeftRoller = new Servo ( <NUM_LIT:2> ) ; topRightRoller = new Servo ( <NUM_LIT:3> ) ; bottomLeftRoller = new Servo ( <NUM_LIT:4> ) ; bottomRightRoller = new Servo ( <NUM_LIT:5> ) ; gripperButton = new DigitalInput ( <NUM_LIT:2> ) ; deployServo = new Servo ( <NUM_LIT:1> ) ; leftLineSensor = new DigitalInput ( <NUM_LIT> ) ; middleLineSensor = new DigitalInput ( <NUM_LIT> ) ; rightLineSensor = new DigitalInput ( <NUM_LIT:12> ) ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_joystick = new Joystick ( <NUM_LIT:1> ) ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < NUM_BUTTONS ; buttonDex ++ ) { m_buttons [ buttonDex ] = ( int ) ( m_joystick . getRawButton ( buttonDex + <NUM_LIT:1> ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } m_autoPeriodicLoops = <NUM_LIT:0> ; m_disabledPeriodicLoops = <NUM_LIT:0> ; m_telePeriodicLoops = <NUM_LIT:0> ; System . out . println ( "<STR_LIT>" ) ; } public void robotInit ( ) { System . out . println ( "<STR_LIT>" ) ; } public void disabledInit ( ) { m_disabledPeriodicLoops = <NUM_LIT:0> ; startSec = ( int ) ( Timer . getUsClock ( ) / <NUM_LIT> ) ; printSec = startSec + <NUM_LIT:1> ; deploy = false ; } public void autonomousInit ( ) { m_autoPeriodicLoops = <NUM_LIT:0> ; try { double bLJP = boomLeftJag . getPosition ( ) ; double sLJP = stickRightJag . getPosition ( ) ; double wJP = wristJag . getPosition ( ) ; boomAngle = ( <NUM_LIT> - ( bLJP * <NUM_LIT> - <NUM_LIT> ) ) ; stickAngle = ( <NUM_LIT> - ( sLJP * <NUM_LIT> - <NUM_LIT> ) ) ; wristAngle = ( <NUM_LIT> - ( wJP * <NUM_LIT> - <NUM_LIT> ) ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double [ ] armCoords = getWristCoordinates ( boomAngle , stickAngle ) ; currentHeight = armCoords [ <NUM_LIT:1> ] ; currentLength = armCoords [ <NUM_LIT:0> ] ; lineLoops = <NUM_LIT:0> ; dropLoops = <NUM_LIT:0> ; yLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; droppedTube = false ; backwardsLoops = <NUM_LIT:0> ; ignoreLines = <NUM_LIT:0> ; currentPreset = <NUM_LIT:10> ; targetHeight = <NUM_LIT:20> ; targetLength = <NUM_LIT> ; lastTargetHeight = Math . max ( currentHeight , <NUM_LIT> ) ; lastTargetLength = currentLength ; lastTargetWrist = wristAngle ; targetWrist = <NUM_LIT:0> ; middlePeg = <NUM_LIT:1> ; int yIncrements = ( int ) Math . abs ( Math . floor ( ( targetHeight - lastTargetHeight ) / <NUM_LIT> ) ) + <NUM_LIT:1> ; int xIncrements = ( int ) Math . abs ( Math . floor ( ( targetLength - lastTargetLength ) / <NUM_LIT:1.0> ) ) + <NUM_LIT:1> ; numIncrements = Math . max ( xIncrements , yIncrements ) ; heightIncrement = ( targetHeight - lastTargetHeight ) / ( double ) numIncrements ; lengthIncrement = ( targetLength - lastTargetLength ) / ( double ) numIncrements ; wristIncrement = ( targetWrist - lastTargetWrist ) / ( double ) numIncrements ; } public void teleopInit ( ) { m_telePeriodicLoops = <NUM_LIT:0> ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; } static int printSec ; static int startSec ; public void disabledPeriodic ( ) { updateDashboard ( ) ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] = <NUM_LIT:0> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; lineLoops ++ ; Watchdog . getInstance ( ) . feed ( ) ; m_disabledPeriodicLoops ++ ; lineLoops = <NUM_LIT:0> ; dropLoops = <NUM_LIT:0> ; yLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; droppedTube = false ; backwardsLoops = <NUM_LIT:0> ; ignoreLines = <NUM_LIT:0> ; deploy = false ; try { float bLJP = ( float ) boomLeftJag . getPosition ( ) ; float sLJP = ( float ) stickRightJag . getPosition ( ) ; float wJP = ( float ) wristJag . getPosition ( ) ; boomAngle = ( <NUM_LIT> - ( bLJP * <NUM_LIT> - <NUM_LIT> ) ) ; stickAngle = ( <NUM_LIT> - ( sLJP * <NUM_LIT> - <NUM_LIT> ) ) ; wristAngle = ( <NUM_LIT> - ( wJP * <NUM_LIT> - <NUM_LIT> ) ) ; double [ ] armCoords = getWristCoordinates ( boomAngle , stickAngle ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double bPot = <NUM_LIT:0> ; double sPot = <NUM_LIT:0> ; double wPot = <NUM_LIT:0> ; try { bPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:2> ) ; sPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:4> ) ; wPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:6> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } public void autonomousPeriodic ( ) { updateDashboard ( ) ; Watchdog . getInstance ( ) . feed ( ) ; m_autoPeriodicLoops ++ ; deployServo . setAngle ( <NUM_LIT> ) ; boolean straightLine = true ; boolean goLeft = false ; boolean doAuto = false ; try { double sPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:4> ) ; double wPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:6> ) ; if ( wPot > <NUM_LIT> * <NUM_LIT> ) doAuto = true ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } if ( doAuto ) { if ( ! ( hasStopped || hitY ) ) { int lineReading = <NUM_LIT:0> ; lineReading += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lineReading += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lineReading += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; double rightMotors = <NUM_LIT:0> ; double leftMotors = <NUM_LIT:0> ; switch ( lineReading ) { case <NUM_LIT:0> : rightMotors = <NUM_LIT> * ( lastThreeLines [ <NUM_LIT:0> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:1> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:2> ] % <NUM_LIT:10> ) / <NUM_LIT> ; leftMotors = <NUM_LIT> * ( Math . floor ( lastThreeLines [ <NUM_LIT:0> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + Math . floor ( lastThreeLines [ <NUM_LIT:1> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + Math . floor ( lastThreeLines [ <NUM_LIT:2> ] / <NUM_LIT:100> ) % <NUM_LIT:10> ) / <NUM_LIT> ; break ; case <NUM_LIT:1> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:11> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:10> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:100> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : if ( straightLine ) { hasStopped = true ; System . out . print ( "<STR_LIT>" ) ; dropLoops = m_autoPeriodicLoops ; } else { if ( ! goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; yLoops = m_autoPeriodicLoops ; } break ; case <NUM_LIT> : if ( ! straightLine ) { if ( ! goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; yLoops = m_autoPeriodicLoops ; } break ; default : break ; } m_robotDrive . tankDrive ( - leftMotors * <NUM_LIT> , - rightMotors * <NUM_LIT> ) ; if ( lineReading > <NUM_LIT:0> ) lastThreeLines [ lineLoops % <NUM_LIT:3> ] = lineReading ; lineLoops ++ ; } else if ( currentPreset == - <NUM_LIT:1> && m_autoPeriodicLoops < dropLoops + <NUM_LIT:10> ) { } else if ( ! droppedTube ) { presetStage = <NUM_LIT:0> ; lastTargetHeight = Math . max ( currentHeight , <NUM_LIT> ) ; lastTargetLength = currentLength ; lastTargetWrist = wristAngle ; targetWrist = <NUM_LIT> ; middlePeg = <NUM_LIT:0> ; targetHeight = currentHeight - <NUM_LIT:6> ; targetLength = currentLength - <NUM_LIT:6> ; gripperSolenoid . set ( true ) ; droppedTube = true ; currentPreset = <NUM_LIT:0> ; int yIncrements = ( int ) Math . abs ( Math . floor ( ( targetHeight - lastTargetHeight ) / <NUM_LIT> ) ) + <NUM_LIT:1> ; int xIncrements = ( int ) Math . abs ( Math . floor ( ( targetLength - lastTargetLength ) / <NUM_LIT:1.0> ) ) + <NUM_LIT:1> ; numIncrements = Math . max ( xIncrements , yIncrements ) ; heightIncrement = ( targetHeight - lastTargetHeight ) / ( double ) numIncrements ; lengthIncrement = ( targetLength - lastTargetLength ) / ( double ) numIncrements ; wristIncrement = ( targetWrist - lastTargetWrist ) / ( double ) numIncrements ; } else if ( currentPreset == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; m_robotDrive . tankDrive ( <NUM_LIT> , <NUM_LIT> ) ; backwardsLoops = m_autoPeriodicLoops ; } else if ( currentPreset == - <NUM_LIT:1> ) { System . out . println ( "<STR_LIT>" ) ; m_robotDrive . tankDrive ( <NUM_LIT> , <NUM_LIT> ) ; } try { double bLJP = boomLeftJag . getPosition ( ) ; double sLJP = stickRightJag . getPosition ( ) ; double wJP = wristJag . getPosition ( ) ; boomAngle = ( <NUM_LIT> - ( bLJP * <NUM_LIT> - <NUM_LIT> ) ) ; stickAngle = ( <NUM_LIT> - ( sLJP * <NUM_LIT> - <NUM_LIT> ) ) ; wristAngle = ( <NUM_LIT> - ( wJP * <NUM_LIT> - <NUM_LIT> ) ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double [ ] armCoords = getWristCoordinates ( boomAngle , stickAngle ) ; currentHeight = armCoords [ <NUM_LIT:1> ] ; currentLength = armCoords [ <NUM_LIT:0> ] ; double [ ] targetAngles = { <NUM_LIT> , <NUM_LIT> } ; double targetWristA = <NUM_LIT> ; if ( currentPreset > - <NUM_LIT:1> ) { if ( ( presetStage + <NUM_LIT:1> ) % numIncrements == <NUM_LIT:0> ) { boolean defaultCase = false ; switch ( currentPreset ) { case <NUM_LIT:10> : targetHeight = ( <NUM_LIT> + <NUM_LIT:8> * middlePeg ) / <NUM_LIT> ; targetLength = <NUM_LIT> ; currentPreset = <NUM_LIT> ; targetWrist = <NUM_LIT> ; break ; case <NUM_LIT> : targetHeight = <NUM_LIT> + <NUM_LIT:8> * middlePeg ; targetLength = <NUM_LIT> ; currentPreset = <NUM_LIT> ; targetWrist = <NUM_LIT> ; break ; case <NUM_LIT:0> : targetHeight = <NUM_LIT:20> ; targetLength = <NUM_LIT> ; targetWrist = <NUM_LIT> ; currentPreset = <NUM_LIT:3> ; break ; case <NUM_LIT:3> : targetHeight = <NUM_LIT:20> ; targetLength = <NUM_LIT> ; targetWrist = <NUM_LIT:0> ; gripperSolenoid . set ( false ) ; currentPreset = <NUM_LIT:31> ; break ; default : currentPreset = - <NUM_LIT:1> ; defaultCase = true ; targetAngles = getArmAngles ( targetLength , targetHeight ) ; targetWristA = targetWrist ; break ; } presetStage = <NUM_LIT:0> ; if ( ! defaultCase ) { lastTargetHeight = currentHeight ; lastTargetLength = currentLength ; lastTargetWrist = wristAngle ; int yIncrements = ( int ) Math . abs ( Math . floor ( ( targetHeight - lastTargetHeight ) / <NUM_LIT> ) ) + <NUM_LIT:1> ; int xIncrements = ( int ) Math . abs ( Math . floor ( ( targetLength - lastTargetLength ) / <NUM_LIT:1.0> ) ) + <NUM_LIT:1> ; numIncrements = Math . max ( xIncrements , yIncrements ) ; heightIncrement = ( targetHeight - lastTargetHeight ) / ( double ) numIncrements ; lengthIncrement = ( targetLength - lastTargetLength ) / ( double ) numIncrements ; wristIncrement = ( targetWrist - lastTargetWrist ) / ( double ) numIncrements ; targetAngles [ <NUM_LIT:0> ] = boomAngle ; targetAngles [ <NUM_LIT:1> ] = stickAngle ; targetWristA = wristAngle ; } } else { presetStage ++ ; double tX = lastTargetLength + lengthIncrement * presetStage ; double tY = lastTargetHeight + heightIncrement * presetStage ; targetWristA = lastTargetWrist + wristIncrement * presetStage ; targetAngles = getArmAngles ( tX , tY ) ; if ( ( presetStage + <NUM_LIT:1> ) % numIncrements == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + targetAngles [ <NUM_LIT:0> ] + "<STR_LIT:U+002CU+0020>" + targetAngles [ <NUM_LIT:1> ] + "<STR_LIT:U+002CU+0020>" + targetWristA ) ; double targetboom = <NUM_LIT:1> - ( targetAngles [ <NUM_LIT:0> ] + <NUM_LIT> ) / <NUM_LIT> ; double targetstick = <NUM_LIT:1> - ( targetAngles [ <NUM_LIT:1> ] + <NUM_LIT> ) / <NUM_LIT> ; double targetwrist = <NUM_LIT:1> - ( targetWristA + <NUM_LIT> ) / <NUM_LIT> ; System . out . println ( "<STR_LIT>" + ( float ) targetboom + "<STR_LIT:U+002CU+0020>" + ( float ) targetstick + "<STR_LIT:U+002CU+0020>" + ( float ) targetwrist ) ; float TboomAngle = ( float ) ( <NUM_LIT> - ( targetboom * <NUM_LIT> - <NUM_LIT> ) ) ; float TstickAngle = ( float ) ( <NUM_LIT> - ( targetstick * <NUM_LIT> - <NUM_LIT> ) ) ; float TwristAngle = ( float ) ( <NUM_LIT> - ( targetwrist * <NUM_LIT> - <NUM_LIT> ) ) ; System . out . println ( "<STR_LIT>" + TboomAngle + "<STR_LIT:U+002CU+0020>" + TstickAngle + "<STR_LIT:U+002CU+0020>" + TwristAngle + "<STR_LIT>" ) ; } } } else { targetAngles = getArmAngles ( targetLength , targetHeight ) ; targetWristA = targetWrist ; } double boomV = <NUM_LIT:0> ; double targetboom = <NUM_LIT:1> - ( targetAngles [ <NUM_LIT:0> ] + <NUM_LIT> ) / <NUM_LIT> ; double boomDiff = <NUM_LIT:0> ; try { if ( boomLeftJag . getPosition ( ) != <NUM_LIT:0> ) boomDiff = targetboom - boomLeftJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double boomGain = <NUM_LIT> ; if ( boomDiff > <NUM_LIT:0> ) boomGain = <NUM_LIT> ; boomV = ( - <NUM_LIT:1> * boomGain * boomDiff ) ; double boomMaxV = <NUM_LIT:9> * <NUM_LIT:1> ; if ( Math . abs ( boomV ) > boomMaxV ) boomV = ( boomV < boomMaxV ) ? - boomMaxV : boomMaxV ; if ( Math . abs ( boomV ) > <NUM_LIT> ) { if ( Math . abs ( boomV ) < <NUM_LIT> ) boomV = ( boomV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else boomV = <NUM_LIT:0> ; try { boomLeftJag . setX ( boomV / <NUM_LIT> ) ; boomRightJag . setX ( boomV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double stickV = <NUM_LIT:0> ; double targetstick = <NUM_LIT:1> - ( targetAngles [ <NUM_LIT:1> ] + <NUM_LIT> ) / <NUM_LIT> ; double stickDiff = <NUM_LIT:0> ; try { if ( stickRightJag . getPosition ( ) != <NUM_LIT:0> ) stickDiff = targetstick - stickRightJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } stickV = <NUM_LIT:1> * ( <NUM_LIT> * stickDiff ) ; if ( Math . abs ( stickV ) > <NUM_LIT:9> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT:9> : <NUM_LIT:9> ; if ( Math . abs ( stickV ) > <NUM_LIT:1.0> ) { if ( Math . abs ( stickV ) < <NUM_LIT> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else stickV = <NUM_LIT:0> ; try { stickLeftJag . setX ( stickV / <NUM_LIT> ) ; stickRightJag . setX ( stickV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double wristV = <NUM_LIT:0> ; double targetwrist = <NUM_LIT:1> - ( targetWristA + <NUM_LIT> ) / <NUM_LIT> ; double wristDiff = <NUM_LIT:0> ; try { if ( wristJag . getPosition ( ) != <NUM_LIT:0> ) wristDiff = targetwrist - wristJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } wristV = - <NUM_LIT:1> * ( <NUM_LIT> * wristDiff ) ; if ( Math . abs ( wristV ) > <NUM_LIT:12> ) wristV = ( wristV < <NUM_LIT:0> ) ? - <NUM_LIT:12> : <NUM_LIT:12> ; if ( Math . abs ( wristV ) > <NUM_LIT> ) { if ( Math . abs ( wristV ) < <NUM_LIT:1.0> ) wristV = ( wristV < <NUM_LIT:0> ) ? - <NUM_LIT:1.0> : <NUM_LIT:1.0> ; } else wristV = <NUM_LIT:0> ; try { wristJag . setX ( wristV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } } public void teleopPeriodic ( ) { Watchdog . getInstance ( ) . feed ( ) ; m_telePeriodicLoops ++ ; m_dsPacketsReceivedInCurrentSecond ++ ; updateDashboard ( ) ; try { double bLJP = boomLeftJag . getPosition ( ) ; double sLJP = stickRightJag . getPosition ( ) ; double wJP = wristJag . getPosition ( ) ; boomAngle = ( <NUM_LIT> - ( bLJP * <NUM_LIT> - <NUM_LIT> ) ) ; stickAngle = ( <NUM_LIT> - ( sLJP * <NUM_LIT> - <NUM_LIT> ) ) ; wristAngle = ( <NUM_LIT> - ( wJP * <NUM_LIT> - <NUM_LIT> ) ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double [ ] armCoords = getWristCoordinates ( boomAngle , stickAngle ) ; currentHeight = armCoords [ <NUM_LIT:1> ] ; currentLength = armCoords [ <NUM_LIT:0> ] ; lastOverButton = m_buttons [ <NUM_LIT:9> ] ; lastArcadeButton = m_buttons [ <NUM_LIT:2> ] ; lastStartingButton = m_buttons [ <NUM_LIT:3> ] ; lastGripperButton = m_buttons [ <NUM_LIT:5> ] ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < NUM_BUTTONS ; buttonDex ++ ) { m_buttons [ buttonDex ] = ( int ) ( m_joystick . getRawButton ( buttonDex + <NUM_LIT:1> ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } if ( m_buttons [ <NUM_LIT:2> ] == <NUM_LIT:1> && lastArcadeButton == <NUM_LIT:0> ) { arcadeDrive = ! arcadeDrive ; } if ( m_buttons [ <NUM_LIT:9> ] == <NUM_LIT:1> && lastOverButton == <NUM_LIT:0> ) { override = ! override ; } if ( m_buttons [ <NUM_LIT:5> ] == <NUM_LIT:1> && lastGripperButton == <NUM_LIT:0> ) { gripperSolenoid . set ( ! gripperSolenoid . get ( ) ) ; } double bPot = <NUM_LIT> * <NUM_LIT> ; double sPot = <NUM_LIT> * <NUM_LIT> ; double wPot = <NUM_LIT> * <NUM_LIT> ; boolean rotateUp = false ; boolean rotateDown = false ; boolean deployment = false ; try { ds . getEnhancedIO ( ) . setLED ( <NUM_LIT:1> , arcadeDrive ) ; ds . getEnhancedIO ( ) . setLED ( <NUM_LIT:2> , ( m_buttons [ <NUM_LIT:6> ] == <NUM_LIT:1> ) ) ; ds . getEnhancedIO ( ) . setLED ( <NUM_LIT:3> , override ) ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < <NUM_LIT> ; buttonDex ++ ) { dsButtons [ buttonDex ] = ! ds . getEnhancedIO ( ) . getDigital ( buttonDex + <NUM_LIT:1> ) ; } rotateUp = dsButtons [ <NUM_LIT:9> ] ; rotateDown = dsButtons [ <NUM_LIT:7> ] ; deployment = dsButtons [ <NUM_LIT:11> ] ; bPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:2> ) ; sPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:4> ) ; wPot = ds . getEnhancedIO ( ) . getAnalogIn ( <NUM_LIT:6> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double halfArm = <NUM_LIT:1.0> ; if ( ! override ) { if ( arcadeDrive ) { m_robotDrive . arcadeDrive ( ( <NUM_LIT:1> - <NUM_LIT:2> * m_buttons [ <NUM_LIT:6> ] ) * m_joystick . getRawAxis ( <NUM_LIT:2> ) * halfArm , m_joystick . getRawAxis ( <NUM_LIT:4> ) / ( <NUM_LIT:3> + ( m_buttons [ <NUM_LIT:7> ] * <NUM_LIT:3> ) ) * <NUM_LIT:2> * halfArm , false ) ; } else { if ( m_buttons [ <NUM_LIT:6> ] == <NUM_LIT:1> ) m_robotDrive . tankDrive ( - m_joystick . getRawAxis ( <NUM_LIT:3> ) , - m_joystick . getRawAxis ( <NUM_LIT:2> ) ) ; else m_robotDrive . tankDrive ( m_joystick . getRawAxis ( <NUM_LIT:2> ) , m_joystick . getRawAxis ( <NUM_LIT:3> ) ) ; } } if ( m_buttons [ <NUM_LIT:4> ] == <NUM_LIT:1> || deployment ) deploy = true ; if ( deploy ) deployServo . setAngle ( <NUM_LIT> ) ; else deployServo . setAngle ( <NUM_LIT> ) ; if ( ! override ) { if ( gripperSolenoid . get ( ) != dsButtons [ <NUM_LIT:0> ] ) { gripperSolenoid . set ( dsButtons [ <NUM_LIT:0> ] ) ; } if ( rotateUp || rotateDown ) { double rotateValue = <NUM_LIT:0> ; rotateValue -= ( rotateUp ) ? <NUM_LIT> : <NUM_LIT:0> ; rotateValue += ( rotateDown ) ? <NUM_LIT> : <NUM_LIT:0> ; topLeftRoller . set ( ( <NUM_LIT> ) + rotateValue ) ; topRightRoller . set ( <NUM_LIT> - rotateValue ) ; bottomRightRoller . set ( <NUM_LIT> - rotateValue ) ; bottomLeftRoller . set ( ( <NUM_LIT> ) + rotateValue ) ; } else if ( gripperButton . get ( ) && ! dsButtons [ <NUM_LIT:0> ] ) { topLeftRoller . set ( ( <NUM_LIT> ) + <NUM_LIT> ) ; topRightRoller . set ( <NUM_LIT> - <NUM_LIT> ) ; bottomLeftRoller . set ( <NUM_LIT> - <NUM_LIT> ) ; bottomRightRoller . set ( ( <NUM_LIT> ) + <NUM_LIT> ) ; } else { topLeftRoller . set ( ( <NUM_LIT> ) ) ; topRightRoller . set ( <NUM_LIT> ) ; bottomLeftRoller . set ( <NUM_LIT> ) ; bottomRightRoller . set ( ( <NUM_LIT> ) ) ; } } double boomV = <NUM_LIT:0> ; if ( ! override ) { double targetboom = ( <NUM_LIT> - bPot ) / <NUM_LIT> + <NUM_LIT> ; double boomDiff = <NUM_LIT:0> ; try { if ( boomLeftJag . getPosition ( ) != <NUM_LIT:0> ) boomDiff = targetboom - boomLeftJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double boomGain = <NUM_LIT> ; if ( boomDiff > <NUM_LIT:0> ) boomGain = <NUM_LIT> ; boomV = ( ( boomGain * - <NUM_LIT:1> ) * boomDiff ) ; double boomMaxV = <NUM_LIT:9> * <NUM_LIT:1> ; if ( Math . abs ( boomV ) > boomMaxV ) boomV = ( boomV < boomMaxV ) ? - boomMaxV : boomMaxV ; if ( Math . abs ( boomV ) > <NUM_LIT> ) { if ( Math . abs ( boomV ) < <NUM_LIT> ) boomV = ( boomV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else boomV = <NUM_LIT:0> ; } else { if ( lastStartingButton == <NUM_LIT:1> ) { double targetboom = <NUM_LIT> ; double boomDiff = <NUM_LIT:0> ; try { if ( boomLeftJag . getPosition ( ) != <NUM_LIT:0> ) boomDiff = targetboom - boomLeftJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } boomV = ( - <NUM_LIT> * boomDiff ) ; if ( Math . abs ( boomV ) > <NUM_LIT:9> ) boomV = ( boomV < <NUM_LIT:0> ) ? - <NUM_LIT:9> : <NUM_LIT:9> ; if ( Math . abs ( boomV ) > <NUM_LIT> ) { if ( Math . abs ( boomV ) < <NUM_LIT> ) boomV = ( boomV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else boomV = <NUM_LIT:0> ; } else boomV = <NUM_LIT:12> * - m_joystick . getRawAxis ( <NUM_LIT:4> ) ; } try { boomLeftJag . setX ( boomV / <NUM_LIT> ) ; boomRightJag . setX ( boomV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double stickV = <NUM_LIT:0> ; if ( ! override ) { double targetstick = sPot / <NUM_LIT> + <NUM_LIT> ; double stickDiff = <NUM_LIT:0> ; try { if ( stickRightJag . getPosition ( ) != <NUM_LIT:0> ) stickDiff = targetstick - stickRightJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } stickV = ( ( <NUM_LIT> * <NUM_LIT:1> ) * stickDiff ) ; double stickMaxV = <NUM_LIT:9> * <NUM_LIT:1> ; if ( Math . abs ( stickV ) > stickMaxV ) stickV = ( stickV < stickMaxV ) ? - stickMaxV : stickMaxV ; if ( Math . abs ( stickV ) > <NUM_LIT:1.0> ) { if ( Math . abs ( stickV ) < <NUM_LIT> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else stickV = <NUM_LIT:0> ; } else { if ( lastStartingButton == <NUM_LIT:1> ) { double targetstick = <NUM_LIT> ; double stickDiff = <NUM_LIT:0> ; try { if ( stickRightJag . getPosition ( ) != <NUM_LIT:0> ) stickDiff = targetstick - stickRightJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } stickV = <NUM_LIT:1> * ( <NUM_LIT> * stickDiff ) ; if ( Math . abs ( stickV ) > <NUM_LIT:12> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT:12> : <NUM_LIT:12> ; if ( Math . abs ( stickV ) > <NUM_LIT> ) { if ( Math . abs ( stickV ) < <NUM_LIT> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; } else stickV = <NUM_LIT:0> ; } else stickV = <NUM_LIT:7> * - m_joystick . getRawAxis ( <NUM_LIT:3> ) ; } try { stickLeftJag . setX ( stickV / <NUM_LIT> ) ; stickRightJag . setX ( stickV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } double wristV = <NUM_LIT:0> ; if ( ! override ) { double targetwrist = ( <NUM_LIT:1> - wPot / <NUM_LIT> ) - <NUM_LIT> ; double wristDiff = <NUM_LIT:0> ; try { if ( wristJag . getPosition ( ) != <NUM_LIT:0> ) wristDiff = targetwrist - wristJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } wristV = ( ( - <NUM_LIT> * <NUM_LIT:1> ) * wristDiff ) ; double wristMaxV = <NUM_LIT:9> * <NUM_LIT:1> ; if ( Math . abs ( wristV ) > wristMaxV ) wristV = ( wristV < wristMaxV ) ? - wristMaxV : wristMaxV ; if ( Math . abs ( wristV ) > <NUM_LIT> ) { if ( Math . abs ( wristV ) < <NUM_LIT:1.0> ) wristV = ( wristV < <NUM_LIT:0> ) ? - <NUM_LIT:1.0> : <NUM_LIT:1.0> ; } else wristV = <NUM_LIT:0> ; } else { if ( lastStartingButton == <NUM_LIT:1> ) { double targetwrist = <NUM_LIT> ; double wristDiff = <NUM_LIT:0> ; try { if ( wristJag . getPosition ( ) != <NUM_LIT:0> ) wristDiff = targetwrist - wristJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } wristV = - <NUM_LIT:1> * ( <NUM_LIT> * wristDiff ) ; if ( Math . abs ( wristV ) > <NUM_LIT:12> ) wristV = ( wristV < <NUM_LIT:0> ) ? - <NUM_LIT:12> : <NUM_LIT:12> ; if ( Math . abs ( wristV ) > <NUM_LIT> ) { if ( Math . abs ( wristV ) < <NUM_LIT:1.0> ) wristV = ( wristV < <NUM_LIT:0> ) ? - <NUM_LIT:1.0> : <NUM_LIT:1.0> ; } else wristV = <NUM_LIT:0> ; } else wristV = <NUM_LIT:4> * - m_joystick . getRawAxis ( <NUM_LIT:2> ) ; } try { wristJag . setX ( wristV / <NUM_LIT> ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } double [ ] getArmAngles ( double wristX , double wristY ) { double hypotenuse = Math . sqrt ( MathUtils . pow ( wristX , <NUM_LIT:2> ) + MathUtils . pow ( wristY - <NUM_LIT> , <NUM_LIT:2> ) ) ; double stickBoomAngle = MathUtils . acos ( ( <NUM_LIT> * <NUM_LIT> + <NUM_LIT> * <NUM_LIT> - hypotenuse * hypotenuse ) / ( <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> ) ) ; double hypotenuseHorizontalAngle = MathUtils . atan2 ( ( wristY - <NUM_LIT> ) , wristX ) ; double hypotenuseBoomAngle = MathUtils . acos ( ( <NUM_LIT> * <NUM_LIT> + hypotenuse * hypotenuse - <NUM_LIT> * <NUM_LIT> ) / ( <NUM_LIT:2> * <NUM_LIT> * hypotenuse ) ) ; double boomHorizontalAngle = ( hypotenuseHorizontalAngle + hypotenuseBoomAngle ) ; double [ ] armAngles = { boomHorizontalAngle / Math . PI * <NUM_LIT> , stickBoomAngle / Math . PI * <NUM_LIT> } ; return armAngles ; } double [ ] getWristCoordinates ( double boomAngle , double stickAngle ) { double hypotenuse = Math . sqrt ( <NUM_LIT> * <NUM_LIT> + <NUM_LIT> * <NUM_LIT> - <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> * Math . cos ( stickAngle / <NUM_LIT> * Math . PI ) ) ; double hypotenuseBoomAngle = MathUtils . acos ( ( <NUM_LIT> * <NUM_LIT> + hypotenuse * hypotenuse - <NUM_LIT> * <NUM_LIT> ) / ( <NUM_LIT:2> * <NUM_LIT> * hypotenuse ) ) ; double hypotenuseHorizontalAngle = boomAngle / <NUM_LIT> * Math . PI - hypotenuseBoomAngle ; double xCoord = hypotenuse * Math . cos ( hypotenuseHorizontalAngle ) ; double yCoord = hypotenuse * Math . sin ( hypotenuseHorizontalAngle ) + <NUM_LIT> ; double [ ] wristCoords = { xCoord , yCoord } ; return wristCoords ; } int GetLoopsPerSec ( ) { return <NUM_LIT:20> ; } void updateDashboard ( ) { Dashboard lowDashData = ds . getDashboardPackerLow ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:4> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { int module = <NUM_LIT:6> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addByte ( Solenoid . getAllFromDefaultModule ( ) ) ; lowDashData . commit ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . defaultCode ; import com . sun . squawk . util . MathUtils ; import edu . wpi . first . wpilibj . AnalogChannel ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . CANJaguar ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . DigitalInput ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Servo ; import edu . wpi . first . wpilibj . Solenoid ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; public class DefaultRobot1 extends IterativeRobot { RobotDrive m_robotDrive ; DriverStation ds ; CANJaguar frontLeftJag ; CANJaguar frontRightJag ; CANJaguar rearLeftJag ; CANJaguar rearRightJag ; CANJaguar boomRightJag ; CANJaguar boomLeftJag ; CANJaguar stickRightJag ; CANJaguar stickLeftJag ; Servo wristServo ; Solenoid gripperSolenoid ; double boomAngle = <NUM_LIT> ; double stickAngle = <NUM_LIT> ; double lastTargetHeight = <NUM_LIT> ; double currentHeight = <NUM_LIT> ; double targetHeight = <NUM_LIT> ; double heightIncrement = <NUM_LIT:0> ; int currentPreset = - <NUM_LIT:1> ; int presetStage = <NUM_LIT:0> ; boolean doAutoArmStuff = false ; Servo deployServo ; boolean deployed = false ; DigitalInput leftLineSensor ; DigitalInput middleLineSensor ; DigitalInput rightLineSensor ; int [ ] lastThreeLines = new int [ <NUM_LIT:3> ] ; int lineLoops = <NUM_LIT:0> ; boolean hitY = false ; boolean hasStopped = false ; int ignoreLines = <NUM_LIT:0> ; int m_dsPacketsReceivedInCurrentSecond ; Joystick m_joystick ; static final int NUM_BUTTONS = <NUM_LIT:10> ; int [ ] m_buttons = new int [ NUM_BUTTONS ] ; boolean slow_drive = false ; int m_autoPeriodicLoops ; int m_disabledPeriodicLoops ; int m_telePeriodicLoops ; public DefaultRobot1 ( ) { System . out . println ( "<STR_LIT>" ) ; ds = DriverStation . getInstance ( ) ; try { frontLeftJag = new CANJaguar ( <NUM_LIT:4> ) ; frontRightJag = new CANJaguar ( <NUM_LIT:5> ) ; rearLeftJag = new CANJaguar ( <NUM_LIT:3> ) ; rearRightJag = new CANJaguar ( <NUM_LIT:2> ) ; } catch ( Exception e ) { } m_robotDrive = new RobotDrive ( frontLeftJag , rearLeftJag , frontRightJag , rearRightJag ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearLeft , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kFrontRight , true ) ; m_robotDrive . setInvertedMotor ( RobotDrive . MotorType . kRearRight , true ) ; try { boomRightJag = new CANJaguar ( <NUM_LIT:6> , CANJaguar . ControlMode . kPosition ) ; boomLeftJag = new CANJaguar ( <NUM_LIT:9> , CANJaguar . ControlMode . kPosition ) ; stickRightJag = new CANJaguar ( <NUM_LIT:7> , CANJaguar . ControlMode . kPosition ) ; stickLeftJag = new CANJaguar ( <NUM_LIT:8> , CANJaguar . ControlMode . kPosition ) ; for ( int setThatMode = <NUM_LIT:0> ; setThatMode < <NUM_LIT:5> ; setThatMode ++ ) { boomRightJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; boomLeftJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; stickRightJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; stickLeftJag . changeControlMode ( CANJaguar . ControlMode . kPosition ) ; Thread . sleep ( <NUM_LIT:100> ) ; if ( boomRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && boomLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && stickLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition && stickRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPosition ) break ; } boomRightJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; boomLeftJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; stickRightJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; stickLeftJag . setPositionReference ( CANJaguar . PositionReference . kPotentiometer ) ; for ( int setThatMode = <NUM_LIT:0> ; setThatMode < <NUM_LIT:5> ; setThatMode ++ ) { boomRightJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; boomLeftJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; stickRightJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; stickLeftJag . changeControlMode ( CANJaguar . ControlMode . kPercentVbus ) ; Thread . sleep ( <NUM_LIT:100> ) ; if ( boomRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && boomLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && stickLeftJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus && stickRightJag . getControlMode ( ) == CANJaguar . ControlMode . kPercentVbus ) break ; } } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } wristServo = new Servo ( <NUM_LIT:2> ) ; gripperSolenoid = new Solenoid ( <NUM_LIT:1> ) ; deployServo = new Servo ( <NUM_LIT:1> ) ; leftLineSensor = new DigitalInput ( <NUM_LIT> ) ; middleLineSensor = new DigitalInput ( <NUM_LIT> ) ; rightLineSensor = new DigitalInput ( <NUM_LIT:12> ) ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_joystick = new Joystick ( <NUM_LIT:1> ) ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < NUM_BUTTONS ; buttonDex ++ ) { m_buttons [ buttonDex ] = ( int ) ( m_joystick . getRawButton ( buttonDex + <NUM_LIT:1> ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } m_autoPeriodicLoops = <NUM_LIT:0> ; m_disabledPeriodicLoops = <NUM_LIT:0> ; m_telePeriodicLoops = <NUM_LIT:0> ; System . out . println ( "<STR_LIT>" ) ; } public void robotInit ( ) { System . out . println ( "<STR_LIT>" ) ; } public void disabledInit ( ) { m_disabledPeriodicLoops = <NUM_LIT:0> ; startSec = ( int ) ( Timer . getUsClock ( ) / <NUM_LIT> ) ; printSec = startSec + <NUM_LIT:1> ; } public void autonomousInit ( ) { m_autoPeriodicLoops = <NUM_LIT:0> ; try { boomAngle = ( boomLeftJag . getPosition ( ) + boomRightJag . getPosition ( ) ) / <NUM_LIT> * <NUM_LIT> ; stickAngle = ( stickLeftJag . getPosition ( ) + stickRightJag . getPosition ( ) ) / <NUM_LIT> * <NUM_LIT> ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } if ( boomAngle != <NUM_LIT:0> && stickAngle != <NUM_LIT:0> ) doAutoArmStuff = true ; } public void teleopInit ( ) { m_telePeriodicLoops = <NUM_LIT:0> ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; try { boomAngle = ( boomLeftJag . getPosition ( ) + boomRightJag . getPosition ( ) ) / <NUM_LIT> * <NUM_LIT> ; stickAngle = ( stickLeftJag . getPosition ( ) + stickRightJag . getPosition ( ) ) / <NUM_LIT> * <NUM_LIT> ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } static int printSec ; static int startSec ; public void disabledPeriodic ( ) { updateDashboard ( ) ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] = <NUM_LIT:0> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; lineLoops ++ ; Watchdog . getInstance ( ) . feed ( ) ; m_disabledPeriodicLoops ++ ; lineLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; ignoreLines = <NUM_LIT:0> ; try { System . out . println ( "<STR_LIT>" + boomLeftJag . getPosition ( ) + "<STR_LIT>" + boomRightJag . getPosition ( ) ) ; System . out . println ( "<STR_LIT>" + stickLeftJag . getPosition ( ) + "<STR_LIT>" + stickRightJag . getPosition ( ) ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } public void autonomousPeriodic ( ) { updateDashboard ( ) ; Watchdog . getInstance ( ) . feed ( ) ; m_autoPeriodicLoops ++ ; deployServo . setAngle ( <NUM_LIT> ) ; if ( ! hasStopped ) { boolean straightLine = ds . getDigitalIn ( <NUM_LIT:1> ) ; boolean goLeft = ds . getDigitalIn ( <NUM_LIT:2> ) && ! straightLine ; int lineReading = <NUM_LIT:0> ; lineReading += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lineReading += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lineReading += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; System . out . print ( "<STR_LIT>" + lineReading + "<STR_LIT>" ) ; double rightMotors = <NUM_LIT:0> ; double leftMotors = <NUM_LIT:0> ; switch ( lineReading ) { case <NUM_LIT:0> : { rightMotors = <NUM_LIT> * ( lastThreeLines [ <NUM_LIT:0> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:1> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:2> ] % <NUM_LIT:10> ) / <NUM_LIT> ; leftMotors = <NUM_LIT> * ( Math . floor ( lastThreeLines [ <NUM_LIT:0> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + Math . floor ( lastThreeLines [ <NUM_LIT:1> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + Math . floor ( lastThreeLines [ <NUM_LIT:2> ] / <NUM_LIT:100> ) % <NUM_LIT:10> ) / <NUM_LIT> ; } break ; case <NUM_LIT:1> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:11> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:10> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:100> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : if ( straightLine || hitY ) { hasStopped = true ; System . out . print ( "<STR_LIT>" ) ; } else { if ( goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; } break ; case <NUM_LIT> : if ( ! straightLine ) { if ( goLeft ) { leftMotors = <NUM_LIT> ; rightMotors = - <NUM_LIT> ; lineReading = <NUM_LIT:100> ; } else { leftMotors = - <NUM_LIT> ; rightMotors = <NUM_LIT> ; lineReading = <NUM_LIT:1> ; } hitY = true ; System . out . print ( "<STR_LIT>" ) ; } break ; default : break ; } m_robotDrive . tankDrive ( - leftMotors , - rightMotors ) ; System . out . println ( "<STR_LIT>" + leftMotors + "<STR_LIT>" + rightMotors ) ; if ( lineReading > <NUM_LIT:0> ) lastThreeLines [ lineLoops % <NUM_LIT:3> ] = lineReading ; lineLoops ++ ; } else if ( ignoreLines > <NUM_LIT> ) { int lineReading = <NUM_LIT:0> ; lineReading += ( leftLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:100> ; lineReading += ( middleLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:10> ; lineReading += ( rightLineSensor . get ( ) ) ? <NUM_LIT:0> : <NUM_LIT:1> ; System . out . print ( "<STR_LIT>" + lineReading + "<STR_LIT>" ) ; double rightMotors = <NUM_LIT:0> ; double leftMotors = <NUM_LIT:0> ; switch ( lineReading ) { case <NUM_LIT:0> : leftMotors = <NUM_LIT:1> * ( lastThreeLines [ <NUM_LIT:0> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:1> ] % <NUM_LIT:10> + lastThreeLines [ <NUM_LIT:2> ] % <NUM_LIT:10> ) / <NUM_LIT> ; rightMotors = <NUM_LIT:1> * ( ( lastThreeLines [ <NUM_LIT:0> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:1> ] / <NUM_LIT:100> ) % <NUM_LIT:10> + ( lastThreeLines [ <NUM_LIT:2> ] / <NUM_LIT:100> ) % <NUM_LIT:10> ) / <NUM_LIT> ; break ; case <NUM_LIT:1> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:10> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:11> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT:100> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; case <NUM_LIT> : leftMotors = <NUM_LIT> ; rightMotors = <NUM_LIT> ; break ; default : break ; } m_robotDrive . tankDrive ( - leftMotors , - rightMotors ) ; System . out . println ( "<STR_LIT>" + leftMotors + "<STR_LIT>" + rightMotors ) ; lastThreeLines [ lineLoops % <NUM_LIT:3> ] = lineReading ; lineLoops ++ ; } else { if ( ! doAutoArmStuff ) { ignoreLines ++ ; m_robotDrive . tankDrive ( <NUM_LIT> , - <NUM_LIT> ) ; System . out . println ( "<STR_LIT>" ) ; } } } public void teleopPeriodic ( ) { lineLoops = <NUM_LIT:0> ; hitY = false ; hasStopped = false ; ignoreLines = <NUM_LIT:0> ; Watchdog . getInstance ( ) . feed ( ) ; m_telePeriodicLoops ++ ; m_dsPacketsReceivedInCurrentSecond ++ ; updateDashboard ( ) ; for ( int buttonDex = <NUM_LIT:0> ; buttonDex < NUM_BUTTONS ; buttonDex ++ ) { m_buttons [ buttonDex ] = ( int ) ( m_joystick . getRawButton ( buttonDex + <NUM_LIT:1> ) ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } m_robotDrive . arcadeDrive ( ( <NUM_LIT:1> + m_buttons [ <NUM_LIT:6> ] * - <NUM_LIT:2> ) * m_joystick . getRawAxis ( <NUM_LIT:2> ) , m_joystick . getRawAxis ( <NUM_LIT:4> ) / <NUM_LIT:3> * <NUM_LIT:2> , false ) ; if ( m_buttons [ <NUM_LIT:4> ] == <NUM_LIT:1> ) deployed = true ; if ( deployed ) deployServo . setAngle ( <NUM_LIT:0> ) ; else deployServo . setAngle ( <NUM_LIT> ) ; wristServo . setAngle ( <NUM_LIT> + <NUM_LIT> * m_buttons [ <NUM_LIT:8> ] ) ; if ( m_buttons [ <NUM_LIT:5> ] == <NUM_LIT:1> ) { if ( ! gripperSolenoid . get ( ) ) gripperSolenoid . set ( true ) ; else gripperSolenoid . set ( true ) ; } double targetboom = ( m_joystick . getRawAxis ( <NUM_LIT:1> ) + <NUM_LIT:1> ) * <NUM_LIT> + <NUM_LIT> ; if ( targetboom < <NUM_LIT> ) targetboom = <NUM_LIT> ; if ( targetboom > <NUM_LIT> ) targetboom = <NUM_LIT> ; double boomDiff = <NUM_LIT:0> ; try { if ( boomLeftJag . getPosition ( ) != <NUM_LIT:0> ) boomDiff = targetboom - boomLeftJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } if ( Math . abs ( boomDiff ) < <NUM_LIT> ) boomDiff = <NUM_LIT:0> ; double boomV = boomDiff * <NUM_LIT> ; if ( boomV != <NUM_LIT:0> ) if ( Math . abs ( boomV ) < <NUM_LIT> ) boomV = ( boomV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; try { boomLeftJag . setX ( boomV / <NUM_LIT> ) ; boomRightJag . setX ( boomV / <NUM_LIT> ) ; } catch ( Exception e ) { } double targetstick = ( - m_joystick . getRawAxis ( <NUM_LIT:3> ) + <NUM_LIT:1> ) * <NUM_LIT> + <NUM_LIT> ; if ( targetstick < <NUM_LIT> ) targetstick = <NUM_LIT> ; if ( targetstick > <NUM_LIT> ) targetstick = <NUM_LIT> ; double stickDiff = <NUM_LIT:0> ; try { if ( stickLeftJag . getPosition ( ) != <NUM_LIT:0> ) stickDiff = targetstick - stickLeftJag . getPosition ( ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } if ( Math . abs ( stickDiff ) < <NUM_LIT> ) stickDiff = <NUM_LIT:0> ; double stickV = stickDiff * - <NUM_LIT> ; if ( stickV != <NUM_LIT:0> ) if ( Math . abs ( stickV ) < <NUM_LIT> ) stickV = ( stickV < <NUM_LIT:0> ) ? - <NUM_LIT> : <NUM_LIT> ; try { stickLeftJag . setX ( stickV / <NUM_LIT> ) ; stickRightJag . setX ( stickV / <NUM_LIT> ) ; } catch ( Exception e ) { } } int GetLoopsPerSec ( ) { return <NUM_LIT:20> ; } void updateDashboard ( ) { Dashboard lowDashData = ds . getDashboardPackerLow ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:4> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { int module = <NUM_LIT:6> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addByte ( gripperSolenoid . getAll ( ) ) ; lowDashData . commit ( ) ; } } </s>
<s> package robot ; import edu . wpi . first . wpilibj . Joystick ; public class ButtonChange { Joystick joystick ; int buttonNumber ; boolean previousState ; public ButtonChange ( Joystick joystick , int buttonNumber ) { this . joystick = joystick ; this . buttonNumber = buttonNumber ; } public void setPreviousState ( ) { previousState = joystick . getRawButton ( buttonNumber ) ; } public boolean didButtonChange ( boolean actOnRelease ) { boolean currentState = joystick . getRawButton ( buttonNumber ) ; if ( actOnRelease ) { if ( currentState == false ) { if ( previousState == false ) { return false ; } else { return true ; } } else { return false ; } } else { if ( currentState ) { if ( previousState == false ) { return true ; } else { return false ; } } else { return false ; } } } } </s>
<s> package robot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Victor ; public class Intake { public static final int STOP = <NUM_LIT:0> ; public static final int INTAKE = <NUM_LIT:1> ; public static final int FIRE = <NUM_LIT:2> ; public static final int REVERSE = - <NUM_LIT:1> ; private Joystick joystick ; private Victor beltMotorOne , beltMotorTwo , unobtaniumMotor ; private ButtonChange intakeButton ; private int intakeMode , previousMode ; public Intake ( Joystick joystick , Victor beltMotorOne , Victor beltMotorTwo , Victor unobtaniumMotor ) { this . joystick = joystick ; this . beltMotorOne = beltMotorOne ; this . beltMotorTwo = beltMotorTwo ; this . unobtaniumMotor = unobtaniumMotor ; intakeMode = STOP ; previousMode = STOP ; intakeButton = new ButtonChange ( joystick , <NUM_LIT:3> ) ; } public void doAction ( ) { if ( intakeButton . didButtonChange ( true ) ) { if ( intakeMode == INTAKE ) { intakeMode = STOP ; } else { intakeMode = INTAKE ; } } else { toggleModeFromJoystickButton ( <NUM_LIT:2> , - <NUM_LIT:1> ) ; toggleModeFromJoystickButton ( <NUM_LIT:1> , <NUM_LIT:2> ) ; } double beltSpeed = <NUM_LIT:0> ; double unobtaniumSpeed = <NUM_LIT:0> ; switch ( intakeMode ) { case REVERSE : beltSpeed = <NUM_LIT:1> ; unobtaniumSpeed = <NUM_LIT:0> ; break ; case STOP : beltSpeed = <NUM_LIT:0> ; unobtaniumSpeed = <NUM_LIT:0> ; break ; case INTAKE : beltSpeed = - <NUM_LIT:1> ; unobtaniumSpeed = <NUM_LIT> ; break ; case FIRE : beltSpeed = - <NUM_LIT:1> ; unobtaniumSpeed = - <NUM_LIT:1> ; break ; default : beltSpeed = <NUM_LIT:0> ; unobtaniumSpeed = <NUM_LIT:0> ; break ; } setBeltSpeed ( beltSpeed ) ; setUnobtaniumSpeed ( unobtaniumSpeed ) ; intakeButton . setPreviousState ( ) ; } public void toggleModeFromJoystickButton ( int joystickButton , int desiredMode ) { if ( joystick . getRawButton ( joystickButton ) ) { if ( intakeMode != desiredMode ) { previousMode = intakeMode ; } intakeMode = desiredMode ; } else if ( ! joystick . getRawButton ( joystickButton ) && intakeMode == desiredMode ) { intakeMode = previousMode ; previousMode = STOP ; } } public void setBeltSpeed ( double speed ) { beltMotorOne . set ( speed ) ; beltMotorTwo . set ( speed ) ; } public void setUnobtaniumSpeed ( double speed ) { unobtaniumMotor . set ( speed ) ; } } </s>
<s> package robot ; import edu . wpi . first . wpilibj . DigitalInput ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Jaguar ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Victor ; public class LoganRover extends IterativeRobot { public static final double AUTO_CORNER_FORWARD_TIME = <NUM_LIT:2> ; public static final double AUTO_MIDDLE_FORWARD_TIME = <NUM_LIT:1> ; public static final double AUTO_FORWARD_SPEED = - <NUM_LIT> ; public static final double AUTO_RIGHT_SPIN_SPEED = - <NUM_LIT:1> ; public static final double AUTO_LEFT_SPIN_SPEED = <NUM_LIT:1> ; private Joystick joystickOne ; private DigitalInput leftAutoSwitch ; private DigitalInput rightAutoSwitch ; private Timer autoTimer ; private RobotDrive drivetrain ; private Intake intake ; private Jaguar leftDrive , rightDrive ; private Victor intakeMotorOne , intakeMotorTwo ; private Victor unobtaniumMotor ; public void robotInit ( ) { joystickOne = new Joystick ( <NUM_LIT:1> ) ; leftAutoSwitch = new DigitalInput ( <NUM_LIT:1> ) ; rightAutoSwitch = new DigitalInput ( <NUM_LIT:2> ) ; autoTimer = new Timer ( ) ; leftDrive = new Jaguar ( <NUM_LIT:3> ) ; rightDrive = new Jaguar ( <NUM_LIT:1> ) ; intakeMotorOne = new Victor ( <NUM_LIT:2> ) ; intakeMotorTwo = new Victor ( <NUM_LIT:4> ) ; unobtaniumMotor = new Victor ( <NUM_LIT:5> ) ; drivetrain = new RobotDrive ( leftDrive , rightDrive ) ; drivetrain . setInvertedMotor ( RobotDrive . MotorType . kFrontLeft , true ) ; drivetrain . setInvertedMotor ( RobotDrive . MotorType . kRearLeft , true ) ; drivetrain . setInvertedMotor ( RobotDrive . MotorType . kFrontRight , true ) ; drivetrain . setInvertedMotor ( RobotDrive . MotorType . kRearRight , true ) ; intake = new Intake ( joystickOne , intakeMotorOne , intakeMotorTwo , unobtaniumMotor ) ; } public void autonomousInit ( ) { autoTimer . start ( ) ; } public void autonomousPeriodic ( ) { getWatchdog ( ) . feed ( ) ; double elapsedTime = autoTimer . get ( ) ; if ( leftAutoSwitch . get ( ) == true && rightAutoSwitch . get ( ) == false ) { if ( elapsedTime <= AUTO_CORNER_FORWARD_TIME ) { drivetrain . arcadeDrive ( AUTO_FORWARD_SPEED , <NUM_LIT:0> ) ; } else { drivetrain . arcadeDrive ( <NUM_LIT:0> , AUTO_LEFT_SPIN_SPEED ) ; } } else if ( leftAutoSwitch . get ( ) == false && rightAutoSwitch . get ( ) == true ) { if ( elapsedTime <= AUTO_CORNER_FORWARD_TIME ) { drivetrain . arcadeDrive ( AUTO_FORWARD_SPEED , <NUM_LIT:0> ) ; } else { drivetrain . arcadeDrive ( <NUM_LIT:0> , AUTO_RIGHT_SPIN_SPEED ) ; } } else { if ( elapsedTime < AUTO_MIDDLE_FORWARD_TIME ) { drivetrain . arcadeDrive ( AUTO_FORWARD_SPEED , <NUM_LIT:0> ) ; } else { drivetrain . arcadeDrive ( <NUM_LIT:0> , AUTO_LEFT_SPIN_SPEED ) ; } } } public void teleopInit ( ) { autoTimer . stop ( ) ; } public void teleopPeriodic ( ) { getWatchdog ( ) . feed ( ) ; drivetrain . arcadeDrive ( joystickOne ) ; intake . doAction ( ) ; } } </s>
<s> package edu . missdaisy ; import edu . wpi . first . wpilibj . * ; import java . util . TimerTask ; public class Daisy2009 extends IterativeRobot { private class FastPeriodicTask extends TimerTask { private Daisy2009 instance ; private boolean run100HzTasks = true ; java . util . Timer timer ; public FastPeriodicTask ( Daisy2009 instance ) { this . instance = instance ; timer = new java . util . Timer ( ) ; timer . schedule ( this , <NUM_LIT> , <NUM_LIT> ) ; } private void run200Hz ( ) { if ( instance . rightStick . getRawButton ( <NUM_LIT:11> ) ) { if ( turretPID . isEnabled ( ) ) { turretPID . reset ( ) ; turretPID . enable ( ) ; } turretMotor . set ( - <NUM_LIT:1> ) ; turretEncoder . reset ( ) ; } else if ( instance . rightStick . getRawButton ( <NUM_LIT:10> ) ) { if ( turretPID . isEnabled ( ) ) { turretPID . reset ( ) ; turretPID . enable ( ) ; } turretMotor . set ( <NUM_LIT:1> ) ; turretEncoder . reset ( ) ; } else if ( instance . turretPID . isEnabled ( ) ) { if ( instance . turretPID . onTarget ( <NUM_LIT> ) ) { instance . turretMotor . set ( <NUM_LIT:0> ) ; instance . turretPID . calculate ( instance . turretEncoder . getDistance ( ) , <NUM_LIT:0> ) ; } else { instance . turretMotor . set ( instance . turretPID . calculate ( instance . turretEncoder . getDistance ( ) , <NUM_LIT:0> ) ) ; } } if ( instance . leftDrivePID . isEnabled ( ) ) { instance . leftDrive . set ( instance . leftDrivePID . calculate ( instance . leftDriveEncoder . getRate ( ) , <NUM_LIT:0> ) ) ; } if ( instance . rightDrivePID . isEnabled ( ) ) { instance . rightDrive . set ( instance . rightDrivePID . calculate ( instance . rightDriveEncoder . getRate ( ) , <NUM_LIT:0> ) ) ; } } private void run100Hz ( ) { } public void run ( ) { run200Hz ( ) ; if ( run100HzTasks ) { run100Hz ( ) ; } run100HzTasks = ! run100HzTasks ; } } final double kMaxSpeedInPerSec = <NUM_LIT> ; boolean isTwoStick ; boolean turretShooting ; int autoState ; double secondsInAutonomous ; Jaguar leftDrive ; Jaguar rightDrive ; Jaguar turretMotor ; Victor conveyorMotor ; Victor brushSpinner1 ; Victor brushSpinner2 ; Compressor compressor ; Solenoid hoodSolenoid ; Solenoid gateSolenoid ; Joystick leftStick ; Joystick rightStick ; Joystick operatorStick ; Encoder turretEncoder ; Encoder rightDriveEncoder ; Encoder leftDriveEncoder ; Gyro gyro ; SynchronousPID turretPID ; DigitalFilter turretFilter ; SynchronousPID leftDrivePID ; DigitalFilter leftDriveFilter ; SynchronousPID rightDrivePID ; DigitalFilter rightDriveFilter ; FastPeriodicTask fastTask ; public Daisy2009 ( ) { leftDrive = new Jaguar ( <NUM_LIT:2> ) ; rightDrive = new Jaguar ( <NUM_LIT:1> ) ; turretMotor = new Jaguar ( <NUM_LIT:3> ) ; conveyorMotor = new Victor ( <NUM_LIT:4> ) ; brushSpinner1 = new Victor ( <NUM_LIT:5> ) ; brushSpinner2 = new Victor ( <NUM_LIT:6> ) ; compressor = new Compressor ( <NUM_LIT> , <NUM_LIT:1> ) ; hoodSolenoid = new Solenoid ( <NUM_LIT:1> ) ; gateSolenoid = new Solenoid ( <NUM_LIT:4> ) ; operatorStick = new Joystick ( <NUM_LIT:3> ) ; leftStick = new Joystick ( <NUM_LIT:4> ) ; rightStick = new Joystick ( <NUM_LIT:1> ) ; turretEncoder = new Encoder ( <NUM_LIT:10> , <NUM_LIT:11> , false , Encoder . EncodingType . k4X ) ; turretEncoder . setDistancePerPulse ( - <NUM_LIT> ) ; rightDriveEncoder = new Encoder ( <NUM_LIT:3> , <NUM_LIT:4> , false , Encoder . EncodingType . k1X ) ; rightDriveEncoder . setDistancePerPulse ( <NUM_LIT> ) ; rightDriveEncoder . setMinRate ( <NUM_LIT:1.0> ) ; leftDriveEncoder = new Encoder ( <NUM_LIT:1> , <NUM_LIT:2> , false , Encoder . EncodingType . k1X ) ; leftDriveEncoder . setDistancePerPulse ( <NUM_LIT> ) ; leftDriveEncoder . setMinRate ( <NUM_LIT:1.0> ) ; gyro = new Gyro ( <NUM_LIT:1> ) ; gyro . setSensitivity ( <NUM_LIT> ) ; turretPID = new SynchronousPID ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; turretFilter = DigitalFilter . SinglePoleIIRFilter ( <NUM_LIT> ) ; rightDrivePID = new SynchronousPID ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ; rightDriveFilter = DigitalFilter . SinglePoleIIRFilter ( <NUM_LIT> ) ; leftDrivePID = new SynchronousPID ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ; leftDriveFilter = DigitalFilter . SinglePoleIIRFilter ( <NUM_LIT> ) ; fastTask = new FastPeriodicTask ( this ) ; getWatchdog ( ) . setEnabled ( true ) ; getWatchdog ( ) . setExpiration ( kDefaultPeriod ) ; } public void robotInit ( ) { isTwoStick = false ; turretShooting = true ; leftDriveEncoder . start ( ) ; rightDriveEncoder . start ( ) ; turretEncoder . start ( ) ; compressor . start ( ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } public void disabledPeriodic ( ) { getWatchdog ( ) . feed ( ) ; if ( leftStick . getRawButton ( <NUM_LIT:4> ) ) { isTwoStick = true ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } else if ( leftStick . getRawButton ( <NUM_LIT:5> ) ) { isTwoStick = false ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } } public void disabledInit ( ) { turretPID . reset ( ) ; leftDrivePID . reset ( ) ; rightDrivePID . reset ( ) ; } public void autonomousInit ( ) { autoState = <NUM_LIT:0> ; secondsInAutonomous = <NUM_LIT:0.0> ; gyro . reset ( ) ; } public void teleopInit ( ) { turretPID . enable ( ) ; turretPID . setSetpoint ( <NUM_LIT:0> ) ; leftDrivePID . enable ( ) ; leftDrivePID . setSetpoint ( <NUM_LIT:0> ) ; rightDrivePID . enable ( ) ; rightDrivePID . setSetpoint ( <NUM_LIT:0> ) ; } public void autonomousPeriodic ( ) { getWatchdog ( ) . feed ( ) ; secondsInAutonomous += <NUM_LIT> ; drive ( <NUM_LIT:1.0> * kMaxSpeedInPerSec , <NUM_LIT:1.0> * kMaxSpeedInPerSec ) ; } public void teleopPeriodic ( ) { getWatchdog ( ) . feed ( ) ; double leftSpeed ; double rightSpeed ; if ( leftStick . getRawButton ( <NUM_LIT:4> ) ) { isTwoStick = true ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } else if ( leftStick . getRawButton ( <NUM_LIT:5> ) ) { isTwoStick = false ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } if ( isTwoStick ) { leftSpeed = - leftStick . getY ( ) ; rightSpeed = - rightStick . getY ( ) ; } else { leftSpeed = - leftStick . getY ( ) + leftStick . getX ( ) ; if ( leftSpeed > <NUM_LIT:1.0> ) { leftSpeed = <NUM_LIT:1.0> ; } else if ( leftSpeed < - <NUM_LIT:1.0> ) { leftSpeed = - <NUM_LIT:1.0> ; } rightSpeed = - leftStick . getY ( ) - leftStick . getX ( ) ; if ( rightSpeed > <NUM_LIT:1.0> ) { rightSpeed = <NUM_LIT:1.0> ; } else if ( rightSpeed < - <NUM_LIT:1.0> ) { rightSpeed = - <NUM_LIT:1.0> ; } } drive ( leftSpeed * kMaxSpeedInPerSec , rightSpeed * kMaxSpeedInPerSec ) ; if ( operatorStick . getTrigger ( ) ) { brushSpinner1 . set ( - <NUM_LIT:1> ) ; brushSpinner2 . set ( - <NUM_LIT:1> ) ; } else { brushSpinner1 . set ( ( operatorStick . getThrottle ( ) - <NUM_LIT:1.0> ) / <NUM_LIT> ) ; brushSpinner2 . set ( ( operatorStick . getThrottle ( ) - <NUM_LIT:1.0> ) / <NUM_LIT> ) ; } if ( operatorStick . getRawButton ( <NUM_LIT:2> ) ) { conveyorMotor . set ( - <NUM_LIT:1> ) ; brushSpinner1 . set ( <NUM_LIT:1> ) ; brushSpinner2 . set ( <NUM_LIT:1> ) ; } else if ( ! turretShooting && turretPID . onTarget ( <NUM_LIT> ) ) { conveyorMotor . set ( <NUM_LIT> ) ; } else if ( operatorStick . getTrigger ( ) ) { conveyorMotor . set ( <NUM_LIT:1> ) ; } else { conveyorMotor . set ( <NUM_LIT:0> ) ; } if ( operatorStick . getTrigger ( ) ) { gateSolenoid . set ( true ) ; } else { gateSolenoid . set ( false ) ; } if ( operatorStick . getRawButton ( <NUM_LIT:7> ) ) { turretShooting = true ; } else if ( operatorStick . getRawButton ( <NUM_LIT:11> ) ) { turretShooting = false ; } if ( turretShooting ) { turretPID . setSetpoint ( turretFilter . calculate ( operatorStick . getX ( ) * <NUM_LIT> ) ) ; } else { turretPID . setSetpoint ( <NUM_LIT> ) ; } } private void drive ( double leftDesiredSpeed , double rightDesiredSpeed ) { leftDrivePID . setSetpoint ( leftDriveFilter . calculate ( leftDesiredSpeed ) ) ; rightDrivePID . setSetpoint ( rightDriveFilter . calculate ( rightDesiredSpeed ) ) ; } } </s>
<s> package edu . missdaisy ; import java . util . Vector ; public class DigitalFilter { private class CircularBuffer { private double [ ] data ; private int front ; public CircularBuffer ( int size ) { data = new double [ size ] ; front = <NUM_LIT:0> ; } public void increment ( ) { front ++ ; if ( front >= data . length ) { front = <NUM_LIT:0> ; } } public void reset ( ) { for ( int d = <NUM_LIT:0> ; d < data . length ; d ++ ) { data [ d ] = <NUM_LIT:0> ; } } public int size ( ) { return data . length ; } public double elementAt ( int position ) { return data [ ( position + front ) % data . length ] ; } public void setElementAt ( double value , int position ) { data [ ( position + front ) % data . length ] = value ; } } private CircularBuffer inputs ; private CircularBuffer outputs ; private Vector inputGains ; private Vector outputGains ; public DigitalFilter ( Vector inputGains , Vector outputGains ) { this . inputGains = inputGains ; this . outputGains = outputGains ; inputs = new CircularBuffer ( inputGains . size ( ) ) ; outputs = new CircularBuffer ( outputGains . size ( ) ) ; } public static DigitalFilter SinglePoleIIRFilter ( double gain ) { Vector inputGain = new Vector ( ) ; Vector outputGain = new Vector ( ) ; inputGain . addElement ( new Double ( gain ) ) ; outputGain . addElement ( new Double ( <NUM_LIT:1.0f> - gain ) ) ; return new DigitalFilter ( inputGain , outputGain ) ; } public static DigitalFilter MovingAverageFilter ( int taps ) { if ( taps < <NUM_LIT:1> ) { taps = <NUM_LIT:1> ; } Double gain = new Double ( <NUM_LIT:1.0> / taps ) ; Vector gains = new Vector ( ) ; for ( int i = <NUM_LIT:0> ; i < taps ; i ++ ) { gains . addElement ( gain ) ; } return new DigitalFilter ( gains , new Vector ( ) ) ; } public void reset ( ) { inputs . reset ( ) ; outputs . reset ( ) ; } public double calculate ( double value ) { double retVal = <NUM_LIT:0.0> ; if ( inputs . size ( ) > <NUM_LIT:0> ) { inputs . increment ( ) ; inputs . setElementAt ( value , <NUM_LIT:0> ) ; } for ( int i = <NUM_LIT:0> ; i < inputs . size ( ) ; i ++ ) { retVal += inputs . elementAt ( i ) * ( ( Double ) inputGains . elementAt ( i ) ) . doubleValue ( ) ; } for ( int i = <NUM_LIT:0> ; i < outputs . size ( ) ; i ++ ) { retVal += outputs . elementAt ( i ) * ( ( Double ) outputGains . elementAt ( i ) ) . doubleValue ( ) ; } if ( outputs . size ( ) > <NUM_LIT:0> ) { outputs . increment ( ) ; outputs . setElementAt ( retVal , <NUM_LIT:0> ) ; } return retVal ; } } </s>
<s> package edu . missdaisy ; import edu . wpi . first . wpilibj . util . BoundaryException ; public class SynchronousPID { private double m_P ; private double m_I ; private double m_D ; private double m_maximumOutput = <NUM_LIT:1.0> ; private double m_minimumOutput = - <NUM_LIT:1.0> ; private double m_maximumInput = <NUM_LIT:0.0> ; private double m_minimumInput = <NUM_LIT:0.0> ; private boolean m_continuous = false ; private boolean m_enabled = false ; private double m_prevError = <NUM_LIT:0.0> ; private double m_totalError = <NUM_LIT:0.0> ; private double m_setpoint = <NUM_LIT:0.0> ; private double m_error = <NUM_LIT:0.0> ; private double m_result = <NUM_LIT:0.0> ; private double m_last_input = <NUM_LIT:0.0> ; public SynchronousPID ( double Kp , double Ki , double Kd ) { m_P = Kp ; m_I = Ki ; m_D = Kd ; } public synchronized double calculate ( double input , double time ) { m_last_input = input ; if ( m_enabled ) { m_error = m_setpoint - input ; if ( m_continuous ) { if ( Math . abs ( m_error ) > ( m_maximumInput - m_minimumInput ) / <NUM_LIT:2> ) { if ( m_error > <NUM_LIT:0> ) { m_error = m_error - m_maximumInput + m_minimumInput ; } else { m_error = m_error + m_maximumInput - m_minimumInput ; } } } if ( ( ( m_totalError + m_error ) * m_I < m_maximumOutput ) && ( ( m_totalError + m_error ) * m_I > m_minimumOutput ) ) { m_totalError += m_error ; } m_result = ( m_P * m_error + m_I * m_totalError + m_D * ( m_error - m_prevError ) ) ; m_prevError = m_error ; if ( m_result > m_maximumOutput ) { m_result = m_maximumOutput ; } else if ( m_result < m_minimumOutput ) { m_result = m_minimumOutput ; } return m_result ; } return <NUM_LIT:0> ; } public synchronized void setPID ( double p , double i , double d ) { m_P = p ; m_I = i ; m_D = d ; } public double getP ( ) { return m_P ; } public double getI ( ) { return m_I ; } public synchronized double getD ( ) { return m_D ; } public synchronized double get ( ) { return m_result ; } public synchronized void setContinuous ( boolean continuous ) { m_continuous = continuous ; } public synchronized void setContinuous ( ) { this . setContinuous ( true ) ; } public synchronized void setInputRange ( double minimumInput , double maximumInput ) { if ( minimumInput > maximumInput ) { throw new BoundaryException ( "<STR_LIT>" ) ; } m_minimumInput = minimumInput ; m_maximumInput = maximumInput ; setSetpoint ( m_setpoint ) ; } public synchronized void setOutputRange ( double minimumOutput , double maximumOutput ) { if ( minimumOutput > maximumOutput ) { throw new BoundaryException ( "<STR_LIT>" ) ; } m_minimumOutput = minimumOutput ; m_maximumOutput = maximumOutput ; } public synchronized void setSetpoint ( double setpoint ) { if ( m_maximumInput > m_minimumInput ) { if ( setpoint > m_maximumInput ) { m_setpoint = m_maximumInput ; } else if ( setpoint < m_minimumInput ) { m_setpoint = m_minimumInput ; } else { m_setpoint = setpoint ; } } else { m_setpoint = setpoint ; } } public synchronized double getSetpoint ( ) { return m_setpoint ; } public synchronized double getError ( ) { return m_error ; } public synchronized boolean onTarget ( double tolerance ) { if ( Math . abs ( m_last_input - m_setpoint ) < tolerance ) { return true ; } else { return false ; } } public synchronized void enable ( ) { m_enabled = true ; } public synchronized void disable ( ) { m_result = <NUM_LIT:0> ; m_enabled = false ; } public synchronized boolean isEnabled ( ) { return m_enabled ; } public synchronized void reset ( ) { disable ( ) ; m_last_input = <NUM_LIT:0> ; m_prevError = <NUM_LIT:0> ; m_totalError = <NUM_LIT:0> ; m_result = <NUM_LIT:0> ; m_setpoint = <NUM_LIT:0> ; } } </s>
<s> package edu . wpi . first . wpilibj . templates ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Jaguar ; import edu . wpi . first . wpilibj . Victor ; import edu . wpi . first . wpilibj . BeachbotEncoder ; import edu . wpi . first . wpilibj . PIDController ; import edu . wpi . first . wpilibj . Gyro ; import edu . wpi . first . wpilibj . DriverStationLCD ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . Solenoid ; public class Beachbot2009 extends IterativeRobot { private RobotDrive drivetrain ; private Jaguar turntable ; private Victor pickup ; private Victor dumperA ; private Victor dumperB ; private Joystick steeringWheel ; private Joystick driverJoystick ; private Joystick operatorJoystick ; private BeachbotEncoder turntableEncoder ; private PIDController turntableController ; private Gyro baseGyro ; private PIDController baseGyroController ; private DriverStationLCD driverStationLCD ; private int autoMode = <NUM_LIT:0> ; static final int numAutoModes = <NUM_LIT:2> ; private boolean prevButton4 = false ; private boolean prevButton5 = false ; private double autoTimer = <NUM_LIT:0> ; public void robotInit ( ) { final double TURNTABLEWHEEL = <NUM_LIT> ; final int TURNTABLEWHEELGEARRATIO = <NUM_LIT> ; final int TURNTABLEENCODERGEARRATIO = <NUM_LIT:2> ; final double TURNTABLEFUDGEFACTOR = <NUM_LIT> ; final int TURNTABLETICKSPERREVOLUTION = <NUM_LIT> ; final int DEGREESPERREVOLUTION = <NUM_LIT> ; drivetrain = new RobotDrive ( <NUM_LIT:1> , <NUM_LIT:3> ) ; turntable = new Jaguar ( <NUM_LIT:7> ) ; pickup = new Victor ( <NUM_LIT:8> ) ; dumperA = new Victor ( <NUM_LIT:9> ) ; dumperB = new Victor ( <NUM_LIT:10> ) ; steeringWheel = new Joystick ( <NUM_LIT:1> ) ; driverJoystick = new Joystick ( <NUM_LIT:2> ) ; operatorJoystick = new Joystick ( <NUM_LIT:3> ) ; turntableEncoder = new BeachbotEncoder ( <NUM_LIT:9> , <NUM_LIT:10> , false , BeachbotEncoder . EncodingType . k4X ) ; turntableController = new PIDController ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , turntableEncoder , turntable , <NUM_LIT> ) ; baseGyro = new Gyro ( <NUM_LIT:1> ) ; baseGyroController = new PIDController ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> , baseGyro , turntable , <NUM_LIT> ) ; turntableEncoder . setDistancePerPulse ( DEGREESPERREVOLUTION / ( TURNTABLEWHEELGEARRATIO / TURNTABLEWHEEL * TURNTABLEFUDGEFACTOR * TURNTABLEENCODERGEARRATIO * TURNTABLETICKSPERREVOLUTION ) ) ; turntableEncoder . start ( ) ; turntableController . setSetpoint ( <NUM_LIT:0> ) ; turntableController . setOutputRange ( - <NUM_LIT> , <NUM_LIT> ) ; baseGyro . setSensitivity ( <NUM_LIT> ) ; baseGyro . reset ( ) ; baseGyroController . setSetpoint ( <NUM_LIT:0> ) ; baseGyroController . setOutputRange ( - <NUM_LIT> , <NUM_LIT> ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kUser2 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kUser3 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kUser4 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kUser5 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; } public void autonomousInit ( ) { turntableController . disable ( ) ; baseGyroController . enable ( ) ; drivetrain . arcadeDrive ( <NUM_LIT:0> , <NUM_LIT:0> ) ; pickup . set ( <NUM_LIT:0> ) ; dumperA . set ( <NUM_LIT:0> ) ; dumperB . set ( <NUM_LIT:0> ) ; autoTimer = <NUM_LIT:0> ; } public void autonomousPeriodic ( ) { if ( autoMode == <NUM_LIT:1> ) { if ( autoTimer < <NUM_LIT> ) { baseGyroController . setSetpoint ( <NUM_LIT> ) ; drivetrain . arcadeDrive ( <NUM_LIT:1> , <NUM_LIT:0> ) ; } else if ( autoTimer >= <NUM_LIT> && autoTimer <= <NUM_LIT> ) { } else if ( autoTimer >= <NUM_LIT> && autoTimer <= <NUM_LIT> ) { drivetrain . arcadeDrive ( <NUM_LIT> , <NUM_LIT:0> , false ) ; } else { baseGyroController . setSetpoint ( <NUM_LIT:0> ) ; drivetrain . arcadeDrive ( <NUM_LIT:0> , <NUM_LIT:0> ) ; } } autoTimer += <NUM_LIT:1> / getLoopsPerSec ( ) ; sendDashboardData ( ) ; } public void disabledPeriodic ( ) { if ( steeringWheel . getRawButton ( <NUM_LIT:4> ) && prevButton4 ) autoMode ++ ; if ( steeringWheel . getRawButton ( <NUM_LIT:5> ) && prevButton5 ) autoMode ++ ; prevButton4 = steeringWheel . getRawButton ( <NUM_LIT:4> ) ; prevButton5 = steeringWheel . getRawButton ( <NUM_LIT:5> ) ; if ( autoMode < <NUM_LIT:0> ) autoMode = numAutoModes - <NUM_LIT:1> ; if ( autoMode >= numAutoModes ) autoMode = <NUM_LIT:0> ; if ( autoMode == <NUM_LIT:0> ) DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; else if ( autoMode == <NUM_LIT:1> ) DriverStationLCD . getInstance ( ) . println ( DriverStationLCD . Line . kMain6 , <NUM_LIT:1> , "<STR_LIT>" ) ; DriverStationLCD . getInstance ( ) . updateLCD ( ) ; sendDashboardData ( ) ; } public void teleopInit ( ) { baseGyroController . disable ( ) ; turntableController . enable ( ) ; drivetrain . arcadeDrive ( <NUM_LIT:0> , <NUM_LIT:0> ) ; pickup . set ( <NUM_LIT:0> ) ; dumperA . set ( <NUM_LIT:0> ) ; dumperB . set ( <NUM_LIT:0> ) ; } public void teleopPeriodic ( ) { drivetrain . arcadeDrive ( driverJoystick , false ) ; turntableController . setSetpoint ( steeringWheel . getX ( ) * <NUM_LIT> ) ; if ( operatorJoystick . getRawButton ( <NUM_LIT:4> ) || driverJoystick . getRawButton ( <NUM_LIT:4> ) ) { pickup . set ( <NUM_LIT:1.0> ) ; } else if ( operatorJoystick . getRawButton ( <NUM_LIT:5> ) || driverJoystick . getRawButton ( <NUM_LIT:5> ) ) { pickup . set ( - <NUM_LIT:1.0> ) ; } else { pickup . set ( <NUM_LIT:0> ) ; } if ( operatorJoystick . getRawButton ( <NUM_LIT:1> ) || driverJoystick . getRawButton ( <NUM_LIT:1> ) ) { dumperA . set ( <NUM_LIT:1.0> ) ; dumperB . set ( <NUM_LIT:1.0> ) ; } else if ( operatorJoystick . getRawButton ( <NUM_LIT:3> ) || driverJoystick . getRawButton ( <NUM_LIT:3> ) ) { dumperA . set ( - <NUM_LIT:1.0> ) ; dumperB . set ( - <NUM_LIT:1.0> ) ; } else { dumperA . set ( <NUM_LIT:0> ) ; dumperB . set ( <NUM_LIT:0> ) ; } if ( driverJoystick . getRawButton ( <NUM_LIT:2> ) ) { turntableEncoder . reset ( ) ; } sendDashboardData ( ) ; } private void buildPIDDashboard ( Dashboard dashboard , PIDController pid ) { double setpoint = <NUM_LIT:0> ; double output = <NUM_LIT:0> ; boolean stable = false ; double p = <NUM_LIT:0> ; double i = <NUM_LIT:0> ; double d = <NUM_LIT:0> ; if ( pid != null ) { setpoint = pid . getSetpoint ( ) ; output = pid . get ( ) ; stable = pid . onTarget ( ) ; p = pid . getP ( ) ; i = pid . getI ( ) ; d = pid . getD ( ) ; } dashboard . addCluster ( ) ; { dashboard . addDouble ( setpoint ) ; dashboard . addDouble ( output ) ; dashboard . addBoolean ( false ) ; dashboard . addDouble ( <NUM_LIT:10> ) ; dashboard . addDouble ( <NUM_LIT:11> ) ; dashboard . addDouble ( <NUM_LIT:12> ) ; dashboard . addBoolean ( stable ) ; dashboard . addCluster ( ) ; { dashboard . addCluster ( ) ; { dashboard . addDouble ( p ) ; dashboard . addDouble ( i ) ; dashboard . addDouble ( d ) ; } dashboard . finalizeCluster ( ) ; dashboard . addDouble ( <NUM_LIT> ) ; dashboard . addDouble ( <NUM_LIT> ) ; } dashboard . finalizeCluster ( ) ; } dashboard . finalizeCluster ( ) ; } private void buildCameraDashboard ( Dashboard dashboard ) { dashboard . addCluster ( ) ; { dashboard . addCluster ( ) ; { dashboard . addInt ( <NUM_LIT:1> ) ; dashboard . addInt ( <NUM_LIT:2> ) ; dashboard . addInt ( <NUM_LIT:3> ) ; dashboard . addInt ( <NUM_LIT:4> ) ; } dashboard . finalizeCluster ( ) ; dashboard . addDouble ( <NUM_LIT:5> ) ; dashboard . addArray ( ) ; { dashboard . addDouble ( <NUM_LIT:6> ) ; } dashboard . finalizeArray ( ) ; dashboard . addShort ( ( short ) <NUM_LIT:0> ) ; } dashboard . finalizeCluster ( ) ; } public void sendDashboardData ( ) { Dashboard dash = DriverStation . getInstance ( ) . getDashboardPacker ( ) ; dash . addCluster ( ) ; { dash . addCluster ( ) ; { dash . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { dash . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } dash . finalizeCluster ( ) ; dash . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { dash . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; dash . addCluster ( ) ; { dash . addCluster ( ) ; { dash . addCluster ( ) ; { int module = <NUM_LIT:4> ; dash . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; dash . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; dash . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; dash . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; dash . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { dash . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; dash . addCluster ( ) ; { dash . addCluster ( ) ; { int module = <NUM_LIT:6> ; dash . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; dash . addByte ( DigitalModule . getInstance ( module ) . getRelayReverse ( ) ) ; dash . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; dash . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; dash . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { dash . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; } dash . finalizeCluster ( ) ; dash . addByte ( Solenoid . getAll ( ) ) ; } dash . finalizeCluster ( ) ; buildPIDDashboard ( dash , null ) ; buildPIDDashboard ( dash , null ) ; buildPIDDashboard ( dash , turntableController ) ; buildPIDDashboard ( dash , null ) ; buildPIDDashboard ( dash , null ) ; buildCameraDashboard ( dash ) ; dash . commit ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj ; public class BeachbotEncoder extends Encoder implements PIDSource { public BeachbotEncoder ( final int aSlot , final int aChannel , final int bSlot , final int bChannel , boolean reverseDirection ) { super ( aSlot , aChannel , bSlot , bChannel , reverseDirection ) ; } public BeachbotEncoder ( final int aSlot , final int aChannel , final int bSlot , final int bChannel ) { this ( aSlot , aChannel , bSlot , bChannel , false ) ; } public BeachbotEncoder ( final int aSlot , final int aChannel , final int bSlot , final int bChannel , boolean reverseDirection , final EncodingType encodingType ) { super ( aSlot , aChannel , bSlot , bChannel , reverseDirection , encodingType ) ; } public BeachbotEncoder ( final int aSlot , final int aChannel , final int bSlot , final int bChannel , final int indexSlot , final int indexChannel , boolean reverseDirection ) { super ( aSlot , aChannel , bSlot , bChannel , indexSlot , indexChannel , reverseDirection ) ; } public BeachbotEncoder ( final int aSlot , final int aChannel , final int bSlot , final int bChannel , final int indexSlot , final int indexChannel ) { this ( aSlot , aChannel , bSlot , bChannel , indexSlot , indexChannel , false ) ; } public BeachbotEncoder ( final int aChannel , final int bChannel , boolean reverseDirection ) { super ( aChannel , bChannel , reverseDirection ) ; } public BeachbotEncoder ( final int aChannel , final int bChannel ) { this ( aChannel , bChannel , false ) ; } public BeachbotEncoder ( final int aChannel , final int bChannel , boolean reverseDirection , final EncodingType encodingType ) { super ( aChannel , bChannel , reverseDirection , encodingType ) ; } public BeachbotEncoder ( final int aChannel , final int bChannel , final int indexChannel , boolean reverseDirection ) { super ( aChannel , bChannel , indexChannel , reverseDirection ) ; } public BeachbotEncoder ( final int aChannel , final int bChannel , final int indexChannel ) { this ( aChannel , bChannel , indexChannel , false ) ; } public BeachbotEncoder ( DigitalSource aSource , DigitalSource bSource , boolean reverseDirection ) { super ( aSource , bSource , reverseDirection ) ; } public BeachbotEncoder ( DigitalSource aSource , DigitalSource bSource ) { this ( aSource , bSource , false ) ; } public BeachbotEncoder ( DigitalSource aSource , DigitalSource bSource , boolean reverseDirection , final EncodingType encodingType ) { super ( aSource , bSource , reverseDirection , encodingType ) ; } public BeachbotEncoder ( DigitalSource aSource , DigitalSource bSource , DigitalSource indexSource , boolean reverseDirection ) { super ( aSource , bSource , indexSource , reverseDirection ) ; } public BeachbotEncoder ( DigitalSource aSource , DigitalSource bSource , DigitalSource indexSource ) { this ( aSource , bSource , indexSource , false ) ; } public double pidGet ( ) { return getDistance ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . samples ; import edu . wpi . first . wpilibj . Gyro ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . PIDController ; import edu . wpi . first . wpilibj . PIDOutput ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; import edu . wpi . first . wpilibj . camera . AxisCamera ; import edu . wpi . first . wpilibj . camera . AxisCameraException ; import edu . wpi . first . wpilibj . image . ColorImage ; import edu . wpi . first . wpilibj . image . NIVisionException ; public class CircleTrackerDemo extends IterativeRobot { double kScoreThreshold = <NUM_LIT> ; AxisCamera cam ; Gyro gyro = new Gyro ( <NUM_LIT:1> ) ; RobotDrive drive = new RobotDrive ( <NUM_LIT:1> , <NUM_LIT:2> ) ; { drive . setInvertedMotor ( RobotDrive . MotorType . kRearLeft , true ) ; drive . setInvertedMotor ( RobotDrive . MotorType . kRearRight , true ) ; } Joystick js = new Joystick ( <NUM_LIT:1> ) ; PIDController turnController = new PIDController ( <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , gyro , new PIDOutput ( ) { public void pidWrite ( double output ) { drive . arcadeDrive ( <NUM_LIT:0> , output ) ; } } , <NUM_LIT> ) ; TrackerDashboard trackerDashboard = new TrackerDashboard ( ) ; public void robotInit ( ) { Timer . delay ( <NUM_LIT> ) ; getWatchdog ( ) . setExpiration ( <NUM_LIT> ) ; cam = AxisCamera . getInstance ( ) ; cam . writeResolution ( AxisCamera . ResolutionT . k320x240 ) ; cam . writeBrightness ( <NUM_LIT:0> ) ; gyro . setSensitivity ( <NUM_LIT> ) ; turnController . setInputRange ( - <NUM_LIT> , <NUM_LIT> ) ; turnController . setTolerance ( <NUM_LIT:1> / <NUM_LIT> * <NUM_LIT:100> ) ; turnController . disable ( ) ; } public void autonomousPeriodic ( ) { } public void disabledPeriodic ( ) { } public void teleopInit ( ) { } boolean lastTrigger = false ; public void teleopPeriodic ( ) { long startTime = Timer . getUsClock ( ) ; if ( ! js . getTrigger ( ) ) { if ( lastTrigger ) { turnController . disable ( ) ; } lastTrigger = false ; drive . arcadeDrive ( js ) ; } else { if ( ! lastTrigger ) { turnController . enable ( ) ; turnController . setSetpoint ( gyro . pidGet ( ) ) ; } lastTrigger = true ; ColorImage image = null ; try { if ( cam . freshImage ( ) ) { double gyroAngle = gyro . pidGet ( ) ; image = cam . getImage ( ) ; Thread . yield ( ) ; Target [ ] targets = Target . findCircularTargets ( image ) ; Thread . yield ( ) ; if ( targets . length == <NUM_LIT:0> || targets [ <NUM_LIT:0> ] . m_score < kScoreThreshold ) { System . out . println ( "<STR_LIT>" ) ; Target [ ] newTargets = new Target [ targets . length + <NUM_LIT:1> ] ; newTargets [ <NUM_LIT:0> ] = new Target ( ) ; newTargets [ <NUM_LIT:0> ] . m_majorRadius = <NUM_LIT:0> ; newTargets [ <NUM_LIT:0> ] . m_minorRadius = <NUM_LIT:0> ; newTargets [ <NUM_LIT:0> ] . m_score = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < targets . length ; i ++ ) { newTargets [ i + <NUM_LIT:1> ] = targets [ i ] ; } trackerDashboard . updateVisionDashboard ( <NUM_LIT:0.0> , gyro . getAngle ( ) , <NUM_LIT:0.0> , <NUM_LIT:0.0> , newTargets ) ; } else { System . out . println ( targets [ <NUM_LIT:0> ] ) ; System . out . println ( "<STR_LIT>" + targets [ <NUM_LIT:0> ] . getHorizontalAngle ( ) ) ; turnController . setSetpoint ( gyroAngle + targets [ <NUM_LIT:0> ] . getHorizontalAngle ( ) ) ; trackerDashboard . updateVisionDashboard ( <NUM_LIT:0.0> , gyro . getAngle ( ) , <NUM_LIT:0.0> , targets [ <NUM_LIT:0> ] . m_xPos / targets [ <NUM_LIT:0> ] . m_xMax , targets ) ; } } } catch ( NIVisionException ex ) { ex . printStackTrace ( ) ; } catch ( AxisCameraException ex ) { ex . printStackTrace ( ) ; } finally { try { if ( image != null ) { image . free ( ) ; } } catch ( NIVisionException ex ) { } } System . out . println ( "<STR_LIT>" + ( Timer . getUsClock ( ) - startTime ) / <NUM_LIT> ) ; System . out . println ( "<STR_LIT>" + gyro . getAngle ( ) ) ; } } } </s>
<s> package edu . wpi . first . wpilibj . samples ; import com . sun . squawk . platform . posix . natives . Time ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . Solenoid ; import java . util . Date ; import java . util . Timer ; import java . util . TimerTask ; public class TrackerDashboard { public TrackerDashboard ( ) { Timer dashTimer = new Timer ( ) ; dashTimer . schedule ( new TimerTask ( ) { public void run ( ) { updateDefaultDashboard ( ) ; } } , <NUM_LIT:0> , <NUM_LIT:100> ) ; } void updateDefaultDashboard ( ) { Dashboard lowDashData = DriverStation . getInstance ( ) . getDashboardPackerLow ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:4> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:6> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayReverse ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addByte ( Solenoid . getAll ( ) ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . commit ( ) ; } Date time = new Date ( ) ; public void updateVisionDashboard ( double joyStickX , double gyroAngle , double gyroRate , double targetX , Target [ ] targets ) { Dashboard highDashData = DriverStation . getInstance ( ) . getDashboardPackerHigh ( ) ; highDashData . addCluster ( ) ; { highDashData . addCluster ( ) ; { highDashData . addDouble ( joyStickX ) ; highDashData . addDouble ( ( ( gyroAngle + <NUM_LIT> + <NUM_LIT> ) % <NUM_LIT> ) - <NUM_LIT> ) ; highDashData . addDouble ( gyroRate ) ; highDashData . addDouble ( targetX ) ; } highDashData . finalizeCluster ( ) ; highDashData . addCluster ( ) ; { highDashData . addArray ( ) ; { for ( int i = <NUM_LIT:0> ; i < targets . length ; i ++ ) { highDashData . addCluster ( ) ; { highDashData . addDouble ( targets [ i ] . m_score ) ; highDashData . addCluster ( ) ; { highDashData . addCluster ( ) ; { highDashData . addFloat ( ( float ) ( targets [ i ] . m_xPos / targets [ i ] . m_xMax ) ) ; highDashData . addFloat ( ( float ) targets [ i ] . m_yPos ) ; } highDashData . finalizeCluster ( ) ; highDashData . addDouble ( targets [ i ] . m_rotation ) ; highDashData . addDouble ( targets [ i ] . m_majorRadius ) ; highDashData . addDouble ( targets [ i ] . m_minorRadius ) ; highDashData . addDouble ( targets [ i ] . m_rawScore ) ; } highDashData . finalizeCluster ( ) ; } highDashData . finalizeCluster ( ) ; } } highDashData . finalizeArray ( ) ; highDashData . addInt ( ( int ) time . getTime ( ) ) ; } highDashData . finalizeCluster ( ) ; } highDashData . finalizeCluster ( ) ; highDashData . commit ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . samples ; import com . sun . squawk . util . MathUtils ; import edu . wpi . first . wpilibj . image . ColorImage ; import edu . wpi . first . wpilibj . image . CurveOptions ; import edu . wpi . first . wpilibj . image . EllipseDescriptor ; import edu . wpi . first . wpilibj . image . EllipseMatch ; import edu . wpi . first . wpilibj . image . MonoImage ; import edu . wpi . first . wpilibj . image . NIVisionException ; import edu . wpi . first . wpilibj . image . ShapeDetectionOptions ; import edu . wpi . first . wpilibj . util . SortedVector ; public class Target { public double m_majorRadius ; public double m_minorRadius ; public double m_xPos ; public double m_yPos ; public double m_score ; public double m_rawScore ; public double m_rotation ; public boolean m_bothFound ; public double m_xMax ; Target ( ) { } public double getHorizontalAngle ( ) { double x = m_xPos ; x = ( x * <NUM_LIT> / m_xMax ) ; x = MathUtils . atan2 ( x , <NUM_LIT> ) ; x = x * <NUM_LIT> / Math . PI ; return x ; } public String toString ( ) { return "<STR_LIT>" + "<STR_LIT>" + m_xPos + "<STR_LIT>" + m_yPos + "<STR_LIT:n>" + "<STR_LIT>" + m_majorRadius + "<STR_LIT>" + m_minorRadius + "<STR_LIT:n>" + "<STR_LIT>" + m_rotation + "<STR_LIT>" + m_score + "<STR_LIT>" + m_bothFound + "<STR_LIT:n>" ; } static EllipseDescriptor ellipseDescriptor = new EllipseDescriptor ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:100> ) ; static CurveOptions curveOptions = new CurveOptions ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT:1> , <NUM_LIT:0> ) ; static ShapeDetectionOptions shapeOptions = new ShapeDetectionOptions ( ShapeDetectionOptions . IMAQ_GEOMETRIC_MATCH_SHIFT_INVARIANT , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ; public static Target [ ] findCircularTargets ( ColorImage image ) throws NIVisionException { int width = image . getWidth ( ) ; int height = image . getHeight ( ) ; MonoImage lumPlane = image . getLuminancePlane ( ) ; EllipseMatch [ ] results = lumPlane . detectEllipses ( ellipseDescriptor , curveOptions , shapeOptions , null ) ; lumPlane . free ( ) ; SortedVector . Comparator targetComparator = new SortedVector . Comparator ( ) { public int compare ( Object target1 , Object target2 ) { if ( ( ( Target ) target1 ) . m_score > ( ( Target ) target2 ) . m_score ) { return <NUM_LIT:1> ; } if ( ( ( Target ) target1 ) . m_score < ( ( Target ) target2 ) . m_score ) { return - <NUM_LIT:1> ; } return <NUM_LIT:0> ; } } ; SortedVector sortedTargetList = new SortedVector ( targetComparator ) ; SortedVector combinedTargetList = new SortedVector ( targetComparator ) ; for ( int i = <NUM_LIT:0> ; i < results . length ; i ++ ) { Target target = new Target ( ) ; target . m_rawScore = results [ i ] . m_score ; target . m_score = ( results [ i ] . m_majorRadius * results [ i ] . m_minorRadius ) / ( <NUM_LIT> - results [ i ] . m_score ) / ( height * width ) * <NUM_LIT:100> ; target . m_majorRadius = results [ i ] . m_majorRadius / height ; target . m_minorRadius = results [ i ] . m_minorRadius / height ; target . m_xPos = ( <NUM_LIT> * results [ i ] . m_xPos - width ) / height ; target . m_yPos = ( <NUM_LIT> * results [ i ] . m_yPos - height ) / height ; target . m_rotation = results [ i ] . m_rotation ; target . m_bothFound = false ; target . m_xMax = ( double ) width / height ; sortedTargetList . addElement ( target ) ; } while ( ! sortedTargetList . isEmpty ( ) ) { Target firstTarget = ( Target ) sortedTargetList . elementAt ( <NUM_LIT:0> ) ; for ( int i = <NUM_LIT:1> ; i < sortedTargetList . size ( ) ; i ++ ) { Target otherTarget = ( Target ) sortedTargetList . elementAt ( i ) ; if ( ( Math . abs ( firstTarget . m_xPos - otherTarget . m_xPos ) < Math . min ( firstTarget . m_minorRadius , otherTarget . m_minorRadius ) ) && ( Math . abs ( firstTarget . m_yPos - otherTarget . m_yPos ) < Math . min ( firstTarget . m_majorRadius , otherTarget . m_majorRadius ) ) ) { firstTarget . m_xPos = ( firstTarget . m_xPos + otherTarget . m_xPos ) / <NUM_LIT:2> ; firstTarget . m_yPos = ( firstTarget . m_yPos + otherTarget . m_yPos ) / <NUM_LIT:2> ; firstTarget . m_rawScore += otherTarget . m_rawScore ; firstTarget . m_score += otherTarget . m_score ; firstTarget . m_majorRadius = Math . max ( firstTarget . m_majorRadius , otherTarget . m_majorRadius ) ; firstTarget . m_minorRadius = Math . max ( firstTarget . m_minorRadius , otherTarget . m_minorRadius ) ; firstTarget . m_bothFound = true ; sortedTargetList . removeElementAt ( i ) ; break ; } } sortedTargetList . removeElementAt ( <NUM_LIT:0> ) ; combinedTargetList . addElement ( firstTarget ) ; } Target [ ] toReturn = new Target [ combinedTargetList . size ( ) ] ; combinedTargetList . copyInto ( toReturn ) ; return toReturn ; } } </s>
<s> package edu . wpi . first . wpilibj . trackerdemo ; import edu . wpi . first . wpilibj . SimpleRobot ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . camera . AxisCamera ; import edu . wpi . first . wpilibj . camera . AxisCameraException ; import edu . wpi . first . wpilibj . image . BinaryImage ; import edu . wpi . first . wpilibj . image . ColorImage ; import edu . wpi . first . wpilibj . image . NIVisionException ; public class TrackerDemo extends SimpleRobot { public void autonomous ( ) { } public void operatorControl ( ) { Tracker tracker = Tracker . getInstance ( ) ; AxisCamera . getInstance ( ) . writeCompression ( <NUM_LIT:0> ) ; AxisCamera . getInstance ( ) . writeBrightness ( <NUM_LIT:10> ) ; AxisCamera . getInstance ( ) . writeResolution ( AxisCamera . ResolutionT . k160x120 ) ; Timer . delay ( <NUM_LIT> ) ; Timer timer = new Timer ( ) ; System . out . println ( "<STR_LIT>" ) ; timer . start ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { try { AxisCamera . getInstance ( ) . freshImage ( ) ; AxisCamera . getInstance ( ) . getImage ( ) . free ( ) ; Timer . delay ( <NUM_LIT> ) ; } catch ( NIVisionException e ) { } catch ( AxisCameraException e ) { } } System . out . println ( "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; timer . reset ( ) ; System . out . println ( "<STR_LIT>" ) ; timer . start ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { while ( ! AxisCamera . getInstance ( ) . freshImage ( ) ) { Timer . delay ( <NUM_LIT> ) ; } try { AxisCamera . getInstance ( ) . getImage ( ) . free ( ) ; } catch ( AxisCameraException e ) { } catch ( NIVisionException e ) { } Timer . delay ( <NUM_LIT> ) ; } System . out . println ( "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; timer . reset ( ) ; System . out . println ( "<STR_LIT>" ) ; timer . start ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { try { AxisCamera . getInstance ( ) . freshImage ( ) ; ColorImage image = AxisCamera . getInstance ( ) . getImage ( ) ; image . thresholdHSL ( <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) . free ( ) ; image . thresholdHSL ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:20> ) . free ( ) ; image . free ( ) ; Timer . delay ( <NUM_LIT> ) ; } catch ( AxisCameraException e ) { } catch ( NIVisionException e ) { } } System . out . println ( "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; timer . reset ( ) ; System . out . println ( "<STR_LIT>" ) ; timer . start ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { AxisCamera . getInstance ( ) . freshImage ( ) ; try { tracker . getTarget ( ) ; } catch ( AxisCameraException e ) { } catch ( NIVisionException e ) { } Timer . delay ( <NUM_LIT> ) ; } System . out . println ( "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; timer . reset ( ) ; while ( true ) { if ( AxisCamera . getInstance ( ) . freshImage ( ) ) { System . out . println ( "<STR_LIT>" ) ; } Target target = null ; try { target = tracker . getTarget ( ) ; } catch ( AxisCameraException e ) { } catch ( NIVisionException e ) { } if ( target != null ) { System . out . println ( target + "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" + timer . get ( ) + "<STR_LIT>" ) ; } timer . reset ( ) ; Timer . delay ( <NUM_LIT> ) ; } } } </s>
<s> package edu . wpi . first . wpilibj . trackerdemo ; import edu . wpi . first . wpilibj . image . BinaryImage ; import edu . wpi . first . wpilibj . image . ColorImage ; import edu . wpi . first . wpilibj . image . NIVisionException ; import edu . wpi . first . wpilibj . image . ParticleAnalysisReport ; public class Target { private static final double FRC_PARTICLE_TO_IMAGE_PERCENT = <NUM_LIT> ; private static final double FRC_SIZE_FACTOR = <NUM_LIT> ; private static final double FRC_MAX_IMAGE_SEPARATION = <NUM_LIT> ; private static final double FRC_ALIGNMENT_SCALE = <NUM_LIT> ; final ParticleAnalysisReport firstParticle ; final ParticleAnalysisReport secondParticle ; Target ( ParticleAnalysisReport firstParticle , ParticleAnalysisReport secondParticle ) { this . firstParticle = firstParticle ; this . secondParticle = secondParticle ; } public static class Position { public final int value ; protected static final int above_val = <NUM_LIT:0> ; protected static final int below_val = <NUM_LIT:1> ; protected static final int right_val = <NUM_LIT:2> ; protected static final int left_val = <NUM_LIT:3> ; public static final Position above = new Position ( above_val ) ; public static final Position bellow = new Position ( below_val ) ; public static final Position right = new Position ( right_val ) ; public static final Position left = new Position ( left_val ) ; private Position ( int value ) { this . value = value ; } } public static class Threshold { int plane1Low ; int plane1High ; int plane2Low ; int plane2High ; int plane3Low ; int plane3High ; public Threshold ( int plane1Low , int plane1High , int plane2Low , int plane2High , int plane3Low , int plane3High ) { this . plane1Low = plane1Low ; this . plane1High = plane1High ; this . plane2Low = plane2Low ; this . plane2High = plane2High ; this . plane3Low = plane3Low ; this . plane3High = plane3High ; } } private static boolean aligned ( int center1 , int center2 , int dimension1 , int dimension2 ) { double averageWidth = ( dimension1 + dimension2 ) / <NUM_LIT> ; averageWidth *= FRC_ALIGNMENT_SCALE ; int centerDiff = Math . abs ( center1 - center2 ) ; if ( centerDiff < averageWidth ) { return true ; } return false ; } private static boolean adjacent ( int value1 , int value2 ) { if ( Math . abs ( value1 - value2 ) <= FRC_MAX_IMAGE_SEPARATION ) { return true ; } return false ; } private static boolean sizesRelative ( double area1 , double area2 ) { if ( ( area2 < ( area1 * FRC_SIZE_FACTOR ) ) && ( area1 < ( area2 * FRC_SIZE_FACTOR ) ) ) { return true ; } return false ; } public static Target getTarget ( ColorImage image , Position position , Threshold firstThreshold , Threshold secondThreshold ) throws NIVisionException { BinaryImage firstColor = image . thresholdHSL ( firstThreshold . plane1Low , firstThreshold . plane1High , firstThreshold . plane2Low , firstThreshold . plane2High , firstThreshold . plane3Low , firstThreshold . plane3High ) ; BinaryImage secondColor = image . thresholdHSL ( secondThreshold . plane1Low , secondThreshold . plane1High , secondThreshold . plane2Low , secondThreshold . plane2High , secondThreshold . plane3Low , secondThreshold . plane3High ) ; ParticleAnalysisReport [ ] firstColorHits = firstColor . getOrderedParticleAnalysisReports ( <NUM_LIT:3> ) ; ParticleAnalysisReport [ ] secondColorHits = secondColor . getOrderedParticleAnalysisReports ( <NUM_LIT:3> ) ; firstColor . free ( ) ; secondColor . free ( ) ; for ( int i = <NUM_LIT:0> ; i < firstColorHits . length ; i ++ ) { ParticleAnalysisReport firstTrackReport = firstColorHits [ i ] ; if ( firstTrackReport . particleToImagePercent < FRC_PARTICLE_TO_IMAGE_PERCENT ) { break ; } for ( int j = <NUM_LIT:0> ; j < secondColorHits . length ; j ++ ) { ParticleAnalysisReport secondTrackReport = secondColorHits [ j ] ; if ( secondTrackReport . particleToImagePercent < FRC_PARTICLE_TO_IMAGE_PERCENT ) { break ; } switch ( position . value ) { case Position . above_val : if ( secondTrackReport . center_mass_y < firstTrackReport . center_mass_y ) { if ( aligned ( firstTrackReport . center_mass_x , secondTrackReport . center_mass_x , firstTrackReport . boundingRectWidth , secondTrackReport . boundingRectWidth ) && adjacent ( firstTrackReport . boundingRectTop , ( secondTrackReport . boundingRectTop + secondTrackReport . boundingRectHeight ) ) && sizesRelative ( firstTrackReport . particleArea , secondTrackReport . particleArea ) ) { return new Target ( firstTrackReport , secondTrackReport ) ; } } break ; case Position . below_val : if ( secondTrackReport . center_mass_y > firstTrackReport . center_mass_y ) { if ( aligned ( firstTrackReport . center_mass_x , secondTrackReport . center_mass_x , firstTrackReport . boundingRectWidth , secondTrackReport . boundingRectWidth ) && adjacent ( ( firstTrackReport . boundingRectTop + firstTrackReport . boundingRectHeight ) , secondTrackReport . boundingRectTop ) ) { return new Target ( firstTrackReport , secondTrackReport ) ; } } break ; case Position . left_val : if ( secondTrackReport . center_mass_x < firstTrackReport . center_mass_x ) { if ( aligned ( firstTrackReport . center_mass_y , secondTrackReport . center_mass_y , firstTrackReport . boundingRectWidth , secondTrackReport . boundingRectWidth ) && adjacent ( firstTrackReport . boundingRectLeft , ( secondTrackReport . boundingRectLeft + secondTrackReport . boundingRectWidth ) ) ) { return new Target ( firstTrackReport , secondTrackReport ) ; } } break ; case Position . right_val : if ( secondTrackReport . center_mass_x > firstTrackReport . center_mass_x ) { if ( aligned ( firstTrackReport . center_mass_y , secondTrackReport . center_mass_y , firstTrackReport . boundingRectWidth , secondTrackReport . boundingRectWidth ) && adjacent ( ( firstTrackReport . boundingRectLeft + secondTrackReport . boundingRectWidth ) , secondTrackReport . boundingRectLeft ) ) { return new Target ( firstTrackReport , secondTrackReport ) ; } } break ; } } } return null ; } public double getXPosition ( ) { return ( firstParticle . center_mass_x_normalized * firstParticle . particleToImagePercent + secondParticle . center_mass_x_normalized * secondParticle . particleToImagePercent ) / getSize ( ) ; } public double getYPosition ( ) { return ( firstParticle . center_mass_y_normalized * firstParticle . particleToImagePercent + secondParticle . center_mass_y_normalized * secondParticle . particleToImagePercent ) / getSize ( ) ; } public double getSize ( ) { return firstParticle . particleToImagePercent + secondParticle . particleToImagePercent ; } public String toString ( ) { return "<STR_LIT>" + getXPosition ( ) + "<STR_LIT>" + getYPosition ( ) + "<STR_LIT>" + getSize ( ) ; } } </s>
<s> package edu . wpi . first . wpilibj . trackerdemo ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . camera . AxisCamera ; import edu . wpi . first . wpilibj . camera . AxisCameraException ; import edu . wpi . first . wpilibj . image . ColorImage ; import edu . wpi . first . wpilibj . image . NIVisionException ; public class Tracker { static Tracker instance = null ; Target . Threshold firstColor = new Target . Threshold ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> , <NUM_LIT:7> , <NUM_LIT:255> ) ; Target . Threshold secondColor = new Target . Threshold ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:255> , <NUM_LIT:7> , <NUM_LIT:255> ) ; Target . Position position = Target . Position . above ; AxisCamera camera = AxisCamera . getInstance ( ) ; public static Tracker getInstance ( ) { if ( instance == null ) { instance = new Tracker ( ) ; } return instance ; } public void setFirstColorThresholds ( int lowerHue , int upperHue , int lowerSaturation , int upperSaturation , int lowerLuminance , int upperLuminance ) { firstColor = new Target . Threshold ( lowerHue , upperHue , lowerSaturation , upperSaturation , lowerLuminance , upperLuminance ) ; } public void setSecondColorThresholds ( int lowerHue , int upperHue , int lowerSaturation , int upperSaturation , int lowerLuminance , int upperLuminance ) { secondColor = new Target . Threshold ( lowerHue , upperHue , lowerSaturation , upperSaturation , lowerLuminance , upperLuminance ) ; } public Target getTarget ( ) throws NIVisionException , AxisCameraException { while ( true ) { ColorImage image = camera . getImage ( ) ; try { return Target . getTarget ( image , position , firstColor , secondColor ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { if ( image != null ) { image . free ( ) ; } image = null ; } Timer . delay ( <NUM_LIT> ) ; } } } </s>
<s> package edu . wpi . first . wpilibj . samples ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . DriverStationEnhancedIO ; import edu . wpi . first . wpilibj . IterativeRobot ; import java . util . Timer ; import java . util . TimerTask ; public class EnhancedIOSample extends IterativeRobot { public void robotInit ( ) { } DriverStationEnhancedIO enhancedIO = DriverStation . getInstance ( ) . getEnhancedIO ( ) ; public void disabledPeriodic ( ) { } public void autonomousPeriodic ( ) { } byte ledCounter = <NUM_LIT:0> ; Timer timer ; public void teleopInit ( ) { timer = new Timer ( ) ; timer . schedule ( new TimerTask ( ) { public void run ( ) { printData ( ) ; } } , <NUM_LIT:0> , <NUM_LIT> ) ; } public void autonomousInit ( ) { if ( timer != null ) { timer . cancel ( ) ; } } public void disabledInit ( ) { if ( timer != null ) { timer . cancel ( ) ; } } boolean ledAccelerometer = false ; public synchronized void teleopPeriodic ( ) { try { double touchSlider = enhancedIO . getTouchSlider ( ) ; if ( Math . abs ( enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelX ) ) > <NUM_LIT> || Math . abs ( enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelY ) ) > <NUM_LIT> ) { ledCounter = <NUM_LIT:0> ; } if ( Math . abs ( enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelZ ) ) > <NUM_LIT> ) { System . out . println ( "<STR_LIT>" ) ; ledAccelerometer = ! ledAccelerometer ; edu . wpi . first . wpilibj . Timer . delay ( <NUM_LIT:1.0> ) ; } if ( touchSlider == - <NUM_LIT:1.0> ) { if ( ledAccelerometer ) { double accel = - enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelX ) ; if ( accel > <NUM_LIT:1.0> ) { accel = <NUM_LIT:1.0> ; } if ( accel < - <NUM_LIT:1.0> ) { accel = - <NUM_LIT:1.0> ; } enhancedIO . setLEDs ( ( byte ) ( <NUM_LIT> << ( int ) ( ( accel + <NUM_LIT:1.0> ) * <NUM_LIT> ) ) ) ; } else { enhancedIO . setLEDs ( ledCounter ) ; } } else { enhancedIO . setLEDs ( ( byte ) ( <NUM_LIT> << ( int ) ( touchSlider * <NUM_LIT> ) ) ) ; } } catch ( DriverStationEnhancedIO . EnhancedIOException ex ) { System . out . println ( ex . getMessage ( ) ) ; } } public synchronized void printData ( ) { try { System . out . println ( "<STR_LIT>" + enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelX ) + "<STR_LIT:U+0020>" + enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelY ) + "<STR_LIT:U+0020>" + enhancedIO . getAcceleration ( DriverStationEnhancedIO . tAccelChannel . kAccelZ ) ) ; System . out . println ( "<STR_LIT>" + enhancedIO . getTouchSlider ( ) ) ; ledCounter ++ ; } catch ( DriverStationEnhancedIO . EnhancedIOException ex ) { System . out . println ( ex . getMessage ( ) ) ; } } } </s>
<s> package edu . wpi . first . wpilibj . defaultCode ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Joystick ; import edu . wpi . first . wpilibj . RobotDrive ; import edu . wpi . first . wpilibj . Solenoid ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; public class DefaultRobot extends IterativeRobot { RobotDrive m_robotDrive ; DriverStation m_ds ; int m_priorPacketNumber ; int m_dsPacketsReceivedInCurrentSecond ; Joystick m_rightStick ; Joystick m_leftStick ; static final int NUM_JOYSTICK_BUTTONS = <NUM_LIT:16> ; boolean [ ] m_rightStickButtonState = new boolean [ ( NUM_JOYSTICK_BUTTONS + <NUM_LIT:1> ) ] ; boolean [ ] m_leftStickButtonState = new boolean [ ( NUM_JOYSTICK_BUTTONS + <NUM_LIT:1> ) ] ; static final int NUM_SOLENOIDS = <NUM_LIT:8> ; Solenoid [ ] m_solenoids = new Solenoid [ NUM_SOLENOIDS ] ; static final int UNINITIALIZED_DRIVE = <NUM_LIT:0> ; static final int ARCADE_DRIVE = <NUM_LIT:1> ; static final int TANK_DRIVE = <NUM_LIT:2> ; int m_driveMode ; int m_autoPeriodicLoops ; int m_disabledPeriodicLoops ; int m_telePeriodicLoops ; public DefaultRobot ( ) { System . out . println ( "<STR_LIT>" ) ; m_robotDrive = new RobotDrive ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:4> ) ; m_ds = DriverStation . getInstance ( ) ; m_priorPacketNumber = <NUM_LIT:0> ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_rightStick = new Joystick ( <NUM_LIT:1> ) ; m_leftStick = new Joystick ( <NUM_LIT:2> ) ; int buttonNum = <NUM_LIT:1> ; for ( buttonNum = <NUM_LIT:1> ; buttonNum <= NUM_JOYSTICK_BUTTONS ; buttonNum ++ ) { m_rightStickButtonState [ buttonNum ] = false ; m_leftStickButtonState [ buttonNum ] = false ; } int solenoidNum = <NUM_LIT:1> ; for ( solenoidNum = <NUM_LIT:0> ; solenoidNum < NUM_SOLENOIDS ; solenoidNum ++ ) { m_solenoids [ solenoidNum ] = new Solenoid ( solenoidNum + <NUM_LIT:1> ) ; } m_driveMode = UNINITIALIZED_DRIVE ; m_autoPeriodicLoops = <NUM_LIT:0> ; m_disabledPeriodicLoops = <NUM_LIT:0> ; m_telePeriodicLoops = <NUM_LIT:0> ; System . out . println ( "<STR_LIT>" ) ; } public void robotInit ( ) { System . out . println ( "<STR_LIT>" ) ; } public void disabledInit ( ) { m_disabledPeriodicLoops = <NUM_LIT:0> ; ClearSolenoidLEDsKITT ( ) ; } public void autonomousInit ( ) { m_autoPeriodicLoops = <NUM_LIT:0> ; ClearSolenoidLEDsKITT ( ) ; } public void teleopInit ( ) { m_telePeriodicLoops = <NUM_LIT:0> ; m_dsPacketsReceivedInCurrentSecond = <NUM_LIT:0> ; m_driveMode = UNINITIALIZED_DRIVE ; ClearSolenoidLEDsKITT ( ) ; } static int printSec = ( int ) ( ( Timer . getUsClock ( ) / <NUM_LIT> ) + <NUM_LIT:1.0> ) ; static final int startSec = ( int ) ( Timer . getUsClock ( ) / <NUM_LIT> ) ; public void disabledPeriodic ( ) { Watchdog . getInstance ( ) . feed ( ) ; m_disabledPeriodicLoops ++ ; if ( ( Timer . getUsClock ( ) / <NUM_LIT> ) > printSec ) { System . out . println ( "<STR_LIT>" + ( printSec - startSec ) + "<STR_LIT>" ) ; printSec ++ ; } } public void autonomousPeriodic ( ) { Watchdog . getInstance ( ) . feed ( ) ; m_autoPeriodicLoops ++ ; SolenoidLEDsKITT ( m_autoPeriodicLoops ) ; } public void teleopPeriodic ( ) { Watchdog . getInstance ( ) . feed ( ) ; m_telePeriodicLoops ++ ; m_dsPacketsReceivedInCurrentSecond ++ ; Solenoid [ ] firstGroup = new Solenoid [ <NUM_LIT:4> ] ; Solenoid [ ] secondGroup = new Solenoid [ <NUM_LIT:4> ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:4> ; i ++ ) { firstGroup [ i ] = m_solenoids [ i ] ; secondGroup [ i ] = m_solenoids [ i + <NUM_LIT:4> ] ; } DemonstrateJoystickButtons ( m_rightStick , m_rightStickButtonState , "<STR_LIT>" , firstGroup ) ; DemonstrateJoystickButtons ( m_leftStick , m_leftStickButtonState , "<STR_LIT>" , secondGroup ) ; if ( m_rightStick . getZ ( ) <= <NUM_LIT:0> ) { m_robotDrive . arcadeDrive ( m_rightStick , false ) ; if ( m_driveMode != ARCADE_DRIVE ) { System . out . println ( "<STR_LIT>" ) ; m_driveMode = ARCADE_DRIVE ; } } else { m_robotDrive . tankDrive ( m_leftStick , m_rightStick ) ; if ( m_driveMode != TANK_DRIVE ) { System . out . println ( "<STR_LIT>" ) ; m_driveMode = TANK_DRIVE ; } } } public void ClearSolenoidLEDsKITT ( ) { int solenoidNum = <NUM_LIT:1> ; for ( solenoidNum = <NUM_LIT:0> ; solenoidNum < NUM_SOLENOIDS ; solenoidNum ++ ) { m_solenoids [ solenoidNum ] . set ( false ) ; } } public void SolenoidLEDsKITT ( int numloops ) { final int NUM_KITT_POSITIONS = <NUM_LIT:6> ; int numloop_within_second = numloops % GetLoopsPerSec ( ) ; if ( numloop_within_second == <NUM_LIT:0> ) { m_solenoids [ <NUM_LIT:1> ] . set ( true ) ; m_solenoids [ <NUM_LIT:8> ] . set ( true ) ; m_solenoids [ <NUM_LIT:2> ] . set ( false ) ; m_solenoids [ <NUM_LIT:7> ] . set ( false ) ; } else if ( numloop_within_second == ( GetLoopsPerSec ( ) / NUM_KITT_POSITIONS ) ) { m_solenoids [ <NUM_LIT:2> ] . set ( true ) ; m_solenoids [ <NUM_LIT:7> ] . set ( true ) ; m_solenoids [ <NUM_LIT:1> ] . set ( false ) ; m_solenoids [ <NUM_LIT:8> ] . set ( false ) ; } else if ( numloop_within_second == ( GetLoopsPerSec ( ) * <NUM_LIT:2> / NUM_KITT_POSITIONS ) ) { m_solenoids [ <NUM_LIT:3> ] . set ( true ) ; m_solenoids [ <NUM_LIT:6> ] . set ( true ) ; m_solenoids [ <NUM_LIT:2> ] . set ( false ) ; m_solenoids [ <NUM_LIT:7> ] . set ( false ) ; } else if ( numloop_within_second == ( GetLoopsPerSec ( ) * <NUM_LIT:3> / NUM_KITT_POSITIONS ) ) { m_solenoids [ <NUM_LIT:4> ] . set ( true ) ; m_solenoids [ <NUM_LIT:5> ] . set ( true ) ; m_solenoids [ <NUM_LIT:3> ] . set ( false ) ; m_solenoids [ <NUM_LIT:6> ] . set ( false ) ; } else if ( numloop_within_second == ( GetLoopsPerSec ( ) * <NUM_LIT:4> / NUM_KITT_POSITIONS ) ) { m_solenoids [ <NUM_LIT:3> ] . set ( true ) ; m_solenoids [ <NUM_LIT:6> ] . set ( true ) ; m_solenoids [ <NUM_LIT:4> ] . set ( false ) ; m_solenoids [ <NUM_LIT:5> ] . set ( false ) ; } else if ( numloop_within_second == ( GetLoopsPerSec ( ) * <NUM_LIT:5> / NUM_KITT_POSITIONS ) ) { m_solenoids [ <NUM_LIT:2> ] . set ( true ) ; m_solenoids [ <NUM_LIT:7> ] . set ( true ) ; m_solenoids [ <NUM_LIT:3> ] . set ( false ) ; m_solenoids [ <NUM_LIT:6> ] . set ( false ) ; } } int GetLoopsPerSec ( ) { return <NUM_LIT> ; } public void DemonstrateJoystickButtons ( Joystick currStick , boolean [ ] buttonPreviouslyPressed , String stickString , Solenoid solenoids [ ] ) { int buttonNum = <NUM_LIT:1> ; boolean outputGenerated = false ; int numOfButtonPressed = <NUM_LIT:0> ; for ( buttonNum = <NUM_LIT:1> ; buttonNum <= NUM_JOYSTICK_BUTTONS ; buttonNum ++ ) { if ( currStick . getRawButton ( buttonNum ) ) { if ( ! buttonPreviouslyPressed [ buttonNum ] ) { if ( ! outputGenerated ) { outputGenerated = true ; System . out . println ( "<STR_LIT>" + stickString ) ; } System . out . println ( "<STR_LIT:U+0020>" + buttonNum ) ; } buttonPreviouslyPressed [ buttonNum ] = true ; if ( numOfButtonPressed == <NUM_LIT:0> ) { numOfButtonPressed = buttonNum ; } else { numOfButtonPressed = - <NUM_LIT:1> ; } } else { buttonPreviouslyPressed [ buttonNum ] = false ; } } if ( outputGenerated ) { System . out . println ( "<STR_LIT:n>" ) ; } if ( numOfButtonPressed == - <NUM_LIT:1> ) { DisplayBinaryNumberOnSolenoidLEDs ( <NUM_LIT:15> , solenoids ) ; } else { DisplayBinaryNumberOnSolenoidLEDs ( numOfButtonPressed , solenoids ) ; } } void DisplayBinaryNumberOnSolenoidLEDs ( int displayNumber , Solenoid [ ] solenoids ) { if ( displayNumber > <NUM_LIT:15> ) { displayNumber = <NUM_LIT:0> ; } solenoids [ <NUM_LIT:3> ] . set ( ( displayNumber & <NUM_LIT:1> ) != <NUM_LIT:0> ) ; solenoids [ <NUM_LIT:2> ] . set ( ( displayNumber & <NUM_LIT:2> ) != <NUM_LIT:0> ) ; solenoids [ <NUM_LIT:1> ] . set ( ( displayNumber & <NUM_LIT:4> ) != <NUM_LIT:0> ) ; solenoids [ <NUM_LIT:0> ] . set ( ( displayNumber & <NUM_LIT:8> ) != <NUM_LIT:0> ) ; } } </s>
<s> package edu . wpi . first . wpilibj . samples ; import edu . wpi . first . wpilibj . AnalogModule ; import edu . wpi . first . wpilibj . Dashboard ; import edu . wpi . first . wpilibj . DigitalModule ; import edu . wpi . first . wpilibj . DriverStation ; import edu . wpi . first . wpilibj . IterativeRobot ; import edu . wpi . first . wpilibj . Jaguar ; import edu . wpi . first . wpilibj . Solenoid ; import edu . wpi . first . wpilibj . Timer ; import edu . wpi . first . wpilibj . Watchdog ; public class DashBoardExample extends IterativeRobot { public void robotInit ( ) { Watchdog . getInstance ( ) . setEnabled ( false ) ; } public void autonomousPeriodic ( ) { } Jaguar jag = new Jaguar ( <NUM_LIT:1> ) ; double speed = - <NUM_LIT:1.0> ; public void teleopPeriodic ( ) { updateDashboard ( ) ; } void updateDashboard ( ) { Dashboard lowDashData = DriverStation . getInstance ( ) . getDashboardPackerLow ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:1> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:8> ; i ++ ) { lowDashData . addFloat ( ( float ) AnalogModule . getInstance ( <NUM_LIT:2> ) . getAverageVoltage ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:4> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addCluster ( ) ; { lowDashData . addCluster ( ) ; { int module = <NUM_LIT:6> ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayForward ( ) ) ; lowDashData . addByte ( DigitalModule . getInstance ( module ) . getRelayReverse ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getAllDIO ( ) ) ; lowDashData . addShort ( DigitalModule . getInstance ( module ) . getDIODirection ( ) ) ; lowDashData . addCluster ( ) ; { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:10> ; i ++ ) { lowDashData . addByte ( ( byte ) DigitalModule . getInstance ( module ) . getPWM ( i ) ) ; } } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . addByte ( Solenoid . getAll ( ) ) ; } lowDashData . finalizeCluster ( ) ; lowDashData . commit ( ) ; } } </s>
<s> public class Main { } </s>
<s> import java . io . IOException ; import java . util . ArrayList ; import com . google . gdata . util . ServiceException ; import edu . gac . arboretumweb . server . * ; import edu . gac . arboretumweb . shared . domain . * ; public class TestRetrieval { public static void main ( String [ ] args ) throws IOException , ServiceException { ArrayList < Tree > treeList = new ArrayList < Tree > ( ) ; ArrayList < Brick > brickList = new ArrayList < Brick > ( ) ; ArrayList < Bench > benchList = new ArrayList < Bench > ( ) ; SpreadsheetRetrieval sheets = new SpreadsheetRetrieval ( ) ; sheets . updateMasterLists ( ) ; treeList = sheets . getTreeMasterList ( ) ; brickList = sheets . getBrickMasterList ( ) ; benchList = sheets . getBenchMasterList ( ) ; for ( Brick brick : brickList ) { System . out . print ( brick . getSize ( ) + "<STR_LIT:U+0020>" + brick . getDonatedFor ( ) + "<STR_LIT:U+0020>" + brick . getYearDonated ( ) ) ; System . out . println ( ) ; } for ( Bench bench : benchList ) { System . out . print ( bench . getBenchType ( ) + "<STR_LIT:U+0020>" + bench . getDonatedFor ( ) + "<STR_LIT:U+0020>" + bench . getYearDonated ( ) + "<STR_LIT:U+0020>" + bench . getLongitude ( ) + "<STR_LIT:U+0020>" + bench . getLatitude ( ) ) ; System . out . println ( ) ; } for ( Tree tree : treeList ) { System . out . print ( tree . getCommonName ( ) + "<STR_LIT:U+0020>" + tree . getScientificName ( ) + "<STR_LIT:U+0020>" + tree . getYearPlanted ( ) + "<STR_LIT:U+0020>" + tree . getLongitude ( ) + "<STR_LIT:U+0020>" + tree . getLatitude ( ) ) ; System . out . println ( ) ; } } } </s>
<s> package edu . gac . arboretumweb . shared ; public class FieldVerifier { public static boolean isValidName ( String name ) { if ( name == null ) { return false ; } return name . length ( ) > <NUM_LIT:3> ; } } </s>
<s> package edu . gac . arboretumweb . shared ; import java . util . ArrayList ; import com . google . gwt . user . client . rpc . AsyncCallback ; import edu . gac . arboretumweb . shared . domain . Bench ; import edu . gac . arboretumweb . shared . domain . Brick ; import edu . gac . arboretumweb . shared . domain . Tree ; public interface MasterListRetrievalAsync { void getBenchMasterList ( AsyncCallback < ArrayList < Bench > > callback ) ; void getBrickMasterList ( AsyncCallback < ArrayList < Brick > > callback ) ; void getTreeMasterList ( AsyncCallback < ArrayList < Tree > > callback ) ; } </s>
<s> package edu . gac . arboretumweb . shared . domain ; import java . io . Serializable ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; public class Bench extends DonatedObject implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; private String type ; private double longitude ; private double latitude ; private Quadrant quadrant ; public Bench ( ) { } public String getBenchType ( ) { return type ; } public void setType ( String type ) { this . type = type ; } public double getLongitude ( ) { return longitude ; } public void setLongitude ( double longitude ) { this . longitude = longitude ; } public double getLatitude ( ) { return latitude ; } public void setLatitude ( double d ) { this . latitude = d ; } public void setQuadrant ( ) { double latitude = this . getLatitude ( ) ; double longitude = this . getLongitude ( ) ; if ( latitude < <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . B ; } else if ( latitude < <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . A ; } else if ( latitude < <NUM_LIT> && longitude >= - <NUM_LIT> ) { this . quadrant = Quadrant . D ; } else if ( latitude >= <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . C ; } else this . quadrant = Quadrant . E ; } public Quadrant getQuadrant ( ) { return quadrant ; } } </s>
<s> package edu . gac . arboretumweb . shared . domain ; import java . io . Serializable ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; public class Tree extends DonatedObject implements Serializable { private static final long serialVersionUID = <NUM_LIT:1L> ; private String commonName ; private String scientificName ; private String yearPlanted ; private String health ; private double longitude ; private double latitude ; private String diameter ; private String donatedFor ; private Quadrant quadrant ; public Tree ( ) { } public static void main ( String [ ] args ) { } public String getCommonName ( ) { return commonName ; } public void setCommonName ( String commonName ) { this . commonName = commonName ; } public String getScientificName ( ) { return scientificName ; } public void setScientificName ( String scientificName ) { this . scientificName = scientificName ; } public String getYearPlanted ( ) { return yearPlanted ; } public void setYearPlanted ( String yearPlanted ) { this . yearPlanted = yearPlanted ; } public void setYearDonated ( String yearDonated ) { this . yearDonated = yearDonated ; } public String getHealth ( ) { return health ; } public void setHealth ( String health ) { this . health = health ; } public double getLongitude ( ) { return longitude ; } public void setLongitude ( double longitude ) { this . longitude = longitude ; } public double getLatitude ( ) { return latitude ; } public void setLatitude ( double latitude ) { this . latitude = latitude ; } public String getDiameter ( ) { return diameter ; } public void setDiameter ( String diameter ) { this . diameter = diameter ; } public String getDonatedFor ( ) { return donatedFor ; } public void setDonatedFor ( String donatedFor ) { this . donatedFor = donatedFor ; } public void setQuadrant ( ) { double latitude = this . getLatitude ( ) ; double longitude = this . getLongitude ( ) ; if ( latitude < <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . B ; } else if ( latitude < <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . A ; } else if ( latitude < <NUM_LIT> && longitude >= - <NUM_LIT> ) { this . quadrant = Quadrant . D ; } else if ( latitude >= <NUM_LIT> && longitude < - <NUM_LIT> ) { this . quadrant = Quadrant . C ; } else this . quadrant = Quadrant . E ; } public Quadrant getQuadrant ( ) { return quadrant ; } } </s>
<s> package edu . gac . arboretumweb . shared . domain ; import java . io . Serializable ; public class Brick extends DonatedObject implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; private String size ; private String distance ; public Brick ( ) { } public String getSize ( ) { return size ; } public void setSize ( String size ) { this . size = size ; } public String getDistance ( ) { return distance ; } public void setDistance ( String distance ) { this . distance = distance ; } } </s>
<s> package edu . gac . arboretumweb . shared . domain ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; public class DonatedObject { public String yearDonated ; public String donatedFor ; public String getYearDonated ( ) { return yearDonated ; } public void setYearDonated ( String yearDonated ) { this . yearDonated = yearDonated ; } public String getDonatedFor ( ) { return donatedFor ; } public void setDonatedFor ( String donatedFor ) { this . donatedFor = donatedFor ; } public Quadrant getQuadrant ( ) { return Quadrant . E ; } } </s>
<s> package edu . gac . arboretumweb . shared ; import edu . gac . arboretumweb . shared . domain . * ; import java . io . IOException ; import java . util . * ; import com . google . gdata . util . ServiceException ; import com . google . gwt . user . client . rpc . RemoteService ; import com . google . gwt . user . client . rpc . RemoteServiceRelativePath ; @ RemoteServiceRelativePath ( "<STR_LIT>" ) public interface MasterListRetrieval extends RemoteService { ArrayList < Tree > getTreeMasterList ( ) ; ArrayList < Brick > getBrickMasterList ( ) ; ArrayList < Bench > getBenchMasterList ( ) ; } </s>
<s> package edu . gac . arboretumweb . server ; import java . io . IOException ; import java . net . MalformedURLException ; import java . net . URL ; import java . util . ArrayList ; import java . util . List ; import com . google . gdata . client . spreadsheet . SpreadsheetService ; import com . google . gdata . data . spreadsheet . ListEntry ; import com . google . gdata . data . spreadsheet . ListFeed ; import com . google . gdata . data . spreadsheet . WorksheetEntry ; import com . google . gdata . data . spreadsheet . WorksheetFeed ; import com . google . gdata . util . ServiceException ; import com . google . gwt . user . client . Timer ; import com . google . gwt . user . server . rpc . RemoteServiceServlet ; import edu . gac . arboretumweb . shared . MasterListRetrieval ; import edu . gac . arboretumweb . shared . domain . * ; public class SpreadsheetRetrieval extends RemoteServiceServlet implements MasterListRetrieval { private static final long serialVersionUID = - <NUM_LIT> ; private ArrayList < Tree > treeMasterList ; private ArrayList < Brick > brickMasterList ; private ArrayList < Bench > benchMasterList ; private URL treeURL ; public void updateMasterLists ( ) throws IOException , ServiceException { SpreadsheetService treeSpreadsheetService = new SpreadsheetService ( "<STR_LIT>" ) ; WorksheetFeed feed = treeSpreadsheetService . getFeed ( treeURL , WorksheetFeed . class ) ; List < WorksheetEntry > worksheets = feed . getEntries ( ) ; if ( worksheets . size ( ) == <NUM_LIT:0> ) { } WorksheetEntry treeWorksheet = new WorksheetEntry ( ) ; for ( WorksheetEntry worksheet : worksheets ) { if ( "<STR_LIT>" . equals ( worksheet . getTitle ( ) . getPlainText ( ) ) ) { treeWorksheet = worksheet ; } } URL listFeedUrl = treeWorksheet . getListFeedUrl ( ) ; ListFeed listFeed = treeSpreadsheetService . getFeed ( listFeedUrl , ListFeed . class ) ; this . setTreeMasterList ( new ArrayList < Tree > ( ) ) ; for ( ListEntry entry : listFeed . getEntries ( ) ) { Tree tree = new Tree ( ) ; for ( String tag : entry . getCustomElements ( ) . getTags ( ) ) { if ( "<STR_LIT>" . equals ( tag ) ) { String commonName = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setCommonName ( commonName ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String scientificName = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setScientificName ( scientificName ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String yearPlanted = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setYearPlanted ( yearPlanted ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String health = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setHealth ( health ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String stringLongitude = entry . getCustomElements ( ) . getValue ( tag ) ; if ( stringLongitude == null ) { tree . setLongitude ( <NUM_LIT:0> ) ; } else { try { Double longitude = new Double ( stringLongitude ) ; tree . setLongitude ( longitude . doubleValue ( ) ) ; } catch ( NumberFormatException e ) { } } } else if ( "<STR_LIT>" . equals ( tag ) ) { String stringLatitude = entry . getCustomElements ( ) . getValue ( tag ) ; if ( stringLatitude == null ) { tree . setLatitude ( <NUM_LIT:0> ) ; } else { try { Double latitude = new Double ( stringLatitude ) ; tree . setLatitude ( latitude . doubleValue ( ) ) ; } catch ( NumberFormatException e ) { } } } else if ( "<STR_LIT>" . equals ( tag ) ) { String diameter = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setDiameter ( diameter ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String yearDonated = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setYearDonated ( yearDonated ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String donatedFor = entry . getCustomElements ( ) . getValue ( tag ) ; tree . setDonatedFor ( donatedFor ) ; } } tree . setQuadrant ( ) ; this . treeMasterList . add ( tree ) ; } this . setBenchMasterList ( new ArrayList < Bench > ( ) ) ; if ( worksheets . size ( ) == <NUM_LIT:0> ) { } WorksheetEntry benchWorksheet = new WorksheetEntry ( ) ; for ( WorksheetEntry worksheet : worksheets ) { if ( "<STR_LIT>" . equals ( worksheet . getTitle ( ) . getPlainText ( ) ) ) { benchWorksheet = worksheet ; } } listFeedUrl = benchWorksheet . getListFeedUrl ( ) ; listFeed = treeSpreadsheetService . getFeed ( listFeedUrl , ListFeed . class ) ; for ( ListEntry entry : listFeed . getEntries ( ) ) { Bench bench = new Bench ( ) ; for ( String tag : entry . getCustomElements ( ) . getTags ( ) ) { if ( "<STR_LIT>" . equals ( tag ) ) { String benchType = entry . getCustomElements ( ) . getValue ( tag ) ; bench . setType ( benchType ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String yearDonated = entry . getCustomElements ( ) . getValue ( tag ) ; bench . setYearDonated ( yearDonated ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String stringLongitude = entry . getCustomElements ( ) . getValue ( tag ) ; if ( stringLongitude == null ) { bench . setLongitude ( <NUM_LIT:0> ) ; } else { try { Double longitude = new Double ( stringLongitude ) ; bench . setLongitude ( longitude . doubleValue ( ) ) ; } catch ( NumberFormatException e ) { } } } else if ( "<STR_LIT>" . equals ( tag ) ) { String stringLatitude = entry . getCustomElements ( ) . getValue ( tag ) ; if ( stringLatitude == null ) { bench . setLatitude ( <NUM_LIT:0> ) ; } else { try { Double latitude = new Double ( stringLatitude ) ; bench . setLatitude ( latitude . doubleValue ( ) ) ; } catch ( NumberFormatException e ) { } } } else if ( "<STR_LIT>" . equals ( tag ) ) { String donatedFor = entry . getCustomElements ( ) . getValue ( tag ) ; bench . setDonatedFor ( donatedFor ) ; } } bench . setQuadrant ( ) ; this . benchMasterList . add ( bench ) ; } this . setBrickMasterList ( new ArrayList < Brick > ( ) ) ; WorksheetEntry brickWorksheet = new WorksheetEntry ( ) ; for ( WorksheetEntry worksheet : worksheets ) { if ( "<STR_LIT>" . equals ( worksheet . getTitle ( ) . getPlainText ( ) ) ) { brickWorksheet = worksheet ; } } listFeedUrl = brickWorksheet . getListFeedUrl ( ) ; listFeed = treeSpreadsheetService . getFeed ( listFeedUrl , ListFeed . class ) ; for ( ListEntry entry : listFeed . getEntries ( ) ) { Brick brick = new Brick ( ) ; for ( String tag : entry . getCustomElements ( ) . getTags ( ) ) { if ( "<STR_LIT:size>" . equals ( tag ) ) { String brickSize = entry . getCustomElements ( ) . getValue ( tag ) ; brick . setSize ( brickSize ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String yearDonated = entry . getCustomElements ( ) . getValue ( tag ) ; brick . setYearDonated ( yearDonated ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String donatedFor = entry . getCustomElements ( ) . getValue ( tag ) ; brick . setDonatedFor ( donatedFor ) ; } else if ( "<STR_LIT>" . equals ( tag ) ) { String distance = entry . getCustomElements ( ) . getValue ( tag ) ; brick . setDistance ( distance ) ; } } this . brickMasterList . add ( brick ) ; } } public SpreadsheetRetrieval ( ) throws MalformedURLException { this . treeURL = new URL ( "<STR_LIT>" ) ; try { this . updateMasterLists ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( ServiceException e ) { e . printStackTrace ( ) ; } } public ArrayList < Tree > getTreeMasterList ( ) { return treeMasterList ; } public void setTreeMasterList ( ArrayList < Tree > treeMasterList ) { this . treeMasterList = treeMasterList ; } public ArrayList < Brick > getBrickMasterList ( ) { return brickMasterList ; } public void setBrickMasterList ( ArrayList < Brick > brickMasterList ) { this . brickMasterList = brickMasterList ; } public ArrayList < Bench > getBenchMasterList ( ) { return benchMasterList ; } public void setBenchMasterList ( ArrayList < Bench > benchMasterList ) { this . benchMasterList = benchMasterList ; } public URL getTreeURL ( ) { return treeURL ; } public void setTreeURL ( URL treeURL ) { this . treeURL = treeURL ; } } </s>
<s> package edu . gac . arboretumweb . client ; import com . google . gwt . core . client . EntryPoint ; import com . google . gwt . event . dom . client . ClickEvent ; import com . google . gwt . event . dom . client . ClickHandler ; import com . google . gwt . user . client . ui . RootPanel ; import com . google . gwt . user . client . ui . Label ; import com . google . gwt . user . client . ui . Image ; import edu . gac . arboretumweb . shared . domain . Bench ; import com . google . gwt . user . client . ui . Button ; import com . google . gwt . user . client . ui . AbsolutePanel ; public class BenchPage implements EntryPoint { Bench bench ; final RootPanel rootPanel = RootPanel . get ( ) ; Button buttonRoadMap = new Button ( "<STR_LIT>" ) ; Button buttonHybridMap = new Button ( "<STR_LIT>" ) ; Button buttonSatelliteMap = new Button ( "<STR_LIT>" ) ; Button buttonHomePage = new Button ( "<STR_LIT>" ) ; Button buttonBack = new Button ( "<STR_LIT>" ) ; Label labelYourBench = new Label ( "<STR_LIT>" ) ; Label labelDonatedFor = new Label ( "<STR_LIT>" ) ; Label labelYearDonated = new Label ( "<STR_LIT>" ) ; Label labelBenchDonor = new Label ( "<STR_LIT>" ) ; Label labelBenchGetYearDonated = new Label ( "<STR_LIT>" ) ; String zoom ; String mapType = "<STR_LIT>" ; String url = new String ( "<STR_LIT>" ) ; Image image = new Image ( ( String ) url ) ; Float benchLatitude ; Float benchLongitude ; private final AbsolutePanel absolutePanel = new AbsolutePanel ( ) ; @ Override public void onModuleLoad ( ) { show ( bench , new SearchParameter ( ) ) ; } public BenchPage ( ) { rootPanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( image ) ; image . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelYourBench , <NUM_LIT> , <NUM_LIT:0> ) ; labelYourBench . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelDonatedFor , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelBenchDonor , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelBenchGetYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( buttonHomePage , <NUM_LIT> , <NUM_LIT> ) ; buttonHomePage . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonBack , <NUM_LIT> , <NUM_LIT> ) ; buttonBack . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonRoadMap , <NUM_LIT:10> , <NUM_LIT> ) ; buttonRoadMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonHybridMap , <NUM_LIT> , <NUM_LIT> ) ; buttonHybridMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonSatelliteMap , <NUM_LIT> , <NUM_LIT> ) ; buttonSatelliteMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; buttonSatelliteMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { createMap ( bench , zoom , "<STR_LIT>" ) ; } } ) ; buttonHybridMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { createMap ( bench , zoom , "<STR_LIT>" ) ; } } ) ; buttonRoadMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { createMap ( bench , zoom , "<STR_LIT>" ) ; } } ) ; buttonHomePage . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showMainPage ( ) ; } } ) ; } public void show ( Bench bench , final SearchParameter sp ) { rootPanel . add ( absolutePanel , <NUM_LIT:0> , <NUM_LIT:0> ) ; benchLatitude = ( float ) Double . valueOf ( bench . getLatitude ( ) ) . doubleValue ( ) ; benchLongitude = ( float ) Double . valueOf ( bench . getLongitude ( ) ) . doubleValue ( ) ; zoom = checkSize ( benchLatitude , benchLongitude ) ; createMap ( bench , zoom , mapType ) ; labelBenchDonor . setText ( bench . getDonatedFor ( ) ) ; labelBenchGetYearDonated . setText ( String . valueOf ( bench . getYearDonated ( ) ) ) ; buttonBack . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showSearchResultsPage ( sp ) ; } } ) ; } private String checkSize ( Float treeLatitude , Float treeLongitude ) { if ( treeLatitude > <NUM_LIT> || treeLongitude > - <NUM_LIT> ) { return "<STR_LIT>" ; } return "<STR_LIT>" ; } private void createMap ( final Bench Bench , String zoom , String mapType ) { String url = new String ( "<STR_LIT>" + zoom + "<STR_LIT>" + mapType + "<STR_LIT>" + Bench . getLatitude ( ) + "<STR_LIT:U+002C>" + Bench . getLongitude ( ) + "<STR_LIT>" ) ; image . setUrl ( url ) ; } } </s>
<s> package edu . gac . arboretumweb . client ; import com . google . gwt . core . client . EntryPoint ; import com . google . gwt . dom . client . Style . Position ; import com . google . gwt . event . dom . client . ClickEvent ; import com . google . gwt . event . dom . client . ClickHandler ; import com . google . gwt . user . client . ui . RootPanel ; import com . google . gwt . user . client . ui . Label ; import com . google . gwt . user . client . ui . Image ; import edu . gac . arboretumweb . shared . domain . Tree ; import com . google . gwt . user . client . ui . Button ; import com . google . gwt . user . client . ui . AbsolutePanel ; public class TreePage implements EntryPoint { private Tree tree ; final RootPanel rootPanel = RootPanel . get ( ) ; AbsolutePanel absolutePanel = new AbsolutePanel ( ) ; Button buttonSatelliteMap = new Button ( "<STR_LIT>" ) ; Button buttonRoadMap = new Button ( "<STR_LIT>" ) ; Button buttonHybridMap = new Button ( "<STR_LIT>" ) ; Button buttonHomePage = new Button ( "<STR_LIT>" ) ; Button buttonBack = new Button ( "<STR_LIT>" ) ; Float treeLatitude ; Float treeLongitude ; String zoom = "<STR_LIT>" ; String mapType = "<STR_LIT>" ; String url = null ; Image image = new Image ( "<STR_LIT>" ) ; Label labelYourTree = new Label ( "<STR_LIT>" ) ; Label labelCommonName = new Label ( "<STR_LIT>" ) ; Label labelGetCommonName = new Label ( "<STR_LIT>" ) ; Label labelScientificName = new Label ( "<STR_LIT>" ) ; Label labelGetScientificName = new Label ( "<STR_LIT>" ) ; Label labelYearPlanted = new Label ( "<STR_LIT>" ) ; Label labelGetYearPlanted = new Label ( "<STR_LIT>" ) ; Label labelYearDonated = new Label ( "<STR_LIT>" ) ; Label labelGetYearDonated = new Label ( "<STR_LIT>" ) ; Label labelDonatedFor = new Label ( "<STR_LIT>" ) ; Label labelGetDonatedFor = new Label ( "<STR_LIT>" ) ; @ Override public void onModuleLoad ( ) { show ( tree , new SearchParameter ( ) ) ; } public void show ( Tree tree , final SearchParameter sp ) { treeLatitude = ( float ) Double . valueOf ( tree . getLatitude ( ) ) . doubleValue ( ) ; treeLongitude = ( float ) Double . valueOf ( tree . getLongitude ( ) ) . doubleValue ( ) ; zoom = checkSize ( treeLatitude , treeLongitude ) ; createMap ( tree , zoom ) ; rootPanel . add ( absolutePanel , <NUM_LIT:10> , <NUM_LIT:10> ) ; labelGetCommonName . setText ( tree . getCommonName ( ) ) ; labelGetScientificName . setText ( tree . getScientificName ( ) ) ; labelGetYearPlanted . setText ( tree . getYearPlanted ( ) ) ; labelGetYearDonated . setText ( tree . getYearDonated ( ) ) ; labelGetDonatedFor . setText ( tree . getDonatedFor ( ) ) ; buttonBack . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showSearchResultsPage ( sp ) ; } } ) ; } public TreePage ( ) { rootPanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; rootPanel . getElement ( ) . getStyle ( ) . setPosition ( Position . RELATIVE ) ; absolutePanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelYourTree , <NUM_LIT> , <NUM_LIT:0> ) ; absolutePanel . add ( image ) ; image . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonSatelliteMap , <NUM_LIT> , <NUM_LIT> ) ; buttonSatelliteMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonHomePage , <NUM_LIT> , <NUM_LIT> ) ; buttonHomePage . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonBack , <NUM_LIT> , <NUM_LIT> ) ; buttonBack . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonRoadMap , <NUM_LIT:10> , <NUM_LIT> ) ; buttonRoadMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( buttonHybridMap , <NUM_LIT> , <NUM_LIT> ) ; buttonHybridMap . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelCommonName , <NUM_LIT> , <NUM_LIT> ) ; labelCommonName . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelGetCommonName , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelScientificName , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetScientificName , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelYearPlanted , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetYearPlanted , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelDonatedFor , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetDonatedFor , <NUM_LIT> , <NUM_LIT> ) ; buttonHybridMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { mapType = "<STR_LIT>" ; createMap ( tree , zoom ) ; } } ) ; buttonRoadMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { mapType = "<STR_LIT>" ; createMap ( tree , zoom ) ; } } ) ; buttonHomePage . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showMainPage ( ) ; } } ) ; buttonSatelliteMap . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { mapType = "<STR_LIT>" ; createMap ( tree , zoom ) ; } } ) ; } private String checkSize ( Float treeLatitude , Float treeLongitude ) { if ( treeLatitude > <NUM_LIT> || treeLongitude > - <NUM_LIT> ) { return "<STR_LIT>" ; } return "<STR_LIT>" ; } private void createMap ( final Tree tree , String zoom ) { String url = new String ( "<STR_LIT>" + zoom + "<STR_LIT>" + mapType + "<STR_LIT>" + tree . getLatitude ( ) + "<STR_LIT:U+002C>" + tree . getLongitude ( ) + "<STR_LIT>" ) ; image . setUrl ( url ) ; } } </s>
<s> package edu . gac . arboretumweb . client ; import java . util . ArrayList ; public class SearchParameter { public enum SearchType { commonName ( "<STR_LIT>" ) , scientificName ( "<STR_LIT>" ) , donatedFor ( "<STR_LIT>" ) ; private final String name ; SearchType ( String name ) { this . name = name ; } public String toString ( ) { return name ; } } enum SearchFor { trees ( "<STR_LIT>" ) , benches ( "<STR_LIT>" ) , bricks ( "<STR_LIT>" ) ; private final String name ; SearchFor ( String name ) { this . name = name ; } public String toString ( ) { return name ; } } public enum Quadrant { A , B , C , D , E } String keywordQuery ; private SearchFor searchFor ; private SearchType searchType ; private ArrayList < Quadrant > quadrants ; private boolean undonatedBoxChecked ; public SearchParameter ( ) { ArrayList < Quadrant > quadrants = new ArrayList < Quadrant > ( ) ; quadrants . add ( Quadrant . E ) ; this . keywordQuery = "<STR_LIT>" ; this . searchFor = SearchFor . trees ; this . searchType = SearchType . commonName ; this . quadrants = quadrants ; this . undonatedBoxChecked = false ; } public SearchParameter ( String keywordQuery , SearchFor searchFor , SearchType searchType , ArrayList < Quadrant > quadrants , boolean unDonatedBoxChecked ) { this . keywordQuery = keywordQuery ; this . searchType = searchType ; this . searchFor = searchFor ; this . quadrants = quadrants ; this . undonatedBoxChecked = unDonatedBoxChecked ; } public boolean isUndonatedBoxChecked ( ) { return undonatedBoxChecked ; } public String getKeywordQuery ( ) { return keywordQuery ; } public String getSearchTypeAsString ( ) { return searchType . toString ( ) ; } public ArrayList < Quadrant > getQuadrants ( ) { return quadrants ; } public SearchType getSearchType ( ) { return searchType ; } public SearchFor getSearchFor ( ) { return searchFor ; } } </s>
<s> package edu . gac . arboretumweb . client ; import java . util . * ; import edu . gac . arboretumweb . shared . MasterListRetrieval ; import edu . gac . arboretumweb . shared . MasterListRetrievalAsync ; import edu . gac . arboretumweb . shared . domain . Bench ; import edu . gac . arboretumweb . shared . domain . Brick ; import edu . gac . arboretumweb . shared . domain . Tree ; import edu . gac . arboretumweb . client . SearchParameter ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; import com . google . gwt . core . client . * ; import com . google . gwt . user . client . rpc . AsyncCallback ; public class Searcher { private ArrayList < Bench > updatedBenchList ; private ArrayList < Brick > updatedBrickList ; private ArrayList < Tree > updatedTreeList ; private final MasterListRetrievalAsync masterListRetrieval = GWT . create ( MasterListRetrieval . class ) ; private AsyncCallback < ArrayList < Tree > > treeUpdater = new AsyncCallback < ArrayList < Tree > > ( ) { @ Override public void onFailure ( Throwable caught ) { System . out . println ( "<STR_LIT>" ) ; } @ Override public void onSuccess ( ArrayList < Tree > result ) { updatedTreeList = result ; } } ; private AsyncCallback < ArrayList < Bench > > benchUpdater = new AsyncCallback < ArrayList < Bench > > ( ) { @ Override public void onFailure ( Throwable caught ) { System . out . println ( "<STR_LIT>" ) ; } @ Override public void onSuccess ( ArrayList < Bench > result ) { updatedBenchList = result ; } } ; private AsyncCallback < ArrayList < Brick > > brickUpdater = new AsyncCallback < ArrayList < Brick > > ( ) { @ Override public void onFailure ( Throwable caught ) { System . out . println ( "<STR_LIT>" ) ; } @ Override public void onSuccess ( ArrayList < Brick > result ) { updatedBrickList = result ; } } ; public void updateLocalMasterLists ( ) { masterListRetrieval . getTreeMasterList ( treeUpdater ) ; masterListRetrieval . getBenchMasterList ( benchUpdater ) ; masterListRetrieval . getBrickMasterList ( brickUpdater ) ; } public ArrayList < Tree > searchResultsForTreeSearch ( SearchParameter sp ) { ArrayList < Tree > accumulatorList = new ArrayList < Tree > ( ) ; if ( sp . getSearchTypeAsString ( ) == null ) { return updatedTreeList ; } else if ( updatedTreeList == null ) { return accumulatorList ; } else if ( sp . getSearchTypeAsString ( ) == "<STR_LIT>" ) { for ( Tree loopTree : updatedTreeList ) { if ( ( loopTree ) . getCommonName ( ) . toLowerCase ( ) . contains ( sp . getKeywordQuery ( ) . toLowerCase ( ) ) ) { accumulatorList . add ( loopTree ) ; } } } else if ( sp . getSearchTypeAsString ( ) == "<STR_LIT>" ) { for ( Tree loopTree : updatedTreeList ) { if ( ( loopTree ) . getScientificName ( ) . toLowerCase ( ) . contains ( sp . getKeywordQuery ( ) . toLowerCase ( ) ) ) { accumulatorList . add ( loopTree ) ; } } } else if ( sp . getSearchTypeAsString ( ) == "<STR_LIT>" ) { for ( Tree loopTree : updatedTreeList ) { if ( ( loopTree ) . getDonatedFor ( ) . toLowerCase ( ) . contains ( sp . getKeywordQuery ( ) . toLowerCase ( ) ) ) { accumulatorList . add ( loopTree ) ; } } } ArrayList < Tree > newAccumList = new ArrayList < Tree > ( ) ; for ( Tree loopTree : accumulatorList ) { if ( sp . getQuadrants ( ) . contains ( Quadrant . A ) ) { System . out . println ( "<STR_LIT>" ) ; if ( loopTree . getQuadrant ( ) == Quadrant . A ) { System . out . println ( "<STR_LIT>" ) ; newAccumList . add ( loopTree ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . B ) ) { System . out . println ( "<STR_LIT>" ) ; if ( loopTree . getQuadrant ( ) == Quadrant . B ) { System . out . println ( "<STR_LIT>" ) ; newAccumList . add ( loopTree ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . C ) ) { System . out . println ( "<STR_LIT>" ) ; if ( loopTree . getQuadrant ( ) == Quadrant . C ) { System . out . println ( "<STR_LIT>" ) ; newAccumList . add ( loopTree ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . D ) ) { System . out . println ( "<STR_LIT>" ) ; if ( loopTree . getQuadrant ( ) == Quadrant . D ) { System . out . println ( "<STR_LIT>" ) ; newAccumList . add ( loopTree ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . E ) ) { System . out . println ( "<STR_LIT>" ) ; if ( loopTree . getQuadrant ( ) == Quadrant . E ) { System . out . println ( "<STR_LIT>" ) ; newAccumList . add ( loopTree ) ; } } } accumulatorList = newAccumList ; if ( sp . isUndonatedBoxChecked ( ) ) { ArrayList < Tree > newAccumList1 = new ArrayList < Tree > ( ) ; for ( Tree loopTree : accumulatorList ) { if ( loopTree . getDonatedFor ( ) == null ) { newAccumList1 . add ( loopTree ) ; } } accumulatorList = newAccumList1 ; } return accumulatorList ; } public ArrayList < Bench > searchResultsForBenchSearch ( SearchParameter sp ) { ArrayList < Bench > accumulatorList = new ArrayList < Bench > ( ) ; if ( sp . getSearchTypeAsString ( ) == null ) { return updatedBenchList ; } else if ( updatedBenchList == null ) { return accumulatorList ; } else if ( sp . getSearchTypeAsString ( ) == "<STR_LIT>" ) { for ( Bench loopBench : updatedBenchList ) { if ( loopBench . getDonatedFor ( ) . toLowerCase ( ) . contains ( sp . getKeywordQuery ( ) . toLowerCase ( ) ) ) { accumulatorList . add ( loopBench ) ; } } } ArrayList < Bench > newAccumList = new ArrayList < Bench > ( ) ; for ( Bench loopBench : accumulatorList ) { if ( sp . getQuadrants ( ) . contains ( Quadrant . A ) ) { if ( loopBench . getQuadrant ( ) == Quadrant . A ) { newAccumList . add ( loopBench ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . B ) ) { if ( loopBench . getQuadrant ( ) == Quadrant . B ) { newAccumList . add ( loopBench ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . C ) ) { if ( loopBench . getQuadrant ( ) == Quadrant . C ) { newAccumList . add ( loopBench ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . D ) ) { if ( loopBench . getQuadrant ( ) == Quadrant . D ) { newAccumList . add ( loopBench ) ; } } if ( sp . getQuadrants ( ) . contains ( Quadrant . E ) ) { if ( loopBench . getQuadrant ( ) == Quadrant . E ) { newAccumList . add ( loopBench ) ; } } } accumulatorList = newAccumList ; if ( sp . isUndonatedBoxChecked ( ) ) { ArrayList < Bench > newAccumList1 = new ArrayList < Bench > ( ) ; for ( Bench loopBench : accumulatorList ) { if ( loopBench . getDonatedFor ( ) == null ) { newAccumList1 . add ( loopBench ) ; } } accumulatorList = newAccumList1 ; } return accumulatorList ; } public ArrayList < Brick > searchResultsForBrickSearch ( SearchParameter sp ) { ArrayList < Brick > accumulatorList = new ArrayList < Brick > ( ) ; if ( sp . getSearchTypeAsString ( ) == null ) { return updatedBrickList ; } else if ( updatedBrickList == null ) { return accumulatorList ; } else if ( sp . getSearchTypeAsString ( ) == "<STR_LIT>" ) { for ( Brick loopBrick : updatedBrickList ) { if ( ( loopBrick ) . getDonatedFor ( ) . toLowerCase ( ) . contains ( sp . getKeywordQuery ( ) . toLowerCase ( ) ) ) { accumulatorList . add ( loopBrick ) ; } } } if ( sp . isUndonatedBoxChecked ( ) ) { ArrayList < Brick > newAccumList = new ArrayList < Brick > ( ) ; for ( Brick loopBrick : accumulatorList ) { if ( loopBrick . getDonatedFor ( ) == null ) { newAccumList . add ( loopBrick ) ; } } accumulatorList = newAccumList ; } return accumulatorList ; } } </s>
<s> package edu . gac . arboretumweb . client ; import java . util . ArrayList ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; import edu . gac . arboretumweb . client . SearchParameter . SearchFor ; import edu . gac . arboretumweb . client . SearchParameter . SearchType ; import com . google . gwt . core . client . EntryPoint ; import com . google . gwt . dom . client . Style . Position ; import com . google . gwt . event . dom . client . ClickEvent ; import com . google . gwt . event . dom . client . ClickHandler ; import com . google . gwt . event . dom . client . KeyUpEvent ; import com . google . gwt . event . dom . client . KeyUpHandler ; import com . google . gwt . user . client . Window ; import com . google . gwt . user . client . ui . Button ; import com . google . gwt . user . client . ui . CheckBox ; import com . google . gwt . user . client . ui . HasHorizontalAlignment ; import com . google . gwt . user . client . ui . InlineLabel ; import com . google . gwt . user . client . ui . Label ; import com . google . gwt . user . client . ui . RadioButton ; import com . google . gwt . user . client . ui . RootPanel ; import com . google . gwt . user . client . ui . TextBox ; import com . google . gwt . user . client . ui . AbsolutePanel ; public class MainPage implements EntryPoint , ClickHandler { RootPanel rootPanel = RootPanel . get ( ) ; AbsolutePanel absolutePanel = new AbsolutePanel ( ) ; final String INCONSISTENT_SEARCH_CRITERIA = "<STR_LIT>" ; final RadioButton commonNameSearchTypeRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; final RadioButton donatedForSearchTypeRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; final RadioButton scientificNameSearchTypeRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; final RadioButton benchesRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; final RadioButton treesRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; final RadioButton bricksRadioButton = new RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) ; private final CheckBox checkBoxNotYetDonated = new CheckBox ( "<STR_LIT>" ) ; CheckBox checkBoxQuadrantA = new CheckBox ( "<STR_LIT:A>" ) ; CheckBox checkBoxQuadrantB = new CheckBox ( "<STR_LIT:B>" ) ; CheckBox checkBoxQuadrantC = new CheckBox ( "<STR_LIT:C>" ) ; CheckBox checkBoxQuadrantD = new CheckBox ( "<STR_LIT:D>" ) ; CheckBox checkBoxQuadrantE = new CheckBox ( "<STR_LIT:E>" ) ; final TextBox searchField = new TextBox ( ) ; Label labelIn = new InlineLabel ( "<STR_LIT>" ) ; Label labelBy = new InlineLabel ( "<STR_LIT>" ) ; Label labelQuery = new InlineLabel ( "<STR_LIT>" ) ; Label labelHeader = new InlineLabel ( "<STR_LIT>" ) ; Label labelLocatedInQuadrant = new Label ( "<STR_LIT>" ) ; Button searchButton = new Button ( "<STR_LIT>" ) ; public void onModuleLoad ( ) { this . show ( ) ; } @ Override public void onClick ( ClickEvent event ) { } public void show ( ) { rootPanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; rootPanel . getElement ( ) . getStyle ( ) . setPosition ( Position . RELATIVE ) ; rootPanel . add ( absolutePanel , <NUM_LIT:0> , <NUM_LIT:0> ) ; absolutePanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; searchField . setText ( "<STR_LIT>" ) ; absolutePanel . add ( checkBoxQuadrantA , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( checkBoxQuadrantB , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( checkBoxQuadrantC , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( checkBoxQuadrantD , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( checkBoxQuadrantE , <NUM_LIT> , <NUM_LIT> ) ; checkBoxQuadrantA . setValue ( true ) ; checkBoxQuadrantB . setValue ( true ) ; checkBoxQuadrantC . setValue ( true ) ; checkBoxQuadrantD . setValue ( true ) ; checkBoxQuadrantE . setValue ( true ) ; checkBoxNotYetDonated . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { if ( checkBoxNotYetDonated . getValue ( ) ) { donatedForSearchTypeRadioButton . setEnabled ( false ) ; if ( donatedForSearchTypeRadioButton . getValue ( ) ) donatedForSearchTypeRadioButton . setValue ( false ) ; } if ( ! checkBoxNotYetDonated . getValue ( ) ) donatedForSearchTypeRadioButton . setEnabled ( true ) ; } } ) ; checkBoxNotYetDonated . setHTML ( "<STR_LIT>" ) ; absolutePanel . add ( checkBoxNotYetDonated , <NUM_LIT> , <NUM_LIT> ) ; checkBoxNotYetDonated . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelIn , <NUM_LIT> , <NUM_LIT> ) ; labelIn . setStyleName ( "<STR_LIT>" ) ; absolutePanel . add ( labelBy , <NUM_LIT> , <NUM_LIT> ) ; labelBy . setStyleName ( "<STR_LIT>" ) ; absolutePanel . add ( labelQuery , <NUM_LIT> , <NUM_LIT> ) ; labelQuery . setStyleName ( "<STR_LIT>" ) ; labelLocatedInQuadrant . setStyleName ( "<STR_LIT>" ) ; absolutePanel . add ( labelLocatedInQuadrant , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelHeader , <NUM_LIT> , <NUM_LIT:10> ) ; labelHeader . setHorizontalAlignment ( HasHorizontalAlignment . ALIGN_CENTER ) ; labelHeader . setStyleName ( "<STR_LIT>" ) ; labelHeader . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; class MySearchForRadioButtonHandler implements ClickHandler { public void onClick ( ClickEvent event ) { checkCurrentSearchConfiguration ( ) ; } private void checkCurrentSearchConfiguration ( ) { if ( ! bricksRadioButton . getValue ( ) && ! benchesRadioButton . getValue ( ) ) { commonNameSearchTypeRadioButton . setEnabled ( true ) ; scientificNameSearchTypeRadioButton . setEnabled ( true ) ; } else { commonNameSearchTypeRadioButton . setEnabled ( false ) ; scientificNameSearchTypeRadioButton . setEnabled ( false ) ; if ( commonNameSearchTypeRadioButton . getValue ( ) ) commonNameSearchTypeRadioButton . setValue ( false ) ; if ( scientificNameSearchTypeRadioButton . getValue ( ) ) scientificNameSearchTypeRadioButton . setValue ( false ) ; } } } absolutePanel . add ( commonNameSearchTypeRadioButton , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( donatedForSearchTypeRadioButton , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( scientificNameSearchTypeRadioButton , <NUM_LIT> , <NUM_LIT> ) ; treesRadioButton . setHTML ( "<STR_LIT>" ) ; treesRadioButton . setStyleName ( "<STR_LIT>" ) ; absolutePanel . add ( treesRadioButton , <NUM_LIT> , <NUM_LIT> ) ; bricksRadioButton . setHTML ( "<STR_LIT>" ) ; absolutePanel . add ( bricksRadioButton , <NUM_LIT> , <NUM_LIT> ) ; bricksRadioButton . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; benchesRadioButton . setHTML ( "<STR_LIT>" ) ; absolutePanel . add ( benchesRadioButton , <NUM_LIT> , <NUM_LIT> ) ; treesRadioButton . addClickHandler ( new MySearchForRadioButtonHandler ( ) ) ; benchesRadioButton . addClickHandler ( new MySearchForRadioButtonHandler ( ) ) ; bricksRadioButton . addClickHandler ( new MySearchForRadioButtonHandler ( ) ) ; class MySendButtonHandler implements ClickHandler , KeyUpHandler { public void onClick ( ClickEvent event ) { if ( checkCurrentSearchConfigurationForConsistency ( ) ) { SearchType searchBy = SearchType . commonName ; if ( commonNameSearchTypeRadioButton . getValue ( ) ) searchBy = SearchType . commonName ; if ( scientificNameSearchTypeRadioButton . getValue ( ) ) searchBy = SearchType . scientificName ; if ( donatedForSearchTypeRadioButton . getValue ( ) ) searchBy = SearchType . donatedFor ; SearchFor searchFor = SearchFor . trees ; if ( treesRadioButton . getValue ( ) ) searchFor = SearchFor . trees ; if ( benchesRadioButton . getValue ( ) ) searchFor = SearchFor . benches ; if ( bricksRadioButton . getValue ( ) ) searchFor = SearchFor . bricks ; ArrayList < Quadrant > quadrants = new ArrayList < Quadrant > ( ) ; if ( checkBoxQuadrantA . getValue ( ) ) quadrants . add ( Quadrant . A ) ; if ( checkBoxQuadrantB . getValue ( ) ) quadrants . add ( Quadrant . B ) ; if ( checkBoxQuadrantC . getValue ( ) ) quadrants . add ( Quadrant . C ) ; if ( checkBoxQuadrantD . getValue ( ) ) quadrants . add ( Quadrant . D ) ; if ( checkBoxQuadrantE . getValue ( ) ) quadrants . add ( Quadrant . E ) ; SearchParameter searchParameter = new SearchParameter ( searchField . getText ( ) , searchFor , searchBy , quadrants , checkBoxNotYetDonated . getValue ( ) ) ; rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showSearchResultsPage ( searchParameter ) ; } } private boolean checkCurrentSearchConfigurationForConsistency ( ) { System . out . println ( checkBoxQuadrantA . getValue ( ) ) ; System . out . println ( checkBoxQuadrantB . getValue ( ) ) ; System . out . println ( checkBoxQuadrantC . getValue ( ) ) ; System . out . println ( checkBoxQuadrantD . getValue ( ) ) ; System . out . println ( checkBoxQuadrantE . getValue ( ) ) ; if ( ! checkBoxQuadrantA . getValue ( ) && ! checkBoxQuadrantB . getValue ( ) && ! checkBoxQuadrantC . getValue ( ) && ! checkBoxQuadrantD . getValue ( ) && ! checkBoxQuadrantE . getValue ( ) ) { Window . alert ( "<STR_LIT>" ) ; return false ; } if ( ! benchesRadioButton . getValue ( ) && ! bricksRadioButton . getValue ( ) && ! treesRadioButton . getValue ( ) ) { Window . alert ( "<STR_LIT>" ) ; return false ; } return true ; } @ Override public void onKeyUp ( KeyUpEvent event ) { } } absolutePanel . add ( searchButton , <NUM_LIT> , <NUM_LIT> ) ; searchButton . setStyleName ( "<STR_LIT>" ) ; searchButton . addStyleName ( "<STR_LIT>" ) ; searchButton . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; searchField . setFocus ( true ) ; MySendButtonHandler handler = new MySendButtonHandler ( ) ; searchField . addKeyUpHandler ( handler ) ; searchButton . addClickHandler ( handler ) ; absolutePanel . add ( searchField , <NUM_LIT> , <NUM_LIT> ) ; } } </s>
<s> package edu . gac . arboretumweb . client ; import com . google . gwt . core . client . EntryPoint ; import com . google . gwt . dom . client . Style . Position ; import com . google . gwt . event . dom . client . ClickEvent ; import com . google . gwt . event . dom . client . ClickHandler ; import com . google . gwt . user . client . ui . RootPanel ; import com . google . gwt . user . client . ui . Label ; import edu . gac . arboretumweb . shared . domain . Brick ; import com . google . gwt . user . client . ui . Button ; import com . google . gwt . user . client . ui . AbsolutePanel ; public class BrickPage implements EntryPoint { Brick brick = new Brick ( ) ; final RootPanel rootPanel = RootPanel . get ( ) ; private final AbsolutePanel absolutePanel = new AbsolutePanel ( ) ; private final Label labelYourBrick = new Label ( "<STR_LIT>" ) ; private final Label labelDonatedFor = new Label ( "<STR_LIT>" ) ; private final Label labelYearDonated = new Label ( "<STR_LIT>" ) ; private final Label labelBrickSize = new Label ( "<STR_LIT>" ) ; private final Label labelDistance = new Label ( "<STR_LIT>" ) ; private final Label labelGetDonatedFor = new Label ( "<STR_LIT>" ) ; private final Label labelGetYearDonated = new Label ( "<STR_LIT>" ) ; private final Label labelGetSize = new Label ( "<STR_LIT>" ) ; private final Label labelGetDistance = new Label ( "<STR_LIT>" ) ; private final Button buttonHomePage = new Button ( "<STR_LIT>" ) ; private final Button buttonBack = new Button ( "<STR_LIT>" ) ; @ Override public void onModuleLoad ( ) { show ( brick , new SearchParameter ( ) ) ; } public BrickPage ( ) { rootPanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; rootPanel . getElement ( ) . getStyle ( ) . setPosition ( Position . RELATIVE ) ; absolutePanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelYourBrick , <NUM_LIT> , <NUM_LIT:10> ) ; labelYourBrick . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelDonatedFor , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelBrickSize , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelDistance , <NUM_LIT> , <NUM_LIT> ) ; labelDistance . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( labelGetDonatedFor , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetYearDonated , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetSize , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( labelGetDistance , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( buttonHomePage , <NUM_LIT> , <NUM_LIT> ) ; buttonHomePage . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; buttonHomePage . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { PageController . sharedPageController ( ) . showMainPage ( ) ; } } ) ; absolutePanel . add ( buttonBack , <NUM_LIT> , <NUM_LIT> ) ; buttonBack . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; } public void show ( Brick brick2 , final SearchParameter sp ) { rootPanel . add ( absolutePanel , <NUM_LIT:0> , <NUM_LIT:0> ) ; labelGetSize . setText ( brick . getSize ( ) ) ; labelGetYearDonated . setText ( brick . getYearDonated ( ) ) ; labelGetDonatedFor . setText ( brick . getDonatedFor ( ) ) ; labelGetDistance . setText ( brick . getDistance ( ) ) ; buttonBack . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { PageController . sharedPageController ( ) . showSearchResultsPage ( sp ) ; } } ) ; } } </s>
<s> package edu . gac . arboretumweb . client ; import java . util . ArrayList ; import com . google . gwt . cell . client . TextCell ; import com . google . gwt . core . client . EntryPoint ; import com . google . gwt . core . client . GWT ; import com . google . gwt . event . dom . client . ClickEvent ; import com . google . gwt . event . dom . client . ClickHandler ; import com . google . gwt . uibinder . client . UiField ; import com . google . gwt . user . cellview . client . Column ; import com . google . gwt . user . cellview . client . DataGrid ; import com . google . gwt . user . cellview . client . SimplePager ; import com . google . gwt . user . cellview . client . SimplePager . TextLocation ; import com . google . gwt . user . client . Window ; import com . google . gwt . user . client . ui . Label ; import com . google . gwt . user . client . ui . ListBox ; import com . google . gwt . user . client . ui . RootPanel ; import com . google . gwt . user . client . ui . TextBox ; import com . google . gwt . view . client . SelectionChangeEvent ; import com . google . gwt . view . client . SingleSelectionModel ; import edu . gac . arboretumweb . client . SearchParameter . Quadrant ; import edu . gac . arboretumweb . client . SearchParameter . SearchFor ; import edu . gac . arboretumweb . client . SearchParameter . SearchType ; import edu . gac . arboretumweb . shared . domain . Bench ; import edu . gac . arboretumweb . shared . domain . Brick ; import edu . gac . arboretumweb . shared . domain . DonatedObject ; import edu . gac . arboretumweb . shared . domain . Tree ; import com . google . gwt . user . client . ui . Button ; import com . google . gwt . user . client . ui . CheckBox ; import com . google . gwt . user . client . ui . AbsolutePanel ; import com . google . gwt . user . client . ui . Image ; public class SearchResultsPage implements EntryPoint { @ UiField ( provided = true ) DataGrid < DonatedObject > dataGrid = new DataGrid < DonatedObject > ( ) ; @ UiField ( provided = true ) SimplePager pager ; private RootPanel rootPanel = RootPanel . get ( ) ; private AbsolutePanel absolutePanel = new AbsolutePanel ( ) ; Image image ; Searcher searcher = new Searcher ( ) ; ArrayList < DonatedObject > sampleTreeList = new ArrayList < DonatedObject > ( ) ; ArrayList < DonatedObject > sampleBenchList = new ArrayList < DonatedObject > ( ) ; ArrayList < DonatedObject > sampleBrickList = new ArrayList < DonatedObject > ( ) ; CheckBox checkBoxQuadrantA = new CheckBox ( "<STR_LIT:A>" ) ; CheckBox checkBoxQuadrantB = new CheckBox ( "<STR_LIT:B>" ) ; CheckBox checkBoxQuadrantC = new CheckBox ( "<STR_LIT:C>" ) ; CheckBox checkBoxQuadrantD = new CheckBox ( "<STR_LIT:D>" ) ; CheckBox checkBoxQuadrantE = new CheckBox ( "<STR_LIT:E>" ) ; Column < DonatedObject , String > donatedForColumn ; Column < DonatedObject , String > yearDonatedColumn ; Column < DonatedObject , String > quadrantColumn ; Column < DonatedObject , String > commonNameColumn ; Column < DonatedObject , String > scientificNameColumn ; Column < DonatedObject , String > benchTypeColumn ; Column < DonatedObject , String > brickLocationColumn ; Column < DonatedObject , String > brickSizeColumn ; ListBox byListBox = new ListBox ( ) ; ListBox inListBox = new ListBox ( ) ; Label searchResultsLabel = new Label ( "<STR_LIT>" ) ; Label inLabel = new Label ( "<STR_LIT>" ) ; Label byLabel = new Label ( "<STR_LIT>" ) ; Label locatedInQuadrantLabel = new Label ( "<STR_LIT>" ) ; TextBox searchKeywordsTextBox = new TextBox ( ) ; Button updateSearchButton = new Button ( "<STR_LIT>" ) ; Button backButton = new Button ( "<STR_LIT>" ) ; @ Override public void onModuleLoad ( ) { this . show ( new SearchParameter ( ) ) ; } public SearchResultsPage ( ) { rootPanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( dataGrid , <NUM_LIT:0> , <NUM_LIT> ) ; dataGrid . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; searcher . updateLocalMasterLists ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:100> ; i ++ ) { sampleBenchList . add ( new Bench ( ) ) ; sampleBrickList . add ( new Brick ( ) ) ; sampleTreeList . add ( new Tree ( ) ) ; } commonNameColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject tree ) { if ( tree instanceof Tree ) return ( ( Tree ) tree ) . getCommonName ( ) ; else return null ; } } ; scientificNameColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject tree ) { if ( tree instanceof Tree ) return ( ( Tree ) tree ) . getScientificName ( ) ; else return null ; } } ; donatedForColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject o ) { return o . getDonatedFor ( ) ; } } ; yearDonatedColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject o ) { return o . getYearDonated ( ) ; } } ; quadrantColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject o ) { return o . getQuadrant ( ) . toString ( ) ; } } ; benchTypeColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject o ) { if ( o instanceof Bench ) return ( ( Bench ) o ) . getBenchType ( ) ; else return null ; } } ; brickLocationColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject brick ) { if ( brick instanceof Brick ) return ( ( Brick ) brick ) . getDistance ( ) ; else return null ; } } ; brickSizeColumn = new Column < DonatedObject , String > ( new TextCell ( ) ) { @ Override public String getValue ( DonatedObject brick ) { if ( brick instanceof Brick ) return ( ( Brick ) brick ) . getSize ( ) ; else return null ; } } ; dataGrid . addColumn ( commonNameColumn , "<STR_LIT>" ) ; dataGrid . addColumn ( scientificNameColumn , "<STR_LIT>" ) ; dataGrid . addColumn ( donatedForColumn , "<STR_LIT>" ) ; dataGrid . addColumn ( yearDonatedColumn , "<STR_LIT>" ) ; dataGrid . addColumn ( quadrantColumn , "<STR_LIT>" ) ; dataGrid . setTitle ( "<STR_LIT>" ) ; byListBox . addItem ( "<STR_LIT>" ) ; byListBox . addItem ( "<STR_LIT>" ) ; byListBox . addItem ( "<STR_LIT>" ) ; byListBox . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; byListBox . setVisibleItemCount ( <NUM_LIT:1> ) ; inListBox . addItem ( "<STR_LIT>" ) ; inListBox . addItem ( "<STR_LIT>" ) ; inListBox . addItem ( "<STR_LIT>" ) ; inListBox . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; inListBox . setVisibleItemCount ( <NUM_LIT:1> ) ; absolutePanel . add ( byListBox , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( inListBox , <NUM_LIT> , <NUM_LIT> ) ; absolutePanel . add ( checkBoxQuadrantA , <NUM_LIT> , <NUM_LIT:10> ) ; checkBoxQuadrantA . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( checkBoxQuadrantB , <NUM_LIT> , <NUM_LIT:10> ) ; checkBoxQuadrantB . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( checkBoxQuadrantC , <NUM_LIT> , <NUM_LIT:10> ) ; checkBoxQuadrantC . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( checkBoxQuadrantD , <NUM_LIT> , <NUM_LIT:10> ) ; checkBoxQuadrantD . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( checkBoxQuadrantE , <NUM_LIT> , <NUM_LIT:10> ) ; absolutePanel . add ( searchResultsLabel , <NUM_LIT:24> , <NUM_LIT:10> ) ; absolutePanel . add ( inLabel , <NUM_LIT:24> , <NUM_LIT> ) ; inLabel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( byLabel , <NUM_LIT> , <NUM_LIT> ) ; byLabel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( locatedInQuadrantLabel , <NUM_LIT> , <NUM_LIT:10> ) ; locatedInQuadrantLabel . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( searchKeywordsTextBox , <NUM_LIT> , <NUM_LIT:10> ) ; searchKeywordsTextBox . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; absolutePanel . add ( updateSearchButton , <NUM_LIT> , <NUM_LIT:24> ) ; updateSearchButton . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; updateSearchButton . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { if ( currentConfigurationIsAcceptable ( ) ) { SearchParameter newParam = extractSearchParameterFromConfiguration ( ) ; configureColumnsBasedOnSearchParameter ( newParam ) ; } } } ) ; absolutePanel . add ( backButton , <NUM_LIT> , <NUM_LIT> ) ; backButton . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; backButton . addClickHandler ( new ClickHandler ( ) { public void onClick ( ClickEvent event ) { rootPanel . clear ( ) ; PageController . sharedPageController ( ) . showMainPage ( ) ; } } ) ; final SingleSelectionModel < DonatedObject > selectionModel = new SingleSelectionModel < DonatedObject > ( ) ; dataGrid . setSelectionModel ( selectionModel ) ; selectionModel . addSelectionChangeHandler ( new SelectionChangeEvent . Handler ( ) { public void onSelectionChange ( SelectionChangeEvent event ) { DonatedObject selectedObject = selectionModel . getSelectedObject ( ) ; if ( selectedObject != null ) { rootPanel . clear ( ) ; SearchParameter searchParameter = extractSearchParameterFromConfiguration ( ) ; if ( selectedObject instanceof Tree ) { PageController . sharedPageController ( ) . showTreePage ( ( Tree ) selectedObject , searchParameter ) ; } if ( selectedObject instanceof Bench ) { PageController . sharedPageController ( ) . showBenchPage ( ( Bench ) selectedObject , searchParameter ) ; } if ( selectedObject instanceof Brick ) { PageController . sharedPageController ( ) . showBrickPage ( ( Brick ) selectedObject , searchParameter ) ; } } } } ) ; } public void show ( final SearchParameter searchParameter ) { rootPanel . add ( absolutePanel , <NUM_LIT:0> , <NUM_LIT:0> ) ; rootPanel . add ( image , <NUM_LIT> , <NUM_LIT> ) ; image . setSize ( "<STR_LIT>" , "<STR_LIT>" ) ; configureColumnsBasedOnSearchParameter ( searchParameter ) ; searchKeywordsTextBox . setText ( searchParameter . getKeywordQuery ( ) ) ; if ( searchParameter . getSearchType ( ) == SearchType . donatedFor ) byListBox . setItemSelected ( <NUM_LIT:0> , true ) ; if ( searchParameter . getSearchType ( ) == SearchType . commonName ) byListBox . setItemSelected ( <NUM_LIT:1> , true ) ; if ( searchParameter . getSearchType ( ) == SearchType . scientificName ) byListBox . setItemSelected ( <NUM_LIT:2> , true ) ; if ( searchParameter . getSearchFor ( ) == SearchFor . trees ) inListBox . setItemSelected ( <NUM_LIT:0> , true ) ; if ( searchParameter . getSearchFor ( ) == SearchFor . benches ) inListBox . setItemSelected ( <NUM_LIT:1> , true ) ; if ( searchParameter . getSearchFor ( ) == SearchFor . bricks ) inListBox . setItemSelected ( <NUM_LIT:2> , true ) ; if ( searchParameter . getQuadrants ( ) . contains ( Quadrant . A ) ) checkBoxQuadrantA . setValue ( true ) ; if ( searchParameter . getQuadrants ( ) . contains ( Quadrant . B ) ) checkBoxQuadrantB . setValue ( true ) ; if ( searchParameter . getQuadrants ( ) . contains ( Quadrant . C ) ) checkBoxQuadrantC . setValue ( true ) ; if ( searchParameter . getQuadrants ( ) . contains ( Quadrant . D ) ) checkBoxQuadrantD . setValue ( true ) ; if ( searchParameter . getQuadrants ( ) . contains ( Quadrant . E ) ) checkBoxQuadrantE . setValue ( true ) ; dataGrid . setPageSize ( <NUM_LIT> ) ; SimplePager . Resources pagerResources = GWT . create ( SimplePager . Resources . class ) ; pager = new SimplePager ( TextLocation . CENTER , pagerResources , false , <NUM_LIT:0> , true ) ; pager . setVisible ( true ) ; } private void configureColumnsBasedOnSearchParameter ( SearchParameter searchParameter ) { if ( searchParameter . getSearchFor ( ) == SearchFor . trees ) { ArrayList < Tree > trees = searcher . searchResultsForTreeSearch ( searchParameter ) ; dataGrid . setRowData ( trees ) ; if ( dataGrid . getColumnIndex ( scientificNameColumn ) == - <NUM_LIT:1> ) { dataGrid . insertColumn ( <NUM_LIT:0> , scientificNameColumn , "<STR_LIT>" ) ; } if ( dataGrid . getColumnIndex ( commonNameColumn ) == - <NUM_LIT:1> ) { dataGrid . insertColumn ( <NUM_LIT:0> , commonNameColumn , "<STR_LIT>" ) ; } if ( ! ( dataGrid . getColumnIndex ( benchTypeColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( benchTypeColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( brickLocationColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( brickLocationColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( brickSizeColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( brickSizeColumn ) ; } setupMapForTrees ( trees ) ; } if ( searchParameter . getSearchFor ( ) == SearchFor . benches ) { ArrayList < Bench > benches = searcher . searchResultsForBenchSearch ( searchParameter ) ; dataGrid . setRowData ( sampleBenchList ) ; if ( ! ( dataGrid . getColumnIndex ( commonNameColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( commonNameColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( scientificNameColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( scientificNameColumn ) ; } if ( dataGrid . getColumnIndex ( benchTypeColumn ) == - <NUM_LIT:1> ) { dataGrid . addColumn ( benchTypeColumn , "<STR_LIT>" ) ; } if ( ! ( dataGrid . getColumnIndex ( brickLocationColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( brickLocationColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( brickSizeColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( brickSizeColumn ) ; } setupMapForBenches ( benches ) ; } if ( searchParameter . getSearchFor ( ) == SearchFor . bricks ) { dataGrid . setRowData ( sampleBrickList ) ; if ( ! ( dataGrid . getColumnIndex ( commonNameColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( commonNameColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( scientificNameColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( scientificNameColumn ) ; } if ( ! ( dataGrid . getColumnIndex ( benchTypeColumn ) == - <NUM_LIT:1> ) ) { dataGrid . removeColumn ( benchTypeColumn ) ; } if ( dataGrid . getColumnIndex ( brickLocationColumn ) == - <NUM_LIT:1> ) { dataGrid . addColumn ( brickLocationColumn , "<STR_LIT>" ) ; } if ( dataGrid . getColumnIndex ( brickSizeColumn ) == - <NUM_LIT:1> ) { dataGrid . addColumn ( brickSizeColumn , "<STR_LIT>" ) ; } } dataGrid . redraw ( ) ; } private void setupMapForTrees ( ArrayList < Tree > sampleTreeList2 ) { String baseString = "<STR_LIT>" + "<STR_LIT>" ; for ( Tree tree : sampleTreeList2 ) { String appendingString = "<STR_LIT>" + tree . getLatitude ( ) + "<STR_LIT:U+002CU+0020>" + tree . getLongitude ( ) ; baseString += appendingString ; } baseString += "<STR_LIT>" ; image . setUrl ( baseString ) ; } private void setupMapForBenches ( ArrayList < Bench > benches ) { String baseString = "<STR_LIT>" + "<STR_LIT>" ; for ( Bench bench : benches ) { String appendingString = "<STR_LIT>" + bench . getLatitude ( ) + "<STR_LIT:U+002CU+0020>" + bench . getLongitude ( ) ; baseString += appendingString ; } baseString += "<STR_LIT>" ; image . setUrl ( baseString ) ; } private boolean currentConfigurationIsAcceptable ( ) { if ( ! checkBoxQuadrantA . getValue ( ) && ! checkBoxQuadrantB . getValue ( ) && ! checkBoxQuadrantC . getValue ( ) && ! checkBoxQuadrantD . getValue ( ) && ! checkBoxQuadrantE . getValue ( ) ) { Window . alert ( "<STR_LIT>" ) ; return false ; } if ( inListBox . getSelectedIndex ( ) == - <NUM_LIT:1> ) { Window . alert ( "<STR_LIT>" ) ; return false ; } String searchInSelectedText = inListBox . getItemText ( inListBox . getSelectedIndex ( ) ) ; String searchForSelectedText = byListBox . getItemText ( byListBox . getSelectedIndex ( ) ) ; if ( ( searchInSelectedText . equals ( "<STR_LIT>" ) || searchInSelectedText . equals ( "<STR_LIT>" ) ) && searchForSelectedText . equals ( "<STR_LIT>" ) || searchForSelectedText . equals ( "<STR_LIT>" ) ) { Window . alert ( "<STR_LIT>" + "<STR_LIT>" ) ; return false ; } return true ; } private SearchParameter extractSearchParameterFromConfiguration ( ) { SearchFor searchFor = SearchFor . trees ; if ( inListBox . getItemText ( inListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchFor = SearchFor . trees ; if ( inListBox . getItemText ( inListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchFor = SearchFor . benches ; if ( inListBox . getItemText ( inListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchFor = SearchFor . bricks ; SearchType searchType = SearchType . commonName ; if ( byListBox . getItemText ( byListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchType = SearchType . donatedFor ; if ( byListBox . getItemText ( byListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchType = SearchType . commonName ; if ( byListBox . getItemText ( byListBox . getSelectedIndex ( ) ) . equals ( "<STR_LIT>" ) ) searchType = SearchType . scientificName ; ArrayList < Quadrant > quadrants = new ArrayList < Quadrant > ( ) ; if ( checkBoxQuadrantA . getValue ( ) ) quadrants . add ( Quadrant . A ) ; if ( checkBoxQuadrantB . getValue ( ) ) quadrants . add ( Quadrant . B ) ; if ( checkBoxQuadrantC . getValue ( ) ) quadrants . add ( Quadrant . C ) ; if ( checkBoxQuadrantD . getValue ( ) ) quadrants . add ( Quadrant . D ) ; if ( checkBoxQuadrantE . getValue ( ) ) quadrants . add ( Quadrant . E ) ; SearchParameter newParam = new SearchParameter ( searchKeywordsTextBox . getText ( ) , searchFor , searchType , quadrants , false ) ; return newParam ; } } </s>
<s> package edu . gac . arboretumweb . client ; import com . google . gwt . core . client . EntryPoint ; import edu . gac . arboretumweb . shared . domain . Bench ; import edu . gac . arboretumweb . shared . domain . Brick ; import edu . gac . arboretumweb . shared . domain . Tree ; public class PageController implements EntryPoint { private static PageController instance = null ; private final MainPage mainPage = new MainPage ( ) ; private final SearchResultsPage searchResultsPage = new SearchResultsPage ( ) ; private final TreePage treePage = new TreePage ( ) ; private final BenchPage benchPage = new BenchPage ( ) ; private final BrickPage brickPage = new BrickPage ( ) ; protected PageController ( ) { } public static PageController sharedPageController ( ) { if ( instance == null ) { instance = new PageController ( ) ; } return instance ; } public void showMainPage ( ) { mainPage . show ( ) ; } public void showSearchResultsPage ( SearchParameter p ) { searchResultsPage . show ( p ) ; } public void showTreePage ( Tree tree , SearchParameter sp ) { treePage . show ( tree , sp ) ; } public void showBenchPage ( Bench bench , SearchParameter sp ) { benchPage . show ( bench , sp ) ; } public void showBrickPage ( Brick brick , SearchParameter sp ) { brickPage . show ( brick , sp ) ; } @ Override public void onModuleLoad ( ) { showMainPage ( ) ; } } </s>
<s> package com . petebevin . markdown ; import java . io . Reader ; import org . apache . tools . ant . filters . BaseParamFilterReader ; import org . apache . tools . ant . filters . ChainableReader ; public class MarkdownFilter extends BaseParamFilterReader implements ChainableReader { char [ ] chars = null ; int pos = <NUM_LIT:0> ; int len = <NUM_LIT:0> ; public MarkdownFilter ( ) { super ( ) ; } public MarkdownFilter ( Reader reader ) { super ( reader ) ; } public Reader chain ( Reader reader ) { MarkdownFilter result = new MarkdownFilter ( reader ) ; result . setParameters ( this . getParameters ( ) ) ; return ( result ) ; } @ Override public final int read ( ) throws java . io . IOException { if ( chars == null ) { char [ ] cbuf = new char [ <NUM_LIT> ] ; StringBuffer buf = new StringBuffer ( ) ; int charsRead = in . read ( cbuf ) ; while ( charsRead >= <NUM_LIT:0> ) { buf . append ( cbuf , <NUM_LIT:0> , charsRead ) ; charsRead = in . read ( cbuf ) ; } MarkdownProcessor markdown = new MarkdownProcessor ( ) ; chars = markdown . markdown ( buf . toString ( ) ) . toCharArray ( ) ; len = chars . length ; } return ( pos >= len ? - <NUM_LIT:1> : chars [ pos ++ ] ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . TextEditor ; import org . junit . Test ; import static org . junit . Assert . * ; public class TestTextEditor { @ Test public void testDetabify ( ) { assertEquals ( "<STR_LIT:U+0020U+0020U+0020U+0020>" , new TextEditor ( "<STR_LIT:t>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT:U+0020U+0020U+0020U+0020>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT:U+0020U+0020U+0020U+0020>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT:U+0020U+0020U+0020U+0020>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; assertEquals ( "<STR_LIT>" , new TextEditor ( "<STR_LIT>" ) . detabify ( ) . toString ( ) ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . MarkdownProcessor ; import org . junit . Before ; import org . junit . Test ; import static org . junit . Assert . * ; public class LineConventions { private static final String EXPECTED = "<STR_LIT>" ; private MarkdownProcessor m ; @ Before public void createProcessor ( ) { m = new MarkdownProcessor ( ) ; } @ Test public void testUnixLineConventions ( ) { assertEquals ( EXPECTED , m . markdown ( "<STR_LIT>" ) ) ; } @ Test public void testWindowsLineConventions ( ) { MarkdownProcessor markup = new MarkdownProcessor ( ) ; assertEquals ( EXPECTED , markup . markdown ( "<STR_LIT>" ) ) ; } @ Test public void testMacLineConventions ( ) { MarkdownProcessor markup = new MarkdownProcessor ( ) ; assertEquals ( EXPECTED , markup . markdown ( "<STR_LIT>" ) ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . MarkdownProcessor ; import java . util . regex . Pattern ; import org . junit . Before ; import org . junit . Test ; import static org . junit . Assert . * ; public class EdgeCases { private MarkdownProcessor m ; @ Before public void createProcessor ( ) { m = new MarkdownProcessor ( ) ; } @ Test public void testEmptyString ( ) { assertEquals ( "<STR_LIT:n>" , m . markdown ( "<STR_LIT>" ) ) ; } @ Test public void testSpaces ( ) { assertEquals ( "<STR_LIT:n>" , m . markdown ( "<STR_LIT:U+0020U+0020>" ) ) ; } @ Test public void testNull ( ) { assertEquals ( "<STR_LIT:n>" , m . markdown ( null ) ) ; } @ Test public void testSplitAssumption ( ) { Pattern x = Pattern . compile ( "<STR_LIT:x>" ) ; String [ ] xs = x . split ( "<STR_LIT>" ) ; assertEquals ( <NUM_LIT:1> , xs . length ) ; assertEquals ( "<STR_LIT>" , xs [ <NUM_LIT:0> ] ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . HTMLDecoder ; import com . petebevin . markdown . MarkdownProcessor ; import org . junit . Before ; import org . junit . Test ; import static org . junit . Assert . * ; public class EmailAddresses { MarkdownProcessor m ; @ Before public void createProcessor ( ) { m = new MarkdownProcessor ( ) ; } @ Test public void testDecoder ( ) { String encoded = "<STR_LIT>" ; String billg = "<STR_LIT>" ; assertEquals ( billg , HTMLDecoder . decode ( encoded ) ) ; assertEquals ( "<STR_LIT>" , HTMLDecoder . decode ( "<STR_LIT>" ) ) ; } @ Test public void testEmail ( ) { String html = m . markdown ( "<STR_LIT>" ) ; String plain = HTMLDecoder . decode ( html ) ; assertEquals ( "<STR_LIT>" , plain ) ; assertFalse ( "<STR_LIT>" , plain . equals ( html ) ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . MarkdownProcessor ; import org . junit . Before ; import org . junit . Test ; import static org . junit . Assert . * ; public class EscapeSpecialCharsWithinTagAttributes { MarkdownProcessor m ; @ Before public void createProcessor ( ) { m = new MarkdownProcessor ( ) ; } @ Test public void testImages ( ) { String url = "<STR_LIT>" ; String processed = m . markdown ( url ) ; String output = "<STR_LIT>" ; assertEquals ( output , processed ) ; } @ Test public void testAutoLinks ( ) { String url = "<STR_LIT>" ; String processed = m . markdown ( url ) ; String output = "<STR_LIT>" ; assertEquals ( output , processed ) ; } } </s>
<s> package com . petebevin . markdown . test ; public class TestResultPair { private String name ; private String test ; private String result ; public TestResultPair ( String name , String test , String result ) { this . name = name ; this . test = test ; this . result = result ; } public String getTest ( ) { return test ; } public String getResult ( ) { return result ; } @ Override public String toString ( ) { return name ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . MarkdownProcessor ; import java . io . File ; import java . io . FileReader ; import java . io . IOException ; import java . net . URL ; import java . net . URLDecoder ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . junit . runners . Parameterized ; import org . junit . runners . Parameterized . Parameters ; import static org . junit . Assert . * ; @ RunWith ( value = Parameterized . class ) public class MarkdownTestTester { private final static String MARKDOWN_TEST_DIR = "<STR_LIT>" ; String test ; String dir ; @ Parameters public static Collection < Object [ ] > markdownTests ( ) { List list = new ArrayList < Object [ ] > ( ) ; URL fileUrl = MarkdownTestTester . class . getResource ( MARKDOWN_TEST_DIR ) ; File dir = new File ( fileUrl . getFile ( ) ) ; File [ ] dirEntries = dir . listFiles ( ) ; for ( int i = <NUM_LIT:0> ; i < dirEntries . length ; i ++ ) { File dirEntry = dirEntries [ i ] ; String fileName = dirEntry . getName ( ) ; if ( fileName . endsWith ( "<STR_LIT>" ) ) { String testName = fileName . substring ( <NUM_LIT:0> , fileName . lastIndexOf ( '<CHAR_LIT:.>' ) ) ; list . add ( new Object [ ] { MARKDOWN_TEST_DIR , testName } ) ; } } return list ; } public MarkdownTestTester ( String dir , String test ) { this . test = test ; this . dir = dir ; } @ Test public void runTest ( ) throws IOException { String testText = slurp ( dir + File . separator + test + "<STR_LIT>" ) ; String htmlText = slurp ( dir + File . separator + test + "<STR_LIT>" ) ; MarkdownProcessor markup = new MarkdownProcessor ( ) ; String markdownText = markup . markdown ( testText ) ; assertEquals ( test , htmlText . trim ( ) , markdownText . trim ( ) ) ; } private String slurp ( String fileName ) throws IOException { URL fileUrl = this . getClass ( ) . getResource ( fileName ) ; File file = new File ( URLDecoder . decode ( fileUrl . getFile ( ) , "<STR_LIT:UTF-8>" ) ) ; FileReader in = new FileReader ( file ) ; StringBuffer sb = new StringBuffer ( ) ; int ch ; while ( ( ch = in . read ( ) ) != - <NUM_LIT:1> ) { sb . append ( ( char ) ch ) ; } return sb . toString ( ) ; } } </s>
<s> package com . petebevin . markdown . test ; import com . petebevin . markdown . MarkdownProcessor ; import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . net . URL ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . junit . runners . Parameterized ; import org . junit . runners . Parameterized . Parameters ; import static org . junit . Assert . * ; @ RunWith ( value = Parameterized . class ) public class MarkupFileTester { private final static String [ ] TEST_FILENAMES = new String [ ] { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; TestResultPair pair ; @ Parameters public static Collection < Object [ ] > testResultPairs ( ) throws IOException { List < TestResultPair > fullResultPairList = new ArrayList < TestResultPair > ( ) ; for ( String filename : TEST_FILENAMES ) { fullResultPairList . addAll ( newTestResultPairList ( filename ) ) ; } Collection < Object [ ] > testResultPairs = new ArrayList < Object [ ] > ( ) ; for ( TestResultPair p : fullResultPairList ) { testResultPairs . add ( new Object [ ] { p } ) ; } return testResultPairs ; } public MarkupFileTester ( TestResultPair pair ) { this . pair = pair ; } public static List < TestResultPair > newTestResultPairList ( String filename ) throws IOException { List < TestResultPair > list = new ArrayList < TestResultPair > ( ) ; URL fileUrl = MarkupFileTester . class . getResource ( filename ) ; FileReader file = new FileReader ( fileUrl . getFile ( ) ) ; BufferedReader in = new BufferedReader ( file ) ; StringBuffer test = null ; StringBuffer result = null ; Pattern pTest = Pattern . compile ( "<STR_LIT>" ) ; Pattern pResult = Pattern . compile ( "<STR_LIT>" ) ; String line ; int lineNumber = <NUM_LIT:0> ; String testNumber = null ; String testName = null ; StringBuffer curbuf = null ; while ( ( line = in . readLine ( ) ) != null ) { lineNumber ++ ; Matcher mTest = pTest . matcher ( line ) ; Matcher mResult = pResult . matcher ( line ) ; if ( mTest . matches ( ) ) { addTestResultPair ( list , test , result , testNumber , testName ) ; testNumber = mTest . group ( <NUM_LIT:1> ) ; testName = mTest . group ( <NUM_LIT:2> ) ; test = new StringBuffer ( ) ; result = new StringBuffer ( ) ; curbuf = test ; } else if ( mResult . matches ( ) ) { if ( testNumber == null ) { throw new RuntimeException ( "<STR_LIT>" + lineNumber + "<STR_LIT:)>" ) ; } String resultNumber = mResult . group ( <NUM_LIT:1> ) ; if ( ! testNumber . equals ( resultNumber ) ) { throw new RuntimeException ( "<STR_LIT>" + resultNumber + "<STR_LIT>" + testNumber + "<STR_LIT>" + lineNumber + "<STR_LIT:)>" ) ; } curbuf = result ; } else { curbuf . append ( line ) ; curbuf . append ( "<STR_LIT:n>" ) ; } } addTestResultPair ( list , test , result , testNumber , testName ) ; return list ; } private static void addTestResultPair ( List list , StringBuffer testbuf , StringBuffer resultbuf , String testNumber , String testName ) { if ( testbuf == null || resultbuf == null ) { return ; } String test = chomp ( testbuf . toString ( ) ) ; String result = chomp ( resultbuf . toString ( ) ) ; String id = testNumber + "<STR_LIT:(>" + testName + "<STR_LIT:)>" ; list . add ( new TestResultPair ( id , test , result ) ) ; } private static String chomp ( String s ) { int lastPos = s . length ( ) - <NUM_LIT:1> ; while ( s . charAt ( lastPos ) == '<STR_LIT:\n>' || s . charAt ( lastPos ) == '<STR_LIT>' ) { lastPos -- ; } return s . substring ( <NUM_LIT:0> , lastPos + <NUM_LIT:1> ) ; } @ Test public void runTest ( ) { MarkdownProcessor markup = new MarkdownProcessor ( ) ; assertEquals ( pair . toString ( ) , pair . getResult ( ) . trim ( ) , markup . markdown ( pair . getTest ( ) ) . trim ( ) ) ; } } </s>
<s> package com . petebevin . markdown ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import java . util . Collection ; import java . util . List ; import java . util . ArrayList ; public class TextEditor { private StringBuffer text ; public TextEditor ( CharSequence text ) { this . text = new StringBuffer ( text . toString ( ) ) ; } @ Override public String toString ( ) { return text . toString ( ) ; } public TextEditor replaceAll ( String regex , String replacement ) { if ( text . length ( ) > <NUM_LIT:0> ) { final String r = replacement ; Pattern p = Pattern . compile ( regex , Pattern . MULTILINE ) ; Matcher m = p . matcher ( text ) ; StringBuffer sb = new StringBuffer ( ) ; while ( m . find ( ) ) { m . appendReplacement ( sb , r ) ; } m . appendTail ( sb ) ; text = sb ; } return this ; } public TextEditor replaceAllLiteral ( String regex , final String replacement ) { return replaceAll ( Pattern . compile ( regex , Pattern . MULTILINE ) , new Replacement ( ) { public String replacement ( Matcher m ) { return replacement ; } } ) ; } public TextEditor replaceAll ( Pattern pattern , Replacement replacement ) { Matcher m = pattern . matcher ( text ) ; int lastIndex = <NUM_LIT:0> ; StringBuffer sb = new StringBuffer ( ) ; while ( m . find ( ) ) { sb . append ( text . subSequence ( lastIndex , m . start ( ) ) ) ; sb . append ( replacement . replacement ( m ) ) ; lastIndex = m . end ( ) ; } sb . append ( text . subSequence ( lastIndex , text . length ( ) ) ) ; text = sb ; return this ; } public TextEditor deleteAll ( String pattern ) { return replaceAll ( pattern , "<STR_LIT>" ) ; } public TextEditor detabify ( ) { return detabify ( <NUM_LIT:4> ) ; } public TextEditor detabify ( final int tabWidth ) { replaceAll ( Pattern . compile ( "<STR_LIT>" ) , new Replacement ( ) { public String replacement ( Matcher m ) { String lineSoFar = m . group ( <NUM_LIT:1> ) ; int width = lineSoFar . length ( ) ; StringBuffer replacement = new StringBuffer ( lineSoFar ) ; do { replacement . append ( '<CHAR_LIT:U+0020>' ) ; ++ width ; } while ( width % tabWidth != <NUM_LIT:0> ) ; return replacement . toString ( ) ; } } ) ; return this ; } public TextEditor outdent ( int spaces ) { return deleteAll ( "<STR_LIT>" + spaces + "<STR_LIT>" ) ; } public TextEditor outdent ( ) { return outdent ( <NUM_LIT:4> ) ; } public TextEditor trim ( ) { text = new StringBuffer ( text . toString ( ) . trim ( ) ) ; return this ; } public TextEditor indent ( int spaces ) { StringBuffer sb = new StringBuffer ( spaces ) ; for ( int i = <NUM_LIT:0> ; i < spaces ; i ++ ) { sb . append ( '<CHAR_LIT:U+0020>' ) ; } return replaceAll ( "<STR_LIT>" , sb . toString ( ) ) ; } public void append ( CharSequence s ) { text . append ( s ) ; } public Collection < HTMLToken > tokenizeHTML ( ) { List < HTMLToken > tokens = new ArrayList < HTMLToken > ( ) ; String nestedTags = nestedTagsRegex ( <NUM_LIT:6> ) ; Pattern p = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:|>" + "<STR_LIT>" + "<STR_LIT:|>" + nestedTags + "<STR_LIT>" , Pattern . CASE_INSENSITIVE ) ; Matcher m = p . matcher ( text ) ; int lastPos = <NUM_LIT:0> ; while ( m . find ( ) ) { if ( lastPos < m . start ( ) ) { tokens . add ( HTMLToken . text ( text . substring ( lastPos , m . start ( ) ) ) ) ; } tokens . add ( HTMLToken . tag ( text . substring ( m . start ( ) , m . end ( ) ) ) ) ; lastPos = m . end ( ) ; } if ( lastPos < text . length ( ) ) { tokens . add ( HTMLToken . text ( text . substring ( lastPos , text . length ( ) ) ) ) ; } return tokens ; } private String nestedTagsRegex ( int depth ) { if ( depth == <NUM_LIT:0> ) { return "<STR_LIT>" ; } else { return "<STR_LIT>" + nestedTagsRegex ( depth - <NUM_LIT:1> ) + "<STR_LIT>" ; } } public void prepend ( CharSequence s ) { StringBuffer newText = new StringBuffer ( ) ; newText . append ( s ) ; newText . append ( text ) ; text = newText ; } public boolean isEmpty ( ) { return text . length ( ) == <NUM_LIT:0> ; } } </s>
<s> package com . petebevin . markdown ; public class LinkDefinition { private String url ; private String title ; public LinkDefinition ( String url , String title ) { this . url = url ; this . title = title ; } public String getUrl ( ) { return url ; } public String getTitle ( ) { return title ; } @ Override public String toString ( ) { return url + "<STR_LIT:U+0020(>" + title + "<STR_LIT:)>" ; } } </s>
<s> package com . petebevin . markdown ; import java . util . Collection ; import java . util . Map ; import java . util . Random ; import java . util . TreeMap ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class MarkdownProcessor { private Random rnd = new Random ( ) ; private Map < String , LinkDefinition > linkDefinitions = new TreeMap < String , LinkDefinition > ( ) ; private static final CharacterProtector HTML_PROTECTOR = new CharacterProtector ( ) ; private static final CharacterProtector CHAR_PROTECTOR = new CharacterProtector ( ) ; private int listLevel ; private String emptyElementSuffix = "<STR_LIT>" ; private int tabWidth = <NUM_LIT:4> ; public MarkdownProcessor ( ) { listLevel = <NUM_LIT:0> ; } public String markdown ( String txt ) { if ( txt == null ) { txt = "<STR_LIT>" ; } TextEditor text = new TextEditor ( txt ) ; text . replaceAll ( "<STR_LIT>" , "<STR_LIT:n>" ) ; text . replaceAll ( "<STR_LIT>" , "<STR_LIT:n>" ) ; text . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; text . append ( "<STR_LIT>" ) ; text . detabify ( ) ; text . deleteAll ( "<STR_LIT>" ) ; hashHTMLBlocks ( text ) ; stripLinkDefinitions ( text ) ; text = runBlockGamut ( text ) ; unEscapeSpecialChars ( text ) ; text . append ( "<STR_LIT:n>" ) ; return text . toString ( ) ; } private TextEditor encodeBackslashEscapes ( TextEditor text ) { char [ ] normalChars = "<STR_LIT>" . toCharArray ( ) ; char [ ] escapedChars = "<STR_LIT>" . toCharArray ( ) ; text . replaceAllLiteral ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:\\>" ) ) ; encodeEscapes ( text , normalChars , "<STR_LIT>" ) ; encodeEscapes ( text , escapedChars , "<STR_LIT>" ) ; return text ; } private TextEditor encodeEscapes ( TextEditor text , char [ ] chars , String slashes ) { for ( char ch : chars ) { String regex = slashes + ch ; text . replaceAllLiteral ( regex , CHAR_PROTECTOR . encode ( String . valueOf ( ch ) ) ) ; } return text ; } private void stripLinkDefinitions ( TextEditor text ) { Pattern p = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Pattern . MULTILINE ) ; text . replaceAll ( p , new Replacement ( ) { public String replacement ( Matcher m ) { String id = m . group ( <NUM_LIT:1> ) . toLowerCase ( ) ; String url = encodeAmpsAndAngles ( new TextEditor ( m . group ( <NUM_LIT:2> ) ) ) . toString ( ) ; String title = m . group ( <NUM_LIT:3> ) ; if ( title == null ) { title = "<STR_LIT>" ; } title = replaceAll ( title , "<STR_LIT:\">" , "<STR_LIT>" ) ; linkDefinitions . put ( id , new LinkDefinition ( url , title ) ) ; return "<STR_LIT>" ; } } ) ; } public TextEditor runBlockGamut ( TextEditor text ) { doHeaders ( text ) ; doHorizontalRules ( text ) ; doLists ( text ) ; doCodeBlocks ( text ) ; doBlockQuotes ( text ) ; hashHTMLBlocks ( text ) ; return formParagraphs ( text ) ; } private void doHorizontalRules ( TextEditor text ) { String [ ] hrDelimiters = { "<STR_LIT>" , "<STR_LIT:->" , "<STR_LIT:_>" } ; for ( String hrDelimiter : hrDelimiters ) { text . replaceAll ( "<STR_LIT>" + hrDelimiter + "<STR_LIT>" , "<STR_LIT>" ) ; } } private void hashHTMLBlocks ( TextEditor text ) { String [ ] tagsA = { "<STR_LIT:p>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; String [ ] tagsB = { "<STR_LIT>" , "<STR_LIT>" } ; String alternationA = join ( "<STR_LIT:|>" , tagsA ) ; String alternationB = alternationA + "<STR_LIT:|>" + join ( "<STR_LIT:|>" , tagsB ) ; int less_than_tab = tabWidth - <NUM_LIT:1> ; Pattern p1 = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT>" + alternationA + "<STR_LIT:)>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Pattern . MULTILINE ) ; Replacement protectHTML = new Replacement ( ) { public String replacement ( Matcher m ) { String literal = m . group ( ) ; return "<STR_LIT>" + HTML_PROTECTOR . encode ( literal ) + "<STR_LIT>" ; } } ; text . replaceAll ( p1 , protectHTML ) ; Pattern p2 = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + alternationB + "<STR_LIT:)>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Pattern . MULTILINE ) ; text . replaceAll ( p2 , protectHTML ) ; Pattern p3 = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:|>" + "<STR_LIT>" + "<STR_LIT:)>" + "<STR_LIT:(>" + "<STR_LIT>" + less_than_tab + "<STR_LIT:}>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) ; text . replaceAll ( p3 , protectHTML ) ; Pattern p4 = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:|>" + "<STR_LIT>" + "<STR_LIT:)>" + "<STR_LIT:(>" + "<STR_LIT>" + less_than_tab + "<STR_LIT:}>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:>>" + "<STR_LIT:)>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" ) ; text . replaceAll ( p4 , protectHTML ) ; } private TextEditor formParagraphs ( TextEditor markup ) { markup . deleteAll ( "<STR_LIT>" ) ; markup . deleteAll ( "<STR_LIT>" ) ; String [ ] paragraphs ; if ( markup . isEmpty ( ) ) { paragraphs = new String [ <NUM_LIT:0> ] ; } else { paragraphs = Pattern . compile ( "<STR_LIT>" ) . split ( markup . toString ( ) ) ; } for ( int i = <NUM_LIT:0> ; i < paragraphs . length ; i ++ ) { String paragraph = paragraphs [ i ] ; String decoded = HTML_PROTECTOR . decode ( paragraph ) ; if ( decoded != null ) { paragraphs [ i ] = decoded ; } else { paragraph = runSpanGamut ( new TextEditor ( paragraph ) ) . toString ( ) ; paragraphs [ i ] = "<STR_LIT>" + paragraph + "<STR_LIT>" ; } } return new TextEditor ( join ( "<STR_LIT>" , paragraphs ) ) ; } private TextEditor doAutoLinks ( TextEditor markup ) { markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; Pattern email = Pattern . compile ( "<STR_LIT>" ) ; markup . replaceAll ( email , new Replacement ( ) { public String replacement ( Matcher m ) { String address = m . group ( <NUM_LIT:1> ) ; TextEditor ed = new TextEditor ( address ) ; unEscapeSpecialChars ( ed ) ; String addr = encodeEmail ( ed . toString ( ) ) ; String url = encodeEmail ( "<STR_LIT>" + ed . toString ( ) ) ; return "<STR_LIT>" + url + "<STR_LIT>" + addr + "<STR_LIT>" ; } } ) ; return markup ; } private void unEscapeSpecialChars ( TextEditor ed ) { for ( String hash : CHAR_PROTECTOR . getAllEncodedTokens ( ) ) { String plaintext = CHAR_PROTECTOR . decode ( hash ) ; ed . replaceAllLiteral ( hash , plaintext ) ; } } private String encodeEmail ( String s ) { StringBuffer sb = new StringBuffer ( ) ; char [ ] email = s . toCharArray ( ) ; for ( char ch : email ) { double r = rnd . nextDouble ( ) ; if ( r < <NUM_LIT> ) { sb . append ( "<STR_LIT>" ) ; sb . append ( ( int ) ch ) ; sb . append ( '<CHAR_LIT:;>' ) ; } else if ( r < <NUM_LIT> ) { sb . append ( "<STR_LIT>" ) ; sb . append ( Integer . toString ( ( int ) ch , <NUM_LIT:16> ) ) ; sb . append ( '<CHAR_LIT:;>' ) ; } else { sb . append ( ch ) ; } } return sb . toString ( ) ; } private TextEditor doBlockQuotes ( TextEditor markup ) { Pattern p = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" , Pattern . MULTILINE ) ; return markup . replaceAll ( p , new Replacement ( ) { public String replacement ( Matcher m ) { TextEditor blockQuote = new TextEditor ( m . group ( <NUM_LIT:1> ) ) ; blockQuote . deleteAll ( "<STR_LIT>" ) ; blockQuote . deleteAll ( "<STR_LIT>" ) ; blockQuote = runBlockGamut ( blockQuote ) ; blockQuote . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020U+0020>" ) ; Pattern p1 = Pattern . compile ( "<STR_LIT>" , Pattern . DOTALL ) ; blockQuote = blockQuote . replaceAll ( p1 , new Replacement ( ) { public String replacement ( Matcher m1 ) { String pre = m1 . group ( <NUM_LIT:1> ) ; return deleteAll ( pre , "<STR_LIT>" ) ; } } ) ; return "<STR_LIT>" + blockQuote + "<STR_LIT>" ; } } ) ; } private TextEditor doCodeBlocks ( TextEditor markup ) { Pattern p = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" + "<STR_LIT>" , Pattern . MULTILINE ) ; return markup . replaceAll ( p , new Replacement ( ) { private static final String LANG_IDENTIFIER = "<STR_LIT>" ; public String replacement ( Matcher m ) { String codeBlock = m . group ( <NUM_LIT:1> ) ; TextEditor ed = new TextEditor ( codeBlock ) ; ed . outdent ( ) ; encodeCode ( ed ) ; ed . detabify ( ) . deleteAll ( "<STR_LIT>" ) . deleteAll ( "<STR_LIT>" ) ; String text = ed . toString ( ) ; String out = "<STR_LIT>" ; String firstLine = firstLine ( text ) ; if ( isLanguageIdentifier ( firstLine ) ) { out = languageBlock ( firstLine , text ) ; } else { out = genericCodeBlock ( text ) ; } return out ; } public String firstLine ( String text ) { if ( text == null ) return "<STR_LIT>" ; String [ ] splitted = text . split ( "<STR_LIT>" ) ; return splitted [ <NUM_LIT:0> ] ; } public boolean isLanguageIdentifier ( String line ) { if ( line == null ) return false ; String lang = "<STR_LIT>" ; if ( line . startsWith ( LANG_IDENTIFIER ) ) { lang = line . replaceFirst ( LANG_IDENTIFIER , "<STR_LIT>" ) . trim ( ) ; } return lang . length ( ) > <NUM_LIT:0> ; } public String languageBlock ( String firstLine , String text ) { String codeBlockTemplate = "<STR_LIT>" ; String lang = firstLine . replaceFirst ( LANG_IDENTIFIER , "<STR_LIT>" ) . trim ( ) ; String block = text . replaceFirst ( firstLine + "<STR_LIT:n>" , "<STR_LIT>" ) ; return String . format ( codeBlockTemplate , lang , block ) ; } public String genericCodeBlock ( String text ) { String codeBlockTemplate = "<STR_LIT>" ; return String . format ( codeBlockTemplate , text ) ; } } ) ; } private void encodeCode ( TextEditor ed ) { ed . replaceAll ( "<STR_LIT:&>" , "<STR_LIT>" ) ; ed . replaceAll ( "<STR_LIT:<>" , "<STR_LIT>" ) ; ed . replaceAll ( "<STR_LIT:>>" , "<STR_LIT>" ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; ed . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:{>" ) ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:}>" ) ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:[>" ) ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:]>" ) ) ; ed . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:\\>" ) ) ; } private TextEditor doLists ( TextEditor text ) { int lessThanTab = tabWidth - <NUM_LIT:1> ; String wholeList = "<STR_LIT:(>" + "<STR_LIT:(>" + "<STR_LIT>" + lessThanTab + "<STR_LIT:}>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" + "<STR_LIT>" + "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT:|>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" + "<STR_LIT:)>" + "<STR_LIT:)>" ; if ( listLevel > <NUM_LIT:0> ) { Replacement replacer = new Replacement ( ) { public String replacement ( Matcher m ) { String list = m . group ( <NUM_LIT:1> ) ; String listStart = m . group ( <NUM_LIT:3> ) ; String listType = "<STR_LIT>" ; if ( listStart . matches ( "<STR_LIT>" ) ) { listType = "<STR_LIT>" ; } else { listType = "<STR_LIT>" ; } list = replaceAll ( list , "<STR_LIT>" , "<STR_LIT>" ) ; String result = processListItems ( list ) ; result = result . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; String html ; if ( "<STR_LIT>" . equals ( listType ) ) { html = "<STR_LIT>" + result + "<STR_LIT>" ; } else { html = "<STR_LIT>" + result + "<STR_LIT>" ; } return html ; } } ; Pattern matchStartOfLine = Pattern . compile ( "<STR_LIT>" + wholeList , Pattern . MULTILINE ) ; text . replaceAll ( matchStartOfLine , replacer ) ; } else { Replacement replacer = new Replacement ( ) { public String replacement ( Matcher m ) { String list = m . group ( <NUM_LIT:1> ) ; String listStart = m . group ( <NUM_LIT:3> ) ; String listType = "<STR_LIT>" ; if ( listStart . matches ( "<STR_LIT>" ) ) { listType = "<STR_LIT>" ; } else { listType = "<STR_LIT>" ; } list = replaceAll ( list , "<STR_LIT>" , "<STR_LIT>" ) ; String result = processListItems ( list ) ; String html ; if ( listStart . matches ( "<STR_LIT>" ) ) { html = "<STR_LIT>" + result + "<STR_LIT>" ; } else { html = "<STR_LIT>" + result + "<STR_LIT>" ; } return html ; } } ; Pattern matchStartOfLine = Pattern . compile ( "<STR_LIT>" + wholeList , Pattern . MULTILINE ) ; text . replaceAll ( matchStartOfLine , replacer ) ; } return text ; } private String processListItems ( String list ) { listLevel ++ ; list = replaceAll ( list , "<STR_LIT>" , "<STR_LIT:n>" ) ; Pattern p = Pattern . compile ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" , Pattern . MULTILINE ) ; list = replaceAll ( list , p , new Replacement ( ) { public String replacement ( Matcher m ) { String text = m . group ( <NUM_LIT:4> ) ; TextEditor item = new TextEditor ( text ) ; String leadingLine = m . group ( <NUM_LIT:1> ) ; if ( ! isEmptyString ( leadingLine ) || hasParagraphBreak ( item ) ) { item = runBlockGamut ( item . outdent ( ) ) ; } else { item = doLists ( item . outdent ( ) ) ; item = runSpanGamut ( item ) ; } return "<STR_LIT>" + item . trim ( ) . toString ( ) + "<STR_LIT>" ; } } ) ; listLevel -- ; return list ; } private boolean hasParagraphBreak ( TextEditor item ) { return item . toString ( ) . indexOf ( "<STR_LIT>" ) != - <NUM_LIT:1> ; } private boolean isEmptyString ( String leadingLine ) { return leadingLine == null || leadingLine . equals ( "<STR_LIT>" ) ; } private TextEditor doHeaders ( TextEditor markup ) { markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; Pattern p = Pattern . compile ( "<STR_LIT>" , Pattern . MULTILINE ) ; markup . replaceAll ( p , new Replacement ( ) { public String replacement ( Matcher m ) { String marker = m . group ( <NUM_LIT:1> ) ; String heading = m . group ( <NUM_LIT:2> ) ; int level = marker . length ( ) ; String tag = "<STR_LIT>" + level ; return "<STR_LIT:<>" + tag + "<STR_LIT:>>" + heading + "<STR_LIT>" + tag + "<STR_LIT>" ; } } ) ; return markup ; } private String join ( String separator , String [ ] strings ) { int length = strings . length ; StringBuffer buf = new StringBuffer ( ) ; if ( length > <NUM_LIT:0> ) { buf . append ( strings [ <NUM_LIT:0> ] ) ; for ( int i = <NUM_LIT:1> ; i < length ; i ++ ) { buf . append ( separator ) . append ( strings [ i ] ) ; } } return buf . toString ( ) ; } public TextEditor runSpanGamut ( TextEditor text ) { text = escapeSpecialCharsWithinTagAttributes ( text ) ; text = doCodeSpans ( text ) ; text = encodeBackslashEscapes ( text ) ; doImages ( text ) ; doAnchors ( text ) ; doAutoLinks ( text ) ; text = escapeSpecialCharsWithinTagAttributes ( text ) ; encodeAmpsAndAngles ( text ) ; doItalicsAndBold ( text ) ; text . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; return text ; } private TextEditor escapeSpecialCharsWithinTagAttributes ( TextEditor text ) { Collection < HTMLToken > tokens = text . tokenizeHTML ( ) ; TextEditor newText = new TextEditor ( "<STR_LIT>" ) ; for ( HTMLToken token : tokens ) { String value = "<STR_LIT>" ; value = token . getText ( ) ; if ( token . isTag ( ) ) { value = value . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:\\>" ) ) ; value = value . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT>" ) ) ; value = value . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; value = value . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; } newText . append ( value ) ; } return newText ; } private void doImages ( TextEditor text ) { text . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; text . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; } private TextEditor doAnchors ( TextEditor markup ) { Pattern internalLink = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" ) ; markup . replaceAll ( internalLink , new Replacement ( ) { public String replacement ( Matcher m ) { String replacementText ; String wholeMatch = m . group ( <NUM_LIT:1> ) ; String linkText = m . group ( <NUM_LIT:2> ) ; String id = m . group ( <NUM_LIT:3> ) . toLowerCase ( ) ; if ( id == null || "<STR_LIT>" . equals ( id ) ) { id = linkText . toLowerCase ( ) ; } LinkDefinition defn = linkDefinitions . get ( id ) ; if ( defn != null ) { String url = defn . getUrl ( ) ; url = url . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; url = url . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; String title = defn . getTitle ( ) ; String titleTag = "<STR_LIT>" ; if ( title != null && ! title . equals ( "<STR_LIT>" ) ) { title = title . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; title = title . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; titleTag = "<STR_LIT>" + title + "<STR_LIT:\">" ; } replacementText = "<STR_LIT>" + url + "<STR_LIT:\">" + titleTag + "<STR_LIT:>>" + linkText + "<STR_LIT>" ; } else { replacementText = wholeMatch ; } return replacementText ; } } ) ; Pattern inlineLink = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" , Pattern . DOTALL ) ; markup . replaceAll ( inlineLink , new Replacement ( ) { public String replacement ( Matcher m ) { String linkText = m . group ( <NUM_LIT:2> ) ; String url = m . group ( <NUM_LIT:3> ) ; String title = m . group ( <NUM_LIT:6> ) ; url = url . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; url = url . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; StringBuffer result = new StringBuffer ( ) ; result . append ( "<STR_LIT>" ) . append ( url ) . append ( "<STR_LIT:\">" ) ; if ( title != null ) { title = title . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; title = title . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; title = replaceAll ( title , "<STR_LIT:\">" , "<STR_LIT>" ) ; result . append ( "<STR_LIT>" ) ; result . append ( title ) ; result . append ( "<STR_LIT:\">" ) ; } result . append ( "<STR_LIT:>>" ) . append ( linkText ) ; result . append ( "<STR_LIT>" ) ; return result . toString ( ) ; } } ) ; Pattern referenceShortcut = Pattern . compile ( "<STR_LIT:(>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT:)>" , Pattern . DOTALL ) ; markup . replaceAll ( referenceShortcut , new Replacement ( ) { public String replacement ( Matcher m ) { String replacementText ; String wholeMatch = m . group ( <NUM_LIT:1> ) ; String linkText = m . group ( <NUM_LIT:2> ) ; String id = m . group ( <NUM_LIT:2> ) . toLowerCase ( ) ; id = id . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ; LinkDefinition defn = linkDefinitions . get ( id . toLowerCase ( ) ) ; if ( defn != null ) { String url = defn . getUrl ( ) ; url = url . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; url = url . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; String title = defn . getTitle ( ) ; String titleTag = "<STR_LIT>" ; if ( title != null && ! title . equals ( "<STR_LIT>" ) ) { title = title . replaceAll ( "<STR_LIT>" , CHAR_PROTECTOR . encode ( "<STR_LIT:*>" ) ) ; title = title . replaceAll ( "<STR_LIT:_>" , CHAR_PROTECTOR . encode ( "<STR_LIT:_>" ) ) ; titleTag = "<STR_LIT>" + title + "<STR_LIT:\">" ; } replacementText = "<STR_LIT>" + url + "<STR_LIT:\">" + titleTag + "<STR_LIT:>>" + linkText + "<STR_LIT>" ; } else { replacementText = wholeMatch ; } return replacementText ; } } ) ; return markup ; } private TextEditor doItalicsAndBold ( TextEditor markup ) { markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; return markup ; } private TextEditor encodeAmpsAndAngles ( TextEditor markup ) { markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; markup . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; return markup ; } private TextEditor doCodeSpans ( TextEditor markup ) { return markup . replaceAll ( Pattern . compile ( "<STR_LIT>" ) , new Replacement ( ) { public String replacement ( Matcher m ) { String code = m . group ( <NUM_LIT:2> ) ; TextEditor subEditor = new TextEditor ( code ) ; subEditor . deleteAll ( "<STR_LIT>" ) . deleteAll ( "<STR_LIT>" ) ; encodeCode ( subEditor ) ; return "<STR_LIT>" + subEditor . toString ( ) + "<STR_LIT>" ; } } ) ; } private String deleteAll ( String text , String regex ) { return replaceAll ( text , regex , "<STR_LIT>" ) ; } private String replaceAll ( String text , String regex , String replacement ) { TextEditor ed = new TextEditor ( text ) ; ed . replaceAll ( regex , replacement ) ; return ed . toString ( ) ; } private String replaceAll ( String markup , Pattern pattern , Replacement replacement ) { TextEditor ed = new TextEditor ( markup ) ; ed . replaceAll ( pattern , replacement ) ; return ed . toString ( ) ; } @ Override public String toString ( ) { return "<STR_LIT>" ; } public static void main ( String [ ] args ) { StringBuffer buf = new StringBuffer ( ) ; char [ ] cbuf = new char [ <NUM_LIT> ] ; java . io . Reader in = new java . io . InputStreamReader ( System . in ) ; try { int charsRead = in . read ( cbuf ) ; while ( charsRead >= <NUM_LIT:0> ) { buf . append ( cbuf , <NUM_LIT:0> , charsRead ) ; charsRead = in . read ( cbuf ) ; } System . out . println ( new MarkdownProcessor ( ) . markdown ( buf . toString ( ) ) ) ; } catch ( java . io . IOException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( <NUM_LIT:1> ) ; } } } </s>
<s> package com . petebevin . markdown ; import java . util . Collection ; import java . util . HashMap ; import java . util . Map ; import java . util . Random ; class CharacterProtector { private Map < String , String > protectMap = new HashMap < String , String > ( ) ; private Map < String , String > unprotectMap = new HashMap < String , String > ( ) ; private static final String GOOD_CHARS = "<STR_LIT>" ; private Random rnd = new Random ( ) ; public String encode ( String literal ) { if ( ! protectMap . containsKey ( literal ) ) { addToken ( literal ) ; } return protectMap . get ( literal ) ; } public String decode ( String coded ) { return unprotectMap . get ( coded ) ; } public Collection < String > getAllEncodedTokens ( ) { return unprotectMap . keySet ( ) ; } private void addToken ( String literal ) { String encoded = longRandomString ( ) ; protectMap . put ( literal , encoded ) ; unprotectMap . put ( encoded , literal ) ; } private String longRandomString ( ) { StringBuffer sb = new StringBuffer ( ) ; final int CHAR_MAX = GOOD_CHARS . length ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; i ++ ) { sb . append ( GOOD_CHARS . charAt ( rnd . nextInt ( CHAR_MAX ) ) ) ; } return sb . toString ( ) ; } @ Override public String toString ( ) { return protectMap . toString ( ) ; } } </s>
<s> package com . petebevin . markdown ; import java . util . regex . Matcher ; public interface Replacement { String replacement ( Matcher m ) ; } </s>
<s> package com . petebevin . markdown ; public class HTMLToken { private boolean isTag ; private String text ; private HTMLToken ( boolean tag , String value ) { isTag = tag ; text = value ; } public static HTMLToken tag ( String text ) { return new HTMLToken ( true , text ) ; } public static HTMLToken text ( String text ) { return new HTMLToken ( false , text ) ; } public boolean isTag ( ) { return isTag ; } public String getText ( ) { return text ; } @ Override public String toString ( ) { String type ; if ( isTag ( ) ) { type = "<STR_LIT>" ; } else { type = "<STR_LIT:text>" ; } return type + "<STR_LIT::U+0020>" + getText ( ) ; } } </s>
<s> package com . petebevin . markdown ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class HTMLDecoder { public static String decode ( String html ) { TextEditor ed = new TextEditor ( html ) ; Pattern p1 = Pattern . compile ( "<STR_LIT>" ) ; ed . replaceAll ( p1 , new Replacement ( ) { public String replacement ( Matcher m ) { String charDecimal = m . group ( <NUM_LIT:1> ) ; char ch = ( char ) Integer . parseInt ( charDecimal ) ; return Character . toString ( ch ) ; } } ) ; Pattern p2 = Pattern . compile ( "<STR_LIT>" ) ; ed . replaceAll ( p2 , new Replacement ( ) { public String replacement ( Matcher m ) { String charHex = m . group ( <NUM_LIT:1> ) ; char ch = ( char ) Integer . parseInt ( charHex , <NUM_LIT:16> ) ; return Character . toString ( ch ) ; } } ) ; return ed . toString ( ) ; } } </s>
<s> package com . cookbook . domain ; import java . io . Serializable ; import javax . persistence . Entity ; import javax . persistence . GeneratedValue ; import javax . persistence . GenerationType ; import javax . persistence . Id ; import javax . persistence . TableGenerator ; @ Entity public class User implements DomainObject , Serializable { private static final long serialVersionUID = - <NUM_LIT> ; public User ( ) { super ( ) ; } public User ( long id , String name ) { super ( ) ; this . id = id ; this . firstName = name ; } @ TableGenerator ( name = "<STR_LIT>" , table = "<STR_LIT>" , pkColumnName = "<STR_LIT>" , valueColumnName = "<STR_LIT>" , pkColumnValue = "<STR_LIT>" , allocationSize = <NUM_LIT:1> ) @ Id @ GeneratedValue ( strategy = GenerationType . TABLE , generator = "<STR_LIT>" ) private long id ; private String firstName ; private String lastName ; private String empId ; private String status ; public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( int ) ( id ^ ( id > > > <NUM_LIT:32> ) ) ; return result ; } @ Override public boolean equals ( Object obj ) { boolean flag = false ; if ( this == obj ) { return true ; } if ( obj == null ) { return false ; } if ( obj instanceof User ) { User other = ( User ) obj ; if ( id == other . id ) { flag = true ; } } return flag ; } @ Override public String toString ( ) { return "<STR_LIT>" + id + "<STR_LIT>" + firstName + "<STR_LIT:]>" ; } public String getFirstName ( ) { return firstName ; } public void setFirstName ( String firstName ) { this . firstName = firstName ; } public String getLastName ( ) { return lastName ; } public void setLastName ( String lastName ) { this . lastName = lastName ; } public String getEmpId ( ) { return empId ; } public void setEmpId ( String empId ) { this . empId = empId ; } public String getStatus ( ) { return status ; } public void setStatus ( String status ) { this . status = status ; } } </s>
<s> package com . cookbook . domain ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . List ; import javax . persistence . CascadeType ; import javax . persistence . Entity ; import javax . persistence . GeneratedValue ; import javax . persistence . GenerationType ; import javax . persistence . Id ; import javax . persistence . OneToMany ; import javax . persistence . TableGenerator ; import javax . persistence . Version ; @ Entity public class Recipe implements DomainObject , Serializable { private static final long serialVersionUID = - <NUM_LIT> ; public Recipe ( long id , String title , String contents ) { super ( ) ; this . id = id ; this . title = title ; this . contents = contents ; } public Recipe ( ) { super ( ) ; } @ TableGenerator ( name = "<STR_LIT>" , table = "<STR_LIT>" , pkColumnName = "<STR_LIT>" , valueColumnName = "<STR_LIT>" , pkColumnValue = "<STR_LIT>" , allocationSize = <NUM_LIT:1> ) @ Id @ GeneratedValue ( strategy = GenerationType . TABLE , generator = "<STR_LIT>" ) private long id ; private String title ; private String contents ; @ OneToMany ( mappedBy = "<STR_LIT>" , cascade = CascadeType . ALL ) private List < Author > authors ; @ Version private int version ; public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } public String getTitle ( ) { return title ; } public void setTitle ( String title ) { this . title = title ; } public String getContents ( ) { return contents ; } public void setContents ( String contents ) { this . contents = contents ; } public List < Author > getAuthors ( ) { if ( authors == null ) authors = new ArrayList < Author > ( ) ; return authors ; } public boolean addAuthorToRecipe ( Author author ) { boolean flag = false ; if ( author != null ) { author . setRecipe ( this ) ; if ( authors != null ) { flag = this . authors . add ( author ) ; } else { authors = new ArrayList < Author > ( ) ; flag = this . authors . add ( author ) ; } } return flag ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( int ) ( id ^ ( id > > > <NUM_LIT:32> ) ) ; return result ; } @ Override public boolean equals ( Object obj ) { boolean flag = false ; if ( this == obj ) { return true ; } if ( obj == null ) { return false ; } if ( obj instanceof Recipe ) { Recipe other = ( Recipe ) obj ; if ( id == other . id ) { flag = true ; } } return flag ; } @ Override public String toString ( ) { return "<STR_LIT>" + id + "<STR_LIT>" + title + "<STR_LIT>" + contents + "<STR_LIT>" + authors + "<STR_LIT>" + version + "<STR_LIT:]>" ; } } </s>
<s> package com . cookbook . domain ; public interface DomainObject { } </s>
<s> package com . cookbook . domain ; import java . io . Serializable ; import java . util . Date ; import javax . persistence . Entity ; import javax . persistence . GeneratedValue ; import javax . persistence . GenerationType ; import javax . persistence . Id ; import javax . persistence . ManyToOne ; import javax . persistence . TableGenerator ; import javax . persistence . Temporal ; import javax . persistence . TemporalType ; @ Entity public class Author implements DomainObject , Serializable { private static final long serialVersionUID = - <NUM_LIT> ; public Author ( ) { super ( ) ; } public Author ( long id , String name ) { super ( ) ; this . id = id ; this . name = name ; } @ TableGenerator ( name = "<STR_LIT>" , table = "<STR_LIT>" , pkColumnName = "<STR_LIT>" , valueColumnName = "<STR_LIT>" , pkColumnValue = "<STR_LIT>" , allocationSize = <NUM_LIT:1> ) @ Id @ GeneratedValue ( strategy = GenerationType . TABLE , generator = "<STR_LIT>" ) private long id ; private String name ; @ Temporal ( TemporalType . TIMESTAMP ) private Date createdDate ; @ ManyToOne private Recipe recipe ; public long getId ( ) { return id ; } public void setId ( long id ) { this . id = id ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name . trim ( ) ; } public Recipe getRecipe ( ) { return recipe ; } public void setRecipe ( Recipe recipe ) { this . recipe = recipe ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( int ) ( id ^ ( id > > > <NUM_LIT:32> ) ) ; return result ; } @ Override public boolean equals ( Object obj ) { if ( ( obj == null ) || ( obj . getClass ( ) != this . getClass ( ) ) ) { System . out . println ( "<STR_LIT>" ) ; return false ; } if ( obj instanceof Author ) { Author other = ( Author ) obj ; if ( id == other . id ) { System . out . println ( "<STR_LIT>" ) ; return true ; } } if ( this == obj ) { return false ; } return false ; } @ Override public String toString ( ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( id ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( name ) ; builder . append ( "<STR_LIT>" ) ; builder . append ( createdDate ) ; builder . append ( "<STR_LIT>" ) ; if ( recipe != null ) builder . append ( recipe . getId ( ) ) ; builder . append ( "<STR_LIT:]>" ) ; return builder . toString ( ) ; } public Date getCreatedDate ( ) { return createdDate ; } public void setCreatedDate ( Date createdDate ) { this . createdDate = createdDate ; } } </s>
<s> package com . akkineni . domain ; import java . util . ArrayList ; import junit . framework . Assert ; import org . junit . Test ; import com . cookbook . domain . Author ; import com . cookbook . domain . Recipe ; public class AuthorTest { @ Test public void testEqualMethod ( ) { Author author = new Author ( <NUM_LIT:1> , "<STR_LIT>" ) ; Author author1 = new Author ( <NUM_LIT:1> , "<STR_LIT>" ) ; System . out . println ( author . hashCode ( ) + "<STR_LIT::>" + author1 . hashCode ( ) + "<STR_LIT:U+0020>" + author . equals ( author1 ) ) ; Assert . assertEquals ( true , author . equals ( author1 ) ) ; Assert . assertEquals ( false , author . equals ( null ) ) ; Assert . assertEquals ( false , author . equals ( new Object ( ) ) ) ; Assert . assertEquals ( false , author . equals ( new ArrayList < Object > ( ) ) ) ; author = new Author ( <NUM_LIT> , "<STR_LIT>" ) ; Object obj = new Author ( <NUM_LIT> , "<STR_LIT>" ) ; Assert . assertEquals ( false , author . equals ( obj ) ) ; Assert . assertEquals ( true , author . equals ( author ) ) ; author . setId ( <NUM_LIT> ) ; author1 . setId ( <NUM_LIT> ) ; boolean flag = author . equals ( author1 ) ; Assert . assertEquals ( true , flag ) ; } @ Test public void testGettersAndSetters ( ) { Author author = new Author ( ) ; author . setId ( <NUM_LIT:1> ) ; author . setName ( "<STR_LIT>" ) ; Recipe recipe = new Recipe ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" ) ; author . setRecipe ( recipe ) ; Assert . assertEquals ( <NUM_LIT:1> , author . getId ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , author . getName ( ) ) ; Assert . assertEquals ( recipe , author . getRecipe ( ) ) ; } @ Test public void testConstructors ( ) { Author author = new Author ( ) ; Assert . assertNotNull ( author ) ; Author author1 = new Author ( <NUM_LIT> , "<STR_LIT>" ) ; Assert . assertNotNull ( author1 ) ; Assert . assertEquals ( <NUM_LIT> , author1 . getId ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , author . toString ( ) ) ; } @ Test public void testHashCode ( ) { Author author1 = new Author ( <NUM_LIT:1> , "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT:32> , author1 . hashCode ( ) ) ; Author author2 = new Author ( <NUM_LIT:100> , "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT> , author2 . hashCode ( ) ) ; } } </s>
<s> package com . akkineni . domain ; import java . util . ArrayList ; import junit . framework . Assert ; import org . junit . BeforeClass ; import org . junit . Test ; import com . cookbook . domain . Author ; import com . cookbook . domain . Recipe ; public class RecipeTest { private static Recipe recipe ; @ BeforeClass public static void initialize ( ) { recipe = new Recipe ( ) ; } @ Test public void testEqualMethod ( ) { Recipe recipe2 = new Recipe ( <NUM_LIT:10> , "<STR_LIT>" , "<STR_LIT>" ) ; Recipe recipe3 = new Recipe ( <NUM_LIT:10> , "<STR_LIT>" , "<STR_LIT>" ) ; Assert . assertEquals ( true , recipe2 . equals ( recipe3 ) ) ; Assert . assertEquals ( false , recipe3 . equals ( null ) ) ; Assert . assertEquals ( false , recipe3 . equals ( new Object ( ) ) ) ; Assert . assertEquals ( false , recipe3 . equals ( new ArrayList < Object > ( ) ) ) ; recipe2 = new Recipe ( <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) ; Object obj = new Recipe ( <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) ; Assert . assertEquals ( false , recipe2 . equals ( obj ) ) ; Assert . assertEquals ( true , recipe2 . equals ( recipe2 ) ) ; recipe2 = new Recipe ( <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) ; Object obj2 = new Recipe ( <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) ; boolean flag = recipe2 . equals ( obj2 ) ; Assert . assertEquals ( true , flag ) ; } @ Test public void testGettersAndSetters ( ) { recipe . setId ( <NUM_LIT:1> ) ; recipe . setContents ( "<STR_LIT>" ) ; recipe . setTitle ( "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT:1> , recipe . getId ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , recipe . getContents ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , recipe . getTitle ( ) ) ; } @ Test public void testConstructors ( ) { recipe = new Recipe ( ) ; Assert . assertNotNull ( recipe ) ; recipe = new Recipe ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" ) ; Assert . assertNotNull ( recipe ) ; Assert . assertEquals ( <NUM_LIT:1> , recipe . getId ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , recipe . getContents ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , recipe . getTitle ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , recipe . toString ( ) ) ; } @ Test public void testHashCode ( ) { recipe = new Recipe ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT:32> , recipe . hashCode ( ) ) ; recipe = new Recipe ( <NUM_LIT:100> , "<STR_LIT>" , "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT> , recipe . hashCode ( ) ) ; } @ Test public void testAddAuthors ( ) { Assert . assertEquals ( <NUM_LIT:0> , recipe . getAuthors ( ) . size ( ) ) ; Author author1 = new Author ( <NUM_LIT:1> , "<STR_LIT>" ) ; Author author2 = new Author ( <NUM_LIT:2> , "<STR_LIT>" ) ; recipe = new Recipe ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" ) ; recipe . addAuthorToRecipe ( author1 ) ; recipe . addAuthorToRecipe ( author2 ) ; int testSize = recipe . getAuthors ( ) . size ( ) ; Assert . assertEquals ( <NUM_LIT:2> , testSize ) ; } } </s>
<s> package com . akkineni . test ; import org . junit . runner . RunWith ; import org . junit . runners . Suite ; import org . junit . runners . Suite . SuiteClasses ; import com . akkineni . domain . AuthorTest ; import com . akkineni . domain . RecipeTest ; @ RunWith ( value = Suite . class ) @ SuiteClasses ( value = { RecipeTest . class , AuthorTest . class } ) public class DomainClassesTestSuite { } </s>
<s> package cuke4duke . mojo ; import org . apache . maven . artifact . Artifact ; import org . apache . maven . artifact . repository . DefaultArtifactRepository ; import org . apache . maven . artifact . repository . layout . DefaultRepositoryLayout ; import org . apache . maven . plugin . MojoExecutionException ; import org . apache . maven . project . MavenProject ; import org . junit . Before ; import org . junit . Test ; import java . io . File ; import java . util . ArrayList ; import java . util . Arrays ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertTrue ; public class CucumberMojoTest { private CucumberMojo mojo ; @ Before public void setUp ( ) { mojo = new CucumberMojo ( ) ; mojo . launchDirectory = new File ( "<STR_LIT:.>" ) ; mojo . mavenProject = new MavenProject ( ) ; mojo . mavenProject . setFile ( new File ( "<STR_LIT>" ) ) ; mojo . compileClasspathElements = new ArrayList < String > ( ) ; mojo . pluginArtifacts = new ArrayList < Artifact > ( ) ; mojo . testClasspathElements = new ArrayList < String > ( ) ; mojo . localRepository = new DefaultArtifactRepository ( "<STR_LIT>" , "<STR_LIT>" , new DefaultRepositoryLayout ( ) ) ; } @ Test public void shouldAddCucumberArgs ( ) { String cucumberArg = "<STR_LIT>" ; mojo . cucumberArgs = new ArrayList < String > ( ) ; mojo . cucumberArgs . add ( cucumberArg ) ; assertTrue ( mojo . allCucumberArgs ( ) . contains ( cucumberArg ) ) ; } @ Test public void shouldAllowZeroAddCucumberArgs ( ) { mojo . extraCucumberArgs = null ; mojo . allCucumberArgs ( ) ; } @ Test public void shouldSplitAddCucumberArgsIntoRealCucumberArgs ( ) { mojo . extraCucumberArgs = "<STR_LIT>" ; assertEquals ( "<STR_LIT>" , mojo . allCucumberArgs ( ) ) ; } @ Test public void shouldIgnoreNullJvmArg ( ) throws MojoExecutionException { mojo . jvmArgs = Arrays . asList ( "<STR_LIT>" , null , "<STR_LIT>" ) ; assertEquals ( Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" ) , Arrays . asList ( mojo . cucumber ( "<STR_LIT>" ) . getCommandLine ( ) . getVmCommand ( ) . getArguments ( ) ) ) ; } } </s>
<s> package cuke4duke . mojo ; import java . io . File ; import java . util . ArrayList ; import java . util . List ; import org . apache . maven . artifact . Artifact ; import org . apache . maven . artifact . DependencyResolutionRequiredException ; import org . apache . maven . artifact . repository . ArtifactRepository ; import org . apache . maven . plugin . AbstractMojo ; import org . apache . maven . plugin . MojoExecutionException ; import org . apache . maven . plugin . logging . Log ; import org . apache . maven . project . MavenProject ; import org . apache . maven . settings . Proxy ; import org . apache . maven . settings . Settings ; import org . apache . tools . ant . BuildEvent ; import org . apache . tools . ant . BuildListener ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . types . Path ; import org . codehaus . plexus . util . StringUtils ; import cuke4duke . ant . GemTask ; public abstract class AbstractJRubyMojo extends AbstractMojo { protected MavenProject mavenProject ; private Settings settings ; protected File launchDirectory ; protected File gemDirectory ; protected List < String > compileClasspathElements ; protected List < Artifact > pluginArtifacts ; protected List < String > testClasspathElements ; protected ArtifactRepository localRepository ; protected abstract List < String > getJvmArgs ( ) ; protected void installGem ( String gemArgs ) throws MojoExecutionException { GemTask gem = new GemTask ( ) ; if ( gemDirectory != null && gemDirectory . exists ( ) ) { gem . setDir ( gemDirectory ) ; } gem . setProject ( getProject ( ) ) ; gem . setArgs ( gemArgs + getProxyArg ( ) ) ; gem . execute ( ) ; } protected String getProxyArg ( ) { Proxy activeProxy = this . settings . getActiveProxy ( ) ; if ( activeProxy == null ) { return "<STR_LIT>" ; } String proxyArg = "<STR_LIT>" + activeProxy . getProtocol ( ) + "<STR_LIT>" + activeProxy . getHost ( ) + "<STR_LIT::>" + activeProxy . getPort ( ) ; getLog ( ) . debug ( "<STR_LIT>" + proxyArg ) ; return proxyArg ; } protected File jrubyHome ( ) { return new File ( localRepository . getBasedir ( ) , "<STR_LIT>" ) ; } protected Project getProject ( ) throws MojoExecutionException { Project project = new Project ( ) ; project . setBaseDir ( mavenProject . getBasedir ( ) ) ; project . setProperty ( "<STR_LIT>" , jrubyHome ( ) . getAbsolutePath ( ) ) ; project . addBuildListener ( new LogAdapter ( ) ) ; Path jrubyClasspath = new Path ( project ) ; project . addReference ( "<STR_LIT>" , jrubyClasspath ) ; try { append ( jrubyClasspath , testClasspathElements ) ; append ( jrubyClasspath , compileClasspathElements ) ; append ( jrubyClasspath , pluginArtifacts ) ; return project ; } catch ( DependencyResolutionRequiredException e ) { throw new MojoExecutionException ( "<STR_LIT>" , e ) ; } } protected void append ( Path classPath , List < ? > artifacts ) throws DependencyResolutionRequiredException { List < String > list = new ArrayList < String > ( artifacts . size ( ) ) ; for ( Object elem : artifacts ) { String path ; if ( elem instanceof Artifact ) { Artifact a = ( Artifact ) elem ; File file = a . getFile ( ) ; if ( file == null ) { throw new DependencyResolutionRequiredException ( a ) ; } path = file . getPath ( ) ; } else { path = elem . toString ( ) ; } list . add ( path ) ; } Path p = new Path ( classPath . getProject ( ) ) ; p . setPath ( StringUtils . join ( list . iterator ( ) , File . pathSeparator ) ) ; classPath . append ( p ) ; } public class LogAdapter implements BuildListener { public void buildStarted ( BuildEvent event ) { log ( event ) ; } public void buildFinished ( BuildEvent event ) { log ( event ) ; } public void targetStarted ( BuildEvent event ) { log ( event ) ; } public void targetFinished ( BuildEvent event ) { log ( event ) ; } public void taskStarted ( BuildEvent event ) { log ( event ) ; } public void taskFinished ( BuildEvent event ) { log ( event ) ; } public void messageLogged ( BuildEvent event ) { log ( event ) ; } private void log ( BuildEvent event ) { int priority = event . getPriority ( ) ; Log log = getLog ( ) ; String message = event . getMessage ( ) ; switch ( priority ) { case Project . MSG_ERR : log . error ( message ) ; break ; case Project . MSG_WARN : log . warn ( message ) ; break ; case Project . MSG_INFO : log . info ( message ) ; break ; case Project . MSG_VERBOSE : log . debug ( message ) ; break ; case Project . MSG_DEBUG : log . debug ( message ) ; break ; default : log . info ( message ) ; break ; } } } } </s>
<s> package cuke4duke . mojo ; import cuke4duke . ant . CucumberTask ; import cuke4duke . internal . Utils ; import org . apache . maven . plugin . MojoExecutionException ; import org . apache . tools . ant . types . Commandline ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class CucumberMojo extends AbstractJRubyMojo { protected String features = "<STR_LIT>" ; protected boolean installGems = false ; private boolean skip ; protected boolean failOnError = true ; protected List < String > gems ; protected List < String > cucumberArgs = Collections . < String > emptyList ( ) ; protected String extraCucumberArgs ; protected List < String > jvmArgs ; public void execute ( ) throws MojoExecutionException { if ( installGems ) { for ( String gemSpec : gems ) { installGem ( gemSpec ) ; } } if ( skip ) { getLog ( ) . info ( "<STR_LIT>" ) ; return ; } CucumberTask cucumber = cucumber ( allCucumberArgs ( ) ) ; try { cucumber . execute ( ) ; } catch ( Exception e ) { if ( failOnError ) { throw new MojoExecutionException ( "<STR_LIT>" , e ) ; } } } public CucumberTask cucumber ( String args ) throws MojoExecutionException { CucumberTask cucumber = new CucumberTask ( ) ; cucumber . setProject ( getProject ( ) ) ; for ( String jvmArg : getJvmArgs ( ) ) { if ( jvmArg != null ) { Commandline . Argument arg = cucumber . createJvmarg ( ) ; arg . setValue ( jvmArg ) ; } } cucumber . setArgs ( args ) ; return cucumber ; } String allCucumberArgs ( ) { List < String > allCucumberArgs = new ArrayList < String > ( ) ; if ( cucumberArgs != null ) allCucumberArgs . addAll ( cucumberArgs ) ; if ( extraCucumberArgs != null ) allCucumberArgs . add ( extraCucumberArgs ) ; allCucumberArgs . add ( features ) ; return Utils . join ( allCucumberArgs . toArray ( ) , "<STR_LIT:U+0020>" ) ; } protected List < String > getJvmArgs ( ) { return ( jvmArgs != null ) ? jvmArgs : Collections . < String > emptyList ( ) ; } } </s>
<s> package cuke4duke . steps ; import cuke4duke . app . HelloService ; import org . springframework . beans . factory . annotation . Autowired ; import org . springframework . stereotype . Component ; @ Component public class SpringSteps extends AbstractSteps { @ Autowired private HelloService helloService ; protected HelloService getHelloService ( ) { return helloService ; } } </s>
<s> package cuke4duke . steps ; import cuke4duke . app . HelloService ; public class PicoContainerSteps extends AbstractSteps { private final HelloService helloService ; public PicoContainerSteps ( HelloService helloService ) { this . helloService = helloService ; } protected HelloService getHelloService ( ) { return helloService ; } } </s>
<s> package cuke4duke . steps ; import cuke4duke . annotation . I18n . EN . * ; import cuke4duke . app . HelloService ; import java . util . HashMap ; import java . util . Map ; public abstract class AbstractSteps { private final Map < String , Integer > cukes = new HashMap < String , Integer > ( ) ; protected abstract HelloService getHelloService ( ) ; @ Given ( "<STR_LIT>" ) public void iHaveNCukes ( int n , String color ) { this . cukes . put ( color , n ) ; } @ Then ( "<STR_LIT>" ) public void iShouldHaveNCukes ( int n , String color ) { if ( n != cukes . get ( color ) ) { throw new RuntimeException ( "<STR_LIT>" + n + "<STR_LIT>" + cukes . get ( color ) ) ; } } @ Given ( "<STR_LIT>" ) public void longs ( long n ) { } @ Given ( "<STR_LIT>" ) public void iSayHello ( ) { String hello = getHelloService ( ) . hello ( ) ; if ( ! hello . equals ( "<STR_LIT>" ) ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } public void thisIsNotAStep ( ) { } } </s>
<s> package cuke4duke . internal . java ; import cuke4duke . annotation . Pending ; import cuke4duke . spi . jruby . JRuby ; import cuke4duke . spi . jruby . JRubyExceptionFactory ; import org . junit . Before ; import org . junit . Test ; import java . lang . reflect . Method ; public class MethodInvokerTest { private class SomethingWithPending { @ Pending @ SuppressWarnings ( "<STR_LIT:unused>" ) public void dontExecuteMe ( ) { throw new RuntimeException ( "<STR_LIT>" ) ; } } @ Before public void definePendingException ( ) { JRuby . getRuntime ( ) . evalScriptlet ( "<STR_LIT>" ) ; } @ Test ( expected = org . jruby . exceptions . RaiseException . class ) public void shouldRaiseCucumberPendingWhenAnnotatedWithPending ( ) throws Throwable { Method dontExecuteMe = SomethingWithPending . class . getDeclaredMethod ( "<STR_LIT>" ) ; MethodInvoker mi = new MethodInvoker ( new JRubyExceptionFactory ( ) ) ; mi . invoke ( dontExecuteMe , new SomethingWithPending ( ) , new Object [ <NUM_LIT:0> ] ) ; } } </s>
<s> package cuke4duke . internal . java ; import org . junit . Before ; import org . junit . Test ; import java . io . IOException ; import java . lang . reflect . Method ; import java . util . List ; import java . util . Map ; import static org . junit . Assert . assertEquals ; public class MethodFormatTest { private Method methodWithArgsAndException ; private Method methodWithoutArgs ; public void methodWithoutArgs ( ) { } public List methodWithArgsAndException ( String foo , Map bar ) throws IllegalArgumentException , IOException { return null ; } @ Before public void lookupMethod ( ) throws NoSuchMethodException { this . methodWithoutArgs = this . getClass ( ) . getMethod ( "<STR_LIT>" ) ; this . methodWithArgsAndException = this . getClass ( ) . getMethod ( "<STR_LIT>" , String . class , Map . class ) ; } @ Test public void shouldUseSimpleFormatWhenMethodHasException ( ) { assertEquals ( "<STR_LIT>" , new MethodFormat ( "<STR_LIT>" ) . format ( methodWithArgsAndException ) ) ; } @ Test public void shouldUseSimpleFormatWhenMethodHasNoException ( ) { assertEquals ( "<STR_LIT>" , new MethodFormat ( "<STR_LIT>" ) . format ( methodWithoutArgs ) ) ; } } </s>
<s> package cuke4duke . internal . java ; import cuke4duke . annotation . I18n . EN . * ; import cuke4duke . StepMother ; import cuke4duke . internal . jvmclass . ClassAnalyzer ; import cuke4duke . internal . jvmclass . ClassLanguage ; import cuke4duke . internal . jvmclass . ClassLanguageMixin ; import cuke4duke . internal . language . AbstractStepDefinition ; import cuke4duke . internal . language . StepDefinition ; import cuke4duke . spi . ExceptionFactory ; import org . junit . Test ; import org . mockito . Mock ; import java . util . Arrays ; import java . util . List ; import static junit . framework . Assert . assertEquals ; import static org . mockito . Mockito . mock ; import static org . mockito . MockitoAnnotations . initMocks ; public class JavaAnalyzerTest { @ Mock private StepMother stepMother ; @ Mock private ClassLanguageMixin languageMixin ; public JavaAnalyzerTest ( ) { initMocks ( this ) ; } public abstract static class FlintStone { @ Given ( "<STR_LIT>" ) public Class whereIsDino ( ) { return getClass ( ) ; } } public static class Fred extends FlintStone { } public static class Wilma extends FlintStone { } @ Test public void shouldAllowOneInheritedSubclass ( ) throws Throwable { ClassLanguage classLanguage = new ClassLanguage ( languageMixin , mock ( ExceptionFactory . class ) , stepMother , Arrays . < ClassAnalyzer > asList ( new JavaAnalyzer ( ) ) ) ; classLanguage . addClass ( FlintStone . class ) ; classLanguage . addClass ( Fred . class ) ; classLanguage . begin_scenario ( null ) ; List < StepDefinition > stepDefinitions = classLanguage . getStepDefinitions ( ) ; assertEquals ( <NUM_LIT:1> , stepDefinitions . size ( ) ) ; assertEquals ( Fred . class , ( ( AbstractStepDefinition ) stepDefinitions . get ( <NUM_LIT:0> ) ) . invokeWithArgs ( new Object [ <NUM_LIT:0> ] ) ) ; } @ Test ( expected = Exception . class ) public void shouldFailWithTwoInheritedSubclass ( ) throws Throwable { ClassLanguage classLanguage = new ClassLanguage ( languageMixin , mock ( ExceptionFactory . class ) , stepMother , Arrays . < ClassAnalyzer > asList ( new JavaAnalyzer ( ) ) ) ; classLanguage . addClass ( FlintStone . class ) ; classLanguage . addClass ( Fred . class ) ; classLanguage . addClass ( Wilma . class ) ; classLanguage . begin_scenario ( null ) ; List < StepDefinition > stepDefinitions = classLanguage . getStepDefinitions ( ) ; assertEquals ( <NUM_LIT:1> , stepDefinitions . size ( ) ) ; assertEquals ( Fred . class , ( ( AbstractStepDefinition ) stepDefinitions . get ( <NUM_LIT:0> ) ) . invokeWithArgs ( new Object [ <NUM_LIT:0> ] ) ) ; } } </s>
<s> package cuke4duke . internal . jvmclass ; import cuke4duke . StepMother ; import cuke4duke . annotation . Order ; import cuke4duke . internal . java . JavaAnalyzer ; import cuke4duke . internal . java . JavaHook ; import cuke4duke . spi . ExceptionFactory ; import org . hamcrest . BaseMatcher ; import org . hamcrest . Description ; import org . hamcrest . Matcher ; import org . junit . Before ; import org . junit . Test ; import org . mockito . InOrder ; import java . util . Collections ; import static org . junit . Assert . assertEquals ; import static org . mockito . Matchers . argThat ; import static org . mockito . Matchers . eq ; import static org . mockito . Mockito . inOrder ; import static org . mockito . Mockito . mock ; public class ClassLanguageTest { private ClassLanguage language ; @ Before public void createLanguage ( ) throws Throwable { language = new ClassLanguage ( mock ( ClassLanguageMixin . class ) , mock ( ExceptionFactory . class ) , mock ( StepMother . class ) , Collections . < ClassAnalyzer > emptyList ( ) ) ; } @ Test public void shouldLoadExistingClassFromJavaFileName ( ) throws Throwable { language . load_code_file ( "<STR_LIT>" ) ; } @ Test ( expected = ClassNotFoundException . class ) public void shouldFailToLoadMissingClassFromJavaFileName ( ) throws Throwable { language . load_code_file ( "<STR_LIT>" ) ; } public static class A { private final B b ; public A ( B b ) { this . b = b ; } @ cuke4duke . annotation . Before ( ) @ Order ( <NUM_LIT:1> ) public void doA ( ) { assertEquals ( "<STR_LIT>" , b . message ) ; } } public static class B { public String message ; @ cuke4duke . annotation . Before ( ) @ Order ( <NUM_LIT:2> ) public void doB ( ) { message = "<STR_LIT>" ; } } @ Test public void shouldRunBeforeHooksInOrderOfDependencies ( ) throws Throwable { ObjectFactory objectFactory = new PicoFactory ( ) ; ClassLanguageMixin languageMixin = mock ( ClassLanguageMixin . class ) ; language = new ClassLanguage ( languageMixin , mock ( ExceptionFactory . class ) , mock ( StepMother . class ) , Collections . < ClassAnalyzer > singletonList ( new JavaAnalyzer ( ) ) , objectFactory ) ; language . addClass ( A . class ) ; language . addClass ( B . class ) ; language . begin_scenario ( null ) ; InOrder order = inOrder ( languageMixin ) ; order . verify ( languageMixin ) . add_hook ( eq ( "<STR_LIT>" ) , argThat ( isHook ( "<STR_LIT>" ) ) ) ; order . verify ( languageMixin ) . add_hook ( eq ( "<STR_LIT>" ) , argThat ( isHook ( "<STR_LIT>" ) ) ) ; } private Matcher < JavaHook > isHook ( String methodName ) { return new HookMatcher ( methodName ) ; } private class HookMatcher extends BaseMatcher < JavaHook > { private final String methodName ; private String actualMethodName ; public HookMatcher ( String methodName ) { this . methodName = methodName ; } public void describeTo ( Description description ) { description . appendText ( "<STR_LIT>" + methodName + "<STR_LIT>" + actualMethodName ) ; } public boolean matches ( Object o ) { JavaHook hook = ( JavaHook ) o ; actualMethodName = hook . getMethod ( ) . getName ( ) ; return methodName . equals ( actualMethodName ) ; } } } </s>
<s> package cuke4duke . internal . jvmclass ; import cuke4duke . annotation . Transform ; public class MyTransforms { @ Transform public boolean overrideBooleanTransform ( String yes ) { if ( yes . equals ( "<STR_LIT:yes>" ) ) return true ; else return false ; } } </s>
<s> package cuke4duke . internal . jvmclass ; import com . google . inject . AbstractModule ; public class SomeModule extends AbstractModule { @ Override protected void configure ( ) { } } </s>
<s> package cuke4duke . internal . jvmclass ; import com . google . inject . AbstractModule ; import cuke4duke . internal . jvmclass . GuiceFactoryTest . SomeClass . SomeInnerClass ; import org . junit . Before ; import org . junit . Test ; public class GuiceFactoryTest { public static class SomeClass { public class SomeInnerClass { } public Object someInstance = new Object ( ) { } ; } public class SomeModule extends AbstractModule { @ Override protected void configure ( ) { } } private GuiceFactory guiceFactory ; @ Before public void setUp ( ) throws Throwable { guiceFactory = new GuiceFactory ( "<STR_LIT>" ) ; } @ Test public void shouldNotAbortIfClassCannotBeInstantiated ( ) { guiceFactory . addClass ( SomeClass . class ) ; SomeClass instance = new SomeClass ( ) ; Class < ? extends SomeInnerClass > someInnerClass = instance . new SomeInnerClass ( ) . getClass ( ) ; if ( guiceFactory . canHandle ( someInnerClass ) ) { guiceFactory . addClass ( someInnerClass ) ; } guiceFactory . createObjects ( ) ; } } </s>
<s> package cuke4duke . internal . jvmclass ; import cuke4duke . Scenario ; import cuke4duke . internal . language . AbstractProgrammingLanguage ; import org . junit . Before ; import org . junit . Test ; import java . util . Locale ; import static org . junit . Assert . assertEquals ; public class ArgumentsConverterTest { private AbstractProgrammingLanguage p ; @ Before public void setup ( ) { p = new AbstractProgrammingLanguage ( null , null ) { @ Override public void load_code_file ( String file ) throws Throwable { } @ Override protected void begin_scenario ( Scenario scenario ) throws Throwable { } @ Override public void end_scenario ( ) throws Throwable { } @ Override protected Object customTransform ( Object arg , Class < ? > parameterType , Locale locale ) throws Throwable { return null ; } } ; } @ Test public void shouldConvertFromStringToObject ( ) throws Throwable { assertEquals ( "<STR_LIT>" , p . transformOne ( "<STR_LIT>" , Object . class , Locale . getDefault ( ) ) ) ; } @ Test public void shouldConvertFromStringToInt ( ) throws Throwable { assertEquals ( <NUM_LIT:3> , p . transformOne ( "<STR_LIT:3>" , Integer . TYPE , Locale . getDefault ( ) ) ) ; } @ Test public void shouldConvertFromStringToInteger ( ) throws Throwable { assertEquals ( <NUM_LIT:4> , p . transformOne ( "<STR_LIT:4>" , Integer . class , Locale . getDefault ( ) ) ) ; } @ Test public void shouldConvertFromStringToLongPrimitive ( ) throws Throwable { assertEquals ( <NUM_LIT> , p . transformOne ( "<STR_LIT:3>" , Long . TYPE , Locale . getDefault ( ) ) ) ; } @ Test public void shouldConvertFromStringToLong ( ) throws Throwable { assertEquals ( <NUM_LIT> , p . transformOne ( "<STR_LIT:4>" , Long . class , Locale . getDefault ( ) ) ) ; } } </s>
<s> package cuke4duke . internal . language ; import org . junit . Test ; import java . io . UnsupportedEncodingException ; import java . util . List ; import java . util . regex . Pattern ; import static org . junit . Assert . assertEquals ; public class JdkPatternArgumentMatcherTest { @ Test public void shouldDealWithOnlyAscii ( ) throws UnsupportedEncodingException { assertVariables ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:3> , "<STR_LIT>" , <NUM_LIT> ) ; } @ Test public void shouldDealWithUnicodeInsideCaptures ( ) throws UnsupportedEncodingException { assertVariables ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:3> , "<STR_LIT>" , <NUM_LIT> ) ; } @ Test public void shouldDealWithUnicodeOutsideCaptures ( ) throws UnsupportedEncodingException { assertVariables ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , "<STR_LIT>" , <NUM_LIT:15> ) ; } @ Test public void shouldDealWithUnicodeEverywhere ( ) throws UnsupportedEncodingException { assertVariables ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:4> , "<STR_LIT>" , <NUM_LIT:16> ) ; } private void assertVariables ( String regex , String string , String v1 , int pos1 , String v2 , int pos2 ) throws UnsupportedEncodingException { List < StepArgument > args = JdkPatternArgumentMatcher . argumentsFrom ( Pattern . compile ( regex ) , string ) ; assertEquals ( <NUM_LIT:2> , args . size ( ) ) ; assertEquals ( v1 , args . get ( <NUM_LIT:0> ) . getVal ( ) ) ; assertEquals ( pos1 , args . get ( <NUM_LIT:0> ) . getByteOffset ( ) ) ; assertEquals ( v2 , args . get ( <NUM_LIT:1> ) . getVal ( ) ) ; assertEquals ( pos2 , args . get ( <NUM_LIT:1> ) . getByteOffset ( ) ) ; } } </s>
<s> package cuke4duke . internal ; import org . junit . Test ; import java . text . NumberFormat ; import java . text . ParseException ; import java . util . Locale ; import static org . junit . Assert . * ; public class UtilsTest { @ Test public void shouldCreateEnglishLocale ( ) { assertEquals ( Locale . ENGLISH , Utils . localeFor ( "<STR_LIT:en>" ) ) ; } @ Test public void shouldCreateUSLocale ( ) { assertEquals ( Locale . US , Utils . localeFor ( "<STR_LIT>" ) ) ; } @ Test public void shouldFormatLolcatDoubles ( ) throws ParseException { assertEquals ( <NUM_LIT> , NumberFormat . getInstance ( Utils . localeFor ( "<STR_LIT>" ) ) . parse ( "<STR_LIT>" ) . doubleValue ( ) , <NUM_LIT:0.0> ) ; } @ Test public void shouldFormatEnglishDoubles ( ) throws ParseException { assertEquals ( <NUM_LIT> , NumberFormat . getInstance ( Utils . localeFor ( "<STR_LIT>" ) ) . parse ( "<STR_LIT>" ) . doubleValue ( ) , <NUM_LIT:0.0> ) ; } @ Test public void shouldFormatNorwegianDoubles ( ) throws ParseException { assertEquals ( <NUM_LIT> , NumberFormat . getInstance ( Utils . localeFor ( "<STR_LIT>" ) ) . parse ( "<STR_LIT>" ) . doubleValue ( ) , <NUM_LIT:0.0> ) ; } @ Test public void shouldFormatNorwegianDoublesWithEnglishLocaleDifferently ( ) throws ParseException { assertEquals ( <NUM_LIT> , NumberFormat . getInstance ( Utils . localeFor ( "<STR_LIT>" ) ) . parse ( "<STR_LIT>" ) . doubleValue ( ) , <NUM_LIT:0.0> ) ; } } </s>
<s> package cuke4duke . junit ; import cuke4duke . annotation . I18n . EN . * ; import cuke4duke . Table ; import java . util . HashMap ; import java . util . Map ; import static org . junit . Assert . assertEquals ; public class JunitCukeSteps { private final Map < String , Integer > cukes = new HashMap < String , Integer > ( ) ; @ Given ( "<STR_LIT>" ) public void iHaveNCukes ( int n , String color ) { this . cukes . put ( color , n ) ; } @ Then ( "<STR_LIT>" ) public void iShouldHaveNCukes ( int n , String color ) { int cukesOfColor = cukes . get ( color ) ; if ( n != cukesOfColor ) { throw new RuntimeException ( "<STR_LIT>" + n + "<STR_LIT>" + cukes . get ( color ) ) ; } } @ When ( "<STR_LIT>" ) public void aTable ( Table table ) { assertEquals ( <NUM_LIT:1> , table . hashes ( ) . size ( ) ) ; } @ Given ( "<STR_LIT>" ) public void longs ( long n ) { } public void thisIsNotAStep ( ) { } } </s>
<s> package cuke4duke . app ; import org . springframework . stereotype . Service ; @ Service public class SpringHelloService implements HelloService { public String hello ( ) { return "<STR_LIT>" ; } } </s>
<s> package cuke4duke . app ; public class PicoContainerHelloService implements HelloService { public String hello ( ) { return "<STR_LIT>" ; } } </s>
<s> package cuke4duke . app ; public interface HelloService { String hello ( ) ; } </s>
<s> package cuke4duke . ant ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . taskdefs . Java ; import org . apache . tools . ant . types . Environment ; import org . apache . tools . ant . types . Path ; import java . io . File ; public class JRubyTask extends Java { public JRubyTask ( ) { setFork ( true ) ; setFailonerror ( true ) ; } @ Override public void execute ( ) throws BuildException { setClassname ( "<STR_LIT>" ) ; setClasspath ( getJrubyClasspath ( ) ) ; ensureJrubyHomeExists ( ) ; setJRubyHome ( ) ; super . execute ( ) ; } protected File getJrubyHome ( ) { String gemHome = getProject ( ) . getProperty ( "<STR_LIT>" ) ; if ( gemHome == null ) { throw new BuildException ( "<STR_LIT>" ) ; } return new File ( gemHome ) ; } protected File getBinDir ( ) { return new File ( getJrubyHome ( ) , "<STR_LIT>" ) ; } private void ensureJrubyHomeExists ( ) { getJrubyHome ( ) . mkdirs ( ) ; } private Path getJrubyClasspath ( ) { Object jrubyClasspath = getProject ( ) . getReference ( "<STR_LIT>" ) ; if ( jrubyClasspath == null || ! ( jrubyClasspath instanceof Path ) ) { throw new BuildException ( "<STR_LIT>" ) ; } return ( Path ) jrubyClasspath ; } private void setJRubyHome ( ) { Environment . Variable gemHome = new Environment . Variable ( ) ; gemHome . setKey ( "<STR_LIT>" ) ; gemHome . setFile ( getJrubyHome ( ) ) ; this . addEnv ( gemHome ) ; Environment . Variable gemPath = new Environment . Variable ( ) ; gemPath . setKey ( "<STR_LIT>" ) ; gemPath . setFile ( getJrubyHome ( ) ) ; this . addEnv ( gemPath ) ; } } </s>
<s> package cuke4duke . ant ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . types . Environment ; import java . io . File ; public class CucumberTask extends JRubyTask { private String args = "<STR_LIT>" ; private File bin ; public void execute ( ) throws BuildException { createArg ( ) . setFile ( getCuke4dukeBinFile ( ) ) ; getCommandLine ( ) . createArgument ( ) . setLine ( args ) ; super . execute ( ) ; } public void setArgs ( String args ) { this . args = args ; } public void setBin ( File bin ) { this . bin = bin ; } public void setObjectFactory ( String name ) { Environment . Variable objectFactory = new Environment . Variable ( ) ; objectFactory . setKey ( "<STR_LIT>" ) ; objectFactory . setValue ( "<STR_LIT>" + name . substring ( <NUM_LIT:0> , <NUM_LIT:1> ) . toUpperCase ( ) + name . substring ( <NUM_LIT:1> ) + "<STR_LIT>" ) ; this . addSysproperty ( objectFactory ) ; } private File getCuke4dukeBinFile ( ) { if ( bin != null ) { return bin ; } else if ( System . getProperty ( "<STR_LIT>" ) != null ) { return new File ( System . getProperty ( "<STR_LIT>" ) ) ; } else { return new File ( getBinDir ( ) , "<STR_LIT>" ) ; } } } </s>
<s> package cuke4duke . ant ; import org . apache . tools . ant . BuildException ; public class GemTask extends JRubyTask { private String args = "<STR_LIT>" ; public GemTask ( ) { createJvmarg ( ) . setValue ( "<STR_LIT>" ) ; } public void execute ( ) throws BuildException { createArg ( ) . setValue ( "<STR_LIT>" ) ; createArg ( ) . setValue ( "<STR_LIT>" ) ; getCommandLine ( ) . createArgument ( ) . setLine ( args ) ; createArg ( ) . setValue ( "<STR_LIT>" ) ; createArg ( ) . setFile ( getJrubyHome ( ) ) ; createArg ( ) . setValue ( "<STR_LIT>" ) ; createArg ( ) . setValue ( "<STR_LIT>" ) ; try { super . execute ( ) ; } catch ( Exception e ) { throw new BuildException ( "<STR_LIT>" + args , e ) ; } } public void setArgs ( String args ) { this . args = args ; } } </s>
<s> package cuke4duke ; import cuke4duke . internal . groovy . GroovyHook ; import cuke4duke . internal . groovy . GroovyLanguage ; import cuke4duke . internal . groovy . GroovyStepDefinition ; import cuke4duke . internal . language . LanguageMixin ; import groovy . lang . Closure ; import java . util . Arrays ; import java . util . regex . Pattern ; public class GroovyDsl { public static GroovyLanguage groovyLanguage ; public static LanguageMixin languageMixin ; public static void World ( Closure body ) { groovyLanguage . registerWorldFactory ( body ) ; } public static void Before ( Object ... tagsAndBody ) { addHook ( "<STR_LIT>" , tagsAndBody ) ; } public static void After ( Object ... tagsAndBody ) { addHook ( "<STR_LIT>" , tagsAndBody ) ; } private static void addHook ( String phase , Object [ ] tagsAndBody ) { if ( tagsAndBody . length == <NUM_LIT:0> ) return ; String [ ] tagNames = new String [ tagsAndBody . length - <NUM_LIT:1> ] ; System . arraycopy ( tagsAndBody , <NUM_LIT:0> , tagNames , <NUM_LIT:0> , tagNames . length ) ; Closure body = ( Closure ) tagsAndBody [ tagsAndBody . length - <NUM_LIT:1> ] ; languageMixin . add_hook ( phase , new GroovyHook ( Arrays . asList ( tagNames ) , body , groovyLanguage ) ) ; } public static void Given ( Pattern regexp , Closure body ) throws Throwable { registerStepDefinition ( regexp , body ) ; } public static void When ( Pattern regexp , Closure body ) throws Throwable { registerStepDefinition ( regexp , body ) ; } public static void Then ( Pattern regexp , Closure body ) throws Throwable { registerStepDefinition ( regexp , body ) ; } private static void registerStepDefinition ( Pattern regexp , Closure body ) throws Throwable { groovyLanguage . addStepDefinition ( new GroovyStepDefinition ( groovyLanguage , regexp , body ) ) ; } } </s>
<s> package cuke4duke . internal . js ; import cuke4duke . Scenario ; import cuke4duke . internal . language . AbstractProgrammingLanguage ; import cuke4duke . internal . language . LanguageMixin ; import cuke4duke . spi . ExceptionFactory ; import org . mozilla . javascript . Context ; import org . mozilla . javascript . NativeFunction ; import org . mozilla . javascript . Scriptable ; import org . mozilla . javascript . regexp . NativeRegExp ; import org . mozilla . javascript . tools . shell . Global ; import java . io . FileReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; import java . util . Locale ; public class JsLanguage extends AbstractProgrammingLanguage { private static final String JS_DSL = "<STR_LIT>" ; private final List < String > jsFiles = new ArrayList < String > ( ) ; private Context cx ; private Scriptable scope ; public JsLanguage ( LanguageMixin languageMixin , ExceptionFactory exceptionFactory ) throws Exception { super ( languageMixin , exceptionFactory ) ; } public void load_code_file ( String jsFile ) throws Throwable { jsFiles . add ( jsFile ) ; } protected void begin_scenario ( Scenario scenario ) throws Throwable { clearHooksAndStepDefinitions ( ) ; cx = Context . enter ( ) ; scope = new Global ( cx ) ; scope . put ( "<STR_LIT>" , scope , this ) ; cx . evaluateReader ( scope , new InputStreamReader ( getClass ( ) . getResourceAsStream ( JS_DSL ) ) , JS_DSL , <NUM_LIT:1> , null ) ; for ( String jsFile : jsFiles ) { cx . evaluateReader ( scope , new FileReader ( jsFile ) , jsFile , <NUM_LIT:1> , null ) ; } } public void addStepDefinition ( Global jsStepDefinition , NativeFunction argumentsFrom , NativeRegExp regexp , NativeFunction closure ) throws Throwable { addStepDefinition ( new JsStepDefinition ( this , cx , scope , jsStepDefinition , argumentsFrom , regexp , closure ) ) ; } public void end_scenario ( ) throws Throwable { } @ Override protected Object customTransform ( Object arg , Class < ? > parameterType , Locale locale ) { return null ; } } </s>
<s> package cuke4duke . internal . js ; import cuke4duke . internal . language . AbstractStepDefinition ; import cuke4duke . internal . language . StepArgument ; import org . mozilla . javascript . Context ; import org . mozilla . javascript . NativeFunction ; import org . mozilla . javascript . Scriptable ; import org . mozilla . javascript . regexp . NativeRegExp ; import org . mozilla . javascript . tools . shell . Global ; import java . util . List ; public class JsStepDefinition extends AbstractStepDefinition { private final Context cx ; private final Scriptable scope ; private final Global jsStepDefinition ; private final NativeFunction argumentsFrom ; private final NativeRegExp regexp ; private final NativeFunction closure ; private List < StepArgument > arguments ; public JsStepDefinition ( JsLanguage programmingLanguage , Context cx , Scriptable scope , Global jsStepDefinition , NativeFunction argumentsFrom , NativeRegExp regexp , NativeFunction closure ) throws Throwable { super ( programmingLanguage ) ; this . cx = cx ; this . scope = scope ; this . jsStepDefinition = jsStepDefinition ; this . argumentsFrom = argumentsFrom ; this . regexp = regexp ; this . closure = closure ; register ( ) ; } public String regexp_source ( ) { return regexp . toString ( ) ; } public String file_colon_line ( ) { return regexp_source ( ) ; } public Object invokeWithArgs ( Object [ ] args ) throws Throwable { return closure . call ( cx , scope , scope , args ) ; } public List < StepArgument > arguments_from ( String stepName ) { arguments = null ; argumentsFrom . call ( cx , scope , jsStepDefinition , new Object [ ] { stepName , this } ) ; return arguments ; } public void addArguments ( List < StepArgument > arguments ) { this . arguments = arguments ; } } </s>
<s> package cuke4duke . internal . clj ; import clojure . lang . AFunction ; import cuke4duke . internal . Utils ; import cuke4duke . internal . language . AbstractStepDefinition ; import cuke4duke . internal . language . JdkPatternArgumentMatcher ; import cuke4duke . internal . language . StepArgument ; import java . io . UnsupportedEncodingException ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Method ; import java . util . List ; import java . util . regex . Pattern ; public class CljStepDefinition extends AbstractStepDefinition { private final Pattern regexp ; private final AFunction closure ; public CljStepDefinition ( CljLanguage cljLanguage , Pattern regexp , AFunction closure ) throws Throwable { super ( cljLanguage ) ; this . regexp = regexp ; this . closure = closure ; register ( ) ; } public String regexp_source ( ) { return regexp . pattern ( ) ; } public String file_colon_line ( ) { return regexp_source ( ) ; } @ Override public Object invokeWithArgs ( Object [ ] javaArgs ) throws Throwable { Method functionInvoke = lookupInvokeMethod ( javaArgs ) ; try { return functionInvoke . invoke ( closure , javaArgs ) ; } catch ( InvocationTargetException e ) { throw e . getTargetException ( ) ; } } public List < StepArgument > arguments_from ( String stepName ) throws UnsupportedEncodingException { return JdkPatternArgumentMatcher . argumentsFrom ( regexp , stepName ) ; } private Method lookupInvokeMethod ( Object [ ] args ) throws NoSuchMethodException { return AFunction . class . getMethod ( "<STR_LIT>" , Utils . objectClassArray ( args . length ) ) ; } } </s>
<s> package cuke4duke . internal . clj ; import clojure . lang . AFunction ; import cuke4duke . Scenario ; import cuke4duke . internal . language . AbstractHook ; import java . util . List ; public class CljHook extends AbstractHook { private final AFunction closure ; public CljHook ( List < String > tagExpressions , AFunction closure ) { super ( tagExpressions ) ; this . closure = closure ; } public void invoke ( String location , Scenario scenario ) throws Throwable { closure . call ( ) ; } } </s>
<s> package cuke4duke . internal . clj ; import clojure . lang . AFunction ; import clojure . lang . Compiler ; import clojure . lang . RT ; import cuke4duke . Scenario ; import cuke4duke . internal . language . AbstractProgrammingLanguage ; import cuke4duke . internal . language . LanguageMixin ; import cuke4duke . spi . ExceptionFactory ; import java . util . Collections ; import java . util . Locale ; import java . util . regex . Pattern ; public class CljLanguage extends AbstractProgrammingLanguage { private static CljLanguage instance ; public CljLanguage ( LanguageMixin languageMixin , ExceptionFactory exceptionFactory ) throws Exception { super ( languageMixin , exceptionFactory ) ; instance = this ; clearHooksAndStepDefinitions ( ) ; RT . load ( "<STR_LIT>" ) ; } public static void addCljStepDefinition ( Pattern regexp , AFunction closure ) throws Throwable { instance . addStepDefinition ( new CljStepDefinition ( instance , regexp , closure ) ) ; } public static void addCljBeforeHook ( AFunction closure ) { instance . addBeforeHook ( new CljHook ( Collections . < String > emptyList ( ) , closure ) ) ; } public static void addCljAfterHook ( AFunction closure ) { instance . addAfterHook ( new CljHook ( Collections . < String > emptyList ( ) , closure ) ) ; } public void load_code_file ( String cljFile ) throws Throwable { Compiler . loadFile ( cljFile ) ; } protected void begin_scenario ( Scenario scenario ) throws Throwable { } public void end_scenario ( ) throws Throwable { } @ Override protected Object customTransform ( Object arg , Class < ? > parameterType , Locale locale ) { return null ; } } </s>
<s> package cuke4duke . internal ; import java . util . Locale ; public class Utils { public static String join ( Object [ ] objects , String separator ) { StringBuilder sb = new StringBuilder ( ) ; int i = <NUM_LIT:0> ; for ( Object o : objects ) { if ( i != <NUM_LIT:0> ) sb . append ( separator ) ; sb . append ( o ) ; i ++ ; } return sb . toString ( ) ; } public static Class < ? > [ ] objectClassArray ( int n ) { Class < ? > [ ] arr = new Class < ? > [ n ] ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { arr [ i ] = Object . class ; } return arr ; } public static Locale localeFor ( String isoString ) { String [ ] languageAndCountry = isoString . split ( "<STR_LIT:->" ) ; if ( languageAndCountry . length == <NUM_LIT:1> ) { return new Locale ( isoString ) ; } else { return new Locale ( languageAndCountry [ <NUM_LIT:0> ] , languageAndCountry [ <NUM_LIT:1> ] ) ; } } } </s>
<s> package cuke4duke . internal . ik ; import cuke4duke . PyString ; import cuke4duke . Table ; import cuke4duke . internal . language . AbstractStepDefinition ; import cuke4duke . internal . language . StepArgument ; import ioke . lang . IokeObject ; import ioke . lang . Message ; import ioke . lang . Runtime ; import ioke . lang . exceptions . ControlFlow ; import java . util . ArrayList ; import java . util . List ; public class IkStepDefinition extends AbstractStepDefinition { private final Runtime ioke ; private final IokeObject iokeStepDefObject ; private String regexpSource ; private final IkLanguage lang ; public IkStepDefinition ( IkLanguage ikLanguage , Runtime ioke , IokeObject iokeStepDefObject ) throws Throwable { super ( ikLanguage ) ; this . ioke = ioke ; this . iokeStepDefObject = iokeStepDefObject ; this . lang = ikLanguage ; register ( ) ; } public Object invokeWithArgs ( Object [ ] args ) throws Throwable { IokeObject msg = ioke . newMessage ( "<STR_LIT>" ) ; Message invoke = ( Message ) IokeObject . data ( msg ) ; List < Runtime . RescueInfo > pendingRescues = new ArrayList < Runtime . RescueInfo > ( ) ; IokeObject rr = IokeObject . as ( ( ( Message ) IokeObject . data ( ioke . mimic ) ) . sendTo ( ioke . mimic , ioke . ground , ioke . rescue ) , ioke . ground ) ; List < Object > conds = new ArrayList < Object > ( ) ; conds . add ( lang . pendingCondition ) ; pendingRescues . add ( new Runtime . RescueInfo ( rr , conds , pendingRescues , ioke . getBindIndex ( ) ) ) ; ioke . registerRescues ( pendingRescues ) ; List < Runtime . RescueInfo > failureRescues = new ArrayList < Runtime . RescueInfo > ( ) ; IokeObject rr2 = IokeObject . as ( ( ( Message ) IokeObject . data ( ioke . mimic ) ) . sendTo ( ioke . mimic , ioke . ground , ioke . rescue ) , ioke . ground ) ; List < Object > failureConds = new ArrayList < Object > ( ) ; failureConds . add ( lang . failedExpectationCondition ) ; failureRescues . add ( new Runtime . RescueInfo ( rr2 , failureConds , failureRescues , ioke . getBindIndex ( ) ) ) ; ioke . registerRescues ( failureRescues ) ; try { return invoke . sendTo ( msg , iokeStepDefObject , iokeStepDefObject , multilineArg ( args ) ) ; } catch ( ControlFlow . Rescue e ) { if ( e . getRescue ( ) . token == pendingRescues ) { throw lang . cucumberPending ( "<STR_LIT>" ) ; } else if ( e . getRescue ( ) . token == failureRescues ) { throw lang . error ( "<STR_LIT>" , ( ( Message ) IokeObject . data ( ioke . reportMessage ) ) . sendTo ( ioke . reportMessage , ioke . ground , e . getCondition ( ) ) . toString ( ) ) ; } else { throw e ; } } finally { ioke . unregisterRescues ( failureRescues ) ; ioke . unregisterRescues ( pendingRescues ) ; } } public String regexp_source ( ) throws Throwable { if ( regexpSource == null ) findRegexpSource ( ) ; return regexpSource ; } public String file_colon_line ( ) throws Throwable { return regexp_source ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public List < StepArgument > arguments_from ( String stepName ) throws Throwable { IokeObject msg = ioke . newMessage ( "<STR_LIT>" ) ; Message arguments_from = ( Message ) IokeObject . data ( msg ) ; Object args = arguments_from . sendTo ( msg , iokeStepDefObject , iokeStepDefObject , stepName ) ; if ( args instanceof List < ? > ) { return ( List < StepArgument > ) args ; } else { return null ; } } private void findRegexpSource ( ) throws ControlFlow { IokeObject msg = ioke . newMessage ( "<STR_LIT>" ) ; Message regexp_source = ( Message ) IokeObject . data ( msg ) ; regexpSource = regexp_source . sendTo ( msg , iokeStepDefObject , iokeStepDefObject ) . toString ( ) ; } private Object multilineArg ( Object [ ] args ) { Object multilineArg ; if ( args . length > <NUM_LIT:0> ) { if ( args [ args . length - <NUM_LIT:1> ] instanceof PyString ) { multilineArg = ioke . newText ( ( ( PyString ) args [ args . length - <NUM_LIT:1> ] ) . to_s ( ) ) ; } else if ( args [ args . length - <NUM_LIT:1> ] instanceof Table ) { multilineArg = args [ args . length - <NUM_LIT:1> ] ; } else { multilineArg = ioke . nil ; } } else { multilineArg = ioke . nil ; } return multilineArg ; } } </s>
<s> package cuke4duke . internal . ik ; import cuke4duke . Scenario ; import cuke4duke . internal . language . AbstractProgrammingLanguage ; import cuke4duke . internal . language . LanguageMixin ; import cuke4duke . spi . ExceptionFactory ; import ioke . lang . IokeObject ; import ioke . lang . Runtime ; import ioke . lang . exceptions . ControlFlow ; import java . util . Locale ; public class IkLanguage extends AbstractProgrammingLanguage { private final Runtime ioke ; final IokeObject pendingCondition ; final IokeObject failedExpectationCondition ; public IkLanguage ( LanguageMixin languageMixin , ExceptionFactory exceptionFactory ) throws Exception , ControlFlow { super ( languageMixin , exceptionFactory ) ; ioke = new Runtime ( ) ; ioke . init ( ) ; ioke . ground . setCell ( "<STR_LIT>" , this ) ; ioke . evaluateString ( "<STR_LIT>" ) ; clearHooksAndStepDefinitions ( ) ; pendingCondition = IokeObject . as ( IokeObject . getCellChain ( ioke . condition , ioke . message , ioke . ground , "<STR_LIT>" ) , ioke . ground ) ; failedExpectationCondition = IokeObject . as ( IokeObject . getCellChain ( ioke . condition , ioke . message , ioke . ground , "<STR_LIT>" , "<STR_LIT>" ) , ioke . ground ) ; } public void addIokeStepDefinition ( Object iokeStepDefObject ) throws Throwable { addStepDefinition ( new IkStepDefinition ( this , ioke , ( IokeObject ) iokeStepDefObject ) ) ; } public void load_code_file ( String ikFile ) throws Throwable { this . ioke . evaluateString ( "<STR_LIT>" + ikFile + "<STR_LIT>" ) ; } protected void begin_scenario ( Scenario scenario ) throws Throwable { } public void end_scenario ( ) throws Throwable { } @ Override protected Object customTransform ( Object arg , Class < ? > parameterType , Locale locale ) { return null ; } } </s>