refactor: format code and fix typos
This commit is contained in:
parent
60bb026f8a
commit
8e8e14d1c2
@ -3,6 +3,7 @@ package src.main.java.com.conversions;
|
||||
public class AnyBaseToDecimal {
|
||||
/**
|
||||
* This method produces a decimal value of any given input number of any base
|
||||
*
|
||||
* @param inpNum String of which we need the decimal value and base in integer format
|
||||
* @return string format of the decimal value
|
||||
*/
|
||||
@ -24,6 +25,7 @@ public class AnyBaseToDecimal {
|
||||
|
||||
/**
|
||||
* This method produces integer value of the input character and returns it
|
||||
*
|
||||
* @param c Char of which we need the integer value of
|
||||
* @return integer value of input char
|
||||
*/
|
||||
@ -31,8 +33,7 @@ public class AnyBaseToDecimal {
|
||||
private static int valOfChar(char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return (int) c - '0';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (int) c - 'A' + 10;
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ package src.main.java.com.conversions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DecimalToAnyBase {
|
||||
|
||||
/**
|
||||
* This method produces a String value of any given input decimal in any base
|
||||
*
|
||||
* @param inp Decimal of which we need the value in base in String format
|
||||
* @param base base in which we want the decimal value to be converted into
|
||||
* @return string format of the converted value in the given base
|
||||
*/
|
||||
|
||||
public String convertToAnyBase(int inp, int base) {
|
||||
ArrayList<Character> charArr = new ArrayList<>();
|
||||
|
||||
@ -28,6 +29,7 @@ public class DecimalToAnyBase {
|
||||
|
||||
/**
|
||||
* This method produces character value of the input integer and returns it
|
||||
*
|
||||
* @param num integer of which we need the character value of
|
||||
* @return character value of input integer
|
||||
*/
|
||||
|
@ -3,11 +3,12 @@ package src.main.java.com.conversions;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class DecimalToHexadecimal {
|
||||
private static final char hexChars[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
private static final char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
private static final BigInteger valueHex = new BigInteger("16");
|
||||
|
||||
/**
|
||||
* This method converts and decimal number to a Hexadecimal number
|
||||
*
|
||||
* @param decimalStr
|
||||
* @return hexadecimal number
|
||||
*/
|
||||
|
@ -3,11 +3,12 @@ package src.main.java.com.conversions;
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class DecimalToOctal {
|
||||
private static final char octalChars[] = {'0','1','2','3','4','5','6','7'};
|
||||
private static final char[] octalChars = {'0', '1', '2', '3', '4', '5', '6', '7'};
|
||||
private static final BigInteger valueOctal = new BigInteger("8");
|
||||
|
||||
/**
|
||||
* This method converts and decimal number to a octal number
|
||||
*
|
||||
* @param decimalStr
|
||||
* @return octal number
|
||||
*/
|
||||
|
@ -2,9 +2,10 @@ package src.main.java.com.dataStructures;
|
||||
|
||||
/**
|
||||
* Binary tree for general value type, without redundancy
|
||||
* @author RICARDO
|
||||
*
|
||||
* @param <T> root data
|
||||
*/
|
||||
|
||||
public class BinaryTree<T extends Comparable> {
|
||||
private final T data;
|
||||
private BinaryTree right, // the upper binary tree
|
||||
@ -21,7 +22,8 @@ public class BinaryTree<T extends Comparable> {
|
||||
|
||||
/**
|
||||
* inserts a new value in it's correspondant place
|
||||
* @param newDataValue value of the new banary tree to add on this tree
|
||||
*
|
||||
* @param newDataValue value of the new binary tree to add on this tree
|
||||
*/
|
||||
public void insert(T newDataValue) {
|
||||
this.insert(new BinaryTree(newDataValue));
|
||||
@ -29,6 +31,7 @@ public class BinaryTree<T extends Comparable> {
|
||||
|
||||
/**
|
||||
* inserts a new binary tree in it's correspondant place
|
||||
*
|
||||
* @param newData new value to add on this tree
|
||||
*/
|
||||
public void insert(BinaryTree newData) {
|
||||
@ -51,8 +54,9 @@ public class BinaryTree<T extends Comparable> {
|
||||
|
||||
/**
|
||||
* search and specific value on the tree
|
||||
*
|
||||
* @param data Searched value
|
||||
* @return Binary tree wich contains the value, null if it doesn't exist
|
||||
* @return Binary tree which contains the value, null if it doesn't exist
|
||||
*/
|
||||
public BinaryTree search(T data) {
|
||||
int cpr = data.compareTo(this.data); //new value comparission respect to actual value
|
||||
@ -72,6 +76,7 @@ public class BinaryTree<T extends Comparable> {
|
||||
|
||||
/**
|
||||
* Checks if the data value exist in the tree
|
||||
*
|
||||
* @param data data to be searched
|
||||
* @return true if this tree contains the data value, false if not.
|
||||
*/
|
||||
@ -81,6 +86,7 @@ public class BinaryTree<T extends Comparable> {
|
||||
|
||||
/**
|
||||
* uses recursive black magic to print this tree in console
|
||||
*
|
||||
* @param tabCounter prev tabs
|
||||
*/
|
||||
private void print(int tabCounter) {
|
||||
|
@ -15,7 +15,6 @@ import java.util.*;
|
||||
* <p>
|
||||
* 2. quickly query two elements whether contained in the same set, requiring about O(1) time.
|
||||
*
|
||||
* @author yangxf
|
||||
*/
|
||||
public class DisjointSet<T> implements Serializable {
|
||||
private static final long serialVersionUID = 3134700471905625636L;
|
||||
|
@ -42,6 +42,7 @@ public class SimplexNoise {
|
||||
|
||||
/**
|
||||
* Generates a height map.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param width width
|
||||
@ -70,6 +71,7 @@ public class SimplexNoise {
|
||||
|
||||
/**
|
||||
* Generates a two dimensional noise.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @return the generated noise
|
||||
@ -88,6 +90,7 @@ public class SimplexNoise {
|
||||
|
||||
/**
|
||||
* Generates a three dimensional noise.
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
|
@ -14,7 +14,7 @@ public class SimplexNoiseOctave {
|
||||
new Gradient(1, 0, -1), new Gradient(-1, 0, -1), new Gradient(0, 1, 1),
|
||||
new Gradient(0, -1, 1), new Gradient(0, 1, -1), new Gradient(0, -1, -1)
|
||||
};
|
||||
private static final short P_SUPPLY[] = {
|
||||
private static final short[] P_SUPPLY = {
|
||||
|
||||
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225,
|
||||
140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148,
|
||||
|
@ -16,7 +16,6 @@ import java.util.function.Function;
|
||||
* <p>
|
||||
* The accuracy rate depends on capacity and hash functions.
|
||||
*
|
||||
* @author yangxf
|
||||
*/
|
||||
public class BloomFilter implements Serializable {
|
||||
private static final long serialVersionUID = -4466610350741278658L;
|
||||
|
@ -15,7 +15,7 @@ public final class LinearSearch {
|
||||
* @param <T> is any comparable type
|
||||
* @return index of the element
|
||||
*/
|
||||
public static <T extends Comparable<T>> int findIndex(T array[], T key) {
|
||||
public static <T extends Comparable<T>> int findIndex(T[] array, T key) {
|
||||
return search(array, key);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public final class LinearSearch {
|
||||
* @param key The element you are looking for
|
||||
* @return the location of the key or -1 if the element is not found
|
||||
**/
|
||||
private static <T extends Comparable<T>> int search(T array[], T key){
|
||||
private static <T extends Comparable<T>> int search(T[] array, T key){
|
||||
for(int i = 0; i < array.length;i++) {
|
||||
if (array[i].compareTo(key) == 0){
|
||||
return i;
|
||||
|
@ -9,7 +9,6 @@ import static src.main.java.com.sorts.SortUtils.swap;
|
||||
|
||||
public class HeapSort {
|
||||
|
||||
|
||||
private static class Heap<T extends Comparable<T>> {
|
||||
/**
|
||||
* Array to store heap
|
||||
|
@ -5,7 +5,6 @@ import static src.main.java.com.sorts.SortUtils.swap;
|
||||
|
||||
public class QuickSort {
|
||||
|
||||
|
||||
/**
|
||||
* This method implements the Generic Quick Sort
|
||||
*
|
||||
|
@ -8,7 +8,7 @@ public class StoogeSort {
|
||||
/**
|
||||
* This method implements recursion StoogeSort
|
||||
*
|
||||
* @param int[] array to store number elements
|
||||
* @param arr array to store number elements
|
||||
* @param f first element in the array
|
||||
* @param l last element in the array
|
||||
*/
|
||||
|
@ -3,5 +3,5 @@ package src.main.java.com.types;
|
||||
@FunctionalInterface
|
||||
public interface Sort<T> {
|
||||
|
||||
public <T extends Comparable<T>> T[] sort(T[] array);
|
||||
<T extends Comparable<T>> T[] sort(T[] array);
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package src.main.java.com.dataStructures;
|
||||
package src.test.java.com.dataStructures;
|
||||
|
||||
import org.junit.Test;
|
||||
import src.main.java.com.dataStructures.BinaryTree;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RICARDO
|
||||
*/
|
||||
public class BinaryTreeTest {
|
||||
|
||||
public BinaryTreeTest() {
|
||||
@ -16,15 +14,16 @@ public class BinaryTreeTest {
|
||||
* Test of insert method, of class BinaryTree.
|
||||
*/
|
||||
@Test
|
||||
public void testInsert_BinaryTree() {
|
||||
public void testInsertBinaryTree() {
|
||||
System.out.println("insert");
|
||||
BinaryTree<String> lowerdata = new BinaryTree<>("1");
|
||||
BinaryTree<String> upperdata = new BinaryTree<>("3");
|
||||
BinaryTree<String> lowerData = new BinaryTree<>("1");
|
||||
BinaryTree<String> upperData = new BinaryTree<>("3");
|
||||
BinaryTree<String> instance = new BinaryTree<>("2");
|
||||
instance.insert(lowerdata);
|
||||
instance.insert(upperdata);
|
||||
String proof = instance.getLeft().toString()+instance.toString()+instance.getRight().toString();
|
||||
System.out.println(proof);
|
||||
instance.insert(lowerData);
|
||||
instance.insert(upperData);
|
||||
String proof = instance.getLeft().toString()
|
||||
+ instance.toString()
|
||||
+ instance.getRight().toString();
|
||||
assertEquals("123", proof);
|
||||
}
|
||||
|
||||
@ -36,10 +35,10 @@ public class BinaryTreeTest {
|
||||
System.out.println("search");
|
||||
BinaryTree<Integer> instance = new BinaryTree<>(5);
|
||||
for (int i = 1; i < 10; i++) {
|
||||
instance.insert(new Integer(i));
|
||||
instance.insert(i);
|
||||
}
|
||||
BinaryTree result = instance.search(new Integer(1));
|
||||
assertEquals(new Integer(1), result.getData());
|
||||
BinaryTree result = instance.search(1);
|
||||
assertEquals(1, result.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +53,6 @@ public class BinaryTreeTest {
|
||||
}
|
||||
|
||||
boolean result = instance.contains(2) && instance.contains(11);
|
||||
assertEquals(false, result);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user