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

com.jl.set.map.JHashMap Maven / Gradle / Ivy

The newest version!
package com.jl.set.map;

import com.jl.JLSet;
import com.jl.JLambda;
import com.jl.set.list.JArrayList;
import com.jl.set.list.JList;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;

/**
 * HashMap
 */
public class JHashMap extends HashMap implements JMap, Serializable {

    public JHashMap() {

    }

    public JHashMap(int initialCapacity) {
        super(initialCapacity);
    }

    public JHashMap(Map map) {
        super(map);
    }

    @Override
    public JMap set(K key, V value) {
        this.put(key, value);
        return this;
    }

    @Override
    public  JMap set(JLambda.JFunction function, V value) {
        set(getKey(function), value);
        return this;
    }

    @Override
    public V setIfAbsent(K key, V value) {
        return this.putIfAbsent(key, value);
    }

    @Override
    public  V setIfAbsent(JLambda.JFunction function, V value) {
        return setIfAbsent(getKey(function), value);
    }

    @Override
    public JMap setAll(Map map) {
        this.putAll(map);
        return this;
    }

    @Override
    public V del(K key) {
        return this.remove(key);
    }

    @Override
    public  V del(JLambda.JFunction function) {
        return del(getKey(function));
    }

    @Override
    public String getString(K key) {
        return this.get(key) == null ? null : this.get(key).toString();
    }

    @Override
    public  String getString(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : this.get(getKey(function)).toString();
    }

    @Override
    public Integer getInt(K key) {
        return this.get(key) == null ? null : Integer.parseInt(this.get(key).toString());
    }

    @Override
    public  Integer getInt(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : Integer.parseInt(this.get(getKey(function)).toString());
    }

    @Override
    public Long getLong(K key) {
        return this.get(key) == null ? null : Long.parseLong(this.get(key).toString());
    }

    @Override
    public  Long getLong(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : Long.parseLong(this.get(getKey(function)).toString());
    }

    @Override
    public Double getDouble(K key) {
        return this.get(key) == null ? null : Double.parseDouble(this.get(key).toString());
    }

    @Override
    public  Double getDouble(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : Double.parseDouble(this.get(getKey(function)).toString());
    }

    @Override
    public BigDecimal getBigDecimal(K key) {
        return this.get(key) == null ? null : new BigDecimal(this.get(key).toString());
    }

    @Override
    public  BigDecimal getBigDecimal(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : new BigDecimal(this.get(getKey(function)).toString());
    }

    @Override
    public Boolean getBoolean(K key) {
        return this.get(key) == null ? null : Boolean.parseBoolean(this.get(key).toString());
    }

    @Override
    public  Boolean getBoolean(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : Boolean.parseBoolean(this.get(getKey(function)).toString());
    }

    @Override
    public LocalDateTime getLocalDateTime(K key) {
        return this.get(key) == null ? null : (LocalDateTime) this.get(key);
    }

    @Override
    public  LocalDateTime getLocalDateTime(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : (LocalDateTime) this.get(getKey(function));
    }

    @Override
    public Timestamp getTimestamp(K key) {
        return this.get(key) == null ? null : (Timestamp) this.get(key);
    }

    @Override
    public  Timestamp getTimestamp(JLambda.JFunction function) {
        return this.get(getKey(function)) == null ? null : (Timestamp) this.get(getKey(function));
    }

    @Override
    public V get(K key, Class t) {
        V v = this.get(key);
        return v == null ? null : v;
    }

    @Override
    public  V get(JLambda.JFunction function, Class t) {
        V v = this.get(getKey(function));
        return v == null ? null : v;
    }

    @Override
    public JList getKeys() {
        Set keyNameSet = this.keySet();
        List ks = new ArrayList<>(keyNameSet);
        return new JArrayList<>(ks);
    }

    @Override
    public JList getValues() {
        Collection keyValueCollection = this.values();
        List vs = new ArrayList<>(keyValueCollection);
        return new JArrayList<>(vs);
    }

    @Override
    public ToList toList() {
        return new ToList<>(this);
    }

    @Override
    public  T toBean(Class t) {
        return JLSet.map(this).toBean(t);
    }

    private  K getKey(JLambda.JFunction function) {
        return (K) JLambda.getProperty(function);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy