TrianAlgorithm is converted from ObjectiveC to Java version

There are no test cases to test. Please someone do a code review.