惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - qjlyp

群发UDP的性能测试 (摘自:http://www.cnblogs.com/trywebservice/archive/2008/02/19/1073642.html) 从底层了解ASP.NET体系结构 (http://www.cnblogs.com/rijing2004/archive/2007/09/14/howaspnetwork.html#8) 如何用C#编程方式批量对域控制器添加OU(http://topic.csdn.net/t/20051026/11/4351176.html) C# 高级编程(第3版)--Active Directory编程(http://blog.chinaunix.net/u/884/showart_230743.html) LDAP应用程序接口(http://www.networkdictionary.cn/rfc/rfc1823.php#6) - qjlyp 定制你的LDAP目录的Schema(http://www.infoxa.com/asp/tech_file/xxnr_tech_201.htm) 浅析.Net下Active Directory(AD)编程技术(from :http://www.zysun.com/ldap/21944.html) 活动目录.NET编程Tips(摘:http://www.lupaworld.com/22221/viewspace_17754.html) 应用软件人才体系图 针对构架师的.NET 3.0 框架介绍( 摘自:http://www.chinaaspx.com/dotnet/aspnet/20070811/3489.html) Solving problems while passing XML into a Stored Procedure Rremoting 实现SQL Server 2005快速Web分页 让你的SQL数据库优化使之运行得更快 interoperate beneath C#基础概念二十五问 ASP.Net中利用CSS实现多界面两法【转自:中国站长站】 ASP.NET生成静态HTML页面并分别按年月目录存放[来自:中国站长站]
如何用Java 实现 Excel 表达式的解析(摘自:http://topic.csdn.net/t/20030408/17/1634982.html#)
qjlyp · 2008-10-27 · via 博客园 - qjlyp

import   java.util.*;  
  public   class   Calculator  
  {  
   
  public   Calculator(){  
   
  }  
  /*  
  public   Calculator(String   data)  
  {  
  bits   =   data.toCharArray();  
  }  
  */  
   
   
  /**  
    *   计算  
    *   @return   double类型的计算结果  
    *   @throws   ArithmeticException   计算出现错误  
    *   @throws   NumberFormatException   数据格式错误  
    */  
  public   double   evaluate(String   data)  
  throws   ArithmeticException,   NumberFormatException  
  {  
  if(data.toLowerCase().indexOf("if")>=0)  
  data   =   evalIfFunction(data);  
  bits   =   data.toCharArray();  
  pos   =   0;  
  double   ret   =   evalPlusMinus();  
   
  if   (pos   !=   bits.length)   {  
  throw   new   NumberFormatException("Garbage   at   end   of   equation");  
  }  
   
  return   ret;  
  }  
   
   
  public   double   evaluate(double   x,   String   data)  
  throws   ArithmeticException,   NumberFormatException  
  {  
  this.x   =   x;  
  return   evaluate(data);  
  }  
   
  private   void   skipWS()  
  {  
  while   ((pos   <   bits.length)   &&   Character.isWhitespace(bits[pos]))   {  
  pos++;  
  }  
  }  
   
  private   double   evalReal()   throws   NumberFormatException  
  {  
  skipWS();  
  int   save   =   pos;  
   
  while   ((pos   <   bits.length)   &&   Character.isDigit(bits[pos]))   {  
  pos++;  
  }  
   
  if   ((pos   ==   save)   &&   (bits[pos]   !=   '.'))   {  
  throw   new   NumberFormatException("pos   !=   save");  
  }  
   
  if   ((pos   <   bits.length)   &&   bits[pos]   ==   '.')   {  
  int   saved   =   ++pos;  
   
  while   ((pos   <   bits.length)   &&   Character.isDigit(bits[pos]))   {  
  pos++;  
  }  
   
  if   (pos   ==   saved)   {  
  throw   new   NumberFormatException("Invalid   numeric   literal");  
  }  
  }  
   
  return   Double.valueOf(new   String(bits,   save,   pos-save)).doubleValue();  
  }  
   
  private   double   evalSymbol()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   0.0;  
  int   skip   =   pos;  
   
  while   ((skip   <   bits.length)&&   Character.isLetterOrDigit(bits[skip]))   {  
  skip++;  
  }  
   
  if   (skip   >   pos)   {  
  String   symbol   =   new   String(bits,   pos,   skip-pos);  
   
  if   (symbol.equals("pi"))   {  
  lhs   =   Math.PI;  
  }   else   if   (symbol.equals("e"))   {  
  lhs   =   Math.E;  
  }   else   if   (symbol.equals("x"))   {  
  lhs   =   x;  
  }   else   {  
  throw   new   NumberFormatException("Unknown   symbol:   "   +   symbol);  
  }  
  pos   =   skip;  
  }  
   
  return   lhs;  
  }  
   
   
  private   double   evalFunction()  
  throws   ArithmeticException,   NumberFormatException,  
        SymbolNotFoundException  
  {  
  double   lhs   =   0.0;  
  int   skip   =   pos;  
   
  while   ((skip   <   bits.length)&&   Character.isLetterOrDigit(bits[skip]))   {  
  skip++;  
  }  
   
  if   (skip   >   pos)   {  
  String   symbol   =   new   String(bits,   pos,   skip-pos);  
  int   saved   =   pos;   pos   =   skip;  
   
  if   (symbol.equals("sin"))   {  
  lhs   =   Math.sin(evalTerm());  
  }   else   if   (symbol.equals("cos"))   {  
  lhs   =   Math.cos(evalTerm());  
  }   else   if   (symbol.equals("tan"))   {  
  lhs   =   Math.tan(evalTerm());  
  }   else   if   (symbol.equals("asin"))   {  
  lhs   =   Math.asin(evalTerm());  
  }   else   if   (symbol.equals("acos"))   {  
  lhs   =   Math.acos(evalTerm());  
  }   else   if   (symbol.equals("atan"))   {  
  lhs   =   Math.atan(evalTerm());  
  }   else   if   (symbol.equals("ln"))   {  
  lhs   =   Math.log(evalTerm());  
  }   else   if   (symbol.equals("deg"))   {  
  lhs   =   Math.toDegrees(evalTerm());  
  }   else   if   (symbol.equals("rad"))   {  
  lhs   =   Math.toRadians(evalTerm());  
  }   else{  
  pos   =   saved;  
  throw   new   SymbolNotFoundException();  
  }  
   
  if   (Double.isNaN(lhs))   {  
  throw   new   ArithmeticException(symbol   +   ":   Invalid   Domain");  
  }  
  }  
   
  return   lhs;  
  }  
   
  private   double   evalTerm()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   0.0;  
  skipWS();  
   
  switch   (bits[pos])   {  
  case   '(':  
  pos++;  
  lhs   =   evalPlusMinus();  
  skipWS();  
  if   ((pos   <   bits.length)   &&   (bits[pos]   ==   ')'))   {  
  pos++;  
  }   else   {  
  throw   new   NumberFormatException("Missing   ')'   in   expression");  
  }  
  break;  
  case   '[':  
  pos++;  
  lhs   =   evalPlusMinus();  
  skipWS();  
  if   ((pos   <   bits.length)   &&   (bits[pos]   ==   ']'))   {  
  pos++;  
  }   else   {  
  throw   new   NumberFormatException("Missing   ']'   in   expression");  
  }  
  break;  
   
  default:  
  if   (Character.isDigit(bits[pos])   ||   (bits[pos]   ==   '.'))   {  
  lhs   =   evalReal();  
  }   else   if   (Character.isLetter(bits[pos]))   {  
  try   {  
  lhs   =   evalFunction();  
  }   catch   (SymbolNotFoundException   sym)   {  
  lhs   =   evalSymbol();  
  }  
  }   else   {  
  throw   new   NumberFormatException("Expecting   Term");  
  }  
  break;  
  }  
   
  return   lhs;  
  }  
  private   double   evalUnary()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   0.0;  
  skipWS();  
   
  if   (pos   >=   bits.length)   {  
  throw   new   NumberFormatException("Premature   expression   end");  
  }  
   
  switch   (bits[pos])   {  
  case   '-':  
  pos++;  
  lhs   =   -evalUnary();  
  break;  
  case   '+':  
  pos++;  
  lhs   =   evalUnary();  
  break;  
  default:  
  lhs   =   evalTerm();  
  break;  
  }  
   
  return   lhs;  
  }  
   
  private   double   evalExponent()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   evalUnary();  
  boolean   need_more   =   true;  
  skipWS();  
   
  while   ((pos   <   bits.length)   &&   need_more)   {  
  switch   (bits[pos])   {  
  case   '^':  
  pos++;  
  lhs   =   Math.pow(lhs,   evalUnary());  
  break;  
  case   '!':  
  int   lhs_int   =   (int)lhs;  
  pos++;  
   
  if   (lhs   <   0   ||   lhs_int   !=   lhs)   {  
  throw   new   ArithmeticException("Invalid   domain");  
  }  
   
  lhs   =   1.0;  
  for(int   i   =   2;   i   <=   lhs_int;   i++)   {  
  lhs   *=   i;  
  }  
  break;  
  case   '%':  
  pos++;  
  lhs   /=   100;  
  break;  
  default:  
  need_more   =   false;  
  break;  
  }  
  }  
   
  return   lhs;  
  }  
   
  private   double   evalMultDivide()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   evalExponent();  
  boolean   need_more   =   true;  
  skipWS();  
   
  while   ((pos   <   bits.length)   &&   need_more)   {  
  switch   (bits[pos])   {  
  case   '*':  
  pos++;  
  lhs   *=   evalExponent();  
  break;  
  case   '/':  
  pos++;  
  lhs   /=   evalExponent();  
  break;  
  default:  
  need_more   =   false;  
  break;  
  }  
  }  
   
  return   lhs;  
  }  
   
  private   double   evalPlusMinus()  
  throws   ArithmeticException,   NumberFormatException  
  {  
  double   lhs   =   evalMultDivide();  
  boolean   need_more   =   true;  
  skipWS();  
   
  while   ((pos   <   bits.length)   &&   need_more)   {  
  switch   (bits[pos])   {  
  case   '-':  
  pos++;  
  lhs   -=   evalMultDivide();  
  break;  
  case   '+':  
  pos++;  
  lhs   +=   evalMultDivide();  
  break;  
  default:  
  need_more   =   false;  
  break;  
  }  
  }  
   
  return   lhs;  
  }  
   
  private   char   bits[];  
  private   int   pos   =   0;  
  private   double   x   =   0.0;  
   
  private   int   ifPos   =   0;  

 private   String   evalIfFunction(String   express)   throws   ArithmeticException,   NumberFormatException{  
  int   lastIfPos   =   express.lastIndexOf("if");  
  if(lastIfPos<0)   return   express;  
   
  ifPos   =   lastIfPos;  
  String   beforeIf   =   express.substring(0,lastIfPos);  
  String   afterIf   =   express.substring(ifPos);  
  bits   =   afterIf.toCharArray();  
  double   ifValue   =   evalLastIf();  
   
  String   nonIfString   =   beforeIf   +   String.valueOf(ifValue)   +   afterIf.substring(ifPos);  
  express   =   evalIfFunction(nonIfString);  
  return   express;  
   
  }  
  private   double   evalLastIf()   throws   ArithmeticException,   NumberFormatException{  
  double   x   =   0.0;  
  skipWS();  
  int   skip   =   0;  
  String   compareExpress=null;  
  String   trueTerm=null;  
  String   falseTerm=null;  
   
  while((skip<bits.length)   &&   bits[skip]!=','){  
  skip++;  
  }  
  if(skip>0){  
  compareExpress   =   new   String(bits,   3,   skip-3);  
  }  
  //get   the   true   expression  
  skip++;  
  ifPos   =   skip;  
  while(   (skip<bits.length)&&   bits[skip]!=','){  
  skip++;  
  }  
  if(skip>pos){  
  trueTerm   =   new   String(bits,   ifPos,   skip-ifPos);  
  ifPos   =   skip;  
  }  
  //get   the   false   expression  
  skip++;  
  ifPos   =   skip;  
  int   leftBracket   =   0;  
  int   rightBracket   =   0;  
  while((skip<bits.length)   &&   bits[skip]!=')'){  
  if(bits[skip]=='('){  
  leftBracket   ++;  
  }  
  skip++;  
  }  
  while(rightBracket<leftBracket+1){  
  if(bits[skip]==')'){  
  rightBracket++;  
  }  
  skip++;  
  }  
  if(skip>ifPos){  
  falseTerm   =   new   String(bits,   ifPos,   skip-ifPos-1);  
  ifPos   =   skip;  
  }  
   
  boolean   compare   =   evalCompare(compareExpress);  
  if(compare){  
  x   =   this.evaluate(trueTerm);  
  }else{  
  x   =   this.evaluate(falseTerm);  
  }  
  return   x;  
  }  
  private   boolean   evalCompare(String   express)   throws   ArithmeticException,   NumberFormatException   {  
  boolean   isTrue   =   false;  
  char[]   ifBits   =   express.toCharArray();  
  String   partA   =   null;  
  String   partB   =   null;  
  String   compareType   =   null;  
   
  int   i   =   0;  
  int   skip   =   0;  
  while(skip<ifBits.length   &&   !isCompareFlag(ifBits[skip])){  
  skip++;  
  }  
  partA   =   new   String(ifBits,   i,   skip);  
  i   =   skip;  
   
  if(ifBits[skip+1]!='='){  
  compareType   =   new   String(ifBits,skip,1);  
  partB   =   new   String(ifBits,++skip,ifBits.length   -   skip);  
  }else{  
  compareType   =   new   String(ifBits,   skip,   2);  
  partB   =   new   String(ifBits,   skip+2,   ifBits.length   -   skip-2);  
  }  
  double   a   =   this.evaluate(partA);  
  double   b   =   this.evaluate(partB);  
  if(compareType.length()==1){  
  char[]   compareChar   =   compareType.toCharArray();  
  switch(compareChar[0]){  
  case   '>':  
  return   (a>b);  
  case   '<':  
  return   (a<b);  
  case   '=':  
  return   (a==b);  
  default:  
  return   false;  
  }  
  }else{  
  if(compareType.equals(">=")){  
  return   (a>b   ||   a==b);  
  }else   if(compareType.equals("<=")){  
  return   (a<b   ||   a==b);  
  }  
  }  
   
  return   isTrue;  
  }  
  private   boolean   isCompareFlag(char   c){  
  boolean   isCompare   =   false;  
  switch(c){  
  case   '>':  
  return   true;  
  case   '<':  
  return   true;  
  case   '=':  
  return   true;  
  }  
  return   false;  
  }  
   
   
  }