File tree 5 files changed +52
-42
lines changed
src/main/java/kitchenpos/product
5 files changed +52
-42
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import static com .google .common .base .Preconditions .checkArgument ;
4
4
5
+ import com .google .common .base .MoreObjects ;
5
6
import java .util .UUID ;
6
7
import kitchenpos .product .domain .ProductName ;
7
8
import kitchenpos .product .domain .ProductNew ;
@@ -20,4 +21,13 @@ public ProductDTO(final ProductNew entity) {
20
21
price = entity .getPrice ();
21
22
name = entity .getName ();
22
23
}
24
+
25
+ @ Override
26
+ public String toString () {
27
+ return MoreObjects .toStringHelper (this )
28
+ .add ("id" , id )
29
+ .add ("price" , price )
30
+ .add ("name" , name )
31
+ .toString ();
32
+ }
23
33
}
Original file line number Diff line number Diff line change @@ -15,10 +15,6 @@ public Name(final String value) {
15
15
this .value = value ;
16
16
}
17
17
18
- public String getValue () {
19
- return value ;
20
- }
21
-
22
18
@ Override
23
19
public boolean equals (final Object o ) {
24
20
if (this == o ) {
@@ -35,4 +31,8 @@ public boolean equals(final Object o) {
35
31
public int hashCode () {
36
32
return Objects .hashCode (value );
37
33
}
34
+
35
+ public String getValue () {
36
+ return value ;
37
+ }
38
38
}
Original file line number Diff line number Diff line change @@ -10,23 +10,27 @@ public class ProductName {
10
10
11
11
private String value ;
12
12
13
+ protected ProductName () {
14
+ }
15
+
16
+ private ProductName (final Name name ) {
17
+ this .value = name .getValue ();
18
+ }
19
+
13
20
public static ProductName of (final Name name ) {
14
21
checkArgument (name != null , "name must be not null. value: %s" , name );
15
22
16
23
return new ProductName (name );
17
24
}
18
25
19
- public ProductName () {
20
- }
21
-
22
26
@ Override
23
27
public boolean equals (final Object o ) {
24
- if (this == o ) {
25
- return true ;
26
- }
27
- if (o == null || getClass () != o .getClass ()) {
28
- return false ;
29
- }
28
+ if (this == o ) {
29
+ return true ;
30
+ }
31
+ if (o == null || getClass () != o .getClass ()) {
32
+ return false ;
33
+ }
30
34
final ProductName that = (ProductName ) o ;
31
35
return Objects .equal (value , that .value );
32
36
}
@@ -35,9 +39,4 @@ public boolean equals(final Object o) {
35
39
public int hashCode () {
36
40
return Objects .hashCode (value );
37
41
}
38
-
39
-
40
- private ProductName (final Name name ) {
41
- this .value = name .getValue ();
42
- }
43
42
}
Original file line number Diff line number Diff line change @@ -26,27 +26,24 @@ public class ProductNew {
26
26
@ AttributeOverride (name = "value" , column = @ Column (name = "price" ))
27
27
private ProductPrice price ;
28
28
29
- public static ProductNew newOf (final ProductName name , final ProductPrice price ) {
30
- return new ProductNew (UUID .randomUUID (), name , price );
31
- }
32
29
33
- public void changePrice (final ProductPrice price ) {
34
- this .price = price ;
30
+ protected ProductNew () {
35
31
}
36
32
37
-
38
- public UUID getId () {
39
- return id ;
33
+ private ProductNew (final UUID id , final ProductName name , final ProductPrice price ) {
34
+ this .id = id ;
35
+ this .name = name ;
36
+ this .price = price ;
40
37
}
41
38
42
- public ProductName getName ( ) {
43
- return name ;
39
+ public static ProductNew newOf ( final ProductName name , final ProductPrice price ) {
40
+ return new ProductNew ( UUID . randomUUID (), name , price ) ;
44
41
}
45
42
46
- public ProductPrice getPrice ( ) {
47
- return price ;
43
+ public void changePrice ( final ProductPrice price ) {
44
+ this . price = price ;
48
45
}
49
-
46
+
50
47
@ Override
51
48
public boolean equals (final Object o ) {
52
49
if (this == o ) {
@@ -64,12 +61,15 @@ public int hashCode() {
64
61
return Objects .hash (id );
65
62
}
66
63
67
- private ProductNew (final UUID id , final ProductName name , final ProductPrice price ) {
68
- this .id = id ;
69
- this .name = name ;
70
- this .price = price ;
64
+ public UUID getId () {
65
+ return id ;
66
+ }
67
+
68
+ public ProductName getName () {
69
+ return name ;
71
70
}
72
71
73
- public ProductNew () {
72
+ public ProductPrice getPrice () {
73
+ return price ;
74
74
}
75
75
}
Original file line number Diff line number Diff line change @@ -11,15 +11,19 @@ public class ProductPrice {
11
11
12
12
private long value ;
13
13
14
+ protected ProductPrice () {
15
+ }
16
+
17
+ private ProductPrice (final long value ) {
18
+ this .value = value ;
19
+ }
20
+
14
21
public static ProductPrice of (final long value ) {
15
22
checkArgument (value >= 0 , "price must be bigger than 0. value : %s" , value );
16
23
17
24
return new ProductPrice (value );
18
25
}
19
26
20
- public ProductPrice () {
21
- }
22
-
23
27
@ Override
24
28
public boolean equals (final Object o ) {
25
29
if (this == o ) {
@@ -37,7 +41,4 @@ public int hashCode() {
37
41
return Objects .hashCode (value );
38
42
}
39
43
40
- private ProductPrice (final long value ) {
41
- this .value = value ;
42
- }
43
44
}
You can’t perform that action at this time.
0 commit comments