Skip to content

Commit 2726c2e

Browse files
committed
Changes made
1 parent f2b6111 commit 2726c2e

8 files changed

Lines changed: 919 additions & 559 deletions

File tree

README.md

Lines changed: 203 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © 2025 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
// --- File: ByteSize.java ---
17+
package io.cdap.wrangler.api.parser;
18+
19+
import com.google.gson.JsonElement;
20+
import com.google.gson.JsonPrimitive;
21+
22+
/**
23+
* Token representing a byte size value (e.g., "10KB", "2.5MB").
24+
*/
25+
public class ByteSize implements Token {
26+
private final long bytes;
27+
28+
public ByteSize(String value) {
29+
String unit = value.replaceAll("[0-9.]", "").toUpperCase();
30+
double number = Double.parseDouble(value.replaceAll("[^0-9.]", ""));
31+
switch (unit) {
32+
case "KB": this.bytes = (long) (number * 1024); break;
33+
case "MB": this.bytes = (long) (number * 1024 * 1024); break;
34+
case "GB": this.bytes = (long) (number * 1024 * 1024 * 1024); break;
35+
default: this.bytes = (long) number; break;
36+
}
37+
}
38+
39+
public long getBytes() {
40+
return this.bytes;
41+
}
42+
43+
@Override
44+
public Object value() {
45+
return bytes;
46+
}
47+
48+
@Override
49+
public TokenType type() {
50+
return TokenType.BYTE_SIZE;
51+
}
52+
53+
@Override
54+
public JsonElement toJson() {
55+
return new JsonPrimitive(bytes);
56+
}
57+
}
58+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright © 2025 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
18+
// --- File: TimeDuration.java ---
19+
package io.cdap.wrangler.api.parser;
20+
21+
import com.google.gson.JsonElement;
22+
import com.google.gson.JsonPrimitive;
23+
24+
/**
25+
* Token representing a time duration value (e.g., "150ms", "2.5s").
26+
*/
27+
public class TimeDuration implements Token {
28+
private final long milliseconds;
29+
30+
public TimeDuration(String value) {
31+
String unit = value.replaceAll("[0-9.]", "").toLowerCase();
32+
double number = Double.parseDouble(value.replaceAll("[^0-9.]", ""));
33+
switch (unit) {
34+
case "s": this.milliseconds = (long) (number * 1000); break;
35+
case "ms": this.milliseconds = (long) (number); break;
36+
case "min": this.milliseconds = (long) (number * 60000); break;
37+
default: this.milliseconds = (long) number; break;
38+
}
39+
}
40+
41+
public long getMilliseconds() {
42+
return milliseconds;
43+
}
44+
45+
@Override
46+
public Object value() {
47+
return milliseconds;
48+
}
49+
50+
@Override
51+
public TokenType type() {
52+
return TokenType.TIME_DURATION;
53+
}
54+
55+
@Override
56+
public JsonElement toJson() {
57+
return new JsonPrimitive(milliseconds);
58+
}
59+
}
60+
61+

wrangler-api/src/main/java/io/cdap/wrangler/api/parser/Token.java

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@
1414
* the License.
1515
*/
1616

17-
package io.cdap.wrangler.api.parser;
17+
package io.cdap.wrangler.api.parser;
1818

19-
import com.google.gson.JsonElement;
20-
import io.cdap.wrangler.api.annotations.PublicEvolving;
21-
22-
import java.io.Serializable;
23-
24-
/**
25-
* The Token class represents the object that contains the value and type of
26-
* the token as parsed by the parser of the grammar defined for recipe.
27-
*
28-
* <p>This class provides methods for retrieving the wrapped value of token parsed
29-
* as well the type of token the implementation of this interface represents.</p>
30-
*
31-
* <p>It also provides method for providing the {@code JsonElement} of implementation
32-
* of this interface.</p>
33-
*/
34-
@PublicEvolving
35-
public interface Token extends Serializable {
36-
/**
37-
* Returns the {@code value} of the object wrapped by the
38-
* implementation of this interface.
39-
*
40-
* @return {@code value} wrapped by the implementation of this interface.
41-
*/
42-
Object value();
43-
44-
/**
45-
* Returns the {@code TokenType} of the object represented by the
46-
* implementation of this interface.
47-
*
48-
* @return {@code TokenType} of the implementation object.
49-
*/
50-
TokenType type();
51-
52-
/**
53-
* The class implementing this interface will return the {@code JsonElement}
54-
* instance including the values of the object.
55-
*
56-
* @return {@code JsonElement} object containing members of implementing class.
57-
*/
58-
JsonElement toJson();
59-
}
19+
import com.google.gson.JsonElement;
20+
import io.cdap.wrangler.api.annotations.PublicEvolving;
21+
22+
import java.io.Serializable;
23+
24+
/**
25+
* The Token class represents the object that contains the value and type of
26+
* the token as parsed by the parser of the grammar defined for recipe.
27+
*
28+
* <p>This class provides methods for retrieving the wrapped value of token parsed
29+
* as well the type of token the implementation of this interface represents.</p>
30+
*
31+
* <p>It also provides method for providing the {@code JsonElement} of implementation
32+
* of this interface.</p>
33+
*/
34+
@PublicEvolving
35+
public interface Token extends Serializable {
36+
/**
37+
* Returns the {@code value} of the object wrapped by the
38+
* implementation of this interface.
39+
*
40+
* @return {@code value} wrapped by the implementation of this interface.
41+
*/
42+
Object value();
43+
44+
/**
45+
* Returns the {@code TokenType} of the object represented by the
46+
* implementation of this interface.
47+
*
48+
* @return {@code TokenType} of the implementation object.
49+
*/
50+
TokenType type();
51+
52+
/**
53+
* The class implementing this interface will return the {@code JsonElement}
54+
* instance including the values of the object.
55+
*
56+
* @return {@code JsonElement} object containing members of implementing class.
57+
*/
58+
JsonElement toJson();
59+
}
60+

0 commit comments

Comments
 (0)