id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
4c72c0bc-c001-4334-aa16-f81c81bce53b
|
void save(Message message);
|
88707ba2-5f8e-4536-9541-d5df78baf75a
|
public void save(Message message) {
// TODO
}
|
5db79833-5a01-499f-bb5d-b44721b3e892
|
@RequestMapping(value = "/add", method = RequestMethod.POST,
produces = "application/json")
@ResponseBody
public Message addMessage(
@RequestParam(required = true) String text) throws Exception {
return messageManager.addMessage(text);
}
|
a28d178b-869f-4d31-8228-4c8c74825995
|
@RequestMapping(value = "/watch", method = RequestMethod.GET,
produces = "application/json")
@ResponseBody
public DeferredResult<Message> getNewMessage() throws Exception {
return messageManager.getNewMessage();
}
|
2010bf81-db01-4615-b98a-cfb339f072ce
|
@After("execution(* com.city81.redisPubSub.repository.MessageDao.save(..))")
public void interceptMessage(JoinPoint joinPoint) {
Message message = (Message) joinPoint.getArgs()[0];
// this publishes the message
this.redisTemplate.convertAndSend(channelName, message);
}
|
644eb98f-01db-4033-8936-53e4b4361dad
|
public static List<VirtualMachine> buildVirtualMachines(int[] vram, int[] vcpu) {
if(vram.length != vcpu.length) {
throw new IllegalArgumentException("vram array and vcpu array should have the same length");
}
List<VirtualMachine> vms = new ArrayList<>(vram.length);
for(int i=0; i<vram.length; i++) {
vms.add(new VirtualMachine("VM " + i, vram[i], vcpu[i]));
}
return vms;
}
|
c22d2c6b-1be5-4a20-85fe-c3f99a871c7c
|
public static List<ComputeServer> buildComputeServer(int[] ram, int[] cpu, int[] cost, int[] reliability) {
if(ram.length != cpu.length || ram.length != cost.length || cpu.length != cost.length) {
throw new IllegalArgumentException("ram array, cost array and cpu array should have the same length");
}
List<ComputeServer> servers = new ArrayList<>(ram.length);
for(int i=0; i<ram.length; i++) {
servers.add(new ComputeServer("Server " + i, ram[i], cpu[i], cost[i], reliability[i]));
}
return servers;
}
|
d077d9b1-0e1f-4066-860f-fbfc036c8ff5
|
public static Collection<VirtualMachine> findVmsOnServer(final ComputeServer server, final List<VirtualMachine> virtualMachines) {
return Collections2.filter(virtualMachines, new Predicate<VirtualMachine>() {
@Override
public boolean apply(VirtualMachine input) {
return input.getServer().equals(server);
}
});
}
|
277012ac-8ee0-48a2-a83a-85957479d841
|
@Override
public boolean apply(VirtualMachine input) {
return input.getServer().equals(server);
}
|
1d2a06c0-657f-4990-ba6c-7521e508c081
|
public static int sumVirtualMachinesCpu(Collection<VirtualMachine> virtualMachines) {
int sum = 0;
for(VirtualMachine vm : virtualMachines) {
sum += vm.getVcpu();
}
return sum;
}
|
f64eeb43-99e1-41e7-b2bf-7a11f230b3bb
|
public static int sumVirtualMachinesRam(Collection<VirtualMachine> virtualMachines) {
int sum = 0;
for(VirtualMachine vm : virtualMachines) {
sum += vm.getVram();
}
return sum;
}
|
ce452865-df05-4c27-92fd-c29b864bb699
|
@ValueRangeProvider(id = "computeServersRangeProvider")
public List<ComputeServer> getComputeServersList() {
return computeServers;
}
|
6bc48733-40c6-44f4-9f86-e5919b65da57
|
public void setComputeServersList(List<ComputeServer> computeServers) {
this.computeServers = computeServers;
}
|
96f705b6-a2c2-4491-af6f-1df30a511516
|
@PlanningEntityCollectionProperty
public List<VirtualMachine> getVirtualMachinesList() {
return virtualMachine;
}
|
8a0b8c75-ff1e-4ef3-a35e-df2ce7986ce1
|
public void setVirtualMachinesList(List<VirtualMachine> virtualMachine) {
this.virtualMachine = virtualMachine;
}
|
06072784-fa7d-46cc-bc21-0b054adf4886
|
public HardSoftScore getScore() {
return score;
}
|
0d30e4fe-6d79-4489-b277-980f4b87a479
|
public void setScore(HardSoftScore score) {
this.score = score;
}
|
85202735-98ab-4215-8520-d27849b3ee38
|
@Override
public Collection<? extends Object> getProblemFacts() {
List<ComputeServer> facts = new ArrayList<>();
facts.addAll(computeServers);
return facts;
}
|
d6dc72bd-7be3-49f0-b16e-3c87684b59dc
|
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (ComputeServer server : computeServers) {
builder.append("Server : ").append(server.getName()).append("\n");
Collection<VirtualMachine> vmsOnServer = Utils.findVmsOnServer(server, virtualMachine);
for (VirtualMachine vm : vmsOnServer) {
builder.append("VM : ").append(vm.getName()).append(" - ").append(vm.getVcpu()).append(" / ").append(vm.getVram());
builder.append("\n");
}
builder.append("Total CPU usage : " ).append(Utils.sumVirtualMachinesCpu(vmsOnServer)).append("/").append(server.getCpu()).append("\n");
builder.append("Total RAM usage : " ).append(Utils.sumVirtualMachinesRam(vmsOnServer)).append("/").append(server.getRam()).append("\n");
builder.append("Server cost : ").append(server.getCost()).append("\n");
builder.append("Server reliability : ").append(server.getReliability()).append("\n");
builder.append("================================================================================ \n");
}
return builder.toString();
}
|
6c37d1b6-66cd-417a-b496-53ca0f44b1b6
|
public VirtualMachine() {
}
|
f41235b6-ccc9-406c-8fa0-5b2726475cef
|
public VirtualMachine(String name, int vram, int vcpu) {
this.name = name;
this.vram = vram;
this.vcpu = vcpu;
}
|
4b468314-c250-43be-9c3c-019470596fd7
|
public String getName() {
return name;
}
|
31206455-2570-4765-b950-0d6ac70a131f
|
public void setName(String name) {
this.name = name;
}
|
078bceae-281a-499e-aa87-8af0a51f0ad3
|
public int getVram() {
return vram;
}
|
be7cc096-ed7e-4c63-a82f-130ea642ac9b
|
public void setVram(int vram) {
this.vram = vram;
}
|
f9160933-e657-4de9-a119-b50f327068c4
|
public int getVcpu() {
return vcpu;
}
|
29005bcd-0c9c-41da-a8ce-3cbd857f1ace
|
public void setVcpu(int vcpu) {
this.vcpu = vcpu;
}
|
9b133d9e-d22e-40f2-86b8-360c4bc9c2b7
|
@PlanningVariable(valueRangeProviderRefs = {"computeServersRangeProvider"})
public ComputeServer getServer() {
return server;
}
|
55041459-2ec0-4e1e-a08f-9cfe2804d38c
|
public void setServer(ComputeServer server) {
this.server = server;
}
|
6a09abe8-f001-48e2-87b4-5266584b5574
|
public ComputeServer(String name, int ram, int cpu, int cost, int reliability) {
this.name = name;
this.ram = ram;
this.cpu = cpu;
this.cost = cost;
this.reliability = reliability;
}
|
5a1534d8-c3bb-44e5-89cd-8b8fa3b6e852
|
public String getName() {
return name;
}
|
0260fcf4-4bed-4196-830a-84c2de341821
|
public void setName(String name) {
this.name = name;
}
|
4ecbb6b8-ea55-4d81-b4fd-f054ea7213a9
|
public int getRam() {
return ram;
}
|
9899d125-544e-4680-b136-5846dc18a25c
|
public void setRam(int ram) {
this.ram = ram;
}
|
0906b200-9a5d-42b5-9908-7dcda78557df
|
public int getCpu() {
return cpu;
}
|
6cb313c8-23d1-476b-9298-510c85f1472f
|
public void setCpu(int cpu) {
this.cpu = cpu;
}
|
91543a4b-cb58-4d5b-96fc-cb0ddbe24c52
|
public int getCost() {
return cost;
}
|
f41dd7db-70b5-4433-b7e6-c0772b4aca08
|
public void setCost(int cost) {
this.cost = cost;
}
|
e0981f56-9890-4754-ab17-ef25ecf67e21
|
public int getReliability() {
return reliability;
}
|
5510c1c8-a471-48fd-8fc3-d191d1593c39
|
public void setReliability(int reliability) {
this.reliability = reliability;
}
|
f1befb76-8d94-47ce-9702-2fe19627ddca
|
@Test
public void nominalTest() {
// Adapt
final int[] serversRam = { 32, 32, 32, 32 };
final int[] serversCpu = { 8, 8, 8, 8 };
final int[] serversAnnualCosts = { 100, 100, 250, 300 };
final int[] serversReliability = { 100, 100, 250, 300 };
final int[] vmsRam = { 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16 };
final int[] vmsCpu = { 1, 1, 1, 2, 2, 2, 2, 2, 2, 4, 4 };
List<VirtualMachine> vms = ComputeFactory.buildVirtualMachines(vmsRam, vmsCpu);
List<ComputeServer> servers = ComputeFactory.buildComputeServer(serversRam, serversCpu, serversAnnualCosts, serversReliability);
VirtualMachinesAssignment unsolvedVirtualMachinesAssignment = new VirtualMachinesAssignment();
unsolvedVirtualMachinesAssignment.setComputeServersList(servers);
unsolvedVirtualMachinesAssignment.setVirtualMachinesList(vms);
// Act
solver.solve(unsolvedVirtualMachinesAssignment);
VirtualMachinesAssignment solvedVirtualMachinesAssignments = (VirtualMachinesAssignment) solver.getBestSolution();
// Assert
assertTrue(solvedVirtualMachinesAssignments.getScore().isFeasible());
for (VirtualMachine vm : solvedVirtualMachinesAssignments.getVirtualMachinesList()) {
assertNotNull(vm.getServer());
}
for (final ComputeServer server : solvedVirtualMachinesAssignments.getComputeServersList()) {
Collection<VirtualMachine> vmsOnServer = Utils.findVmsOnServer(server, solvedVirtualMachinesAssignments.getVirtualMachinesList());
int usedRam = Utils.sumVirtualMachinesRam(vmsOnServer);
int usedCpu = Utils.sumVirtualMachinesCpu(vmsOnServer);
assertTrue(usedRam <= server.getRam());
assertTrue(usedCpu <= server.getCpu());
}
System.out.println(solvedVirtualMachinesAssignments);
}
|
3f32d586-4336-49f2-aa6f-305ed1c0c77e
|
@Test
public void testComputePacking_surcontrainte_ram() {
final int[] serversRam = { 32, 32, 32, 32 };
final int[] serversCpu = { 8, 8, 8, 8 };
final int[] serversAnnualCosts = { 100, 100, 250, 300 };
final int[] serversReliability = { 25, 25, 50, 100 };
final int[] vmsRam = { 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 8, 8, 8, 16, 16, 32, 32 };
final int[] vmsCpu = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4 };
List<VirtualMachine> vms = ComputeFactory.buildVirtualMachines(vmsRam, vmsCpu);
List<ComputeServer> servers = ComputeFactory.buildComputeServer(serversRam, serversCpu, serversAnnualCosts, serversReliability);
SolverFactory solverFactory = SolverFactory.createFromXmlResource("virtualMachinesAssignmentSolverConfig.xml");
Solver solver = solverFactory.buildSolver();
VirtualMachinesAssignment unsolvedVirtualMachinesAssignment = new VirtualMachinesAssignment();
unsolvedVirtualMachinesAssignment.setComputeServersList(servers);
unsolvedVirtualMachinesAssignment.setVirtualMachinesList(vms);
// Act
solver.solve(unsolvedVirtualMachinesAssignment);
VirtualMachinesAssignment solvedVirtualMachinesAssignments = (VirtualMachinesAssignment) solver.getBestSolution();
assertFalse(solvedVirtualMachinesAssignments.getScore().isFeasible());
}
|
816fd301-9629-4d48-acb0-37c091e3eafe
|
@Test
public void testComputePacking_surcontrainte_cpu() {
final int[] serversRam = { 32, 32, 32, 32 };
final int[] serversCpu = { 8, 8, 8, 8 };
final int[] serversAnnualCosts = { 100, 100, 250, 300 };
final int[] serversReliability = { 25, 25, 50, 100 };
final int[] vmsRam = { 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 8, 8, 8, 16, 16 };
final int[] vmsCpu = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 6, 6, 8, 8 };
List<VirtualMachine> vms = ComputeFactory.buildVirtualMachines(vmsRam, vmsCpu);
List<ComputeServer> servers = ComputeFactory.buildComputeServer(serversRam, serversCpu, serversAnnualCosts, serversReliability);
SolverFactory solverFactory = SolverFactory.createFromXmlResource("virtualMachinesAssignmentSolverConfig.xml");
Solver solver = solverFactory.buildSolver();
VirtualMachinesAssignment unsolvedVirtualMachinesAssignment = new VirtualMachinesAssignment();
unsolvedVirtualMachinesAssignment.setComputeServersList(servers);
unsolvedVirtualMachinesAssignment.setVirtualMachinesList(vms);
// Act
solver.solve(unsolvedVirtualMachinesAssignment);
VirtualMachinesAssignment solvedVirtualMachinesAssignments = (VirtualMachinesAssignment) solver.getBestSolution();
assertFalse(solvedVirtualMachinesAssignments.getScore().isFeasible());
}
|
74cf52da-c405-4f26-bda1-dce28507378f
|
void replaceRotors(Rotor[] rotors) {
// FIXME
}
|
4f7f4664-2763-42f8-b431-50c866e6ac14
|
void setRotors(String setting) {
// FIXME
}
|
24736cdf-e07b-49a7-bfd8-e509f6aaada9
|
String convert(String msg) {
return null;
// FIXME
}
|
0fb62d99-f3fa-4dee-9ece-80ddfca3b5ce
|
static char toLetter(int p) {
return 'A'; // FIXME
}
|
600ad2c4-7a15-4366-aa13-0cf2e1447271
|
static int toIndex(char c) {
return 0; // FIXME
}
|
877fe0df-1709-4845-86f7-bb9b1cca4587
|
boolean advances() {
return true;
}
|
ed0d27e9-d848-4523-9a94-8f261f01f022
|
boolean hasInverse() {
return true;
}
|
e23fac08-ea1e-47c3-9c64-0fd7d439af08
|
int getSetting() {
return _setting;
}
|
3f17bf8f-ff8f-4a69-95f5-40a9c789e3f8
|
void set(int posn) {
assert 0 <= posn && posn < ALPHABET_SIZE;
_setting = posn;
}
|
5e71df21-7496-4dff-83dd-50da0b9a309d
|
int convertForward(int p) {
return 0; // FIXME
}
|
0577f481-310b-4628-a92e-b7e34c64db96
|
int convertBackward(int e) {
return 0; // FIXME
}
|
a49bd0c0-2386-49bc-9b8d-82c394ffec1f
|
boolean atNotch() {
return false; // FIXME
}
|
c76fed08-d994-49c5-9de9-41cd70520691
|
void advance() {
// FIXME
}
|
ebdf4d4e-1119-4952-b7c5-f0bc90617397
|
@Override
boolean hasInverse() {
return false;
}
|
c3a1f557-40b2-42de-bc9e-8776f3e652fe
|
@Override
int convertBackward(int unused) {
throw new UnsupportedOperationException();
}
|
10b9e499-9ac7-4b01-975d-cad460b1becc
|
@Override
boolean advances() {
return false;
}
|
d9123c0c-5c2c-4ea9-a27b-bd5a261cda17
|
@Override
boolean atNotch() {
return false;
}
|
1be21a98-d61d-4481-bd2e-a29d93f4c5e5
|
@Override
void advance() {
}
|
4f13150a-6afd-46e5-bb6d-9ba7c4cbc60b
|
public static void main(String[] unused) {
Machine M;
BufferedReader input =
new BufferedReader(new InputStreamReader(System.in));
buildRotors();
M = null;
try {
while (true) {
String line = input.readLine();
if (line == null) {
break;
}
if (isConfigurationLine(line)) {
M = new Machine();
configure(M, line);
} else {
printMessageLine(M.convert(standardize(line)));
}
}
} catch (IOException excp) {
System.err.printf("Input error: %s%n", excp.getMessage());
System.exit(1);
}
}
|
93b911e5-d898-4463-8a42-ab780df98825
|
private static boolean isConfigurationLine(String line) {
return false; // FIXME
}
|
157c48b3-17bb-47eb-95c5-5ba8c6ff5631
|
private static void configure(Machine M, String config) {
// FIXME
}
|
52ae5914-d30d-48d2-b696-23677859f7e6
|
private static String standardize(String line) {
return line; // FIXME
}
|
10a478e7-5a2c-4e76-9c06-65ed58c07efe
|
private static void printMessageLine(String msg) {
String msgFinal = "";
int index = 0;
while (index < msg.length()) {
msgFinal += msg.substring(index, index + 1);
if ((index + 1) % 5 == 0) {
msgFinal += " ";
}
index += 1;
}
System.out.println(msgFinal);
}
|
c11c310d-1e36-45af-ac56-e18e6dc3ffe5
|
private static void buildRotors() {
// FIXME
}
|
a1599fd6-211d-4ee0-8ac7-0865dd4355ea
|
public void displayTreasureChestNearby(Grid grid);
|
186b59e6-0e4d-4539-83c8-0ef741bcbf5a
|
public static void main(String[] args) {
// Grid g = new Grid(4, 5);
// g.addTreasureChest(new TreasureChest("1"), 0, 0);
// g.addTreasureChest(new TreasureChest("2"), 1, 2);
// TreasureChestManager v = new TreasureChestManager();
// v.displayTreasureChestNearby(g);
instructions();
runTreasurMapApp();
}
|
142e5bf6-6947-403c-bfdd-34b858338584
|
private static void instructions(){
System.out.println("*************************************************************************************");
System.out.println();
System.out.println(" TREASURE MAP INSTRUCTIONS ");
System.out.println();
System.out.println("1.Create a grid by defining the number of colums and rows");
System.out.println("2.Add treasure chests to your grid");
System.out.println("3.Display how many treasure chests are nearby");
System.out.println("1.TYPE EXIT TO TERMINATE");
System.out.println();
System.out.println("*************************************************************************************");
}
|
54f9a26d-e5d0-47b9-a853-d819e3139ad9
|
private static void runTreasurMapApp(){
Scanner scanner = new Scanner(System.in);
Grid grid = createGrid(scanner);
addTreasureChestToGrid(scanner,grid);
}
|
2b5aacee-59f5-4e4d-8bf5-263d87a8c1cd
|
private static Grid createGrid(Scanner scanner){
Grid grid = null;
System.out.println("Enter a name for your Grid :");
String name =getName(scanner);
while(name==null||name.equals("")){
System.out.println("please enter a name for your grid :");
name =getName(scanner);
}
System.out.println("how many rows would you like your grid to have: ");
int numRows =getRows(scanner);
while(numRows<0){
System.out.println("Please enter a number and ensure its greater than 0 :");
numRows=getRows(scanner);
}
System.out.println("how many columns would you like :");
int numCols =getColumns(scanner);
while(numCols<0){
System.out.println("Please enter a number and ensure its greater than 0 :");
numCols=getColumns(scanner);
}
// display grid
grid = new Grid(numRows, numCols);
grid.setName(name);
grid.displayGrid();
return grid;
}
|
71af9deb-77b6-43e2-99ac-7490a25a424a
|
private static void addTreasureChestToGrid(Scanner scanner,Grid grid) {
System.out.println("would you like to add a treasure chest to your grid. Enter Y or N :");
String addTreasure = addTreasure(scanner);
while(!addTreasure.equalsIgnoreCase("y")&&!addTreasure.equalsIgnoreCase("n")){
System.out.println("enter Y or N :");
addTreasure = addTreasure(scanner);
}
if(addTreasure.trim().toLowerCase().equalsIgnoreCase("y")){
addTreasureChest(scanner,grid);
}else{
TreasureChestCounter counter = new TreasureChestManager();
System.out.println("**********Treasure maps nearby****************" );
counter.displayTreasureChestNearby(grid);
}
}
|
d7b68c83-dc8c-43f1-b9a8-6198a659deec
|
private static int getRows(Scanner scanner){
String rows = scanner.nextLine();
int numRows =TreasureMapUtils.convertToInt(rows, -1);
return numRows;
}
|
4016365a-802c-4f61-ade2-71ef796cb418
|
private static String getName(Scanner scanner){
return scanner.nextLine();
}
|
ed389211-7a01-4018-86a8-4729ea601d46
|
private static int getColumns(Scanner scanner){
String cols = scanner.nextLine();
int numCols =TreasureMapUtils.convertToInt(cols, -1);
return numCols;
}
|
2124d0b8-5e9d-48e1-a792-f71b0f956f8c
|
private static void addTreasureChest(Scanner scanner,Grid grid){
System.out.println("please provide a name for your treasure chest :");
String chest = scanner.nextLine();
while(chest==null||chest.equals("")){
System.out.println("please provide a name for your treasure chest :");
chest=scanner.nextLine();
}
System.out.println("please provide a position for your treasure chest ");
System.out.println("please enter a row number row numbers start from 0 and should be less than "+grid.getRows()+" : ");
int row = getRows(scanner);
while(row==-1||row>grid.getRows()){
System.out.println("please enter a valid row number.Row numbers start from 0 and is less than "+grid.getRows()+" :");
row =getRows(scanner);
}
int col = getColumns(scanner);
System.out.println("please enter the column you would like to position your treasure chest columns starts 1 and should be less than "+grid.getColumns()+" : ");
while(col==-1||col>grid.getColumns()){
System.out.println("please enter a valid column number. Column numbers start from 1 and is less than "+grid.getColumns());
col=getColumns(scanner);
}
grid.addTreasureChest(new TreasureChest(chest), row, col);
grid.displayGrid();
System.out.println("would you like to add another treasure chest to the grid ? Y or N");
String yn=addTreasure(scanner);
while(!yn.trim().equalsIgnoreCase("Y")&&!yn.trim().equalsIgnoreCase("N")){
System.out.println("enter Y or N :");
yn = scanner.nextLine();
}
if(yn.trim().equalsIgnoreCase("Y")){
addTreasureChest(scanner,grid);
}else{
TreasureChestCounter counter = new TreasureChestManager();
System.out.println("**********Treasure maps nearby****************" );
counter.displayTreasureChestNearby(grid);
System.out.println("thank you for using the trasure map finder");
}
}
|
7d83431e-7465-4f7d-97ae-88d74f622d6a
|
private static String addTreasure(Scanner scanner){
return scanner.nextLine();
}
|
e7d23376-5327-4178-97d9-48603680ef61
|
public Grid(int rows, int cols){
treasureChest = new TreasureChest[rows][cols] ;
this.rows =rows ;
this.columns =cols ;
}
|
bbfb32f5-f63b-48f6-8f22-be4654f07a8f
|
public int getRows() {
return rows;
}
|
47347ad9-beda-449a-bb33-d9a4d90c5a22
|
public int getColumns() {
return columns;
}
|
ff581af7-a407-421b-8926-a9a2799eb088
|
public String getName() {
return name;
}
|
c112fbaa-9932-4d28-bd6a-91845bba8c78
|
public void setName(String name) {
this.name = name;
}
|
8bd598cb-93e3-4350-9d1c-859a98be482c
|
public TreasureChest[][] getTreasureChest() {
return treasureChest;
}
|
7d0e918a-ea7e-4c7a-8b71-05789b0c8d38
|
public void addTreasureChest(TreasureChest chest, int row,int col){
treasureChest[row][col] = chest ;
}
|
c4f74df1-0825-4005-8fee-a17b38655d13
|
public void removeTreasureChest(TreasureChest chest){
for(int row=0;row<rows;row++){
for(int col=0;col<columns;col++){
TreasureChest chest1 = treasureChest[row][col];
if(chest1.equals(chest)){
chest1 = null;
break;
}
}
}
}
|
02088d9a-70b3-4bde-9258-2c95b0a469f1
|
public void displayGrid(){
System.out.println("Grid name :"+getName());
for(int row=0;row<rows;row++){
StringBuilder gridBulder = new StringBuilder();
for(int col=0;col<columns;col++){
TreasureChest chest = treasureChest[row][col];
if(chest==null){
gridBulder.append("_ ");
}else{
gridBulder.append("X ");
}
}
System.out.println(gridBulder.toString());
}
}
|
11c11d2d-ef13-4608-97fe-9e76a05cdc6b
|
public void displayTreasureChestNearby(Grid grid) {
System.out.println("RESULTS");
if(grid!=null){
TreasureChest[][] treasureChestGrid = grid.getTreasureChest();
int rows = grid.getRows();
int cols =grid.getColumns();
for(int row=0;row<rows;row++){
StringBuilder result = new StringBuilder();
// check first col
for(int col=0;col<cols;col++){
int counter = 0 ;
counter=checkTreasureChestsNearby(row, col, rows, cols, counter, treasureChestGrid);
result.append(counter);
}
System.out.println(result.toString());
}
}
}
|
45c8ce5c-2aa7-488c-a823-b54b58115cbf
|
private int checkPreviousColumn(int col,int row,TreasureChest[][] treasureChestGrid,int counter){
if(col!=0){
counter=checkColumn(treasureChestGrid, row, col-1, counter);
}
return counter;
}
|
14d89ddc-e5ad-408a-b40e-a601c0804fa4
|
private int checkPreviousColumnRowBelow(int row,int col,TreasureChest[][]treasureChestGrid,int counter){
if(col!=0){
counter=checkColumn(treasureChestGrid, row+1, col-1, counter);
}
return counter;
}
|
4682c28c-ab6e-4dcf-8fcc-7cea069683a9
|
private int checkRightColumn(int row,int col,int cols,TreasureChest[][]treasureChestGrid,int counter){
if(col!=(cols-1)){
counter=checkColumn(treasureChestGrid, row, col+1, counter);
}
return counter;
}
|
c093006e-faa0-4cb0-b10c-f648bbe8bf76
|
private int checkRightColumnRowBelow(int row,int col,int cols,TreasureChest[][]treasureChestGrid,int counter){
if(col!=(cols-1)){
counter=checkColumn(treasureChestGrid, row+1, col+1, counter);
}
return counter;
}
|
df9ab819-d58e-4bfb-ba07-e0bca1c3336a
|
private int checkPreviousColumnRowAbove(int row, int col,TreasureChest[][]treasureChestGrid,int counter){
// check previous col if it is not 0
if(col!=0){
counter=checkColumn(treasureChestGrid, row-1, col-1, counter);
}
return counter;
}
|
926ce75a-71e7-4910-9569-61ae39716854
|
private int checkRightColumnRowAbove(int row,int col,int cols,TreasureChest[][]treasureChestGrid,int counter){
if(col!=(cols-1)){
counter=checkColumn(treasureChestGrid, row-1, col+1, counter);
}
return counter ;
}
|
5cadbc4a-e215-4bcb-a791-4e1f7d5f7032
|
private int checkColumn(TreasureChest[][]treasureChestGrid,int row,int col,int counter){
if(row<treasureChestGrid[0].length&&col<treasureChestGrid[1].length){
TreasureChest nChest =treasureChestGrid[row][col];
if(nChest!=null){
counter++;
}
}
return counter;
}
|
7e656cd1-b259-49a6-aa2a-142b2b6aa9de
|
private int checkFirstRow(int row,int col,int cols,int counter,TreasureChest[][] treasureChestGrid){
counter =checkColumn(treasureChestGrid, row, col, counter);
counter=checkPreviousColumn(col, row, treasureChestGrid, counter);
counter=checkRightColumn(row, col, cols, treasureChestGrid, counter);
return counter ;
}
|
03007c63-f6ba-42a6-9c6d-70527cb161c7
|
private int checkNextRow(int row,int col,int rows,int cols,int counter,TreasureChest[][] treasureChestGrid){
if(row!=(rows-1)){
counter=checkColumn(treasureChestGrid, row+1, col, counter);
counter=checkPreviousColumnRowBelow(row, col, treasureChestGrid, counter);
counter=checkRightColumnRowBelow(row, col, cols, treasureChestGrid, counter);
}
return counter;
}
|
17e50ed6-b349-4fe4-965d-ec2b7689792a
|
private int checkRowAbove(int row,int col,int rows,int cols,int counter,TreasureChest[][] treasureChestGrid){
if(row!=0){
counter=checkColumn(treasureChestGrid, row-1, col, counter);
counter=checkPreviousColumnRowAbove(row, col, treasureChestGrid, counter);
counter=checkRightColumnRowAbove(row, col, cols, treasureChestGrid, counter);
}
return counter;
}
|
aa82323e-a6fd-422f-bb47-cfb968d0fc3f
|
private int checkTreasureChestsNearby(int row,int col,int rows,int cols,int counter,TreasureChest[][] treasureChestGrid){
counter =checkFirstRow(row, col, cols, counter, treasureChestGrid);
counter=checkNextRow(row, col, rows, cols, counter, treasureChestGrid);
counter= checkRowAbove(row, col, rows, cols, counter, treasureChestGrid);
return counter;
}
|
673e8f22-5e5c-497d-88ff-0fcc15592873
|
public static int convertToInt(String string,int defaultInt){
int number = 0;
try{
number=Integer.parseInt(string);
}catch (Exception e) {
number =defaultInt;
}
return number;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.