diff --git a/.gitignore b/.gitignore index 7e7fdfe008a3ab2cd14584f45ca5dbbbb6ed1c6b..6947feff7090531647488aab4f4958baaf2a39d9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ /bin/ /out/ /.idea/ +/BDPost/ +/BDPosHttp/ # Ignore Gradle GUI config gradle-app.setting diff --git a/jar/PDFLibrary.jar b/jar/PDFLibrary.jar index babf3241c644f30ae5fff6c6667bd6fa95c517e9..01918a70adf76355a12dfde91901c880aaf54a9c 100644 Binary files a/jar/PDFLibrary.jar and b/jar/PDFLibrary.jar differ diff --git a/lib/BDPost.jar b/lib/BDPost.jar new file mode 100644 index 0000000000000000000000000000000000000000..c2b1dcadff3a6e7948cbcf547eb6c1b5bb532478 Binary files /dev/null and b/lib/BDPost.jar differ diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/CObject.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/CObject.java index 4d5a5c49752e96f40b165196851d8364059b99d5..ef7752e61cc6c316c29e39853a1105013895e5e2 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/CObject.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/CObject.java @@ -1,5 +1,5 @@ package fybug.nulll.pdfunctionlibrary.Processing; -import org.jetbrains.annotations.NotNull; +import com.sun.istack.internal.NotNull; /** *

可克隆对象.

*

暴露{@link Object} 的克隆方法

diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java index 294b3cbfabdd009dd4f75e2312a02a32e3872734..af93dfec477268dc338d2cbed2c84b9adc4891f2 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/FuckChar.java @@ -1,6 +1,5 @@ package fybug.nulll.pdfunctionlibrary.Processing; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.sun.istack.internal.NotNull; import java.lang.ref.SoftReference; import java.util.HashMap; @@ -22,14 +21,14 @@ import static fybug.nulll.pdfunctionlibrary.Processing.sql.Sql.STR; *

提供各种条件下的字符过滤

