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
d971b564
Commit
d971b564
authored
4 years ago
by
Vojtěch Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Make decompressInMemory return Optional<T> instead of maybe null.
parent
01d5185f
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/azgracompress/benchmark/Benchmark.java
+4
-3
4 additions, 3 deletions
src/main/java/azgracompress/benchmark/Benchmark.java
src/main/java/azgracompress/compression/ImageDecompressor.java
+8
-7
8 additions, 7 deletions
...ain/java/azgracompress/compression/ImageDecompressor.java
with
12 additions
and
10 deletions
src/main/java/azgracompress/benchmark/Benchmark.java
+
4
−
3
View file @
d971b564
...
...
@@ -14,6 +14,7 @@ import azgracompress.utilities.Utils;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Optional
;
public
class
Benchmark
extends
BenchmarkBase
{
...
...
@@ -59,8 +60,8 @@ public class Benchmark extends BenchmarkBase {
decompressOps
.
setOutputFilePath
(
decompressedFile
);
ImageDecompressor
decompressor
=
new
ImageDecompressor
(
decompressOps
);
final
ImageU16Dataset
decompressed
Dataset
=
decompressor
.
decompressInMemory
();
if
(
decompressedDataset
==
null
)
{
final
Optional
<
ImageU16Dataset
>
maybe
Dataset
=
decompressor
.
decompressInMemory
();
if
(
!
maybeDataset
.
isPresent
()
)
{
System
.
err
.
println
(
"Errors occurred during decompression."
);
return
;
}
...
...
@@ -75,7 +76,7 @@ public class Benchmark extends BenchmarkBase {
return
;
}
final
int
[]
quantizedData
=
TypeConverter
.
shortArrayToIntArray
(
decompressed
Dataset
.
getPlaneData
(
0
));
final
int
[]
quantizedData
=
TypeConverter
.
shortArrayToIntArray
(
maybe
Dataset
.
get
().
getPlaneData
(
0
));
final
int
[]
diffArray
=
Utils
.
getDifference
(
originalData
,
quantizedData
);
final
double
mse
=
Utils
.
calculateMse
(
diffArray
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/azgracompress/compression/ImageDecompressor.java
+
8
−
7
View file @
d971b564
...
...
@@ -8,6 +8,7 @@ import azgracompress.utilities.Stopwatch;
import
org.jetbrains.annotations.Nullable
;
import
java.io.*
;
import
java.util.Optional
;
@SuppressWarnings
(
"DuplicatedCode"
)
...
...
@@ -233,22 +234,22 @@ public class ImageDecompressor extends CompressorDecompressorBase {
}
// TODO(Moravec): Return optional to get rid of null check.
public
ImageU16Dataset
decompressInMemory
()
{
public
Optional
<
ImageU16Dataset
>
decompressInMemory
()
{
try
(
FileInputStream
fileInputStream
=
new
FileInputStream
(
options
.
getInputDataInfo
().
getFilePath
());
DataInputStream
dataInputStream
=
new
DataInputStream
(
fileInputStream
))
{
final
QCMPFileHeader
header
=
decompressQcmpHeader
(
dataInputStream
);
if
(
header
==
null
)
return
null
;
return
Optional
.
empty
()
;
IImageDecompressor
imageDecompressor
=
getImageDecompressor
(
header
);
if
(
imageDecompressor
==
null
)
{
System
.
err
.
println
(
"Unable to create correct decompressor."
);
return
null
;
return
Optional
.
empty
()
;
}
if
(!
checkInputFileSize
(
header
,
imageDecompressor
))
{
return
null
;
return
Optional
.
empty
()
;
}
final
int
planePixelCount
=
header
.
getImageSizeX
()
*
header
.
getImageSizeY
();
...
...
@@ -259,14 +260,14 @@ public class ImageDecompressor extends CompressorDecompressorBase {
imageDecompressor
.
decompressToBuffer
(
dataInputStream
,
decompressedData
,
header
);
}
catch
(
ImageDecompressionException
ex
)
{
System
.
err
.
println
(
ex
.
getMessage
());
return
null
;
return
Optional
.
empty
()
;
}
return
new
ImageU16Dataset
(
header
.
getImageDims
().
toV2i
(),
header
.
getImageSizeZ
(),
decompressedData
);
return
Optional
.
of
(
new
ImageU16Dataset
(
header
.
getImageDims
().
toV2i
(),
header
.
getImageSizeZ
(),
decompressedData
)
)
;
}
catch
(
IOException
ioEx
)
{
ioEx
.
printStackTrace
();
return
null
;
return
Optional
.
empty
()
;
}
}
...
...
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