-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/flowerfine/milky-all
- Loading branch information
Showing
51 changed files
with
817 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
milky-common/src/main/java/cn/sliew/milky/common/concurrent/AbstractLoopRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.sliew.milky.common.concurrent; | ||
|
||
public abstract class AbstractLoopRunnable implements LoopRunnable { | ||
|
||
protected volatile boolean terminal = false; | ||
|
||
@Override | ||
public void terminate() { | ||
terminal = true; | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
return terminal; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
milky-common/src/main/java/cn/sliew/milky/common/concurrent/LoopRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.sliew.milky.common.concurrent; | ||
|
||
public interface LoopRunnable extends Runnable { | ||
|
||
void execute(); | ||
|
||
void terminate(); | ||
|
||
boolean isTerminated(); | ||
|
||
@Override | ||
default void run() { | ||
while (isTerminated() == false) { | ||
execute(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
milky-common/src/main/java/cn/sliew/milky/common/concurrent/ThreadPoolUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.sliew.milky.common.concurrent; | ||
|
||
import java.util.concurrent.*; | ||
|
||
public enum ThreadPoolUtil { | ||
; | ||
|
||
private static ConcurrentMap<String, ExecutorService> executors = new ConcurrentHashMap<>(); | ||
|
||
private static ExecutorService init(String poolName, int poolSize) { | ||
return new ThreadPoolExecutor(poolSize, poolSize, | ||
0L, TimeUnit.MILLISECONDS, | ||
new LinkedBlockingQueue<Runnable>(), | ||
new DaemonThreadFactory("Pool-" + poolName, true), | ||
new ThreadPoolExecutor.CallerRunsPolicy()); | ||
} | ||
|
||
public static ExecutorService getOrInitExecutors(String poolName, int poolSize) { | ||
return executors.computeIfAbsent(poolName, key -> init(poolName, poolSize)); | ||
} | ||
|
||
public static void releaseExecutors(String poolName) { | ||
ExecutorService executorService = executors.remove(poolName); | ||
if (executorService != null) { | ||
executorService.shutdown(); | ||
} | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
milky-common/src/main/java/cn/sliew/milky/common/unit/MoneyUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package cn.sliew.milky.common.unit; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public enum MoneyUnit { | ||
|
||
HAO { | ||
@Override | ||
public BigDecimal toHao(BigDecimal size) { | ||
return size; | ||
} | ||
|
||
@Override | ||
public BigDecimal toFen(BigDecimal size) { | ||
return size.divide(C1.divide(C0)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toJiao(BigDecimal size) { | ||
return size.divide(C2.divide(C0)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toYuan(BigDecimal size) { | ||
return size.divide(C3.divide(C0)); | ||
} | ||
|
||
@Override | ||
public String getSuffix() { | ||
return "毫"; | ||
} | ||
}, | ||
|
||
FEN { | ||
|
||
@Override | ||
public BigDecimal toHao(BigDecimal size) { | ||
return size.multiply(C1.divide(C0)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toFen(BigDecimal size) { | ||
return size; | ||
} | ||
|
||
@Override | ||
public BigDecimal toJiao(BigDecimal size) { | ||
return size.divide(C2.divide(C1)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toYuan(BigDecimal size) { | ||
return size.divide(C3.divide(C1)); | ||
} | ||
|
||
@Override | ||
public String getSuffix() { | ||
return "分"; | ||
} | ||
}, | ||
|
||
JIAO { | ||
@Override | ||
public BigDecimal toHao(BigDecimal size) { | ||
return size.multiply(C2.divide(C0)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toFen(BigDecimal size) { | ||
return size.multiply(C2.divide(C1)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toJiao(BigDecimal size) { | ||
return size; | ||
} | ||
|
||
@Override | ||
public BigDecimal toYuan(BigDecimal size) { | ||
return size.divide(C3.divide(C2)); | ||
} | ||
|
||
@Override | ||
public String getSuffix() { | ||
return "角"; | ||
} | ||
}, | ||
|
||
YUAN { | ||
@Override | ||
public BigDecimal toHao(BigDecimal size) { | ||
return size.multiply(C3.divide(C0)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toFen(BigDecimal size) { | ||
return size.multiply(C3.divide(C1)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toJiao(BigDecimal size) { | ||
return size.multiply(C3.divide(C2)); | ||
} | ||
|
||
@Override | ||
public BigDecimal toYuan(BigDecimal size) { | ||
return size; | ||
} | ||
|
||
@Override | ||
public String getSuffix() { | ||
return "元"; | ||
} | ||
}; | ||
|
||
static final BigDecimal _TEN = BigDecimal.TEN; | ||
static final BigDecimal _HUNDRED = BigDecimal.valueOf(100L); | ||
static final BigDecimal C0 = BigDecimal.ONE; | ||
static final BigDecimal C1 = C0.multiply(_HUNDRED); | ||
static final BigDecimal C2 = C1.multiply(_TEN); | ||
static final BigDecimal C3 = C2.multiply(_TEN); | ||
|
||
public abstract BigDecimal toHao(BigDecimal size); | ||
|
||
public abstract BigDecimal toFen(BigDecimal size); | ||
|
||
public abstract BigDecimal toJiao(BigDecimal size); | ||
|
||
public abstract BigDecimal toYuan(BigDecimal size); | ||
|
||
public abstract String getSuffix(); | ||
} |
Oops, something went wrong.