My Dears:
亲们:
みなさん:
写这篇文章不容易,所以看到这个话,请留下您的足迹
今天写了一个工具,是将String型的逻辑表达式变成Boolean型的,写的很粗糙,但基本功能实现。
为什么要写这个,因为java对解释型的判断很差,所以做了这个工具的话,java也可以做解释操作了
嘿嘿,别的就不说了具体的下面操作:
package com.chenhailong.exception;
/**
*
* @author chenhailong
*下午07:30:53
*com.chenhailong.exception
*/
public class IllegalAugmentException extends Exception{
/**
*
*/
private static final long serialVersionUID = 4240091329381438566L;
public IllegalAugmentException(Exception e) {
super(e);
}
}
package com.chenhailong.main;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import com.chenhailong.exception.IllegalAugmentException;
/**
*
* @author chenhailong
* 下午07:29:51
* com.chenhailong.main
*/
public class StringExpressToBoolean {
private static final String JAVASCRIPTLAN = "JavaScript";
private static final String SUCCESS = "Success";
private static final String FAILED = "Failed";
private static final String FILENAME = "IFcontroller.txt";
public static void main(String[] args) {
try {
String str = getStringFromFile();
System.out.println(str);
boolean bool = getLogic(str);
if (bool) {
System.out.println(SUCCESS);
} else {
System.out.println(FAILED);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
* @param expressValue
* @return
* @throws IllegalAugmentException
* @throws ScriptException
*/
public static boolean getLogic(String expressValue)
throws IllegalAugmentException, ScriptException {
Boolean bool = null;
if (expressValue == null || expressValue.length() == 0) {
return false;
}
try {
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName(JAVASCRIPTLAN);
String foo = expressValue;
bool = Boolean.valueOf(engine.eval(foo).toString());
} catch (ScriptException e) {
throw e;
} catch (Exception e) {
throw new IllegalAugmentException(e);
}
return bool;
}
/**
*
* @return
* @throws IOException
*/
public static String getStringFromFile() throws IOException {
String str = null;
BufferedReader reader = new BufferedReader(new FileReader(new File(
FILENAME)));
while (reader.ready()) {
str = reader.readLine();
}
return str;
}
}
代码开源,所以也没什么,希望大家努力将这个工具发扬光大,让他成为你项目中的亮点
嘻嘻,多多留言
分享到:
相关推荐
Copyright Notice and Proprietary Information Copyright Notice and Proprietary Information
VS2012 插件,可在项目文档中自动写入Copyright 信息, 1.下载资源解压 2.将Addins 文件夹放入 我的文档-〉Visual Studio 2012文件夹下 3.重启Visual Studio 2012即可看到工具栏多出一个添加Copyright按钮 4.在项目...
copyright的下载包和数据包
Copyright .html
qt creator 新建文件说明模板,copyright模板,文件说明、作者、描述信息、创建时间、版权信息等
前端开源库-typographic-copyright印刷版权,不使用字母替代品
AnCal is personal information management software.
考贝工具,非常好用,大家可以试试,后台运行,不影响运行速度
var Copyright = require ( 'react-copyright' ) ; var Component = React . createClass ( { render : function ( ) { return ( < Copyright> Jason Bellamy < / Copyright > ) ; } } ) ; 选项 财产 类型 ...
Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html
程序写好了,没有加版权信息. 就自己写了一个对指定类型文件批量加入版权信息.
主要用于查看一些系统信息!比如用户名名与主机名IP地址等!
Autoit Copyright UDF
:copyright:一个Svelte组件,用于格式化和显示版权声明。 一个组件,用于格式化和显示版权声明。 安装 该软件包在NPM上可用,您可以使用npm或yarn安装它: npm install svelte-copyright yarn add svelte-...
软件著作权申请教程和模板文档,附带源代码统计工具 1)申请表(单面打印,签名) 2)源码文档(单面打印,签名) 3)软件设计文档或者使用说明文档
Copyright Violations
Watermarking Techniques for Copyright Protection of Videos,Ashish M. Kothari • Vedvyas Dwivedi Rohit M. Thanki,2019
FusionBridge 6.3.0 Copyright Notice 01.zip
wp-display-copyright=== WP Display Copyright ===Contributors: waitigTags: copyright,wordpress,Requires at least: 2.0Tested up to: 4.2.1Stable tag: 1.0License: GPLv2 or laterLicense URI: Donate link: ...