Skip to content

Commit 95be4b2

Browse files
committed
添加随机数生成工具。
1 parent 8a35fb7 commit 95be4b2

8 files changed

Lines changed: 426 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Mac OS X x64 [xJavaFxTool-0.1.6-macosx-x64.pkg](https://dev.tencent.com/s/c5ffd1
137137

138138
47、SedentaryReminderTool:久坐提醒工具;
139139

140+
48、RandomGeneratorTool:随机数生成工具;
141+
140142
传输工具目前支持功能如下:
141143

142144
Receiver接收器:
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.xwintop.xJavaFxTool.controller.codeTools;
2+
3+
import cn.hutool.core.util.RandomUtil;
4+
import com.xwintop.xJavaFxTool.services.codeTools.RandomGeneratorToolService;
5+
import com.xwintop.xJavaFxTool.view.codeTools.RandomGeneratorToolView;
6+
import com.xwintop.xcore.util.UuidUtil;
7+
import javafx.event.ActionEvent;
8+
import javafx.fxml.FXML;
9+
import lombok.Getter;
10+
import lombok.Setter;
11+
import lombok.extern.slf4j.Slf4j;
12+
13+
import java.net.URL;
14+
import java.util.ResourceBundle;
15+
16+
/**
17+
* @ClassName: RandomGeneratorToolController
18+
* @Description: 随机数生成工具
19+
* @author: xufeng
20+
* @date: 2019/6/15 0015 0:52
21+
*/
22+
23+
@Getter
24+
@Setter
25+
@Slf4j
26+
public class RandomGeneratorToolController extends RandomGeneratorToolView {
27+
private RandomGeneratorToolService randomGeneratorToolService = new RandomGeneratorToolService(this);
28+
29+
@Override
30+
public void initialize(URL location, ResourceBundle resources) {
31+
initView();
32+
initEvent();
33+
initService();
34+
}
35+
36+
private void initView() {
37+
}
38+
39+
private void initEvent() {
40+
}
41+
42+
private void initService() {
43+
}
44+
45+
@FXML
46+
private void generateUUID(ActionEvent event) {
47+
uuidResult.setText(UuidUtil.get32UUID());
48+
}
49+
50+
@FXML
51+
private void generateNumber(ActionEvent event) {
52+
String flo = floor.getText();
53+
String cei = ceil.getText();
54+
int p = stringToInt(precision.getText());
55+
int f = stringToInt(flo);
56+
int c = stringToInt(cei);
57+
numberResult.setText(String.valueOf(RandomUtil.randomInt(f, c)));
58+
}
59+
60+
@FXML
61+
private void generateEmail(ActionEvent event) {
62+
String email = RandomUtil.randomString(RandomUtil.randomInt(3, 10)) + "@" + RandomUtil.randomString(RandomUtil.BASE_CHAR, RandomUtil.randomInt(3, 5)) + "." + RandomUtil.randomString(RandomUtil.BASE_CHAR, RandomUtil.randomInt(1, 5));
63+
emailResult.setText(email);
64+
}
65+
66+
@FXML
67+
private void generateLowerCase(ActionEvent event) {
68+
lowerCaseResult.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR, getLength(lowerCaseLength.getText())));
69+
}
70+
71+
@FXML
72+
private void generateUpperCase(ActionEvent event) {
73+
upperCaseResult.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR, getLength(upperCaseLength.getText())).toUpperCase());
74+
}
75+
76+
@FXML
77+
private void generateLetter(ActionEvent event) {
78+
letterResult.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR + RandomUtil.BASE_CHAR.toUpperCase(), getLength(letterLength.getText())));
79+
}
80+
81+
@FXML
82+
private void generateString(ActionEvent event) {
83+
stringResult.setText(RandomUtil.randomString(getLength(stringLength.getText())));
84+
}
85+
86+
@FXML
87+
private void generateText(ActionEvent event) {
88+
textResult.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR + RandomUtil.BASE_CHAR.toUpperCase() + "~!@#$%^&*()_+{}:\"<>?`-=[];'\\|,./", getLength(textLength.getText())));
89+
}
90+
91+
public static int stringToInt(String integer) {
92+
int result = 0;
93+
try {
94+
result = Integer.parseInt(integer.trim());
95+
} catch (Exception e) {
96+
log.warn("转换异常" + e.getMessage());
97+
}
98+
return result > -1 ? result : 0;
99+
}
100+
101+
private int getLength(String len) {
102+
int length = 0;
103+
try {
104+
length = Integer.parseInt(len.trim());
105+
} catch (Exception e) {
106+
log.warn("转换异常" + e.getMessage());
107+
}
108+
return length < 1 ? RandomUtil.randomInt(9, 16) : length;
109+
}
110+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.xwintop.xJavaFxTool.services.codeTools;
2+
3+
import com.xwintop.xJavaFxTool.controller.codeTools.RandomGeneratorToolController;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.extern.slf4j.Slf4j;
7+
8+
/**
9+
* @ClassName: RandomGeneratorToolService
10+
* @Description: 随机数生成工具
11+
* @author: xufeng
12+
* @date: 2019/6/15 0015 0:53
13+
*/
14+
15+
@Getter
16+
@Setter
17+
@Slf4j
18+
public class RandomGeneratorToolService {
19+
private RandomGeneratorToolController randomGeneratorToolController;
20+
21+
public RandomGeneratorToolService(RandomGeneratorToolController randomGeneratorToolController) {
22+
this.randomGeneratorToolController = randomGeneratorToolController;
23+
}
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.xwintop.xJavaFxTool.view.codeTools;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.fxml.Initializable;
5+
import javafx.scene.control.TextField;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
/**
10+
* @ClassName: RandomGeneratorToolView
11+
* @Description: 随机数生成工具
12+
* @author: xufeng
13+
* @date: 2019/6/15 0015 0:53
14+
*/
15+
16+
@Getter
17+
@Setter
18+
public abstract class RandomGeneratorToolView implements Initializable {
19+
@FXML
20+
protected TextField uuidResult;
21+
@FXML
22+
protected TextField floor;
23+
@FXML
24+
protected TextField ceil;
25+
@FXML
26+
protected TextField ignoreRange;
27+
@FXML
28+
protected TextField precision;
29+
@FXML
30+
protected TextField numberResult;
31+
@FXML
32+
protected TextField emailResult;
33+
@FXML
34+
protected TextField lowerCaseLength;
35+
@FXML
36+
protected TextField lowerCaseResult;
37+
@FXML
38+
protected TextField upperCaseLength;
39+
@FXML
40+
protected TextField upperCaseResult;
41+
@FXML
42+
protected TextField letterLength;
43+
@FXML
44+
protected TextField letterResult;
45+
@FXML
46+
protected TextField stringLength;
47+
@FXML
48+
protected TextField stringResult;
49+
@FXML
50+
protected TextField textLength;
51+
@FXML
52+
protected TextField textResult;
53+
54+
}

0 commit comments

Comments
 (0)