public void testBasic() throws Exception { if (!Dpkg.available()) { return; } DebPackagingFormat packagingFormat = (DebPackagingFormat) lookup(PackagingFormat.ROLE, "deb"); FileObject dpkgTest = VFS.getManager().resolveFile(getTestPath("target/deb-test")); FileObject packageRoot = dpkgTest.resolveFile("root"); File packageFile = VfsUtil.asFile(dpkgTest.resolveFile("file.deb")); PackageVersion version = packageVersion("1.0", "123", false, some("1")); PackageParameters parameters = packageParameters( "mygroup", "myartifact", version, "id", "default-name", Option.<java.lang.String>none(), EMPTY, EMPTY) .contact("Kurt Cobain") .architecture("all"); List<String> nil = List.nil(); packagingFormat .start() .parameters(parameters) .debParameters(Option.<String>none(), some("devel"), false, nil, nil, nil, nil, nil, nil) .debug(true) .workingDirectory(packageRoot) .packageToFile(packageFile, ScriptUtil.Strategy.SINGLE); assertTrue(packageFile.canRead()); }
/** @author <a href="mailto:[email protected]">Trygve Laugstøl</a> */ public class FileAttributes { public final Option<String> user; public final Option<String> group; public final Option<UnixFileMode> mode; public final List<String> tags; public static final Show<FileAttributes> singleLineShow = Show.anyShow(); /** A file object with all none fields. Use this when creating template objects. */ public static final FileAttributes EMPTY = new FileAttributes( Option.<String>none(), Option.<String>none(), Option.<UnixFileMode>none(), List.<String>nil()); public FileAttributes(Option<String> user, Option<String> group, Option<UnixFileMode> mode) { this(user, group, mode, List.<String>nil()); } public FileAttributes( Option<String> user, Option<String> group, Option<UnixFileMode> mode, List<String> tags) { validateNotNull(user, group, mode, tags); this.user = user; this.group = group; this.mode = mode; this.tags = tags; } public FileAttributes user(String user) { return new FileAttributes(fromNull(user), group, mode, tags); } public FileAttributes user(Option<String> user) { return new FileAttributes(user, group, mode, tags); } public FileAttributes group(String group) { return new FileAttributes(user, fromNull(group), mode, tags); } public FileAttributes group(Option<String> group) { return new FileAttributes(user, group, mode, tags); } public FileAttributes mode(UnixFileMode mode) { return new FileAttributes(user, group, fromNull(mode), tags); } public FileAttributes mode(Option<UnixFileMode> mode) { return new FileAttributes(user, group, mode, tags); } public FileAttributes addTag(String tag) { return new FileAttributes(user, group, mode, tags.append(single(tag))); } public FileAttributes tags(List<String> tags) { return new FileAttributes(user, group, mode, this.tags.append(tags)); } // ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- public FileAttributes useAsDefaultsFor(FileAttributes other) { return new FileAttributes( other.user.orElse(user), other.group.orElse(group), other.mode.orElse(mode), other.tags); } // ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- public static final F2<FileAttributes, FileAttributes, FileAttributes> useAsDefaultsFor = new F2<FileAttributes, FileAttributes, FileAttributes>() { public FileAttributes f(FileAttributes defaults, FileAttributes other) { return defaults.useAsDefaultsFor(other); } }; public static final F<FileAttributes, Option<String>> userF = new F<FileAttributes, Option<String>>() { public Option<String> f(FileAttributes attributes) { return attributes.user; } }; public static final F<FileAttributes, Option<String>> groupF = new F<FileAttributes, Option<String>>() { public Option<String> f(FileAttributes attributes) { return attributes.group; } }; public static final F<FileAttributes, Option<UnixFileMode>> modeF = new F<FileAttributes, Option<UnixFileMode>>() { public Option<UnixFileMode> f(FileAttributes attributes) { return attributes.mode; } }; public static final F<FileAttributes, List<String>> tagsF = new F<FileAttributes, List<String>>() { public List<String> f(FileAttributes attributes) { return attributes.tags; } }; // ----------------------------------------------------------------------- // Object Overrides // ----------------------------------------------------------------------- public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } FileAttributes that = (FileAttributes) o; return optionEquals(user, that.user) && optionEquals(group, that.group) && optionEquals(mode, that.mode); } public String toString() { return "user="******"<not set>") + ", " + "group=" + group.orSome("<not set>") + ", " + "mode=" + mode.map(showLong).orSome("<not set>"); } }
public FileAttributes(Option<String> user, Option<String> group, Option<UnixFileMode> mode) { this(user, group, mode, List.<String>nil()); }
/** Default constructor. Creates a new instance of {@code ABC}. */ public ABC() { this.initialisationStrategy = new ClonedPopulationInitialisationStrategy(); initialisationStrategy.setEntityNumber(100); initialisationStrategy.setEntityType(new WorkerBee()); workerBees = fj.data.List.nil(); onlookerBees = fj.data.List.nil(); explorerBee = new ExplorerBee(); dancingSelectionStrategy = new RouletteWheelSelector(); forageLimit = ConstantControlParameter.of(500); workerBeePercentage = ConstantControlParameter.of(0.5); explorerBeeUpdateLimit = ConstantControlParameter.of(1.0); }
/** * Binds the given function across each element of this array with a final join. * * @param f The function to apply to each element of this array. * @return A new array after performing the map, then final join. */ @SuppressWarnings({"unchecked"}) public <B> Array<B> bind(final F<A, Array<B>> f) { List<Array<B>> x = List.nil(); int len = 0; for (int i = a.length - 1; i >= 0; i--) { final Array<B> bs = f.f((A) a[i]); len = len + bs.length(); x = x.cons(bs); } final Object[] bs = new Object[len]; x.foreach( new F<Array<B>, Unit>() { private int i; public Unit f(final Array<B> x) { arraycopy(x.a, 0, bs, i, x.a.length); i = i + x.a.length; return unit(); } }); return new Array<B>(bs); }
@Test public void testCreation() { Particle p1 = NichingFunctionsTest.createParticle(new MinimisationFitness(3.0), Vector.of(0.0, 1.0)); Particle p2 = NichingFunctionsTest.createParticle(new MinimisationFitness(2.0), Vector.of(1.0, 1.0)); Particle p3 = NichingFunctionsTest.createParticle(new MinimisationFitness(1.0), Vector.of(2.0, 2.0)); PSO pso = new PSO(); pso.getTopology().addAll(Arrays.asList(p1, p2, p3)); ClosestNeighbourNicheCreationStrategy creator = new ClosestNeighbourNicheCreationStrategy(); creator.setSwarmBehavior(new ParticleBehavior()); NichingSwarms swarms = creator.f(NichingSwarms.of(pso, List.<PopulationBasedAlgorithm>nil()), p1); Assert.assertEquals(1, swarms._1().getTopology().size()); Assert.assertEquals( Vector.of(2.0, 2.0), swarms._1().getTopology().get(0).getCandidateSolution()); Assert.assertEquals(2, swarms._2().head().getTopology().size()); Assert.assertEquals( Vector.of(0.0, 1.0), swarms._2().head().getTopology().get(0).getCandidateSolution()); Assert.assertEquals( Vector.of(1.0, 1.0), swarms._2().head().getTopology().get(1).getCandidateSolution()); }
/** * Returns a list projection of this array. * * @return A list projection of this array. */ @SuppressWarnings("unchecked") public List<A> toList() { List<A> x = List.nil(); for (int i = a.length - 1; i >= 0; i--) { x = x.cons((A) a[i]); } return x; }
/** * Filters elements from this array by returning only elements which produce <code>true</code> * when the given function is applied to them. * * @param f The predicate function to filter on. * @return A new array whose elements all match the given predicate. */ @SuppressWarnings("unchecked") public Array<A> filter(final F<A, Boolean> f) { List<A> x = List.nil(); for (int i = a.length - 1; i >= 0; i--) { if (f.f((A) a[i])) x = x.cons((A) a[i]); } return x.toArray(); }
@Override public List<ApplicationDTO> getList() throws InterruptedException { try { final ObjectMapper mapper = new ObjectMapper(); return array(mapper.readValue(jsonApplications, ApplicationDTO[].class)) .toList() .sort(ord(curry(ordering))); } catch (IOException e) { return List.nil(); } }
/** * Sequence through the option monad. * * @param a The list of option to sequence. * @return The option of list after sequencing. */ public static <A> Option<List<A>> sequence(final List<Option<A>> a) { return a.isEmpty() ? some(List.<A>nil()) : a.head() .bind( new F<A, Option<List<A>>>() { public Option<List<A>> f(final A aa) { return sequence(a.tail()).map(cons_(aa)); } }); }
/** * Sequences through the right side of the either monad with a list of values. * * @param a The list of values to sequence with the either monad. * @return A sequenced value. */ public static <B, X> Either<X, List<B>> sequenceRight(final List<Either<X, B>> a) { return a.isEmpty() ? Either.<X, List<B>>right(List.<B>nil()) : a.head() .right() .bind( new Func<B, Either<X, List<B>>>() { public Either<X, List<B>> f(final B bb) { return sequenceRight(a.tail()).right().map(cons_(bb)); } }); }
/** * Sequences through the left side of the either monad with a list of values. * * @param a The list of values to sequence with the either monad. * @return A sequenced value. */ public static <A, X> Either<List<A>, X> sequenceLeft(final List<Either<A, X>> a) { return a.isEmpty() ? Either.<List<A>, X>left(List.<A>nil()) : a.head() .left() .bind( new Func<A, Either<List<A>, X>>() { public Either<List<A>, X> f(final A aa) { return sequenceLeft(a.tail()).left().map(cons_(aa)); } }); }
/** * Returns all the right values in the given list. * * @param es The list of possible right values. * @return All the right values in the given list. */ public static <A, B> List<B> rights(final List<Either<A, B>> es) { return es.foldRight( new Func<Either<A, B>, Func<List<B>, List<B>>>() { public Func<List<B>, List<B>> f(final Either<A, B> e) { return new Func<List<B>, List<B>>() { public List<B> f(final List<B> bs) { return e.isRight() ? bs.cons(e.right().value()) : bs; } }; } }, List.<B>nil()); }
/** * Returns all the left values in the given list. * * @param es The list of possible left values. * @return All the left values in the given list. */ public static <A, B> List<A> lefts(final List<Either<A, B>> es) { return es.foldRight( new Func<Either<A, B>, Func<List<A>, List<A>>>() { public Func<List<A>, List<A>> f(final Either<A, B> e) { return new Func<List<A>, List<A>>() { public List<A> f(final List<A> as) { return e.isLeft() ? as.cons(e.left().value()) : as; } }; } }, List.<A>nil()); }
private List<Integer> getNeighbourhood(final E e) { int currentIteration = getIteration(); if (currentIteration > lastIteration || nHoods == null || perCall) { lastIteration = currentIteration; nHoods = getNeighbourhoods(distanceMeasure, radius, neighbourhoodSize) .f( P.p( List.<Entity>iterableList((java.util.List<Entity>) entities).zipIndex(), List.<List<Integer>>nil())); } final int index = entities.indexOf(e); return nHoods .find( new F<List<Integer>, Boolean>() { @Override public Boolean f(List<Integer> a) { return a.exists(Equal.intEqual.eq(index)); } }) .orSome(List.single(index)); }
public static <T> List<T> listFromArray(T[] ar) { List<T> l = List.nil(); for (T x : ar) l = l.snoc(x); return l; }
/** * Returns a single element list if this projection has a value, otherwise an empty list. * * @return A single element list if this projection has a value, otherwise an empty list. */ public List<B> toList() { return isRight() ? single(value()) : List.<B>nil(); }
/** * Returns a single element list if this projection has a value, otherwise an empty list. * * @return A single element list if this projection has a value, otherwise an empty list. */ public List<A> toList() { return isLeft() ? single(value()) : List.<A>nil(); }
public FRaceIterationStrategy() { this.minProblems = ConstantControlParameter.of(4.0); this.results = List.<List<OptimisationSolution>>nil(); }
/** * Sequence the list of parsers through {@link #bind}. * * @param ps The parsers to sequence. * @return A parser after sequencing. */ public static <I, A, E> Parser<I, List<A>, E> sequence(final List<Parser<I, A, E>> ps) { return ps.isEmpty() ? Parser.<I, List<A>, E>value(List.<A>nil()) : ps.head().bind(a -> sequence(ps.tail()).map(cons_(a))); }
/** * Returns a list projection of this optional value. * * @return A list projection of this optional value. */ public List<A> toList() { return isSome() ? cons(some(), List.<A>nil()) : List.<A>nil(); }