Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QcmpCompressionLibrary
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
QcmpCompressionLibrary
Commits
20fe954f
Commit
20fe954f
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Use new tryParseRange instead of ad-hoc code in CLI parsing.
parent
32ccb963
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/azgracompress/cli/ParseUtils.java
+33
-3
33 additions, 3 deletions
src/main/java/azgracompress/cli/ParseUtils.java
src/main/java/azgracompress/cli/ParsedCliOptions.java
+7
-59
7 additions, 59 deletions
src/main/java/azgracompress/cli/ParsedCliOptions.java
with
40 additions
and
62 deletions
src/main/java/azgracompress/cli/ParseUtils.java
+
33
−
3
View file @
20fe954f
package
azgracompress.cli
;
package
azgracompress.cli
;
import
azgracompress.compression.Range
;
import
azgracompress.data.V3i
;
import
azgracompress.data.V3i
;
import
java.util.Optional
;
import
java.util.Optional
;
public
abstract
class
ParseUtils
{
public
abstract
class
ParseUtils
{
private
static
String
removeSpacesInString
(
final
String
string
)
{
return
string
.
replaceAll
(
"\\s"
,
""
);
}
/**
/**
* Try to parse int from string.
* Try to parse int from string.
*
*
...
@@ -19,14 +25,38 @@ public abstract class ParseUtils {
...
@@ -19,14 +25,38 @@ public abstract class ParseUtils {
}
}
}
}
/**
* Try to parse integer range from string.
*
* @param rangeString Range string.
* @param delimiter Delimiter between numbers.
* @return Optional parsed range.
*/
public
static
Optional
<
Range
<
Integer
>>
tryParseRange
(
final
String
rangeString
,
final
char
delimiter
)
{
final
String
string
=
removeSpacesInString
(
rangeString
);
final
int
delimiterIndex
=
string
.
indexOf
(
delimiter
);
if
(
delimiterIndex
==
-
1
)
{
return
Optional
.
empty
();
}
final
Optional
<
Integer
>
maybeFrom
=
tryParseInt
(
string
.
substring
(
0
,
delimiterIndex
));
final
Optional
<
Integer
>
maybeTo
=
tryParseInt
(
string
.
substring
(
delimiterIndex
+
1
));
if
(
maybeFrom
.
isPresent
()
&&
maybeTo
.
isPresent
())
{
return
Optional
.
of
(
new
Range
<>(
maybeFrom
.
get
(),
maybeTo
.
get
()));
}
return
Optional
.
empty
();
}
/**
/**
* Try to parse 3 dimensional vector from string.
* Try to parse 3 dimensional vector from string.
*
*
* @param
s
tring
Vector string.
* @param
v3iS
tring Vector string.
* @param delimiter Delimiter between numbers.
* @param delimiter Delimiter between numbers.
* @return Optional parse
result
.
* @return Optional parse
d vector
.
*/
*/
public
static
Optional
<
V3i
>
tryParseV3i
(
final
String
string
,
final
char
delimiter
)
{
public
static
Optional
<
V3i
>
tryParseV3i
(
final
String
v3iString
,
final
char
delimiter
)
{
final
String
string
=
removeSpacesInString
(
v3iString
);
final
int
firstDelimiterIndex
=
string
.
indexOf
(
delimiter
);
final
int
firstDelimiterIndex
=
string
.
indexOf
(
delimiter
);
if
(
firstDelimiterIndex
==
-
1
)
{
if
(
firstDelimiterIndex
==
-
1
)
{
return
Optional
.
empty
();
return
Optional
.
empty
();
...
...
This diff is collapsed.
Click to expand it.
src/main/java/azgracompress/cli/ParsedCliOptions.java
+
7
−
59
View file @
20fe954f
...
@@ -298,21 +298,16 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
...
@@ -298,21 +298,16 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
final
int
inputFileArgumentsOffset
)
{
final
int
inputFileArgumentsOffset
)
{
int
rangeSeparatorIndex
=
inputFileArguments
[
inputFileArgumentsOffset
].
indexOf
(
"-"
);
int
rangeSeparatorIndex
=
inputFileArguments
[
inputFileArgumentsOffset
].
indexOf
(
"-"
);
if
(
rangeSeparatorIndex
!=
-
1
)
{
if
(
rangeSeparatorIndex
!=
-
1
)
{
// Here we parse the plane range option.
final
String
fromIndexString
=
inputFileArguments
[
inputFileArgumentsOffset
].
substring
(
0
,
rangeSeparatorIndex
);
final
String
toIndexString
=
inputFileArguments
[
inputFileArgumentsOffset
].
substring
(
rangeSeparatorIndex
+
1
);
final
Optional
<
Integer
>
indexFromResult
=
ParseUtils
.
tryParseInt
(
fromIndexString
);
Optional
<
Range
<
Integer
>
>
parsedRange
=
final
Optional
<
Integer
>
indexToResult
=
ParseUtils
.
tryParseInt
(
toIndexString
);
ParseUtils
.
tryParseRange
(
inputFileArguments
[
inputFileArgumentsOffset
],
'-'
);
if
(
indexFromResult
.
isPresent
()
&&
indexToResult
.
isPresent
())
{
if
(!
parsedRange
.
isPresent
())
{
getInputDataInfo
().
setPlaneRange
(
new
Range
<>(
indexFromResult
.
get
(),
indexToResult
.
get
()));
}
else
{
parseErrorOccurred
=
true
;
parseErrorOccurred
=
true
;
errorBuilder
.
append
(
"Plane range index is wrong. Expected format D-D, got: "
).
append
(
errorBuilder
.
append
(
"Plane range index is wrong. Expected format D-D, got: "
)
inputFileArguments
[
inputFileArgumentsOffset
]).
append
(
'\n'
);
.
append
(
inputFileArguments
[
inputFileArgumentsOffset
]).
append
(
'\n'
);
}
else
{
getInputDataInfo
().
setPlaneRange
(
parsedRange
.
get
());
}
}
}
else
{
}
else
{
// Here we parse single plane index option.
// Here we parse single plane index option.
...
@@ -328,53 +323,6 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
...
@@ -328,53 +323,6 @@ public class ParsedCliOptions extends CompressionOptions implements Cloneable {
}
}
}
}
// /**
// * Parse image dimensions from the command line.
// *
// * @param dimsString Dimensions string.
// * @param errorBuilder String error builder.
// */
// private V3i parseV3i(final String dimsString, StringBuilder errorBuilder) {
// // We thing of 3x3x1 and 3x3 as the same thing
//
// final int firstDelimiterIndex = dimsString.indexOf('x');
// if (firstDelimiterIndex == -1) {
// parseErrorOccurred = true;
// errorBuilder.append("Error parsing image dimensions. We require DxDxD or DxD [=DxDx1]\n");
// return;
// }
// final String num1String = dimsString.substring(0, firstDelimiterIndex);
// final String secondPart = dimsString.substring(firstDelimiterIndex + 1);
//
// final int secondDelimiterIndex = secondPart.indexOf('x');
// if (secondDelimiterIndex == -1) {
// final Optional<Integer> n1Result = ParseUtils.tryParseInt(num1String);
// final Optional<Integer> n2Result = ParseUtils.tryParseInt(secondPart);
// if (n1Result.isPresent() && n2Result.isPresent()) {
// getInputDataInfo().setDimension(new V3i(n1Result.get(), n2Result.get(), 1));
// } else {
// parseErrorOccurred = true;
// errorBuilder.append(String.format("%sx%s\n", num1String, secondPart));
// }
// } else {
// final String num2String = secondPart.substring(0, secondDelimiterIndex);
// final String num3String = secondPart.substring(secondDelimiterIndex + 1);
//
// final Optional<Integer> n1Result = ParseUtils.tryParseInt(num1String);
// final Optional<Integer> n2Result = ParseUtils.tryParseInt(num2String);
// final Optional<Integer> n3Result = ParseUtils.tryParseInt(num3String);
//
// if (n1Result.isPresent() && n2Result.isPresent() && n3Result.isPresent()) {
// getInputDataInfo().setDimension(new V3i(n1Result.get(), n2Result.get(), n3Result.get()));
// } else {
// parseErrorOccurred = true;
// errorBuilder.append("Failed to parse image dimensions of format DxDxD, got: ");
// errorBuilder.append(String.format("%sx%sx%s\n", num1String, num2String, num3String));
// }
// }
// }
/**
/**
* Parse bits per codebook index.
* Parse bits per codebook index.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment