📄 functionmatchpart.java
字号:
/* * @(#)$Id: FunctionMatchpart.java,v 1.3 2005/03/07 22:17:32 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;import java.util.Iterator;/** * Class FunctionConcat * */public class FunctionMatchpart extends FunctionIsmatchpart implements Function { /** * Method evaluate * * @param parameters * @return */ public Object evaluate(Object[] parameters) { int params = parameters.length; if ((params == 3) || (params == 4) || (params == 5)) { String delim1 = parameters[2].toString(); String delim2 = (params == 4) ? parameters[3].toString() : delim1; boolean toDistance = (params == 5) ? ((Boolean) parameters[4]).booleanValue() : true; ArrayList set1 = (ArrayList) getParts(new ArrayList(), parameters[0].toString(), delim1); ArrayList set2 = (ArrayList) getParts(new ArrayList(), parameters[1].toString(), delim2); return new Integer(haveMatch(set1, set2, toDistance)); } else { return null; } } /** * Method getDistance * * @param count1 * @param size1 * @param count2 * @param size2 * @param toDistance * @return */ protected int getDistance(int count1, int size1, int count2, int size2, boolean toDistance) { if (toDistance) { if (count1 > count2) { return count1; } else { return count2; } } else { int from1 = size1 - count1; int from2 = size2 - count2; if (from1 > from2) { return from2; } else { return from1; } } } /** * Method haveMatch * * @param set1 * @param set2 * @param toDistance * @return */ protected int haveMatch(Collection set1, Collection set2, boolean toDistance) { int count1 = 0; int count2 = 0; Iterator iterator1 = set1.iterator(); while (iterator1.hasNext()) { count1++; Object head1 = iterator1.next(); count2 = 0; Iterator iterator2 = set2.iterator(); while (iterator2.hasNext()) { count2++; Object head2 = iterator2.next(); if (head1.equals(head2)) { return getDistance(count1, set1.size(), count2, set2.size(), toDistance); } } } return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -