15
15
16
16
package software .amazon .awssdk .enhanced .dynamodb .internal .converter ;
17
17
18
+ import java .time .LocalDate ;
19
+ import java .time .LocalDateTime ;
20
+ import java .time .LocalTime ;
18
21
import software .amazon .awssdk .annotations .SdkInternalApi ;
19
22
import software .amazon .awssdk .enhanced .dynamodb .AttributeConverter ;
20
23
import software .amazon .awssdk .enhanced .dynamodb .internal .converter .attribute .DoubleAttributeConverter ;
@@ -49,10 +52,6 @@ public static void validateFloat(Float input) {
49
52
Validate .isTrue (Float .isFinite (input ), "Infinite numbers are not supported by the default converters." );
50
53
}
51
54
52
- public static String padLeft2 (int valueToPad ) {
53
- return valueToPad > 10 ? Integer .toString (valueToPad ) : "0" + valueToPad ;
54
- }
55
-
56
55
public static String padLeft (int paddingAmount , int valueToPad ) {
57
56
String value = Integer .toString (valueToPad );
58
57
int padding = paddingAmount - value .length ();
@@ -64,60 +63,6 @@ public static String padLeft(int paddingAmount, int valueToPad) {
64
63
return result .toString ();
65
64
}
66
65
67
- public static String padRight (int paddingAmount , String valueToPad ) {
68
- StringBuilder result = new StringBuilder (paddingAmount );
69
- result .append (valueToPad );
70
- for (int i = result .length (); i < paddingAmount ; i ++) {
71
- result .append ('0' );
72
- }
73
- return result .toString ();
74
- }
75
-
76
- public static String trimNumber (String number ) {
77
- int startInclusive = findTrimInclusiveStart (number , '0' , 0 );
78
-
79
- if (startInclusive >= number .length ()) {
80
- return "0" ;
81
- }
82
-
83
- if (!number .contains ("." )) {
84
- return number .substring (startInclusive );
85
- }
86
-
87
- int endExclusive = findTrimExclusiveEnd (number , '0' , number .length ());
88
- endExclusive = findTrimExclusiveEnd (number , '.' , endExclusive );
89
-
90
- if (startInclusive >= endExclusive ) {
91
- return "0" ;
92
- }
93
-
94
- String result = number .substring (startInclusive , endExclusive );
95
- if (result .startsWith ("." )) {
96
- return "0" + result ;
97
- }
98
- return result ;
99
- }
100
-
101
- private static int findTrimInclusiveStart (String string , char characterToTrim , int startingIndex ) {
102
- int startInclusive = startingIndex ;
103
-
104
- while (startInclusive < string .length () && string .charAt (startInclusive ) == characterToTrim ) {
105
- ++startInclusive ;
106
- }
107
-
108
- return startInclusive ;
109
- }
110
-
111
- private static int findTrimExclusiveEnd (String string , char characterToTrim , int startingIndex ) {
112
- int endExclusive = startingIndex ;
113
-
114
- while (endExclusive > 0 && string .charAt (endExclusive - 1 ) == characterToTrim ) {
115
- --endExclusive ;
116
- }
117
-
118
- return endExclusive ;
119
- }
120
-
121
66
public static String [] splitNumberOnDecimal (String valueToSplit ) {
122
67
int i = valueToSplit .indexOf ('.' );
123
68
if (i == -1 ) {
@@ -128,55 +73,8 @@ public static String[] splitNumberOnDecimal(String valueToSplit) {
128
73
}
129
74
}
130
75
131
- public static String [] chunk (String valueToChunk , int ... splitSizes ) {
132
- String [] result = new String [splitSizes .length + 1 ];
133
- int splitStartInclusive = chunkLeft (valueToChunk , result , splitSizes );
134
-
135
- Validate .isTrue (splitStartInclusive == valueToChunk .length (), "Value size does not match expected chunking scheme." );
136
-
137
- return result ;
138
- }
139
-
140
- public static String [] chunkWithRightOverflow (String valueToChunk , int ... splitSizesFromLeft ) {
141
- String [] result = new String [splitSizesFromLeft .length + 1 ];
142
- int splitStartInclusive = chunkLeft (valueToChunk , result , splitSizesFromLeft );
143
-
144
- result [splitSizesFromLeft .length ] = valueToChunk .substring (splitStartInclusive );
145
-
146
- return result ;
76
+ public static LocalDateTime convertFromLocalDate (LocalDate localDate ) {
77
+ return LocalDateTime .of (localDate , LocalTime .MIDNIGHT );
147
78
}
148
79
149
- public static String [] chunkWithLeftOverflow (String valueToChunk , int ... splitSizesFromRight ) {
150
- try {
151
- String [] result = new String [splitSizesFromRight .length + 1 ];
152
- int splitEndExclusive = valueToChunk .length ();
153
-
154
- for (int i = splitSizesFromRight .length - 1 ; i >= 0 ; i --) {
155
- int splitStartInclusive = splitEndExclusive - splitSizesFromRight [i ];
156
- result [i + 1 ] = valueToChunk .substring (splitStartInclusive , splitEndExclusive );
157
- splitEndExclusive = splitStartInclusive ;
158
- }
159
-
160
- result [0 ] = valueToChunk .substring (0 , splitEndExclusive );
161
-
162
- return result ;
163
- } catch (StringIndexOutOfBoundsException e ) {
164
- throw new IllegalArgumentException ("Invalid format for value." , e );
165
- }
166
- }
167
-
168
- private static int chunkLeft (String valueToChunk , String [] result , int [] splitSizes ) {
169
- try {
170
- int splitStartInclusive = 0 ;
171
-
172
- for (int i = 0 ; i < splitSizes .length ; i ++) {
173
- int splitEndExclusive = splitStartInclusive + splitSizes [i ];
174
- result [i ] = valueToChunk .substring (splitStartInclusive , splitEndExclusive );
175
- splitStartInclusive = splitEndExclusive ;
176
- }
177
- return splitStartInclusive ;
178
- } catch (StringIndexOutOfBoundsException e ) {
179
- throw new IllegalArgumentException ("Invalid format for value." , e );
180
- }
181
- }
182
80
}
0 commit comments