Skip to content

Commit

Permalink
Merge pull request #4 from lijiahangmax/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lijiahangmax authored Apr 7, 2024
2 parents 14ba61d + 782430e commit 58841d2
Show file tree
Hide file tree
Showing 26 changed files with 258 additions and 82 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ orion-all | 全部模块聚合 包含了上述所有模块的引用

### 如何使用
``` pom.xml
# 当前最新版本 1.0.6
# 当前最新版本 1.0.7
<dependency>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>模块名称</artifactId>
Expand All @@ -61,7 +61,7 @@ orion-all | 全部模块聚合 包含了上述所有模块的引用
<dependency>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-all</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion orion-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion orion-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion orion-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion orion-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion orion-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface OrionConst {

String ORION_DISPLAY = ".orion";

String ORION_KIT_VERSION = "1.0.6";
String ORION_KIT_VERSION = "1.0.7";

String ORION_AUTHOR = "Jiahang Li";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -67,21 +68,20 @@ public class DataGrid<T> extends CloneSupport<DataGrid<T>> implements Serializab
private List<T> rows;

public DataGrid() {
this.page = 1;
this.limit = DEFAULT_LIMIT;
}

public DataGrid(List<T> rows) {
this(rows, Lists.size(rows));
}

public DataGrid(List<T> rows, int total) {
this.page = 1;
this.limit = DEFAULT_LIMIT;
this();
this.rows = rows;
this.size = Lists.size(this.rows);
this.total = total;
if (total != 0) {
this.pages = total % limit == 0 ? total / limit : (total / limit + 1);
}
this.resetPages();
}

public DataGrid(Pager<T> pager) {
Expand Down Expand Up @@ -156,7 +156,9 @@ public List<T> getRows() {
*/
public void setRows(List<T> rows) {
this.rows = rows;
if (rows != null) {
if (rows == null) {
this.size = 0;
} else {
this.size = rows.size();
}
}
Expand All @@ -167,9 +169,7 @@ public int getTotal() {

public void setTotal(int total) {
this.total = total;
if (total != 0) {
this.pages = total % limit == 0 ? total / limit : (total / limit + 1);
}
this.resetPages();
}

public int getPage() {
Expand Down Expand Up @@ -211,7 +211,9 @@ public void setSize(int size) {
* @return this
*/
public DataGrid<T> resetPages() {
if (total != 0) {
if (total == 0) {
this.pages = 0;
} else {
this.pages = total % limit == 0 ? total / limit : (total / limit + 1);
}
return this;
Expand Down Expand Up @@ -249,6 +251,24 @@ public Stream<T> stream() {
}
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> DataGrid<E> map(Function<T, E> mapping) {
DataGrid<E> result = new DataGrid<>();
result.page = this.page;
result.limit = this.limit;
result.size = this.size;
result.pages = this.pages;
result.total = this.total;
result.rows = Lists.map(this.rows, mapping);
return result;
}

@Override
public String toString() {
return String.valueOf(rows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* restful 结果封装
Expand Down Expand Up @@ -224,6 +225,21 @@ public Map<String, Object> toMap() {
return map;
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> HttpWrapper<E> map(Function<T, E> mapping) {
HttpWrapper<E> result = new HttpWrapper<>();
result.code = this.code;
result.msg = this.msg;
result.data = Objects1.map(this.data, mapping);
return result;
}

/**
* @return {@link RpcWrapper}
*/
Expand Down
22 changes: 22 additions & 0 deletions orion-lang/src/main/java/com/orion/lang/define/wrapper/Pager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -325,6 +326,27 @@ public Stream<T> stream() {
}
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> Pager<E> map(Function<T, E> mapping) {
Pager<E> result = new Pager<>();
result.page = this.page;
result.limit = this.limit;
result.offset = this.offset;
result.pages = this.pages;
result.total = this.total;
result.prePage = this.prePage;
result.nextPage = this.nextPage;
result.sql = this.sql;
result.rows = Lists.map(this.rows, mapping);
return result;
}

@Override
public String toString() {
return sql;
Expand Down
13 changes: 13 additions & 0 deletions orion-lang/src/main/java/com/orion/lang/define/wrapper/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.orion.lang.able.IJsonObject;
import com.orion.lang.define.support.CloneSupport;
import com.orion.lang.utils.Objects1;

import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

/**
* 对象 包装类
Expand Down Expand Up @@ -47,6 +49,17 @@ public void setValue(T value) {
this.value = value;
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> Ref<E> map(Function<T, E> mapping) {
return new Ref<>(Objects1.map(this.value, mapping));
}

/**
* @return Optional
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import com.orion.lang.define.support.CloneSupport;
import com.orion.lang.id.UUIds;
import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Objects1;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.lang.utils.json.Jsons;

import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -307,6 +309,23 @@ public HttpWrapper<T> toHttpWrapper() {
return HttpWrapper.of(code, msg, data);
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> RpcWrapper<E> map(Function<T, E> mapping) {
RpcWrapper<E> result = new RpcWrapper<>();
result.code = this.code;
result.msg = this.msg;
result.traceId = this.traceId;
result.errorMessages = this.errorMessages;
result.data = Objects1.map(this.data, mapping);
return result;
}

/**
* @return result 的 Optional
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.orion.lang.define.wrapper;

import com.orion.lang.constant.Const;
import com.orion.lang.utils.Objects1;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

/**
* 时间戳数据
Expand Down Expand Up @@ -49,8 +54,44 @@ public void setValue(T value) {
this.value = value;
}

/**
* 映射
*
* @param mapping mapping
* @param <E> E
* @return mapped
*/
public <E> TimestampValue<E> map(Function<T, E> mapping) {
return new TimestampValue<>(this.time, Objects1.map(this.value, mapping));
}

/**
* @return Optional
*/
public Optional<T> optional() {
return Optional.ofNullable(value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TimestampValue<?> that = (TimestampValue<?>) o;
return Objects.equals(time, that.time) && Objects.equals(value, that.value);
}

@Override
public int hashCode() {
return Objects.hash(time, value);
}

@Override
public String toString() {
return time + Const.EMPTY + value;
}

}
Loading

0 comments on commit 58841d2

Please sign in to comment.