求两个字符串的最大公共子序列的长度

@param arg0 字符串1
@param arg1 字符串2
@return 两个字符串的最大公共子序列的长度，例：
<ul>
<li>123456和456789的lcs为3</li>
<li>123456和256789的lcs为3</li>
<li>123456和556489的lcs为2</li>
</ul>
18410
public static long lcs(String arg0, String arg1) {
        if (arg0 == null || arg1 == null) {
            return 0;
        }
        return lcs(arg0, arg1, 0, 0);
    }
1180152
public static void main(String[] args) throws Exception {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("table", "my_table_name");
        parameters.put("id", "my_id");
        parameters.put(":1", "first_param");

        final Pattern PATTERN = Pattern.compile("\\{([a-zA-Z0-9_\\.\\:]+)\\}|##\\((.+)\\)");

        String sql = "select form ##(:table) {name} where {id}='{1}'";

        StringBuilder sb = new StringBuilder(sql.length() + 200);
        Matcher matcher = PATTERN.matcher(sql);
        int start = 0;
        while (matcher.find(start)) {
            sb.append(sql.substring(start, matcher.start()));
            String group = matcher.group();
            String key = null;
            if (group.startsWith("{")) {
                key = matcher.group(1);
            } else if (group.startsWith("##(")) {
                key = matcher.group(2);
            }
            System.out.println(key);
            if (key == null || key.length() == 0) {
                continue;
            }
            Object value = parameters.get(key); // 针对{paramName}、{:1}两种情况
            if (value == null) {
                if (key.startsWith(":") || key.startsWith("$")) {
                    value = parameters.get(key.substring(1)); // 针对{:paramName}的情况
                } else {
                    char ch = key.charAt(0);
                    if (ch >= '0' && ch <= '9') {
                        value = parameters.get(":" + key); // 针对{1}两种情况
                    }
                }
            }
            if (value == null) {
                value = parameters.get(key); // 针对常量的情况
            }
            if (value != null) {
                sb.append(value);
            } else {
                sb.append(group);
            }
            start = matcher.end();
        }
        sb.append(sql.substring(start));
        System.out.println(sb);

    }
831975
public static Name getArgumentAsName(Object arg) {
        if (arg instanceof String) {
            return LdapUtils.newLdapName((String) arg);
        } else if (arg instanceof Name) {
            return (Name) arg;
        } else {
            throw new IllegalArgumentException(
                    "First argument needs to be a Name or a String representation thereof");
        }
    }
893346
public static void main3(String args[]) {
        String dbDriver = "COM.ibm.db2.jdbc.app.DB2Driver";
        String url = "jdbc:db2:sample";
        String user = "batra";
        String pass = "varunbatra";
        String querystring = "Select * from batra.employee";
        String fn;
        String ln;
        String bd;
        String sal;

        try {
            ConnectionProperties cp = new ConnectionProperties(dbDriver, url, user, pass);
            Query query = new Query(cp, querystring);
            QueryResults qs = query.execute();
            System.out.println("Number of rows = " + qs.size());

            Enumeration e = qs.getRows();
            while (e.hasMoreElements()) {
                QueryRow qr = (QueryRow) e.nextElement();
                fn = qr.getValue("FIRSTNME");
                ln = qr.getValue("LASTNAME");
                bd = qr.getValue("BIRTHDATE");
                sal = qr.getValue("SALARY");
                System.out.println(fn + " " + ln + " birthdate " + bd + " salary " + sal);
            } // while

            /*
              while (qs.next())
                {
                fn = qs.getValue("FIRSTNME");
                ln = qs.getValue("LASTNAME");
                bd = qs.getValue("BIRTHDATE");
                sal = qs.getValue("SALARY");
                System.out.println(fn + " " + ln +
                                   " birthdate " + bd +
                                   " salary " + sal);
                }
                
              qs.setCurrRow(5);
              fn = qs.getValue("FIRSTNME");
              ln = qs.getValue("LASTNAME");
              bd = qs.getValue("BIRTHDATE");
              sal = qs.getValue("SALARY");
              System.out.println(fn + " " + ln +
                                   " birthdate " + bd +
                                   " salary " + sal);
            */

        } // try
        catch (Exception e) {
            //com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.webcontainer.jsp.tsx.db.Query.main3", "414");
            System.out.println("Exception:: " + e.getMessage());
        }
        System.out.println("All is Fine!!!!!");
    }
