xxl.mathematica.map.AssociationMap Maven / Gradle / Ivy
package xxl.mathematica.map;
import io.vavr.Tuple;
import xxl.mathematica.Rule;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* 关联映射
*/
public class AssociationMap {
/**
* 根据键列表创建关联
*
* @param f
* @param list
* @param
* @param
* @return
*/
public static Map associationMap(Function f, List list) {
return io.vavr.collection.List.ofAll(list)
.toJavaMap(k -> Tuple.of(k, f.apply(k)));
}
/**
* 根据旧的关联创建新的关联
*
* @param f
* @param map
* @param
* @param
* @param
* @param
* @return
*/
public static Map associationMap(Function, Rule> f, Map map) {
return io.vavr.collection.HashMap.ofAll(map)
.map((k1, v1) -> {
Rule res = f.apply(Rule.valueOf(k1, v1));
return Tuple.of(res.getKey(), res.getValue());
})
.toJavaMap();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy