Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow parameterized types in pipeline output
- Loading branch information
1 parent
ba03df6
commit eb667d8
Showing
6 changed files
with
150 additions
and
49 deletions.
There are no files selected for viewing
16 changes: 0 additions & 16 deletions
16
edu.washington.cs.cupid.usage.server/war/WEB-INF/classes/META-INF/jdoconfig.xml
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
edu.washington.cs.cupid.usage.server/war/WEB-INF/classes/META-INF/persistence.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
edu.washington.cs.cupid/src/edu/washington/cs/cupid/standard/Flatten.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013 Todd Schiller. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Todd Schiller - initial API, implementation, and documentation | ||
******************************************************************************/ | ||
package edu.washington.cs.cupid.standard; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.reflect.TypeToken; | ||
|
||
import edu.washington.cs.cupid.capability.linear.GenericLinearCapability; | ||
import edu.washington.cs.cupid.capability.linear.LinearJob; | ||
import edu.washington.cs.cupid.capability.linear.LinearStatus; | ||
|
||
/** | ||
* A capability that flattens nested collections into a single collection | ||
* @author Todd Schiller | ||
* @param <V> element type | ||
*/ | ||
public final class Flatten<V> extends GenericLinearCapability<Collection<Collection<V>>, List<V>> { | ||
|
||
/** | ||
* A capability that returns the number of elements in a collection. | ||
*/ | ||
public Flatten() { | ||
super( | ||
"Flatten", | ||
"Flattens nested collections into a single collection", | ||
Flag.PURE); | ||
} | ||
|
||
@Override | ||
public TypeToken<Collection<Collection<V>>> getInputType() { | ||
return new TypeToken<Collection<Collection<V>>>(getClass()) { | ||
private static final long serialVersionUID = 1L; | ||
}; | ||
} | ||
|
||
@Override | ||
public TypeToken<List<V>> getOutputType() { | ||
return new TypeToken<List<V>>(getClass()) { | ||
private static final long serialVersionUID = 1L; | ||
}; | ||
} | ||
|
||
@Override | ||
public LinearJob<Collection<Collection<V>>, List<V>> getJob(final Collection<Collection<V>> input) { | ||
return new LinearJob<Collection<Collection<V>>, List<V>>(this, input) { | ||
@Override | ||
protected LinearStatus<List<V>> run(final IProgressMonitor monitor) { | ||
try { | ||
monitor.beginTask(getName(), getInput().size()); | ||
List<V> result = Lists.newArrayList(); | ||
|
||
for (Collection<V> inner : getInput()){ | ||
result.addAll(inner); | ||
monitor.worked(1); | ||
} | ||
|
||
return LinearStatus.makeOk(getCapability(), result); | ||
} catch (Exception ex) { | ||
return LinearStatus.<List<V>>makeError(ex); | ||
} finally { | ||
monitor.done(); | ||
} | ||
} | ||
}; | ||
} | ||
} |