1130969
function getEtag(buffer,callback){

    // 判断传入的参数是buffer还是stream还是filepath
    var mode = 'buffer';

    if(typeof buffer === 'string'){
        buffer = require('fs').createReadStream(buffer);
        mode='stream';
    }else if(buffer instanceof require('stream')){
        mode='stream';
    }

    // sha1算法
    var sha1 = function(content){
        var crypto = require('crypto');
        var sha1 = crypto.createHash('sha1');
        sha1.update(content);
        return sha1.digest();
    };

    // 以4M为单位分割
    var blockSize = 4*1024*1024;
    var sha1String = [];
    var prefix = 0x16;
    var blockCount = 0;

    switch(mode){
        case 'buffer':
            var bufferSize = buffer.length;
            blockCount = Math.ceil(bufferSize / blockSize);

            for(var i=0;i<blockCount;i++){
                sha1String.push(sha1(buffer.slice(i*blockSize,(i+1)*blockSize)));
            }
            process.nextTick(function(){
                callback(calcEtag());
            });
            break;
        case 'stream':
            var stream = buffer;
            stream.on('readable', function() {
                var chunk;
                while (chunk = stream.read(blockSize)) {
                    sha1String.push(sha1(chunk));
                    blockCount++;
                }
            });
            stream.on('end',function(){
                callback(calcEtag());
            });
            break;
    }

    function calcEtag(){
        if(!sha1String.length){
            return 'Fto5o-5ea0sNMlW_75VgGJCv2AcJ';
        }
        var sha1Buffer = Buffer.concat(sha1String,blockCount * 20);

        // 如果大于4M，则对各个块的sha1结果再次sha1
        if(blockCount > 1){
            prefix = 0x96;
            sha1Buffer = sha1(sha1Buffer);
        }

        sha1Buffer = Buffer.concat(
            [new Buffer([prefix]),sha1Buffer],
            sha1Buffer.length + 1
        );

        return sha1Buffer.toString('base64')
            .replace(/\//g,'_').replace(/\+/g,'-');

    }

}
1033460
public static String orderBy(OrderByArg... args) {
		if (EmptyUtil.isEmpty(args) == true) {
			return "";
		}
		StringBuilder sql = new StringBuilder();
		Arrays.asList(args).forEach(arg -> {
			sql.append(arg.getColumnName());
			SortType sortType = arg.getSortType();
			if (sortType != null) {
				sql.append(" ");
				sql.append(sortType.toString());
			}
			sql.append(", ");
		});
		sql.setLength(sql.length() - ", ".length());
		return sql.toString();
	}
345784
function resolve(...args) {
    let path = '.',
        idx = 0;

    // 过滤元效参数
    path = args.reduce((str, curr) => {

        // 过滤非法参数
        if (!curr || typeof curr !== 'string') {
            return str;
        }

        // 返回绝对路径
        if (curr[0] === '/') {
            return curr;
        }

        // 返回连接后的路径
        return str + '/' + curr;
    }, path);

    // 解析路径层级
    path = path.split('/').reduce((arr, curr) => {

        if (curr === '.' || !curr) {
            return arr;
        }

        if (curr === '..') {
            idx > 0 && arr.pop();
            idx --;
        } else {
            idx >= 0 && arr.push(curr);
            idx ++;
        }

        return arr;
    }, []).join('/');

    // 返回结果
    return path[0] === '/' ? path : '/' + path;
}
1360321
protected String getSingleArgParameterAsString(Object arg) {
        if (arg instanceof String) {
            return (String) arg;
        }
        return arg == null ? "null" : arg.toString();
    }
86866
function format(str, args) {
  if (!args) {
    throw new Error("args empty!");
  }
  //判断是否是数组
  if (args.constructor == Array) {
    var l = args.length;
    var reg = /(%[sdf])/;
    for(var i= 0; i<l; i++) {
      str = str.replace(reg, args[i]);
    }
  } else if (typeof args == 'object') {
    for(var key in args) {
      var reg = new RegExp(":"+key);
      str = str.replace(reg, args[key]);
    }
  }
  return str;
}
573489
function getArguments() {
  var port = 3000;
  var path = '.';
  var args = process.argv.slice(2);

  while (args.length) {
    var arg = args.shift();
    switch (arg) {
      case '-p':
        port = args.shift();
        break;
      default:
        path = arg || path;
    }
  }

  return {
    port: port,
    path: path
  };
}
1186150
protected String getArgString(Object arg) {
        //if (arg instanceof LatLong) {
        //    return ((LatLong) arg).getVariableName();
        //} else 
        if (arg instanceof JavascriptObject) {
             return ((JavascriptObject) arg).getVariableName();
           // return ((JavascriptObject) arg).getPropertiesAsString();
        } else if( arg instanceof JavascriptEnum ) {
            return ((JavascriptEnum) arg).getEnumValue().toString();
        } else {
            return arg.toString();
        }
    }
565940
public String scanFilterArgument() {
        if (end()) {
            return null;
        }

        int cp = string.codePointAt(pos);
        if (!Character.isJavaIdentifierStart(cp)) {
            return null;
        }

        int begin = pos;
        pos += Character.charCount(cp);

        for (; pos < string.length(); pos += Character.charCount(cp)) {
            cp = string.codePointAt(pos);
            if (!Character.isJavaIdentifierPart(cp) && cp != '.' && cp != '-') {
                break;
            }
        }

        return string.substring(begin, pos);
    }
540413
public static int getLCM(int... arg) throws Exception {
        if (arg == null || arg.length == 0) {
            throw new Exception("parameters must more than one.");
        }
        if (arg.length == 1)
            return arg[0];

        int tmp = lcm(arg[0], arg[1]);

        for (int i = 2; i < arg.length; i++) {
            tmp = lcm(tmp, arg[i]);
        }

        return tmp;
    }
985988
public static boolean checkArgs(String[] args) {        
        if (args.length < 4) {
            return false;
        }
        
        if (args[0].compareToIgnoreCase("-modeldir") != 0) {
            return false;
        }
        
        if (!(args[2].compareToIgnoreCase("-inputfile") == 0 ||
                args[2].compareToIgnoreCase("-inputdir") == 0)) {
            return false;
        }
        
        return true;
    }
1190371
private static String countArgs(final String s) {
        String[] args = ARGS_REGEX.split(s);
        if ("".equals(args[1])) return "0";

        String[] argarray = args[1].split(",");
        for (final String arg : argarray)
            if (arg.contains(VARARGS_SUFFIX)) return "1 or more";
        return valueOf(argarray.length);
    }
812297
function(args) {
  var argsMap = {};
  var mainPos = 1;

  while (args[mainPos].indexOf('--') > 0) {
    mainPos++;
  }
  argsMap.main = args[mainPos];

  for (var i = (mainPos + 1); i < args.length; i++) {
    var arg = args[i];
    var sep = arg.indexOf('=');
    var key = arg.slice(0, sep);
    var value = arg.slice(sep + 1);
    if (!isNaN(Number(value)) && (value.indexOf('.') < 0)) {
      value = Number(value);
    }
    argsMap[key] = value;
  }

  return argsMap;
}
1350767
public static int getConfKey(String... args) {
    switch (args.length) {
      case 0:
        printHelp("Missing argument.");
        return 1;
      case 1:
        String varName = args[0].trim();
        String propertyName = ENV_VIOLATORS.getOrDefault(varName,
            varName.toLowerCase().replace("_", "."));
        if (!PropertyKey.isValid(propertyName)) {
          printHelp(String.format("%s is not a valid configuration key", propertyName));
          return 1;
        }
        PropertyKey key = PropertyKey.fromString(propertyName);
        System.out.println(key.getName());
        break;
      default:
        printHelp("More arguments than expected");
        return 1;
    }
    return 0;
  }