⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functionmatchbytes.java

📁 High performance DB query
💻 JAVA
字号:
/* * @(#)$Id: FunctionMatchbytes.java,v 1.2 2005/03/08 02:17:09 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704.  Attention:  Intel License Inquiry. */package pier.helpers.functions;import java.util.ArrayList;import java.util.Collection;/** * Class FunctionConcat * */public class FunctionMatchbytes extends FunctionMatchpart implements Function {    /**     * Method evaluate     *     * @param parameters     * @return     */    public Object evaluate(Object[] parameters) {        int params = parameters.length;        if ((params == 3) || (params == 4)) {            Byte[] bytes1 = (Byte[]) parameters[0];            Byte[] bytes2 = (Byte[]) parameters[1];            int setLength = ((Integer) parameters[2]).intValue();            boolean toDistance = (params == 4)                                 ? ((Boolean) parameters[3]).booleanValue()                                 : true;            if ((bytes1 == null) || (bytes2 == null)) {                return new Integer(-1);            }            ArrayList set1 = (ArrayList) getParts(new ArrayList(), bytes1,                                                  setLength);            ArrayList set2 = (ArrayList) getParts(new ArrayList(), bytes2,                                                  setLength);            return new Integer(haveMatch(set1, set2, toDistance));        } else {            return null;        }    }    /**     * Method getParts     *     * @param parts     * @param bytes     * @param setLength     * @return     */    protected Collection getParts(Collection parts, Byte[] bytes,                                  int setLength) {        for (int start = 0; start < bytes.length; start += setLength) {            parts.add(new ByteSet(bytes, start, setLength));        }        return parts;    }    /**     * Class ByteSet     *     */    public class ByteSet {        private Byte[] bytes;        private int start;        private int length;        /**         * Constructor ByteSet         *         * @param bytes         * @param start         * @param length         */        public ByteSet(Byte[] bytes, int start, int length) {            this.bytes = bytes;            this.start = start;            this.length = length;        }        /**         * Method equals         *         * @param other         * @return         */        public boolean equals(Object other) {            if (other instanceof ByteSet) {                ByteSet otherSet = (ByteSet) other;                if (otherSet.length == length) {                    for (int i = 0; i < length; i++) {                        if ( !(bytes[start + i].equals(                                otherSet.bytes[otherSet.start + i]))) {                            return false;                        }                    }                    return true;                }                return false;            } else {                throw new RuntimeException(                    "Unsupported data type for comparing: " + this.getClass()                    + " and " + other.getClass());            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -