Skip to content

Commit 2fa84ee

Browse files
committed
refactor: clear up and beautify code
1 parent d073fb8 commit 2fa84ee

File tree

11 files changed

+103
-125
lines changed

11 files changed

+103
-125
lines changed

client/src/main/java/cn/vika/client/api/FieldApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public void deleteField(String spaceId, String datasheetId, String fieldId) {
6161

6262
private void checkDeleteFieldPathArgs(String spaceId, String datasheetId, String fieldId) {
6363
if (!StringUtil.hasText(spaceId)) {
64-
throw new ApiException("space id must be not null");
64+
throw new ApiException("space id must not be null");
6565
}
6666

6767
if (!StringUtil.hasText(datasheetId)) {
68-
throw new ApiException("datasheet id must be not null");
68+
throw new ApiException("datasheet id must not be null");
6969
}
7070

7171
if (!StringUtil.hasText(fieldId)) {
72-
throw new ApiException("fieldId id must be not null");
72+
throw new ApiException("fieldId id must not be null");
7373
}
7474
}
7575
}

client/src/main/java/cn/vika/client/api/model/CreateFieldRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.vika.client.api.model;
22

3+
import cn.vika.client.api.model.field.FieldTypeEnum;
34
import cn.vika.client.api.model.field.property.BaseFieldProperty;
45
import com.fasterxml.jackson.annotation.JsonInclude;
56
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -11,7 +12,7 @@ public class CreateFieldRequest <T extends BaseFieldProperty> {
1112

1213
/**
1314
* field type
14-
* @see cn.vika.client.api.model.field.FieldType
15+
* @see FieldTypeEnum
1516
*/
1617
private String type;
1718

Lines changed: 48 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,53 @@
11
package cn.vika.client.api.model.builder;
22

33
import cn.vika.client.api.model.CreateFieldRequest;
4-
import cn.vika.client.api.model.field.FieldType;
4+
import cn.vika.client.api.model.field.FieldTypeEnum;
55
import cn.vika.client.api.model.field.property.BaseFieldProperty;
66
import cn.vika.client.api.model.field.property.EmptyProperty;
77

88
/**
9+
* step builder
10+
*
911
* @author tao
1012
*/
11-
public class CreateFieldRequestBuilder{
13+
public class CreateFieldRequestBuilder implements IFieldTypeOfCreateField, INameOfCreateField, IPropertyOfCreateField {
1214

13-
public static IFieldTypeOfCreateField create() {
14-
return new FieldTypeOfCreateField(new ContextOfCreateField());
15-
}
16-
17-
}
18-
19-
class ContextOfCreateField {
20-
private FieldType fieldType;
21-
private String name;
22-
private BaseFieldProperty property;
23-
24-
public FieldType getFieldType() {
25-
return fieldType;
26-
}
27-
28-
public void setFieldType(FieldType fieldType) {
29-
this.fieldType = fieldType;
30-
}
31-
32-
public String getName() {
33-
return name;
34-
}
35-
36-
public void setName(String name) {
37-
this.name = name;
38-
}
15+
private final ContextOfCreateField context;
3916

40-
public BaseFieldProperty getProperty() {
41-
return property;
17+
public static IFieldTypeOfCreateField create() {
18+
return new CreateFieldRequestBuilder();
4219
}
4320

44-
public void setProperty(BaseFieldProperty property) {
45-
this.property = property;
46-
}
47-
}
48-
49-
class FieldTypeOfCreateField implements IFieldTypeOfCreateField {
50-
51-
private final ContextOfCreateField context;
52-
53-
FieldTypeOfCreateField(ContextOfCreateField context) {
54-
this.context = context;
21+
public CreateFieldRequestBuilder() {
22+
context = new ContextOfCreateField();
5523
}
5624

5725
@Override
58-
public INameOfCreateField ofType(FieldType fieldType) {
26+
public INameOfCreateField ofType(FieldTypeEnum fieldType) {
5927
context.setFieldType(fieldType);
60-
return new NameOfCreateField(context);
61-
}
62-
63-
}
64-
65-
class NameOfCreateField implements INameOfCreateField {
66-
67-
private final ContextOfCreateField context;
68-
69-
NameOfCreateField(ContextOfCreateField context) {
70-
this.context = context;
28+
return this;
7129
}
7230

7331
@Override
7432
public IPropertyOfCreateField withName(String name) {
7533
context.setName(name);
76-
return new PropertyOfCreateField(context);
77-
}
78-
79-
}
80-
81-
class PropertyOfCreateField implements IPropertyOfCreateField {
82-
83-
private final ContextOfCreateField context;
84-
85-
PropertyOfCreateField(ContextOfCreateField context) {
86-
this.context = context;
34+
return this;
8735
}
8836

8937
@Override
9038
public <T extends BaseFieldProperty> IBuildCreateField<T> withProperty(T property) {
91-
9239
context.setProperty(property);
9340
return new BuildCreateField<>(context);
9441
}
9542

9643
@Override
9744
public IBuildCreateField<EmptyProperty> withoutProperty() {
98-
context.setProperty(new EmptyProperty());
9945
return new BuildCreateField<>(context);
10046
}
47+
10148
}
10249

103-
class BuildCreateField<T extends BaseFieldProperty> implements IBuildCreateField<T> {
50+
class BuildCreateField<T extends BaseFieldProperty> implements IBuildCreateField<T> {
10451

10552
private final ContextOfCreateField context;
10653

@@ -120,3 +67,37 @@ public CreateFieldRequest<T> build() {
12067
}
12168

12269

70+
class ContextOfCreateField {
71+
72+
private FieldTypeEnum fieldType;
73+
74+
private String name;
75+
76+
private BaseFieldProperty property;
77+
78+
public FieldTypeEnum getFieldType() {
79+
return fieldType;
80+
}
81+
82+
public void setFieldType(FieldTypeEnum fieldType) {
83+
this.fieldType = fieldType;
84+
}
85+
86+
public String getName() {
87+
return name;
88+
}
89+
90+
public void setName(String name) {
91+
this.name = name;
92+
}
93+
94+
public BaseFieldProperty getProperty() {
95+
return property;
96+
}
97+
98+
public void setProperty(BaseFieldProperty property) {
99+
this.property = property;
100+
}
101+
}
102+
103+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package cn.vika.client.api.model.builder;
22

3-
import cn.vika.client.api.model.field.FieldType;
3+
import cn.vika.client.api.model.field.FieldTypeEnum;
44

55
/**
66
* @author tao
77
*/
88
public interface IFieldTypeOfCreateField {
99

10-
INameOfCreateField ofType(FieldType fieldType);
10+
INameOfCreateField ofType(FieldTypeEnum fieldType);
1111

1212
}

client/src/main/java/cn/vika/client/api/model/field/FieldType.java renamed to client/src/main/java/cn/vika/client/api/model/field/FieldTypeEnum.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @author tao
77
*/
8-
public enum FieldType {
8+
public enum FieldTypeEnum {
99
/**
1010
*
1111
*/
@@ -101,7 +101,7 @@ public enum FieldType {
101101

102102
private final String fieldType;
103103

104-
FieldType(String fieldType) {
104+
FieldTypeEnum(String fieldType) {
105105
this.fieldType = fieldType;
106106
}
107107

client/src/main/java/cn/vika/client/api/model/field/property/MagicLinkFieldProperty.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public class MagicLinkFieldProperty extends BaseFieldProperty {
1010

1111
private String foreignDatasheetId;
1212

13-
1413
@JsonInclude(Include.NON_NULL)
1514
private String limitToViewId;
1615

client/src/main/java/cn/vika/client/api/model/field/property/MagicLookupFieldProperty.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
*/
1212
public class MagicLookupFieldProperty extends BaseFieldProperty {
1313

14-
1514
private String relatedLinkFieldId;
1615

17-
1816
private String targetFieldId;
1917

2018
@JsonInclude(Include.NON_NULL)

client/src/main/java/cn/vika/client/api/model/field/property/option/Format.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
public class Format<T extends TypeFormat> {
77

8-
private FormatType type;
8+
private FormatTypeEnum type;
99

1010
private T format;
1111

12-
public FormatType getType() {
12+
public FormatTypeEnum getType() {
1313
return type;
1414
}
1515

16-
public void setType(FormatType type) {
16+
public void setType(FormatTypeEnum type) {
1717
this.type = type;
1818
}
1919

client/src/main/java/cn/vika/client/api/model/field/property/option/FormatType.java renamed to client/src/main/java/cn/vika/client/api/model/field/property/option/FormatTypeEnum.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* @author tao
77
*/
8-
public enum FormatType {
8+
public enum FormatTypeEnum {
99
/**
1010
* Format about DateTime
1111
* @see cn.vika.client.api.model.field.property.option.DateTimeFormat
@@ -25,12 +25,11 @@ public enum FormatType {
2525
* Format about Currency
2626
* @see cn.vika.client.api.model.field.property.option.CurrencyFormat
2727
*/
28-
Currency("Currency"),
29-
;
28+
Currency("Currency");
3029

3130
private final String value;
3231

33-
FormatType(String value) {
32+
FormatTypeEnum(String value) {
3433
this.value = value;
3534
}
3635

client/src/test/java/cn/vika/client/api/DatasheetOperationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import cn.vika.client.api.model.CreateDatasheetResponse;
99
import cn.vika.client.api.model.CreateFieldRequest;
1010
import cn.vika.client.api.model.builder.CreateFieldRequestBuilder;
11-
import cn.vika.client.api.model.field.FieldType;
11+
import cn.vika.client.api.model.field.FieldTypeEnum;
1212
import cn.vika.client.api.model.field.property.EmptyProperty;
1313
import cn.vika.client.api.model.field.property.SingleTextFieldProperty;
1414
import org.junit.jupiter.api.Test;
@@ -51,13 +51,13 @@ void testAddDatasheetWithOtherInfo() {
5151
property.setDefaultValue("default");
5252
CreateFieldRequest<SingleTextFieldProperty> singleSelectField = CreateFieldRequestBuilder
5353
.create()
54-
.ofType(FieldType.SingleText)
54+
.ofType(FieldTypeEnum.SingleText)
5555
.withName("singleSelect")
5656
.withProperty(property)
5757
.build();
5858
CreateFieldRequest<EmptyProperty> textField = CreateFieldRequestBuilder
5959
.create()
60-
.ofType(FieldType.Text)
60+
.ofType(FieldTypeEnum.Text)
6161
.withName("text")
6262
.withoutProperty()
6363
.build();

0 commit comments

Comments
 (0)