suumo-search

Perform advanced searches on Suumo.jp
git clone https://git.neuralcrash.com/suumo-search.git
Log | Files | Refs | README

SearchConditions.java (1844B)


      1 package xyz.kebigon.housesearch.domain;
      2 
      3 import java.io.BufferedReader;
      4 import java.io.IOException;
      5 import java.io.InputStreamReader;
      6 
      7 import org.apache.commons.lang3.StringUtils;
      8 
      9 import com.fasterxml.jackson.annotation.JsonProperty;
     10 import com.fasterxml.jackson.databind.ObjectMapper;
     11 
     12 import lombok.Data;
     13 
     14 @Data
     15 public class SearchConditions
     16 {
     17 	private String name;
     18 	private Area area;
     19 	private AnounceType type;
     20 	@JsonProperty("price.min")
     21 	private Long minPrice;
     22 	@JsonProperty("price.max")
     23 	private Long maxPrice;
     24 	@JsonProperty("age.min")
     25 	private Integer minAge;
     26 	@JsonProperty("age.max")
     27 	private Integer maxAge;
     28 	@JsonProperty("surface.land.min")
     29 	private Integer minLandSurface;
     30 	@JsonProperty("surface.land.max")
     31 	private Integer maxLandSurface;
     32 	@JsonProperty("surface.house.min")
     33 	private Integer minHouseSurface;
     34 	@JsonProperty("surface.house.max")
     35 	private Integer maxHouseSurface;
     36 	@JsonProperty("station.walktime.max")
     37 	private Integer maxWalkTimeToStation;
     38 	private String expression;
     39 
     40 	public static SearchConditions[] load() throws IOException
     41 	{
     42 		final ObjectMapper mapper = new ObjectMapper();
     43 		return mapper.readValue(SearchConditions.class.getClassLoader().getResourceAsStream("searches.json"), SearchConditions[].class);
     44 	}
     45 
     46 	@JsonProperty("expression.file")
     47 	private void expressionProp(String expressionFile) throws IOException
     48 	{
     49 		if (StringUtils.isEmpty(expressionFile))
     50 		{
     51 			expression = null;
     52 			return;
     53 		}
     54 
     55 		expression = "";
     56 		try (final BufferedReader reader = new BufferedReader(
     57 				new InputStreamReader(SearchConditions.class.getClassLoader().getResourceAsStream(expressionFile))))
     58 		{
     59 			String line;
     60 			while ((line = reader.readLine()) != null)
     61 			{
     62 				line = line.trim();
     63 				if (line.isEmpty())
     64 					continue;
     65 				if (line.startsWith("#"))
     66 					continue;
     67 				expression += line;
     68 			}
     69 		}
     70 	}
     71 }