repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Left.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Left extends CommandGroup { public Auto_Pos1Left() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Left.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Left extends CommandGroup { public Auto_Pos1Left() { this.addParallel(new Auto_LoadBall());
this.addSequential(new EncoderPosDriveCommand(9088, 0.65));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Left.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Left extends CommandGroup { public Auto_Pos1Left() { this.addParallel(new Auto_LoadBall()); this.addSequential(new EncoderPosDriveCommand(9088, 0.65));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Left.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Left extends CommandGroup { public Auto_Pos1Left() { this.addParallel(new Auto_LoadBall()); this.addSequential(new EncoderPosDriveCommand(9088, 0.65));
this.addSequential(new TurnByAngleCommand(59.4));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultShootCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultShootCommand extends Command { Timer timer; public CatapultShootCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultShootCommand.java import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultShootCommand extends Command { Timer timer; public CatapultShootCommand() {
requires(Robot.catapult);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/SpeedDriveCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.PIDController; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.chassis; public class SpeedDriveCommand extends Command { public static final double MAX_SPEED = 0; // TODO: Find max encoder speed private final double Kp = 0.25; private final double Ki = 0.15; private final double Kd = 0; private PIDController _leftSpeedController; private PIDController _rightSpeedController; private double leftSpeed = 0; private double rightSpeed = 0; public SpeedDriveCommand(double leftSpeed, double rightSpeed) {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/SpeedDriveCommand.java import edu.wpi.first.wpilibj.PIDController; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.chassis; public class SpeedDriveCommand extends Command { public static final double MAX_SPEED = 0; // TODO: Find max encoder speed private final double Kp = 0.25; private final double Ki = 0.15; private final double Kd = 0; private PIDController _leftSpeedController; private PIDController _rightSpeedController; private double leftSpeed = 0; private double rightSpeed = 0; public SpeedDriveCommand(double leftSpeed, double rightSpeed) {
requires(Robot.chassis);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Intake.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeStopCommand.java // public class IntakeStopCommand extends Command { // // public IntakeStopCommand() { // requires(Robot.intake); // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // if(Robot.oi.manipulator.getRawAxis(3) >= 0.1) { // Robot.intake.set(Robot.oi.manipulator.getRawAxis(3) / 2); // }else if(Robot.oi.manipulator.getRawAxis(2) >= 0.1) { // Robot.intake.set(Robot.oi.manipulator.getRawAxis(2) / -2); // }else{ // Robot.intake.set(0); // } // } // // @Override // protected boolean isFinished() { // return false; // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // }
import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.intake.IntakeStopCommand;
package org.usfirst.frc.team2557.robot.subsystems; public class Intake extends Subsystem { CANTalon intakeMotor = RobotMap.intakeMotor; @Override protected void initDefaultCommand() { // Stops the intake when there are no other commands // using the subsystem
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeStopCommand.java // public class IntakeStopCommand extends Command { // // public IntakeStopCommand() { // requires(Robot.intake); // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // if(Robot.oi.manipulator.getRawAxis(3) >= 0.1) { // Robot.intake.set(Robot.oi.manipulator.getRawAxis(3) / 2); // }else if(Robot.oi.manipulator.getRawAxis(2) >= 0.1) { // Robot.intake.set(Robot.oi.manipulator.getRawAxis(2) / -2); // }else{ // Robot.intake.set(0); // } // } // // @Override // protected boolean isFinished() { // return false; // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Intake.java import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.intake.IntakeStopCommand; package org.usfirst.frc.team2557.robot.subsystems; public class Intake extends Subsystem { CANTalon intakeMotor = RobotMap.intakeMotor; @Override protected void initDefaultCommand() { // Stops the intake when there are no other commands // using the subsystem
setDefaultCommand(new IntakeStopCommand());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeInCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeInCommand extends Command { public IntakeInCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeInCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeInCommand extends Command { public IntakeInCommand() {
requires(Robot.intake);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/CorrectAngleOffsetCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.PIDController; import edu.wpi.first.wpilibj.PIDOutput; import edu.wpi.first.wpilibj.PIDSource; import edu.wpi.first.wpilibj.PIDSourceType; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.chassis; public class CorrectAngleOffsetCommand extends Command { private PIDController _controller; private double _degrees; public CorrectAngleOffsetCommand() { this._degrees = 0; // Kp, Ki, Kd, input (gyro), output (chassis) this._controller = new PIDController(0.01, 0.05, 0, new PIDSource() { @Override public void setPIDSourceType(PIDSourceType pidSource) { } @Override public PIDSourceType getPIDSourceType() { return PIDSourceType.kDisplacement; } @Override public double pidGet() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/CorrectAngleOffsetCommand.java import edu.wpi.first.wpilibj.PIDController; import edu.wpi.first.wpilibj.PIDOutput; import edu.wpi.first.wpilibj.PIDSource; import edu.wpi.first.wpilibj.PIDSourceType; import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.chassis; public class CorrectAngleOffsetCommand extends Command { private PIDController _controller; private double _degrees; public CorrectAngleOffsetCommand() { this._degrees = 0; // Kp, Ki, Kd, input (gyro), output (chassis) this._controller = new PIDController(0.01, 0.05, 0, new PIDSource() { @Override public void setPIDSourceType(PIDSourceType pidSource) { } @Override public PIDSourceType getPIDSourceType() { return PIDSourceType.kDisplacement; } @Override public double pidGet() {
return Robot.chassis.getGyroAngle();
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Chassis.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/DriveCommand.java // public class DriveCommand extends Command { // // public DriveCommand() { // requires(Robot.chassis); // } // // // Called just before this Command runs the first time // protected void initialize() { // } // // // Called repeatedly when this Command is scheduled to run // protected void execute() { // double speedEdit = 1 - (Robot.oi.driver.getRawAxis(3) + 1) / 2; // // // Calculate arcade drive so we can use our custom "set" method // double power = -Robot.oi.driver.getRawAxis(1); // double turn = -Robot.oi.driver.getRawAxis(0); // Robot.chassis.set((power - turn) * speedEdit, // (power + turn) * speedEdit); // // } // // // Make this return true when this Command no longer needs to run execute() // protected boolean isFinished() { // return false; // } // // // Called once after isFinished returns true // protected void end() { // // } // // // Called when another command which requires one or more of the same // // subsystems is scheduled to run // protected void interrupted() { // this.end(); // } // }
import edu.wpi.first.wpilibj.*; import edu.wpi.first.wpilibj.interfaces.Gyro; import org.usfirst.frc.team2557.robot.RobotMap; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.commands.chassis.DriveCommand;
package org.usfirst.frc.team2557.robot.subsystems; public class Chassis extends Subsystem { // CANTalon leftEncTalon = RobotMap.driveLeft2; // CANTalon rightEncTalon = RobotMap.driveRight1; // TODO: See whether the comp bot's encoders are switched as well CANTalon leftEncTalon = RobotMap.driveRight1; // Right and left are switched on the practice bot CANTalon rightEncTalon = RobotMap.driveLeft2; RobotDrive drive = RobotMap.robotDrive; Gyro gyro = RobotMap.mainGyro; double leftPosResetValue = 0; double rightPosResetValue = 0; private final double posToMeters = (14 / 28) * 8 * 3.14159; public Chassis() { } public void initDefaultCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/DriveCommand.java // public class DriveCommand extends Command { // // public DriveCommand() { // requires(Robot.chassis); // } // // // Called just before this Command runs the first time // protected void initialize() { // } // // // Called repeatedly when this Command is scheduled to run // protected void execute() { // double speedEdit = 1 - (Robot.oi.driver.getRawAxis(3) + 1) / 2; // // // Calculate arcade drive so we can use our custom "set" method // double power = -Robot.oi.driver.getRawAxis(1); // double turn = -Robot.oi.driver.getRawAxis(0); // Robot.chassis.set((power - turn) * speedEdit, // (power + turn) * speedEdit); // // } // // // Make this return true when this Command no longer needs to run execute() // protected boolean isFinished() { // return false; // } // // // Called once after isFinished returns true // protected void end() { // // } // // // Called when another command which requires one or more of the same // // subsystems is scheduled to run // protected void interrupted() { // this.end(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Chassis.java import edu.wpi.first.wpilibj.*; import edu.wpi.first.wpilibj.interfaces.Gyro; import org.usfirst.frc.team2557.robot.RobotMap; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.commands.chassis.DriveCommand; package org.usfirst.frc.team2557.robot.subsystems; public class Chassis extends Subsystem { // CANTalon leftEncTalon = RobotMap.driveLeft2; // CANTalon rightEncTalon = RobotMap.driveRight1; // TODO: See whether the comp bot's encoders are switched as well CANTalon leftEncTalon = RobotMap.driveRight1; // Right and left are switched on the practice bot CANTalon rightEncTalon = RobotMap.driveLeft2; RobotDrive drive = RobotMap.robotDrive; Gyro gyro = RobotMap.mainGyro; double leftPosResetValue = 0; double rightPosResetValue = 0; private final double posToMeters = (14 / 28) * 8 * 3.14159; public Chassis() { } public void initDefaultCommand() {
setDefaultCommand(new DriveCommand());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/macro/MacroPlayCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; import java.io.FileNotFoundException;
package org.usfirst.frc.team2557.robot.commands.autonomous.macro; public class MacroPlayCommand extends Command { private MacroPlayer _player; public MacroPlayCommand(String filepath) {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/macro/MacroPlayCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; import java.io.FileNotFoundException; package org.usfirst.frc.team2557.robot.commands.autonomous.macro; public class MacroPlayCommand extends Command { private MacroPlayer _player; public MacroPlayCommand(String filepath) {
requires(Robot.arm);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Catapult.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java // public class CatapultSequence extends CommandGroup { // // public CatapultSequence() { // this.addSequential(new CatapultRetractCommand()); // this.addSequential(new WaitForButtonCommand(Robot.oi.manipulatorStart)); // this.addSequential(new CatapultShootCommand()); // } // // }
import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.catapult.CatapultSequence;
package org.usfirst.frc.team2557.robot.subsystems; public class Catapult extends Subsystem { CANTalon motor = RobotMap.catapultMotor; DigitalInput hallEffect = RobotMap.catapultHallEffect; @Override protected void initDefaultCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java // public class CatapultSequence extends CommandGroup { // // public CatapultSequence() { // this.addSequential(new CatapultRetractCommand()); // this.addSequential(new WaitForButtonCommand(Robot.oi.manipulatorStart)); // this.addSequential(new CatapultShootCommand()); // } // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/Catapult.java import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.catapult.CatapultSequence; package org.usfirst.frc.team2557.robot.subsystems; public class Catapult extends Subsystem { CANTalon motor = RobotMap.catapultMotor; DigitalInput hallEffect = RobotMap.catapultHallEffect; @Override protected void initDefaultCommand() {
setDefaultCommand(new CatapultSequence());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(56.5));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(56.5));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Center extends CommandGroup { public Auto_Pos2Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(56.5));
this.addSequential(new EncoderPosDriveCommand(6513, 0.7));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/resolvers/PosBatterResolverCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.autonomous.sequences.*;
package org.usfirst.frc.team2557.robot.commands.autonomous.resolvers; public class PosBatterResolverCommand extends Command { private Command _chosenCommand = null; @Override protected void initialize() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/resolvers/PosBatterResolverCommand.java import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.autonomous.sequences.*; package org.usfirst.frc.team2557.robot.commands.autonomous.resolvers; public class PosBatterResolverCommand extends Command { private Command _chosenCommand = null; @Override protected void initialize() {
switch((int) Robot.instance.posChooser.getSelected()) {
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(7));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(7));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Right extends CommandGroup { public Auto_Pos4Right() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(7));
this.addSequential(new EncoderPosDriveCommand(9295, 0.7));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/SecondArm.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/secondArm/SecondArmLatchCommand.java // public class SecondArmLatchCommand extends Command { // // public SecondArmLatchCommand() { // requires(Robot.secondArm); // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // Robot.secondArm.latch(); // } // // @Override // protected boolean isFinished() { // return false; // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // }
import edu.wpi.first.wpilibj.Servo; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.secondArm.SecondArmLatchCommand;
package org.usfirst.frc.team2557.robot.subsystems; public class SecondArm extends Subsystem { Servo secondArmServo = RobotMap.secondaryArm; @Override protected void initDefaultCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/secondArm/SecondArmLatchCommand.java // public class SecondArmLatchCommand extends Command { // // public SecondArmLatchCommand() { // requires(Robot.secondArm); // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // Robot.secondArm.latch(); // } // // @Override // protected boolean isFinished() { // return false; // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/subsystems/SecondArm.java import edu.wpi.first.wpilibj.Servo; import edu.wpi.first.wpilibj.command.Subsystem; import org.usfirst.frc.team2557.robot.RobotMap; import org.usfirst.frc.team2557.robot.commands.secondArm.SecondArmLatchCommand; package org.usfirst.frc.team2557.robot.subsystems; public class SecondArm extends Subsystem { Servo secondArmServo = RobotMap.secondaryArm; @Override protected void initDefaultCommand() {
setDefaultCommand(new SecondArmLatchCommand());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(34.2));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(34.2));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos3Right.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos3Right extends CommandGroup { public Auto_Pos3Right() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(34.2));
this.addSequential(new EncoderPosDriveCommand(12613, 0.9));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(-22.2));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(-22.2));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos2Left.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos2Left extends CommandGroup { public Auto_Pos2Left() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(-22.2));
this.addSequential(new EncoderPosDriveCommand(10764, 0.5));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeDetectBallCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // }
import org.usfirst.frc.team2557.robot.RobotMap; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeDetectBallCommand extends Command{ @Override protected void initialize() { // TODO Auto-generated method stub } @Override protected void execute() { // TODO Auto-generated method stub
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/RobotMap.java // public class RobotMap { // // // public static CANTalon driveLeft1; // public static CANTalon driveLeft2; // public static CANTalon driveRight1; // public static CANTalon driveRight2; // public static CANTalon catapultMotor; // public static CANTalon climbingMotor; // public static CANTalon leftActuatorMotor; // public static CANTalon rightActuatorMotor; // // public static CANTalon intakeMotor; // // public static Servo secondaryArm; // // public static DigitalInput catapultHallEffect; // // public static Accelerometer rioAccelerometer; // // public static Gyro mainGyro; // // public static AnalogInput leftPotentiometer; // public static AnalogInput rightPotentiometer; // // public static LidarRangeFinder lidarSensor; // public static AnalogInput sonar; // // public static ArduinoComm arduinoComm; // // public static RobotDrive robotDrive; // // /** // * Initializes all the parts of RobotMap. This must be called main init method // * in Robot.java, as WPI needs to set up before these objects can be constructed. // */ // public static void init() { // // /* // * CAN ports 6, 8, 2, and 3 have encoder breakouts. // */ // driveLeft1 = new CANTalon(7); // driveLeft2 = new CANTalon(6); // driveRight1 = new CANTalon(8); // driveRight2 = new CANTalon(5); // catapultMotor = new CANTalon(1); // climbingMotor = new CANTalon(9); // intakeMotor = new CANTalon(4); // // leftActuatorMotor = new CANTalon(2); // leftActuatorMotor.enableLimitSwitch(false, false); // leftActuatorMotor.enableBrakeMode(true); // rightActuatorMotor = new CANTalon(3); // rightActuatorMotor.enableLimitSwitch(false, false); // rightActuatorMotor.enableBrakeMode(true); // // secondaryArm = new Servo(4); // // catapultHallEffect = new DigitalInput(0); // // rioAccelerometer = new BuiltInAccelerometer(); // // mainGyro = new ADXRS450_Gyro(); // // leftPotentiometer = new AnalogInput(1); // rightPotentiometer = new AnalogInput(2); // // lidarSensor = new LidarRangeFinder(SerialPort.Port.kMXP); // Using the MXP breakout for tx/rx (serial) // // robotDrive = new RobotDrive(driveLeft1, driveLeft2, driveRight1, driveRight2); // robotDrive.setExpiration(0.2); // robotDrive.setSafetyEnabled(false); // // arduinoComm = new ArduinoComm(); // Using the MXP breakout for sda/sdt (i2c) // } // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeDetectBallCommand.java import org.usfirst.frc.team2557.robot.RobotMap; import edu.wpi.first.wpilibj.command.Command; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeDetectBallCommand extends Command{ @Override protected void initialize() { // TODO Auto-generated method stub } @Override protected void execute() { // TODO Auto-generated method stub
SmartDashboard.putNumber("Ball Detection", RobotMap.intakeMotor.getOutputVoltage());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/secondArm/SecondArmLatchCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.secondArm; public class SecondArmLatchCommand extends Command { public SecondArmLatchCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/secondArm/SecondArmLatchCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.secondArm; public class SecondArmLatchCommand extends Command { public SecondArmLatchCommand() {
requires(Robot.secondArm);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(77));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(77));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos1Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos1Center extends CommandGroup { public Auto_Pos1Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(77));
this.addSequential(new EncoderPosDriveCommand(11406, 0.9));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/macro/MacroRecordCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; import java.io.IOException;
package org.usfirst.frc.team2557.robot.commands.autonomous.macro; public class MacroRecordCommand extends Command { private MacroRecorder _recorder; public MacroRecordCommand(String filepath) {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/macro/MacroRecordCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; import java.io.IOException; package org.usfirst.frc.team2557.robot.commands.autonomous.macro; public class MacroRecordCommand extends Command { private MacroRecorder _recorder; public MacroRecordCommand(String filepath) {
requires(Robot.arm);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/arm/TeleopArmCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.arm; public class TeleopArmCommand extends Command { public TeleopArmCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/arm/TeleopArmCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.arm; public class TeleopArmCommand extends Command { public TeleopArmCommand() {
requires(Robot.arm);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/lidar/LidarUpdateCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.lidar; public class LidarUpdateCommand extends Command { public LidarUpdateCommand() { // This command can run without other commands // conflicting (requires is not needed). // This command cannot be interrupted!
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/lidar/LidarUpdateCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.lidar; public class LidarUpdateCommand extends Command { public LidarUpdateCommand() { // This command can run without other commands // conflicting (requires is not needed). // This command cannot be interrupted!
requires(Robot.lidar);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeOutCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeOutCommand extends Command { public IntakeOutCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeOutCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeOutCommand extends Command { public IntakeOutCommand() {
requires(Robot.intake);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() {
this.addParallel(new Auto_LoadBall());
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() { this.addParallel(new Auto_LoadBall());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() { this.addParallel(new Auto_LoadBall());
this.addSequential(new TurnByAngleCommand(-57));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand;
package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(-57));
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/automation/Auto_LoadBall.java // public class Auto_LoadBall extends CommandGroup { // // public Auto_LoadBall() { // // Move the arm to the correct position // this.addSequential(new MoveArmToAngleCommand(Arm.ARM_LOADBALL)); // // Spin the intake for 2 seconds // this.addSequential(new IntakeInCommand(), 1.0); // } // // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java // public class EncoderPosDriveCommand extends Command { // // private double _speed; // private double _encpos; // // public EncoderPosDriveCommand(double encpos, double speed) { // requires(Robot.chassis); // // this._speed = speed; // this._encpos = encpos; // } // // @Override // protected void initialize() { // Robot.chassis.resetDriveStraight(); // } // // @Override // protected void execute() { // Robot.chassis.driveStraight(this._speed); // } // // @Override // protected boolean isFinished() { // return Math.abs(Robot.chassis.getLeftEncoderPos()) > this._encpos; // } // // @Override // protected void end() { // Robot.chassis.stop(); // } // // @Override // protected void interrupted() { // this.end(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/TurnByAngleCommand.java // public class TurnByAngleCommand extends Command { // // private PIDController _controller; // private double _degrees; // // public TurnByAngleCommand(double degrees) { // this._degrees = degrees; // // // Kp, Ki, Kd, input (gyro), output (chassis) // this._controller = new PIDController(0.01, 0.05, 0, // new PIDSource() { // @Override // public void setPIDSourceType(PIDSourceType pidSource) { // } // // @Override // public PIDSourceType getPIDSourceType() { // return PIDSourceType.kDisplacement; // } // // @Override // public double pidGet() { // return Robot.chassis.getGyroAngle(); // } // }, new PIDOutput() { // @Override // public void pidWrite(double output) { // Robot.chassis.set(output * 0.65, -output * 0.65); // } // }); // requires(Robot.chassis); // // this._controller.setContinuous(true); // this._controller.setOutputRange(-1, 1); // this._controller.setAbsoluteTolerance(1); // 1 degree tolerance // } // // @Override // protected void initialize() { // // Reset the gyro // Robot.chassis.resetGyro(); // // Reset the PID // this._controller.reset(); // // Set the setpoint for the PID // this._controller.setSetpoint(this._degrees); // } // // @Override // protected void execute() { // this._controller.enable(); // } // // @Override // protected boolean isFinished() { // return this._controller.onTarget(); // } // // protected void end() { // this._controller.disable(); // } // // @Override // protected void interrupted() { // this.end(); // } // // // // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/autonomous/sequences/Auto_Pos4Center.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.commands.automation.Auto_LoadBall; import org.usfirst.frc.team2557.robot.commands.chassis.EncoderPosDriveCommand; import org.usfirst.frc.team2557.robot.commands.chassis.TurnByAngleCommand; package org.usfirst.frc.team2557.robot.commands.autonomous.sequences; public class Auto_Pos4Center extends CommandGroup { public Auto_Pos4Center() { this.addParallel(new Auto_LoadBall()); this.addSequential(new TurnByAngleCommand(-57));
this.addSequential(new EncoderPosDriveCommand(9403, 0.8));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/util/WaitForButtonCommand.java // public class WaitForButtonCommand extends Command { // // JoystickButton button; // // public WaitForButtonCommand(JoystickButton button) { // this.button = button; // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // // } // // @Override // protected boolean isFinished() { // return button.get(); // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.util.WaitForButtonCommand;
package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultSequence extends CommandGroup { public CatapultSequence() { this.addSequential(new CatapultRetractCommand());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/util/WaitForButtonCommand.java // public class WaitForButtonCommand extends Command { // // JoystickButton button; // // public WaitForButtonCommand(JoystickButton button) { // this.button = button; // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // // } // // @Override // protected boolean isFinished() { // return button.get(); // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.util.WaitForButtonCommand; package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultSequence extends CommandGroup { public CatapultSequence() { this.addSequential(new CatapultRetractCommand());
this.addSequential(new WaitForButtonCommand(Robot.oi.manipulatorStart));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/util/WaitForButtonCommand.java // public class WaitForButtonCommand extends Command { // // JoystickButton button; // // public WaitForButtonCommand(JoystickButton button) { // this.button = button; // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // // } // // @Override // protected boolean isFinished() { // return button.get(); // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // }
import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.util.WaitForButtonCommand;
package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultSequence extends CommandGroup { public CatapultSequence() { this.addSequential(new CatapultRetractCommand());
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/util/WaitForButtonCommand.java // public class WaitForButtonCommand extends Command { // // JoystickButton button; // // public WaitForButtonCommand(JoystickButton button) { // this.button = button; // } // // @Override // protected void initialize() { // // } // // @Override // protected void execute() { // // } // // @Override // protected boolean isFinished() { // return button.get(); // } // // @Override // protected void end() { // // } // // @Override // protected void interrupted() { // this.end(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/catapult/CatapultSequence.java import edu.wpi.first.wpilibj.command.CommandGroup; import org.usfirst.frc.team2557.robot.Robot; import org.usfirst.frc.team2557.robot.commands.util.WaitForButtonCommand; package org.usfirst.frc.team2557.robot.commands.catapult; public class CatapultSequence extends CommandGroup { public CatapultSequence() { this.addSequential(new CatapultRetractCommand());
this.addSequential(new WaitForButtonCommand(Robot.oi.manipulatorStart));
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeStopCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeStopCommand extends Command { public IntakeStopCommand() {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/intake/IntakeStopCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.intake; public class IntakeStopCommand extends Command { public IntakeStopCommand() {
requires(Robot.intake);
FIRST-Team-2557-The-SOTABots/FRC_Robot
Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // }
import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot;
package org.usfirst.frc.team2557.robot.commands.chassis; public class EncoderPosDriveCommand extends Command { private double _speed; private double _encpos; public EncoderPosDriveCommand(double encpos, double speed) {
// Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/Robot.java // public class Robot extends IterativeRobot { // // //Subsystem Declarations// // public static OI oi; // public static Chassis chassis; // public static Arm arm; // public static Intake intake; // public static Catapult catapult; // public static Winch winch; // public static SecondArm secondArm; // public static Camera camera; // public static Lidar lidar; // public static Dashboard dashboard; // // //Command Declarations// // Command autonomousCommand; // // SendableChooser autoChooser; // public SendableChooser posChooser; // public SendableChooser batterChooser; // // public static Robot instance; // // public Robot() { // super(); // // instance = this; // } // // /** // * This function is run when the robot is first started up and should be // * used for any initialization code. // */ // public void robotInit() { // // Initialize RobotMap // RobotMap.init(); // // //Subsystem Connections// // chassis = new Chassis(); // arm = new Arm(); // intake = new Intake(); // catapult = new Catapult(); // winch = new Winch(); // secondArm = new SecondArm(); // camera = new Camera(); // lidar = new Lidar(); // dashboard = new Dashboard(); // // //OI Connection// // // NOTE: oi MUST be constructed after subsystems // oi = new OI(); // // // Make a SendableChooser on the SmartDashboard for changing auto programs // autoChooser = new SendableChooser(); // autoChooser.addDefault("Do Nothing (AUTO)", new Auto_DoNothing()); // autoChooser.addObject("Lowbar (AUTO)", new Auto_Lowbar()); // autoChooser.addObject("Lowbar Left Batter (AUTO)", new Auto_LowbarLeft()); // autoChooser.addObject("Lowbar Center Batter (AUTO)", new Auto_LowbarCenter()); // autoChooser.addObject("Chival De Frise (AUTO)", new Auto_ChivalDeFrise()); // autoChooser.addObject("Portcullis (AUTO)", new Auto_Portcullis()); // autoChooser.addObject("Rough Terrain (AUTO)", new Auto_RoughTerrain()); // autoChooser.addObject("Ramparts (AUTO)", new Auto_Rampards()); // autoChooser.addObject("Rock Wall (AUTO)", new Auto_RockWall()); // autoChooser.addObject("Moat (AUTO)", new Auto_Moat()); // // posChooser = new SendableChooser(); // posChooser.addDefault("No Shoot", 0); // posChooser.addObject("Position 1", 1); // posChooser.addObject("Position 2", 2); // posChooser.addObject("Position 3", 3); // posChooser.addObject("Position 4", 4); // // batterChooser = new SendableChooser(); // batterChooser.addDefault("Left", -1); // batterChooser.addObject("Center", 0); // batterChooser.addObject("Right", 1); // // SmartDashboard.putData("Autonomous Chooser", autoChooser); // SmartDashboard.putData("Position Chooser", posChooser); // SmartDashboard.putData("Batter Chooser", batterChooser); // } // // public void disabledPeriodic() { // Scheduler.getInstance().run(); // } // // public void autonomousInit() { // autonomousCommand = (Command) autoChooser.getSelected(); // autonomousCommand.start(); // } // // /** // * This function is called periodically during autonomous // */ // public void autonomousPeriodic() { // // Update the arm subsystem (updates PIDs and such) // arm.update(); // // Scheduler.getInstance().run(); // } // // public void teleopInit() { // // Cancel the autonomous command (if there was one previously running // if(autonomousCommand != null) // autonomousCommand.cancel(); // } // // /** // * This function is called when the disabled button is hit. // * You can use it to reset subsystems before shutting down. // */ // public void disabledInit() { // // } // // /* // // * This function is called periodically during operator control // */ // public void teleopPeriodic() { // // Update the arm // Robot.arm.update(); // // Scheduler.getInstance().run(); // } // // public void testInit() { // // } // // /** // * This function is called periodically during test mode // */ // public void testPeriodic() { // SmartDashboard.putNumber("The lidar is reading; ", RobotMap.lidarSensor.getData(10).getDistance()); // // LiveWindow.run(); // } // } // Path: Robot/src/main/java/org/usfirst/frc/team2557/robot/commands/chassis/EncoderPosDriveCommand.java import edu.wpi.first.wpilibj.command.Command; import org.usfirst.frc.team2557.robot.Robot; package org.usfirst.frc.team2557.robot.commands.chassis; public class EncoderPosDriveCommand extends Command { private double _speed; private double _encpos; public EncoderPosDriveCommand(double encpos, double speed) {
requires(Robot.chassis);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/TimestampProvider.java // public class TimestampProvider // { // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // }
import auditonlybank.util.TimestampProvider; import java.sql.Timestamp;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package auditonlybank.domain; public class Customer extends CustomerAbstract { public Customer(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public Customer() {
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/TimestampProvider.java // public class TimestampProvider // { // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // } // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java import auditonlybank.util.TimestampProvider; import java.sql.Timestamp; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package auditonlybank.domain; public class Customer extends CustomerAbstract { public Customer(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public Customer() {
this(TimestampProvider.getInfinityDate());
goldmansachs/reladomo-kata
mini-kata/src/main/java/kata/util/ObjectSequenceObjectFactory.java
// Path: main-kata/src/main/java/kata/domain/ObjectSequence.java // public class ObjectSequence // extends ObjectSequenceAbstract // implements MithraSequence // { // public ObjectSequence() // { // super(); // } // // public void setSequenceName(String sequenceName) // { // this.setSimulatedSequenceName(sequenceName); // } // // public long getNextId() // { // return this.getNextValue(); // } // // public void setNextId(long nextValue) // { // this.setNextValue(nextValue); // } // }
import com.gs.fw.common.mithra.MithraSequence; import com.gs.fw.common.mithra.MithraSequenceObjectFactory; import kata.domain.ObjectSequence; import kata.domain.ObjectSequenceFinder;
/* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.util; public class ObjectSequenceObjectFactory implements MithraSequenceObjectFactory { public MithraSequence getMithraSequenceObject(String sequenceName, Object sourceAttribute, int initialValue) {
// Path: main-kata/src/main/java/kata/domain/ObjectSequence.java // public class ObjectSequence // extends ObjectSequenceAbstract // implements MithraSequence // { // public ObjectSequence() // { // super(); // } // // public void setSequenceName(String sequenceName) // { // this.setSimulatedSequenceName(sequenceName); // } // // public long getNextId() // { // return this.getNextValue(); // } // // public void setNextId(long nextValue) // { // this.setNextValue(nextValue); // } // } // Path: mini-kata/src/main/java/kata/util/ObjectSequenceObjectFactory.java import com.gs.fw.common.mithra.MithraSequence; import com.gs.fw.common.mithra.MithraSequenceObjectFactory; import kata.domain.ObjectSequence; import kata.domain.ObjectSequenceFinder; /* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.util; public class ObjectSequenceObjectFactory implements MithraSequenceObjectFactory { public MithraSequence getMithraSequenceObject(String sequenceName, Object sourceAttribute, int initialValue) {
ObjectSequence objectSequence = ObjectSequenceFinder.findByPrimaryKey(sequenceName);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/CustomerResource.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // }
import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerFinder; import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.sql.Timestamp;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.web; @Path("/api/customer") public class CustomerResource { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYYY-MM-DD"); private final SerializationConfig serializationConfig; public CustomerResource() { this.serializationConfig = SerializationConfig .shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("businessDate") String businessDate ) { Timestamp businessDateTS = parse(businessDate);
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/CustomerResource.java import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerFinder; import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.sql.Timestamp; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.web; @Path("/api/customer") public class CustomerResource { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYYY-MM-DD"); private final SerializationConfig serializationConfig; public CustomerResource() { this.serializationConfig = SerializationConfig .shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName, @FormParam("businessDate") String businessDate ) { Timestamp businessDateTS = parse(businessDate);
Customer customer = new Customer(businessDateTS);
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAdvancedFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { // Look into these files to see the test data being used return new String[]{"testdata/data_Person.txt", "testdata/data_CustomersAndAccounts.txt"}; } //-------------- Question 1 ------------------------------------------------------ // Given a Customer, find their list of accounts // *without* using customer.getAccounts().
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAdvancedFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { // Look into these files to see the test data being used return new String[]{"testdata/data_Person.txt", "testdata/data_CustomersAndAccounts.txt"}; } //-------------- Question 1 ------------------------------------------------------ // Given a Customer, find their list of accounts // *without* using customer.getAccounts().
public CustomerAccountList getAccountsByCustomer(Customer customer)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAdvancedFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { // Look into these files to see the test data being used return new String[]{"testdata/data_Person.txt", "testdata/data_CustomersAndAccounts.txt"}; } //-------------- Question 1 ------------------------------------------------------ // Given a Customer, find their list of accounts // *without* using customer.getAccounts().
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAdvancedFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { // Look into these files to see the test data being used return new String[]{"testdata/data_Person.txt", "testdata/data_CustomersAndAccounts.txt"}; } //-------------- Question 1 ------------------------------------------------------ // Given a Customer, find their list of accounts // *without* using customer.getAccounts().
public CustomerAccountList getAccountsByCustomer(Customer customer)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
//-------------- Question 4 ------------------------------------------------------ // Find the sum of ages for all Person objects. This is a two stage question: // 1) Find the sum without using any special Mithra features. // 2) Find the sum using Mithra's AggregateList feature. // Note: When done with both questions, look at the SQL debug console output, // and note the difference in how much data Mithra had to move from the // the DB to your application to get the answer! public int getSumAgeNormalMithra() { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ4a() { Assert.assertEquals(556, this.getSumAgeNormalMithra()); } public double getSumAgeUsingAggregateList() { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ4b() { Assert.assertEquals(556, this.getSumAgeUsingAggregateList(), 0.0);
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; //-------------- Question 4 ------------------------------------------------------ // Find the sum of ages for all Person objects. This is a two stage question: // 1) Find the sum without using any special Mithra features. // 2) Find the sum using Mithra's AggregateList feature. // Note: When done with both questions, look at the SQL debug console output, // and note the difference in how much data Mithra had to move from the // the DB to your application to get the answer! public int getSumAgeNormalMithra() { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ4a() { Assert.assertEquals(556, this.getSumAgeNormalMithra()); } public double getSumAgeUsingAggregateList() { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ4b() { Assert.assertEquals(556, this.getSumAgeUsingAggregateList(), 0.0);
final Person person = new Person();
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
Tuples.pair("JPN", 4), Tuples.pair("MA", 1) ); Verify.assertMapsEqual(expectedResult, peopleByCountry); } //-------------- Question 8 ------------------------------------------------------ // Fetch People, ordered by their personId. // For each person, count the number of letters in their name. // Stop counting when you reach stopAtPersonNamed (but include them in the count), // and return the total. // *Do not* fetch all rows, but *do* fetch them efficiently. public int countLettersOfNamesUpTo(final String stopAtPersonNamed) { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ8() { Assert.assertEquals(63, this.countLettersOfNamesUpTo("Clark Kent")); Assert.assertEquals(152, this.countLettersOfNamesUpTo("Donkey Kong")); Assert.assertEquals(174, this.countLettersOfNamesUpTo("Does Not Exist")); } //-------------- Question 9 ------------------------------------------------------ // Add a method to PersonList to increment each Person's age by 1.
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; Tuples.pair("JPN", 4), Tuples.pair("MA", 1) ); Verify.assertMapsEqual(expectedResult, peopleByCountry); } //-------------- Question 8 ------------------------------------------------------ // Fetch People, ordered by their personId. // For each person, count the number of letters in their name. // Stop counting when you reach stopAtPersonNamed (but include them in the count), // and return the total. // *Do not* fetch all rows, but *do* fetch them efficiently. public int countLettersOfNamesUpTo(final String stopAtPersonNamed) { Assert.fail("Implement this functionality to make the test pass"); return 0; } @Test public void testQ8() { Assert.assertEquals(63, this.countLettersOfNamesUpTo("Clark Kent")); Assert.assertEquals(152, this.countLettersOfNamesUpTo("Donkey Kong")); Assert.assertEquals(174, this.countLettersOfNamesUpTo("Does Not Exist")); } //-------------- Question 9 ------------------------------------------------------ // Add a method to PersonList to increment each Person's age by 1.
public void incrementAges(PersonList people)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
// Given an array of Mithra attributes, and a Mithra object, // return a list representing the values indicated by the attributes for the object. // Do not use Reflection. public MutableList<Object> getAttributeValuesForObjects( final MithraObject mithraObject, Attribute... attributes) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ13() { Person ada = PersonFinder.findOne(PersonFinder.personId().eq(8)); MutableList<Object> adaAttrs = this.getAttributeValuesForObjects(ada, PersonFinder.age(), PersonFinder.personId(), PersonFinder.name()); Verify.assertListsEqual(FastList.newListWith(24, 8, "Ada Lovelace"), adaAttrs); Person douglas = PersonFinder.findOne(PersonFinder.personId().eq(9)); MutableList<Object> douglasAttrs = this.getAttributeValuesForObjects(douglas, PersonFinder.age(), PersonFinder.name()); Verify.assertListsEqual(FastList.newListWith(42, "Douglas Adams"), douglasAttrs); // Now use the exact same method for a different Mithra Object and set of attributes.
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; // Given an array of Mithra attributes, and a Mithra object, // return a list representing the values indicated by the attributes for the object. // Do not use Reflection. public MutableList<Object> getAttributeValuesForObjects( final MithraObject mithraObject, Attribute... attributes) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ13() { Person ada = PersonFinder.findOne(PersonFinder.personId().eq(8)); MutableList<Object> adaAttrs = this.getAttributeValuesForObjects(ada, PersonFinder.age(), PersonFinder.personId(), PersonFinder.name()); Verify.assertListsEqual(FastList.newListWith(24, 8, "Ada Lovelace"), adaAttrs); Person douglas = PersonFinder.findOne(PersonFinder.personId().eq(9)); MutableList<Object> douglasAttrs = this.getAttributeValuesForObjects(douglas, PersonFinder.age(), PersonFinder.name()); Verify.assertListsEqual(FastList.newListWith(42, "Douglas Adams"), douglasAttrs); // Now use the exact same method for a different Mithra Object and set of attributes.
CustomerAccount virtual = CustomerAccountFinder.findOne(CustomerAccountFinder.accountId().eq(600));
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
@Test public void testQ17() { MutableMap<Integer, Attribute> actualMap = this.getMyIdToAttributeMap(); MutableMap<Integer, Attribute> expectedMap = UnifiedMap.newMapWith( Tuples.<Integer, Attribute>pair(Integer.valueOf(124), AllTypesFinder.intValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(237), AllTypesFinder.stringValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(874), AllTypesFinder.booleanValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(765), AllTypesFinder.doubleValue())); Verify.assertMapsEqual(expectedMap, actualMap); } //-------------- Question 18 ------------------------------------------------------ // Imagine that you have some external system that sends you changes to a Mithra object // as a map of myId values to newValue. // Implement the method that takes the map of changes, // and applies them to the given Mithra object. // Hint: You can use the answer to the previous question to make this easy to implement. public void applyChanges(final MithraObject mithraObject, MutableMap<Integer, Object> changes) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ18() {
// Path: main-kata/src/main/java/kata/domain/AllTypes.java // public class AllTypes extends AllTypesAbstract // { // public AllTypes() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccount.java // public class CustomerAccount // extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAdvancedFinder.java import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.api.tuple.Twin; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraObject; import com.gs.fw.common.mithra.attribute.Attribute; import com.gs.fw.common.mithra.finder.AbstractRelatedFinder; import com.gs.fw.common.mithra.finder.RelatedFinder; import kata.domain.AccountBalanceFinder; import kata.domain.AllTypes; import kata.domain.AllTypesFinder; import kata.domain.Customer; import kata.domain.CustomerAccount; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; @Test public void testQ17() { MutableMap<Integer, Attribute> actualMap = this.getMyIdToAttributeMap(); MutableMap<Integer, Attribute> expectedMap = UnifiedMap.newMapWith( Tuples.<Integer, Attribute>pair(Integer.valueOf(124), AllTypesFinder.intValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(237), AllTypesFinder.stringValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(874), AllTypesFinder.booleanValue()), Tuples.<Integer, Attribute>pair(Integer.valueOf(765), AllTypesFinder.doubleValue())); Verify.assertMapsEqual(expectedMap, actualMap); } //-------------- Question 18 ------------------------------------------------------ // Imagine that you have some external system that sends you changes to a Mithra object // as a map of myId values to newValue. // Implement the method that takes the map of changes, // and applies them to the given Mithra object. // Hint: You can use the answer to the previous question to make this easy to implement. public void applyChanges(final MithraObject mithraObject, MutableMap<Integer, Object> changes) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ18() {
AllTypes allTypes = new AllTypes();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/CustomerResource.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerList.java // public class CustomerList extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import com.gs.fw.common.mithra.util.serializer.SerializedList; import simplebank.domain.Customer; import simplebank.domain.CustomerFinder; import simplebank.domain.CustomerList; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.web; @Path("/api/customer") public class CustomerResource { private final SerializationConfig serializationConfig; public CustomerResource() { this.serializationConfig = SerializationConfig .shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName) {
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerList.java // public class CustomerList extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/CustomerResource.java import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import com.gs.fw.common.mithra.util.serializer.SerializedList; import simplebank.domain.Customer; import simplebank.domain.CustomerFinder; import simplebank.domain.CustomerList; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.web; @Path("/api/customer") public class CustomerResource { private final SerializationConfig serializationConfig; public CustomerResource() { this.serializationConfig = SerializationConfig .shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName) {
Customer customer = new Customer();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/CustomerResource.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerList.java // public class CustomerList extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import com.gs.fw.common.mithra.util.serializer.SerializedList; import simplebank.domain.Customer; import simplebank.domain.CustomerFinder; import simplebank.domain.CustomerList; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;
.shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName) { Customer customer = new Customer(); customer.setCustomerId(customerId); customer.setFirstName(firstName); customer.setLastName(lastName); customer.insert(); return Response.ok().build(); } @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public Serialized<Customer> getCustomerById(@PathParam("id") int customerId) throws JsonProcessingException { Customer customer = CustomerFinder.findByPrimaryKey(customerId); return new Serialized<>(customer, serializationConfig); } @GET @Path("/findByLastName") @Produces(MediaType.APPLICATION_JSON)
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerList.java // public class CustomerList extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/CustomerResource.java import com.fasterxml.jackson.core.JsonProcessingException; import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.util.serializer.SerializationConfig; import com.gs.fw.common.mithra.util.serializer.Serialized; import com.gs.fw.common.mithra.util.serializer.SerializedList; import simplebank.domain.Customer; import simplebank.domain.CustomerFinder; import simplebank.domain.CustomerList; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; .shallowWithDefaultAttributes(CustomerFinder.getFinderInstance()); serializationConfig.withDeepDependents(); } @POST public Response createCustomer( @FormParam("customerId") int customerId, @FormParam("firstName") String firstName, @FormParam("lastName") String lastName) { Customer customer = new Customer(); customer.setCustomerId(customerId); customer.setFirstName(firstName); customer.setLastName(lastName); customer.insert(); return Response.ok().build(); } @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public Serialized<Customer> getCustomerById(@PathParam("id") int customerId) throws JsonProcessingException { Customer customer = CustomerFinder.findByPrimaryKey(customerId); return new Serialized<>(customer, serializationConfig); } @GET @Path("/findByLastName") @Produces(MediaType.APPLICATION_JSON)
public SerializedList<Customer, CustomerList> getCustomersByLastName(@QueryParam("lastName") String lastName)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAuditOnly.java
// Path: main-kata/src/main/java/kata/domain/Task.java // public class Task extends TaskAbstract // { // public Task(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // @Override // public String toString() // { // return "Task[name=" + this.getName() // + "; from=" + this.getProcessingDateFrom() // + "; to=" + this.getProcessingDateTo() // + "; status=" + this.getStatus() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/TaskList.java // public class TaskList // extends TaskListAbstract // { // public TaskList() // { // super(); // } // // public TaskList(int initialSize) // { // super(initialSize); // } // // public TaskList(Collection c) // { // super(c); // } // // public TaskList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import kata.domain.Task; import kata.domain.TaskFinder; import kata.domain.TaskList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; import java.util.Date;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAuditOnly extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Tasks.txt"}; // Look into this file to see the test data being used } // **** NOTES **** // (1) // Different applications can have different conventions to represent the business dates and processing dates. // In this exercise, we are using: // * IN_Z<@processingDate, OUT_Z> = @processingDate (see toIsInclusive() in processingDate attribute // * Infinity date = "9999-12-01 23:59:00.0", a.k.a. kata.util.TimestampProvider.getInfinityDate(). // Look at the definition of the processingDate attribute in Task.xml to see how this is defined/used. // // (2) // Are you completely unfamiliar with chaining? // See the Reladomo documentation //------------------------ Question 1 -------------------------------------------------------- // Get all Tasks
// Path: main-kata/src/main/java/kata/domain/Task.java // public class Task extends TaskAbstract // { // public Task(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // @Override // public String toString() // { // return "Task[name=" + this.getName() // + "; from=" + this.getProcessingDateFrom() // + "; to=" + this.getProcessingDateTo() // + "; status=" + this.getStatus() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/TaskList.java // public class TaskList // extends TaskListAbstract // { // public TaskList() // { // super(); // } // // public TaskList(int initialSize) // { // super(initialSize); // } // // public TaskList(Collection c) // { // super(c); // } // // public TaskList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAuditOnly.java import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import kata.domain.Task; import kata.domain.TaskFinder; import kata.domain.TaskList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; import java.util.Date; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesAuditOnly extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Tasks.txt"}; // Look into this file to see the test data being used } // **** NOTES **** // (1) // Different applications can have different conventions to represent the business dates and processing dates. // In this exercise, we are using: // * IN_Z<@processingDate, OUT_Z> = @processingDate (see toIsInclusive() in processingDate attribute // * Infinity date = "9999-12-01 23:59:00.0", a.k.a. kata.util.TimestampProvider.getInfinityDate(). // Look at the definition of the processingDate attribute in Task.xml to see how this is defined/used. // // (2) // Are you completely unfamiliar with chaining? // See the Reladomo documentation //------------------------ Question 1 -------------------------------------------------------- // Get all Tasks
public TaskList getActiveTasks()
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesAuditOnly.java
// Path: main-kata/src/main/java/kata/domain/Task.java // public class Task extends TaskAbstract // { // public Task(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // @Override // public String toString() // { // return "Task[name=" + this.getName() // + "; from=" + this.getProcessingDateFrom() // + "; to=" + this.getProcessingDateTo() // + "; status=" + this.getStatus() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/TaskList.java // public class TaskList // extends TaskListAbstract // { // public TaskList() // { // super(); // } // // public TaskList(int initialSize) // { // super(initialSize); // } // // public TaskList(Collection c) // { // super(c); // } // // public TaskList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import kata.domain.Task; import kata.domain.TaskFinder; import kata.domain.TaskList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; import java.util.Date;
return null; } @Test public void testQ3() { TaskList tasks = this.getTaskHistory(1); Verify.assertAllSatisfy(tasks, Predicates.attributeEqual(TaskFinder.name(), "Build Bridge")); Verify.assertSetsEqual(UnifiedSet.newSetWith( Timestamp.valueOf("1965-01-01 06:00:00.0"), Timestamp.valueOf("1967-01-01 11:30:22.0"), Timestamp.valueOf("1990-01-01 06:00:00.0")), tasks.asEcList().collect(TaskFinder.processingDateFrom()).toSet()); } //------------------------ Question 4 -------------------------------------------------------- // End a task. The task should no longer show up in current query results. public void endTask(final String name) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ4() { int tasksBefore = new TaskList(TaskFinder.all()).count();
// Path: main-kata/src/main/java/kata/domain/Task.java // public class Task extends TaskAbstract // { // public Task(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // @Override // public String toString() // { // return "Task[name=" + this.getName() // + "; from=" + this.getProcessingDateFrom() // + "; to=" + this.getProcessingDateTo() // + "; status=" + this.getStatus() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/TaskList.java // public class TaskList // extends TaskListAbstract // { // public TaskList() // { // super(); // } // // public TaskList(int initialSize) // { // super(initialSize); // } // // public TaskList(Collection c) // { // super(c); // } // // public TaskList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesAuditOnly.java import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import kata.domain.Task; import kata.domain.TaskFinder; import kata.domain.TaskList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; import java.util.Date; return null; } @Test public void testQ3() { TaskList tasks = this.getTaskHistory(1); Verify.assertAllSatisfy(tasks, Predicates.attributeEqual(TaskFinder.name(), "Build Bridge")); Verify.assertSetsEqual(UnifiedSet.newSetWith( Timestamp.valueOf("1965-01-01 06:00:00.0"), Timestamp.valueOf("1967-01-01 11:30:22.0"), Timestamp.valueOf("1990-01-01 06:00:00.0")), tasks.asEcList().collect(TaskFinder.processingDateFrom()).toSet()); } //------------------------ Question 4 -------------------------------------------------------- // End a task. The task should no longer show up in current query results. public void endTask(final String name) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ4() { int tasksBefore = new TaskList(TaskFinder.all()).count();
Task damRiver = TaskFinder.findOne(TaskFinder.name().eq("Dam River"));
goldmansachs/reladomo-kata
mini-kata/src/main/java/kata/domain/Pet.java
// Path: mini-kata/src/main/java/kata/util/TimestampProvider.java // public class TimestampProvider // { // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // public static Timestamp getDate(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(timestamp.getTime()); // calendar.set(Calendar.HOUR_OF_DAY, 0); // calendar.set(Calendar.MINUTE, 0); // calendar.set(Calendar.SECOND, 0); // calendar.set(Calendar.MILLISECOND, 0); // return new Timestamp(calendar.getTime().getTime()); // } // // public static Timestamp getCurrentDate() // { // return TimestampProvider.getDate(new Timestamp(Calendar.getInstance().getTime().getTime())); // } // // public static Timestamp getPreviousDay(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTime(timestamp); // calendar.add(Calendar.DATE, -1); // return TimestampProvider.getDate(timestamp); // } // }
import kata.util.TimestampProvider; import java.sql.Timestamp;
/* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.domain; public class Pet extends PetAbstract { public Pet(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public Pet() {
// Path: mini-kata/src/main/java/kata/util/TimestampProvider.java // public class TimestampProvider // { // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // public static Timestamp getDate(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(timestamp.getTime()); // calendar.set(Calendar.HOUR_OF_DAY, 0); // calendar.set(Calendar.MINUTE, 0); // calendar.set(Calendar.SECOND, 0); // calendar.set(Calendar.MILLISECOND, 0); // return new Timestamp(calendar.getTime().getTime()); // } // // public static Timestamp getCurrentDate() // { // return TimestampProvider.getDate(new Timestamp(Calendar.getInstance().getTime().getTime())); // } // // public static Timestamp getPreviousDay(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTime(timestamp); // calendar.add(Calendar.DATE, -1); // return TimestampProvider.getDate(timestamp); // } // } // Path: mini-kata/src/main/java/kata/domain/Pet.java import kata.util.TimestampProvider; import java.sql.Timestamp; /* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.domain; public class Pet extends PetAbstract { public Pet(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public Pet() {
this(TimestampProvider.getInfinityDate());
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesRelationships.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesRelationships.java import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer.
public CustomerAccountList getAccountsForCustomer(Customer customer)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesRelationships.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesRelationships.java import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer.
public CustomerAccountList getAccountsForCustomer(Customer customer)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesRelationships.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer. public CustomerAccountList getAccountsForCustomer(Customer customer) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Customer customer = CustomerFinder.findOne(CustomerFinder.customerId().eq(1)); CustomerAccountList customerAccounts = this.getAccountsForCustomer(customer); Verify.assertSize(3, customerAccounts); Assert.assertNotNull(CustomerFinder.getRelatedFinderByName("accounts")); } //------------------------ Question 2 -------------------------------------------------------- // Get all customers that have accounts of a particular type.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesRelationships.java import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManagerProvider; import kata.domain.Customer; import kata.domain.CustomerAccountFinder; import kata.domain.CustomerAccountList; import kata.domain.CustomerFinder; import kata.domain.CustomerList; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesRelationships extends AbstractMithraTest { private static final Logger LOGGER = LoggerFactory.getLogger(ExercisesRelationships.class); @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_CustomersAndAccounts.txt"}; // Look into this file to see the test data being used } // Create a relationship on Customer called "accounts". // When you regenerate, this should create a getAccounts() method on Customer, and an accounts() relationship in CustomerFinder. // Use this to answer the following questions. // Also make this relationship bi-directional so that it also creates a customer() relationship on CustomerAccount. // Question: // What is the impact on the footprint of Mithra when you add a new relationship? // Answer: NONE! Relationships are not intrusive and don't cause any extra objects to be loaded. //------------------------ Question 1 -------------------------------------------------------- // Get all accounts of a particular customer. public CustomerAccountList getAccountsForCustomer(Customer customer) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Customer customer = CustomerFinder.findOne(CustomerFinder.customerId().eq(1)); CustomerAccountList customerAccounts = this.getAccountsForCustomer(customer); Verify.assertSize(3, customerAccounts); Assert.assertNotNull(CustomerFinder.getRelatedFinderByName("accounts")); } //------------------------ Question 2 -------------------------------------------------------- // Get all customers that have accounts of a particular type.
public CustomerList getCustomersThatHaveAccountType(String accountType)
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise1Test.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // }
import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise1Test extends AbstractMithraTest { /** * Find all the {@code Person} objects. * Use the appropriate method on {@link kata.domain.PersonFinder}. */ @Test public void getAllPeople() {
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // Path: mini-kata/src/test/java/kata/test/Exercise1Test.java import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise1Test extends AbstractMithraTest { /** * Find all the {@code Person} objects. * Use the appropriate method on {@link kata.domain.PersonFinder}. */ @Test public void getAllPeople() {
PersonList people = null;
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise1Test.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // }
import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise1Test extends AbstractMithraTest { /** * Find all the {@code Person} objects. * Use the appropriate method on {@link kata.domain.PersonFinder}. */ @Test public void getAllPeople() { PersonList people = null; Verify.assertSize(8, people); } /** * Find all the {@code Person} objects with {@code lastName().eq("Smith")}. * Use the appropriate method on {@link kata.domain.PersonFinder} */ @Test public void getAllSmiths() { PersonList smiths = null; Verify.assertSize(3, smiths); } /** * Find all the {@code Pet}s which are older than 1 or if the name is "Wuzzy". * Explore concatenation of multiple conditions using {@code and}, {@code or}. * Use the appropriate method on {@link kata.domain.PetFinder} */ @Test public void getAllPets_OlderThan1_Or_Wuzzy() {
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // Path: mini-kata/src/test/java/kata/test/Exercise1Test.java import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise1Test extends AbstractMithraTest { /** * Find all the {@code Person} objects. * Use the appropriate method on {@link kata.domain.PersonFinder}. */ @Test public void getAllPeople() { PersonList people = null; Verify.assertSize(8, people); } /** * Find all the {@code Person} objects with {@code lastName().eq("Smith")}. * Use the appropriate method on {@link kata.domain.PersonFinder} */ @Test public void getAllSmiths() { PersonList smiths = null; Verify.assertSize(3, smiths); } /** * Find all the {@code Pet}s which are older than 1 or if the name is "Wuzzy". * Explore concatenation of multiple conditions using {@code and}, {@code or}. * Use the appropriate method on {@link kata.domain.PetFinder} */ @Test public void getAllPets_OlderThan1_Or_Wuzzy() {
PetList oldPetsOrWuzzy = null;
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise1Test.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // }
import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
/** * There are no {@code Person} objects with {@code firstName} equal to "George". * Bulk update the {@code firstName} of only those {@code Person} objects with {@code lastName} equal to "Smith". * Use the appropriate method on {@link PersonFinder} and {@link PersonList} */ @Test public void updateAllSmithsFirstNamesToGeorge() { Operation georgeSmithOperation = PersonFinder.firstName().eq("George").and(PersonFinder.lastName().eq("Smith")); PersonList georgeSmiths = PersonFinder.findMany(georgeSmithOperation); Verify.assertEmpty(georgeSmiths); /* Add the update logic here. */ georgeSmiths = PersonFinder.findMany(georgeSmithOperation); Verify.assertSize(3, georgeSmiths); } /** * Insert a new {@code Person} object with first name: Jane and last name: Doe. * Do not add any {@code Pet}s to the new {@code Person} object. * Use appropriate method on {@link Person}. */ @Test public void insertJaneDoe() {
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // Path: mini-kata/src/test/java/kata/test/Exercise1Test.java import com.gs.fw.common.mithra.finder.Operation; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import kata.domain.PetList; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /** * There are no {@code Person} objects with {@code firstName} equal to "George". * Bulk update the {@code firstName} of only those {@code Person} objects with {@code lastName} equal to "Smith". * Use the appropriate method on {@link PersonFinder} and {@link PersonList} */ @Test public void updateAllSmithsFirstNamesToGeorge() { Operation georgeSmithOperation = PersonFinder.firstName().eq("George").and(PersonFinder.lastName().eq("Smith")); PersonList georgeSmiths = PersonFinder.findMany(georgeSmithOperation); Verify.assertEmpty(georgeSmiths); /* Add the update logic here. */ georgeSmiths = PersonFinder.findMany(georgeSmithOperation); Verify.assertSize(3, georgeSmiths); } /** * Insert a new {@code Person} object with first name: Jane and last name: Doe. * Do not add any {@code Pet}s to the new {@code Person} object. * Use appropriate method on {@link Person}. */ @Test public void insertJaneDoe() {
Person janeDoe = PersonFinder.findOne(PersonFinder.firstName().eq("Jane").and(PersonFinder.lastName().eq("Doe")));
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test;
MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager); testResource.setUp(); } @Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) {
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager); testResource.setUp(); } @Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) {
Timestamp jan1 = DateUtils.parse(date);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test;
@Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) { Timestamp jan1 = DateUtils.parse(date); MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx);
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; @Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) { Timestamp jan1 = DateUtils.parse(date); MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx);
Customer customer = new Customer(jan1);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test;
fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) { Timestamp jan1 = DateUtils.parse(date); MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Customer customer = new Customer(jan1); customer.setFirstName("mickey"); customer.setLastName("mouse"); customer.setCustomerId(1); customer.setCountry("usa");
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalChainingInAction.java import java.nio.file.Files; import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountFinder; import bitemporalbank.domain.CustomerFinder; import bitemporalbank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; fetchAccountWithBusinessDate("2017-01-01", accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-17", "2017-01-25", accountId, 50); dumpCustomerAccount(accountId); balanceAsOfJan12_OnJan23(accountId); dumpCustomer(1); } private void createAccount(String date, int accountId) { Timestamp jan1 = DateUtils.parse(date); MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Customer customer = new Customer(jan1); customer.setFirstName("mickey"); customer.setLastName("mouse"); customer.setCustomerId(1); customer.setCountry("usa");
CustomerAccount account = new CustomerAccount(jan1);
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesBasicFinder.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.test.MithraRuntimeConfigVerifier; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; import java.io.IOException;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesBasicFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get all people.
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesBasicFinder.java import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.test.MithraRuntimeConfigVerifier; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; import java.io.IOException; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesBasicFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get all people.
public PersonList getAllPeople()
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesBasicFinder.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.test.MithraRuntimeConfigVerifier; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; import java.io.IOException;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesBasicFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get all people. public PersonList getAllPeople() { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Verify.assertSize(16, this.getAllPeople()); } //-------------- Question 2 ------------------------------------------------------ // Get a person with a specific name.
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesBasicFinder.java import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.set.mutable.UnifiedSet; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.test.MithraRuntimeConfigVerifier; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; import java.io.IOException; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesBasicFinder extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get all people. public PersonList getAllPeople() { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Verify.assertSize(16, this.getAllPeople()); } //-------------- Question 2 ------------------------------------------------------ // Get a person with a specific name.
public Person getPersonNamed(String name)
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/AbstractMithraTest.java
// Path: mini-kata/src/main/java/kata/domain/Pet.java // public class Pet extends PetAbstract // { // public Pet(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Pet() // { // this(TimestampProvider.getInfinityDate()); // } // // public Pet(String petName, int personId, int petAge, int petTypeId) // { // this(TimestampProvider.getInfinityDate()); // this.setPetName(petName); // this.setPersonId(personId); // this.setPetAge(petAge); // this.setPetTypeId(petTypeId); // } // }
import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import kata.domain.Pet; import org.eclipse.collections.api.block.function.Function; import org.junit.After; import org.junit.Before;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class AbstractMithraTest {
// Path: mini-kata/src/main/java/kata/domain/Pet.java // public class Pet extends PetAbstract // { // public Pet(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Pet() // { // this(TimestampProvider.getInfinityDate()); // } // // public Pet(String petName, int personId, int petAge, int petTypeId) // { // this(TimestampProvider.getInfinityDate()); // this.setPetName(petName); // this.setPersonId(personId); // this.setPetAge(petAge); // this.setPetTypeId(petTypeId); // } // } // Path: mini-kata/src/test/java/kata/test/AbstractMithraTest.java import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import kata.domain.Pet; import org.eclipse.collections.api.block.function.Function; import org.junit.After; import org.junit.Before; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class AbstractMithraTest {
public static final Function<Pet, String> TO_PET_NAME = Pet::getPetName;
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // }
import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.MithraManagerProvider; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import javax.ws.rs.core.UriBuilder; import java.io.IOException; import java.io.InputStream; import java.net.URI;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.web; public class SimpleBankServer { private ResourceConfig config; public SimpleBankServer(String runtimeConfigXML) throws Exception { this.initReladomo(runtimeConfigXML); } protected void initReladomo(String runtimeConfigXML) throws Exception { MithraManager mithraManager = MithraManagerProvider.getMithraManager(); mithraManager.setTransactionTimeout(60 * 1000); InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); MithraManagerProvider.getMithraManager().readConfiguration(stream); stream.close(); } private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception { InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); if (stream == null) { throw new Exception("Failed to locate " + fileName + " in classpath"); } return stream; } protected void initResources() { this.config = new ResourceConfig(CustomerResource.class); config.register(JacksonFeature.class);
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java import com.gs.fw.common.mithra.MithraManager; import com.gs.fw.common.mithra.MithraManagerProvider; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.server.ResourceConfig; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import javax.ws.rs.core.UriBuilder; import java.io.IOException; import java.io.InputStream; import java.net.URI; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.web; public class SimpleBankServer { private ResourceConfig config; public SimpleBankServer(String runtimeConfigXML) throws Exception { this.initReladomo(runtimeConfigXML); } protected void initReladomo(String runtimeConfigXML) throws Exception { MithraManager mithraManager = MithraManagerProvider.getMithraManager(); mithraManager.setTransactionTimeout(60 * 1000); InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); MithraManagerProvider.getMithraManager().readConfiguration(stream); stream.close(); } private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception { InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); if (stream == null) { throw new Exception("Failed to locate " + fileName + " in classpath"); } return stream; } protected void initResources() { this.config = new ResourceConfig(CustomerResource.class); config.register(JacksonFeature.class);
config.register(SimpleBankJacksonObjectMapperProvider.class);
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesDetachedObjects.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.test.Verify; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesDetachedObjects extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Give a detached object of "Clark Kent" to the [simulated] GUI for editing. public void giveClarkKentToGui() { Assert.fail("Implement this functionality to make the test pass");
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesDetachedObjects.java import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.test.Verify; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesDetachedObjects extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Person.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Give a detached object of "Clark Kent" to the [simulated] GUI for editing. public void giveClarkKentToGui() { Assert.fail("Implement this functionality to make the test pass");
Person clarkKent = null;
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesDetachedObjects.java
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.test.Verify; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test;
private void guiChangesClarkKent(Person person) { Assert.assertNotNull(person); person.setName("Superman"); person.setAge(28); } @Test public void testQ1() { this.giveClarkKentToGui(); Person clarkKent = PersonFinder.findOne(PersonFinder.personId().eq(5)); Assert.assertEquals("Clark Kent", clarkKent.getName()); Assert.assertEquals(38, clarkKent.getAge()); } //-------------- Question 2 ------------------------------------------------------ // Accept a changed object from the [simulated] GUI, and persist the changes. public void persistClarkKentChangesFromGui(Person person) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ2() {
// Path: main-kata/src/main/java/kata/domain/Person.java // public class Person // extends PersonAbstract // { // // Added for ExercisesAdvancedFinder question 9 // public static final Procedure<Person> INCREMENT_AGE = new Procedure<Person>() // { // public void value(Person person) // { // person.incrementAge(); // } // }; // // public Person() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added for ExercisesAdvancedFinder question 9 // public void incrementAge() // { // this.setAge(this.getAge() + 1); // } // // @Override // public String toString() // { // return "Person[name=" + this.getName() // + "; country=" + this.getCountry() // + "; age=" + this.getAge() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesDetachedObjects.java import org.eclipse.collections.impl.block.factory.Predicates; import org.eclipse.collections.impl.test.Verify; import kata.domain.Person; import kata.domain.PersonFinder; import kata.domain.PersonList; import org.junit.Assert; import org.junit.Test; private void guiChangesClarkKent(Person person) { Assert.assertNotNull(person); person.setName("Superman"); person.setAge(28); } @Test public void testQ1() { this.giveClarkKentToGui(); Person clarkKent = PersonFinder.findOne(PersonFinder.personId().eq(5)); Assert.assertEquals("Clark Kent", clarkKent.getName()); Assert.assertEquals(38, clarkKent.getAge()); } //-------------- Question 2 ------------------------------------------------------ // Accept a changed object from the [simulated] GUI, and persist the changes. public void persistClarkKentChangesFromGui(Person person) { Assert.fail("Implement this functionality to make the test pass"); } @Test public void testQ2() {
int peopleBefore = new PersonList(PersonFinder.all()).count();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/TimestampProvider.java // public class TimestampProvider // { // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // }
import auditonlybank.util.TimestampProvider; import java.sql.Timestamp;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package auditonlybank.domain; public class CustomerAccount extends CustomerAccountAbstract { public CustomerAccount(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public CustomerAccount() {
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/TimestampProvider.java // public class TimestampProvider // { // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // } // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java import auditonlybank.util.TimestampProvider; import java.sql.Timestamp; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package auditonlybank.domain; public class CustomerAccount extends CustomerAccountAbstract { public CustomerAccount(Timestamp processingDate) { super(processingDate); // You must not modify this constructor. Mithra calls this internally. // You can call this constructor. You can also add new constructors. } public CustomerAccount() {
this(TimestampProvider.getInfinityDate());
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.api; public class BitemporalBankAPITest { private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception {
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.api; public class BitemporalBankAPITest { private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception {
new BitemporalBankServer(testRuntimeConfigXML).start();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.api; public class BitemporalBankAPITest { private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package bitemporalbank.api; public class BitemporalBankAPITest { private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>()
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName());
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName());
CustomerAccountList mickeysAccounts = mickey.getAccounts();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size());
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount(Timestamp businessDate) // { // super(businessDate); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java // public class BitemporalBankServer // { // // private ResourceConfig config; // // public BitemporalBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml"; // new BitemporalBankServer(runtimeConfigXML).start(); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // loadReladomoXML(runtimeConfigXML); // } // // protected void loadReladomoXML(String fileName) throws Exception // { // InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(BitemporalBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // } // Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import bitemporalbank.domain.Customer; import bitemporalbank.domain.CustomerAccount; import bitemporalbank.domain.CustomerAccountList; import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider; import bitemporalbank.web.BitemporalBankServer; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; testResource.setUp(); } private void initializeApp() throws Exception { new BitemporalBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target .queryParam("businessDate", "2017-01-20") .request(MediaType.APPLICATION_JSON_TYPE) .get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size());
CustomerAccount clubhouseAccount = mickeysAccounts.get(0);
goldmansachs/reladomo-kata
main-kata/src/main/java/kata/util/ObjectSequenceObjectFactory.java
// Path: main-kata/src/main/java/kata/domain/ObjectSequence.java // public class ObjectSequence // extends ObjectSequenceAbstract // implements MithraSequence // { // public ObjectSequence() // { // super(); // } // // public void setSequenceName(String sequenceName) // { // this.setSimulatedSequenceName(sequenceName); // } // // public long getNextId() // { // return this.getNextValue(); // } // // public void setNextId(long nextValue) // { // this.setNextValue(nextValue); // } // }
import com.gs.fw.common.mithra.MithraSequence; import com.gs.fw.common.mithra.MithraSequenceObjectFactory; import kata.domain.ObjectSequence; import kata.domain.ObjectSequenceFinder;
/* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.util; public class ObjectSequenceObjectFactory implements MithraSequenceObjectFactory { public MithraSequence getMithraSequenceObject(String sequenceName, Object sourceAttribute, int initialValue) {
// Path: main-kata/src/main/java/kata/domain/ObjectSequence.java // public class ObjectSequence // extends ObjectSequenceAbstract // implements MithraSequence // { // public ObjectSequence() // { // super(); // } // // public void setSequenceName(String sequenceName) // { // this.setSimulatedSequenceName(sequenceName); // } // // public long getNextId() // { // return this.getNextValue(); // } // // public void setNextId(long nextValue) // { // this.setNextValue(nextValue); // } // } // Path: main-kata/src/main/java/kata/util/ObjectSequenceObjectFactory.java import com.gs.fw.common.mithra.MithraSequence; import com.gs.fw.common.mithra.MithraSequenceObjectFactory; import kata.domain.ObjectSequence; import kata.domain.ObjectSequenceFinder; /* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.util; public class ObjectSequenceObjectFactory implements MithraSequenceObjectFactory { public MithraSequence getMithraSequenceObject(String sequenceName, Object sourceAttribute, int initialValue) {
ObjectSequence objectSequence = ObjectSequenceFinder.findByPrimaryKey(sequenceName);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.api; /** * Created by stanle on 2/18/17. */ public class SimpleBankAPITest { private String testRuntimeConfigXML = "testconfig/SimpleBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception {
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.api; /** * Created by stanle on 2/18/17. */ public class SimpleBankAPITest { private String testRuntimeConfigXML = "testconfig/SimpleBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception {
new SimpleBankServer(testRuntimeConfigXML).start();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
/* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.api; /** * Created by stanle on 2/18/17. */ public class SimpleBankAPITest { private String testRuntimeConfigXML = "testconfig/SimpleBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; /* Copyright 2016 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package simplebank.api; /** * Created by stanle on 2/18/17. */ public class SimpleBankAPITest { private String testRuntimeConfigXML = "testconfig/SimpleBankTestRuntimeConfiguration.xml"; @Before public void setup() throws Exception { intializeReladomoForTest(); initializeApp(); } private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>()
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName());
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; private void intializeReladomoForTest() { MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName());
CustomerAccountList mickeysAccounts = mickey.getAccounts();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size());
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML); ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/SimpleBankTestData.txt"); testResource.setUp(); } private void initializeApp() throws Exception { new SimpleBankServer(testRuntimeConfigXML).start(); } @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size());
CustomerAccount clubhouseAccount = mickeysAccounts.get(0);
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // }
import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder;
@Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size()); CustomerAccount clubhouseAccount = mickeysAccounts.get(0); assertEquals(100, clubhouseAccount.getAccountId()); assertEquals("mickey mouse club", clubhouseAccount.getAccountName()); assertEquals("savings", clubhouseAccount.getAccountType()); assertEquals(5000, clubhouseAccount.getBalance(), 0); } private WebTarget webTarget(String path) { Client client = ClientBuilder.newClient(); client.register(JacksonFeature.class);
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer(int customerId, String firstName, String lastName) // { // super(); // this.setCustomerId(customerId); // this.setFirstName(firstName); // this.setLastName(lastName); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccountList.java // public class CustomerAccountList extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java // public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper> // { // final ObjectMapper defaultObjectMapper; // // public SimpleBankJacksonObjectMapperProvider() // { // defaultObjectMapper = new ObjectMapper(); // defaultObjectMapper.registerModule(new JacksonReladomoModule()); // } // // @Override // public ObjectMapper getContext(Class<?> type) // { // return defaultObjectMapper; // } // } // // Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java // public class SimpleBankServer // { // private ResourceConfig config; // // public SimpleBankServer(String runtimeConfigXML) throws Exception // { // this.initReladomo(runtimeConfigXML); // } // // protected void initReladomo(String runtimeConfigXML) throws Exception // { // MithraManager mithraManager = MithraManagerProvider.getMithraManager(); // mithraManager.setTransactionTimeout(60 * 1000); // InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML); // MithraManagerProvider.getMithraManager().readConfiguration(stream); // stream.close(); // } // // private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception // { // InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName); // if (stream == null) // { // throw new Exception("Failed to locate " + fileName + " in classpath"); // } // return stream; // } // // protected void initResources() // { // this.config = new ResourceConfig(CustomerResource.class); // config.register(JacksonFeature.class); // config.register(SimpleBankJacksonObjectMapperProvider.class); // } // // public void start() throws IOException // { // initResources(); // URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build(); // HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); // server.start(); // } // // public static void main(String[] args) throws Exception // { // String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml"; // new SimpleBankServer(runtimeConfigXML).start(); // } // } // Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.java import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.serializer.Serialized; import org.glassfish.jersey.jackson.JacksonFeature; import org.junit.Before; import org.junit.Test; import simplebank.domain.Customer; import simplebank.domain.CustomerAccount; import simplebank.domain.CustomerAccountList; import simplebank.serialization.SimpleBankJacksonObjectMapperProvider; import simplebank.web.SimpleBankServer; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @Test public void testGetCustomer() { WebTarget target = webTarget("/api/customer/1"); Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>() { }); Customer mickey = mickeySerialized.getWrapped(); assertEquals(1, mickey.getCustomerId()); assertEquals("mickey", mickey.getFirstName()); assertEquals("mouse", mickey.getLastName()); CustomerAccountList mickeysAccounts = mickey.getAccounts(); assertEquals(1, mickeysAccounts.size()); CustomerAccount clubhouseAccount = mickeysAccounts.get(0); assertEquals(100, clubhouseAccount.getAccountId()); assertEquals("mickey mouse club", clubhouseAccount.getAccountName()); assertEquals("savings", clubhouseAccount.getAccountType()); assertEquals(5000, clubhouseAccount.getBalance(), 0); } private WebTarget webTarget(String path) { Client client = ClientBuilder.newClient(); client.register(JacksonFeature.class);
client.register(SimpleBankJacksonObjectMapperProvider.class);
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise2Test.java
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // }
import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise2Test extends AbstractMithraTest { /** * Find the list of {@code Pet}s. Order them first by {@code petAge} descending, and then by {@code petName} ascending. * Use appropriate method on {@link PetFinder} and {@link PetList} */ @Test public void getAllPetsDescendingOrderedByAgeAndAscendingByName() {
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // Path: mini-kata/src/test/java/kata/test/Exercise2Test.java import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise2Test extends AbstractMithraTest { /** * Find the list of {@code Pet}s. Order them first by {@code petAge} descending, and then by {@code petName} ascending. * Use appropriate method on {@link PetFinder} and {@link PetList} */ @Test public void getAllPetsDescendingOrderedByAgeAndAscendingByName() {
PetList pets = null;
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise2Test.java
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // }
import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise2Test extends AbstractMithraTest { /** * Find the list of {@code Pet}s. Order them first by {@code petAge} descending, and then by {@code petName} ascending. * Use appropriate method on {@link PetFinder} and {@link PetList} */ @Test public void getAllPetsDescendingOrderedByAgeAndAscendingByName() { PetList pets = null; Verify.assertListsEqual(Lists.mutable.with("Speedy", "Spot", "Spike", "Dolly", "Tabby", "Tweety", "Fuzzy", "Wuzzy"), pets.asEcList().collect(TO_PET_NAME)); } /** * Find all the {@code Person} objects which have at least 1 {@code Pet}. * Use Reladomo's relationship traversal between {@code Person} and {@code Pet} * Use appropriate method on {@link kata.domain.PersonFinder} */ @Test public void getAllPeopleWithPets() {
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // Path: mini-kata/src/test/java/kata/test/Exercise2Test.java import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class Exercise2Test extends AbstractMithraTest { /** * Find the list of {@code Pet}s. Order them first by {@code petAge} descending, and then by {@code petName} ascending. * Use appropriate method on {@link PetFinder} and {@link PetList} */ @Test public void getAllPetsDescendingOrderedByAgeAndAscendingByName() { PetList pets = null; Verify.assertListsEqual(Lists.mutable.with("Speedy", "Spot", "Spike", "Dolly", "Tabby", "Tweety", "Fuzzy", "Wuzzy"), pets.asEcList().collect(TO_PET_NAME)); } /** * Find all the {@code Person} objects which have at least 1 {@code Pet}. * Use Reladomo's relationship traversal between {@code Person} and {@code Pet} * Use appropriate method on {@link kata.domain.PersonFinder} */ @Test public void getAllPeopleWithPets() {
PersonList petPeople = null;
goldmansachs/reladomo-kata
mini-kata/src/test/java/kata/test/Exercise2Test.java
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // }
import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test;
{ PersonList dogLovers = null; Verify.assertSize(2, dogLovers); } /** * The relationship is one {@link kata.domain.Person} to many {@link kata.domain.Pet}s, many {@link kata.domain.Pet}s to one {@link PetType}. * Since there are three relationships the minimum database hits are 3. * Use appropriate method on {@link kata.domain.PersonFinder} and Reladomo's {@code deepFetch} property. * * @see PersonList#deepFetch(Navigation) */ @Test public void getAllObjectsInMinDatabaseHits() { int minDatabaseHits = 3; PersonList people = null; Verify.assertSize(8, people); int databaseHitsAfterPeopleFetch = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount(); for (int i = 0; i < people.size(); i++) { PetList pets = people.getPersonAt(i).getPets(); int databaseHitsAfterPetFetch = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount(); Assert.assertEquals(databaseHitsAfterPeopleFetch, databaseHitsAfterPetFetch); for (int j = 0; j < pets.size(); j++) {
// Path: main-kata/src/main/java/kata/domain/PersonList.java // public class PersonList // extends PersonListAbstract // { // public PersonList() // { // super(); // } // // public PersonList(int initialSize) // { // super(initialSize); // } // // public PersonList(Collection c) // { // super(c); // } // // public PersonList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetList.java // public class PetList extends PetListAbstract // { // public PetList() // { // super(); // } // // public PetList(int initialSize) // { // super(initialSize); // } // // public PetList(Collection c) // { // super(c); // } // // public PetList(Operation operation) // { // super(operation); // } // // /** // * For each element in the list, print out petName() + " plays". // */ // public void play() // { // throw new UnsupportedOperationException("Implement this as a part of kata.testExercise4Test.makePetsPlay"); // } // } // // Path: mini-kata/src/main/java/kata/domain/PetType.java // public class PetType extends PetTypeAbstract // { // public static final int CAT_ID = 1; // public static final int DOG_ID = 2; // public static final int SNAKE_ID = 3; // public static final int BIRD_ID = 4; // public static final int TURTLE_ID = 5; // public static final int HAMSTER_ID = 6; // // public PetType() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // } // Path: mini-kata/src/test/java/kata/test/Exercise2Test.java import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.finder.Navigation; import kata.domain.PersonList; import kata.domain.PetFinder; import kata.domain.PetList; import kata.domain.PetType; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; { PersonList dogLovers = null; Verify.assertSize(2, dogLovers); } /** * The relationship is one {@link kata.domain.Person} to many {@link kata.domain.Pet}s, many {@link kata.domain.Pet}s to one {@link PetType}. * Since there are three relationships the minimum database hits are 3. * Use appropriate method on {@link kata.domain.PersonFinder} and Reladomo's {@code deepFetch} property. * * @see PersonList#deepFetch(Navigation) */ @Test public void getAllObjectsInMinDatabaseHits() { int minDatabaseHits = 3; PersonList people = null; Verify.assertSize(8, people); int databaseHitsAfterPeopleFetch = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount(); for (int i = 0; i < people.size(); i++) { PetList pets = people.getPersonAt(i).getPets(); int databaseHitsAfterPetFetch = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount(); Assert.assertEquals(databaseHitsAfterPeopleFetch, databaseHitsAfterPetFetch); for (int j = 0; j < pets.size(); j++) {
PetType petType = pets.getPetAt(j).getPetType();
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesObjectFromScratch.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // }
import kata.domain.Customer; import kata.domain.CustomerAccountList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp;
/* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesObjectFromScratch extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_ObjectFromScratch.txt"}; // Look here to see the data for this test } /* * For this exercise you need to introduce a new mithra Class. * This will represent the AccountLimit. * AccountLimit will represent the limit of an account for a particular business date. * This should be a DATED object (FROM_Z, THRU_Z, IN_Z, OUT_Z), * whose key will be the accountId, and have a double "limit" attribute. * A customer can talk to his Bank representative to change his/her account limit, * but the change will only take effect from the date of the change onwards, * such that any charges for going over the limit that happened in the past * can still get calculated after the task. * * * To add the object successfully make sure that: * - You create the xml correctly. * - You get the Mithra Code generator to pick up your xml. * - You register the new object with the mithra runtime config XML * and set the appropriate caching policy for the object. * * * You will need to add test data that will make sense for your tests in: * testdata/data_ObjectFromScratch.txt * * * Add any relationships that make sense. * You are encouraged to add the following: * - AccountLimit - CustomerAccount (relationship between dated and non-dated objects) * - AccountLimit - AccountBalance (relationship between two dated object) */ //---------------------- Question 1 --------------------------------------------- // Get all accounts who have exceeded their balance for a particular day.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesObjectFromScratch.java import kata.domain.Customer; import kata.domain.CustomerAccountList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; /* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesObjectFromScratch extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_ObjectFromScratch.txt"}; // Look here to see the data for this test } /* * For this exercise you need to introduce a new mithra Class. * This will represent the AccountLimit. * AccountLimit will represent the limit of an account for a particular business date. * This should be a DATED object (FROM_Z, THRU_Z, IN_Z, OUT_Z), * whose key will be the accountId, and have a double "limit" attribute. * A customer can talk to his Bank representative to change his/her account limit, * but the change will only take effect from the date of the change onwards, * such that any charges for going over the limit that happened in the past * can still get calculated after the task. * * * To add the object successfully make sure that: * - You create the xml correctly. * - You get the Mithra Code generator to pick up your xml. * - You register the new object with the mithra runtime config XML * and set the appropriate caching policy for the object. * * * You will need to add test data that will make sense for your tests in: * testdata/data_ObjectFromScratch.txt * * * Add any relationships that make sense. * You are encouraged to add the following: * - AccountLimit - CustomerAccount (relationship between dated and non-dated objects) * - AccountLimit - AccountBalance (relationship between two dated object) */ //---------------------- Question 1 --------------------------------------------- // Get all accounts who have exceeded their balance for a particular day.
public CustomerAccountList getAccountsOverTheLimit(Timestamp businessDate)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesObjectFromScratch.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // }
import kata.domain.Customer; import kata.domain.CustomerAccountList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp;
/* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesObjectFromScratch extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_ObjectFromScratch.txt"}; // Look here to see the data for this test } /* * For this exercise you need to introduce a new mithra Class. * This will represent the AccountLimit. * AccountLimit will represent the limit of an account for a particular business date. * This should be a DATED object (FROM_Z, THRU_Z, IN_Z, OUT_Z), * whose key will be the accountId, and have a double "limit" attribute. * A customer can talk to his Bank representative to change his/her account limit, * but the change will only take effect from the date of the change onwards, * such that any charges for going over the limit that happened in the past * can still get calculated after the task. * * * To add the object successfully make sure that: * - You create the xml correctly. * - You get the Mithra Code generator to pick up your xml. * - You register the new object with the mithra runtime config XML * and set the appropriate caching policy for the object. * * * You will need to add test data that will make sense for your tests in: * testdata/data_ObjectFromScratch.txt * * * Add any relationships that make sense. * You are encouraged to add the following: * - AccountLimit - CustomerAccount (relationship between dated and non-dated objects) * - AccountLimit - AccountBalance (relationship between two dated object) */ //---------------------- Question 1 --------------------------------------------- // Get all accounts who have exceeded their balance for a particular day. public CustomerAccountList getAccountsOverTheLimit(Timestamp businessDate) { Assert.fail("Implement this method to get the test to pass"); return null; } @Test public void testQ1() { Assert.fail("Implement to test the behaviour in this question"); } // --------------------- Question 2 ---------------------------------------------- // For a particular customer, get the net balance over the limit // for a particular business date. // If the customer has two accounts, one which is $5 over the limit // and the other one is $6 under the limit the result should be 5 - 6 = -1.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerAccountList.java // public class CustomerAccountList // extends CustomerAccountListAbstract // { // public CustomerAccountList() // { // super(); // } // // public CustomerAccountList(int initialSize) // { // super(initialSize); // } // // public CustomerAccountList(Collection c) // { // super(c); // } // // public CustomerAccountList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesObjectFromScratch.java import kata.domain.Customer; import kata.domain.CustomerAccountList; import org.junit.Assert; import org.junit.Test; import java.sql.Timestamp; /* Copyright 2017 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesObjectFromScratch extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_ObjectFromScratch.txt"}; // Look here to see the data for this test } /* * For this exercise you need to introduce a new mithra Class. * This will represent the AccountLimit. * AccountLimit will represent the limit of an account for a particular business date. * This should be a DATED object (FROM_Z, THRU_Z, IN_Z, OUT_Z), * whose key will be the accountId, and have a double "limit" attribute. * A customer can talk to his Bank representative to change his/her account limit, * but the change will only take effect from the date of the change onwards, * such that any charges for going over the limit that happened in the past * can still get calculated after the task. * * * To add the object successfully make sure that: * - You create the xml correctly. * - You get the Mithra Code generator to pick up your xml. * - You register the new object with the mithra runtime config XML * and set the appropriate caching policy for the object. * * * You will need to add test data that will make sense for your tests in: * testdata/data_ObjectFromScratch.txt * * * Add any relationships that make sense. * You are encouraged to add the following: * - AccountLimit - CustomerAccount (relationship between dated and non-dated objects) * - AccountLimit - AccountBalance (relationship between two dated object) */ //---------------------- Question 1 --------------------------------------------- // Get all accounts who have exceeded their balance for a particular day. public CustomerAccountList getAccountsOverTheLimit(Timestamp businessDate) { Assert.fail("Implement this method to get the test to pass"); return null; } @Test public void testQ1() { Assert.fail("Implement to test the behaviour in this question"); } // --------------------- Question 2 ---------------------------------------------- // For a particular customer, get the net balance over the limit // for a particular business date. // If the customer has two accounts, one which is $5 over the limit // and the other one is $6 under the limit the result should be 5 - 6 = -1.
public double getNetBalanceOverLimit(Customer customer, Timestamp businessDate)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesMTLoader.java
// Path: main-kata/src/main/java/kata/domain/Employee.java // public class Employee extends EmployeeAbstract // { // public Employee(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate // ); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Employee(Timestamp businessDate) // { // super(businessDate); // } // // public Employee( // Timestamp businessDate, // int employeeId, // String firstName, // String lastName, // int age) // { // super(businessDate); // this.setEmployeeId(employeeId); // this.setFirstName(firstName); // this.setLastName(lastName); // this.setAge(age); // } // } // // Path: main-kata/src/main/java/kata/domain/EmployeeList.java // public class EmployeeList extends EmployeeListAbstract // { // public EmployeeList() // { // super(); // } // // public EmployeeList(int initialSize) // { // super(initialSize); // } // // public EmployeeList(Collection c) // { // super(c); // } // // public EmployeeList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/util/TimestampProvider.java // public class TimestampProvider // { // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // public static Timestamp getDate(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(timestamp.getTime()); // calendar.set(Calendar.HOUR_OF_DAY, 0); // calendar.set(Calendar.MINUTE, 0); // calendar.set(Calendar.SECOND, 0); // calendar.set(Calendar.MILLISECOND, 0); // return new Timestamp(calendar.getTime().getTime()); // } // // public static Timestamp getCurrentDate() // { // return TimestampProvider.getDate(new Timestamp(Calendar.getInstance().getTime().getTime())); // } // // public static Timestamp getPreviousDay(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTime(timestamp); // calendar.add(Calendar.DATE, -1); // return TimestampProvider.getDate(timestamp); // } // }
import java.sql.Timestamp; import java.util.List; import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.MithraTransactionalObject; import com.gs.fw.common.mithra.mtloader.InputLoader; import com.gs.fw.common.mithra.util.SingleQueueExecutor; import kata.domain.Employee; import kata.domain.EmployeeFinder; import kata.domain.EmployeeList; import kata.util.TimestampProvider; import org.junit.Assert; import org.junit.Before; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesMTLoader extends AbstractMithraTest { private static final int NUM_THREADS = 3; private static final int BATCH_SIZE = 1; private SingleQueueExecutor executor;
// Path: main-kata/src/main/java/kata/domain/Employee.java // public class Employee extends EmployeeAbstract // { // public Employee(Timestamp businessDate, Timestamp processingDate) // { // super(businessDate, processingDate // ); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Employee(Timestamp businessDate) // { // super(businessDate); // } // // public Employee( // Timestamp businessDate, // int employeeId, // String firstName, // String lastName, // int age) // { // super(businessDate); // this.setEmployeeId(employeeId); // this.setFirstName(firstName); // this.setLastName(lastName); // this.setAge(age); // } // } // // Path: main-kata/src/main/java/kata/domain/EmployeeList.java // public class EmployeeList extends EmployeeListAbstract // { // public EmployeeList() // { // super(); // } // // public EmployeeList(int initialSize) // { // super(initialSize); // } // // public EmployeeList(Collection c) // { // super(c); // } // // public EmployeeList(Operation operation) // { // super(operation); // } // } // // Path: mini-kata/src/main/java/kata/util/TimestampProvider.java // public class TimestampProvider // { // private TimestampProvider() // { // throw new UnsupportedOperationException("utility methods only -- not instantiable"); // } // // private static final Timestamp INFINITY_DATE = TimestampProvider.create(9999, 11, 1, Calendar.PM, 23, 59, 0, 0); // // private static Timestamp create(int year, int month, int dayOfMonth, int amPm, int hourOfDay, int minute, int second, int millisecond) // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, year); // cal.set(Calendar.MONTH, month); // cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); // cal.set(Calendar.AM_PM, amPm); // cal.set(Calendar.HOUR_OF_DAY, hourOfDay); // cal.set(Calendar.MINUTE, minute); // cal.set(Calendar.SECOND, second); // cal.set(Calendar.MILLISECOND, millisecond); // return new Timestamp(cal.getTimeInMillis()); // } // // /** // * Infinity reference date. // * // * @return A timestamp representing date "9999-12-01 23:59:00.0" // */ // public static Timestamp getInfinityDate() // { // return INFINITY_DATE; // } // // public static Timestamp createBusinessDate(Date date) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // private static void setBusinessDateTime(Calendar cal) // { // cal.set(Calendar.AM_PM, Calendar.PM); // cal.set(Calendar.HOUR_OF_DAY, 18); // cal.set(Calendar.MINUTE, 30); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // } // // /** // * Converts the date passed to a Timestamp that is at 18:30 of the same day as the argument passed. // * // * @return a timestamp at 18:30 at the same day as the argument // */ // public static Timestamp ensure1830(Date date) // { // return createBusinessDate(date); // } // // public static Timestamp getNextDay(Timestamp businessDay) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(businessDay); // cal.add(Calendar.DATE, 1); // setBusinessDateTime(cal); // return new Timestamp(cal.getTimeInMillis()); // } // // public static Timestamp getDate(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(timestamp.getTime()); // calendar.set(Calendar.HOUR_OF_DAY, 0); // calendar.set(Calendar.MINUTE, 0); // calendar.set(Calendar.SECOND, 0); // calendar.set(Calendar.MILLISECOND, 0); // return new Timestamp(calendar.getTime().getTime()); // } // // public static Timestamp getCurrentDate() // { // return TimestampProvider.getDate(new Timestamp(Calendar.getInstance().getTime().getTime())); // } // // public static Timestamp getPreviousDay(Timestamp timestamp) // { // Calendar calendar = Calendar.getInstance(); // calendar.setTime(timestamp); // calendar.add(Calendar.DATE, -1); // return TimestampProvider.getDate(timestamp); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesMTLoader.java import java.sql.Timestamp; import java.util.List; import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import com.gs.fw.common.mithra.MithraTransactionalObject; import com.gs.fw.common.mithra.mtloader.InputLoader; import com.gs.fw.common.mithra.util.SingleQueueExecutor; import kata.domain.Employee; import kata.domain.EmployeeFinder; import kata.domain.EmployeeList; import kata.util.TimestampProvider; import org.junit.Assert; import org.junit.Before; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesMTLoader extends AbstractMithraTest { private static final int NUM_THREADS = 3; private static final int BATCH_SIZE = 1; private SingleQueueExecutor executor;
private MutableList<Employee> fileList;
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files;
ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/AuditOnlyChainingInActionTestData.txt"); testResource.setUp(); } @Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchLatestAccount(accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-25", accountId, 50); dumpCustomerAccount(accountId); } private void createAccount(String date, int accountId) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // Simulate the db change happening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx);
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files; ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db"); testResource.createSingleDatabase(connectionManager, "testconfig/AuditOnlyChainingInActionTestData.txt"); testResource.setUp(); } @Test public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchLatestAccount(accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-25", accountId, 50); dumpCustomerAccount(accountId); } private void createAccount(String date, int accountId) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // Simulate the db change happening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx);
Customer customer = new Customer();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files;
public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchLatestAccount(accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-25", accountId, 50); dumpCustomerAccount(accountId); } private void createAccount(String date, int accountId) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // Simulate the db change happening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Customer customer = new Customer(); customer.setFirstName("mickey"); customer.setLastName("mouse"); customer.setCustomerId(1); customer.setCountry("usa");
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files; public void run() throws Exception { int accountId = 12345; createAccount("2017-01-01", accountId); fetchLatestAccount(accountId); updateBalance("2017-01-20", accountId, 200); dumpCustomerAccount(accountId); updateBalance("2017-01-25", accountId, 50); dumpCustomerAccount(accountId); } private void createAccount(String date, int accountId) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // Simulate the db change happening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Customer customer = new Customer(); customer.setFirstName("mickey"); customer.setLastName("mouse"); customer.setCustomerId(1); customer.setCountry("usa");
CustomerAccount account = new CustomerAccount();
goldmansachs/reladomo-kata
reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // }
import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files;
private void updateBalance(String date, int accountId, int deposit) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Operation id = CustomerAccountFinder.accountId().eq(accountId); CustomerAccount account = CustomerAccountFinder.findOne(id); account.setBalance(account.getBalance() + deposit); return null; }); } /* This test relies on an account that has been loaded into memory via the test data file. See the test setup for details. */ @Test public void run2() throws Exception { int accountId = 5678; balanceAsOfJan1(accountId); balanceAsOfJan20(accountId); balanceAsOfJan25(accountId); balanceAsOfJan17(accountId); } private void balanceAsOfJan1(int accountId) {
// Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/Customer.java // public class Customer extends CustomerAbstract // { // public Customer(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public Customer() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/domain/CustomerAccount.java // public class CustomerAccount extends CustomerAccountAbstract // { // public CustomerAccount(Timestamp processingDate) // { // super(processingDate); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // public CustomerAccount() // { // this(TimestampProvider.getInfinityDate()); // } // } // // Path: reladomo-tour/tour-examples/auditonly-bank/src/main/java/auditonlybank/util/DateUtils.java // public class DateUtils // { // private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("YYY-MM-dd"); // // private static final DateTimeFormatter DATE_TIME_FORMATTER_FULL = DateTimeFormat.forPattern("YYY-MM-dd HH:mm:ss.SSS"); // // public static Timestamp parseFull(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String printFull(Timestamp ts) // { // return DATE_TIME_FORMATTER_FULL.print(ts.getTime()); // } // // public static Timestamp parse(String dateTimeString) // { // DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); // return new Timestamp(dateTime.toDateTime().getMillis()); // } // // public static String print(Timestamp ts) // { // return DATE_TIME_FORMATTER.print(ts.getTime()); // } // } // Path: reladomo-tour/tour-examples/auditonly-bank/src/test/java/auditonlybank/api/AuditOnlyChainingInAction.java import java.nio.file.Path; import java.sql.Timestamp; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import auditonlybank.domain.Customer; import auditonlybank.domain.CustomerAccount; import auditonlybank.domain.CustomerAccountFinder; import auditonlybank.util.DateUtils; import com.gs.fw.common.mithra.MithraManagerProvider; import com.gs.fw.common.mithra.MithraTransaction; import com.gs.fw.common.mithra.finder.Operation; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; import com.gs.fw.common.mithra.util.dbextractor.DbExtractor; import org.junit.Before; import org.junit.Test; import java.nio.file.Files; private void updateBalance(String date, int accountId, int deposit) { MithraManagerProvider.getMithraManager().executeTransactionalCommand(tx -> { // We set the processing time to simulate the update opening on a specific date - Do not do this in production doNotDoThisInProduction(date, tx); Operation id = CustomerAccountFinder.accountId().eq(accountId); CustomerAccount account = CustomerAccountFinder.findOne(id); account.setBalance(account.getBalance() + deposit); return null; }); } /* This test relies on an account that has been loaded into memory via the test data file. See the test setup for details. */ @Test public void run2() throws Exception { int accountId = 5678; balanceAsOfJan1(accountId); balanceAsOfJan20(accountId); balanceAsOfJan25(accountId); balanceAsOfJan17(accountId); } private void balanceAsOfJan1(int accountId) {
Timestamp date = DateUtils.parse("2017-01-01");
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesCrud.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManager; import kata.domain.Customer; import kata.domain.CustomerFinder; import kata.domain.CustomerList; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesCrud extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Customer.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get customer with a particular ID.
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesCrud.java import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManager; import kata.domain.Customer; import kata.domain.CustomerFinder; import kata.domain.CustomerList; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesCrud extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Customer.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get customer with a particular ID.
public Customer getCustomer(int customerId)
goldmansachs/reladomo-kata
main-kata/src/test/java/kata/test/ExercisesCrud.java
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // }
import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManager; import kata.domain.Customer; import kata.domain.CustomerFinder; import kata.domain.CustomerList; import org.junit.Assert; import org.junit.Test;
/* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesCrud extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Customer.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get customer with a particular ID. public Customer getCustomer(int customerId) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Customer customer = this.getCustomer(0); Assert.assertEquals("Hiro Tanaka", customer.getName()); Assert.assertEquals("JPN", customer.getCountry()); } //---------- Question 2 ----------------------------------------------------- // Get all customers from a particular country // // Quiz: At which point does mithra actually evaluate the list by going to the database? // Is it when you create the list or when you use it? // Answer: Only when you use it. This typically means when you call .get(), .iterator(), .size(), // but there are a couple other methods that will also cause the fetch query to be executed. // Feel free to experiment to see how this works
// Path: main-kata/src/main/java/kata/domain/Customer.java // public class Customer // extends CustomerAbstract // { // public Customer() // { // super(); // // You must not modify this constructor. Mithra calls this internally. // // You can call this constructor. You can also add new constructors. // } // // // Added as a convenience, particularly for ExercisesCrud questions 4, 7, & 8 // public Customer(final String name, final String country) // { // this(); // this.setName(name); // this.setCountry(country); // } // // @Override // public String toString() // { // return "Customer[id=" + this.getCustomerId() + "; name=" + this.getName() + "; country=" + this.getCountry() + ']'; // } // } // // Path: main-kata/src/main/java/kata/domain/CustomerList.java // public class CustomerList // extends CustomerListAbstract // { // public CustomerList() // { // super(); // } // // public CustomerList(int initialSize) // { // super(initialSize); // } // // public CustomerList(Collection c) // { // super(c); // } // // public CustomerList(Operation operation) // { // super(operation); // } // } // Path: main-kata/src/test/java/kata/test/ExercisesCrud.java import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.primitive.IntSet; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.test.Verify; import org.eclipse.collections.impl.tuple.Tuples; import com.gs.fw.common.mithra.MithraManager; import kata.domain.Customer; import kata.domain.CustomerFinder; import kata.domain.CustomerList; import org.junit.Assert; import org.junit.Test; /* Copyright 2018 Goldman Sachs. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package kata.test; public class ExercisesCrud extends AbstractMithraTest { @Override protected String[] getTestDataFilenames() { return new String[]{"testdata/data_Customer.txt"}; // Look into this file to see the test data being used } //-------------- Question 1 ------------------------------------------------------ // Get customer with a particular ID. public Customer getCustomer(int customerId) { Assert.fail("Implement this functionality to make the test pass"); return null; } @Test public void testQ1() { Customer customer = this.getCustomer(0); Assert.assertEquals("Hiro Tanaka", customer.getName()); Assert.assertEquals("JPN", customer.getCountry()); } //---------- Question 2 ----------------------------------------------------- // Get all customers from a particular country // // Quiz: At which point does mithra actually evaluate the list by going to the database? // Is it when you create the list or when you use it? // Answer: Only when you use it. This typically means when you call .get(), .iterator(), .size(), // but there are a couple other methods that will also cause the fetch query to be executed. // Feel free to experiment to see how this works
public CustomerList getCustomersFrom(String country)
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/vocabulary/WARCWordDistribution.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.InputFormat; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import java.util.StringTokenizer;
/* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.vocabulary; /** * @author Omnia Zayed */ public class WARCWordDistribution extends WordDistributionStatisticsCollector { @Override Class<? extends InputFormat> getInputFormatClass() { return WARCInputFormat.class; } @Override Class<? extends Mapper> getMapperClass() { return TokenizerMapper.class; } public static void main(String[] args) throws Exception { ToolRunner.run(new WARCWordDistribution(), args); } public static class TokenizerMapper
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/vocabulary/WARCWordDistribution.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.InputFormat; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import java.util.StringTokenizer; /* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.vocabulary; /** * @author Omnia Zayed */ public class WARCWordDistribution extends WordDistributionStatisticsCollector { @Override Class<? extends InputFormat> getInputFormatClass() { return WARCInputFormat.class; } @Override Class<? extends Mapper> getMapperClass() { return TokenizerMapper.class; } public static void main(String[] args) throws Exception { ToolRunner.run(new WARCWordDistribution(), args); } public static class TokenizerMapper
extends Mapper<LongWritable, WARCWritable, Text, IntWritable>
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/WordCounterExample.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List;
/* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.examples; /** * Example how to read processed data with the famous Hadoop word counter * * @author Ivan Habernal */ public class WordCounterExample extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Configuration conf = getConf(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job = Job.getInstance(); job.setJarByClass(WordCounterExample.class); job.setJobName(WordCounterExample.class.getName()); // mapper job.setMapperClass(WordCounterMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/WordCounterExample.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; /* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.examples; /** * Example how to read processed data with the famous Hadoop word counter * * @author Ivan Habernal */ public class WordCounterExample extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Configuration conf = getConf(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job = Job.getInstance(); job.setJarByClass(WordCounterExample.class); job.setJobName(WordCounterExample.class.getName()); // mapper job.setMapperClass(WordCounterMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer
job.setCombinerClass(TextLongCountingReducer.class);
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/WordCounterExample.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List;
job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer job.setCombinerClass(TextLongCountingReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new WordCounterExample(), args); } /** * Reads "boilerplated" text (can contain "minimal html") emits token counts */ static class WordCounterMapper
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/WordCounterExample.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.List; job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer job.setCombinerClass(TextLongCountingReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new WordCounterExample(), args); } /** * Reads "boilerplated" text (can contain "minimal html") emits token counts */ static class WordCounterMapper
extends Mapper<LongWritable, WARCWritable, Text, LongWritable>
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/ContentTypeAndSizeDistribution.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics; /** * Document length distribution over content type and charset (mixed in one output) * * @author Ivan Habernal */ public class ContentTypeAndSizeDistribution extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); job.setJarByClass(ContentTypeAndSizeDistribution.class); job.setJobName(ContentTypeAndSizeDistribution.class.getName()); // mapper job.setMapperClass(ContentAndSizeMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // reducer // job.setReducerClass(DistributionReducer.class);
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/ContentTypeAndSizeDistribution.java import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; /* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics; /** * Document length distribution over content type and charset (mixed in one output) * * @author Ivan Habernal */ public class ContentTypeAndSizeDistribution extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); job.setJarByClass(ContentTypeAndSizeDistribution.class); job.setJobName(ContentTypeAndSizeDistribution.class.getName()); // mapper job.setMapperClass(ContentAndSizeMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // reducer // job.setReducerClass(DistributionReducer.class);
job.setReducerClass(TextLongCountingReducer.class);
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/ContentTypeAndSizeDistribution.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
/* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics; /** * Document length distribution over content type and charset (mixed in one output) * * @author Ivan Habernal */ public class ContentTypeAndSizeDistribution extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); job.setJarByClass(ContentTypeAndSizeDistribution.class); job.setJobName(ContentTypeAndSizeDistribution.class.getName()); // mapper job.setMapperClass(ContentAndSizeMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // reducer // job.setReducerClass(DistributionReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = args[0]; String outputPath = args[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new ContentTypeAndSizeDistribution(), args); } /** * Mapper; omits ContentType and size */ public static class ContentAndSizeMapper
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/ContentTypeAndSizeDistribution.java import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; /* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics; /** * Document length distribution over content type and charset (mixed in one output) * * @author Ivan Habernal */ public class ContentTypeAndSizeDistribution extends Configured implements Tool { @Override public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); job.setJarByClass(ContentTypeAndSizeDistribution.class); job.setJobName(ContentTypeAndSizeDistribution.class.getName()); // mapper job.setMapperClass(ContentAndSizeMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // reducer // job.setReducerClass(DistributionReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = args[0]; String outputPath = args[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new ContentTypeAndSizeDistribution(), args); } /** * Mapper; omits ContentType and size */ public static class ContentAndSizeMapper
extends Mapper<LongWritable, WARCWritable, Text, LongWritable>
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/SimpleTextSearch.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;
/* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.examples; /** * Example how to search for a given regex in the processed C4Corpus * * @author Ivan Habernal */ public class SimpleTextSearch extends Configured implements Tool { public static final String MAPREDUCE_MAP_REGEX = "mapreduce.map.search.regex"; @Override public int run(String[] args) throws Exception { Configuration conf = getConf(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job = Job.getInstance(); job.setJarByClass(SimpleTextSearch.class); job.setJobName(SimpleTextSearch.class.getName()); // mapper job.setMapperClass(TextSearchMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/SimpleTextSearch.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /* * Copyright 2016 * Ubiquitous Knowledge Processing (UKP) Lab * Technische Universität Darmstadt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.examples; /** * Example how to search for a given regex in the processed C4Corpus * * @author Ivan Habernal */ public class SimpleTextSearch extends Configured implements Tool { public static final String MAPREDUCE_MAP_REGEX = "mapreduce.map.search.regex"; @Override public int run(String[] args) throws Exception { Configuration conf = getConf(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); Job job = Job.getInstance(); job.setJarByClass(SimpleTextSearch.class); job.setJobName(SimpleTextSearch.class.getName()); // mapper job.setMapperClass(TextSearchMapper.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); // combiner + reducer
job.setCombinerClass(TextLongCountingReducer.class);
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/SimpleTextSearch.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;
job.setCombinerClass(TextLongCountingReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; // regex with a phrase to be searched for String regex = otherArgs[2]; job.getConfiguration().set(MAPREDUCE_MAP_REGEX, regex); FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new SimpleTextSearch(), args); } /** * Reads clean text (can contain "minimal html") and emits occurrences of given patterns */ public static class TextSearchMapper
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/helper/TextLongCountingReducer.java // public class TextLongCountingReducer // extends Reducer<Text, LongWritable, Text, LongWritable> // { // @Override // protected void reduce(Text key, Iterable<LongWritable> values, Context context) // throws IOException, InterruptedException // { // long sum = 0; // for (LongWritable intWritable : values) { // sum += intWritable.get(); // } // // context.write(key, new LongWritable(sum)); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/examples/SimpleTextSearch.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.helper.TextLongCountingReducer; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; job.setCombinerClass(TextLongCountingReducer.class); job.setReducerClass(TextLongCountingReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; // regex with a phrase to be searched for String regex = otherArgs[2]; job.getConfiguration().set(MAPREDUCE_MAP_REGEX, regex); FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new SimpleTextSearch(), args); } /** * Reads clean text (can contain "minimal html") and emits occurrences of given patterns */ public static class TextSearchMapper
extends Mapper<LongWritable, WARCWritable, Text, LongWritable>
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/WARCRecordCounter.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // }
import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import java.util.Arrays;
job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); // combiner + reducer job.setCombinerClass(MyReducer.class); job.setReducerClass(MyReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new WARCRecordCounter(), args); } /** * Mapper; simply omits one for each entry (under the same key) */ public static class ResponseMapper
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/WARCRecordCounter.java import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCInputFormat; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import java.io.IOException; import java.util.Arrays; job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); // combiner + reducer job.setCombinerClass(MyReducer.class); job.setReducerClass(MyReducer.class); job.setInputFormatClass(WARCInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); // paths String commaSeparatedInputFiles = otherArgs[0]; String outputPath = otherArgs[1]; FileInputFormat.addInputPaths(job, commaSeparatedInputFiles); FileOutputFormat.setOutputPath(job, new Path(outputPath)); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new WARCRecordCounter(), args); } /** * Mapper; simply omits one for each entry (under the same key) */ public static class ResponseMapper
extends Mapper<LongWritable, WARCWritable, Text, IntWritable>
dkpro/dkpro-c4corpus
dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/LangLicenseStatistics.java
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // }
import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.ConfigurationHelper; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner;
public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); ConfigurationHelper .configureJob(job, LangLicenseStatistics.class, MapperClass.class, ReducerClass.class, args[0], args[1]); // intermediate data job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(MapWritable.class); // output data job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(Text.class); job.setOutputFormatClass(TextOutputFormat.class); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new LangLicenseStatistics(), args); } public static class MapperClass
// Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/io/WARCWritable.java // public class WARCWritable // implements Writable // { // // private WARCRecord record; // // /** // * Creates an empty writable (with a null record). // */ // public WARCWritable() // { // this.record = null; // } // // /** // * Creates a writable wrapper around a given WARCRecord. // * // * @param record existing record // */ // public WARCWritable(WARCRecord record) // { // this.record = record; // } // // /** // * Returns the record currently wrapped by this writable. // * // * @return current record // */ // public WARCRecord getRecord() // { // return record; // } // // /** // * Updates the record held within this writable wrapper. // * // * @param record the record to be set // */ // public void setRecord(WARCRecord record) // { // this.record = record; // } // // /** // * Appends the current record to a {@link DataOutput} stream. // */ // @Override // public void write(DataOutput out) // throws IOException // { // if (record != null) { // record.write(out); // } // } // // /** // * Parses a {@link WARCRecord} out of a {@link DataInput} stream, and makes it the // * writable's current record. // * // * @throws IOException if the input is malformed // */ // @Override // public void readFields(DataInput in) // throws IOException // { // record = new WARCRecord(in); // } // } // Path: dkpro-c4corpus-hadoop/src/main/java/de/tudarmstadt/ukp/dkpro/c4corpus/hadoop/statistics/LangLicenseStatistics.java import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.ConfigurationHelper; import de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.io.WARCWritable; import de.tudarmstadt.ukp.dkpro.c4corpus.warc.io.WARCRecord; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.io.*; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public int run(String[] args) throws Exception { Job job = Job.getInstance(getConf()); ConfigurationHelper .configureJob(job, LangLicenseStatistics.class, MapperClass.class, ReducerClass.class, args[0], args[1]); // intermediate data job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(MapWritable.class); // output data job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(Text.class); job.setOutputFormatClass(TextOutputFormat.class); return job.waitForCompletion(true) ? 0 : 1; } public static void main(String[] args) throws Exception { ToolRunner.run(new LangLicenseStatistics(), args); } public static class MapperClass
extends Mapper<LongWritable, WARCWritable, Text, MapWritable>