Fix checkstyle errors and delete unused methods for high coverage

This commit is contained in:
cugurlu
2019-03-31 00:50:21 +01:00
parent cc236c46b6
commit 383d505f52
2 changed files with 130 additions and 150 deletions

View File

@@ -4,127 +4,130 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class InputValidator { public class InputValidator {
private static final List<InputItem> inputItems = Arrays.asList( private static final List<InputItem> inputItems = Arrays.asList(
new InputItem("input_location", false, "Chicago"), new InputItem("input_location", false, "Chicago"),
new InputItem("input_location_mode", false, "1"), new InputItem("input_location_mode", false, "1"),
new InputItem("input_size", false, "3"), new InputItem("input_size", false, "3"),
new InputItem("input_income", false, "3000"), new InputItem("input_income", false, "3000"),
new InputItem("input_population", false, "1"), new InputItem("input_population", false, "1"),
new InputItem("input_changed", false, "0"), new InputItem("input_changed", false, "0"),
new InputItem("input_footprint_household_adults", false, "0"), new InputItem("input_footprint_household_adults", false, "0"),
new InputItem("input_footprint_household_children", false, "0"), new InputItem("input_footprint_household_children", false, "0"),
new InputItem("input_footprint_transportation_num_vehicles", false, "1"), new InputItem("input_footprint_transportation_num_vehicles", false, "10"),
new InputItem("input_footprint_transportation_miles1", false, "16100", false), new InputItem("input_footprint_transportation_miles1", false, "16100", false),
new InputItem("input_footprint_transportation_mpg1", false, "22", false), new InputItem("input_footprint_transportation_mpg1", false, "22", false),
new InputItem("input_footprint_transportation_fuel1", false, "0", false), new InputItem("input_footprint_transportation_fuel1", false, "0", false),
new InputItem("input_footprint_transportation_miles2", false, "0", false), new InputItem("input_footprint_transportation_miles2", false, "0", false),
new InputItem("input_footprint_transportation_fuel2", false, "0", false), new InputItem("input_footprint_transportation_fuel2", false, "0", false),
new InputItem("input_footprint_transportation_mpg2", false, "0", false), new InputItem("input_footprint_transportation_mpg2", false, "0", false),
new InputItem("input_footprint_transportation_miles3", false, "0", false), new InputItem("input_footprint_transportation_miles3", false, "0", false),
new InputItem("input_footprint_transportation_fuel3", false, "0", false), new InputItem("input_footprint_transportation_fuel3", false, "0", false),
new InputItem("input_footprint_transportation_mpg3", false, "0", false), new InputItem("input_footprint_transportation_mpg3", false, "0", false),
new InputItem("input_footprint_transportation_miles4", false, "0", false), new InputItem("input_footprint_transportation_miles4", false, "0", false),
new InputItem("input_footprint_transportation_fuel4", false, "0", false), new InputItem("input_footprint_transportation_fuel4", false, "0", false),
new InputItem("input_footprint_transportation_mpg4", false, "0", false), new InputItem("input_footprint_transportation_mpg4", false, "0", false),
new InputItem("input_footprint_transportation_miles5", false, "0", false), new InputItem("input_footprint_transportation_miles5", false, "0", false),
new InputItem("input_footprint_transportation_fuel5", false, "0", false), new InputItem("input_footprint_transportation_fuel5", false, "0", false),
new InputItem("input_footprint_transportation_mpg5", false, "0", false), new InputItem("input_footprint_transportation_mpg5", false, "0", false),
new InputItem("input_footprint_transportation_miles6", false, "0", false), new InputItem("input_footprint_transportation_miles6", false, "0", false),
new InputItem("input_footprint_transportation_fuel6", false, "0", false), new InputItem("input_footprint_transportation_fuel6", false, "0", false),
new InputItem("input_footprint_transportation_mpg6", false, "0", false), new InputItem("input_footprint_transportation_mpg6", false, "0", false),
new InputItem("input_footprint_transportation_miles7", false, "0", false), new InputItem("input_footprint_transportation_miles7", false, "0", false),
new InputItem("input_footprint_transportation_fuel7", false, "0", false), new InputItem("input_footprint_transportation_fuel7", false, "0", false),
new InputItem("input_footprint_transportation_mpg7", false, "0", false), new InputItem("input_footprint_transportation_mpg7", false, "0", false),
new InputItem("input_footprint_transportation_miles8", false, "0", false), new InputItem("input_footprint_transportation_miles8", false, "0", false),
new InputItem("input_footprint_transportation_fuel8", false, "0", false), new InputItem("input_footprint_transportation_fuel8", false, "0", false),
new InputItem("input_footprint_transportation_mpg8", false, "0", false), new InputItem("input_footprint_transportation_mpg8", false, "0", false),
new InputItem("input_footprint_transportation_miles9", false, "0", false), new InputItem("input_footprint_transportation_miles9", false, "0", false),
new InputItem("input_footprint_transportation_fuel9", false, "0", false), new InputItem("input_footprint_transportation_fuel9", false, "0", false),
new InputItem("input_footprint_transportation_mpg9", false, "0", false), new InputItem("input_footprint_transportation_mpg9", false, "0", false),
new InputItem("input_footprint_transportation_miles10", false, "0", false), new InputItem("input_footprint_transportation_miles10", false, "0", false),
new InputItem("input_footprint_transportation_fuel10", false, "0", false), new InputItem("input_footprint_transportation_fuel10", false, "0", false),
new InputItem("input_footprint_transportation_mpg10", false, "0", false), new InputItem("input_footprint_transportation_mpg10", false, "0", false),
new InputItem("input_footprint_transportation_groundtype", false, "0"), new InputItem("input_footprint_transportation_groundtype", false, "0"),
new InputItem("input_footprint_transportation_publictrans", false, "436"), new InputItem("input_footprint_transportation_publictrans", false, "436"),
new InputItem("input_footprint_transportation_bus", false, "174"), new InputItem("input_footprint_transportation_bus", false, "174"),
new InputItem("input_footprint_transportation_transit", false, "131"), new InputItem("input_footprint_transportation_transit", false, "131"),
new InputItem("input_footprint_transportation_commuter", false, "87"), new InputItem("input_footprint_transportation_commuter", false, "87"),
new InputItem("input_footprint_transportation_intercity", false, "44"), new InputItem("input_footprint_transportation_intercity", false, "44"),
new InputItem("input_footprint_transportation_airtype", false, "0"), new InputItem("input_footprint_transportation_airtype", false, "0"),
new InputItem("input_footprint_transportation_airtotal", false, "6"), new InputItem("input_footprint_transportation_airtotal", false, "6"),
new InputItem("input_footprint_transportation_airshort", false, "3"), new InputItem("input_footprint_transportation_airshort", false, "3"),
new InputItem("input_footprint_transportation_airmedium", false, "3"), new InputItem("input_footprint_transportation_airmedium", false, "3"),
new InputItem("input_footprint_transportation_airlong", false, "0"), new InputItem("input_footprint_transportation_airlong", false, "0"),
new InputItem("input_footprint_transportation_airextended", false, "0"), new InputItem("input_footprint_transportation_airextended", false, "0"),
new InputItem("input_footprint_housing_cdd", false, "40000"), new InputItem("input_footprint_housing_cdd", false, "40000"),
new InputItem("input_footprint_housing_hdd", false, "40000"), new InputItem("input_footprint_housing_hdd", false, "40000"),
new InputItem("input_footprint_housing_electricity_type", false, "0"), new InputItem("input_footprint_housing_electricity_type", false, "0"),
new InputItem("input_footprint_housing_electricity_dollars", false, "1200"), new InputItem("input_footprint_housing_electricity_dollars", false, "1200"),
new InputItem("input_footprint_housing_electricity_kwh", false, "12632"), new InputItem("input_footprint_housing_electricity_kwh", false, "12632"),
new InputItem("input_footprint_housing_cleanpercent", false, "0"), new InputItem("input_footprint_housing_cleanpercent", false, "0"),
new InputItem("input_footprint_housing_naturalgas_type", false, "0"), new InputItem("input_footprint_housing_naturalgas_type", false, "0"),
new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"), new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"),
new InputItem("input_footprint_housing_naturalgas_therms", false, "472"), new InputItem("input_footprint_housing_naturalgas_therms", false, "472"),
new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"), new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"),
new InputItem("input_footprint_housing_heatingoil_type", false, "0"), new InputItem("input_footprint_housing_heatingoil_type", false, "0"),
new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"), new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"),
new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"), new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"),
new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"), new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"),
new InputItem("input_footprint_housing_squarefeet", false, "1850"), new InputItem("input_footprint_housing_squarefeet", false, "1850"),
new InputItem("input_footprint_housing_watersewage", false, "100"), new InputItem("input_footprint_housing_watersewage", false, "100"),
new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"), new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"),
new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"), new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"),
new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"), new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"),
new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"), new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"),
new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"), new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"),
new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"), new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"),
new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"), new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"),
new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"), new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"),
new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"), new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"),
new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"), new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"),
new InputItem("input_footprint_shopping_food_meattype", true, "0"), new InputItem("input_footprint_shopping_food_meattype", true, "0"),
new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"), new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"),
new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"), new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"),
new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"), new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"),
new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"), new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"),
new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"), new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"),
new InputItem("input_footprint_shopping_food_cereals", true, "4.1"), new InputItem("input_footprint_shopping_food_cereals", true, "4.1"),
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"), new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"), new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"), new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
new InputItem("input_footprint_shopping_goods_default_furnitureappliances", false, "1310"), new InputItem("input_footprint_shopping_goods_default_furnitureappliances",
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"), false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_entertainment", false, "1310"), new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_entertainment",
new InputItem("input_footprint_shopping_goods_default_other_personalcare", false, "1310"), false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_autoparts", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"), new InputItem(
new InputItem("input_footprint_shopping_goods_type", false, "1310"), "input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
new InputItem("input_footprint_shopping_goods_total", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_autoparts",
new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"), false, "1310"),
new InputItem("input_footprint_shopping_goods_clothing", false, "391"), new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
new InputItem("input_footprint_shopping_goods_other_type", false, "0"), new InputItem("input_footprint_shopping_goods_type", false, "1310"),
new InputItem("input_footprint_shopping_goods_other_total", false, "1311"), new InputItem("input_footprint_shopping_goods_total", false, "1310"),
new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"), new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"),
new InputItem("input_footprint_shopping_goods_other_office", false, "38"), new InputItem("input_footprint_shopping_goods_clothing", false, "391"),
new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"), new InputItem("input_footprint_shopping_goods_other_type", false, "0"),
new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"), new InputItem("input_footprint_shopping_goods_other_total", false, "1311"),
new InputItem("input_footprint_shopping_goods_other_medical", false, "172"), new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"),
new InputItem("input_footprint_shopping_services_type", false, "0"), new InputItem("input_footprint_shopping_goods_other_office", false, "38"),
new InputItem("input_footprint_shopping_services_total", false, "2413"), new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"),
new InputItem("input_footprint_shopping_services_healthcare", false, "841"), new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"),
new InputItem("input_footprint_shopping_services_education", false, "122"), new InputItem("input_footprint_shopping_goods_other_medical", false, "172"),
new InputItem("input_footprint_shopping_services_communications", false, "163"), new InputItem("input_footprint_shopping_services_type", false, "0"),
new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"), new InputItem("input_footprint_shopping_services_total", false, "2413"),
new InputItem("input_footprint_shopping_services_finance", false, "566"), new InputItem("input_footprint_shopping_services_healthcare", false, "841"),
new InputItem("input_footprint_shopping_services_household", false, "28"), new InputItem("input_footprint_shopping_services_education", false, "122"),
new InputItem("input_footprint_shopping_services_charity", false, "146"), new InputItem("input_footprint_shopping_services_communications", false, "163"),
new InputItem("input_footprint_shopping_services_miscservices", false, "114"), new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"),
new InputItem("internal_state_abbreviation", false, "US") new InputItem("input_footprint_shopping_services_finance", false, "566"),
new InputItem("input_footprint_shopping_services_household", false, "28"),
new InputItem("input_footprint_shopping_services_charity", false, "146"),
new InputItem("input_footprint_shopping_services_miscservices", false, "114"),
new InputItem("internal_state_abbreviation", false, "US")
); );
/** /**
@@ -149,7 +152,7 @@ public class InputValidator {
item = inputItem; item = inputItem;
} }
} }
if (Objects.requireNonNull(item).getFloat()) { if (item.getFloat()) {
try { try {
Float.parseFloat(value); Float.parseFloat(value);
} catch (NumberFormatException | NullPointerException nfe) { } catch (NumberFormatException | NullPointerException nfe) {

View File

@@ -5,20 +5,13 @@ import greenify.server.InputValidator;
import lombok.Data; import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import javax.persistence.ElementCollection; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@Entity @Entity
@@ -28,7 +21,7 @@ public class User {
@Id @Id
@NotNull @NotNull
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.TABLE)
private Long id; private Long id;
@NotNull @NotNull
@@ -44,8 +37,7 @@ public class User {
private Map<String, String> footPrintInputs = new HashMap<>(); private Map<String, String> footPrintInputs = new HashMap<>();
@ManyToMany @ManyToMany
@JoinColumn private List<User> friends;
private Collection<User> friends;
public User() {} public User() {}
@@ -147,15 +139,15 @@ public class User {
* This method gets the friends of the user. * This method gets the friends of the user.
* @return friends list of the user * @return friends list of the user
*/ */
public ArrayList<User> getFriends() { public List<User> getFriends() {
return (ArrayList<User>)this.friends; return this.friends;
} }
/** /**
* This method sets the friend list of the user. * This method sets the friend list of the user.
* @param friends friend list of the user * @param friends friend list of the user
*/ */
public void setFriends(Collection<User> friends) { public void setFriends(List<User> friends) {
this.friends = friends; this.friends = friends;
} }
@@ -164,7 +156,7 @@ public class User {
* @param user the friend you want to add. * @param user the friend you want to add.
*/ */
public void addFriend(User user) { public void addFriend(User user) {
if (user.equals(this)) { if (user.equals(this) || friends.contains(user)) {
throw new ApplicationException("Cannot add yourself as a friend"); throw new ApplicationException("Cannot add yourself as a friend");
} else { } else {
friends.add(user); friends.add(user);
@@ -182,21 +174,6 @@ public class User {
+ this.password + ")"; + this.password + ")";
} }
/**
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
* @return a JSON object of the friendlist with only names and scores.
*/
public String friendsToString() {
String result = "friends=[";
for (User u : friends) {
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
}
if (result.endsWith(", ")) {
return result.substring(0, result.lastIndexOf(",")) + "]";
}
return result + "]";
}
/** This method checks whether two users are equal or not. /** This method checks whether two users are equal or not.
* * @param other an other user * * @param other an other user
* @return users are (not) equal * @return users are (not) equal