org.hy.common.Help Java Examples

The following examples show how to use org.hy.common.Help. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JU_Formula.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 测试:解释Excel公式中的单元格ID
 * 
 * @author      ZhengWei(HY)
 * @createDate  2020-05-21
 * @version     v1.0
 *
 */
@Test
public void test_parserFormula()
{
    String [] v_Formulas = {"=A1 + B1"
                           ,"=A1 - B1"
                           ,"=A1 * B1"
                           ,"=A1 / B1"
                           ,"=A1 / B1 + C1 - D1 * E1"
                           ,"=$A1 / B$1 + $C$1 - D1 * E1"
                           ,"=$A1 / B$1 + A1 + B1 + $C$1 - D1 * E1"
    };
    
    for (String v_Formula : v_Formulas)
    {
        System.out.println("\n\n" + v_Formula);
        
        Help.print(ExcelFormula.parserFormula(v_Formula));
    }
}
 
Example #2
Source File: Job.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 设置:允许执行的条件。
 * 
 *  表达式中,预定义占位符有(占位符不区分大小写):
 *    :Y    表示年份
 *    :M    表示月份
 *    :D    表示天
 *    :H    表示小时(24小时制)
 *    :MI   表示分钟
 *    :S    表示秒
 *    :YMD  表示年月日,格式为YYYYMMDD 样式的整数类型。整数类型是为了方便比较
 * 
 * @param i_Condition 
 */
public void setCondition(String i_Condition)
{
    this.condition = Help.NVL(i_Condition).toUpperCase();
    this.condition = StringHelp.replaceAll(this.condition 
                                          ,new String[]{
                                                        ":" + $Condition_YMD
                                                       ,":" + $Condition_S
                                                       ,":" + $Condition_MI
                                                       ,":" + $Condition_H
                                                       ,":" + $Condition_D
                                                       ,":" + $Condition_D
                                                       ,":" + $Condition_Y
                                                       } 
                                          ,new String[]{
                                                        $Condition_YMD
                                                       ,$Condition_S
                                                       ,$Condition_MI
                                                       ,$Condition_H
                                                       ,$Condition_D
                                                       ,$Condition_M
                                                       ,$Condition_Y
                                                        });
}
 
Example #3
Source File: Job.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 设置:开始时间组。多个开始时间用分号分隔。多个开始时间对 "间隔类型:秒、分" 是无效的(只取最小时间为开始时间)
 * 
 * @param i_StartTimesStr
 */
public void setStartTime(String i_StartTimesStr)
{
    if ( Help.isNull(i_StartTimesStr) )
    {
        return;
    }
    
    this.startTimes = new ArrayList<Date>();
    String [] v_STimeArr = StringHelp.replaceAll(i_StartTimesStr ,new String[]{"\t" ,"\n" ,"\r"} ,new String[]{""}).split(",");
    for (String v_STime : v_STimeArr)
    {
        this.startTimes.add(new Date(v_STime.trim()));
    }
    
    Help.toSort(this.startTimes);
}
 
Example #4
Source File: RTemplate.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(RTemplate i_Other)
{
    if ( i_Other == null )
    {
        return 1;
    }
    else if ( this == i_Other )
    {
        return 0;
    }
    else
    {
        if ( Help.isNull(this.name) || Help.isNull(this.excelFileName) )
        {
            return -1;
        }
        
        int v_Ret = this.name.compareTo(i_Other.getName());
        if ( v_Ret == 0 )
        {
            v_Ret = this.excelFileName.compareTo(i_Other.getExcelFileName());
        }
        return v_Ret;
    }
}
 
Example #5
Source File: ImageListener.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 重置图片大小,设置顶部、左侧边距
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-10-31
 * @version     v1.0
 *
 * @param i_Picture
 */
