Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
embulk-input-filename
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
embulk-input-filename
Commits
f83e6c97
Commit
f83e6c97
authored
Aug 14, 2017
by
yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sorter
parent
e20b5ac0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
34 deletions
+94
-34
src/main/java/org/embulk/input/filename/FilenameInputPlugin.java
...n/java/org/embulk/input/filename/FilenameInputPlugin.java
+94
-34
No files found.
src/main/java/org/embulk/input/filename/FilenameInputPlugin.java
View file @
f83e6c97
...
...
@@ -162,45 +162,32 @@ public class FilenameInputPlugin
// We have to sort the files before we set them to the tasks.
// Here we get the parameter about the order
Comparator
comparator
;
String
order
=
task
.
getLoadOrder
();
if
(
order
.
equals
(
""
)){
order
=
"ALPHABETICAL"
;}
switch
(
order
)
{
case
"ASCEND_MODIFIED"
:
comparator
=
AscendModifiedSorter
.
getComparator
();
break
;
case
"DESCEND_MODIFIED"
:
comparator
=
DescendModifiedSorter
.
getComparator
();
break
;
case
"ASCEND_CREATION"
:
comparator
=
AscendCreationSorter
.
getComparator
();
break
;
case
"DESCEND_CREATION"
:
comparator
=
DescendModifiedSorter
.
getComparator
();
break
;
default
:
comparator
=
new
Comparator
<
String
>();
break
;
}
// This method return the files in a directory,however the files in the varibale files is in random order. we have to sort them next
ArrayList
<
String
>
files
=
listFiles
(
task
,
Paths
.
get
(
dir
).
normalize
(),
lastPath
,
order
);
// Sort the files if each directory
if
(
order
.
equals
(
"ALPHABETICAL"
)){
Collections
.
sort
(
files
);
}
else
if
(
order
.
equals
(
"ASCEND_MODIFIED"
)
||
order
.
equals
(
"DESCEND_MODIFIED"
)){
Collections
.
sort
(
files
,
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
getLastModifiedTime
(
f1
).
compareTo
(
getLastModifiedTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
if
(
order
.
equals
(
"DESCEND_MODIFIED"
)){
Collections
.
reverse
(
files
);
}
}
else
if
(
order
.
equals
(
"ASCEND_CREATION"
)
||
order
.
equals
(
"DESCEND_CREATION"
)
){
Collections
.
sort
(
files
,
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
getCreationTime
(
f1
).
compareTo
(
getCreationTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
if
(
order
.
equals
(
"DESCEND_CREATION"
)
)
{
Collections
.
reverse
(
files
);}
}
else
{
throw
new
RuntimeException
(
"Input a correct order"
);
}
// Sort the files for each directory
Collections
.
sort
(
files
,
comparator
);
// End of sort
...
...
@@ -398,3 +385,76 @@ public class FilenameInputPlugin
return
fileTime
;
}
}
interface
Sorter
{
public
static
Comparator
getComparator
();
}
class
AscendModifiedSorter
implements
Sorter
{
public
static
Comparator
getComparator
(){
return
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
getLastModifiedTime
(
f1
).
compareTo
(
getLastModifiedTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
}
}
class
AscendCreationSorter
implements
Sorter
{
public
static
Comparator
getComparator
(){
return
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
getCreationTime
(
f1
).
compareTo
(
getCreationTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
}
}
class
DescendModifiedSorter
implements
Sorter
{
public
static
Comparator
getComparator
(){
return
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
-
getLastModifiedTime
(
f1
).
compareTo
(
getLastModifiedTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
}
}
class
DescendCreationSorter
implements
Sorter
{
public
static
Comparator
getComparator
(){
return
new
Comparator
<
String
>(){
@Override
public
int
compare
(
String
f1
,
String
f2
)
{
try
{
return
-
getCreationTime
(
f1
).
compareTo
(
getCreationTime
(
f2
));
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
return
0
;
}
});
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment