| Conditions | 9 |
| Total Lines | 71 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package it.cnr.istc.pst.cognition.koala.reasoner.goal; |
||
| 34 | public void init(ObservationReasoner env) |
||
| 35 | throws Exception |
||
|
|
|||
| 36 | { |
||
| 37 | // set environment |
||
| 38 | this.environment = env; |
||
| 39 | this.environment.subscribe(this); |
||
| 40 | |||
| 41 | // set wait flag |
||
| 42 | synchronized (this.updates) { |
||
| 43 | this.updates.clear(); |
||
| 44 | this.updates.notifyAll(); |
||
| 45 | } |
||
| 46 | |||
| 47 | // check already running process |
||
| 48 | if (this.process != null && this.process.isAlive()) { |
||
| 49 | // stop process |
||
| 50 | this.process.interrupt(); |
||
| 51 | this.process.wait(); |
||
| 52 | } |
||
| 53 | |||
| 54 | // create background thread |
||
| 55 | this.process = new Thread(new Runnable() { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * |
||
| 59 | */ |
||
| 60 | public void run() |
||
| 61 | { |
||
| 62 | boolean run = true; |
||
| 63 | while (run) |
||
| 64 | { |
||
| 65 | try |
||
| 66 | { |
||
| 67 | // list of updates to handle |
||
| 68 | List<ObservationReasonerUpdate> list = new ArrayList<ObservationReasonerUpdate>(); |
||
| 69 | // wait a signal |
||
| 70 | synchronized (updates) { |
||
| 71 | // check signal flag |
||
| 72 | while (updates.isEmpty()) { |
||
| 73 | // wait signal |
||
| 74 | updates.wait(); |
||
| 75 | } |
||
| 76 | |||
| 77 | // get updates |
||
| 78 | list.addAll(updates); |
||
| 79 | // clear |
||
| 80 | updates.clear(); |
||
| 81 | // release lock |
||
| 82 | updates.notifyAll(); |
||
| 83 | } |
||
| 84 | |||
| 85 | |||
| 86 | // do goal triggering if necessary |
||
| 87 | doGoalTriggering(list); |
||
| 88 | } |
||
| 89 | catch (InterruptedException ex) { |
||
| 90 | // stop goal triggering |
||
| 91 | run = false; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | }); |
||
| 96 | |||
| 97 | // complete initialization |
||
| 98 | this.doInitialize(this.environment); |
||
| 99 | |||
| 100 | |||
| 101 | // check if initialize |
||
| 102 | if (this.process != null && !this.process.isAlive()) { |
||
| 103 | // start background process |
||
| 104 | this.process.start(); |
||
| 105 | } |
||
| 155 |