Permalink
Browse files

Adopted Gradle as build system.

  • Loading branch information...
1 parent 6ae50e0 commit 3cb4db98b43cd79b7bbc39d506fab9b74c39ed25 @decitrig committed Oct 27, 2011
Showing with 54 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +27 −0 build.gradle
  3. +19 −0 src/net/decitrig/galaxy/Galaxy.java
View
@@ -0,0 +1,8 @@
+# eclipse stuff
+.classpath
+.project
+.settings
+
+# gradle stuf
+.gradle
+build
View
@@ -0,0 +1,27 @@
+apply plugin: 'java'
+apply plugin: 'eclipse'
+
+sourceCompatibility = 1.7
+version = '1'
+
+repositories {
+ mavenCentral()
+}
+
+sourceSets {
+ main {
+ java {
+ srcDir 'src'
+ }
+ }
+ test {
+ java {
+ srcDir 'junit'
+ }
+ }
+}
+
+dependencies {
+ compile group: 'com.google.guava', name: 'guava', version: '10.0.1'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
@@ -1,18 +1,24 @@
package net.decitrig.galaxy;
import java.awt.geom.Point2D;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** Represents a single galaxy. */
public class Galaxy {
+ private static final AtomicInteger nextId = new AtomicInteger(0);
+
+ private final int id;
private final int mass;
private final ReadWriteLock positionLock = new ReentrantReadWriteLock();
private double x;
private double y;
public Galaxy(int mass, double x, double y) {
+ this.id = nextId.getAndIncrement();
this.mass = mass;
this.x = x;
this.y = y;
@@ -30,4 +36,17 @@ Point2D location() {
public int getMass() {
return mass;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Galaxy)) {
+ return false;
+ }
+ return ((Galaxy) obj).id == this.id;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
}

0 comments on commit 3cb4db9

Please sign in to comment.