diff --git a/.checkstyle b/.checkstyle
new file mode 100644
index 00000000..5783bc0d
--- /dev/null
+++ b/.checkstyle
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/src/main/java/com/github/pedrovgs/binarytree/BinaryNode.java b/src/main/java/com/github/pedrovgs/binarytree/BinaryNode.java
index 0db25d25..a7693715 100644
--- a/src/main/java/com/github/pedrovgs/binarytree/BinaryNode.java
+++ b/src/main/java/com/github/pedrovgs/binarytree/BinaryNode.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.github.pedrovgs.binarytree;
/**
@@ -63,14 +64,24 @@ public boolean hasRight() {
}
@Override public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof BinaryNode)) return false;
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof BinaryNode)) {
+ return false;
+ }
BinaryNode that = (BinaryNode) o;
- if (!data.equals(that.data)) return false;
- if (left != null ? !left.equals(that.left) : that.left != null) return false;
- if (right != null ? !right.equals(that.right) : that.right != null) return false;
+ if (!data.equals(that.data)) {
+ return false;
+ }
+ if (left != null ? !left.equals(that.left) : that.left != null) {
+ return false;
+ }
+ if (right != null ? !right.equals(that.right) : that.right != null) {
+ return false;
+ }
return true;
}
diff --git a/src/main/java/com/github/pedrovgs/equations/Grade2Equation.java b/src/main/java/com/github/pedrovgs/equations/Grade2Equation.java
new file mode 100644
index 00000000..522b6ab6
--- /dev/null
+++ b/src/main/java/com/github/pedrovgs/equations/Grade2Equation.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.github.pedrovgs.equations;
+
+/**
+ * This class contains an algorithm that solves 2nd grade equations.
+ * @author ShoeMaker
+ *
+ */
+
+public class Grade2Equation {
+
+ /**
+ * Method solves 2nd grade equations.
+ * @param a from a*x^2
+ * @param b from b*x
+ * @param c the fixed number
+ * @return An array with the solution/solutions of the equation.
+ * @throws IllegalArgumentException there is no Real solution to the equation.
+ */
+ public Double[] solve(double a, double b, double c) {
+
+ double d = (b * b) - (4 * a * c);
+ if (d < 0) {
+ throw new IllegalArgumentException("There is no Real solution to this equation.");
+ }
+ Double[] x = new Double[2];
+ x[0] = (-b + Math.sqrt(d)) / (2 * a);
+ x[1] = (-b - Math.sqrt(d)) / (2 * a);
+ return x;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/pedrovgs/files/TxtToList.java b/src/main/java/com/github/pedrovgs/files/TxtToList.java
new file mode 100644
index 00000000..17215079
--- /dev/null
+++ b/src/main/java/com/github/pedrovgs/files/TxtToList.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.github.pedrovgs.files;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * This class contains an algorithm that reads txt files and turns them to Lists for further use.
+ * @author ShoeMaker
+ *
+ */
+
+public class TxtToList {
+
+ /**
+ * Method gets a txt file's path. It opens the file and reads it,
+ * then tries to get the txt lines and return them as a List.
+ * @param filepath The file's path.
+ * @return A List with the file's lines.
+ * @throws IllegalArgumentException when an IOException occurs or the file is empty.
+ */
+ public List readFileToList(String filepath) {
+
+ List datas = new ArrayList();
+ BufferedReader br = null;
+ String line = null;
+ try {
+ br = new BufferedReader(new FileReader(filepath));
+ line = br.readLine();
+ while (line != null) {
+ datas.add(line);
+ line = br.readLine();
+ }
+ br.close();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Something went wrong. Wrong path or file doesn't exist.");
+ }
+ if (datas.size() == 0) {
+ throw new IllegalArgumentException("File was empty.");
+ }
+ return datas;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/pedrovgs/linkedlist/ListNode.java b/src/main/java/com/github/pedrovgs/linkedlist/ListNode.java
index 377701e0..6b49855c 100644
--- a/src/main/java/com/github/pedrovgs/linkedlist/ListNode.java
+++ b/src/main/java/com/github/pedrovgs/linkedlist/ListNode.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.github.pedrovgs.linkedlist;
/**
@@ -50,12 +51,18 @@ public void setNext(ListNode next) {
}
@Override public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof ListNode)) return false;
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof ListNode)) {
+ return false;
+ }
ListNode listNode = (ListNode) o;
- if (!data.equals(listNode.data)) return false;
+ if (!data.equals(listNode.data)) {
+ return false;
+ }
return true;
}
diff --git a/src/main/java/com/github/pedrovgs/pair/Pair.java b/src/main/java/com/github/pedrovgs/pair/Pair.java
index 58a3bce7..affd0c34 100644
--- a/src/main/java/com/github/pedrovgs/pair/Pair.java
+++ b/src/main/java/com/github/pedrovgs/pair/Pair.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.github.pedrovgs.pair;
/**
@@ -31,13 +32,21 @@ public Pair(A a, B b) {
}
@Override public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Pair)) return false;
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Pair)) {
+ return false;
+ }
Pair pair = (Pair) o;
- if (!a.equals(pair.a)) return false;
- if (!b.equals(pair.b)) return false;
+ if (!a.equals(pair.a)) {
+ return false;
+ }
+ if (!b.equals(pair.b)) {
+ return false;
+ }
return true;
}
diff --git a/src/main/java/com/github/pedrovgs/statistics/Sample.java b/src/main/java/com/github/pedrovgs/statistics/Sample.java
new file mode 100644
index 00000000..92bba7f1
--- /dev/null
+++ b/src/main/java/com/github/pedrovgs/statistics/Sample.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.github.pedrovgs.statistics;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+
+
+public class Sample {
+
+ private List