suumo-search

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

SuumoSearchURLBuilder.java (11186B)


      1 package xyz.kebigon.housesearch.browser.suumo;
      2 
      3 import xyz.kebigon.housesearch.domain.AnounceType;
      4 import xyz.kebigon.housesearch.domain.Area;
      5 import xyz.kebigon.housesearch.domain.SearchConditions;
      6 
      7 public class SuumoSearchURLBuilder
      8 {
      9     private static final String SEARCH_URI = "https://suumo.jp/jj/bukken/ichiran/JJ012FC001";
     10     private static final String MIN_PRICE_FIELD = "kb";
     11     private static final String MAX_PRICE_FIELD = "kt";
     12     private static final String MIN_AGE_FIELD = "cnb";
     13     private static final String MAX_AGE_FIELD = "cn";
     14     private static final String MIN_LAND_SURFACE_FIELD = "tb";
     15     private static final String MAX_LAND_SURFACE_FIELD = "tt";
     16     private static final String MIN_HOUSE_SURFACE_FIELD = "hb";
     17     private static final String MAX_HOUSE_SURFACE_FIELD = "ht";
     18     private static final String MAX_WALK_TIME_TO_STATION_FIELD = "et";
     19 
     20     public static String build(SearchConditions conditions)
     21     {
     22         final Area area = conditions.getArea();
     23         if (area == null)
     24             throw new RuntimeException();
     25 
     26         final AnounceType type = conditions.getType();
     27         if (type == null)
     28             throw new RuntimeException();
     29 
     30         final StringBuilder builder = new StringBuilder(SEARCH_URI);
     31         builder.append("?ar=").append(area.getCode());
     32         builder.append("&bs=").append(type.getCode());
     33         builder.append("&pc=100"); // 100 results per page
     34         builder.append("&kr=A"); // Buying the land with the house
     35 
     36         // Price
     37         encodeMinPrice(builder, conditions.getMinPrice());
     38         encodeMaxPrice(builder, conditions.getMaxPrice());
     39         // Age
     40         encodeMinAge(builder, conditions.getMinAge());
     41         encodeMaxAge(builder, conditions.getMaxAge());
     42         // LandSurface
     43         encodeMinLandSurface(builder, conditions.getMinLandSurface());
     44         encodeMaxLandSurface(builder, conditions.getMaxLandSurface());
     45         // HouseSurface
     46         encodeMinHouseSurface(builder, conditions.getMinHouseSurface());
     47         encodeMaxHouseSurface(builder, conditions.getMaxHouseSurface());
     48         // WalkTimeToStation
     49         encodeMaxWalkTimeToStation(builder, conditions.getMaxWalkTimeToStation());
     50 
     51         return builder.toString();
     52     }
     53 
     54     private static void encodeMinPrice(StringBuilder builder, Long minPrice)
     55     {
     56         if (minPrice == null || minPrice < 5000000)
     57             return; // 下限なし
     58 
     59         builder.append('&').append(MIN_PRICE_FIELD).append('=');
     60 
     61         if (5000000 <= minPrice && minPrice < 10000000)
     62             builder.append(500); // 500万円以上
     63         else if (10000000 <= minPrice && minPrice < 15000000)
     64             builder.append(1000); // 1000万円以上
     65         else
     66             builder.append(1500); // 1500万円以上
     67     }
     68 
     69     private static void encodeMaxPrice(StringBuilder builder, Long maxPrice)
     70     {
     71         if (maxPrice == null || 120000000 < maxPrice)
     72             return; // 上限なし
     73 
     74         builder.append('&').append(MAX_PRICE_FIELD).append('=');
     75 
     76         if (100000000 < maxPrice && maxPrice <= 120000000)
     77             builder.append(12000); // 1億2千万円未満
     78         else if (90000000 < maxPrice && maxPrice <= 100000000)
     79             builder.append(10000); // 1億円未満
     80         else if (80000000 < maxPrice && maxPrice <= 90000000)
     81             builder.append(9000); // 9000万円未満
     82         else if (75000000 < maxPrice && maxPrice <= 80000000)
     83             builder.append(8000); // 8000万円未満
     84         else if (70000000 < maxPrice && maxPrice <= 75000000)
     85             builder.append(7500); // 7500万円未満
     86         else if (65000000 < maxPrice && maxPrice <= 70000000)
     87             builder.append(7000); // 7000万円未満
     88         else if (60000000 < maxPrice && maxPrice <= 65000000)
     89             builder.append(6500); // 6500万円未満
     90         else if (55000000 < maxPrice && maxPrice <= 60000000)
     91             builder.append(6000); // 6000万円未満
     92         else if (50000000 < maxPrice && maxPrice <= 55000000)
     93             builder.append(5500); // 5500万円未満
     94         else if (45000000 < maxPrice && maxPrice <= 50000000)
     95             builder.append(5000); // 5000万円未満
     96         else if (40000000 < maxPrice && maxPrice <= 45000000)
     97             builder.append(4500); // 4500万円未満
     98         else if (35000000 < maxPrice && maxPrice <= 40000000)
     99             builder.append(4000); // 4000万円未満
    100         else if (30000000 < maxPrice && maxPrice <= 35000000)
    101             builder.append(3500); // 3500万円未満
    102         else if (25000000 < maxPrice && maxPrice <= 30000000)
    103             builder.append(3000); // 3000万円未満
    104         else if (20000000 < maxPrice && maxPrice <= 25000000)
    105             builder.append(2500); // 2500万円未満
    106         else if (15000000 < maxPrice && maxPrice <= 20000000)
    107             builder.append(2000); // 2000万円未満
    108         else if (10000000 < maxPrice && maxPrice <= 15000000)
    109             builder.append(1500); // 1500万円未満
    110         else if (5000000 < maxPrice && maxPrice <= 10000000)
    111             builder.append(1000); // 1000万円未満
    112         else
    113             builder.append(500); // 500万円未満
    114     }
    115 
    116     private static void encodeMinAge(StringBuilder builder, Integer minAge)
    117     {
    118         if (minAge == null || minAge < 3)
    119             return; // 下限なし
    120 
    121         builder.append('&').append(MIN_AGE_FIELD).append('=');
    122 
    123         if (3 <= minAge && minAge < 5)
    124             builder.append(3); // 3年以上
    125         else if (5 <= minAge && minAge < 7)
    126             builder.append(5); // 5年以上
    127         else if (7 <= minAge && minAge < 10)
    128             builder.append(7); // 7年以上
    129         else if (10 <= minAge && minAge < 15)
    130             builder.append(10); // 10年以上
    131         else
    132             builder.append(15); // 15年以上
    133     }
    134 
    135     private static void encodeMaxAge(StringBuilder builder, Integer maxAge)
    136     {
    137         if (maxAge == null || 30 < maxAge)
    138             return; // 上限なし
    139 
    140         builder.append('&').append(MAX_AGE_FIELD).append('=');
    141 
    142         if (25 < maxAge && maxAge <= 30)
    143             builder.append(30); // 30年以内
    144         else if (20 < maxAge && maxAge <= 25)
    145             builder.append(25); // 25年以内
    146         else if (15 < maxAge && maxAge <= 20)
    147             builder.append(20); // 20年以内
    148         else if (10 < maxAge && maxAge <= 15)
    149             builder.append(15); // 15年以内
    150         else if (7 < maxAge && maxAge <= 10)
    151             builder.append(10); // 10年以内
    152         else if (5 < maxAge && maxAge <= 7)
    153             builder.append(7); // 7年以内
    154         else if (3 < maxAge && maxAge <= 5)
    155             builder.append(5); // 5年以内
    156         else
    157             builder.append(3); // 3年以内
    158     }
    159 
    160     private static void encodeMinLandSurface(StringBuilder builder, Integer minLandSurface)
    161     {
    162         encodeMinSurface(builder, MIN_LAND_SURFACE_FIELD, minLandSurface);
    163     }
    164 
    165     private static void encodeMaxLandSurface(StringBuilder builder, Integer maxLandSurface)
    166     {
    167         encodeMaxSurface(builder, MAX_LAND_SURFACE_FIELD, maxLandSurface);
    168     }
    169 
    170     private static void encodeMinHouseSurface(StringBuilder builder, Integer minHouseSurface)
    171     {
    172         encodeMinSurface(builder, MIN_HOUSE_SURFACE_FIELD, minHouseSurface);
    173     }
    174 
    175     private static void encodeMaxHouseSurface(StringBuilder builder, Integer maxHouseSurface)
    176     {
    177         encodeMaxSurface(builder, MAX_HOUSE_SURFACE_FIELD, maxHouseSurface);
    178     }
    179 
    180     private static void encodeMinSurface(StringBuilder builder, String field, Integer minLandSurface)
    181     {
    182         if (minLandSurface == null || minLandSurface < 60)
    183             return; // 下限なし
    184 
    185         builder.append('&').append(field).append('=');
    186 
    187         if (60 <= minLandSurface && minLandSurface < 70)
    188             builder.append(60); // 60m2以上
    189         else if (70 <= minLandSurface && minLandSurface < 80)
    190             builder.append(70); // 70m2以上
    191         else if (80 <= minLandSurface && minLandSurface < 90)
    192             builder.append(80); // 80m2以上
    193         else if (90 <= minLandSurface && minLandSurface < 100)
    194             builder.append(90); // 90m2以上
    195         else if (100 <= minLandSurface && minLandSurface < 110)
    196             builder.append(100); // 100m2以上
    197         else if (110 <= minLandSurface && minLandSurface < 120)
    198             builder.append(110); // 110m2以上
    199         else if (120 <= minLandSurface && minLandSurface < 130)
    200             builder.append(120); // 120m2以上
    201         else if (130 <= minLandSurface && minLandSurface < 140)
    202             builder.append(130); // 130m2以上
    203         else if (140 <= minLandSurface && minLandSurface < 150)
    204             builder.append(140); // 140m2以上
    205         else
    206             builder.append(150); // 150m2以上
    207     }
    208 
    209     private static void encodeMaxSurface(StringBuilder builder, String field, Integer maxLandSurface)
    210     {
    211         if (maxLandSurface == null || 150 < maxLandSurface)
    212             return; // 上限なし
    213 
    214         builder.append('&').append(field).append('=');
    215 
    216         if (140 < maxLandSurface && maxLandSurface <= 150)
    217             builder.append(150); // 150m2未満
    218         else if (130 < maxLandSurface && maxLandSurface <= 140)
    219             builder.append(140); // 140m2未満
    220         else if (120 < maxLandSurface && maxLandSurface <= 130)
    221             builder.append(130); // 130m2未満
    222         else if (110 < maxLandSurface && maxLandSurface <= 120)
    223             builder.append(120); // 120m2未満
    224         else if (100 < maxLandSurface && maxLandSurface <= 110)
    225             builder.append(110); // 110m2未満
    226         else if (90 < maxLandSurface && maxLandSurface <= 100)
    227             builder.append(100); // 100m2未満
    228         else if (80 < maxLandSurface && maxLandSurface <= 90)
    229             builder.append(90); // 90m2未満
    230         else if (70 < maxLandSurface && maxLandSurface <= 80)
    231             builder.append(80); // 80m2未満
    232         else if (60 < maxLandSurface && maxLandSurface <= 70)
    233             builder.append(70); // 70m2未満
    234         else
    235             builder.append(60); // 60m2未満
    236     }
    237 
    238     public static void encodeMaxWalkTimeToStation(StringBuilder builder, Integer maxWalkTimeToStation)
    239     {
    240         if (maxWalkTimeToStation == null || 20 < maxWalkTimeToStation)
    241             return; // 指定なし
    242 
    243         builder.append('&').append(MAX_WALK_TIME_TO_STATION_FIELD).append('=');
    244 
    245         if (15 < maxWalkTimeToStation && maxWalkTimeToStation <= 20)
    246             builder.append(20); // 20分以内
    247         else if (10 < maxWalkTimeToStation && maxWalkTimeToStation <= 15)
    248             builder.append(15); // 15分以内
    249         else if (7 < maxWalkTimeToStation && maxWalkTimeToStation <= 10)
    250             builder.append(10); // 10分以内
    251         else if (5 < maxWalkTimeToStation && maxWalkTimeToStation <= 7)
    252             builder.append(7); // 7分以内
    253         else if (3 < maxWalkTimeToStation && maxWalkTimeToStation <= 5)
    254             builder.append(5); // 5分以内
    255         else if (1 < maxWalkTimeToStation && maxWalkTimeToStation <= 3)
    256             builder.append(3); // 3分以内
    257         else
    258             builder.append(1); // 1分以内
    259     }
    260 }