Skip to content
Snippets Groups Projects
Commit b0f0ba96 authored by Jakub Kolman's avatar Jakub Kolman
Browse files

[#81] documentation: added java docs and resolved lint wanrings

parent 04d278fb
No related branches found
No related tags found
No related merge requests found
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cz.fidentis.analyst.procrustes;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.procrustes.exceptions.ProcrustesAnalysisException;
import cz.fidentis.analyst.procrustes.utils.ProcrustesAnalysisUtils;
import java.util.List;
/**
*
* @author kubok
* @author Jakub Kolman
*/
public class ProcrustesAnalysis {
public ProcrustesAnalysis() {
private final List<FeaturePoint> orderedFpList1;
private final List<FeaturePoint> orderedFpList2;
/**
*
* @param fpList1
* @param fpList2
* @throws ProcrustesAnalysisException
*/
public ProcrustesAnalysis(List<FeaturePoint> fpList1, List<FeaturePoint> fpList2) throws ProcrustesAnalysisException {
if (fpList1.size() != fpList2.size()) {
throw new ProcrustesAnalysisException("Lists of feature points do not have the same size");
}
orderedFpList1 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList1);
orderedFpList2 = ProcrustesAnalysisUtils.sortByFeaturePointType(fpList2);
if (!ProcrustesAnalysisUtils.checkfeaturePointsType(orderedFpList1, orderedFpList2)) {
throw new ProcrustesAnalysisException("Lists of feature points do not have the same feature point types");
}
}
/**
* Calculate scaling ratio of how much the appropriate object corresponding to the second feature
* point list has to be scale up or shrunk.
*
* If returned ratioValue is greater 1 then it means that the second object should be scaled up ratioValue times.
* If returned ratioValue is smaller 1 than the second object should be shrunk.
*
* @return ratioValue
*/
private double calculateScalingValue() {
double[] distancesOfList1 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList1);
double[] distancesOfList2 = ProcrustesAnalysisUtils.calculateMeanDistancesFromOrigin(orderedFpList2);
double[] ratioArray = new double[distancesOfList1.length];
double ratioValue = 0;
for (int i = 0; i < distancesOfList1.length; i++) {
ratioArray[i] += distancesOfList1[i] / distancesOfList2[i];
}
for (double ratio: ratioArray) {
ratioValue += ratio;
}
return ratioValue / distancesOfList1.length;
}
}
package cz.fidentis.analyst.feature;
import java.io.Serializable;
import java.util.Objects;
import javax.vecmath.Point3d;
/**
*
* @author Jakub Kolman
* @author Jakub Kolman
*/
public class FeaturePoint implements Serializable {
......@@ -14,8 +15,8 @@ public class FeaturePoint implements Serializable {
/**
* Constructor.
*
* @param x Location x
*
* @param x Location x
* @param y Location y
* @param z Location z
* @param featurePointType Original type
......@@ -24,11 +25,11 @@ public class FeaturePoint implements Serializable {
this.position = new Point3d(x, y, z);
this.featurePointType = featurePointType;
}
public Point3d getPosition() {
return position;
}
public double getX() {
return position.x;
}
......@@ -44,5 +45,42 @@ public class FeaturePoint implements Serializable {
public FeaturePointType getFeaturePointType() {
return featurePointType;
}
@Override
public boolean equals(Object o) {
// self check
if (this == o) {
return true;
}
// null check
if (o == null) {
return false;
}
// type check and cast
if (getClass() != o.getClass()) {
return false;
}
FeaturePoint fp = (FeaturePoint) o;
// field comparison
return Objects.equals(position.x, fp.position.x)
&& Objects.equals(position.y, fp.position.y)
&& Objects.equals(position.z, fp.position.z)
&& Objects.equals(featurePointType.getCode(), fp.featurePointType.getCode())
&& Objects.equals(featurePointType.getInfo(), fp.featurePointType.getInfo())
&& Objects.equals(featurePointType.getName(), fp.featurePointType.getName())
&& Objects.equals(featurePointType.getType(), fp.featurePointType.getType());
}
/**
* generated hash code function
*
* @return
*/
@Override
public int hashCode() {
int hash = 5;
hash = 23 * hash + Objects.hashCode(this.position);
hash = 23 * hash + Objects.hashCode(this.featurePointType);
return hash;
}
}
......@@ -13,6 +13,14 @@ public class FeaturePointType implements Serializable {
private final String info;
private final String code;
/**
* Constructor
*
* @param type
* @param name
* @param info
* @param code
*/
public FeaturePointType(int type, String name, String info, String code) {
this.type = type;
this.name = name;
......
......@@ -10,7 +10,7 @@ import java.util.Map;
*
* @author Jakub Kolman
*/
public class FeaturePointTypeProvider {
public final class FeaturePointTypeProvider {
private final Map<Integer, FeaturePointType> featurePointTypesById;
private final Map<String, FeaturePointType> featurePointTypesByCode;
......@@ -21,7 +21,8 @@ public class FeaturePointTypeProvider {
*/
private static class InstanceHolder {
public static FeaturePointTypeProvider instance = new FeaturePointTypeProvider();
public static final FeaturePointTypeProvider INSTANCE = new FeaturePointTypeProvider();
}
/**
......@@ -39,7 +40,7 @@ public class FeaturePointTypeProvider {
* @return
*/
public static FeaturePointTypeProvider getInstance() {
return InstanceHolder.instance;
return InstanceHolder.INSTANCE;
}
/**
......
package cz.fidentis.analyst.feature.utils;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
/**
* Deprecated class
*
* @author Jakub Kolman
*/
public class FileResourcesUtils {
/**
* main method
*
* @param args
* @throws IOException
* @throws URISyntaxException
*/
public static void main(String[] args) throws IOException, URISyntaxException {
FileResourcesUtils app = new FileResourcesUtils();
......@@ -28,8 +44,13 @@ public class FileResourcesUtils {
}
// get a file from the resources folder
// works everywhere, IDEA, unit test and JAR file.
/**
* get a file from the resources folder
* works everywhere, IDEA, unit test and JAR file.
*
* @param fileName
* @return
*/
public InputStream getFileFromResourceAsStream(String fileName) {
// The class loader that loaded the class
......@@ -45,12 +66,14 @@ public class FileResourcesUtils {
}
/*
The resource URL is not working in the JAR
If we try to access a file that is inside a JAR,
It throws NoSuchFileException (linux), InvalidPathException (Windows)
Resource URL Sample: file:java-io.jar!/json/file1.json
/**
* The resource URL is not working in the JAR If we try to access a file
* that is inside a JAR, It throws NoSuchFileException (linux),
* InvalidPathException (Windows)
*
* Resource URL Sample: file:java-io.jar!/json/file1.json
*
* @param fileName
*/
private File getFileFromResource(String fileName) throws URISyntaxException {
......@@ -67,17 +90,35 @@ public class FileResourcesUtils {
}
// get a file from the resources folder
// works everywhere, IDEA, unit test and JAR file.
/**
* get a file from the resources folder works everywhere, IDEA, unit test
* and JAR file.
*
* @param path
* @param fileName
* @return
* @throws FileNotFoundException
*/
public InputStream getFileAsStream(String path, String fileName) throws FileNotFoundException {
return new FileInputStream(getFile(path, fileName));
}
/**
* get File from path, file name
*
* @param path
* @param fileName
* @return
*/
private File getFile(String path, String fileName) {
return new File(path, fileName);
}
// print input stream
/**
* print input stream
*
* @param is
*/
private static void printInputStream(InputStream is) {
try (InputStreamReader streamReader
= new InputStreamReader(is, StandardCharsets.UTF_8);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment