forked from fanruan/design
Qinghui.Liu
4 years ago
22 changed files with 707 additions and 433 deletions
@ -0,0 +1,61 @@
|
||||
package com.fr.design.utils; |
||||
|
||||
import com.fr.base.Parameter; |
||||
import com.fr.base.ParameterHelper; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.ArrayUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: Yuan.Wang |
||||
* @Date: 2020/8/11 |
||||
*/ |
||||
public class ParameterUtils { |
||||
/** |
||||
* 获得新的参数集合,返回的集合中的参数的顺序为:新增参数全部放在后面,以保证原有参数的相对顺序 |
||||
* |
||||
* @param paramTexts sql语句 |
||||
* @param oldParameters 旧的参数集合 |
||||
* @return 新参数集合 |
||||
*/ |
||||
public static Parameter[] analyzeAndUnionParameters(String[] paramTexts, Parameter[] oldParameters) { |
||||
Parameter[] newParameters = ParameterHelper.analyze4Parameters(paramTexts, false); |
||||
return unionParametersInRelativeOrder(oldParameters, newParameters); |
||||
} |
||||
|
||||
/** |
||||
* 合并新旧参数集合,新增参数全部放在后面,以保证原有参数的相对顺序 |
||||
* |
||||
* @param oldParameters 旧的参数集合 |
||||
* @param newParameters 新的参数集合 |
||||
* @return 新参数集合 |
||||
*/ |
||||
private static Parameter[] unionParametersInRelativeOrder(Parameter[] oldParameters, Parameter[] newParameters) { |
||||
if (ArrayUtils.isEmpty(newParameters) || ArrayUtils.isEmpty(oldParameters)) { |
||||
return newParameters; |
||||
} |
||||
|
||||
Parameter[] result = new Parameter[newParameters.length]; |
||||
List<Parameter> newParameterList = new ArrayList<>(Arrays.asList(newParameters)); |
||||
int i = 0; |
||||
//遍历旧参数数组中的参数,如果新参数list中存在同名参数,将该参数加入到result里,同时删除list中的同名参数
|
||||
for (Parameter oldParameter : oldParameters) { |
||||
Iterator<Parameter> iterator = newParameterList.listIterator(); |
||||
while (iterator.hasNext()) { |
||||
Parameter newParameter = iterator.next(); |
||||
if (ComparatorUtils.equals(oldParameter.getName(), newParameter.getName())) { |
||||
result[i++] = oldParameter; |
||||
iterator.remove(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
//将新参数list中的剩余参数添加到result中
|
||||
System.arraycopy(newParameterList.toArray(new Parameter[0]), 0, result, i, newParameterList.size()); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.fr.design.utils; |
||||
|
||||
import com.fr.base.Parameter; |
||||
import junit.framework.TestCase; |
||||
|
||||
/** |
||||
* @Author: Yuan.Wang |
||||
* @Date: 2020/8/11 |
||||
*/ |
||||
public class ParameterUtilsTest extends TestCase { |
||||
public void testAnalyzeAndUnionParameters() { |
||||
String[] paramTexts = {"${a}${b}${d}", ""}; |
||||
Parameter[] oldParameters = new Parameter[]{new Parameter("c"), new Parameter("b"), new Parameter("a")}; |
||||
Parameter[] rightResult = new Parameter[]{new Parameter("b"), new Parameter("a"), new Parameter("d")}; |
||||
Parameter[] result = ParameterUtils.analyzeAndUnionParameters(paramTexts, oldParameters); |
||||
assertEquals(result.length, rightResult.length); |
||||
for (int i = 0; i < rightResult.length; i++) { |
||||
assertEquals(rightResult[i].getName(), result[i].getName()); |
||||
} |
||||
|
||||
paramTexts = new String[]{"${a}${b}${d}", ""}; |
||||
oldParameters = new Parameter[]{}; |
||||
rightResult = new Parameter[]{new Parameter("a"), new Parameter("b"), new Parameter("d")}; |
||||
result = ParameterUtils.analyzeAndUnionParameters(paramTexts, oldParameters); |
||||
assertEquals(result.length,rightResult.length); |
||||
|
||||
paramTexts = new String[]{"${b}", ""}; |
||||
oldParameters = new Parameter[]{new Parameter("b"), new Parameter("a"), new Parameter("d")}; |
||||
rightResult = new Parameter[]{new Parameter("b")}; |
||||
result = ParameterUtils.analyzeAndUnionParameters(paramTexts, oldParameters); |
||||
assertEquals(result.length,rightResult.length); |
||||
assertEquals(result.length, rightResult.length); |
||||
for (int i = 0; i < rightResult.length; i++) { |
||||
assertEquals(rightResult[i].getName(), result[i].getName()); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.fr.grid.action; |
||||
|
||||
import com.fr.design.os.impl.SupportOSImpl; |
||||
import com.fr.grid.Grid; |
||||
import com.fr.grid.help.GridHelper; |
||||
import com.fr.stable.os.support.OSBasedAction; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/8/12 |
||||
*/ |
||||
public class GridInputAction implements OSBasedAction { |
||||
|
||||
private Grid grid; |
||||
private char ch; |
||||
|
||||
@Override |
||||
public void execute(Object... objects) { |
||||
// win下韩语输入法与其他输入法不一样 在输入第二个字符时 就开始触发keyType 而其中grid的焦点转移会导致输入失效
|
||||
boolean accept = SupportOSImpl.KOREAN_INPUT.support() && grid != null; |
||||
if (accept) { |
||||
grid.setNeedRequestFocus(!GridHelper.isKoreanCharacter(ch)); |
||||
} |
||||
} |
||||
|
||||
public void register(Grid grid, char ch) { |
||||
this.grid = grid; |
||||
this.ch = ch; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.grid.help; |
||||
|
||||
/** |
||||
* 韩文unicode编码范围 |
||||
* http://www.ch2ko.com/hanguoyu/hanwen-unicode/
|
||||
* |
||||
* 韩文音节:AC00-D7AF |
||||
* Character.UnicodeBlock.HANGUL_SYLLABLES |
||||
* https://www.unicode.org/charts/PDF/UAC00.pdf
|
||||
* |
||||
* |
||||
* 韩文兼容字母:3130-318F |
||||
* Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO |
||||
* https://www.unicode.org/charts/PDF/U3130.pdf
|
||||
* |
||||
* |
||||
* 韩文字母:1100-11FF |
||||
* Character.UnicodeBlock.HANGUL_JAMO |
||||
* https://www.unicode.org/charts/PDF/U1100.pdf
|
||||
* |
||||
* |
||||
* 韩文字母扩展A |
||||
* Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_A |
||||
* https://www.unicode.org/charts/PDF/UA960.pdf
|
||||
* |
||||
* |
||||
* 韩文字母扩展B |
||||
* haracter.UnicodeBlock.HANGUL_JAMO_EXTENDED_B |
||||
* https://www.unicode.org/charts/PDF/UD7B0.pdf
|
||||
* |
||||
* |
||||
* 使用java内部的韩文unicode集判断 |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/8/7 |
||||
*/ |
||||
public class GridHelper { |
||||
/** |
||||
* 韩国货币符号 |
||||
*/ |
||||
private static final char HEX_20A9 = 0x20A9; |
||||
|
||||
public static boolean isKoreanCharacter(char value) { |
||||
Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(value); |
||||
return unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO |
||||
|| unicodeBlock == Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO |
||||
|| unicodeBlock == Character.UnicodeBlock.HANGUL_SYLLABLES |
||||
|| unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_A |
||||
|| unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_B |
||||
|| value == HEX_20A9; |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.fr.grid.help; |
||||
|
||||
import junit.framework.TestCase; |
||||
import org.junit.Assert; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2020/8/7 |
||||
*/ |
||||
public class GridHelperTest extends TestCase { |
||||
|
||||
/** |
||||
* 为空 |
||||
*/ |
||||
private char ch; |
||||
|
||||
public void testIsKoreanCharacter() { |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('1')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('A')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('z')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('测')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('測')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('鐪')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('&')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter(' ')); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter(ch)); |
||||
Assert.assertFalse(GridHelper.isKoreanCharacter('は')); |
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('먀')); |
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('이')); |
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('한')); |
||||
// 韩文音节
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('휖')); |
||||
// 韩文兼容字母
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('ㆋ')); |
||||
// 韩文字母
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('ᇪ')); |
||||
// 韩文字母扩展A
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('ꥵ')); |
||||
// 韩文字母扩展B
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('ퟂ')); |
||||
// 韩文货币符号
|
||||
Assert.assertTrue(GridHelper.isKoreanCharacter('₩')); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue