com.smallaswater.easysql.mysql.data.SqlData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of EasyMySQL Show documentation
Show all versions of EasyMySQL Show documentation
EasyMySQL -- MySQL tool for Nukkit
package com.smallaswater.easysql.mysql.data;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
/**
* @author SmallasWater
*/
public class SqlData {
private final LinkedHashMap data = new LinkedHashMap<>();
public SqlData() {
}
public SqlData(String column, Object object) {
data.put(column.toLowerCase(), object);
}
public LinkedHashMap getData() {
return data;
}
/**
* 添加数据
*
* @param column 字段名
* @param object 数据
*/
public SqlData put(String column, Object object) {
data.put(column.toLowerCase(), object);
return this;
}
/**
* 获取数据
*
* @param column 字段名
* @param 数据类型
*/
public Object get(String column, T defaultValue) {
return data.getOrDefault(column.toLowerCase(), defaultValue);
}
public int getInt(String key) {
return this.getInt(key, 0);
}
public int getInt(String key, int defaultValue) {
return Integer.parseInt(this.get(key, defaultValue).toString());
}
/**
* 这个似乎没啥用
* */
@Deprecated
public boolean isInt(String key) {
Object val = data.get(key);
return val instanceof Integer;
}
public double getDouble(String key) {
return this.getDouble(key, 0.0D);
}
public double getDouble(String key, double defaultValue) {
return Double.parseDouble(this.get(key, defaultValue).toString());
}
/**
* 这个似乎没啥用
* */
@Deprecated
public boolean isDouble(String key) {
Object val = data.get(key);
return val instanceof Double;
}
public String getString(String key) {
return this.getString(key, "");
}
public String getString(String key, String defaultValue) {
Object result = this.get(key, defaultValue);
return String.valueOf(result);
}
/**
* 这个似乎没啥用
* */
@Deprecated
public boolean isString(String key) {
Object val = data.get(key);
return val instanceof String;
}
public boolean getBoolean(String key) {
return this.getBoolean(key, false);
}
public boolean getBoolean(String key, boolean defaultValue) {
return Boolean.parseBoolean(this.get(key, defaultValue).toString());
}
/**
* 这个似乎没啥用
* */
@Deprecated
public boolean isBoolean(String key) {
Object val = data.get(key);
return val instanceof Boolean;
}
/**
* 获取所有字段名
*
* @return 字段名
*/
public List getColumns() {
return new LinkedList<>(data.keySet());
}
public String getColumn() {
return getColumn(0);
}
public Object getValue() {
return getValue(0);
}
public String getColumn(int index) {
LinkedList names = new LinkedList<>(data.keySet());
if (names.size() > index) {
return names.get(index);
}
return null;
}
/**
* 根据索引位置获取返回的数据
*/
public Object getValue(int index) {
LinkedList