com.jfinal.kit.Okv Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjoy Show documentation
Show all versions of enjoy Show documentation
Enjoy is a simple, light, rapid, independent, extensible Java Template Engine.
The newest version!
/**
* Copyright (c) 2011-2023, James Zhan 詹波 ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jfinal.kit;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.Map;
// import com.jfinal.json.Json;
/**
* Okv (Ordered Key Value)
*
* Okv 与 Kv 的唯一区别在于 Okv 继承自 LinkedHashMap,而 Kv 继承自 HashMap
* 所以对 Okv 中的数据进行迭代输出的次序与数据插入的先后次序一致
*
* Example:
* Okv para = Okv.of("id", 123);
* User user = user.findFirst(getSqlPara("find", para));
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class Okv extends LinkedHashMap {
private static final long serialVersionUID = -6517132544791494383L;
public Okv() {
}
public static Okv of(Object key, Object value) {
return new Okv().set(key, value);
}
public static Okv by(Object key, Object value) {
return new Okv().set(key, value);
}
public static Okv create() {
return new Okv();
}
public Okv set(Object key, Object value) {
super.put(key, value);
return this;
}
public Okv setIfNotBlank(Object key, String value) {
if (StrKit.notBlank(value)) {
set(key, value);
}
return this;
}
public Okv setIfNotNull(Object key, Object value) {
if (value != null) {
set(key, value);
}
return this;
}
public Okv set(Map map) {
super.putAll(map);
return this;
}
public Okv set(Okv okv) {
super.putAll(okv);
return this;
}
public Okv delete(Object key) {
super.remove(key);
return this;
}
public T getAs(Object key) {
return (T)get(key);
}
public T getAs(Object key, T defaultValue) {
Object ret = get(key);
return ret != null ? (T) ret : defaultValue;
}
public T getAs(Object key, T defaultValue, com.jfinal.kit.Func.F11
© 2015 - 2025 Weber Informatics LLC | Privacy Policy