Browse files

Tidy unnecessary else clauses

  • Loading branch information...
1 parent 374c2ed commit cc06e26522b006a09631c5696892db1804ec4bea @mikera committed Oct 18, 2012
View
3 src/main/java/mikera/ai/Tasks.java
@@ -158,9 +158,8 @@ public R2 run(T actor, P param) {
R1 test=cond.run(actor, param);
if (test!=null) {
return a.run(actor, param);
- } else {
- return b.run(actor, param);
}
+ return b.run(actor, param);
}
};
}
View
10 src/main/java/mikera/data/BigRational.java
@@ -28,11 +28,10 @@ public BigRational create(String s) {
return create(
BigInteger.valueOf(Long.parseLong(ss[0])),
BigInteger.ONE);
- } else {
- return create(
- Long.parseLong(ss[0]),
- Long.parseLong(ss[1]));
}
+ return create(
+ Long.parseLong(ss[0]),
+ Long.parseLong(ss[1]));
}
public BigRational create(BigInteger num, BigInteger denom) {
@@ -112,9 +111,8 @@ public BigInteger bigIntegerValue() {
public String toString() {
if (denominator.equals(BigInteger.ONE)) {
return numerator.toString();
- } else {
- return numerator.toString()+"/"+denominator.toString();
}
+ return numerator.toString()+"/"+denominator.toString();
}
public BigRational subtract(BigRational b) {
View
7 src/main/java/mikera/engine/BaseObject.java
@@ -131,11 +131,8 @@ public boolean set(String key, Object value) {
private static final boolean checkEquals(Object a, Object b) {
if (a==b) return true;
- if (a==null) {
- return false;
- } else {
- return a.equals(b);
- }
+ if (a==null) return false;
+ return a.equals(b);
}
private boolean realSet(String key, Object value) {
View
40 src/main/java/mikera/engine/Hex.java
@@ -67,29 +67,24 @@ public static int direction (int dx, int dy) {
if (c>=0) {
// South or south east
return (b==0)?S:SE;
- } else {
- if (a>=0) {
- // North east
- return NE;
- } else {
- // North
- return N;
- }
}
- } else {
- if (c<=0) {
- // North west
- return NW;
- } else {
- if (a<=0) {
- // South West
- return SW;
- } else {
- // South
- return S;
- }
+ if (a>=0) {
+ // North east
+ return NE;
}
+ // North
+ return N;
}
+ if (c<=0) {
+ // North west
+ return NW;
+ }
+ if (a<=0) {
+ // South West
+ return SW;
+ }
+ // South
+ return S;
}
public static float toPositionX (int lx, int ly) {
@@ -112,10 +107,9 @@ public static int distance(int x1, int y1, int x2, int y2) {
if (dx*dy>0) {
// dx and dy have same sign (i.e. within 60 degrees between same-signed x and y axes)
return Maths.abs(dx)+Maths.abs(dy);
- } else {
- // dx and dy have opposite signs (i.e. in 120 degrees between opposite signed x and y axes)
- return Maths.max(Maths.abs(dx),Maths.abs(dy));
}
+ // dx and dy have opposite signs (i.e. in 120 degrees between opposite signed x and y axes)
+ return Maths.max(Maths.abs(dx),Maths.abs(dy));
}
View
38 src/main/java/mikera/engine/Octreap.java
@@ -255,11 +255,9 @@ public void visitNodes(NodeVisitor nf) {
private boolean checkEquals(T a, T b) {
if (a==b) return true;
- if (a==null) {
- return false;
- } else {
- return a.equals(b);
- }
+ if (a==null) return false;
+
+ return a.equals(b);
}
public void delete(Octreap<T> t) {
@@ -730,16 +728,16 @@ private void deleteRange(long za, long zb, ZNode node) {
node.z2=za-1; // shrink range
addRange(nza,nzb,(T)node.object);
return;
- } else {
- // delete ranges on either side
- // this does not alter structure since can't be cutting out any holes
- if (za<node.z1) deleteRange(za,zb,node.left);
- if (zb>node.z2) deleteRange(za,zb,node.right);
-
- // exit if no overlap
- if ((zb<node.z1)||(za>node.z2)) return;
}
+ // delete ranges on either side
+ // this does not alter structure since can't be cutting out any holes
+ if (za<node.z1) deleteRange(za,zb,node.left);
+ if (zb>node.z2) deleteRange(za,zb,node.right);
+
+ // exit if no overlap
+ if ((zb<node.z1)||(za>node.z2)) return;
+
// at least some overlap, not a hole....
if ((za<=node.z1)&&(zb>=node.z2)) {
// delete whole node
@@ -763,14 +761,14 @@ public ZNode deleteNode(ZNode node, ZNode head) {
if (node==head) {
ZNode result= raiseUp(node);
return result;
+ }
+
+ int dir=node.compareTo(head);
+ if (dir<0) {
+ head.left=deleteNode(node,head.left);
} else {
- int dir=node.compareTo(head);
- if (dir<0) {
- head.left=deleteNode(node,head.left);
- } else {
- // if (dir==0) throw new Error("Duplicate z1 in deleteNode");
- head.right=deleteNode(node,head.right);
- }
+ // if (dir==0) throw new Error("Duplicate z1 in deleteNode");
+ head.right=deleteNode(node,head.right);
}
return head;
}
View
22 src/main/java/mikera/engine/PathFinder.java
@@ -264,18 +264,18 @@ private PathNode tryDir(PathNode node, byte dir) {
addNode(pn);
return pn;
- } else {
- if (target.travelled<=(cost+travelled)) return target;
-
- // we have found a shorter path to target
- target.last=node;
- target.travelled=cost+travelled;
- target.checkedDirCount=0;
-
- // ensure place on search list
- addNode(target);
- return target;
}
+
+ if (target.travelled<=(cost+travelled)) return target;
+
+ // we have found a shorter path to target
+ target.last=node;
+ target.travelled=cost+travelled;
+ target.checkedDirCount=0;
+
+ // ensure place on search list
+ addNode(target);
+ return target;
}
private void setFound(PathNode pn) {
View
17 src/main/java/mikera/engine/SparseArray.java
@@ -40,16 +40,15 @@ public Object getSubObject(int i) {
public T get(long index) {
if (shift==0) {
return (T)data[(int)index];
- } else {
- int si=(int)(index>>shift);
- Object d=data[si];
- if (d==null) return null;
- if (d instanceof SparseArray) {
- return ((SparseArray<T>)d).get(index-(((long)si)<<shift));
- } else {
- return (T)d;
- }
}
+
+ int si=(int)(index>>shift);
+ Object d=data[si];
+ if (d==null) return null;
+ if (d instanceof SparseArray) {
+ return ((SparseArray<T>)d).get(index-(((long)si)<<shift));
+ }
+ return (T)d;
}
@Override
View
3 src/main/java/mikera/engine/SparseGrid.java
@@ -32,9 +32,8 @@ public T get(int x, int y, int z) {
long zz=calculateIndex(x, y, z);
if (inRange(zz)) {
return data.get(zz);
- } else {
- return null;
}
+ return null;
}
@Override
View
7 src/main/java/mikera/net/Server.java
@@ -158,11 +158,10 @@ public boolean handleMessage(ByteBuffer buffer, Connection c) {
if (c.userTag==null) {
handleConnectRequest(buffer,c);
return true; // since message should be fully handled, can safely recycle
- } else {
- Data data=Data.create(buffer);
- queueIncomingMessage(data,(Integer)c.userTag);
- return false; // since we want to keep the ByteBuffer data.....
}
+ Data data=Data.create(buffer);
+ queueIncomingMessage(data,(Integer)c.userTag);
+ return false; // since we want to keep the ByteBuffer data.....
}
}
View
8 src/main/java/mikera/net/Util.java
@@ -117,11 +117,11 @@ public static int writeASCIIString(Data data, String src) {
data.appendByte((byte)(src.charAt(i)));
}
return hlen+len;
- } else {
- // send -1 for null string
- writeCompacted(data,-1);
- return 1;
}
+
+ // send -1 for null string
+ writeCompacted(data,-1);
+ return 1;
}
public static int readASCIIString(ByteBuffer bb, String[] dest) {
View
25 src/main/java/mikera/persistent/ASCIIString.java
@@ -95,18 +95,16 @@ public ASCIIString replace(byte oldByte, byte newByte) {
while ((pos < count) && (value[pos] != oldByte))
pos++;
-
- if (pos < count) {
- ASCIIString s = new ASCIIString(this);
- s.value[pos] = newByte;
- for (int i = pos + 1; i < count; i++) {
- if (s.value[pos] == oldByte)
- s.value[pos] = newByte;
- }
- return s;
- } else {
- return this;
+
+ if (pos>=count) return this;
+
+ ASCIIString s = new ASCIIString(this);
+ s.value[pos] = newByte;
+ for (int i = pos + 1; i < count; i++) {
+ if (s.value[pos] == oldByte)
+ s.value[pos] = newByte;
}
+ return s;
}
public boolean matches(String regex) {
@@ -181,9 +179,8 @@ public int compareTo(ASCIIString t) {
if (pos >= len1) {
if (pos >= len2) {
return 0;
- } else {
- return 1;
- }
+ }
+ return 1;
} else if (pos >= len2) {
return -1;
}
View
13 src/main/java/mikera/persistent/IntMap.java
@@ -418,9 +418,8 @@ private final int slotFromIndex(int index) {
newData[i]=node;
if (data.length==31) {
return new IMFullNode<V>(newData,shift);
- } else {
- return new IMBitMapNode<V>(newData,shift,bitmap|(1<<s));
}
+ return new IMBitMapNode<V>(newData,shift,bitmap|(1<<s));
}
@@ -624,12 +623,10 @@ protected int size() {
@Override
protected IMEntry<V> findNext(IMEntrySetIterator<V> it) {
- if (it.index>0) {
- return null;
- } else {
- it.index=1;
- return this;
- }
+ if (it.index>0) return null;
+
+ it.index=1;
+ return this;
}
@Override
View
5 src/main/java/mikera/persistent/LongMap.java
@@ -60,9 +60,8 @@ public boolean allowsNullKey() {
private long toKey(Object key) {
if (!(key instanceof Long)) {
throw new IllegalArgumentException("Key must be Long!");
- } else {
- return (Long)key;
- }
+ }
+ return (Long)key;
}
@Override

0 comments on commit cc06e26

Please sign in to comment.