DataFormat重构为继承自DateNumberFormat

This commit is contained in:
datagear 2021-05-28 21:41:05 +08:00
parent f64c51b56a
commit 4e2f64cecc
3 changed files with 85 additions and 75 deletions

View File

@ -9,7 +9,7 @@ package org.datagear.analysis.support;
import java.io.Serializable;
import org.datagear.util.DateFormat;
import org.datagear.util.DateNumberFormat;
/**
* 数据格式
@ -17,66 +17,12 @@ import org.datagear.util.DateFormat;
* @author datagear@163.com
*
*/
public class DataFormat extends DateFormat implements Serializable
public class DataFormat extends DateNumberFormat implements Serializable
{
private static final long serialVersionUID = 1L;
/**
* 默认数值格式#.##########
*/
public static final String DEFAULT_NUMBER_FORMAT = "#.##########";
/** 数值格式 */
private String numberFormat = DEFAULT_NUMBER_FORMAT;
public DataFormat()
{
super();
}
public String getNumberFormat()
{
return numberFormat;
}
public void setNumberFormat(String numberFormat)
{
this.numberFormat = numberFormat;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((numberFormat == null) ? 0 : numberFormat.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
DataFormat other = (DataFormat) obj;
if (numberFormat == null)
{
if (other.numberFormat != null)
return false;
}
else if (!numberFormat.equals(other.numberFormat))
return false;
return true;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [dateFormat=" + getDateFormat() + ", timeFormat=" + getTimeFormat()
+ ", timestampFormat=" + getTimestampFormat() + ", numberFormat=" + numberFormat + "]";
}
}

View File

@ -10,7 +10,7 @@ package org.datagear.dataexchange;
import java.io.Serializable;
import java.util.Locale;
import org.datagear.util.DateFormat;
import org.datagear.util.DateNumberFormat;
/**
* 数据格式
@ -18,12 +18,10 @@ import org.datagear.util.DateFormat;
* @author datagear@163.com
*
*/
public class DataFormat extends DateFormat implements Serializable
public class DataFormat extends DateNumberFormat implements Serializable
{
private static final long serialVersionUID = 1L;
public static final String DEFAULT_NUMBER_FORMAT = "#.######";
public static final String BINARY_FORMAT_HEX = "Hex";
public static final String BINARY_FORMAT_BASE64 = "Base64";
@ -33,9 +31,6 @@ public class DataFormat extends DateFormat implements Serializable
/** 地区 */
private Locale locale = Locale.getDefault();
/** 数值格式 */
private String numberFormat = DEFAULT_NUMBER_FORMAT;
/** 二进制格式 */
private String binaryFormat = BINARY_FORMAT_HEX;
@ -52,7 +47,7 @@ public class DataFormat extends DateFormat implements Serializable
setDateFormat(dateFormat);
setTimeFormat(timeFormat);
setTimestampFormat(timestampFormat);
this.numberFormat = numberFormat;
setNumberFormat(numberFormat);
this.binaryFormat = binaryFormat;
}
@ -66,16 +61,6 @@ public class DataFormat extends DateFormat implements Serializable
this.locale = locale;
}
public String getNumberFormat()
{
return numberFormat;
}
public void setNumberFormat(String numberFormat)
{
this.numberFormat = numberFormat;
}
public String getBinaryFormat()
{
return binaryFormat;
@ -90,7 +75,8 @@ public class DataFormat extends DateFormat implements Serializable
public String toString()
{
return getClass().getSimpleName() + " [dateFormat=" + getDateFormat() + ", timeFormat=" + getTimeFormat()
+ ", timestampFormat=" + getTimestampFormat() + ", numberFormat=" + numberFormat + ", binaryFormat="
+ ", timestampFormat=" + getTimestampFormat() + ", numberFormat=" + getNumberFormat()
+ ", binaryFormat="
+ binaryFormat + "]";
}
}

View File

@ -0,0 +1,78 @@
/*
* Copyright 2018 datagear.tech
*
* Licensed under the LGPLv3 license:
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
package org.datagear.util;
/**
* 日期时间格式
*
* @author datagear@163.com
*
*/
public class DateNumberFormat extends DateFormat
{
private static final long serialVersionUID = 1L;
/**
* 默认数值格式#.##########
*/
public static final String DEFAULT_NUMBER_FORMAT = "#.##########";
/** 数值格式 */
private String numberFormat = DEFAULT_NUMBER_FORMAT;
public DateNumberFormat()
{
super();
}
public String getNumberFormat()
{
return numberFormat;
}
public void setNumberFormat(String numberFormat)
{
this.numberFormat = numberFormat;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((numberFormat == null) ? 0 : numberFormat.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
DateNumberFormat other = (DateNumberFormat) obj;
if (numberFormat == null)
{
if (other.numberFormat != null)
return false;
}
else if (!numberFormat.equals(other.numberFormat))
return false;
return true;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [dateFormat=" + getDateFormat() + ", timeFormat=" + getTimeFormat()
+ ", timestampFormat=" + getTimestampFormat() + ", numberFormat=" + numberFormat + "]";
}
}