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

com.databasesandlife.util.jooq.CurrencyIso4217NumericCodeSetConverter Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util.jooq;

import com.databasesandlife.util.jooq.CurrencyIso4217NumericCodeConverter.InvalidCurrencyException;
import org.jooq.Converter;

import java.util.*;

import static com.databasesandlife.util.jooq.CurrencyIso4217NumericCodeConverter.lookup;
import static java.util.Arrays.asList;

@SuppressWarnings({ "serial" })
public class CurrencyIso4217NumericCodeSetConverter implements Converter {

    public static class CurrencyIso4217NumericCodeSortedSet extends TreeSet {
        public CurrencyIso4217NumericCodeSortedSet() {
            super(Comparator.comparingInt(Currency::getNumericCode));
        }

        public CurrencyIso4217NumericCodeSortedSet(Collection currencyIds) throws InvalidCurrencyException {
            this();
            for (var c : currencyIds) add(lookup(c));
        }
    }

    @Override public Class fromType() { return Integer[].class; }
    @Override public Class toType() { return CurrencyIso4217NumericCodeSortedSet.class; }

    @Override
    public CurrencyIso4217NumericCodeSortedSet from(Integer[] x) {
        try {
            if (x == null) return null;
            return new CurrencyIso4217NumericCodeSortedSet(asList(x));
        }
        catch (InvalidCurrencyException e) { throw new RuntimeException(e); }
    }

    @Override
    public Integer[] to(CurrencyIso4217NumericCodeSortedSet m) {
        if (m == null) return null;
        return m.stream().map(Currency::getNumericCode).toArray(Integer[]::new);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy