id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
4402c408-0ce0-47aa-b1ed-b8ff38ea7dbf | public void testMoreThanTenPins() {
Bowling game=bowling();
try {
game.roll(pinCount(2));
game.roll(pinCount(5));
game.roll(pinCount(3));
game.roll(pinCount(6));
game.roll(pinCount(11));
System.out.println("7: "+game.score(fr... |
2ca11c9b-0537-478f-bd55-ddbb62f88e23 | public void testInvalidRoll() {
Bowling game=bowling();
try {
game.roll(pinCount(10));
game.roll(pinCount(5));
game.roll(pinCount(6));
game.roll(pinCount(7));
game.roll(pinCount(1));
game.roll(pinCount(10));
... |
46ccb652-2339-42da-a41a-99b621f8a2d5 | protected boolean roll(Frame frame, PinCount pinCount) {
return rolled();
} |
6260f602-b86c-4c94-af75-a2bae0945906 | protected int score(int pins) {
return pins;
} |
047204af-f79a-47b9-9e63-8f459fc21b05 | RolledBall(Ball ball) {
this.ball=ball;
} |
0a771361-e28d-4db4-a03c-420374933526 | protected boolean rolled() {
return true;
} |
97034a00-cf4d-4599-a0d3-29d4f86fe583 | public Ball next(PinCount pinCount) {
return ball.next(pinCount);
} |
c422453a-c429-4796-b714-d69e9a4975e5 | public Ball firstBall() {
return new RolledBall(new Ball() {
protected Ball markSuccessor() {
return new BallFactory().firstStrikeBonusBall();
}
protected Ball nonMarkSuccessor() {
return new BallFactory().secondBall();
}
... |
60779c46-fb3d-408c-9a45-48f73744b14d | protected Ball markSuccessor() {
return new BallFactory().firstStrikeBonusBall();
} |
5fcca565-7db4-46cd-a5a0-81e6618a57d4 | protected Ball nonMarkSuccessor() {
return new BallFactory().secondBall();
} |
feaa1ada-5263-4137-9a37-e75be25a12d8 | Ball secondBall() {
return new RolledBall(new Ball() {
protected Ball markSuccessor() {
return new BallFactory().spareBonusBall();
}
protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
}
});
... |
f2382806-7e08-4687-b53e-bfae3d368a63 | protected Ball markSuccessor() {
return new BallFactory().spareBonusBall();
} |
9044604c-ee05-4bd4-b0dc-b6fb7f5eb8b1 | protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
} |
6a32c59a-bf79-43ea-9e66-d2ffa5690080 | Ball firstStrikeBonusBall() {
return new Ball() {
protected Ball nonMarkSuccessor() {
return new BallFactory().secondStrikeBonusBall();
}
};
} |
6a6d8bae-bc0d-4544-b2b3-5493da2bcbc5 | protected Ball nonMarkSuccessor() {
return new BallFactory().secondStrikeBonusBall();
} |
9d3ab3a8-80d2-4cb6-a2b1-2664c8115333 | Ball secondStrikeBonusBall() {
return new Ball() {
protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
}
};
} |
315d4b50-f105-494e-a714-094f57cf962c | protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
} |
e80a121b-0645-4d0d-a5a5-98f70b3ff1b1 | Ball spareBonusBall() {
return new Ball() {
protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
}
};
} |
49c9a091-6eda-49c0-be34-fc9bba19e83a | protected Ball nonMarkSuccessor() {
return new BallFactory().scoredBall();
} |
9999c31a-1ee6-4258-9e2f-f45384ae8667 | Ball scoredBall() {
return new ScoredBall();
} |
288b1d03-7bce-44e1-9b0f-ffedb78900f0 | protected boolean roll(Frame frame, PinCount pinCount) {
frame.transition(pinCount);
return rolled();
} |
23cf66b1-0a6a-40d4-81d7-ef2ef6834267 | protected boolean rolled() {
return false;
} |
3e69dc39-e2e3-439c-a091-91b703da6730 | public Ball next(PinCount pinCount) {
return pinCount.nextBall(this);
} |
2dbadc23-9879-4bda-9c4b-95972dba2098 | protected Ball markSuccessor() {
return nonMarkSuccessor();
} |
3dfb351f-e8fb-4b2b-9eaf-65bda24c2b6e | protected Ball nonMarkSuccessor() {
throw new RuntimeException("Undefined - nonMarkSuccessor()");
} |
d6ce181a-4338-4af6-855e-85dbe607e4a8 | protected int score(int pins) {
return 0;
} |
a83562df-5908-4cbc-aa97-c65abdabcc42 | public Frame(Ball first, PinCount initial) {
ball=first;
pinCount=initial;
} |
c0c0c588-3fc8-4a31-ab58-12d2b4491103 | boolean roll(PinCount count) {
return ball.roll(this, count);
} |
bee8970f-ec80-4e3e-8023-d70e69e21836 | void transition(PinCount count) {
pinCount=pinCount.add(count);
ball=ball.next(pinCount);
} |
0c1d3ad7-e653-497d-bae1-4649d130eb89 | int score() {
return pinCount.score(ball);
} |
8313b802-fcf2-4cdc-bd57-96e57362f65c | public FrameCount(int frames) {
this.frames=frames;
} |
827f1b8e-df01-4147-acac-2ea4adda8abc | public Score score(Bowling game) {
return game.score(validFrames());
} |
aa078277-54d4-405d-ba08-59bdc078b687 | private int validFrames() {
return frames < 1 ? 0 : Math.min(frames, Bowling.FRAMES);
} |
79991133-70c0-4236-931e-da0790b4e993 | public Score(int points) {
this.points=points;
} |
f5cc4811-e317-4023-9c08-8f5c1516f250 | public String toString() {
return new Integer(points).toString();
} |
23b08d56-67f7-454b-9ecb-75ff5dade467 | public static PinCount instance(int pins) {
return new PinCount(0).add(new PinCount(pins));
} |
b9c381c7-411f-4838-85ee-15d696c90c7c | private PinCount(int pins) {
this.pins=pins;
} |
7cccfedd-b9fe-4439-8adc-c8f38dac6eb9 | PinCount add(PinCount pinCount) {
int sum=this.pins+pinCount.pins;
if(sum >= minimum() && sum <= maximum()) return new PinCount(sum);
throw new RuntimeException(message(sum));
} |
2566e10f-cdc0-4961-80d7-cc1603e3e760 | private int minimum() {
return this.pins;
} |
c0cae75a-7b45-4612-a07e-4ea25b5ce1fc | private int maximum() {
return Math.min(3*Bowling.PINS, Bowling.PINS*(1+(minimum()/Bowling.PINS)));
} |
86f98bd0-0e31-46fa-b369-514e5185a353 | private String message(int count) {
return "EXPECTED PIN COUNT: "+minimum()+" - "+maximum()+". BUT FOUND: "+count+".";
} |
26aed840-d3d5-4c95-b65f-a2f4425479a3 | Ball nextBall(Ball current) {
return pins==Bowling.PINS ? current.markSuccessor() : current.nonMarkSuccessor();
} |
77e5e64a-e3de-4955-9fef-f3cdf1c8ff2e | int score(Ball ball) {
return ball.score(pins);
} |
d419d3b5-1d31-4a83-b0f1-f8be76a4a07f | public Bowling(Frame[] frames) {
this.frames=java.util.Arrays.copyOfRange(frames, 0, Bowling.FRAMES);
} |
c2ea4b85-cd1e-4a2f-96b7-38a883159c42 | public void roll(PinCount count) {
for(Frame each : frames)
if(each.roll(count)) return;
} |
95548e56-5da9-446a-9bff-b77a164891cb | public Score score() {
return score(frames.length);
} |
c89b82b9-17a9-4557-998a-9c1f2e08116d | public Score score(FrameCount count) {
return count.score(this);
} |
5e91a709-c016-4468-82c8-2ac75294ecf3 | Score score(int frames) {
int score=0;
for(int frame=0; frame < frames; frame++)
score+=this.frames[frame].score();
return new Score(score);
} |
b4e00207-f94b-4299-9ea8-d8480dc33af4 | public Bowling game() {
return new Bowling(frames());
} |
b04bd412-1fba-4c1c-be68-bbe8fff9ec63 | private Frame[] frames() {
Frame[] frames=new Frame[Bowling.FRAMES];
for(int frame=0; frame < frames.length; frame++) {
Ball first=new BallFactory().firstBall();
PinCount none=PinCount.instance(0);
frames[frame]=new Frame(first, none);
}
return frames;
} |
ddd1a4ee-f500-4e7e-bb61-84dbb15ffd39 | public static void main(String[] args) {
HashMap<String, Object> options = new HashMap<String, Object>();
for(String arg : args) {
if(arg.startsWith("-VM")){
options.put("virtual_memory", Integer.parseInt(arg.substring(3)));
}else if(arg.startsWith("-PM")){
... |
aea8bafb-9d14-4c1f-879d-ef5bbfe97c39 | public Scheduler(int memoryBaseAddress, int memorySize, int diskBaseAddress, int diskSize,
int processNumber, int threadNumber, int memoryPerProcess, int processTimeSlot,
int threadTimeSlot, OperationPattern.TYPE type, int operationPerThread, int workloadRatio,
... |
1c6c9d74-4962-4969-a2f5-c64dac457d9d | public LinkedList<Integer> getDeadProcess(){
return deadProcess;
} |
fd4e7478-5b22-433e-94c2-8f0006c3f654 | public Process getLowestProcess(){
Process process = this.currentProcess;
int cnt =0;
while(this.priorityQueue.iterator().hasNext() && cnt++ < processNumber){
Process tmp = this.priorityQueue.iterator().next();
if(tmp == process)
break;
if(proc... |
a7c8ba60-39ba-4cc5-9040-247a253e9aa4 | private boolean switchContext() {
//no process, get one to start
if(this.currentProcess == null){
this.currentProcess = priorityQueue.poll();
logger.info("Process==null, get new process"+this.currentProcess.printQueue());
return true;
}
//check if exce... |
f23e6a6f-b880-4766-9289-0f0023195e91 | public Event getEvent(){
Event event;
//Check if we need to switch between process
if(this.switchContext()){
event = new Event(Event.EVENT_TYPE.SWITCH_PROCESS_CONTEXT, null, null);
}else{
//if no need to switch, try get event from this process
event = ... |
553f4bd6-5a82-4840-af3c-ce5a1b179241 | public int getMaxOperations() {
return maxOperations;
} |
721cfa10-ea45-4617-a7cd-bd49580305aa | public int getOperationCounter() {
return operationCounter;
} |
6ce8eb25-cf92-46aa-9b03-00b777dc52c7 | Thread(int maxOperations){
this.maxOperations = maxOperations;
} |
08cc78c7-d13d-403f-918a-3ac92a654b8c | public boolean destroy(){
return this.operationCounter >= maxOperations;
} |
a471647a-2a80-4e14-8560-3022a130c437 | public void addCounter(){
operationCounter++;
} |
dc94af0d-76d0-45e6-840b-29c8467a3303 | @Override
public String toString() {
return "{id:"+this.hashCode()+",accumulate:"+this.getAccumulatedExecutionTime()+",execution:"+this.getExecutionTime()+",operation:"+this.operationCounter+"}";
} |
442cb974-b970-4919-a907-074a52b03be9 | public Memory(int virtualMemSize, int physicalMemSize, int memoryPerProcess, int processNumber, MemoryReplacementAlgo.ALGORITHM algo, Disk disk, Scheduler scheduler) {
this.algo = algo;
this.disk = disk;
this.memoryPerProcess = memoryPerProcess;
this.processNumber = processNumber;
... |
c3b35a0e-2c66-42f4-ab27-474a599d6d97 | private int loadMemory(int blk, Event event){
int time = 0;
time += this.removeMemory(event);
//update working set ratio
if(algo != MemoryReplacementAlgo.ALGORITHM.RANDOM)
this.LRU.put(blk, 1);
this.memorySpace.put(blk, IN_MEM);
if(algo == MemoryReplacementAlg... |
2fa0aa87-d7f4-490c-ba10-e0cc150fa85d | private int removeMemory(Event event){
int lowest = 0;
int hit = 9999;
int time = 0;
if(algo == MemoryReplacementAlgo.ALGORITHM.WORKSET){
LinkedList<Integer> deadProcess = this.scheduler.getDeadProcess();
Process process = this.scheduler.getLowestProcess();
... |
a51a885d-53d8-45a2-89f7-0f31280f1116 | public void read(Event event) {
int time = 0;
int pFault = 0;
// logger.trace("start "+LRU.toString());
// logger.trace(memorySpace.toString());
try{
for(int i = event.getBaseAddress(); i < event.getBaseAddress()+event.getAddressLength(); i++) {
if(memor... |
3f51629e-ea87-4c19-b2dd-b9d60707d6fe | public void write(Event event) {
int time = 0;
int pFault = 0;
try{
for(int i = event.getBaseAddress(); i < event.getBaseAddress()+event.getAddressLength(); i++) {
if(memorySpace.get(i) == OUT_MEM){
logger.trace("Block "+i+" out of memory");
... |
f1f6c310-d8eb-471a-891c-dd8ca683458a | public Disk(Integer seek_time){
this.lastLocation = 0;
this.seekTime = seek_time;
} |
ae2e70bc-e739-4aaf-b53d-01bb6fa2e5e2 | public int loadMemory(int address){
int time=0;
int seekDistance = Math.abs(this.lastLocation-address);
if(seekDistance!=0)
time += seekTime;
this.lastLocation = address;
return time + DISK_TIME;
} |
9060b591-e7f2-4c7a-a767-150220e39e5a | public int writeMemory(int address){
int time=0;
int seekDistance = Math.abs(this.lastLocation-address);
if(seekDistance!=0)
time += seekTime;
this.lastLocation = address;
return time + DISK_TIME;
} |
20e5ee46-d1a2-43f6-934a-59c497832851 | public void read(Event event){
int seekDistance = Math.abs(this.lastLocation-event.getBaseAddress());
if (seekDistance!=0)
event.addTime(seekTime);
this.lastLocation = event.getBaseAddress()+event.getAddressLength();
event.addTime(DISK_TIME);
} |
f6ef1788-e91d-4f61-a416-26d0bda92e15 | public void write(Event event){
int seekDistance = Math.abs(this.lastLocation-event.getBaseAddress());
if (seekDistance!=0)
event.addTime(seekTime);
this.lastLocation = event.getBaseAddress()+event.getAddressLength();
event.addTime(DISK_TIME);
} |
10fadfa2-9072-4b2a-b6be-599c8e96386d | @Override
public int compare(Process p1, Process p2){
if(p1.getAccumulatedExecutionTime() < p2.getAccumulatedExecutionTime()){
return -1;
}
if(p1.getAccumulatedExecutionTime() > p2.getAccumulatedExecutionTime()){
return 1;
}
return 0;
} |
39d38580-b92e-46e5-8435-ef15e3c1bf31 | public Thread getThread() {
return thread;
} |
cbb79035-4ebb-4887-90c3-dbe8cbb16510 | Event(EVENT_TYPE eventType, int baseAddress, int addressLength, Process process, Thread thread){
this.eventType = eventType;
this.baseAddress = baseAddress;
this.addressLength = addressLength;
this.thread = thread;
this.process = process;
} |
4d6c9248-b9b1-45a8-bda5-3989800bcf8e | Event(EVENT_TYPE eventType, Process process, Thread thread){
this.eventType = eventType;
this.thread = thread;
this.process = process;
} |
21990a84-eb68-4089-a5e0-c030cec7e5fa | public int getBaseAddress() {
return baseAddress;
} |
8ac49ada-dad2-4a93-9204-3d473676e49c | public int getAddressLength() {
return addressLength;
} |
8ab23149-61ae-4dd2-b31a-f3e0be23e409 | public EVENT_TYPE getEventType() {
return eventType;
} |
e6088d10-2100-4276-a240-a5c985850097 | public void addInMemoryWorkSetSize(){
if(this.process!=null){
this.process.setInMemoryWorkingSet(
this.process.getInMemoryWorkingSet()+1
);
}
} |
c1017262-dbf6-44d5-8c61-ff243e567bf7 | public void addPageFault(int time){
if(this.process!=null){
this.process.addPageFaultCount(time);
}
if(this.thread!=null){
this.thread.addPageFaultCount(time);
}
} |
b754fb83-aa3b-4189-8834-34fae83822b0 | public void addTime(int time) {
if(this.process!=null)
this.process.addExecutionTime(time);
if(this.thread!=null)
this.thread.addExecutionTime(time);
} |
d32a33c6-3eef-4096-8efd-75547f5de354 | @Override
public String toString() {
return this.eventType.toString()+" "+this.baseAddress+":"+this.addressLength+" "+this.thread;
} |
012074d0-4566-4544-af5e-2676d424f64f | public int getPageFaultCount() {
return pageFaultCount;
} |
1a3a2ce5-fb91-4162-b255-57324e160fcb | public void addPageFaultCount(int pageFaultCount) {
this.pageFaultCount += pageFaultCount;
} |
128ff6d1-bc48-442e-8ad5-c8b2eed2a05a | public Integer getAccumulatedExecutionTime(){
return this.accumulatedExecutionTime;
} |
65324566-a7f9-4d3c-b7a2-675f1739db03 | public void addAccumulatedExecutionTime(Integer accumulatedExecutionTime) {
this.accumulatedExecutionTime += accumulatedExecutionTime;
} |
2ce42397-63f0-4575-befa-c43e92a53d00 | public int getExecutionTime() {
return executionTime;
} |
2e9862cc-4589-4842-8506-82f7d16b52ca | public void setExecutionTime(int executionTime) {
this.executionTime = executionTime;
} |
0d41cb67-2574-466c-90ed-53d73374c86f | public void addExecutionTime(int executionTime) {
this.executionTime += executionTime;
} |
b5f0b17b-fec3-4478-aa9f-c44bd14fa854 | @Override
public int compare(Process p1, Process p2){
if(p1.getWorkingSetRatio() > p2.getWorkingSetRatio()){
return -1;
}
if(p1.getWorkingSetRatio() < p2.getWorkingSetRatio()){
return 1;
}
return 0;
} |
035d8e06-a145-4601-ac7a-a656ecaca130 | public int getPid() {
return this.pid;
} |
9d8260b2-4817-4edb-9ecc-f2df35110ab6 | public double getWorkingSetRatio(){
return this.inMemoryWorkingSet / this.totalWorkingSet;
} |
ba77e9fc-58f8-44ea-85d8-4ca770d31dcb | public void setInMemoryWorkingSet(int n){
this.inMemoryWorkingSet = n;
} |
37cf01b1-f9dd-4ce5-a129-baad43e147f1 | public int getInMemoryWorkingSet(){
return this.inMemoryWorkingSet;
} |
7e4610fc-84ad-494c-baaf-a5d482b17f28 | public Process(int pid, int memoryBaseAddress, int memorySize, int diskBaseAddress, int diskSize,
int threadNumber, int timeSlot, OperationPattern.TYPE type, int operationPerThread,
int workloadRatio, int physicalMemory) {
this.pid = pid;
this.memoryBaseAddress = me... |
8212b891-0275-494e-bcde-07fa886c9ed4 | private boolean threadFinished(){
if(this.currentThread.destroy()){
this.currentThread = null;
return true;
}
return false;
} |
88e27bd9-4609-4c92-8924-43b8896a43c5 | private boolean processFinished(){
return this.priorityQueue.size()==0 && this.currentThread==null;
} |
dc085deb-a7dd-4d93-bee5-1cde8045ac46 | private boolean switchContext(){
if(this.priorityQueue.size() == 0){
//one thread, never switch
return false;
}
if(this.currentThread == null) {
//no thread, get a new one from pool
this.currentThread = this.priorityQueue.poll();
return... |
f40b7065-f682-48dd-8cf0-1326664b2056 | public Event getEvent(){
return eventGenerator();
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.