Skip to content

Commit d079860

Browse files
authored
Merge pull request #23 from ClearXs/1.1.x
1.1.x
2 parents 7e1c318 + c413a83 commit d079860

File tree

11 files changed

+315
-19
lines changed

11 files changed

+315
-19
lines changed

mkdocs.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
site_name: uno文档
2+
repo_name: uno
3+
repo_url: https://github.com/ClearXs/uno
4+
site_author: J.x (jiangw1027@gmail.com)
5+
copyright: Copyright © 2023 - 2024 ClearX
6+
7+
nav:
8+
- README.md
9+
- core: core.md
10+
- data: data.md
11+
- rule: rule.md
12+
- web: web.md
13+
- test: test.md
14+
- gis: gis.md
15+
- auto: auto.md
16+
- bom: bom.md
17+
- plugins: plugins.md
18+
- components:
19+
- http: components/http.md
20+
- kafka: components/kafka.md
21+
- media: components/media.md
22+
- netty: components/netty.md
23+
- sequential: components/sequential.md
24+
- websocket: components/websocket.md
25+
- starter: starter.md
26+
27+
theme:
28+
# https://squidfunk.github.io/mkdocs-material/creating-your-site/#configuration
29+
name: material
30+
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/
31+
palette:
32+
- scheme: default
33+
toggle:
34+
icon: material/brightness-7
35+
primary: indigo
36+
accent: light blue
37+
- scheme: slate
38+
toggle:
39+
icon: material/brightness-4
40+
primary: indigo
41+
accent: grey
42+
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-fonts/
43+
font:
44+
text: Nunito Sans
45+
code: Roboto Mono
46+
logo: favicon.png
47+
favicon: favicon.png
48+
features:
49+
# Navigation
50+
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/
51+
- navigation.instant # some features may not work properly with XHR
52+
- navigation.tracking # the URL changes with the active anchor
53+
- navigation.instant.prefetch
54+
- navigation.tabs # first top-level folders are shown as tabs
55+
- navigation.tabs.sticky # tabs always show
56+
- navigation.prune
57+
- navigation.sections # second-level folders are expanded
58+
- navigation.expand # all folders are expanded
59+
- navigation.indexes # link an index page to its parent folder
60+
- navigation.top # show the back-to-top button
61+
- toc.integrate # show the table of contents in the navigation panel
62+
# Search
63+
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search
64+
- search.suggest # display the likeliest completion for the last word
65+
- search.highlight # highlight all occurrences
66+
- search.share # show a share button of the current search
67+
# Header
68+
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-the-header/
69+
- header.autohide # hide the post title when scroll down
70+
# Content
71+
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
72+
- content.code.annotate # add comment to code blocks
73+
- content.tabs.link # link tabs with the same label
74+
- content.tooltips
75+
76+
#
77+
# Plugins
78+
#
79+
plugins:
80+
- tags
81+
- search: # must be included at the first place
82+
lang:
83+
- en
84+
- zh
85+
separator: '[\s\u200b\-]'
86+
- offline
87+
#
88+
# Extensions
89+
#
90+
markdown_extensions:
91+
- abbr # add a small tooltip to elements
92+
- admonition # add call-out blocks
93+
- attr_list # allow to add HTML attributes and CSS classes
94+
- def_list # add description lists
95+
- footnotes # define inline footnotes
96+
- meta # attach arbitrary key-value pairs to a document
97+
- md_in_html # allow to write Markdown inside HTML elements
98+
- tables # create tables in Markdown
99+
- toc: # generate a table of contents from documents
100+
permalink: '#' # anchor
101+
toc_depth: 4 # header 1 to header 4
102+
slugify: !!python/name:pymdownx.slugs.uslugify # convert title to html-compatible text
103+
- sane_lists # make better lists
104+
- smarty: # convert some special characters
105+
smart_angled_quotes: true
106+
- pymdownx.highlight:
107+
anchor_linenums: true
108+
# - pymdownx.betterem: # improve the detection of Markup to emphasize text in Markdown
109+
# smart_enable: all
110+
- pymdownx.caret # define superscript
111+
- pymdownx.mark # highlight text
112+
- pymdownx.tilde # define subscript
113+
- pymdownx.critic # track changes
114+
- pymdownx.details # add collapsible call-outs
115+
- pymdownx.emoji: # add inlines bundled and custom icons and emojis
116+
emoji_index: !!python/name:materialx.emoji.twemoji
117+
emoji_generator: !!python/name:materialx.emoji.to_svg
118+
- pymdownx.superfences # define code blocks and nesting of code
119+
- pymdownx.highlight: # highlight of code blocks
120+
linenums_style: pymdownx-inline
121+
# anchor_linenums: true # create anchor link on each line of code
122+
- pymdownx.inlinehilite # highlight inline code blocks
123+
- pymdownx.smartsymbols # convert some sequences of characters into their corresponding symbols
124+
- pymdownx.snippets: # embed content from arbitrary files into a document
125+
check_paths: true
126+
- pymdownx.tabbed: # group related content and code blocks under accessible tabs
127+
alternate_style: true
128+
- pymdownx.tasklist: # define list of task with checkbox
129+
custom_checkbox: true
130+
- pymdownx.escapeall:
131+
hardbreak: true # use \ to create new line
132+
nbsp: true # use \<space> to create &nbsp;
133+
# - pymdownx.keys # syntax ++ctrl+c++ does not look clear in MD document
134+
- pymdownx.progressbar
135+
extra:
136+
version:
137+
provider: mike
138+
disqus: "vuquangtrong-github-io"

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "turbo-docs",
3+
"version": "1.0.0",
4+
"description": "turbo documentation",
5+
"private": true,
6+
"scripts": {
7+
"dev": "mkdocs serve",
8+
"build": "mkdocs build -d public"
9+
}
10+
}

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mkdocs
2+
mkdocs-material
3+
mkdocs-roamlinks-plugin

uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TreeSupport.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package cc.allio.uno.core.datastructure.tree;
22

3+
import cc.allio.uno.core.bean.BeanWrapper;
4+
import cc.allio.uno.core.function.lambda.MethodFunction;
35
import cc.allio.uno.core.util.CollectionUtils;
46
import com.google.common.collect.Lists;
57

68
import java.io.Serializable;
79
import java.util.*;
810
import java.util.function.Function;
911
import java.util.stream.Collectors;
12+
import java.util.stream.Stream;
1013

1114
/**
1215
* 提供树相关操作
@@ -17,9 +20,6 @@
1720
*/
1821
public final class TreeSupport {
1922

20-
private TreeSupport() {
21-
}
22-
2323
/**
2424
* @see #treeify(List, Function)
2525
*/
@@ -127,7 +127,7 @@ public static <R extends Element<R>> List<DefaultExpand> expand(List<R> forest)
127127
* @param <R> 继承于{@link Element}的泛型
128128
* @return expand
129129
*/
130-
public static synchronized <T extends Expand, R extends Element<R>> List<T> expand(List<R> forest, Function<R, T> expandFunc, Comparator<T> comparator) {
130+
public static <T extends Expand, R extends Element<R>> List<T> expand(List<R> forest, Function<R, T> expandFunc, Comparator<T> comparator) {
131131
List<T> expands = Lists.newArrayList();
132132
try {
133133
Element.ROOT_SENTINEL.setChildren(Lists.newArrayList(forest));
@@ -145,4 +145,34 @@ public static synchronized <T extends Expand, R extends Element<R>> List<T> expa
145145
}
146146
return expands;
147147
}
148+
149+
/**
150+
* with any 'forest' type expand collection type R data
151+
*
152+
* @param forest the forest about description tree data structure
153+
* @param childrenFunc the description children function
154+
* @param transfer transfer type T to type R
155+
* @return the collection of type R
156+
* @param <T> the forest type T
157+
* @param <R> the expand type R
158+
* @see #doExpandFn(Collection, MethodFunction, Function)
159+
*/
160+
public static <T, R> Collection<R> withExpandFn(Collection<T> forest, MethodFunction<T,Collection<T>> childrenFunc, Function<T, R> transfer) {
161+
return doExpandFn(forest, childrenFunc, transfer).toList();
162+
}
163+
164+
/**
165+
* through use java stream feature, do expand
166+
*/
167+
static <T, R> Stream<R> doExpandFn(Collection<T> forest, MethodFunction<T,Collection<T>> childrenFunc, Function<T, R> transfer) {
168+
return forest.stream()
169+
.flatMap(element -> {
170+
String fieldName = childrenFunc.getFieldName();
171+
Collection<T> children = BeanWrapper.getValue(element, fieldName, Collection.class);
172+
if (CollectionUtils.isNotEmpty(children)) {
173+
return doExpandFn(forest, childrenFunc, transfer);
174+
}
175+
return Stream.of(transfer.apply(element));
176+
});
177+
}
148178
}

uno-core/src/main/java/cc/allio/uno/core/function/lambda/MethodFunction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
* @since 1.1.7
1313
*/
1414
@FunctionalInterface
15-
public interface MethodFunction<T, K> extends Serializable, LambdaMethod {
15+
public interface MethodFunction<T, R> extends Serializable, LambdaMethod {
1616

17-
K apply(T t);
17+
R apply(T t);
1818

1919
/**
2020
* 获取参数值的类型
@@ -26,7 +26,7 @@ default Class<T> getParameterType() {
2626
/**
2727
* 获取返回值的类型
2828
*/
29-
default Class<K> getReturnType() {
30-
return (Class<K>) ReflectTools.getGenericType(this, MethodFunction.class, 1);
29+
default Class<R> getReturnType() {
30+
return (Class<R>) ReflectTools.getGenericType(this, MethodFunction.class, 1);
3131
}
3232
}

uno-core/src/main/java/cc/allio/uno/core/type/ShortTypeOperator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cc.allio.uno.core.type;
22

3-
import cc.allio.uno.core.StringPool;
4-
53
/**
64
* Short类型的转换器。可能抛出NumberFormatException异常
75
*

uno-core/src/main/java/cc/allio/uno/core/util/DateUtil.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import org.springframework.util.Assert;
66
import reactor.core.publisher.Flux;
77

8+
import java.text.DateFormat;
89
import java.text.ParseException;
10+
import java.text.SimpleDateFormat;
911
import java.time.*;
1012
import java.time.format.DateTimeFormatter;
1113
import java.time.temporal.Temporal;
@@ -55,6 +57,10 @@ public class DateUtil {
5557
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE);
5658
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(DateUtil.PATTERN_TIME);
5759

60+
static final ThreadLocal<DateFormat> DATE_FORMAT_SHORT_DATE_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMdd"));
61+
static final ThreadLocal<DateFormat> DATE_FORMAT_SHORT_MONTH_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMM"));
62+
static final ThreadLocal<DateFormat> DATE_FORMAT_YEAR_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy"));
63+
5864
/**
5965
* 获取当前日期
6066
*
@@ -888,4 +894,41 @@ public static boolean isBetween(Date nowTime, Date startTime, Date endTime) {
888894
public static Date getEpochTime() {
889895
return new Date(0);
890896
}
897+
898+
/**
899+
* get current datetime format to 'yyyyMMdd'
900+
*
901+
* @return the format 'yyyyMMdd' time
902+
*/
903+
public static String getNowYMD() {
904+
return DATE_FORMAT_SHORT_DATE_LOCAL.get().format(new Date());
905+
}
906+
907+
/**
908+
* get current datetime format to 'yyyyMM'
909+
*
910+
* @return the format 'yyyyMM' time
911+
*/
912+
public static String getNowYM() {
913+
return DATE_FORMAT_SHORT_MONTH_LOCAL.get().format(new Date());
914+
}
915+
916+
/**
917+
* get current datetime format to 'yyyy'
918+
*
919+
* @return the format 'yyyy' time
920+
*/
921+
public static String getNowY() {
922+
return DATE_FORMAT_YEAR_LOCAL.get().format(new Date());
923+
}
924+
925+
/**
926+
* get current datetime specifies pattern format time
927+
*
928+
* @param pattern the format pattern
929+
* @return format time
930+
*/
931+
public static String getNowPart(String pattern) {
932+
return format(now(), pattern);
933+
}
891934
}

uno-core/src/main/java/cc/allio/uno/core/util/template/TemplateContext.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import cc.allio.uno.core.api.OptionalContext;
44
import cc.allio.uno.core.type.Types;
5-
import cc.allio.uno.core.util.BeanUtils;
6-
import cc.allio.uno.core.util.ClassUtils;
7-
import cc.allio.uno.core.util.DateUtil;
8-
import cc.allio.uno.core.util.JsonUtils;
5+
import cc.allio.uno.core.util.*;
96
import com.google.common.collect.Maps;
107
import lombok.Getter;
118
import org.springframework.context.ApplicationContext;
@@ -41,6 +38,7 @@ public class TemplateContext implements OptionalContext {
4138
private static final String JSON_UTILITY_NAME = "json";
4239
private static final String BEAN_UTILITY_NAME = "bean";
4340
private static final String CLASS_UTILITY_NAME = "class";
41+
private static final String STRING_UTILITY_NAME = "string";
4442

4543
public TemplateContext() {
4644
this.vars = Maps.newConcurrentMap();
@@ -58,6 +56,7 @@ void initial() {
5856
addImport(JSON_UTILITY_NAME, JsonUtils.class);
5957
addImport(BEAN_UTILITY_NAME, BeanUtils.class);
6058
addImport(CLASS_UTILITY_NAME, ClassUtils.class);
59+
addImport(STRING_UTILITY_NAME, StringUtils.class);
6160
}
6261

6362
@Override
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cc.allio.uno.core.util.template.mvel;
2+
3+
import org.mvel2.templates.util.TemplateOutputStream;
4+
5+
import java.io.IOException;
6+
import java.io.OutputStreamWriter;
7+
8+
/**
9+
* solution messy code
10+
*
11+
* @author j.x
12+
* @date 2024/5/29 19:30
13+
* @since 1.1.9
14+
*/
15+
public class CharsetOutputStream implements TemplateOutputStream {
16+
17+
OutputStreamWriter writer;
18+
19+
public CharsetOutputStream(OutputStreamWriter writer) {
20+
this.writer = writer;
21+
}
22+
23+
@Override
24+
public TemplateOutputStream append(char[] chars) {
25+
try {
26+
for (char c : chars) {
27+
writer.write(c);
28+
}
29+
return this;
30+
} catch (IOException ex) {
31+
throw new RuntimeException("failed to write to stream", ex);
32+
}
33+
}
34+
35+
@Override
36+
public TemplateOutputStream append(CharSequence c) {
37+
try {
38+
for (int i = 0; i < c.length(); ++i) {
39+
this.writer.write(c.charAt(i));
40+
}
41+
return this;
42+
} catch (IOException ex) {
43+
throw new RuntimeException("failed to write to stream", ex);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)