Skip to content

Commit fe7b6fc

Browse files
authored
Merge pull request #308 from rpmoore/iter-helpers-improvement
Changed the way that filters can be applied to the fluentiterable
2 parents 351bc5c + d09ed92 commit fe7b6fc

File tree

3 files changed

+51
-50
lines changed

3 files changed

+51
-50
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
allprojects {
1717
group = 'com.spectralogic.ds3'
18-
version = '3.0.6-SNAPSHOT'
18+
version = '3.0.6'
1919
}
2020

2121
subprojects {

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpers.java

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package com.spectralogic.ds3client.helpers;
1717

18+
import com.google.common.base.Function;
19+
import com.google.common.collect.FluentIterable;
1820
import com.spectralogic.ds3client.Ds3Client;
1921
import com.spectralogic.ds3client.helpers.options.ReadJobOptions;
2022
import com.spectralogic.ds3client.helpers.options.WriteJobOptions;
@@ -23,6 +25,7 @@
2325
import com.spectralogic.ds3client.serializer.XmlProcessingException;
2426
import com.spectralogic.ds3client.utils.Predicate;
2527

28+
import javax.annotation.Nullable;
2629
import java.io.IOException;
2730
import java.nio.channels.SeekableByteChannel;
2831
import java.nio.file.Path;
@@ -100,8 +103,8 @@ public static Ds3ClientHelpers wrap(final Ds3Client client, final int retryAfter
100103
}
101104

102105
/**
103-
* Performs a bulk put job creation request and returns an {@link WriteJob}.
104-
* See {@link WriteJob} for information on how to write the objects for the job.
106+
* Performs a bulk put job creation request and returns an {@link WriteJobImpl}.
107+
* See {@link WriteJobImpl} for information on how to write the objects for the job.
105108
*
106109
* @throws SignatureException
107110
* @throws IOException
@@ -111,8 +114,8 @@ public abstract Ds3ClientHelpers.Job startWriteJob(final String bucket, final It
111114
throws SignatureException, IOException, XmlProcessingException;
112115

113116
/**
114-
* Performs a bulk put job creation request and returns an {@link WriteJob}.
115-
* See {@link WriteJob} for information on how to write the objects for the job.
117+
* Performs a bulk put job creation request and returns an {@link WriteJobImpl}.
118+
* See {@link WriteJobImpl} for information on how to write the objects for the job.
116119
*
117120
* @throws SignatureException
118121
* @throws IOException
@@ -122,8 +125,8 @@ public abstract Ds3ClientHelpers.Job startWriteJob(final String bucket, final It
122125
throws SignatureException, IOException, XmlProcessingException;
123126

124127
/**
125-
* Performs a bulk get job creation request and returns an {@link ReadJob}.
126-
* See {@link ReadJob} for information on how to read the objects for the job.
128+
* Performs a bulk get job creation request and returns an {@link ReadJobImpl}.
129+
* See {@link ReadJobImpl} for information on how to read the objects for the job.
127130
*
128131
* @throws SignatureException
129132
* @throws IOException
@@ -133,8 +136,8 @@ public abstract Ds3ClientHelpers.Job startReadJob(final String bucket, final Ite
133136
throws SignatureException, IOException, XmlProcessingException;
134137

135138
/**
136-
* Performs a bulk get job creation request and returns an {@link ReadJob}.
137-
* See {@link ReadJob} for information on how to read the objects for the job.
139+
* Performs a bulk get job creation request and returns an {@link ReadJobImpl}.
140+
* See {@link ReadJobImpl} for information on how to read the objects for the job.
138141
*
139142
* @throws SignatureException
140143
* @throws IOException
@@ -147,7 +150,7 @@ public abstract Ds3ClientHelpers.Job startReadJob(
147150
throws SignatureException, IOException, XmlProcessingException;
148151

149152
/**
150-
* Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJob}.
153+
* Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJobImpl}.
151154
*
152155
* @throws SignatureException
153156
* @throws IOException
@@ -157,7 +160,7 @@ public abstract Ds3ClientHelpers.Job startReadAllJob(final String bucket)
157160
throws SignatureException, IOException, XmlProcessingException;
158161

159162
/**
160-
* Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJob}.
163+
* Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJobImpl}.
161164
*
162165
* @throws SignatureException
163166
* @throws IOException
@@ -167,7 +170,7 @@ public abstract Ds3ClientHelpers.Job startReadAllJob(final String bucket, final
167170
throws SignatureException, IOException, XmlProcessingException;
168171

169172
/**
170-
* Queries job information based on job id and returns a {@link ReadJob} that can resume the job.
173+
* Queries job information based on job id and returns a {@link ReadJobImpl} that can resume the job.
171174
* @throws SignatureException
172175
* @throws IOException
173176
* @throws XmlProcessingException
@@ -177,7 +180,7 @@ public abstract Ds3ClientHelpers.Job recoverWriteJob(final UUID jobId)
177180
throws SignatureException, IOException, XmlProcessingException, JobRecoveryException;
178181

179182
/**
180-
* Queries job information based on job id and returns a {@link WriteJob} that can resume the job.
183+
* Queries job information based on job id and returns a {@link WriteJobImpl} that can resume the job.
181184
* @throws SignatureException
182185
* @throws IOException
183186
* @throws XmlProcessingException
@@ -265,7 +268,7 @@ public abstract Iterable<Contents> listObjects(final String bucket, final String
265268

266269

267270
/**
268-
* Returns an object list with which you can call {@code startWriteJob} based on the files in a {@code directory}.
271+
* Returns an object list with which you can call {@code startWriteJobImpl} based on the files in a {@code directory}.
269272
* This method traverses the {@code directory} recursively.
270273
*
271274
* @throws IOException
@@ -288,14 +291,41 @@ public abstract Iterable<Contents> listObjects(final String bucket, final String
288291
*/
289292
public abstract Iterable<Ds3Object> removePrefixFromDs3ObjectsList(final Iterable<Ds3Object> objectsList, final String prefix);
290293

291-
/**
292-
* Filter out folders from the object list. Use this method when piping the list of objects from listObjects to a bulk job.
293-
* @param objects
294-
* @return
295-
*/
296-
public abstract Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects);
294+
public Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects) {
295+
return toDs3Iterable(objects, null);
296+
}
297297