protected void resizeMarginLeftTop(Picture i_Picture ,BufferedImage i_Image ,boolean i_IsScale ,Double i_ScaleX ,Double i_ScaleY)
{
    if ( i_ScaleX != null && i_ScaleY != null )
    {
        i_Picture.resize(i_ScaleX ,i_ScaleY);
    }
    else if ( i_ScaleX != null )
    {
        i_Picture.resize(i_ScaleX ,1);
    }
    else if ( i_ScaleY != null )
    {
        i_Picture.resize(1 ,i_ScaleY);
    }
    else if ( i_Image != null )
    {
        autoScale(i_Picture ,i_Image);
    }
    
    i_Picture.getAnchor().setDx1(i_Picture.getAnchor().getDx1() + Help.NVL(this.marginLeft ,0));
    i_Picture.getAnchor().setDx2(i_Picture.getAnchor().getDx2() + Help.NVL(this.marginLeft ,0));
    i_Picture.getAnchor().setDy1(i_Picture.getAnchor().getDy1() + Help.NVL(this.marginTop  ,0));
    i_Picture.getAnchor().setDy2(i_Picture.getAnchor().getDy2() + Help.NVL(this.marginTop  ,0));
}
 
Example #6
Source File: Task.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 构造器
 * 
 * @param i_TaskType  任务类型
 */
public Task(String i_TaskType)
{
	if ( Help.isNull(i_TaskType) )
	{
		throw new NullPointerException("Task Type is null");
	}
	
	this.taskType    = i_TaskType;
	this.taskNo      = this.getSerialNo();
	this.taskName    = this.taskType + "-" + this.taskNo; 
	this.isFinish    = false;
	this.isStop      = false;
	
	this.printBuffer = new StringBuilder();
	this.sqlBuffer   = new StringBuilder();
}
 
Example #7
Source File: DatasMaker.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
public List<AppendComplex03> makeAppendComplex03()
{
    List<AppendComplex03> v_Datas = new ArrayList<AppendComplex03>();
    
    for (int i=1; i<=3; i++)
    {
        String          v_No   = StringHelp.lpad(i ,3 ,"0");
        AppendComplex03 v_Data = new AppendComplex03();
        
        v_Data.setQty(     "Q" + v_No);
        v_Data.setTypeName("T" + v_No);
        v_Data.setRemark(  "R" + v_No);
        v_Data.setLength(  i);
        v_Data.setWidth(   Help.multiply(i ,100));
        v_Data.setHeight(  Help.multiply(i ,60));
        v_Data.setNet(     Help.multiply(i ,10));
        v_Data.setRt(      Help.multiply(i ,30));
        v_Data.setGross(   Help.multiply(i ,Math.PI));  // 在模板上可设置显示的小数位数
        v_Data.setQcode(XJava.getParam("QCodeImagePath").getValue() + i + ".png");
        
        v_Datas.add(v_Data);
    }
    
    return v_Datas;
}
 
Example #8
Source File: RTemplate.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
@Override
public int hashCode()
{
    int v_Ret = 0;
    
    if ( !Help.isNull(this.name) )
    {
        v_Ret = this.name.hashCode();
    }
    if ( !Help.isNull(this.excelFileName) )
    {
        v_Ret += this.excelFileName.hashCode() * 1000;
    }
    if ( v_Ret == 0 )
    {
        return super.hashCode();
    }
    
    return v_Ret;
}
 
Example #9
Source File: ImageListener.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 自动缩放
 * 
 * @author      ZhengWei(HY)
 * @createDate  2019-05-30
 * @version     v1.0
 *
 * @param i_Picture
 * @param i_Image
 */
protected void autoScale(Picture i_Picture ,BufferedImage i_Image)
{
    double v_Scale = 1D;
    
    if ( i_Image.getWidth() > i_Image.getHeight() )
    {
        double v_ScaleY = Help.division(i_Image.getHeight() ,i_Image.getWidth());
        i_Picture.resize(v_Scale ,v_ScaleY);
        // i_Picture.resize(v_Scale ,v_Scale);
    }
    else if ( i_Image.getWidth() < i_Image.getHeight() )
    {
        double v_ScaleX = Help.division(i_Image.getWidth() ,i_Image.getHeight());
        i_Picture.resize(v_ScaleX ,v_Scale);
        // i_Picture.resize(0.5D ,v_Scale);
    }
    else
    {
        i_Picture.resize(v_Scale ,v_Scale);
    }
}
 
Example #10
Source File: ExcelHelp.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
/**
 * 计算单元格自动的行高
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-09-11
 * @version     v1.0
 *
 * @param i_Text               单元格文本
 * @param i_FontWidth          字体宽度(字体高度)
 * @param i_DefaultRowHeight   默认行高
 * @param i_CellWidth          单元格宽度
 * @return
 */
public static float calcCellAutoHeight(String i_Text ,float i_FontWidth ,float i_DefaultRowHeight ,float i_CellWidth)
{
    int    v_HightCount  = 1;
    double v_PerRowWidth = 0f;
    
    for (int i = 0; i < i_Text.length(); i++)
    {
        double v_CharWidth    = Help.multiply(calcCharWidth(i_Text.substring(i ,i + 1)) ,0.55);
        v_CharWidth           = Help.multiply(v_CharWidth ,i_FontWidth);
        
        double v_TempRowWidth = Help.addition(v_PerRowWidth ,v_CharWidth);
        
        if ( v_TempRowWidth <= i_CellWidth )
        {
            v_PerRowWidth = v_TempRowWidth;
        }
        else
        {
            v_PerRowWidth = v_CharWidth;
            v_HightCount++;
        }
    }
    
    return (float)Help.multiply(v_HightCount ,i_DefaultRowHeight);
}
 
Example #11
Source File: Jobs.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 是否启动的灾备机制
 * 
 * @author      ZhengWei(HY)
 * @createDate  2019-02-21
 * @version     v1.0
 *
 * @return
 */
public boolean isDisasterRecovery()
{
    if ( Help.isNull(this.disasterRecoverys) )
    {
        return false;
    }
    else if ( this.disasterRecoverys.size() >= 2 )
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
Example #12
Source File: ClassReflect.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 从指定集合i_Classes中,挑出有注解的Class的方法。
 * 
 * @param i_Classes          Java元类型的集合
 * @param i_AnnotationClass  注解类型的元类型
 * @return
 */
public static List<ClassInfo> getAnnotationMethods(List<Class<?>> i_Classes ,Class<? extends Annotation> i_AnnotationClass)
{
    List<ClassInfo> v_Ret = new ArrayList<ClassInfo>();
    
    for (int i=0; i<i_Classes.size(); i++)
    {
        Class<?>  v_Class     = i_Classes.get(i);
        ClassInfo v_ClassInfo = new ClassInfo(v_Class);
        
        // 判断类中的自有方法是否注解
        List<Method> v_Methods = MethodReflect.getAnnotationMethods(v_Class ,i_AnnotationClass);
        if ( !Help.isNull(v_Methods) )
        {
            v_ClassInfo.setMethods(v_Methods);
            
            v_Ret.add(v_ClassInfo);
        }
    }
    
    return v_Ret;
}
 
Example #13
Source File: AppParameter.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 判定参数是否存在
 * 
 * @param i_ParamName  参数名称
 * @return
 */
public boolean isExists(String i_ParamName)
{
	if ( Help.isNull(this.parameters) || Help.isNull(i_ParamName) )
	{
		return false;
	}
	
	if ( this.parameters.containsKey(i_ParamName.trim().toLowerCase()) )
	{
		return true;
	}
	else
	{
		return false;
	}
}
 
Example #14
Source File: AppParameter.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 获取参数的值
 * 
 * @param i_ParamName  参数名称
 * @return
 */
public String getParamValue(String i_ParamName)
{
	if ( this.isExists(i_ParamName) )
	{
		String v_ParamValue = this.parameters.get(i_ParamName.trim().toLowerCase());
		
		if ( Help.isNull(v_ParamValue) )
		{
			return null;
		}
		else
		{
			return v_ParamValue;
		}
	}
	else
	{
		return null;
	}
}
 
Example #15
Source File: AppParameter.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 是否显示帮助信息
 * 
 * @return
 */
public boolean isShowHelp()
{
	if ( Help.isNull(this.parameters) )
	{
		return false;
	}
	
	if ( this.parameters.containsKey("/help") )
	{
		return true;
	}
	else if ( this.parameters.containsKey("/h") )
	{
		return true;
	}
	else if ( this.parameters.containsKey("/?") )
	{
		return true;
	}
	else
	{
		return false;
	}
}
 
Example #16
Source File: AppParameter.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
/**
 * 是否显示帮助信息
 * 
 * @return
 */
public boolean isShowVersion()
{
	if ( Help.isNull(this.parameters) )
	{
		return false;
	}
	
	if ( this.parameters.containsKey("/version") )
	{
		return true;
	}
	else if ( this.parameters.containsKey("/v") )
	{
		return true;
	}
	else
	{
		return false;
	}
}
 
Example #17
Source File: JU_StringHelp.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
    @Test
    public void test_ABC36()
    {
        int v_Value = 999999;
        
        System.out.println(Help.round(Help.division(125L ,3L) ,2));
        
        //System.out.println(StringHelp.toABC26(v_Value));
        //System.out.println(StringHelp.reABC26(StringHelp.toABC26(v_Value)));
        
//        for (int i=0; i<36; i++)
//        {
//            System.out.println(StringHelp.toABC36(i));
//            System.out.println(StringHelp.reABC36(StringHelp.toABC36(i)));
//        }
        
        //System.out.println(StringHelp.reABC36(StringHelp.toABC36(v_Value)));
    }
 
Example #18
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 6 votes vote down vote up
@Test
public void test_toSortByMap()
{
    Counter<String> v_Counter = new Counter<String>();
    String []       v_ABC     = {"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" ,"H" ,"I" ,"J" ,"K" ,"M" ,"N"};
    
    for (int i=0; i<10; i++)
    {
        v_Counter.put(v_ABC[i] ,Help.random(10));
    }
    
    System.out.println("-- 正排序Map.value");
    Help.print(Help.toSortByMap(   v_Counter));
    
    System.out.println("\n-- 倒排序Map.value");
    Help.print(Help.toReverseByMap(v_Counter));
}
 
Example #19
Source File: TaskTypeTotal.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 获取某一任务类型的活动线程数
 * 
 * @param i_TaskType
 * @return
 */
public long getActiveCount(String i_TaskType)
{
	if ( Help.isNull(i_TaskType) )
	{
		throw new NullPointerException("Task Type is null");
	}
	
	if ( this.totalMap.containsKey(i_TaskType) )
	{
		return this.totalMap.get(i_TaskType).getActiveCount();
	}
	else
	{
		return 0;
	}
}
 
Example #20
Source File: TaskGroup.java    From hy.common.tpool with Apache License 2.0 6 votes vote down vote up
/**
 * 构造器
 * 
 * @param i_TaskGroupName  任务组名称
 */
public TaskGroup(String i_TaskGroupName)
{
	if ( Help.isNull(i_TaskGroupName) )
	{
		throw new NullPointerException("Task group name is null.");
	}
	
	this.taskGroupName     = i_TaskGroupName;
	this.taskList          = new ArrayList<Task<?>>();
	this.finishSize        = 0;
	this.taskGroupIsFinish = false;
	this.tasksIsFinish     = false;
	
	setUpperTaskGroup(this);
}
 
Example #21
Source File: InitConfig.java    From hy.common.report with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private synchronized void init()
{
    if ( !$Init )
    {
        $Init = true;
        
        try
        {
            this.init("startup.Config.xml");
            this.init((List<Param>)XJava.getObject("StartupConfig") ,Help.getClassPath(this));
        }
        catch (Exception exce)
        {
            System.out.println(exce.getMessage());
            exce.printStackTrace();
        }
    }
}
 
Example #22
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
@Test
public void test_subtract()
{
    double v_Ret01 = Help.subtract("60.3" ,"60.01");
    double v_Ret02 = Help.subtract(60.3   ,60.01);
    
    System.out.println("减法的差值不等于0.29:" + (60.3 - 60.01));
    
    Assert.assertTrue("减法的差值是否相等" ,v_Ret01 == 0.29);
    Assert.assertTrue("减法的差值是否相等" ,v_Ret02 == 0.29);
}
 
Example #23
Source File: RTemplate.java    From hy.common.report with Apache License 2.0 5 votes vote down vote up
/**
 * 获取报表模板对应的工作表
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-16
 * @version     v1.0
 *
 * @return
 */
public synchronized Sheet getTemplateSheet()
{
    if ( null == this.templateSheet )
    {
        this.isCheck = true;
        
        List<Sheet> v_Sheets = ExcelHelp.read(this.excelFileName);
        
        if ( Help.isNull(v_Sheets) )
        {
            this.templateSheet = null;
        }
        else
        {
            this.templateSheet = v_Sheets.get(this.sheetIndex);
        }
        
        this.init();
        
        this.getExcelVersion();
        
        if ( this.getTitlePageHeaderFirstWriteByRow() >= 1 )
        {
            this.titlePageHeaderFirstWriteByRealDataCount = this.getTitlePageHeaderFirstWriteByRow() - this.getRowCountTitlePageFooter() - this.getRowCountTitle();
            this.titlePageHeaderRate                      = this.getRowCountTitlePageHeader();
        }
        else
        {
            this.titlePageHeaderFirstWriteByRealDataCount = 0;
            this.titlePageHeaderRate                      = 0;
        }
    }
    
    return this.templateSheet;
}
 
Example #24
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
@Test
public void test_division()
{
    double v_Ret01 = Help.division("1" ,"3");
    double v_Ret02 = Help.division(1   ,3);
    
    System.out.println("除法的差值不等于0.333333333:" + (1.0 / 3.0));
    
    Assert.assertTrue("减法的差值是否相等" ,v_Ret01 == 0.333333333);
    Assert.assertTrue("减法的差值是否相等" ,v_Ret02 == 0.333333333);
}
 
Example #25
Source File: ExcelHelp.java    From hy.common.report with Apache License 2.0 5 votes vote down vote up
/**
 * 创建一个工作表
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-16
 * @version     v1.0
 *
 * @param i_Workbook   工作薄对象
 * @param i_SheetName  工作表名称(当为空时,自动生成)
 * @return
 */
public final static Sheet createSheet(Workbook i_Workbook ,String i_SheetName) 
{
    int    v_SheetCount = i_Workbook.getNumberOfSheets();
    String v_SheetName  = i_SheetName;
    
    if ( Help.isNull(v_SheetName) ) 
    {
        v_SheetName = "sheet" + (v_SheetCount + 1);
    }
    
    return i_Workbook.createSheet(v_SheetName);
}
 
Example #26
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
public void test_toList()
{
    List<JU_XJSON> v_Datas = new ArrayList<JU_XJSON>();
    
    v_Datas.add(new JU_XJSON("00" ,"1"   ,1));
    v_Datas.add(new JU_XJSON("01" ,"10"  ,2));
    v_Datas.add(new JU_XJSON("02" ,"11"  ,3));
    
    System.out.println("\n\n按SID列抽取");
    Help.print(Help.toList(v_Datas ,"SID"));
    
    System.out.println("\n\n按doubleValue列抽取");
    Help.print(Help.toList(v_Datas ,"doubleValue"));
}
 
Example #27
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
public void test_toDistinct()
{
    List<JU_XJSON> v_Datas = new ArrayList<JU_XJSON>();
    
    v_Datas.add(new JU_XJSON("00" ,"1"   ,1));
    v_Datas.add(new JU_XJSON("01" ,"10"  ,2));
    v_Datas.add(new JU_XJSON("02" ,"11"  ,3));
    v_Datas.add(new JU_XJSON("00" ,"111" ,4));
    v_Datas.add(new JU_XJSON("03" ,"2"   ,5));
    
    System.out.println("\n\n重除显示");
    Help.toDistinct(v_Datas ,"SID");
    Help.print(v_Datas);
}
 
Example #28
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
/**
 * 测试数据排序
 * 
 * @author      ZhengWei(HY)
 * @createDate  2016-02-20
 * @version     v1.0
 *
 */
public void test_SortArray()
{
    System.out.println("-- 测试元素个数为偶数的倒序排序");
    Help.print(Help.toReverse(new int[]{1 ,2 ,3 ,4}));
    
    System.out.println("-- 测试元素个数为奇数的倒序排序");
    Help.print(Help.toReverse(new int[]{1 ,2 ,3}));
}
 
Example #29
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getClasses()
{
    List<Class<?>> v_Ret = Help.getClasses("org.hy.common.一个不存在包名");
    
    Help.print(v_Ret);
}
 
Example #30
Source File: JU_Help.java    From hy.common.base with Apache License 2.0 5 votes vote down vote up
@Test
public void test_toSortByNum()
{
    System.out.println("\n\n正序排序。不改变数据格式");
    Help.print(Help.toSortByNum("3.1" ,"3.0" ,"3.010"));
    
    System.out.println("\n\n倒序排序。不改变数据格式");
    Help.print(Help.toReverseByNum("3.1" ,"3.0" ,"3.010"));
}