All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.pubcodetools.japanPostalCode.JapanPostalCodes Maven / Gradle / Ivy

There is a newer version: 0.0.7_old-0.0.0
Show newest version
package io.github.pubcodetools.japanPostalCode;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class JapanPostalCodes {
    private static final String version = "2021-03-31";
    private static final String jsonResource = "/japanese-postal-code.json";
    private List japanPostalCodes;

    public JapanPostalCodes() {
        try (InputStream is = getClass().getResourceAsStream(jsonResource);
             BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
            ObjectMapper mapper = new ObjectMapper();
            japanPostalCodes = mapper.readValue(br,
                    new TypeReference>() {});
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public JapanPostalCode get(String postalCode) {
        for (JapanPostalCode jpc: japanPostalCodes) {
            if (postalCode.equals(jpc.getPostalCode())) {
                return jpc;
            }
        }
        return null;
    }

    public List getAll() {
        return japanPostalCodes;
    }

    public String getVersion() {
        return version;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy