Skip to content

Commit

Permalink
Merge pull request #23 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
1.1.x
  • Loading branch information
ClearXs authored Jul 4, 2024
2 parents 7e1c318 + c413a83 commit d079860
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 19 deletions.
138 changes: 138 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
site_name: uno文档
repo_name: uno
repo_url: https://github.com/ClearXs/uno
site_author: J.x ([email protected])
copyright: Copyright © 2023 - 2024 ClearX

nav:
- README.md
- core: core.md
- data: data.md
- rule: rule.md
- web: web.md
- test: test.md
- gis: gis.md
- auto: auto.md
- bom: bom.md
- plugins: plugins.md
- components:
- http: components/http.md
- kafka: components/kafka.md
- media: components/media.md
- netty: components/netty.md
- sequential: components/sequential.md
- websocket: components/websocket.md
- starter: starter.md

theme:
# https://squidfunk.github.io/mkdocs-material/creating-your-site/#configuration
name: material
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/
palette:
- scheme: default
toggle:
icon: material/brightness-7
primary: indigo
accent: light blue
- scheme: slate
toggle:
icon: material/brightness-4
primary: indigo
accent: grey
# https://squidfunk.github.io/mkdocs-material/setup/changing-the-fonts/
font:
text: Nunito Sans
code: Roboto Mono
logo: favicon.png
favicon: favicon.png
features:
# Navigation
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/
- navigation.instant # some features may not work properly with XHR
- navigation.tracking # the URL changes with the active anchor
- navigation.instant.prefetch
- navigation.tabs # first top-level folders are shown as tabs
- navigation.tabs.sticky # tabs always show
- navigation.prune
- navigation.sections # second-level folders are expanded
- navigation.expand # all folders are expanded
- navigation.indexes # link an index page to its parent folder
- navigation.top # show the back-to-top button
- toc.integrate # show the table of contents in the navigation panel
# Search
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search
- search.suggest # display the likeliest completion for the last word
- search.highlight # highlight all occurrences
- search.share # show a share button of the current search
# Header
# https://squidfunk.github.io/mkdocs-material/setup/setting-up-the-header/
- header.autohide # hide the post title when scroll down
# Content
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
- content.code.annotate # add comment to code blocks
- content.tabs.link # link tabs with the same label
- content.tooltips

#
# Plugins
#
plugins:
- tags
- search: # must be included at the first place
lang:
- en
- zh
separator: '[\s\u200b\-]'
- offline
#
# Extensions
#
markdown_extensions:
- abbr # add a small tooltip to elements
- admonition # add call-out blocks
- attr_list # allow to add HTML attributes and CSS classes
- def_list # add description lists
- footnotes # define inline footnotes
- meta # attach arbitrary key-value pairs to a document
- md_in_html # allow to write Markdown inside HTML elements
- tables # create tables in Markdown
- toc: # generate a table of contents from documents
permalink: '#' # anchor
toc_depth: 4 # header 1 to header 4
slugify: !!python/name:pymdownx.slugs.uslugify # convert title to html-compatible text
- sane_lists # make better lists
- smarty: # convert some special characters
smart_angled_quotes: true
- pymdownx.highlight:
anchor_linenums: true
# - pymdownx.betterem: # improve the detection of Markup to emphasize text in Markdown
# smart_enable: all
- pymdownx.caret # define superscript
- pymdownx.mark # highlight text
- pymdownx.tilde # define subscript
- pymdownx.critic # track changes
- pymdownx.details # add collapsible call-outs
- pymdownx.emoji: # add inlines bundled and custom icons and emojis
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.superfences # define code blocks and nesting of code
- pymdownx.highlight: # highlight of code blocks
linenums_style: pymdownx-inline
# anchor_linenums: true # create anchor link on each line of code
- pymdownx.inlinehilite # highlight inline code blocks
- pymdownx.smartsymbols # convert some sequences of characters into their corresponding symbols
- pymdownx.snippets: # embed content from arbitrary files into a document
check_paths: true
- pymdownx.tabbed: # group related content and code blocks under accessible tabs
alternate_style: true
- pymdownx.tasklist: # define list of task with checkbox
custom_checkbox: true
- pymdownx.escapeall:
hardbreak: true # use \ to create new line
nbsp: true # use \<space> to create &nbsp;
# - pymdownx.keys # syntax ++ctrl+c++ does not look clear in MD document
- pymdownx.progressbar
extra:
version:
provider: mike
disqus: "vuquangtrong-github-io"
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "turbo-docs",
"version": "1.0.0",
"description": "turbo documentation",
"private": true,
"scripts": {
"dev": "mkdocs serve",
"build": "mkdocs build -d public"
}
}
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mkdocs
mkdocs-material
mkdocs-roamlinks-plugin
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package cc.allio.uno.core.datastructure.tree;

import cc.allio.uno.core.bean.BeanWrapper;
import cc.allio.uno.core.function.lambda.MethodFunction;
import cc.allio.uno.core.util.CollectionUtils;
import com.google.common.collect.Lists;

import java.io.Serializable;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* 提供树相关操作
Expand All @@ -17,9 +20,6 @@
*/
public final class TreeSupport {

private TreeSupport() {
}

/**
* @see #treeify(List, Function)
*/
Expand Down Expand Up @@ -127,7 +127,7 @@ public static <R extends Element<R>> List<DefaultExpand> expand(List<R> forest)
* @param <R> 继承于{@link Element}的泛型
* @return expand
*/
public static synchronized <T extends Expand, R extends Element<R>> List<T> expand(List<R> forest, Function<R, T> expandFunc, Comparator<T> comparator) {
public static <T extends Expand, R extends Element<R>> List<T> expand(List<R> forest, Function<R, T> expandFunc, Comparator<T> comparator) {
List<T> expands = Lists.newArrayList();
try {
Element.ROOT_SENTINEL.setChildren(Lists.newArrayList(forest));
Expand All @@ -145,4 +145,34 @@ public static synchronized <T extends Expand, R extends Element<R>> List<T> expa
}
return expands;
}

/**
* with any 'forest' type expand collection type R data
*
* @param forest the forest about description tree data structure
* @param childrenFunc the description children function
* @param transfer transfer type T to type R
* @return the collection of type R
* @param <T> the forest type T
* @param <R> the expand type R
* @see #doExpandFn(Collection, MethodFunction, Function)
*/
public static <T, R> Collection<R> withExpandFn(Collection<T> forest, MethodFunction<T,Collection<T>> childrenFunc, Function<T, R> transfer) {
return doExpandFn(forest, childrenFunc, transfer).toList();
}

/**
* through use java stream feature, do expand
*/
static <T, R> Stream<R> doExpandFn(Collection<T> forest, MethodFunction<T,Collection<T>> childrenFunc, Function<T, R> transfer) {
return forest.stream()
.flatMap(element -> {
String fieldName = childrenFunc.getFieldName();
Collection<T> children = BeanWrapper.getValue(element, fieldName, Collection.class);
if (CollectionUtils.isNotEmpty(children)) {
return doExpandFn(forest, childrenFunc, transfer);
}
return Stream.of(transfer.apply(element));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* @since 1.1.7
*/
@FunctionalInterface
public interface MethodFunction<T, K> extends Serializable, LambdaMethod {
public interface MethodFunction<T, R> extends Serializable, LambdaMethod {

K apply(T t);
R apply(T t);

/**
* 获取参数值的类型
Expand All @@ -26,7 +26,7 @@ default Class<T> getParameterType() {
/**
* 获取返回值的类型
*/
default Class<K> getReturnType() {
return (Class<K>) ReflectTools.getGenericType(this, MethodFunction.class, 1);
default Class<R> getReturnType() {
return (Class<R>) ReflectTools.getGenericType(this, MethodFunction.class, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cc.allio.uno.core.type;

import cc.allio.uno.core.StringPool;

/**
* Short类型的转换器。可能抛出NumberFormatException异常
*
Expand Down
43 changes: 43 additions & 0 deletions uno-core/src/main/java/cc/allio/uno/core/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import org.springframework.util.Assert;
import reactor.core.publisher.Flux;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
Expand Down Expand Up @@ -55,6 +57,10 @@ public class DateUtil {
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE);
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern(DateUtil.PATTERN_TIME);

static final ThreadLocal<DateFormat> DATE_FORMAT_SHORT_DATE_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMdd"));
static final ThreadLocal<DateFormat> DATE_FORMAT_SHORT_MONTH_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMM"));
static final ThreadLocal<DateFormat> DATE_FORMAT_YEAR_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy"));

/**
* 获取当前日期
*
Expand Down Expand Up @@ -888,4 +894,41 @@ public static boolean isBetween(Date nowTime, Date startTime, Date endTime) {
public static Date getEpochTime() {
return new Date(0);
}

/**
* get current datetime format to 'yyyyMMdd'
*
* @return the format 'yyyyMMdd' time
*/
public static String getNowYMD() {
return DATE_FORMAT_SHORT_DATE_LOCAL.get().format(new Date());
}

/**
* get current datetime format to 'yyyyMM'
*
* @return the format 'yyyyMM' time
*/
public static String getNowYM() {
return DATE_FORMAT_SHORT_MONTH_LOCAL.get().format(new Date());
}

/**
* get current datetime format to 'yyyy'
*
* @return the format 'yyyy' time
*/
public static String getNowY() {
return DATE_FORMAT_YEAR_LOCAL.get().format(new Date());
}

/**
* get current datetime specifies pattern format time
*
* @param pattern the format pattern
* @return format time
*/
public static String getNowPart(String pattern) {
return format(now(), pattern);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import cc.allio.uno.core.api.OptionalContext;
import cc.allio.uno.core.type.Types;
import cc.allio.uno.core.util.BeanUtils;
import cc.allio.uno.core.util.ClassUtils;
import cc.allio.uno.core.util.DateUtil;
import cc.allio.uno.core.util.JsonUtils;
import cc.allio.uno.core.util.*;
import com.google.common.collect.Maps;
import lombok.Getter;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -41,6 +38,7 @@ public class TemplateContext implements OptionalContext {
private static final String JSON_UTILITY_NAME = "json";
private static final String BEAN_UTILITY_NAME = "bean";
private static final String CLASS_UTILITY_NAME = "class";
private static final String STRING_UTILITY_NAME = "string";

public TemplateContext() {
this.vars = Maps.newConcurrentMap();
Expand All @@ -58,6 +56,7 @@ void initial() {
addImport(JSON_UTILITY_NAME, JsonUtils.class);
addImport(BEAN_UTILITY_NAME, BeanUtils.class);
addImport(CLASS_UTILITY_NAME, ClassUtils.class);
addImport(STRING_UTILITY_NAME, StringUtils.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cc.allio.uno.core.util.template.mvel;

import org.mvel2.templates.util.TemplateOutputStream;

import java.io.IOException;
import java.io.OutputStreamWriter;

/**
* solution messy code
*
* @author j.x
* @date 2024/5/29 19:30
* @since 1.1.9
*/
public class CharsetOutputStream implements TemplateOutputStream {

OutputStreamWriter writer;

public CharsetOutputStream(OutputStreamWriter writer) {
this.writer = writer;
}

@Override
public TemplateOutputStream append(char[] chars) {
try {
for (char c : chars) {
writer.write(c);
}
return this;
} catch (IOException ex) {
throw new RuntimeException("failed to write to stream", ex);
}
}

@Override
public TemplateOutputStream append(CharSequence c) {
try {
for (int i = 0; i < c.length(); ++i) {
this.writer.write(c.charAt(i));
}
return this;
} catch (IOException ex) {
throw new RuntimeException("failed to write to stream", ex);
}
}
}
Loading

0 comments on commit d079860

Please sign in to comment.