* * @author fybug - * @version 0.0.4 + * @version 0.0.6 * @since PDF 1.3 */ @SuppressWarnings( "all" ) public final class FuckChar { /**

过滤表.

*/ - @NotNull private static SoftReference<@Nullable HashMap> map; + @NotNull private static volatile SoftReference> map; @NotNull private static synchronized @@ -51,6 +50,7 @@ class FuckChar { put(RN, "@010"); put(NAMEMARK, "@011"); put("@", "@012"); + put(TABMAPVAL, "@013"); }}); } @@ -70,6 +70,7 @@ class FuckChar { @NotNull String str = s.toString(); @NotNull final HashMap m = getMap(); + str = str.replaceAll("@", m.get("@")); str = str.replaceAll(ENDMARK, m.get(ENDMARK)); str = str.replaceAll(ANDPR, m.get(ANDPR)); str = str.replaceAll(GREATER, m.get(GREATER)); @@ -96,15 +97,60 @@ class FuckChar { @NotNull String str = s.toString(); @NotNull final HashMap m = getMap(); + str = str.replaceAll(m.get(PERCENTAGE), PERCENTAGE); + str = str.replaceAll(m.get(ROD), ROD); + str = str.replaceAll(m.get(ANNOTATION), ANNOTATION); + str = str.replaceAll(m.get(NAME), NAME); + str = str.replaceAll(m.get(STR), STR); + str = str.replaceAll(m.get(LESS), LESS); + str = str.replaceAll(m.get(GREATER), GREATER); + str = str.replaceAll(m.get(ANDPR), ANDPR); str = str.replaceAll(m.get(ENDMARK), ENDMARK); + str = str.replaceAll(m.get("@"), "@"); + + return str; + } + + /** + *

过滤 TabMap 关键字.

+ * + * @param s 要过滤的数据 + * + * @return 过滤后的数据 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + String fuckTabMap(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); + + str = str.replaceAll("@", m.get("@")); + str = str.replaceAll(ANDPR, m.get(ANDPR)); + str = str.replaceAll(TABMAPVAL, m.get(TABMAPVAL)); + + return str; + } + + /** + *

恢复被过滤的 TabMap 关键字.

+ * + * @param s 要恢复的数据 + * + * @return 恢复后的数据 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + String refuckTabMap(@NotNull final CharSequence s) { + @NotNull String str = s.toString(); + @NotNull final HashMap m = getMap(); + + str = str.replaceAll(m.get(TABMAPVAL), TABMAPVAL); str = str.replaceAll(m.get(ANDPR), ANDPR); - str = str.replaceAll(m.get(GREATER), GREATER); - str = str.replaceAll(m.get(LESS), LESS); - str = str.replaceAll(m.get(STR), STR); - str = str.replaceAll(m.get(NAME), NAME); - str = str.replaceAll(m.get(ANNOTATION), ANNOTATION); - str = str.replaceAll(m.get(ROD), ROD); - str = str.replaceAll(m.get(PERCENTAGE), PERCENTAGE); + str = str.replaceAll(m.get("@"), "@"); return str; } @@ -122,11 +168,11 @@ class FuckChar { @NotNull String str = s.toString(); @NotNull final HashMap m = getMap(); + str = str.replaceAll("@", "@012"); str = str.replaceAll(ANDPR, m.get(ANDPR)); str = str.replaceAll(CLASS, m.get(CLASS)); str = str.replaceAll(RN, m.get(RN)); str = str.replaceAll(NAMEMARK, m.get(NAMEMARK)); - str = str.replaceAll("@", "@012"); return str; } @@ -144,12 +190,14 @@ class FuckChar { @NotNull String str = s.toString(); @NotNull final HashMap m = getMap(); - str = str.replaceAll(m.get(ANDPR), ANDPR); - str = str.replaceAll(m.get(CLASS), CLASS); - str = str.replaceAll(m.get(RN), RN); str = str.replaceAll(m.get(NAMEMARK), NAMEMARK); + str = str.replaceAll(m.get(RN), RN); + str = str.replaceAll(m.get(CLASS), CLASS); + str = str.replaceAll(m.get(ANDPR), ANDPR); str = str.replaceAll(m.get("@"), "@"); return str; } + + @NotNull public static final String TABMAPVAL = "="; } \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Interface/NeedStop.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Interface/NeedStop.java index 7d8a2d20614d8a3bcacc05a9adb952e74baeb407..65fdb4d5fcc825fcad8356f85028857fe940d0fe 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Interface/NeedStop.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Interface/NeedStop.java @@ -1,5 +1,5 @@ package fybug.nulll.pdfunctionlibrary.Processing.Interface; -import org.jetbrains.annotations.NotNull; +import com.sun.istack.internal.NotNull; import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; /** diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java index 73e84ee5cfb35a7625bf08aacc1b39e184e5b513..42ae3c70f2c6b0c17ddad8ce127b137f222d62fc 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SelectionSort.java @@ -3,42 +3,338 @@ import com.sun.istack.internal.NotNull; import com.sun.istack.internal.Nullable; import java.io.File; -import java.lang.annotation.Retention; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import fybug.nulll.pdfunctionlibrary.Annotations.IntDef; +import fybug.nulll.pdfunctionlibrary.Processing.Sort.SortMode.FileMode; +import fybug.nulll.pdfunctionlibrary.Processing.Sort.SortMode.Mode; import fybug.nulll.pdfunctionlibrary.Util.Processing.Lists; - -import static java.lang.annotation.RetentionPolicy.SOURCE; /** *

选择排序.

*

用于对各种数据进行排序,排序方式为选择排序

* * @author fybug - * @version 0.0.5 + * @version 0.0.6 + * @see SortMode * @since PDF 1.2 */ @SuppressWarnings( "all" ) public final class SelectionSort { - /**

文件排序模式:文件夹置顶.

*/ - public static final int MODE_DIR = 0; - /**

文件排序模式:文件置顶.

*/ - public static final int MODE_FILE = 1; - /**

文件排序模式:仅对比字符.

*/ - public static final int MODE_DEFAULT = 2; - /**

排序模式:char较小的在上.

*/ - public static final int DOWN = 0; - /**

排序模式:char较大的在上.

*/ - public static final int UP = 1; /** {@Hide} */ @Deprecated private SelectionSort() {} + /* + * Int + */ + /* + * Array + */ + + /** + *

排序整数数组.

+ *
+     * 会对数组中内容按指定的方式进行排序
+     * 不会影响传入的数组
+     * 
+ * + * @param is 要排序的整数数组 + * @param sort 排序方式 + * + * @return 必定不为空 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + int[] sortInt(@Nullable final int[] is, @NotNull final Mode sort) { + if (is == null || is.length == 0) + return new int[0]; + else if (is.length == 1) + return is.clone(); + + @NotNull int[] array = is.clone(); + int j, z, // 要交换的位置 + tmp; // 当前符合标准的变量 + + switch ( sort ) { + case DOWN: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] > tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + case UP: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] < tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + } + + return array; + } + + /* + * Long + */ + /* + * Array + */ + + /** + *

排序长整数数组.

+ *
+     * 会对数组中内容按指定的方式进行排序
+     * 不会影响传入的数组
+     * 
+ * + * @param is 要排序的长整数数组 + * @param sort 排序方式 + * + * @return 必定不为空 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + long[] sortLong(@Nullable final long[] is, @NotNull final Mode sort) { + if (is == null || is.length == 0) + return new long[0]; + else if (is.length == 1) + return is.clone(); + + @NotNull long[] array = is.clone(); + int j, z; // 要交换的位置 + long tmp; // 当前符合标准的变量 + + switch ( sort ) { + case DOWN: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] > tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + case UP: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] < tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + } + + return array; + } + + /* + * Float + */ + /* + * Array + */ + + /** + *

排序单浮点数组.

+ *
+     * 会对数组中内容按指定的方式进行排序
+     * 不会影响传入的数组
+     * 
+ * + * @param is 要排序的数组 + * @param sort 排序方式 + * + * @return 必定不为空 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + float[] sortFloat(@Nullable final float[] is, @NotNull final Mode sort) { + if (is == null || is.length == 0) + return new float[0]; + else if (is.length == 1) + return is.clone(); + + @NotNull float[] array = is.clone(); + int j, z; // 要交换的位置 + float tmp; // 当前符合标准的变量 + + switch ( sort ) { + case DOWN: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] > tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + case UP: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] < tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + } + + return array; + } + + /* + * Float + */ + /* + * Array + */ + + /** + *

排序双浮点数组.

+ *
+     * 会对数组中内容按指定的方式进行排序
+     * 不会影响传入的数组
+     * 
+ * + * @param is 要排序的数组 + * @param sort 排序方式 + * + * @return 必定不为空 + * + * @since PDF 1.3 expander 2 + */ + @NotNull + public static + double[] sortDouble(@Nullable final double[] is, @NotNull final Mode sort) { + if (is == null || is.length == 0) + return new double[0]; + else if (is.length == 1) + return is.clone(); + + @NotNull double[] array = is.clone(); + int j, z; // 要交换的位置 + double tmp; // 当前符合标准的变量 + + switch ( sort ) { + case DOWN: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] > tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + case UP: + for ( int i = 0, length = array.length - 1; i < length; i++ ){ + tmp = array[i]; + z = i; + + for ( j = i + 1; j < array.length; j++ ){ + if (array[j] < tmp) { + z = j; + tmp = array[j]; + } + } + + // 交换 + tmp = array[i]; + array[i] = array[z]; + array[z] = tmp; + } + break; + } + + return array; + } + + /* + * String + */ + /* + * List + */ + /** *

对字符集合进行排序.

*

排序不会影响传入的对象.

@@ -59,7 +355,7 @@ class SelectionSort { */ @NotNull public static - List sortString(@Nullable final List a, @SortMode final int sort) + List sortString(@Nullable final List a, @NotNull final Mode sort) { if (a == null || a.size() == 0) return new ArrayList<>(); @@ -156,6 +452,10 @@ class SelectionSort { return arrayList; } + /* + * Array + */ + /** *

对文本数组进行排序.

*

排序不会影响传入的对象.

@@ -173,7 +473,7 @@ class SelectionSort { */ @NotNull public static - String[] sortString(@Nullable final String[] a, @SortMode final int sort) { + String[] sortString(@Nullable final String[] a, @NotNull final Mode sort) { if (a == null || a.length == 0) return new String[0]; else if (a.length == 1) @@ -256,6 +556,79 @@ class SelectionSort { return arrayList; } + /* + * Help + */ + + /** + *

解析排序规则.

+ * + * @param sort 排序规则 + * + * @return 错误规则返回 {@code null} + */ + @Nullable + private static + char[] getSortMode(@NotNull final Mode sort) { + @NotNull char[] cs = new char[]{0, 0}; + switch ( sort ) { + case DOWN: + cs[0] = 1; + break; + case UP: + cs[1] = 1; + break; + default: + /* 规则错误 */ + return null; + } + return cs; + } + + /** + *

检查是否所有数据都相同.

+ *
+     * 检查是否以检查到最大可检查的长度
+     * 如果是,则根据排序方式 按照数据长度 进行额外排序
+     * 
+ * + * @param sort 排序方式 + * @param index 当前标记位置 + * @param nowLeight 当前解析的长度 + * @param i1 第一个字符串的长度 + * @param i2 第二个字符串的长度 + * @param stringLenght 最大对比的长度 + * @param s 当前检查位置 + * + * @return 检查后应使用的位置 + */ + private static + int checkIndex(@NotNull final Mode sort, int index, final int nowLeight, final int i1, + final int i2, final int stringLenght, final int s) + { + // 检查是否已对比完成 + if (nowLeight == stringLenght) { + // 按照排序方式进行额外排序 + switch ( sort ) { + case UP: + if (i1 <= i2) + break; + case DOWN: + if (i2 <= i1) + break; + index = s; + } + } + return index; + } + + /* + * File + */ + /* + * Array + */ + /** *

对文件列表进行排序.

* @@ -273,14 +646,14 @@ class SelectionSort { * * @param f 即将进行排序的文件表 * @param mode 文件排序方式 - * @param sort 文本排序方式 + * @param sort 排序方式 * * @return 返回被排序好的文件列表 */ @NotNull public static - File[] sortFile(@Nullable final File[] f, @FileSortMode final int mode, - @SortMode final int sort) + File[] sortFile(@Nullable final File[] f, @NotNull final FileMode mode, + @NotNull final Mode sort) { if (f == null || f.length == 0) { return new File[0]; @@ -324,6 +697,10 @@ class SelectionSort { return file[0].toArray(new File[file[0].size()]); } + /* + * List + */ + /** *

转化为数组后用{@link #sortFile(File[], int, int)}进行排序.

* @@ -338,8 +715,8 @@ class SelectionSort { */ @NotNull public static - List sortFile(@Nullable final List f, @FileSortMode final int mode, - @SortMode final int sort) + List sortFile(@Nullable final List f, @NotNull final FileMode mode, + @NotNull final Mode sort) { if (f == null || f.size() == 0) return new LinkedList<>(); @@ -386,11 +763,15 @@ class SelectionSort { return file[0]; } + /* + * Help + */ + /** * 排序文件 */ private static - void sortFile(@SortMode int sort, LinkedList[] file) + void sortFile(@NotNull Mode sort, LinkedList[] file) { LinkedList linkedList; LinkedList list; @@ -411,43 +792,6 @@ class SelectionSort { } } - /** - *

检查是否所有数据都相同.

- *
-     * 检查是否以检查到最大可检查的长度
-     * 如果是,则根据排序方式 按照数据长度 进行额外排序
-     * 
- * - * @param sort 排序方式 - * @param index 当前标记位置 - * @param nowLeight 当前解析的长度 - * @param i1 第一个字符串的长度 - * @param i2 第二个字符串的长度 - * @param stringLenght 最大对比的长度 - * @param s 当前检查位置 - * - * @return 检查后应使用的位置 - */ - private static - int checkIndex(@SortMode final int sort, int index, final int nowLeight, final int i1, - final int i2, final int stringLenght, final int s) - { - // 检查是否已对比完成 - if (nowLeight == stringLenght) { - // 按照排序方式进行额外排序 - switch ( sort ) { - case DOWN: - if (i1 <= i2) - break; - case UP: - if (i2 <= i1) - break; - index = s; - } - } - return index; - } - /** *

获取文件排序方式.

* @@ -458,7 +802,7 @@ class SelectionSort { */ @Nullable private static - LinkedList[] getFileSortMode(@FileSortMode int mode, LinkedList[] file) { + LinkedList[] getFileSortMode(@NotNull FileMode mode, LinkedList[] file) { @NotNull LinkedList ls[] = new LinkedList[]{file[0], file[0]}; switch ( mode ) { case MODE_DIR: @@ -498,41 +842,4 @@ class SelectionSort { // 虚路径,不处理 } } - - /** - *

解析排序规则.

- * - * @param sort 排序规则 - * - * @return 错误规则返回 {@code null} - */ - @Nullable - private static - char[] getSortMode(@SortMode final int sort) { - @NotNull char[] cs = new char[]{0, 0}; - switch ( sort ) { - case UP: - cs[0] = 1; - break; - case DOWN: - cs[1] = 1; - break; - default: - /* 规则错误 */ - return null; - } - return cs; - } - - /**

文件排序类型.

*/ - @Retention( SOURCE ) - @IntDef( value = {MODE_DIR, MODE_FILE, MODE_DEFAULT} ) - private - @interface FileSortMode {} - - /**

排序类型.

*/ - @Retention( SOURCE ) - @IntDef( value = {DOWN, UP} ) - private - @interface SortMode {} -} +} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SortMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SortMode.java new file mode 100644 index 0000000000000000000000000000000000000000..a97ca79460b40905add06e842af8a3c73889f46a --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Sort/SortMode.java @@ -0,0 +1,42 @@ +package fybug.nulll.pdfunctionlibrary.Processing.Sort; +/** + *

排序方式枚举存放.

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 expander 2 + */ +public final +class SortMode { + /** + *

文件排序的方式.

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 expander 2 + */ + public + enum FileMode { + /**

文件排序模式:文件夹置顶.

*/ + MODE_DIR, + /**

文件排序模式:文件置顶.

*/ + MODE_FILE, + /**

文件排序模式:仅对比字符.

*/ + MODE_DEFAULT + } + + /** + *

常规排序方式.

+ * + * @author fybug + * @version 0.0.1 + * @since PDF 1.3 expander 2 + */ + public + enum Mode { + /**

排序模式:较小的在上.

*/ + UP, + /**

排序模式:较大的在上.

*/ + DOWN + } +} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/Stop.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/Stop.java index cfff1b420f44151a28892f097f11879edf7999c1..36f1a5b126a4f71fb924e0224e1fc0b8a7d3acbe 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/Stop.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/Stop.java @@ -1,5 +1,12 @@ package fybug.nulll.pdfunctionlibrary.Processing.Stop; + +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; + import java.io.Serializable; + +import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; +import fybug.nulll.pdfunctionlibrary.Util.DataGrid; /** *

中断.

*
@@ -11,15 +18,43 @@ import java.io.Serializable;
  * 
* * @author fybug - * @version 0.0.5 + * @version 0.0.6 * @see MaybeStop * @see CallStop * @since PDF 1.1 */ +@SuppressWarnings( "all" ) +@CanSynchronized public class Stop extends Error implements Serializable { private static final long serialVersionUID = -5863099734169161181L; Stop() { super("The error should be caught, indicating that the result is the same regardless of whether it is running or not. The interrupt function runs."); } + + /** + *

运行可能会进行停止的操作.

+ *

使用接口进行异常处理

+ * + * @param runnable 要运行的可能会中断的操作 + * @param fuck 中断处理 + * + * @return 如果没有发生异常将会返回 {@code null} ,如果发生了将会返回一个 {@link DataGrid} 里面 + * 放入处理接口返回的东西 + * + * @see StopFuck + * @since PDF 1.3 expander 2 + */ + @CanSynchronized + @Nullable + public static + DataGrid runMeberStop(@NotNull final Runnable runnable, @NotNull final StopFuck fuck) { + try { + runnable.run(); + } catch ( Stop e ) { + return DataGrid.getDataGrid(fuck.stop()); + } + + return null; + } } \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/StopFuck.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/StopFuck.java new file mode 100644 index 0000000000000000000000000000000000000000..8922ae56d0755da348a12b5affdebe87c2e039e0 --- /dev/null +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/Stop/StopFuck.java @@ -0,0 +1,22 @@ +package fybug.nulll.pdfunctionlibrary.Processing.Stop; +import com.sun.istack.internal.NotNull; +/** + *

中断处理接口.

+ *

返回处理后的消息

+ * + * @author fybug + * @version 0.0.1 + * @see Stop#runMeberStop(Runnable, StopFuck) + * @since PDF 1.3 expander 2 + */ +@SuppressWarnings( "all" ) +public +interface StopFuck { + /** + *

处理中断异常.

+ * + * @return 处理后返回的对象 + */ + @NotNull + Object stop(); +} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java deleted file mode 100644 index 980e9ab86bb53f73bf4f05290a1c1303711fa866..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Comparison.java +++ /dev/null @@ -1,68 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; -import com.sun.istack.internal.NotNull; - -import org.jetbrains.annotations.Nullable; -/** - *

比较运算符枚举.

- * - * @author fybug - * @version 0.0.3 - * @since PDF 1.2 - */ -@SuppressWarnings( "All" ) -public -enum Comparison { - /**

等于.

*/ - EQULE(" = "), - /**

大于.

*/ - MORE(" > "), - /**

小于.

*/ - LESS(" < "), - /**

大于等于.

*/ - MORE_AND(" >= "), - /**

小于等于.

*/ - LESS_AND(" <= "), - /**

不等于.

*/ - NO(" <> "), - /**

严格检查.

*/ - STRICT(" <=> "); - @NotNull final private String s; - - Comparison(@NotNull final CharSequence s) {this.s = s.toString();} - - @Override - public - String toString() { return s; } - - /** - *

转化字符串为条件枚举.

- * - * @param ss 要转化的字符串 - * - * @return 转化成的枚举 - */ - @Nullable - public final static - Comparison getMde(@NotNull final CharSequence ss) { - @NotNull final String s = String.valueOf(ss).trim(); - switch ( s ) { - case "=": - return EQULE; - case ">": - return MORE; - case "<": - return LESS; - case ">=": - return MORE_AND; - case "<=": - return LESS_AND; - case "<>": - case "!=": - return NO; - case "<=>": - return STRICT; - default: - return null; - } - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java deleted file mode 100644 index 01c4af536b0c295dbd4aee2ef9adf915441f8461..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/InserMode.java +++ /dev/null @@ -1,31 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; -/** - *

插入模式.

- *

指定了当前数据的插入方式和内容

- * 所有键都需要包装和过滤 - * - * @author fybug - * @version 0.0.1 - * @since PDF 1.3 - */ -@SuppressWarnings( "all" ) -public -enum InserMode { - /** - *

插入 Null 值.

- * 后面不需要值 - */ - NULL, - /**

插入一个值.

*/ - VAL, - /** - *

插入一个值.

- * 不提供包装 - */ - OUT, - /** - *

使用赋值 sql 语句.

- * 不过滤 - */ - SQL; -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java deleted file mode 100644 index 9b10893787b15360606fb55b36c325884cc16a42..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/Logical.java +++ /dev/null @@ -1,51 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; -import com.sun.istack.internal.NotNull; - -import org.jetbrains.annotations.Nullable; -/** - *

逻辑运算符枚举.

- * - * @author fybug - * @version 0.0.3 - * @since PDF 1.2 - */ -@SuppressWarnings( "All" ) -public -enum Logical { - /**

并且.

*/ - AND(" AND "), - /**

或者.

*/ - OR(" OR "), - /**

异或.

*/ - XOR(" XOR "); - @NotNull final private String s; - - Logical(@NotNull final CharSequence s) { this.s = s.toString(); } - - @Override - @NotNull - public - String toString() { return s; } - - /** - *

转化字符串为条件关系枚举.

- * - * @param ss 要转化的字符串 - * - * @return default:{@link #AND} - */ - @Nullable - public static - Logical get(@Nullable final CharSequence ss) { - switch ( String.valueOf(ss).trim().toUpperCase() ) { - case "AND": - return AND; - case "OR": - return OR; - case "XOR": - return XOR; - default: - return AND; - } - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java deleted file mode 100644 index 4cb06c300f441dc424a494005f37a314a3a9b384..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/UpdataMode.java +++ /dev/null @@ -1,73 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; -import org.jetbrains.annotations.NotNull; -/** - *

更新模式.

- *

指定了当前数据的更新方式和内容

- * 所有键都需要包装和过滤 - * - * @author fybug - * @version 0.0.2 - * @since PDF 1.3 - */ -@SuppressWarnings( "all" ) -public -enum UpdataMode { - /** - *

更新为 Null 值.

- * 后面不需要值 - */ - NULL, - /**

更新为一个值.

*/ - VAL, - /** - *

插入一个值.

- * 不提供包装 - */ - OUT, - /** - *

使用赋值 sql 语句.

- * 不过滤 - */ - SQL, - /** - *

更新为自增.

- * 参数为自增的值 - */ - UP("+"), - /** - *

更新为自减.

- * 参数为自减的值 - */ - DOWN("-"), - /** - *

更新为自乘.

- * 参数为自乘的值 - */ - MUL("*"), - /** - *

更新为自除.

- * 参数为自除的值 - */ - EXCE("/"), - /** - *

更新为自取商.

- */ - DIV(" DIV "), - /**

更新为自取模.

*/ - MOD(" MOD "), - /**

按位取或.

*/ - BITOR("|"), - /**

按位取于.

*/ - BITAND("&"), - /**

按位异或.

*/ - BITXOR("^"), - /**

位左移.

*/ - BITLEFT("<<"), - /**

位右移.

*/ - BITRIGHT(">>"); - @NotNull public final String s; - - UpdataMode() { this(""); } - - UpdataMode(@NotNull final String s) { this.s = s; } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java deleted file mode 100644 index dc52388c75386ea5ef51910a4493397507e6546c..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Enum/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - *

sql 标识枚举.

- *

用来代表 SQL 的相关状态标识

- * - * @author fybug - * @version 0.0.2 - * @since PDF 1.2 - */ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Enum; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java deleted file mode 100644 index 11b6420426be5a8dda721dff88d51a22f34e2eb7..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Mysql.java +++ /dev/null @@ -1,195 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql; -import com.sun.istack.internal.NotNull; -import com.sun.istack.internal.Nullable; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import fybug.nulll.bdpost.Instruct; -import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.CObject; -import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.MysqlSql; -import fybug.nulll.pdfunctionlibrary.Processing.sql.mysql.Updata; -/** - *

mysql 数据库工具类.

- *
- * 使用该工具类进行 Sql 操作
- * 该工具会进行字段过滤和包装出 sql
- * 需使用 {@link #getDatabase(String, int, String, String, String)} 构造
- * 
- * - * @author fybug - * @version 0.0.4 - * @see Sql - * @since PDF 1.3 - */ -@SuppressWarnings( "all" ) -@CanSynchronized -public -class Mysql extends Sql { - // mysql 连接名 - @NotNull private static final String URL = "jdbc:mysql://"; - // JDBC 驱动名 - @NotNull private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; - - public - Mysql(@NotNull final Sql.database da) throws SQLException { - super(da); - } - - /** - *

输入要连接的数据库信息.

- *
-     * 需设置数据库所在地址和端口及数据库名
-     * 还有用户名和密码
-     * 
- * - * @param ip 数据库所在地址 - * @param port 端口 - * @param database 数据库名称 - * @param user 用户名 - * @param pass 密码 - * - * @return 获取赋值数据后的数据库对象 - */ - public static - Mysql getDatabase(@NotNull final String ip, final int port, @NotNull final String database, - @NotNull final String user, @NotNull final String pass) throws SQLException - { - try { - //加载驱动程序 - Class.forName(JDBC_DRIVER); - } catch ( Exception e ) { - //数据库驱动类异常处理 - throw new SQLException("Sorry,can`t find the Driver!"); - } - return new Mysql( - new Sql.database(URL + ip + ":" + Integer.toString(port) + "/" + database, user, - pass)); - } - - /** - *

输入要连接的数据库信息.

- *
-     * 需设置数据库所在地址和端口及数据库名
-     * 还有用户名和密码
-     * 
- * - * @param instruct 数据库信息指令

# ip 数据库所在地址
- * # port 端口
- * # base 数据库名称
- * # user 用户名
- * # pass 密码

- * - * @return 获取赋值数据后的数据库对象 - */ - public static - Mysql getDatabase(@NotNull final Instruct instruct) throws SQLException - { - final int port; - @NotNull final String ip, database, user, pass; - - try { - //加载驱动程序 - Class.forName(JDBC_DRIVER); - } catch ( Exception e ) { - //数据库驱动类异常处理 - throw new SQLException("Sorry,can`t find the Driver!"); - } - - port = Integer.parseInt(String.valueOf(instruct.getPostField("port").getField())); - ip = String.valueOf(instruct.getPostField("ip")); - database = String.valueOf(instruct.getPostField("base")); - user = String.valueOf("user"); - pass = String.valueOf("passer"); - - return new Mysql( - new Sql.database(URL + ip + ":" + Integer.toString(port) + "/" + database, user, - pass)); - } - - /** - *

执行 Mysql 语句.

- *
-     * 通过语句对象对查询方式进行包装
-     * 并保证安全和完整性
-     * 
- * - * @param sql 要执行的语句对象 - * - * @return 是否发生异常 - * - * @see MysqlSql - */ - @Nullable - public - boolean exe(@NotNull final MysqlSql sql) { - @NotNull final CObject lock = new CObject(); - try { - // 获取插入语句 - exe(lock, sql.toString()); - return true; - } catch ( Exception e ) { - e.printStackTrace(); - return false; - } finally { - close(lock); - } - } - - /** - *

更新数据库内容.

- *
-     * 通过传入的字段映射和查询条件对数据库中的数据进行更新
-     * 
- * - * @param updata 更新语句对象 - * - * @return 影响的行数 - * - * @see Updata - */ - public - int updata(@NotNull final Updata updata) - { - @NotNull final CObject lock = new CObject(); - try { - return updata(lock, updata.toString()); - } catch ( Exception e ) { - e.printStackTrace(); - throw new RuntimeException(e); - } finally { - close(lock); - } - } - - // 查 - - /** - *

查询数据库数据.

- *
-     * 查询功能使用直接 sql 进行
-     * 
- * - * @param sql 查询的 sql - * - * @return 查询的结果, 如果为 {@code Null} 则查询失败 - */ - @Nullable - public - ResultSet qurey(@NotNull final String sql) - { - @Nullable ResultSet set; - @NotNull final CObject lock = new CObject(); - - try { - // 获取查询数据 - set = get(lock, sql); - } catch ( Exception r ) { - throw new RuntimeException(r); - } finally { - } - - return set; - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java deleted file mode 100644 index df9662fecc23d079753ffb691f08b9d2554fd120..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Sql.java +++ /dev/null @@ -1,245 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.Serializable; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; - -import fybug.nulll.pdfunctionlibrary.Annotations.CanSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.CObject; -/** - *

Sql 底层操作类.

- *
- * 用于执行查询语句
- * 不进行任何处理
- * 
- * - * @author fybug - * @version 0.0.3 - * @see database - * @since PDF 1.2 - */ -@SuppressWarnings( "All" ) -@CanSynchronized -public -class Sql implements AutoCloseable { - @NotNull protected Sql.database database; - @NotNull private HashMap con = new HashMap<>(); - @NotNull private HashMap statement = new HashMap<>(); - - public - Sql(@NotNull final database d) throws SQLException { database = d; } - - @NotNull - @Override - public - Object clone() throws CloneNotSupportedException { - Sql s = (Sql) super.clone(); - s.database = database; - s.con = new HashMap<>(); - s.statement = new HashMap<>(); - return s; - } - - @Override - protected - void finalize() throws Throwable { - super.finalize(); - close(); - } - - /** - *

使用语句查询数据.

- * - * @param cObject 事务标识 - * @param sql 查询语句 - * - * @return 返回的查询集合,如果执行失败则会返回{@code null} - */ - @Nullable - public - ResultSet get(@Nullable final CObject cObject, @NotNull final CharSequence sql) - throws SQLException - { - @Nullable ResultSet rs = null; - @NotNull Connection c = null; - @NotNull Statement s; - - if (!con.containsKey(cObject)) { - // getConnection()方法,连接数据库 - con.put(cObject, - DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); - } - c = con.get(cObject); - - if (!statement.containsKey(cObject)) { - statement.put(cObject, c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_READ_ONLY, - ResultSet.HOLD_CURSORS_OVER_COMMIT)); - } - s = statement.get(cObject); - - //ResultSet类,用来存放获取的结果集!! - rs = s.executeQuery(sql.toString()); - return rs; - } - - /** - *

执行更新语句.

- * - * @param cObject 事务标识 - * @param sql 要执行的更新语句 - * - * @return 受影响的行数 - */ - public - int updata(@Nullable final CObject cObject, @NotNull final CharSequence sql) throws SQLException - { - @Nullable ResultSet rs = null; - @NotNull Connection c = null; - @NotNull Statement s; - - if (!con.containsKey(cObject)) { - // getConnection()方法,连接数据库 - con.put(cObject, - DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); - } - c = con.get(cObject); - - if (!statement.containsKey(cObject)) { - statement.put(cObject, - c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - ResultSet.HOLD_CURSORS_OVER_COMMIT)); - } - s = statement.get(cObject); - - return s.executeUpdate(sql.toString()); - } - - /** - *

执行语句.

- * - * @param cObject 事务标识 - * @param sql 查询语句 - * - * @return 执行是否成功 - */ - public - boolean exe(@Nullable final CObject cObject, @NotNull final CharSequence sql) - throws SQLException - { - @Nullable ResultSet rs = null; - @NotNull Connection c = null; - @NotNull Statement s; - - if (!con.containsKey(cObject)) { - // getConnection()方法,连接数据库 - con.put(cObject, - DriverManager.getConnection(database.DB_URL, database.USER, database.PASS)); - } - c = con.get(cObject); - - if (!statement.containsKey(cObject)) { - statement.put(cObject, - c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, - ResultSet.HOLD_CURSORS_OVER_COMMIT)); - } - s = statement.get(cObject); - - try { - s.execute(sql.toString()); - } catch ( SQLException e ) { - e.printStackTrace(); - return false; - } - return true; - } - - /** - *

关闭对应的连接.

- * - * @param cObject 连接标识 - * - * @since PDF 1.3 - */ - public - void close(@Nullable final CObject cObject) { - @Nullable final Connection c = con.remove(cObject); - if (c != null) - try { - c.commit(); - c.close(); - } catch ( Throwable e ) { - } - - @Nullable final Statement s = statement.remove(cObject); - if (s != null) - try { - s.close(); - } catch ( Throwable e ) { - } - } - - /** - *

关闭所有连接.

- * 并释放事务映射表 - */ - @Override - public - void close() throws SQLException { - synchronized ( this ){ - for ( Connection c : con.values() ){ - try { - c.commit(); - c.close(); - } catch ( Throwable e ) { - } - } - con.clear(); - con = null; - - for ( Statement s : statement.values() ){ - try { - s.close(); - } catch ( Throwable e ) { - } - } - statement.clear(); - statement = null; - } - database = null; - } - - /** - *

数据库信息.

- *
-     * 用于存放数据库相关信息
-     * 
- * - * @author fybug - * @version 0.0.1 - * @since PDF 1.2 - */ - public static - class database implements Serializable { - // 数据库 URL - @NotNull final String DB_URL, // 数据库的用户名与密码,需要根据自己的设置 - USER, PASS; - - public - database(String db, String user, String pass) { - DB_URL = db; - USER = user; - PASS = pass; - } - } - - /* 过滤字段 */ - public final static String ENDMARK = ";", ANDPR = "&", GREATER = "<", LESS = ">", STR = "'", - NAME = "`", ANNOTATION = "--", ROD = "/", PERCENTAGE = "%"; -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java deleted file mode 100644 index 33975c9cb2019531af63ea6ed11aeda229256939..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/InsertVal.java +++ /dev/null @@ -1,275 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.ref.SoftReference; - -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.InserMode; -import fybug.nulll.pdfunctionlibrary.Util.DataMap; -import fybug.nulll.pdfunctionlibrary.Util.Map.ArrayMap; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

插入操作段语句.

- *

用于保存插入的参数和类型,并生成 {@code (??, ??) VALUE (??, ??)} 语句

- * - * @author fybug - * @version 0.0.2 - * @see InserMode - * @since PDF 1.3 - */ -@NoSynchronized -@SuppressWarnings( "All" ) -public -class InsertVal extends ArrayMap> { - /**

插入空类型的指向缓存.

*/ - @NotNull private static SoftReference> nullCache = - new SoftReference<>(DataMap.getDataMap(InserMode.NULL, null)); - - /** - *

获取空类型指向的缓存.

- * 使用软引用 - * - * @return {@link InserMode#NULL} - */ - @NotNull - protected - DataMap getNullCache() { - @Nullable DataMap d = nullCache.get(); - if (d == null) - nullCache = new SoftReference<>(d = DataMap.getDataMap(InserMode.NULL, null)); - return d; - } - - /** - *

加入空插入.

- * - * @param name 要插入的属性名 - * - * @return this - * - * @see InserMode#NULL - */ - @NotNull - public - InsertVal addNull(@NotNull final String name) { - add(fuckSql(name).trim(), getNullCache()); - return this; - } - - /** - *

加入值插入.

- * - * @param name 要插入的属性名 - * @param val 要插入的属性,为空则转化为空插入 - * - * @return this - * - * @see InserMode#VAL - */ - @NotNull - public - InsertVal addVal(@NotNull final String name, @Nullable final String val) { - add(fuckSql(name).trim(), - val == null ? getNullCache() : DataMap.getDataMap(InserMode.VAL, fuckSql(val).trim())); - return this; - } - - /** - *

加入值插入.

- * 插入非字符串的值,不提供包装 - * - * @param name 要插入的属性名 - * @param val 要插入的属性,为空则转化为空插入 - * - * @return this - * - * @see InserMode#OUT - */ - @NotNull - public - InsertVal addOut(@NotNull final String name, @Nullable final Object val) { - add(fuckSql(name).trim(), - val == null ? getNullCache() : DataMap.getDataMap(InserMode.OUT, val)); - return this; - } - - /** - *

加入 sql 插入.

- * - * @param name 要插入的属性名 - * @param sql 要插入的 sql 语句,为空则转化为空插入 - * - * @return this - * - * @see InserMode#SQL - */ - @NotNull - public - InsertVal addSql(@NotNull final String name, @Nullable final String sql) { - add(fuckSql(name).trim(), - sql == null ? getNullCache() : DataMap.getDataMap(InserMode.SQL, sql)); - return this; - } - - // 检查数据并加入 - private - void checkData(@NotNull final StringBuilder key, @NotNull final StringBuilder val, - @NotNull final DataMap> d) - { - @NotNull final String name = d.getKey(); // 键名 - @NotNull DataMap dataMap = d.getValue(); - - // 加入键名 - key.append(name); - - /* 检查输入类型 */ - switch ( dataMap.getKey() ) { - case VAL: - try { - dataMap = ((DataMap) dataMap.clone()).setValue( - "'" + dataMap.getValue() + "'"); - } catch ( CloneNotSupportedException e ) { - } - case OUT: - case SQL: - val.append(dataMap.getValue()); - break; - case NULL: - val.append("null"); - break; - } - } - - /** - *

转化为插入属性的语句.

- * - * @return {@code (??) VALUE (??)} - */ - @NotNull - @Override - public - String toString() { - @NotNull final StringBuilder inst = new StringBuilder("("), val = new StringBuilder( - ") VALUE ("); - - /* tmp */ - @Nullable DataMap> d; - - final int nowmark = mark; // 记录当前标记 - mark = 0; - - /* 取出数据并包装为 Sql */ - for ( boolean b = true; (d = get()) != null; next() ){ - /* 检查是否是第一个 */ - if (!b) { - inst.append(", "); - val.append(", "); - } else { - b = false; - } - - checkData(inst, val, d); - } - - mark = nowmark; - - // 收尾 - inst.ensureCapacity(val.length() + inst.length() + 1); - inst.append(val); - - val.setLength(0); - val.trimToSize(); - - inst.append(")"); - return inst.toString(); - } - - /** - *

解析 BDPos 格式的数据.

- * - * @param post {@link InserMode}&field
- * {@link InserMode}&field - * - * @see #passing(String[], InsertVal) - * @since PDF 1.3 expander 1 - */ - @NotNull - public static - InsertVal passingBDPos(@NotNull final PostField post) { - @NotNull final InsertVal set = new InsertVal(); - @Nullable final Object o = post.getField(); - - /* 多记录 */ - if (post.isMore()) { - for ( int i = 0; i < ((Object[]) o).length; i++ ){ - if (((Object[]) o)[i].getClass().isArray()) { - passing((String[]) ((Object[]) o)[i], set); - } - } - } else - /* 多内容 */ - if (o.getClass().isArray()) { - passing((String[]) o, set); - } - - return set; - } - - // 分发插入消息 - private static - void passing(String[] s, InsertVal insertVal) { - if (s.length == 0) - return; - - InserMode im = InserMode.valueOf(s[0]); - switch ( im ) { - case NULL: - insertVal.addNull(s[1]); - break; - case VAL: - insertVal.addVal(s[1], s[2]); - break; - case OUT: - insertVal.addOut(s[1], s[2]); - break; - case SQL: - insertVal.addSql(s[1], s[2]); - break; - } - } - - /** - *

转化为 BDPos 属性对象.

- * - * @return {@link PostField} - * - * @since PDF 1.3 expander 1 - */ - public - PostField toBDPos() { - PostField postField = new PostField(); - postField.name = "Inserval"; - StringBuilder stringBuilder = new StringBuilder(); - final int nowmark = mark; // 记录当前标记 - mark = 0; - DataMap dos; - - for ( DataMap> d; (d = get()) != null; next() ){ - dos = d.getValue(); - stringBuilder.append(dos.getKey()).append('&').append(d.getKey()).append('&').append( - dos.getValue()).append('\n'); - } - stringBuilder.deleteCharAt(stringBuilder.length() - 1); - - postField.loadField(stringBuilder.toString()); - - mark = nowmark; - - stringBuilder.setLength(0); - stringBuilder.trimToSize(); - return postField; - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java deleted file mode 100644 index 121469a7d06db2baa737193c598c1ccfa3605b25..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/UpDataVal.java +++ /dev/null @@ -1,416 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.ref.SoftReference; - -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.UpdataMode; -import fybug.nulll.pdfunctionlibrary.Util.DataMap; -import fybug.nulll.pdfunctionlibrary.Util.Map.ArrayMap; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

更新操作段语句.

- *

用于保存更新的参数和类型,并生成 {@code ??=??, ??=??} 语句

- * - * @author fybug - * @version 0.0.2 - * @see UpdataMode - * @since PDF 1.3 - */ -@NoSynchronized -@SuppressWarnings( "All" ) -public -class UpDataVal extends ArrayMap> { - /**

插入空类型的指向缓存.

*/ - @NotNull private transient static SoftReference> nullCache = - new SoftReference<>(DataMap.getDataMap(UpdataMode.NULL, null)); - - /** - *

获取空类型指向的缓存.

- * 使用软引用 - * - * @return {@link UpdataMode#NULL} - */ - @NotNull - protected - DataMap getNullCache() { - @Nullable DataMap d = nullCache.get(); - if (d == null) - nullCache = new SoftReference<>(d = DataMap.getDataMap(UpdataMode.NULL, null)); - return d; - } - - /** - *

检查字段类型,并进行过滤.

- * - * @param o 要检查的字段 - * - * @return 检查并进行相应处理的字段 - */ - @NotNull - private - String checkFidle(@Nullable final Object o) { - if (o instanceof String) - return '\'' + fuckSql(o.toString()).trim() + '\''; - - return fuckSql(String.valueOf(o)).trim(); - } - - /** - *

更新为空值.

- * - * @param name 要更新的属性名 - * - * @return this - * - * @see UpdataMode#NULL - */ - @NotNull - public - UpDataVal addNull(@NotNull final String name) { - add(fuckSql(name).trim(), getNullCache()); - return this; - } - - /** - *

加入值更新.

- * - * @param name 要更新的属性名 - * @param val 要更新的属性,为空则转化为空更新 - * - * @return this - * - * @see UpdataMode#VAL - */ - @NotNull - public - UpDataVal addVal(@NotNull final String name, @Nullable final String val) { - add(fuckSql(name).trim(), - val == null ? getNullCache() : DataMap.getDataMap(UpdataMode.VAL, fuckSql(val).trim())); - return this; - } - - /** - *

加入值更新.

- * 插入非字符串的值,不提供包装 - * - * @param name 要更新的属性名 - * @param val 要更新的属性,为空则转化为空更新 - * - * @return this - * - * @see UpdataMode#OUT - */ - @NotNull - public - UpDataVal addOut(@NotNull final String name, @Nullable final Object val) { - add(fuckSql(name).trim(), - val == null ? getNullCache() : DataMap.getDataMap(UpdataMode.OUT, val)); - return this; - } - - /** - * /** - *

加入 sql 更新.

- * - * @param name 要更新的属性名 - * @param sql 要更新的 sql 语句,为空则转化为空更新 - * - * @return this - * - * @see UpdataMode#SQL - */ - @NotNull - public - UpDataVal addSql(@NotNull final String name, @Nullable final String sql) { - add(fuckSql(name).trim(), - sql == null ? getNullCache() : DataMap.getDataMap(UpdataMode.SQL, sql)); - return this; - } - - /** - *

加入自增.

- * - * @param name 要更新的属性名 - * @param val 自增的量 - * - * @return this - * - * @see UpdataMode#UP - */ - @NotNull - public - UpDataVal addUp(@NotNull final String name, final Object val) { - add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.UP, val)); - return this; - } - - /** - *

加入自减.

- * - * @param name 要更新的属性名 - * @param val 自减的量 - * - * @return this - * - * @see UpdataMode#DOWN - */ - @NotNull - public - UpDataVal addDown(@NotNull final String name, final Object val) { - add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.DOWN, val)); - return this; - } - - /** - *

加入自除.

- * - * @param name 要更新的属性名 - * @param val 自除的量 - * - * @return this - * - * @see UpdataMode#EXCE - */ - @NotNull - public - UpDataVal addExce(@NotNull final String name, final Object val) { - add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.EXCE, val)); - return this; - } - - /** - *

加入取值.

- * - * @param name 要更新的属性名 - * @param val 对应的属性 - * @param div 求商还是求模 - * - * @return this - * - * @see UpdataMode#DIV - * @see UpdataMode#MOD - */ - @NotNull - public - UpDataVal addExce(@NotNull final String name, final Object val, final boolean div) { - add(fuckSql(name).trim(), DataMap.getDataMap(div ? UpdataMode.DIV : UpdataMode.MOD, val)); - return this; - } - - /** - *

加入自乘.

- * - * @param name 要更新的属性名 - * @param val 自乘的量 - * - * @return this - * - * @see UpdataMode#MUL - */ - @NotNull - public - UpDataVal addMul(@NotNull final String name, final Object val) { - add(fuckSql(name).trim(), DataMap.getDataMap(UpdataMode.MUL, val)); - return this; - } - - /** - *

加入位运算.

- * - * @param name 要更新的属性名 - * @param bit 运算方式 - * @param val 量 - * - * @return this - * - * @see UpdataMode - */ - @NotNull - public - UpDataVal addBit(@NotNull final String name, @NotNull final UpdataMode bit, final Object val) { - add(fuckSql(name).trim(), DataMap.getDataMap(bit, val)); - return this; - } - - // 检查数据并加入 - private - void checkData(@NotNull final StringBuilder key, - @NotNull final DataMap> d) - { - @NotNull final String name = d.getKey(); // 键名 - @NotNull DataMap dataMap = d.getValue(); - - // 加入键名 - key.ensureCapacity(key.length() + name.length() + 3); - key.append('`').append(name).append('`').append("="); - - /* 检查输入类型 */ - switch ( dataMap.getKey() ) { - case VAL: - case OUT: - try { - dataMap = ((DataMap) dataMap.clone()).setValue( - checkFidle(dataMap.getValue())); - } catch ( CloneNotSupportedException e ) { - } - case SQL: - key.append(dataMap.getValue()); - break; - case NULL: - key.append("null"); - break; - default: - key.append("`" + name + "`").append(dataMap.getKey().s).append( - checkFidle(dataMap.getValue())); - break; - } - } - - /** - *

转化为更新属性的语句.

- * - * @return {@code ??=??, ??=??} - */ - @NotNull - @Override - public - String toString() { - @NotNull final StringBuilder inst = new StringBuilder(); - - /* tmp */ - @Nullable DataMap> d; - - final int nowmark = mark; // 记录当前标记 - - /* 取出数据并包装为 Sql */ - for ( boolean b = true; (d = get()) != null; next() ){ - /* 检查是否是第一个 */ - if (!b) { - inst.append(", "); - } else { - b = false; - } - - checkData(inst, d); - } - - mark = nowmark; - - return inst.toString(); - } - - /** - *

解析 BDPos 格式的数据.

- * - * @param post {@link UpdataMode}&field
- * {@link UpdataMode}&field - * - * @see #passing(String[], WhereSet) - * @since PDF 1.3 expander 1 - */ - @NotNull - public static - UpDataVal passingBDPos(@NotNull final PostField post) { - @NotNull final UpDataVal set = new UpDataVal(); - @Nullable final Object o = post.getField(); - - /* 多记录 */ - if (post.isMore()) { - for ( int i = 0; i < ((Object[]) o).length; i++ ){ - if (((Object[]) o)[i].getClass().isArray()) { - passing((String[]) ((Object[]) o)[i], set); - } - } - } else - /* 多内容 */ - if (o.getClass().isArray()) { - passing((String[]) o, set); - } - - return set; - } - - // 分发指令 - private static - void passing(String[] s, UpDataVal insertVal) { - if (s.length == 0) - return; - - UpdataMode im = UpdataMode.valueOf(s[0]); - switch ( im ) { - case NULL: - insertVal.addNull(s[1]); - break; - case VAL: - insertVal.addVal(s[1], s[2]); - break; - case OUT: - insertVal.addOut(s[1], s[2]); - break; - case SQL: - insertVal.addSql(s[1], s[2]); - break; - case UP: - insertVal.addUp(s[1], s[2]); - break; - case DOWN: - insertVal.addDown(s[1], s[2]); - break; - case EXCE: - insertVal.addExce(s[1], s[2]); - break; - case DIV: - insertVal.addExce(s[1], s[2], true); - break; - case MOD: - insertVal.addExce(s[1], s[2], false); - break; - case MUL: - insertVal.addMul(s[1], s[2]); - break; - case BITOR: - case BITAND: - case BITXOR: - case BITLEFT: - case BITRIGHT: - insertVal.addBit(s[1], im, s[2]); - break; - } - } - - /** - *

转化为 BDPos 属性对象.

- * - * @return {@link PostField} - * - * @since PDF 1.3 expander 1 - */ - public - PostField toBDPos() { - PostField postField = new PostField(); - postField.name = "Updateval"; - StringBuilder stringBuilder = new StringBuilder(); - final int nowmark = mark; // 记录当前标记 - mark = 0; - DataMap dos; - - for ( DataMap> d; (d = get()) != null; next() ){ - dos = d.getValue(); - stringBuilder.append(dos.getKey()).append('&').append(d.getKey()).append('&').append( - dos.getValue()).append('\n'); - } - stringBuilder.deleteCharAt(stringBuilder.length() - 1); - - postField.loadField(stringBuilder.toString()); - - mark = nowmark; - - stringBuilder.setLength(0); - stringBuilder.trimToSize(); - return postField; - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java deleted file mode 100644 index abe02e04e0bdedb90e6fb5e9cae6b1d6a02d2b27..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/WhereSet.java +++ /dev/null @@ -1,914 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; -import com.sun.istack.internal.NotNull; -import com.sun.istack.internal.Nullable; - -import java.io.Serializable; -import java.util.LinkedList; - -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.FuckChar; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Comparison; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Logical; -import fybug.nulll.pdfunctionlibrary.Util.DataMap; -import fybug.nulll.pdfunctionlibrary.lang.Cleanable; -import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

数据库条件集.

- *
- * 存放 sql 查询条件的对象,使用字符串进行缓存
- * 可使用内部指定参数进行添加,将会过滤输入的值
- * 或直接添加 sql 语句,会接在当前语句后面,但不过滤
- * 
- *
插入的语句展示符号说明:
- * ( * ) 代表着使用一个枚举对象作为这里的参数,通常是固定的语句
- * [ * ] 代表着这个语句会根据你输入的参数决定是否出现,通常为取反语句
- * [ * | * ] 代表这这个语句会根据你输入的参数决定使用哪个参数
- * \(\) 代表这个不是上面的括号,和转义符一样
- * \[\] 同上
- * 大写代表 sql 语句
- * 小写代表 变量
- * 
- * - * @author fybug - * @version 0.0.5 - * @see Logical - * @see Comparison - * @since PDF 1.3 - */ -@NoSynchronized -@SuppressWarnings( "All" ) -public -class WhereSet extends ConsistentField implements Cleanable, Serializable, Cloneable { - @NotNull private LinkedList> dataMaps = new LinkedList<>(); - - @Override - protected - boolean consistent(@Nullable final Object obj) - { return obj.toString().equals(toString()); } - - @Override - @NotNull - public - String toString() { - @NotNull final StringBuilder sql = new StringBuilder(); - - getWhere(this, sql); - - sql.trimToSize(); - return sql.toString(); - } - - @Override - protected - void finalize() throws Throwable { - super.finalize(); - dataMaps.clear(); - } - - @NotNull - @Override - public - Object clone() throws CloneNotSupportedException { - @NotNull final WhereSet s = (WhereSet) super.clone(); - - s.dataMaps = (LinkedList>) dataMaps.clone(); - - return s; - } - - /* - * 释放 - */ - - @Override - public - void clean() { dataMaps.clear(); } - - @Override - public - void free() { clean(); } - - @Override - public - void close() { - free(); - dataMaps = null; - } - - /* - * check - */ - - /** - *

检查字段类型,并进行过滤.

- * - * @param o 要检查的字段 - * - * @return 检查并进行相应处理的字段 - */ - @NotNull - static - String checkFidle(@Nullable final Object o) { - if (o instanceof String) - return '\'' + fuckSql(o.toString()).trim() + '\''; - - return fuckSql(String.valueOf(o)).trim(); - } - - // 加入关系 - @NotNull - private - StringBuilder addRelation(@NotNull final Logical logical, @NotNull final StringBuilder set) { - if (set.length() > 0) - set.append(logical); - return set; - } - - /* - * Add - */ - - /** - *

添加等值条件.

- *
-     * 添加条件如下 {@code "( Logical ) key [ ! ]= val"}
-     * 即添加一个检查该键是否等于该值的条件
-     * 
- * - * @param logical 与前面条件的关系 - * @param key 键 - * @param val 要等于的值,如不是字符串类型则不会包装 - * @param negation 是否取反,即使用 != - * - * @return this - */ - @NotNull - public - WhereSet addEqual(@NotNull final Logical logical, @NotNull String key, - @Nullable final Object val, final boolean negation) - { - @NotNull String ss[] = new String[4]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.EQUAL, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = checkFidle(val); - ss[3] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

添加键值逻辑条件.

- *
-     * 添加条件如下 {@code "( Logical ) key ( Comparison ) val"}
-     * 与等值条件不同的是,你可以指定键和值的逻辑运算符
-     * 
- * - * @param logical 与前面条件的关系 - * @param key 键 - * @param how 逻辑运算符 - * @param val 要判断的值,如不是字符串则不会进行包装 - * - * @return this - */ - @NotNull - public - WhereSet addWhere(@NotNull final Logical logical, @NotNull String key, - @NotNull final Comparison how, @NotNull final Object val) - { - @NotNull String ss[] = new String[4]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.WHERE, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = how.toString(); - ss[3] = checkFidle(val); - - dataMaps.add(da); - - return this; - } - - /** - *

添加空检查.

- *
-     * 添加条件如下 {@code "( Logical ) key IS [ NOT ] NULL"}
-     * 
- * - * @param logical 与前面的条件的关系 - * @param key 要检查的键 - * @param negation 取反 - * - * @return this - */ - @NotNull - public - WhereSet addNullCheck(@NotNull final Logical logical, @NotNull String key, - final boolean negation) - { - @NotNull String ss[] = new String[3]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.NULLCHECK, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

添加范围检查.

- *
-     * 添加条件如下 {@code "( Logical ) key [ NOT ] BETWEEN val AND val"}
-     * 
- * - * @param logical 与前面的条件的关系 - * @param key 要检查的键 - * @param num1 开始范围,如不是字符串则不会进行包装 - * @param num2 结束范围,如不是字符串则不会进行包装 - * @param negation 取反 - * - * @return this - */ - @NotNull - public - WhereSet addBetween(@NotNull final Logical logical, @NotNull String key, @NotNull Object num1, - @NotNull Object num2, final boolean negation) - { - @NotNull String ss[] = new String[5]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.BETWEEN, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = checkFidle(num1); - ss[3] = checkFidle(num2); - ss[4] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

加入列举检查.

- *
-     * 添加条件如下 {@code "( Logical ) key [ NOT ] IN (val, val)"}
-     * 
- * - * @param logical 与前面的条件的关系 - * @param key 要检查的键 - * @param negation 是否取反 - * @param val 列举的值,如不是字符串则不会进行包装 - * - * @return this - */ - @NotNull - public - WhereSet addIn(@NotNull final Logical logical, @NotNull String key, final boolean negation, - @NotNull final Object... val) - { - @NotNull final LinkedList ls = new LinkedList<>(); - ls.add(logical.toString()); - ls.add('`' + fuckSql(key).trim() + '`'); - ls.add(Boolean.toString(negation)); - - /* 加入列表组 */ - for ( int i = 0, lenght = val.length; i < lenght; i++ ){ - ls.add(checkFidle(val[i])); - } - - String[] ss = new String[ls.size()]; - ls.toArray(ss); - @NotNull final DataMap dataMap = DataMap.getDataMap(WhereEnum.IN, ss); - - dataMaps.add(dataMap); - - return this; - } - - /** - *

加入模糊查询.

- *
-     * 添加条件如下 {@code "( Logical ) key [ NOT ] LIKE val"}
-     * 
- * - * @param logical 与前面的条件的关系 - * @param key 要检查的键 - * @param val 条件,不支持除字符串以外的类型 - * @param negation 是否取反 - * - * @return this - */ - @NotNull - public - WhereSet addLike(@NotNull final Logical logical, @NotNull String key, @NotNull final String val, - final boolean negation) - { - @NotNull String ss[] = new String[4]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.LIKE, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = val; - ss[3] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

加入正则查询.

- *
-     * 添加条件如下 {@code "( Logical ) [ NOT ( ] key REGEXP val [ ) ]"}
-     * 
- * - * @param logical 与前面的条件的关系 - * @param key 要检查的键 - * @param val 正则,不支持除字符串以外的类型 - * @param negation 是否取反 - * - * @return this - */ - @NotNull - public - WhereSet addRegexp(@NotNull final Logical logical, @NotNull String key, - @NotNull final String val, final boolean negation) - { - @NotNull String ss[] = new String[4]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.REGEXP, ss); - - ss[0] = logical.toString(); - ss[1] = '`' + fuckSql(key).trim() + '`'; - ss[2] = val; - ss[3] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

添加 Sql 语句.

- *
-     * 添加的语句在 Where 后,请不要添加条件语句以外的语句
-     * 
- * - * @param logical 与前面语句的关系 - * @param sql 要添加的 Sql 语句,不支持除字符串以外的类型,并且不进行过滤和包装 - * - * @return this - */ - @NotNull - public - WhereSet addSql(@NotNull final Logical logical, @NotNull final String sql) { - @NotNull String ss[] = new String[2]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.SQL, ss); - - ss[0] = logical.toString(); - ss[1] = sql; - - dataMaps.add(da); - - return this; - } - - /** - *

添加整合条件语句.

- *
-     * 即使用 () 将语句包起来,可提高该串语句的优先度
-     * 添加条件如下 {@code "( Logical ) [ NOT ] \( ( WhereSet ) \)"}
-     * 
- * - * @param logical 与前面语句的关系 - * @param whereSet 要插入的语句,不会进行过滤和包装 - * @param negation 是否取反 - * - * @return this - */ - @NotNull - public - WhereSet addMoreSql(@NotNull final Logical logical, @NotNull final WhereSet whereSet, - final boolean negation) - { - @NotNull String ss[] = new String[3]; - @NotNull DataMap da = DataMap.getDataMap(WhereEnum.MORESQL, ss); - - ss[0] = logical.toString(); - - @Nullable final String s = whereSet.get().trim(); // 语句缓存 - if (s == null) - return this; - ss[1] = s; - - ss[2] = Boolean.toString(negation); - - dataMaps.add(da); - - return this; - } - - /** - *

泛添加.

- *
-     * 根据传入的枚举选择对应的方法
-     * 使用反射执行
-     * 
- * - * @param whereEnum 要添加的条件类型枚举 - * @param os 该方法的参数 - * - * @since PDF 1.3 expander 1 - */ - @NotNull - public - WhereSet exe(@NotNull final WhereEnum whereEnum, @NotNull final Object... os) { - @NotNull String name = ""; - - switch ( whereEnum ) { - case EQUAL: - name = "addEqual"; - // 反射执行 - addEqual((Logical) os[0], (String) os[1], os[2], (boolean) os[3]); - break; - case WHERE: - name = "addWhere"; - addWhere((Logical) os[0], (String) os[1], (Comparison) os[2], os[3]); - break; - case NULLCHECK: - name = "addNullCheck"; - addNullCheck((Logical) os[0], (String) os[1], (boolean) os[2]); - break; - case BETWEEN: - name = "addBetween"; - addBetween((Logical) os[0], (String) os[1], os[2], os[3], (boolean) os[4]); - break; - case IN: - name = "addIn"; - addIn((Logical) os[0], (String) os[1], (boolean) os[2], os[3]); - break; - case LIKE: - name = "addLike"; - addLike((Logical) os[0], (String) os[1], (String) os[2], (boolean) os[3]); - break; - case REGEXP: - name = "addRegexp"; - addRegexp((Logical) os[0], (String) os[1], (String) os[2], (boolean) os[3]); - break; - case SQL: - name = "addSql"; - addSql((Logical) os[0], (String) os[1]); - break; - case MORESQL: - name = "addMoreSql"; - addMoreSql((Logical) os[0], (WhereSet) os[1], (boolean) os[2]); - break; - } - - return this; - } - - /* - * toString - */ - - /** - *

获取语句.

- * - * @return 没参数为 {@code Null} - */ - @Nullable - private - String get() { - if (dataMaps.size() == 0) - return null; - @NotNull final StringBuilder stringBuilder = new StringBuilder(); - - for ( DataMap d : dataMaps ){ - swWhere(d, stringBuilder); - } - - stringBuilder.trimToSize(); - return stringBuilder.toString(); - } - - private - void swWhere(DataMap ds, StringBuilder sql) { - final - class pas { - private - void eq(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[3]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + d[2].length() + 2); - - sql.append(d[1]).append(b ? "!" : "").append("=").append(d[2]); - } - - private - void wh(String[] d, StringBuilder sql) { - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + d[2].length() + d[3].length()); - - sql.append(d[1]).append(d[2]).append(d[3]); - } - - private - void nu(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[2]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + 12); - - sql.append(d[1]).append(" IS ").append(b ? "NOT " : "").append("NULL"); - } - - private - void bw(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[4]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + d[2].length() + d[3].length() + 20); - - sql.append('(').append(d[1]).append(b ? " NOT" : "").append(" BETWEEN ").append( - d[2]).append(" AND ").append(d[3]).append(')'); - } - - private - void in(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[2]); - - addRelation(Logical.get(d[0]), sql).ensureCapacity(sql.length() + d[1].length()); - sql.append(d[1]).append(b ? " NOT" : "").append(" IN ("); - - for ( int i = 3; i < d.length; i++ ){ - if (i != 3) { - sql.ensureCapacity(sql.length() + d[i].length() + 2); - sql.append(", "); - } - sql.append(d[i]); - } - - sql.append(')'); - } - - private - void li(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[3]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + d[2].length() + 10); - - sql.append(d[1]).append(b ? " NOT" : "").append(" LIKE ").append(d[2]); - } - - private - void re(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[3]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + d[2].length() + 12); - - sql.append(d[1]).append(b ? " NOT" : "").append(" REGEXP ").append(d[2]); - } - - private - void sql(String[] d, StringBuilder sql) - { addRelation(Logical.get(d[0]), sql).append(d[1]); } - - private - void more(String[] d, StringBuilder sql) { - boolean b = Boolean.parseBoolean(d[2]); - addRelation(Logical.get(d[0]), sql).ensureCapacity( - sql.length() + d[1].length() + 6); - - sql.append(b ? "NOT " : "").append('(').append(d[1]).append(')'); - } - } - pas pa = new pas(); - /* 分发 */ - switch ( ds.getKey() ) { - case EQUAL: - pa.eq(ds.getValue(), sql); - break; - case WHERE: - pa.wh(ds.getValue(), sql); - break; - case NULLCHECK: - pa.nu(ds.getValue(), sql); - break; - case BETWEEN: - pa.bw(ds.getValue(), sql); - break; - case IN: - pa.in(ds.getValue(), sql); - break; - case LIKE: - pa.li(ds.getValue(), sql); - break; - case REGEXP: - pa.re(ds.getValue(), sql); - break; - case SQL: - pa.sql(ds.getValue(), sql); - break; - case MORESQL: - pa.more(ds.getValue(), sql); - break; - } - } - - /** - *

获取查询条件.

- *
-     * 获取条件集里面的条件并添加到传入的字符缓存区
-     * 
- * - * @param whele 要提取的条件集 - * @param sql 要添加的字符缓冲区 - */ - public static - void getWhere(@NotNull final WhereSet whele, @NotNull final StringBuilder sql) - { - // 条件语句 - @Nullable final String s = whele.get(); - if (s == null) - return; - - sql.ensureCapacity(7 + s.length() + sql.length()); - sql.append(" WHERE ").append(s); - } - - /* - * BDPos - */ - - /** - *

转化为 BDPos 属性对象.

- * - * @return {@link PostField} - * - * @since PDF 1.3 expander 1 - */ - public - PostField toBDPos() { - if (dataMaps.size() == 0) - return null; - @NotNull final PostField postField = new PostField(); - postField.name = "where"; - StringBuilder s = new StringBuilder(); - String[] ss; - - for ( DataMap d : dataMaps ){ - if (d.getKey() == WhereEnum.MORESQL) { - continue; - } - - s.append(d.getKey()).append('&'); - ss = d.getValue(); - - for ( int i = 0, leng = ss.length; i < leng; i++ ){ - if (ss[i].startsWith("'")) { - ss[i] = ss[i].substring(1, ss[i].length() - 1); - } else if (ss[i].startsWith("`")) { - ss[i] = ss[i].substring(1, ss[i].length() - 1); - } - - s.append(ss[i]).append('&'); - } - - s.setCharAt(s.length() - 1, '\n'); - } - - s.deleteCharAt(s.length() - 1); - s.trimToSize(); - - postField.loadField(s.toString()); - - s.setLength(0); - s.trimToSize(); - - return postField; - } - - /** - *

解析 BDPos 格式的数据.

- * - * @param post {@link WhereEnum}&field&field
- * {@link WhereEnum}&field&field - * - * @see #passing(String[], WhereSet) - * @since PDF 1.3 expander 1 - */ - @NotNull - public static - WhereSet passingBDPos(@NotNull final PostField post) { - @NotNull final WhereSet set = new WhereSet(); - @Nullable final Object o = post.getField(); - - /* 多记录 */ - if (post.isMore()) { - for ( int i = 0; i < ((Object[]) o).length; i++ ){ - if (((Object[]) o)[i].getClass().isArray()) { - passing((String[]) ((Object[]) o)[i], set); - } - } - } else - /* 多内容 */ - if (o.getClass().isArray()) { - passing((String[]) o, set); - } - - return set; - } - - /** - *

解析内容.

- *
-     * 将运行解析好的 BDPos 的指令
-     * 添加条件语句段
-     * 
- * - * @see WhereEnum - */ - private static - void passing(String[] s, WhereSet set) { - if (s.length == 0) - return; - - WhereEnum whereEnum = WhereEnum.get(s[0]); - if (whereEnum == null) { - throw new RuntimeException("操作枚举不正确"); - } - - /* 根据类型进行转化 */ - @NotNull Object[] o; - switch ( whereEnum ) { - case EQUAL: { - // 获取属性名 - @NotNull final String key = fuckSql(s[2]); - // 获取内容 - @NotNull final String val = fuckSql(s[3]); - final boolean b = Boolean.parseBoolean(s[4].trim()); - - o = new Object[]{Logical.get(s[1]), key, val, b}; - } - break; - case WHERE: { - // 获取属性名 - @NotNull final String key = fuckSql(s[2]); - - /* 获取逻辑关系符 */ - @Nullable Comparison comparison = Comparison.getMde(s[3].trim()); - if (comparison == null) - comparison = Comparison.EQULE; - - // 获取内容 - @NotNull final String val = fuckSql(s[4]); - - o = new Object[]{Logical.get(s[1]), key, comparison, val}; - } - break; - case NULLCHECK: { - // 获取属性名 - @NotNull final String key = fuckSql(s[2]); - final Boolean b = Boolean.parseBoolean(s[3].trim()); - - o = new Object[]{Logical.get(s[1]), key, b}; - } - break; - case BETWEEN: { - // 获取属性名 - @NotNull final String key = fuckSql(s[2]); - - @NotNull final String ps1 = fuckSql(s[3]), ps2 = fuckSql(s[4]); - final Boolean b = Boolean.parseBoolean(s[5].trim()); - - o = new Object[]{Logical.get(s[1]), key, ps1, ps2, b}; - } - break; - case IN: { - @NotNull final String key = fuckSql(s[2]); // 属性名 - final Boolean b = Boolean.parseBoolean(s[3].trim()); // 是否取反 - - /* 取出变长参数 */ - @NotNull LinkedList stringLinkedList = new LinkedList<>(); - for ( int i = 4; i < s.length; i++ ){ - stringLinkedList.add(fuckSql(s[i])); - } - @NotNull final String[] sa = new String[stringLinkedList.size()]; - stringLinkedList.toArray(sa); - stringLinkedList.clear(); - - o = new Object[]{Logical.get(s[1]), key, b, sa}; - } - break; - case LIKE: { - @NotNull final String key = fuckSql(s[2]); - @NotNull final String like = fuckSql(s[3]); - final Boolean b = Boolean.parseBoolean(s[4].trim()); - - o = new Object[]{Logical.get(s[1]), key, like, b}; - } - break; - case REGEXP: { - @NotNull final String key = fuckSql(s[2]); - @NotNull final String rex = s[3]; - final Boolean b = Boolean.parseBoolean(s[4]); - - o = new Object[]{Logical.get(s[1]), key, rex, b}; - } - break; - case SQL: - o = new Object[]{Logical.get(s[1]), s[2]}; - break; - case MORESQL: - o = new Object[]{Logical.get(s[1]), WhereSet.passingBDPos( - new PostField(FuckChar.refuckBDPos(s[2]))), Boolean.parseBoolean( - s[3].trim())}; - break; - default: - o = null; - } - - set.exe(whereEnum, o); - } - - /** - *

条件添加枚举.

- * - * @author fybug - * @version 0.0.1 - * @since PDF 1.3 expander 1 - */ - public static - enum WhereEnum { - /** @see WhereSet#addEqual(Logical, String, Object, boolean) */ - EQUAL("equal"), - /** @see WhereSet#addWhere(Logical, String, Comparison, Object) */ - WHERE("where"), - /** @see WhereSet#addNullCheck(Logical, String, boolean) */ - NULLCHECK("nullcheck"), - /** @see WhereSet#addBetween(Logical, String, Object, Object, boolean) */ - BETWEEN("between"), - /** @see WhereSet#addIn(Logical, String, boolean, Object...) */ - IN("in"), - /** @see WhereSet#addLike(Logical, String, String, boolean) */ - LIKE("like"), - /** @see WhereSet#addRegexp(Logical, String, String, boolean) */ - REGEXP("regexp"), - /** @see WhereSet#addSql(Logical, String) */ - SQL("sql"), - /** @see WhereSet#addMoreSql(Logical, WhereSet, boolean) */ - MORESQL("moresql"); - @NotNull private final String string; - - private - WhereEnum(@NotNull final String s) { string = s; } - - /** - *

解析操作类型.

- * - * @param s 要解析的字符串 - * - * @return {@link WhereEnum} - */ - @Nullable - public static - WhereEnum get(@NotNull String s) { - s = s.trim().toLowerCase(); - - switch ( s ) { - case "equal": - return EQUAL; - case "where": - return WHERE; - case "nullcheck": - return NULLCHECK; - case "between": - return BETWEEN; - case "in": - return IN; - case "like": - return LIKE; - case "regexp": - return REGEXP; - case "sql": - return SQL; - case "moresql": - return MORESQL; - default: - return null; - } - } - - @Override - @NotNull - public - String toString() { return string; } - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java deleted file mode 100644 index 53680b915859f342b510b519007ffead63d26709..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/Util/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - *

数据库辅助对象包.

- *
提供 Sql 执行辅助对象
- * - * @author fybug - * @version 0.0.2 - * @since PDF 1.2 - */ -package fybug.nulll.pdfunctionlibrary.Processing.sql.Util; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java deleted file mode 100644 index 9dcb90fb8a8d0a2eba29c291d12299b393601903..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Delete.java +++ /dev/null @@ -1,249 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; - -import fybug.nulll.bdpost.Instruct; -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; -import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

删除语句对象.

- *
- * 该对象包含一个完整的 {@code Mysql} 删除语句
- * 需传入所需要的 条件语句 对象
- * 
- * - * @author fybug - * @version 0.0.2 - * @see MysqlSql - * @since PDF 1.3 - */ -@NoSynchronized -@SuppressWarnings( "All" ) -public final -class Delete extends ConsistentField implements MysqlSql { - @Nullable protected ArrayList tabname = new ArrayList<>(); - @Nullable protected WhereSet where = null; - - /**

构造一个空的删除语句对象.

*/ - public - Delete() {} - - /** - *

构造一个删除语句并初始化.

- * - * @param tab 要删除的表 - * @param w 删除的条件 - */ - public - Delete(@NotNull final String tab, @NotNull final WhereSet w) { - setWhere(w); - addTabname(tab); - } - - /** - *

添加要操作的表名.

- * - * @param s 要操作的表 - * - * @return this - */ - @Override - public @NotNull - Delete addTabname(@NotNull String s) { - s = fuckSql(s).trim(); - if (!s.equals("")) - this.tabname.add(s); - else - tabname = null; - return this; - } - - /** - *

获取当前要操作的表的列表.

- * - * @return 要操作的表 - */ - @NotNull - public - Collection getTabname() { return tabname; } - - /** - *

设置操作条件.

- * - * @param where 如果是{@code null} 则会清空条件 - * - * @return this - */ - @NotNull - public - Delete setWhere(@Nullable final WhereSet where) { - if (where == null) - this.where = null; - else - this.where = where; - return this; - } - - /** - *

获取条件对象.

- * - * @return {@link WhereSet} - */ - @Nullable - public - WhereSet getWhere() { return where; } - - @Override - protected - boolean consistent(@NotNull final Object obj) - { return hashCode() == obj.hashCode(); } - - @Override - public - int hashCode() { - return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + - ((where == null ? -1 : where.hashCode()) << 5); - } - - @Override - @NotNull - protected - Object clone() throws CloneNotSupportedException { - @NotNull final Delete d = (Delete) super.clone(); - d.tabname = tabname; - d.where = where == null ? null : (WhereSet) where.clone(); - return d; - } - - @NotNull - @Override - public - String toString() { - if (where == null || tabname == null) - throw new NullPointerException("No Field Sql!"); - - boolean f = true; - @NotNull final StringBuilder sql = new StringBuilder("DELETE FROM "); - tabname.trimToSize(); - - /* 获取插入表组 */ - for ( String key : tabname ){ - if (f) { - sql.ensureCapacity(sql.length() + 2 + key.length()); - f = false; - } else { - sql.ensureCapacity(sql.length() + key.length() + 4); - sql.append(", "); - } - sql.append('`').append(key).append('`'); - } - - WhereSet.getWhere(where, sql); - - sql.trimToSize(); - return sql.toString(); - } - - @Override - public - void clean() { - tabname.clear(); - where = null; - } - - @Override - public - void free() { clean(); } - - @Override - public - void close() { - where.close(); - free(); - tabname = null; - } - - /** - *

解析 BDPos 为删除语句.

- * - * @param post {@code # where:}{@link WhereSet#passingBDPos(PostField)}
- * {@code # table:}table&table - * - * @return {@link Delete} - * - * @since PDF 1.3 expander 1 - */ - @NotNull - public static - Delete passingBDPos(@NotNull final Instruct post) { - @NotNull final Delete delete = new Delete(); - @Nullable PostField field; - - field = post.getPostField("table"); - if (field != null) { - /* 解析表名 */ - @NotNull final String f[]; - if (field.getField().getClass() == String[].class) { - f = (String[]) field.getField(); - } else if (field.getField() instanceof String) { - f = new String[]{field.getField().toString()}; - } else { - f = new String[]{}; - } - - /* 加入表名 */ - for ( int i = 0; i < f.length; i++ ){ - delete.addTabname(f[i]); - } - } - - field = post.getPostField("where"); - if (field != null) { - @NotNull final WhereSet whereSet = WhereSet.passingBDPos(field); - delete.setWhere(whereSet); - } - - return delete; - } - - /** - *

生成 BDPos 对象.

- * - * @return {@link Instruct} - * - * @since PDF 1.3 expander 1 - */ - @NotNull - public - Instruct toBDPos() { - @NotNull final Instruct instruct = new Instruct(); - instruct.name = "delete"; - - // 放入条件 - if (where != null) - instruct.putPostField(where.toBDPos()); - - /* 放入表名 */ - @NotNull final StringBuilder stringBuilder = new StringBuilder(); - @NotNull String ta; // 减少寻址 - for ( int i = 0; i < tabname.size(); i++ ){ - ta = tabname.get(i); - stringBuilder.ensureCapacity(stringBuilder.length() + ta.length() + 1); - stringBuilder.append(ta).append('&'); - } - stringBuilder.deleteCharAt(stringBuilder.length() - 1); - instruct.putPostField(new PostField(stringBuilder.toString())); - - stringBuilder.setLength(0); - stringBuilder.trimToSize(); - - return instruct; - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java deleted file mode 100644 index 7a09467591e677bb351501abd4b392532729aeb5..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Insert.java +++ /dev/null @@ -1,260 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import fybug.nulll.bdpost.Instruct; -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.InsertVal; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; -import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

插入语句对象.

- *
- * 该对象包含一个完整的 {@code Mysql} 插入语句
- * 需传入所需要的 操作段语句 对象
- * 如果传入了 更新操作段 对象则会在 已有插入 的情况下进行更新
- * 
- * - * @author fybug - * @version 0.0.2 - * @see MysqlSql - * @since PDF 1.3 - */ -@NoSynchronized -@SuppressWarnings( "all" ) -public final -class Insert extends ConsistentField implements MysqlSql { - @Nullable protected String tabname = null; - @Nullable protected InsertVal In = null; - @Nullable protected UpDataVal up = null; - - /** - *

构造一个插入语句并初始化.

- * - * @param tabname 要插入的表 - * @param insertVal 插入值的语句 - */ - public - Insert(@NotNull final String tabname, @NotNull final InsertVal insertVal) { - setInserVal(insertVal); - addTabname(tabname); - } - - /**

构造一个空的插入语句对象.

*/ - public - Insert() {} - - /** - *

设置要操作的表名.

- * - * @param s 要操作的表 - * - * @return this - */ - @Override - public @NotNull - Insert addTabname(@NotNull String s) { - tabname = fuckSql(s).trim(); - if (!s.equals("")) - this.tabname = s; - else - tabname = null; - return this; - } - - /** - *

获取当前要操作的表名.

- * - * @return 要操作的表的名称 - */ - @Nullable - public - String getTabname() { return tabname; } - - /** - *

设置插入值语句.

- * - * @param bv 如果是{@code Null} 则会清空语句对象 - * - * @return this - * - * @see InsertVal - */ - @NotNull - public - Insert setInserVal(@Nullable final InsertVal bv) { - In = bv; - return this; - } - - /** - *

获取插入值语句.

- * - * @return {@link InsertVal} - */ - @Nullable - public - InsertVal getInserVal() { return In; } - - /** - *

设置更新语句.

- * - * @param u 如果是{@code Null} 则会清空语句对象 - * - * @return this - * - * @see UpDataVal - */ - @NotNull - public - Insert setUpDataVal(@Nullable final UpDataVal u) { - up = u; - return this; - } - - /** - *

获取更新语句.

- * - * @return {@link UpDataVal} - */ - @Nullable - public - UpDataVal getUpDataVal() { return up; } - - @NotNull - @Override - public - String toString() { - if (In == null || In.size() == 0 || tabname == null) - throw new NullPointerException("No Field Sql!"); - - @NotNull final StringBuilder sql = new StringBuilder("INSERT INTO "); - - /* 插入语句部分 */ - sql.ensureCapacity(sql.length() + 3 + tabname.length()); - sql.append('`').append(tabname).append("`").append(In); - - /* 更新语句部分 */ - if (up != null) { - sql.append(" ON DUPLICATE KEY UPDATE ").append(up); - } - - sql.append(';'); - sql.trimToSize(); - return sql.toString(); - } - - @Override - protected - boolean consistent(@NotNull final Object obj) - { return obj.hashCode() == this.hashCode(); } - - @Override - public - int hashCode() { - return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + - ((In == null ? -1 : In.hashCode()) << 5) + ((up == null ? -1 : up.hashCode()) << 5); - } - - @Override - @NotNull - public - Object clone() throws CloneNotSupportedException { - @NotNull final Insert i = (Insert) super.clone(); - i.tabname = this.tabname; - i.In = In == null ? null : (InsertVal) this.In.clone(); - i.up = up == null ? null : (UpDataVal) up.clone(); - return i; - } - - /* - * 释放 - */ - - @Override - public - void clean() { - tabname = null; - In = null; - up = null; - } - - @Override - public - void free() { clean(); } - - @Override - public - void close() { - In.clean(); - up.clean(); - free(); - } - - /** - *

解析 BDPos 为插入语句.

- * - * @param post {@code # table:}table&table
- * {@code # Inerval:}{@link InsertVal#passingBDPos(PostField)}
- * {@code # Updataval:}{@link UpDataVal#passingBDPos(PostField)} - * - * @return {@link Insert} - */ - @NotNull - public static - Insert passingBDPos(@NotNull final Instruct post) { - @NotNull final Insert insert = new Insert(); - @Nullable PostField field; - - // 加入表名 - field = post.getPostField("table"); - if (field != null) { - /* 解析表名 */ - if (field.getField().getClass() == String[].class) { - if (((String[]) field.getField()).length > 0) - insert.addTabname(((String[]) field.getField())[0]); - } else if (field.getField() instanceof String) { - insert.addTabname((String) field.getField()); - } - } - - field = post.getPostField("Inserval"); - if (field != null) { - insert.setInserVal(InsertVal.passingBDPos(field)); - } - - field = post.getPostField("Updataval"); - if (field != null) { - insert.setUpDataVal(UpDataVal.passingBDPos(field)); - } - - return insert; - } - - /** - *

生成 BDPos 对象.

- * - * @return {@link Instruct} - */ - @NotNull - public - Instruct toBDPos() { - @NotNull final Instruct instruct = new Instruct(); - instruct.name = "insert"; - @NotNull PostField field = new PostField(); - - if (tabname != null) - instruct.putPostField(field.loadField(tabname)); - - if (In != null) - instruct.putPostField(In.toBDPos()); - - if (up != null) - instruct.putPostField(up.toBDPos()); - - return instruct; - } -} \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java deleted file mode 100644 index 14b414b2dcf5e07a646528b6e4022f6b9259240e..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/MysqlSql.java +++ /dev/null @@ -1,40 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; -import org.jetbrains.annotations.NotNull; - -import java.io.Serializable; - -import fybug.nulll.pdfunctionlibrary.Processing.sql.Mysql; -import fybug.nulll.pdfunctionlibrary.lang.Cleanable; -/** - *

Mysql 数据库操作对象.

- *
- * 此接口表示当前对象代表一个完整的 Mysql 操作语句
- * 可通过 {@link #toString()} 打印该语句
- * 
- * - * @author fybug - * @version 0.0.1 - * @see Mysql - * @since PDF 1.3 - */ -@SuppressWarnings( "all" ) -public -interface MysqlSql extends Serializable, Cloneable, Cleanable { - /** - *

打印当前操作的 sql 语句.

- * - * @return 当前操作的 SQL 语句 - */ - @NotNull - String toString(); - - /** - *

添加要操作的表名.

- * - * @param s 要操作的表 - * - * @return this - */ - @NotNull - MysqlSql addTabname(@NotNull final String s); -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java deleted file mode 100644 index 71a1d6ca7b0cdca72f7c70d302e5f573bcbf4800..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/Updata.java +++ /dev/null @@ -1,242 +0,0 @@ -package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import fybug.nulll.bdpost.Instruct; -import fybug.nulll.bdpost.PostField; -import fybug.nulll.pdfunctionlibrary.Annotations.NoSynchronized; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; -import fybug.nulll.pdfunctionlibrary.lang.ConsistentField; - -import static fybug.nulll.pdfunctionlibrary.Processing.FuckChar.fuckSql; -/** - *

更新语句对象.

- *
- * 该对象包含一个完整的 {@code Mysql} 更新语句
- * 需传入所需要的 条件语句 对象
- * 以及需要的 更新语句段 对象
- * 
- * - * @author fybug - * @version 0.0.2 - * @see MysqlSql - * @since PDF 1.3 - */ -@SuppressWarnings( "all" ) -@NoSynchronized -public final -class Updata extends ConsistentField implements MysqlSql { - @Nullable protected String tabname = null; - @Nullable protected WhereSet where = null; - @Nullable protected UpDataVal up = null; - - /** - *

添加要操作的表名.

- * - * @param s 要操作的表 - * - * @return this - */ - @Override - public @NotNull - Updata addTabname(@NotNull final String s) { - tabname = fuckSql(s).trim(); - if (!s.equals("")) - this.tabname = s; - else - tabname = null; - return this; - } - - /** - *

获取当前要操作的表名.

- * - * @return 要操作的表 - */ - @Nullable - public - String getTabname() { return tabname; } - - /** - *

设置操作条件.

- * - * @param where 如果是{@code null} 则会清空条件 - * - * @return this - */ - @NotNull - public - Updata setWhere(@Nullable final WhereSet where) { - if (where == null) - this.where = null; - else - this.where = where; - return this; - } - - /** - *

获取条件对象.

- * - * @return {@link WhereSet} - */ - @Nullable - public - WhereSet getWhere() { return where; } - - /** - *

设置更新语句段.

- * - * @param updata 如果为{@code null} 则会清空对应的语句段 - * - * @return this - * - * @see UpDataVal - */ - @NotNull - public - Updata setUpdata(@Nullable final UpDataVal updata) { - if (updata == null) - up = null; - else - up = updata; - return this; - } - - /** - *

获取更新语句段.

- * - * @return {@link UpDataVal} - */ - @Nullable - public - UpDataVal getUpData() { return up; } - - @Override - protected - boolean consistent(@NotNull final Object obj) - { return hashCode() == obj.hashCode(); } - - @Override - public - int hashCode() { - return ((super.hashCode() + (tabname == null ? -1 : tabname.hashCode())) << 5) + - ((where == null ? -1 : where.hashCode()) << 5) + - ((up == null ? -1 : up.hashCode()) << 5); - } - - @Override - @NotNull - protected - Object clone() throws CloneNotSupportedException { - @NotNull final Updata d = (Updata) super.clone(); - d.tabname = tabname; - d.where = where == null ? null : (WhereSet) where.clone(); - d.up = up == null ? null : (UpDataVal) up.clone(); - return d; - } - - @NotNull - @Override - public - String toString() { - if (up == null || up.size() == 0 || tabname == null) - throw new NullPointerException("No Field Sql!"); - - @NotNull final StringBuilder sql = new StringBuilder("UPDATE "); - @NotNull final String fs = up.toString(); - - // 过滤表名 - sql.ensureCapacity(sql.length() + tabname.length() + 6 + fs.length()); - sql.append('`').append(tabname).append('`').append(" SET ").append(fs); - - // 获取条件 - WhereSet.getWhere(where, sql); - - sql.trimToSize(); - return sql.toString(); - } - - @Override - public - void clean() { - up = null; - tabname = null; - where = null; - } - - @Override - public - void free() { clean(); } - - @Override - public - void close() { - up.close(); - where.close(); - free(); - } - - /** - *

解析 BDPos 为更新语句.

- * - * @param post {@code # table:}table&table
- * {@code # Updataval:}{@link UpDataVal#passingBDPos(PostField)}
- * {@code # where:}{@link WhereSet#passingBDPos(PostField)} - * - * @return {@link Insert} - */ - @NotNull - public static - Updata passingBDPos(@NotNull final Instruct post) { - @NotNull final Updata upDataVal = new Updata(); - @Nullable PostField field; - - // 加入表名 - field = post.getPostField("table"); - if (field != null) { - /* 解析表名 */ - if (field.getField().getClass() == String[].class) { - if (((String[]) field.getField()).length > 0) - upDataVal.addTabname(((String[]) field.getField())[0]); - } else if (field.getField() instanceof String) { - upDataVal.addTabname((String) field.getField()); - } - } - - field = post.getPostField("Updataval"); - if (field != null) { - upDataVal.setUpdata(UpDataVal.passingBDPos(field)); - } - - field = post.getPostField("where"); - if (field != null) - upDataVal.setWhere(WhereSet.passingBDPos(field)); - - return upDataVal; - } - - /** - *

生成 BDPos 对象.

- * - * @return {@link Instruct} - */ - @NotNull - public - Instruct toBDPos() { - @NotNull final Instruct instruct = new Instruct(); - instruct.name = "updata"; - @NotNull PostField field = new PostField(); - - if (tabname != null) - instruct.putPostField(field.loadField(tabname)); - - if (where != null) - instruct.putPostField(where.toBDPos()); - - if (up != null) - instruct.putPostField(up.toBDPos()); - - return instruct; - } -} diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java deleted file mode 100644 index 2b7bc9bdff628b40a85323d95c34b49337ec63bc..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/mysql/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - *

MySQL 相关包.

- * - * @author fybug - * @version 0.0.1 - * @since PDF 1.3 - */ -package fybug.nulll.pdfunctionlibrary.Processing.sql.mysql; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/package-info.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/package-info.java deleted file mode 100644 index aa05653fa2eef98f6ff807e180881576c78fdccb..0000000000000000000000000000000000000000 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Processing/sql/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - *

数据库工具包.

- *
提供基础 Sql 执行工具和其他数据库工具
- * - * @author fybug - * @version 0.0.1 - * @since PDF 1.2 - */ -package fybug.nulll.pdfunctionlibrary.Processing.sql; \ No newline at end of file diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java index 46752bbc54e3b8b022b74ec32a053d8bf5cd8a65..a4dc3477f864b7e9b4b19d5fa137e8579a10e67c 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/ArrayMap.java @@ -1,6 +1,6 @@ package fybug.nulll.pdfunctionlibrary.Util.Map; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; import java.util.ArrayList; @@ -10,7 +10,7 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap; *

使用了数组实现的映射集.

* * @author fybug - * @version 0.0.2 + * @version 0.0.3 * @see ArrayList * @see DataMap * @see MapFile @@ -74,6 +74,14 @@ class ArrayMap extends ArrayList> implements MapFile { return this; } + @NotNull + @Override + public + MapFile restart() { + mark = 0; + return this; + } + @Override public boolean isEmpty() { return size() == 0; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java index 149e3b942760d4c87fe55bd9bb452485451be696..3e5ab4f2f57cda401b1b7890fd894098d008f22b 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/LinkMap.java @@ -1,6 +1,6 @@ package fybug.nulll.pdfunctionlibrary.Util.Map; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; import java.util.LinkedList; @@ -10,7 +10,7 @@ import fybug.nulll.pdfunctionlibrary.Util.DataMap; *

使用了链表实现的映射集.

* * @author fybug - * @version 0.0.2 + * @version 0.0.3 * @see LinkedList * @see DataMap * @see MapFile @@ -75,6 +75,14 @@ class LinkMap extends LinkedList> implements MapFile { return this; } + @Override + @NotNull + public + MapFile restart() { + mark = 0; + return this; + } + @Override public boolean isEmpty() { return size() == 0; } diff --git a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java index b4459b2af5717f0727b670907f3560d23315ba8e..59dcb7f930fb115fa82b78e40c2ebef4fa78591f 100644 --- a/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java +++ b/src/main/java/fybug/nulll/pdfunctionlibrary/Util/Map/MapFile.java @@ -1,6 +1,6 @@ package fybug.nulll.pdfunctionlibrary.Util.Map; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.sun.istack.internal.NotNull; +import com.sun.istack.internal.Nullable; import java.util.Iterator; @@ -20,7 +20,7 @@ import fybug.nulll.pdfunctionlibrary.lang.CanEmpty; * @param 值类型 * * @author fybug - * @version 0.0.2 + * @version 0.0.3 * @see CanEmpty * @see Iterator * @see DataMap @@ -87,6 +87,16 @@ interface MapFile extends CanEmpty { @NotNull MapFile next(); + /** + *

重置指针.

+ * + * @return this + * + * @since PDF 1.3 expander 2 + */ + @NotNull + MapFile restart(); + /**

创建一个使用数组的映射集.

*/ @NotNull static diff --git a/src/main/java/org/jetbrains/annotations/NotNull.java b/src/main/java/org/jetbrains/annotations/NotNull.java deleted file mode 100644 index 81d5f86cb64d8e31505735dc58a4695ad020e7fd..0000000000000000000000000000000000000000 --- a/src/main/java/org/jetbrains/annotations/NotNull.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.annotations; - -import java.lang.annotation.*; - -/** - * An element annotated with NotNull claims {@code null} value is forbidden - * to return (for methods), pass to (parameters) and hold (local variables and fields). - * Apart from documentation purposes this annotation is intended to be used by static analysis tools - * to validate against probable runtime errors and element contract violations. - * - * @author max - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) -public @interface NotNull { - /** - * @return Custom exception message - */ - String value() default ""; - - /** - * @return Custom exception type that should be thrown when not-nullity contract is violated. - * The exception class should have a constructor with one String argument (message). - * - * By default, {@link IllegalArgumentException} is thrown on null method arguments and - * {@link IllegalStateException} — on null return value. - */ - Class exception() default Exception.class; -} diff --git a/src/main/java/org/jetbrains/annotations/Nullable.java b/src/main/java/org/jetbrains/annotations/Nullable.java deleted file mode 100644 index 39e3123061d247fc8085f7966f61f21007c87e37..0000000000000000000000000000000000000000 --- a/src/main/java/org/jetbrains/annotations/Nullable.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.annotations; - -import java.lang.annotation.*; - -/** - * An element annotated with {@link Nullable} claims {@code null} value is perfectly valid - * to return (for methods), pass to (parameters) or hold in (local variables and fields). - * Apart from documentation purposes this annotation is intended to be used by static analysis tools - * to validate against probable runtime errors or element contract violations. - *
- * By convention, this annotation applied only when the value should always be checked against {@code null} - * because the developer could do nothing to prevent null from happening. - * Otherwise, too eager {@link Nullable} usage could lead to too many false positives from static analysis tools. - *
- * For example, {@link java.util.Map#get(Object key)} should not be annotated {@link Nullable} because - * someone may have put not-null value in the map by this key and is expecting to find this value there ever since. - *
- * On the other hand, the {@link java.lang.ref.Reference#get()} should be annotated {@link Nullable} because - * it returns {@code null} if object got collected which can happen at any time completely unexpectedly. - * - * @author max - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE}) -public @interface Nullable { - String value() default ""; -} diff --git a/src/test/java/TestBDPost.java b/src/test/java/TestBDPost.java deleted file mode 100644 index f6afa27edb26b180913e314756708ca20b1a9ed1..0000000000000000000000000000000000000000 --- a/src/test/java/TestBDPost.java +++ /dev/null @@ -1,89 +0,0 @@ -import org.junit.Before; -import org.junit.Test; - -import fybug.nulll.bdpost.BDPos; - -public -class TestBDPost { - String da; - - @Before - public - void init() { - StringBuilder stringBuilder = new StringBuilder(" ### c1:"); - { - stringBuilder.append(" ## I1:"); - { - stringBuilder.append(" # f1:"); - { - stringBuilder.append("as"); - } - stringBuilder.append(" # f2:"); - { - stringBuilder.append("a1").append("&"); - stringBuilder.append("a2").append("&"); - stringBuilder.append("a3"); - } - } - stringBuilder.append(" ## I2:"); - { - stringBuilder.append(" # f1:"); - { - stringBuilder.append("sw"); - stringBuilder.append("ewq"); - } - { - stringBuilder.append("ewq").append("&"); - stringBuilder.append("tret"); - } - } - } - stringBuilder.append(" ### :"); - { - stringBuilder.append(" ## I1:"); - { - stringBuilder.append(" # f1:"); - { - stringBuilder.append("as"); - } - stringBuilder.append(" # f2:"); - { - stringBuilder.append("a1").append("&"); - stringBuilder.append("a2").append("&"); - stringBuilder.append("a3"); - } - } - stringBuilder.append(" ## I2:"); - { - stringBuilder.append(" # f1:"); - { - stringBuilder.append("sw"); - stringBuilder.append("ewq"); - } - { - stringBuilder.append("ewq").append("&"); - stringBuilder.append("tret"); - } - } - } - - stringBuilder.trimToSize(); - da = stringBuilder.toString(); - } - - @Test - public - void TestBDPos() { - BDPos pos = new BDPos(da); - System.out.println(pos.toString()); - } - - @Test - public - void TestDBPost() { - BDPos pos = new BDPos(da); - System.out.println(pos.getClass("").name); - System.out.println(pos.getClass("").getInstruct("I1").name); - System.out.println(pos.getClass("").getInstruct("I1").getPostField("f1").getField()); - } -} \ No newline at end of file diff --git a/src/test/java/TestMysql.java b/src/test/java/TestMysql.java deleted file mode 100644 index 32c53214d7f5b7e183acc94d70cc5d54506aa370..0000000000000000000000000000000000000000 --- a/src/test/java/TestMysql.java +++ /dev/null @@ -1,60 +0,0 @@ -import org.junit.Before; -import org.junit.Test; - -import java.sql.SQLException; - -import fybug.nulll.pdfunctionlibrary.Processing.sql.Enum.Logical; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Mysql; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.InsertVal; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.UpDataVal; -import fybug.nulll.pdfunctionlibrary.Processing.sql.Util.WhereSet; -public -class TestMysql { - Mysql mysql; - - @Before - public - void init() { - try { - mysql.close(); - } catch ( Throwable ignored ) { - } - try { - mysql = Mysql.getDatabase("127.0.0.1", 3306, "pageviews", "root", "2650693483"); - } catch ( SQLException e ) { - e.printStackTrace(); - } - } - - @Test - public - void TestWhere() { - WhereSet whereSet = new WhereSet(); - - whereSet.addRegexp(Logical.AND, "asd", "lakjad", false); - whereSet.addRegexp(Logical.AND, "asd", "lakjad", true); - whereSet = WhereSet.passingBDPos(whereSet.toBDPos()); - - System.out.println(whereSet.toString()); - } - - @Test - public - void TestInserModer() { - InsertVal insertVal = new InsertVal(); - - insertVal.addVal("asd", "kor").addNull("s"); - System.out.println(insertVal); - System.out.println(insertVal.toBDPos()); - } - - @Test - public - void TestUpdateModer() { - UpDataVal insertVal = new UpDataVal(); - - insertVal.addVal("asd", "kor").addNull("s"); - System.out.println(insertVal); - System.out.println(insertVal.toBDPos()); - } -} diff --git a/src/test/java/bdpos/testField.java b/src/test/java/bdpos/testField.java new file mode 100644 index 0000000000000000000000000000000000000000..4aedde231e2efddc21feab4f69e42b7dc21eb0c5 --- /dev/null +++ b/src/test/java/bdpos/testField.java @@ -0,0 +1,48 @@ +package bdpos; +import org.junit.Test; + +import fybug.nulll.bdpost.PostField; +public final +class testField { + @Test + public + void test1() { + PostField field = new PostField(); + field.name = "i"; + field.loadField("a&s&g\nz&v&l"); + show(field); + } + + @Test + public + void test2() { + PostField field = new PostField(); + field.name = "i"; + field.loadArray(new Object[]{new String[]{"a", "2", "g"}, new String[]{"z", "c", "h"}}); + show(field); + } + + private static + void show(PostField s) { + System.out.println(s.toString()); + System.out.println("\n-------------------\n"); + + Object[] os; + String[] ss; + + if (s.isMore()) { + os = (Object[]) s.getField(); + } else { + os = new Object[]{s.getField()}; + } + + for ( Object o : os ){ + ss = (String[]) o; + for ( String s1 : ss ){ + System.out.print(" - "); + System.out.print(s1); + } + System.out.print("\n"); + } + } +} \ No newline at end of file diff --git a/src/test/java/bdpos/testInst.java b/src/test/java/bdpos/testInst.java new file mode 100644 index 0000000000000000000000000000000000000000..f1b2d1c0c916c35e2ee48573e5749b77b56a83d3 --- /dev/null +++ b/src/test/java/bdpos/testInst.java @@ -0,0 +1,35 @@ +package bdpos; +import org.junit.Test; + +import fybug.nulll.bdpost.Instruct; +import fybug.nulll.bdpost.PostField; +public final +class testInst { + @Test + public + void test1() { + Instruct instruct = new Instruct(); + instruct.name = "asdas"; + instruct = instruct.loading(" # asd:fafd&dfg&dsf # asdiou:iodfg"); + show(instruct); + } + + @Test + public + void test2() { + Instruct instruct = new Instruct(); + instruct.name = "asdas"; + instruct = instruct.loadingArray(new PostField[]{new PostField("asdfij")}); + show(instruct); + } + + private static + void show(Instruct is) { + System.out.println(is.toString()); + System.out.println("\n---------------------\n"); + String[] s = is.listName(); + for ( String value : s ){ + System.out.println(is.getPostField(value)); + } + } +} \ No newline at end of file diff --git a/src/test/java/bdpos/testclass.java b/src/test/java/bdpos/testclass.java new file mode 100644 index 0000000000000000000000000000000000000000..9cbc3a62b90c964da463cd4e42cd31291b7dcf44 --- /dev/null +++ b/src/test/java/bdpos/testclass.java @@ -0,0 +1,15 @@ +package bdpos; +import org.junit.Test; + +import fybug.nulll.bdpost.PosClass; +public final +class testclass { + @Test + public + void test1() { + PosClass posClass = new PosClass(); + posClass.name = "asd"; + posClass.loadClass(" ## in: # dioadf:gjldf&asji"); + System.out.println(posClass); + } +} \ No newline at end of file diff --git a/src/test/java/test/lang/TestCloall.java b/src/test/java/test/lang/TestCloall.java new file mode 100644 index 0000000000000000000000000000000000000000..4aa046c05eb3becd9f8acbe2b4959f66748d9a02 --- /dev/null +++ b/src/test/java/test/lang/TestCloall.java @@ -0,0 +1,34 @@ +package test.lang; +import org.junit.Test; + +import java.io.Closeable; + +import fybug.nulll.pdfunctionlibrary.lang.CloseAll; +public final +class TestCloall { + @Test + public + void test() { + Closeable[] cs = {new cl(), new cl(), new cl(), new cl()}; + for ( int i = 0; i < cs.length; i++ ){ + System.out.println(((cl) cs[i]).s); + } + System.out.println("-------------"); + CloseAll ca = CloseAll.getCloseAll(cs); + ca.close(); + for ( int i = 0; i < cs.length; i++ ){ + System.out.println(((cl) cs[i]).s); + } + } + + private static final + class cl implements Closeable { + private String s = "not close"; + + @Override + public + void close() { + s = "is close!"; + } + } +} \ No newline at end of file diff --git a/src/test/java/test/processing/selectsort.java b/src/test/java/test/processing/selectsort.java new file mode 100644 index 0000000000000000000000000000000000000000..cacf7e98ecb3074e0b3e3d47d9363ef5d724dd53 --- /dev/null +++ b/src/test/java/test/processing/selectsort.java @@ -0,0 +1,45 @@ +package test.processing; +import org.junit.Test; + +import fybug.nulll.pdfunctionlibrary.Processing.Sort.SelectionSort; +import fybug.nulll.pdfunctionlibrary.Processing.Sort.SortMode; +public final +class selectsort { + @Test + public + void testint() { + int[] is = {1, 2, 564, 1231, 5640, 0, 54, 54, 10, 540, 654868, 54, 0, 51}; + + is = SelectionSort.sortInt(is, SortMode.Mode.UP); + for ( int i = 0; i < is.length; i++ ){ + System.out.println(is[i]); + } + + System.out.println("\n------------------\n"); + + is = SelectionSort.sortInt(is, SortMode.Mode.DOWN); + for ( int i = 0; i < is.length; i++ ){ + System.out.println(is[i]); + } + } + + @Test + public + void testchar() { + String[] is = + {"a", "b", "564", "ab3a", "5640", "0", "54", "54", "a0", "540", "654868", "54", "0", + "5a"}; + + is = SelectionSort.sortString(is, SortMode.Mode.UP); + for ( int i = 0; i < is.length; i++ ){ + System.out.println(is[i]); + } + + System.out.println("\n------------------\n"); + + is = SelectionSort.sortString(is, SortMode.Mode.DOWN); + for ( int i = 0; i < is.length; i++ ){ + System.out.println(is[i]); + } + } +} diff --git a/src/test/java/test/util/TestMapfile.java b/src/test/java/test/util/TestMapfile.java new file mode 100644 index 0000000000000000000000000000000000000000..7e502da2706b4d0faf9eec041bbfceae81bad993 --- /dev/null +++ b/src/test/java/test/util/TestMapfile.java @@ -0,0 +1,68 @@ +package test.util; +import org.junit.Test; + +import fybug.nulll.pdfunctionlibrary.Util.DataMap; +import fybug.nulll.pdfunctionlibrary.Util.Map.MapFile; +public final +class TestMapfile { + private static MapFile mf; + + @Test + public + void testLink() { + mf = (MapFile) MapFile.userLink(); + add(mf); + mf.clear(); + show(mf); + System.out.println("\n---------------------------\n"); + add(mf); + show(mf); + System.out.println("\n---------------------------\n"); + DataMap sa; + while( (sa = mf.poll()) != null ){ + System.out.println(sa.getKey() + " : " + sa.getValue()); + } + System.out.println("\n---------------------------\n"); + mf.restart(); + show(mf); + } + + @Test + public + void testArr() { + mf = (MapFile) MapFile.userArray(); + add(mf); + mf.clear(); + show(mf); + System.out.println("\n---------------------------\n"); + add(mf); + show(mf); + System.out.println("\n---------------------------\n"); + DataMap sa; + while( (sa = mf.poll()) != null ){ + System.out.println(sa.getKey() + " : " + sa.getValue()); + } + System.out.println("\n---------------------------\n"); + mf.restart(); + show(mf); + } + + private static + void add(MapFile s) { + s.add("1", "as"); + s.add("2", "asasd"); + s.add("3", "a2s"); + s.add("4", "a"); + s.add("5", "aghs"); + s.add("1", "as"); + } + + private + void show(MapFile s) { + DataMap sa; + while( (sa = s.get()) != null ){ + System.out.println(sa.getKey() + " : " + sa.getValue()); + s.next(); + } + } +} \ No newline at end of file