id
stringlengths
36
36
text
stringlengths
1
1.25M
5d8c6899-24e3-4945-93da-f753bee33720
public SalariedEmployee(String fname, String lname, double salary, int empID){ this.firstName = fname; this.lastName = lname; this.salary = salary; this.empID = empID; }
9d972be7-13b8-429d-ab80-960745291a8c
public String getFirstName(){ return this.firstName; }
4b07e8c8-ca70-4d5c-b6b0-63bfce7a4454
public void setFirstName(String firstName){ this.firstName = firstName; }
48cdb3ea-92ce-4755-9e9c-927537cd7e09
public String getLastName(){ return this.lastName; }
ae352c12-a2e4-4b40-a511-b6b89342fcfe
public void setLastName(String lastName){ this.lastName = lastName; }
0d3d0bbe-1530-4894-8468-64c70eb1c2a9
public void setEmpID(int empID){ this.empID = empID; }
63c4209c-af21-480c-b50d-d2885561f976
public int getEmpID(){ return this.empID; }
4a82c747-0fb7-41a2-92a9-e6b6a23918bf
public double getYearlyPay(){ return salary; }
df758d20-9cad-497d-b352-46f5dedea4c2
@Override public String toString(){ return super.toString() + "\rAnnual salary: $" + this.salary; }
b478f7bf-652f-4e66-8c7a-1f1e6e710a56
public HourlyEmployee(String fname, String lname, double pay, double hours, int empID){ this.firstName = fname; this.lastName = lname; this.empID = empID; this.hourlyRate = pay; this.weeklyHours = hours; }
09e93311-7a01-420b-9b0d-e1bec895c01e
public String getFirstName(){ return this.firstName; }
7ed2e013-5872-44fa-81c7-dcac52fc15d0
public void setFirstName(String firstName){ this.firstName = firstName; }
5778efb7-86b4-4bba-9b1a-07962098db73
public String getLastName(){ return this.lastName; }
6a9479f9-c1a5-48a6-96fd-1e662a9c5412
public void setLastName(String lastName){ this.lastName = lastName; }
1646ca72-3f3f-4f34-b00b-13eddb8322fd
public void setEmpID(int empID){ this.empID = empID; }
9642e6de-9bf1-4550-a70a-fa4e4f1f1284
public int getEmpID(){ return this.empID; }
122b8c69-fd8f-4529-8f93-51d2c97c9bfb
public double getYearlyPay(){ return (hourlyRate * weeklyHours) * 52; }
8e2efe12-5ae4-4b21-a2a6-5f9af7f6a0c6
@Override public String toString(){ return super.toString() + "\rHourly rate: " + this.hourlyRate + "\rHours per week: " + this.weeklyHours; }
1cddbe0a-732e-44a0-93f8-56324f7cbcf6
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWithoutXCoordinate() { new Rover(null, 3, "S"); }
093d8d4c-3861-4567-93e7-0236917d6cfc
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWithoutYCoordinate() { new Rover(3, null, "S"); }
feb9f5cb-3529-43b4-9c03-1e70c994742c
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWithoutDirection() { new Rover(3, 3, null); }
11524249-4b06-4b16-b637-24519659eca5
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWhenXCoordinateIsNegative() { new Rover(-3, 3, "S"); }
9ed05c36-2d44-4c54-90a0-0b0be8268e30
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWhenYCoordinateIsNegative() { new Rover(3, -3, "S"); }
34413522-7d91-4d35-a2ac-719f98c68d8f
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWhenXCoordinateIsOver9() { new Rover(11, 3, "S"); }
8a89c7bc-3365-48d4-88fc-cf71e03d0622
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWhenYCoordinateIsOver9() { new Rover(3, 11, "S"); }
33792316-79e3-4506-a4f5-528169428aa5
@Test(expected=IllegalArgumentException.class) public void testRoverShouldNotBeInitialisedWhenDirectionIsNotNESW() { new Rover(3, 3, "UNKNOWNDIRECTION"); }
9ffa0ad2-c54c-4209-81e7-93defc6ba129
@Test public void testRoverShouldBeInitialised() { Rover rover = new Rover(3, 9, "W"); assertEquals(rover.getX(), new Integer(3)); }
5cef7266-cd51-4118-8d27-04bf0ce3c464
@Test public void testRoverCannotMoveWhenFacingWestAtPoint00() { Rover rover = new Rover(0, 0, "W"); rover.move(); assertEquals(rover.getX(), new Integer(0)); assertEquals(rover.getY(), new Integer(0)); assertEquals(rover.getDirection(), "W"); }
6d2162cf-8b38-4f6f-978b-c371859727d3
@Test public void testRoverCannotMoveWhenFacingSouthAtPoint00() { Rover rover = new Rover(0, 0, "S"); rover.move(); assertEquals(rover.getX(), new Integer(0)); assertEquals(rover.getY(), new Integer(0)); assertEquals(rover.getDirection(), "S"); }
2559ca91-fdbd-4fa1-a5c2-847c3cc8831f
@Test public void testRoverCannotMoveWhenFacingWestAtPoint09() { Rover rover = new Rover(0, 9, "W"); rover.move(); assertEquals(rover.getX(), new Integer(0)); assertEquals(rover.getY(), new Integer(9)); assertEquals(rover.getDirection(), "W"); }
576492bc-ab3a-449e-b3a6-0b832dd2580b
@Test public void testRoverCannotMoveWhenFacingNorthAtPoint09() { Rover rover = new Rover(0, 9, "N"); rover.move(); assertEquals(rover.getX(), new Integer(0)); assertEquals(rover.getY(), new Integer(9)); assertEquals(rover.getDirection(), "N"); }
8896d7f2-a377-4256-b703-e74107230023
@Test public void testRoverCannotMoveWhenFacingEastAtPoint90() { Rover rover = new Rover(9, 0, "E"); rover.move(); assertEquals(rover.getX(), new Integer(9)); assertEquals(rover.getY(), new Integer(0)); assertEquals(rover.getDirection(), "E"); }
857494d0-e8a2-4961-9149-eaa9758fbe9b
@Test public void testRoverCannotMoveWhenFacingSouthAtPoint90() { Rover rover = new Rover(9, 0, "S"); rover.move(); assertEquals(rover.getX(), new Integer(9)); assertEquals(rover.getY(), new Integer(0)); assertEquals(rover.getDirection(), "S"); }
f2c8b204-708a-4909-a544-907ff0918654
@Test public void testRoverCannotMoveWhenFacingEastAtPoint99() { Rover rover = new Rover(9, 9, "E"); rover.move(); assertEquals(rover.getX(), new Integer(9)); assertEquals(rover.getY(), new Integer(9)); assertEquals(rover.getDirection(), "E"); }
d88251b4-12e1-4138-b81a-48d5c1026dbf
@Test public void testRoverCannotMoveWhenFacingNorthAtPoint99() { Rover rover = new Rover(9, 9, "N"); rover.move(); assertEquals(rover.getX(), new Integer(9)); assertEquals(rover.getY(), new Integer(9)); assertEquals(rover.getDirection(), "N"); }
9ca2c34e-77d5-450b-b4ca-bc4644b9bcc8
@Test public void testRoverCanMoveWhenFacingNorthAtPoint35() { Rover rover = new Rover(3, 5, "N"); rover.move(); assertEquals(rover.getX(), new Integer(3)); assertEquals(rover.getY(), new Integer(6)); assertEquals(rover.getDirection(), "N"); }
a7f08462-c734-4a6e-add8-22338bd040fd
@Test(expected=IllegalArgumentException.class) public void testRoverCannotChangeDirectionWhenInstructionIsNull() { new Rover(3, 5, "N").changeDirection(null); }
11c0d29f-9ad0-4965-a396-f0f731c2dbaf
@Test(expected=IllegalArgumentException.class) public void testRoverCannotChangeDirectionWhenInstructionIsNotLorR() { new Rover(3, 5, "N").changeDirection("WRONG"); }
f6094402-7e3b-4ce2-ac42-f6492c574f58
@Test public void testRoverCanChangeDirectionFromNtoWWhenInstructionL() { Rover rover = new Rover(3, 5, "N"); rover.changeDirection("L"); assertEquals(rover.getDirection(), "W"); }
e3e1b1ea-4953-45a9-b72d-227672804fad
@Test public void testRoverCanChangeDirectionFromEtoNWhenInstructionL() { Rover rover = new Rover(3, 5, "E"); rover.changeDirection("L"); assertEquals(rover.getDirection(), "N"); }
bc9a7e01-2858-4de5-ab6b-2d3819c6b3cc
@Test public void testRoverCanChangeDirectionFromStoEWhenInstructionL() { Rover rover = new Rover(3, 5, "S"); rover.changeDirection("L"); assertEquals(rover.getDirection(), "E"); }
4338ef62-6130-4da3-961a-8bffae4733e6
@Test public void testRoverCanChangeDirectionFromWtoSWhenInstructionL() { Rover rover = new Rover(3, 5, "W"); rover.changeDirection("L"); assertEquals(rover.getDirection(), "S"); }
8491c6f5-98fa-45b6-a2ec-260ac822fba8
@Test public void testRoverCanChangeDirectionFromNtoEWhenInstructionR() { Rover rover = new Rover(3, 5, "N"); rover.changeDirection("R"); assertEquals(rover.getDirection(), "E"); }
e1c4963e-9416-41e9-9c3f-6c9aa3ecb9f4
@Test public void testRoverCanChangeDirectionFromEtoSWhenInstructionR() { Rover rover = new Rover(3, 5, "E"); rover.changeDirection("R"); assertEquals(rover.getDirection(), "S"); }
90657054-631a-4271-914d-5d1242b3904d
@Test public void testRoverCanChangeDirectionFromStoWWhenInstructionR() { Rover rover = new Rover(3, 5, "S"); rover.changeDirection("R"); assertEquals(rover.getDirection(), "W"); }
9a73cba4-2c9f-4707-815c-a6f1cdeb3ff3
@Test public void testRoverCanChangeDirectionFromWtoNWhenInstructionR() { Rover rover = new Rover(3, 5, "W"); rover.changeDirection("R"); assertEquals(rover.getDirection(), "N"); }
9dbd56af-b3bd-494d-a717-db0e49005461
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerShouldNotBeInitialisedWhenLandingPositionIsNull() { new InstructionController(null, "LMMMRRM"); }
3ca030a0-ef2b-4fb4-989b-566901a459d7
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerShouldNotBeInitialisedWhenMovementPlannedIsNull() { new InstructionController("44N", null); }
f8b47675-508b-42a9-8ae7-53a029655af3
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerShouldNotBeInitialisedWhenLandingPositionIsEmpty() { new InstructionController("", "LMMMRRM"); }
bca8c16c-4af6-478d-809a-6a54635c6784
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerShouldNotBeInitialisedWhenLandingPositionIsTooLong() { new InstructionController("TOOLONG", "LMMMRRM"); }
58d5a93e-feaa-4159-91f6-b67572143c51
@Test public void testInstructionControllerShouldBeInitialised() { new InstructionController("44N", "LMMMRRM"); }
3209808e-3ba6-4aa8-9269-1cdd19b7c4b6
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerCannotLandTheRoverWhenLandingPositionIsWrong() { InstructionController controller = new InstructionController("09F", "LMMMRRM"); controller.landTheRover(); }
3b6f8df7-dfa3-44a8-8b2b-1904104e2ac2
@Test public void testInstructionControllerCanLandTheRoverWhenLandingPositionIsCorrect() { InstructionController controller = new InstructionController("99S", "LMMMRRM"); controller.landTheRover(); }
eb31fef2-46a9-4f4e-8ee2-565c42e91e88
@Test public void testInstructionControllerCanReportRoversPositonWhenRoverIsNotLanded() { InstructionController controller = new InstructionController("99S", "LMMMRRM"); String actual_position = controller.reportPosition(); String expected_position = "The rover has landed yet."; assertEquals(expected_position, actual_position); }
a7a3d845-4d74-4283-b222-1f0ec90bec31
@Test public void testInstructionControllerCanReportRoversPositonWhenRoverIsLanded() { InstructionController controller = new InstructionController("99S", "LMMMRRM"); controller.landTheRover(); String actual_position = controller.reportPosition(); String expected_position = "Rover [x=9, y=9, direction=S]"; assertEquals(expected_position, actual_position); }
768faa79-4922-4370-8eeb-eb05a903557a
@Test public void testInstructionControllerCanNotPerformMovementWhenRoverIsNotLanded() { InstructionController controller = new InstructionController("44N", "LMMMRRM"); controller.performMovement(); String actual_position = controller.reportPosition(); String expected_position = "The rover has landed yet."; assertEquals(expected_position, actual_position); }
29b3b0cd-f7dc-41fd-922f-afd1d25ed63e
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerCanNotPerformMovementWhenmovementPlannedIsWrong() { InstructionController controller = new InstructionController("44N", "LMMMRRMH"); controller.landTheRover(); controller.performMovement(); }
ebe7c5d9-d806-4cb5-9939-c60d6f7975ce
@Test(expected=IllegalArgumentException.class) public void testInstructionControllerShouldNotBeInitialisedWhenMovementPlanIsInValid() { InstructionController controller = new InstructionController("44N", "097s*@$&;lsdfSDF"); controller.landTheRover(); controller.performMovement(); }
50c0de33-f15b-49af-8bdc-e9b654a24aee
@Test public void testInstructionControllerCanPerformMovementWhenmovementPlannedIsCorrect() { InstructionController controller = new InstructionController("44N", "LMMMRRM"); controller.landTheRover(); controller.performMovement(); String actual_position = controller.reportPosition(); String expected_position = "Rover [x=2, y=4, direction=E]"; assertEquals(expected_position, actual_position); }
217bfdaf-85b4-40e2-8d93-7693600b23a3
@Test public void testInstructionControllerCanPerformMovementWhenLandedAt99SAndPlanIsMMMRMMMLMM() { InstructionController controller = new InstructionController("99S", "MMMRMMMLMM"); controller.landTheRover(); controller.performMovement(); String actual_position = controller.reportPosition(); String expected_position = "Rover [x=6, y=4, direction=S]"; assertEquals(expected_position, actual_position); }
9086be01-c9ab-4416-bcf2-a189dac3080f
@Test public void testInstructionControllerCannotPerformMovementWhenLandedAt00SAndPlanIsMMMMM() { InstructionController controller = new InstructionController("00S", "MMMMMM"); controller.landTheRover(); controller.performMovement(); String actual_position = controller.reportPosition(); String expected_position = "Rover [x=0, y=0, direction=S]"; assertEquals(expected_position, actual_position); }
d53be42c-a76e-45ad-b6af-10d4116af257
public Rover(Integer x, Integer y, String direction) { super(); if (x == null) { throw new IllegalArgumentException("X co-ordinate can't be NULL"); } if (x < this.minBorder || x > this.maxBorder) { throw new IllegalArgumentException("X co-ordinate must be within 0 - 9"); } if (y == null) { throw new IllegalArgumentException("Y co-ordinate can't be NULL"); } if (y < this.minBorder || y > this.maxBorder) { throw new IllegalArgumentException("Y co-ordinate must be within 0 - 9"); } if (direction == null || direction.isEmpty()) { throw new IllegalArgumentException("Direction can't be NULL or Empty"); } Set<String> directions = new HashSet<String>(Arrays.asList(new String[]{ "N", "E", "S", "W" })); if (!directions.contains(direction)) { throw new IllegalArgumentException("Direction (case sensitive) must be in " + directions); } this.x = x; this.y = y; this.direction = direction; initDirDelTa(); initMappings(); }
de522f5c-6052-4a53-97fe-57ce61498863
public void move() { Integer[] deltas = this.dirDelta.get(this.direction); this.x += deltas[0]; this.y += deltas[1]; verifyWithBorder(deltas); }
303b18a6-1fbf-4ce3-b0a2-39f359ca68bd
public void changeDirection(String instruction) { Set<String> instructions = new HashSet<String>(Arrays.asList(new String[]{ "L", "R" })); if (instruction == null) { throw new IllegalArgumentException("Instruction can't be NULL"); } else if (!instructions.contains(instruction)) { throw new IllegalArgumentException("Direction (case sensitive) must be in " + instructions); } Integer degree = this.dirToDegree.get(this.direction) + this.dirToDegree.get(instruction); if (degree >= 360) { degree -= 360; } else if (degree < 0) { degree += 360; } this.direction = this.degreeToDir.get(degree); }
79e9705a-afe2-4748-9c20-6cf40495e819
public Integer getX() { return x; }
f7e4f02c-844f-4398-81bc-b5d613173968
public Integer getY() { return y; }
85a2411a-dd16-4532-8966-e976e3e3dd92
public String getDirection() { return direction; }
2ff1b3fe-5c68-4b90-b658-bd1b628d3747
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((direction == null) ? 0 : direction.hashCode()); result = prime * result + ((x == null) ? 0 : x.hashCode()); result = prime * result + ((y == null) ? 0 : y.hashCode()); return result; }
4c9a44cd-22e2-4e3a-8f5c-93fd3d0f41c8
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Rover other = (Rover) obj; if (direction == null) { if (other.direction != null) return false; } else if (!direction.equals(other.direction)) return false; if (x == null) { if (other.x != null) return false; } else if (!x.equals(other.x)) return false; if (y == null) { if (other.y != null) return false; } else if (!y.equals(other.y)) return false; return true; }
527e0d65-11cd-4135-bb0d-873513ca6de2
@Override public String toString() { return "Rover [x=" + x + ", y=" + y + ", direction=" + direction + "]"; }
4d18268b-7532-4151-808e-f6f096bacf12
private void initDirDelTa() { this.dirDelta = new HashMap<String, Integer[]>(); this.dirDelta.put("N", new Integer[]{0, 1}); this.dirDelta.put("S", new Integer[]{0, -1}); this.dirDelta.put("W", new Integer[]{-1, 0}); this.dirDelta.put("E", new Integer[]{1, 0}); }
d8ecb78d-17c2-4653-95fa-56f368d867d0
private void verifyWithBorder(Integer[] delta) { if (this.x < this.minBorder || this.x > this.maxBorder || this.y < this.minBorder || this.y > this.maxBorder) { System.out.println("Cannot move when the position is " + this.toString()); this.x -= delta[0]; this.y -= delta[1]; } }
c73ddb04-4777-46aa-8bde-5b3eaf38c2bf
private void initMappings() { this.dirToDegree = new HashMap<String, Integer>(); this.dirToDegree.put("N", 0); this.dirToDegree.put("E", 90); this.dirToDegree.put("S", 180); this.dirToDegree.put("W", 270); this.dirToDegree.put("L", -90); this.dirToDegree.put("R", 90); this.degreeToDir = new HashMap<Integer, String>(); this.degreeToDir.put(0, "N"); this.degreeToDir.put(90, "E"); this.degreeToDir.put(180, "S"); this.degreeToDir.put(270, "W"); }
c9f7313a-78c1-4d0b-8e23-184553d4a012
public static void main(String[] args) { Scanner userInput = new Scanner(System.in); String landingPosition = null; System.out.print("Enter rover's landing position: "); landingPosition = userInput.next(); String movementPlanned = null; System.out.print("Enter rover's movement planed: "); movementPlanned = userInput.next(); InstructionController controller = new InstructionController(landingPosition, movementPlanned); System.out.println("OK. The rover is landing .. "); controller.landTheRover(); System.out.println("Landed. Rover is moving ..."); controller.performMovement(); System.out.println("Finished. Rover is at " + controller.reportPosition()); }
b0714384-89ec-422f-800e-222ffac5d7d3
public InstructionController(String landingPosition, String movementPlanned) { super(); if (landingPosition == null ) { throw new IllegalArgumentException("Landing Position can't be NULL"); } if (landingPosition.length() != 3) { throw new IllegalArgumentException("Landing Position must be in the format of XYD, e.g. 44N"); } if (movementPlanned == null ) { throw new IllegalArgumentException("Movement Plan can't be NULL"); } this.landingPosition = landingPosition; this.movementPlanned = movementPlanned; }
9a5bddc6-e045-4bba-8967-4ad5b88fd3aa
public void landTheRover() { String[] landingInfo = this.landingPosition.toUpperCase().split("(?!^)"); Integer x = Integer.valueOf(landingInfo[0]); Integer y = Integer.valueOf(landingInfo[1]); String direction = landingInfo[2]; this.rover = new Rover(x, y, direction); }
2517bb7a-d0c9-4b38-a719-cdb81ec2160c
public String reportPosition() { if (this.rover == null) { return "The rover has landed yet."; } else { return this.rover.toString(); } }
6e7853bf-ca3a-43fa-a5ae-9eece3c3d01d
public void performMovement() { if (this.rover == null) { System.out.println("Please land the rover first"); } else { String[] instructions = this.movementPlanned.toUpperCase().split("(?!^)"); for (String instruction : instructions) { if (instruction.equals("M")) { this.rover.move(); } else if (instruction.equals("R") || instruction.equals("L")) { this.rover.changeDirection(instruction); } else { throw new IllegalArgumentException("Movement Plan must in [M, R, L]"); } } } }
1f304a3d-9eb6-4f56-8afd-afb488369428
protected MyKV() throws RemoteException { System.out.println(new Date() + " Initializing Node"); }
824ad7b3-81a7-4593-ac94-3eb529ee58fe
public static void main(String[] args) { if(args.length >= 1 && !args[0].equals("${ServiceName}")) { ServiceName = args[0]; } else { ServiceName = DEFAULT_SERVICE_NAME; } Registry reg = establishRegistry(); try { MyKV myKV = new MyKV(); reg.rebind(ServiceName, myKV); // Bind object System.out.println(new Date() + " Registered with registry"); } catch (RemoteException e) { System.out.println(new Date() + " Error: " + e); } // try NetworkInterface ni; try { ni = NetworkInterface.getByName("net4"); Node me = new Node(KEYLENGTH); // String address = ni.getInetAddresses().nextElement().getHostAddress(); // String address1 = ni.getInetAddresses().nextElement().getHostAddress(); me.setIP(getIPAdressOfNic("net4")); me.setPort(port); me.setServiceName(ServiceName); System.out.println(new Date() + " created me {"); System.out.println(new Date() + " \t IP: " + me.getIP()); System.out.println(new Date() + " \t Port: " + me.getPort()); System.out.println(new Date() + " \t ServiceName: " + me.getServiceName()); System.out.println(new Date() + " \t ChordIdentifier: " + me.getChordIdentifier()); System.out.println(new Date() + " }"); myKV = new KV(me, KEYLENGTH); } catch (SocketException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (args.length >= 1 && !args[1].equals("${NodeIP:Port}")) { ConnectionURI = args[1]; Join(new Node(ConnectionURI.split(":")[0], Integer.parseInt(ConnectionURI.split(":")[1]), KEYLENGTH)); } else { Join(null); } }
057ea182-5765-4023-8d08-0af798652677
private static String getIPAdressOfNic(String NIC_Name) { String IP = null; try { NetworkInterface ni = NetworkInterface.getByName(NIC_Name); Enumeration<InetAddress> addresses = ni.getInetAddresses(); while (addresses.hasMoreElements()){ InetAddress current_addr = addresses.nextElement(); if (current_addr.isLoopbackAddress() || !(current_addr instanceof Inet4Address)) continue; IP = current_addr.getHostAddress(); } } catch(Exception ex) { } return IP; }
9ef0a585-e689-4590-a99a-7f60bb581d73
private static Registry establishRegistry() { Registry reg = null; try { for (port = MIN_PORT_NUMBER; port <= MAX_PORT_NUMBER && !IsPortAvailable(port); port++); System.out.println(new Date() + " using port " + port); reg = LocateRegistry.createRegistry(port); } catch (IllegalArgumentException ae) { System.out.println(new Date() + " No ports avilable"); System.exit(0); } catch (RemoteException e) { try { reg = LocateRegistry.getRegistry(); } catch (RemoteException e2) { System.out.println(new Date() + " Registry could not be established" + e); System.exit(0); } // try-catch-e2 } // try-catch-e System.out.println(new Date() + " Registry established"); return reg; }
71a236d5-19d7-4796-a62c-3c448eed3dd7
private static void Join(Node nodeToJoinTo) { myKV.Join(nodeToJoinTo, ServiceName); }
99f4012c-e104-4994-b1f6-70830d95860a
public Node findSuccessor(long searchID) { System.out.println(new Date() + "Someone wants to get my successor"); return myKV.findSuccessor(searchID, ServiceName); }
fb8aacd8-9635-44d1-a261-618c04d383cf
public Node getClosestPrecedingFinger(long searchID) { System.out.println(new Date() + "Someone wants to get my Closest Preceding Finger"); return myKV.getClosestPrecedingFinger(searchID); }
ff0115c8-693c-4272-91d7-b19c9e8efaa0
public Node findPredecessor(long searchID) { System.out.println(new Date() + "Someone wants to get my Predecessor"); return myKV.findPredecessor(searchID, ServiceName); }
7b5d173e-9632-4611-b657-4dfd720cf301
public static boolean IsPortAvailable(int port) { if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) { throw new IllegalArgumentException("Invalid start port: " + port); } ServerSocket ss = null; DatagramSocket ds = null; try { ss = new ServerSocket(port); ss.setReuseAddress(true); ds = new DatagramSocket(port); ds.setReuseAddress(true); return true; } catch (IOException e) { } finally { if (ds != null) { ds.close(); } if (ss != null) { try { ss.close(); } catch (IOException e) { /* should not be thrown */ } } } return false; }
e3c5291f-9da0-4f50-a175-87d1a8aa2dc3
@Override public void updateFingerTable(Node newNode, int index) throws RemoteException { myKV.updateFingerTable(newNode, index, ServiceName); }
96328426-762a-4a3a-9708-08fb6dc88c4f
public Node findSuccessor(long l) throws RemoteException;
a15a5967-2001-4b37-8b09-d102b7fa62fe
public Node findPredecessor(long searchID) throws RemoteException;
e63753a3-0535-44a2-8fb2-605dcc23a32d
public Node getClosestPrecedingFinger(long searchID) throws RemoteException;
fcc5b307-b532-42b5-87af-3625bf27112a
public void updateFingerTable(Node newNode, int index) throws RemoteException;
9fd41d29-a7dd-4161-9d48-8e3e20ef1ea8
public FingerTable(int keysize) { this.entries = new ArrayList<FingerTableEntry>(); }
b0f0b6db-31e7-4a61-a32f-ff8e00c677d7
public void setSuccessor(FingerTableEntry fte) { if(entries.size() == 0) { entries.add(fte); } else { entries.set(0, fte); } }
6a95d403-6489-4c34-9f24-82bb5036baa7
public FingerTableEntry getSuccessor() { return entries.get(0); }
fb4d64e8-47d0-4233-85c6-7354b7212ca0
public FingerTableEntry get(int i) { return entries.get(i); }
18aa0833-9209-44df-8aea-1f8c0c04141a
public void setFingerTableEntry(FingerTableEntry fte, int index) { if(index < entries.size()) { entries.set(index, fte); } else { entries.add(fte); } }
92d5f42c-da3c-4bd5-be63-fcffbe85690e
public int length() { return entries.size(); }
1b182e39-8951-431b-857a-19a34b81eb2e
public MyValue(int keysize) { this.keysize = keysize; }
b8cd8742-0f5c-4c67-a516-9eadf19277ce
public MyValue(byte[] data) { this.setData(data); }