All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.lib.collections.Enumerations Maven / Gradle / Ivy

Go to download

A main program (executable JAR) that will listen to port 29998. At first, it can only answer that it is an Envoy (a limited agent). The only function it supports is installing a -runpath. It will then create a framework + agent and transfer the connection to the just installed agent who will then install the bundles. This JAR is a main command for JPM called bndremote. In JPM, it will start up with debug enabled. This JAR does some highly complicated class loading wizardy to ensure that it does not enforce any constraints on the -runpath.

The newest version!
package aQute.lib.collections;

import static java.util.Objects.requireNonNull;

import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class Enumerations {

	private Enumerations() {}

	final static class EnumerationSpliterator implements Enumeration, Consumer {
		private final Spliterator			spliterator;
		private final Function	mapper;
		private final Predicate				filter;
		private boolean									hasNext	= false;
		private R										next;
		private T										t;

		EnumerationSpliterator(Spliterator spliterator, Function mapper,
			Predicate filter) {
			this.spliterator = spliterator != null ? spliterator : Spliterators.emptySpliterator();
			this.mapper = requireNonNull(mapper);
			this.filter = requireNonNull(filter);
		}

		@Override
		public boolean hasMoreElements() {
			if (hasNext) {
				return true;
			}
			while (spliterator.tryAdvance(this)) {
				R r = mapper.apply(t);
				if (filter.test(r)) {
					next = r;
					return hasNext = true;
				}
			}
			return false;
		}

		@Override
		public R nextElement() {
			if (hasMoreElements()) {
				R r = next;
				hasNext = false;
				return r;
			}
			throw new NoSuchElementException();
		}

		@Override
		public void accept(T t) {
			this.t = t;
		}
	}

	public static  Enumeration enumeration(Spliterator spliterator) {
		return new EnumerationSpliterator<>(spliterator, t -> t, t -> true);
	}

	public static  Enumeration enumeration(Spliterator spliterator,
		Function mapper) {
		return new EnumerationSpliterator<>(spliterator, mapper, r -> true);
	}

	public static  Enumeration enumeration(Spliterator spliterator,
		Function mapper, Predicate filter) {
		return new EnumerationSpliterator<>(spliterator, mapper, filter);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy