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
577f01a2
Commit
577f01a2
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
HyperStackDimensions parsing util.
parent
d2e7c11a
No related branches found
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/cz/it4i/qcmp/cli/ParseUtils.java
+66
-0
66 additions, 0 deletions
src/main/java/cz/it4i/qcmp/cli/ParseUtils.java
src/main/java/cz/it4i/qcmp/data/HyperStackDimensions.java
+5
-0
5 additions, 0 deletions
src/main/java/cz/it4i/qcmp/data/HyperStackDimensions.java
with
71 additions
and
0 deletions
src/main/java/cz/it4i/qcmp/cli/ParseUtils.java
+
66
−
0
View file @
577f01a2
package
cz.it4i.qcmp.cli
;
package
cz.it4i.qcmp.cli
;
import
cz.it4i.qcmp.data.HyperStackDimensions
;
import
cz.it4i.qcmp.data.Range
;
import
cz.it4i.qcmp.data.Range
;
import
cz.it4i.qcmp.data.V2i
;
import
cz.it4i.qcmp.data.V2i
;
import
cz.it4i.qcmp.data.V3i
;
import
cz.it4i.qcmp.data.V3i
;
import
java.util.ArrayList
;
import
java.util.Optional
;
import
java.util.Optional
;
public
abstract
class
ParseUtils
{
public
abstract
class
ParseUtils
{
...
@@ -95,4 +97,68 @@ public abstract class ParseUtils {
...
@@ -95,4 +97,68 @@ public abstract class ParseUtils {
}
}
return
Optional
.
empty
();
return
Optional
.
empty
();
}
}
/**
* Find all occurrences of c in string.
*
* @param string String to look for c in.
* @param c Characted to find in the string.
* @return Array of all indexes in the string.
*/
private
static
int
[]
findAllIndexesOfChar
(
final
String
string
,
final
char
c
)
{
final
ArrayList
<
Integer
>
indexes
=
new
ArrayList
<>(
2
);
int
index
=
string
.
indexOf
(
c
);
while
(
index
>=
0
)
{
indexes
.
add
(
index
);
index
=
string
.
indexOf
(
c
,
index
+
1
);
}
return
indexes
.
stream
().
mapToInt
(
Integer:
:
intValue
).
toArray
();
}
/**
* Tries to parse HyperStackDimensions from a string with delimiters.
*
* @param hyperStackDimensionsString String containing the dimensions.
* @param delimiter Delimiter.
* @return Parsed HyperStackDimensions or empty optional.
*/
public
static
Optional
<
HyperStackDimensions
>
tryParseHyperStackDimensions
(
final
String
hyperStackDimensionsString
,
final
char
delimiter
)
{
final
String
string
=
(
delimiter
!=
' '
)
?
removeSpacesInString
(
hyperStackDimensionsString
)
:
hyperStackDimensionsString
;
final
int
[]
indexes
=
findAllIndexesOfChar
(
string
,
delimiter
);
if
((
indexes
.
length
<
1
)
||
(
indexes
.
length
>
3
))
return
Optional
.
empty
();
int
x
=
-
1
;
int
y
=
-
1
;
int
z
=
1
;
int
t
=
1
;
// Required part.
final
Optional
<
Integer
>
maybeX
=
tryParseInt
(
string
.
substring
(
0
,
indexes
[
0
]));
final
Optional
<
Integer
>
maybeY
=
tryParseInt
(
string
.
substring
(
indexes
[
0
]
+
1
,
indexes
.
length
>
1
?
indexes
[
1
]
:
string
.
length
()));
if
(!
maybeX
.
isPresent
()
||
!
maybeY
.
isPresent
())
return
Optional
.
empty
();
x
=
maybeX
.
get
();
y
=
maybeY
.
get
();
if
(
indexes
.
length
>
1
)
{
final
Optional
<
Integer
>
maybeZ
=
tryParseInt
(
string
.
substring
(
indexes
[
1
],
indexes
.
length
>
2
?
indexes
[
2
]
:
string
.
length
()));
if
(!
maybeZ
.
isPresent
())
return
Optional
.
empty
();
z
=
maybeZ
.
get
();
if
(
indexes
.
length
>
2
)
{
final
Optional
<
Integer
>
maybeT
=
tryParseInt
(
string
.
substring
(
indexes
[
2
]));
if
(!
maybeT
.
isPresent
())
return
Optional
.
empty
();
t
=
maybeT
.
get
();
}
}
return
Optional
.
of
(
new
HyperStackDimensions
(
x
,
y
,
z
,
t
));
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/cz/it4i/qcmp/data/HyperStackDimensions.java
+
5
−
0
View file @
577f01a2
...
@@ -82,4 +82,9 @@ public class HyperStackDimensions {
...
@@ -82,4 +82,9 @@ public class HyperStackDimensions {
public
final
int
getNumberOfTimepoints
()
{
public
final
int
getNumberOfTimepoints
()
{
return
numberOfTimepoints
;
return
numberOfTimepoints
;
}
}
@Override
public
String
toString
()
{
return
String
.
format
(
"X=%d;Y=%d;Z=%d;T=%d"
,
width
,
height
,
sliceCount
,
numberOfTimepoints
);
}
}
}
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