-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrucks.java
More file actions
96 lines (81 loc) · 2.63 KB
/
Copy pathTrucks.java
File metadata and controls
96 lines (81 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.instaclustr.kongo;
import java.util.Random;
import java.util.UUID;
/*
* Trucks move from one warehouse location to another warehouse location and transport Goods.
* They can have a temperature controlled environment.
*/
public class Trucks
{
final String prefix = "trucks_"; // what am i?
final String id;
boolean tempControlled = false;
int tempRange = -1;
Temp temp = null; // new temp object
// Hack: keep track of what Goods categories are on board by using a dummy Goods object
Goods categoriesOnBoard = new Goods();
// create new Truck object
public Trucks()
{
this.id = this.prefix + randomUUID();
Random rand = new Random();
if (rand.nextDouble() < 0.8)
{
tempControlled = true;
int r = rand.nextInt(5);
tempRange = r;
temp = new Temp(r);
}
else temp = new Temp(-1);
}
public static String randomUUID()
{
UUID uuid = UUID.randomUUID();
String r = uuid.toString();
return r;
}
public String toStr()
{
String s = "";
s += "Truck Id=" + id;
s += ", temp controlled " + tempControlled;
if (tempControlled)
s += ", temp range " + tempRange;
return s;
}
// when unloaded reset cats
// Note that we don't have dry and temp cats here yet as not used to check if loading is ok
public void resetCats()
{
categoriesOnBoard.categoryBulky = false;
categoriesOnBoard.categoryEdible = false;
categoriesOnBoard.categoryFragile = false;
categoriesOnBoard.categoryHazardous = false;
categoriesOnBoard.categoryMedicinal = false;
categoriesOnBoard.categoryPerishable = false;
}
// Logical OR new goods loaded onto truck with existing categories
public void updateCategories(Goods g)
{
categoriesOnBoard.categoryBulky |= g.categoryBulky;
categoriesOnBoard.categoryEdible |= g.categoryEdible;
categoriesOnBoard.categoryFragile |= g.categoryFragile;
categoriesOnBoard.categoryHazardous |= g.categoryHazardous;
categoriesOnBoard.categoryMedicinal |= g.categoryMedicinal;
categoriesOnBoard.categoryPerishable |= g.categoryPerishable;
}
// check temp rules for delivery to warehouse
public boolean canDeliverToWarehouse(Warehouses w)
{
// trucks not temp controlled can unload anywhere
if (!tempControlled)
return true;
// identical temp ranges can unload
if (tempRange == w.tempRange)
return true;
// if truck is ambient temp can unload to any except freezing
if (tempRange == 4)
return (w.tempRange == 1 || w.tempRange == 2 || w.tempRange == 3 || w.tempRange == 4);
return false;
}
}