298-
public abstract Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final Predicate<Contents> filter);
298+
@SafeVarargs
299+
public final Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final Predicate<Contents>... filters) {
300+
301+
FluentIterable<Contents> fluentIterable = FluentIterable.from(objects).filter(new com.google.common.base.Predicate<Contents>() {
302+
@Override
303+
public boolean apply(@Nullable final Contents input) {
304+
return input != null;
305+
}
306+
});
307+
308+
for (final Predicate<Contents> filter : filters) {
309+
fluentIterable = fluentIterable.filter(new com.google.common.base.Predicate<Contents>() {
310+
@Override
311+
public boolean apply(@Nullable final Contents input) {
312+
if (filter != null) {
313+
return filter.test(input);
314+
} else {
315+
return true; // do not filter anything if filter is null
316+
}
317+
}
318+
});
319+
}
320+
321+
return fluentIterable.transform(new Function<Contents, Ds3Object>() {
322+
@Nullable
323+
@Override
324+
public Ds3Object apply(@Nullable final Contents input) {
325+
return new Ds3Object(input.getKey(), input.getSize());
326+
}
327+
});
328+
}
299329
/**
300330
* Strip prefix from the beginning of objectName. If objectName does not start with prefix, return objectName unmodified.
301331
* @param objectName

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpersImpl.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -285,33 +285,4 @@ public Iterable<Ds3Object> removePrefixFromDs3ObjectsList(final Iterable<Ds3Obje
285285
return newObjectsList;
286286
}
287287

288-
@Override
289-
public Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects) {
290-
return toDs3Iterable(objects, null);
291-
}
292-
293-
@Override
294-
public Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final Predicate<Contents> filter) {
295-
return FluentIterable.from(objects).filter(new com.google.common.base.Predicate<Contents>() {
296-
@Override
297-
public boolean apply(@Nullable final Contents input) {
298-
return input != null;
299-
}
300-
}).filter(new com.google.common.base.Predicate<Contents>() {
301-
@Override
302-
public boolean apply(@Nullable final Contents input) {
303-
if (filter != null) {
304-
return filter.test(input);
305-
} else {
306-
return true; // do not filter anything if filter is null
307-
}
308-
}
309-
}).transform(new Function<Contents, Ds3Object>() {
310-
@Nullable
311-
@Override
312-
public Ds3Object apply(@Nullable final Contents input) {
313-
return new Ds3Object(input.getKey(), input.getSize());
314-
}
315-
});
316-
}
317288
}

0 commit comments

Comments
 (0)