List of usage examples for java.lang Iterable Iterable
Iterable
From source file:io.fabric8.forge.devops.setup.Fabric8SetupStep.java
@Override public void initializeUI(final UIBuilder builder) throws Exception { organization.setDefaultValue("fabric8"); builder.add(organization);//w ww . j ava 2 s. c o m final Project project = getSelectedProject(builder.getUIContext()); String packaging = getProjectPackaging(project); boolean springBoot = hasSpringBoot(project); // limit the choices depending on the project packaging final List<String> choices = new ArrayList<String>(); if (packaging == null || springBoot || "jar".equals(packaging)) { String currentImage = getDockerFromImage(project); if (currentImage != null) { choices.add(currentImage); } else { choices.addAll(Arrays.asList(jarImages)); } } if (packaging == null || "bundle".equals(packaging)) { choices.add(bundleImages[0]); } if (!springBoot && (packaging == null || "war".equals(packaging))) { choices.addAll(Arrays.asList(warImages)); } from.setCompleter(new UICompleter<String>() { @Override public Iterable<String> getCompletionProposals(UIContext context, InputComponent<?, String> input, String value) { return choices; } }); // is it possible to pre select a choice? if (choices.size() > 0) { String defaultChoice = choices.get(0); if (defaultChoice != null) { from.setDefaultValue(defaultChoice); } } from.addValueChangeListener(new ValueChangeListener() { @Override public void valueChanged(ValueChangeEvent event) { // use a listener so the docker step knows what we selected as it want to reuse builder.getUIContext().getAttributeMap().put("docker.from", event.getNewValue()); } }); builder.add(from); if (packaging == null || (!packaging.equals("war") && !packaging.equals("ear"))) { boolean jarImage = DockerSetupHelper.isJarImage(from.getValue()); // TODO until we can detect reliably executable JARS versus mains lets not make this mandatory /* main.setRequired(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return jarImage; } }); */ // only enable main if its required // TODO we could disable if we knew this was an executable jar main.setEnabled(jarImage); if (project != null) { main.setDefaultValue(DockerSetupHelper.defaultMainClass(project)); } main.addValidator(new ClassNameOrMavenPropertyValidator(true)); main.addValueChangeListener(new ValueChangeListener() { @Override public void valueChanged(ValueChangeEvent event) { // use a listener so the docker step knows what we selected as it want to reuse builder.getUIContext().getAttributeMap().put("docker.main", event.getNewValue()); } }); builder.add(main); } container.setDefaultValue(new Callable<String>() { @Override public String call() throws Exception { String from = (String) builder.getUIContext().getAttributeMap().get("docker.from"); if (from != null) { return asContainer(from); } return null; } }); // the from image values icon.setValueChoices(new Iterable<String>() { @Override public Iterator<String> iterator() { Set<String> choices = new LinkedHashSet<String>(); choices.add("activemq"); choices.add("camel"); choices.add("java"); choices.add("jetty"); choices.add("karaf"); choices.add("mule"); choices.add("spring-boot"); choices.add("tomcat"); choices.add("tomee"); choices.add("vertx"); choices.add("weld"); choices.add("wildfly"); return choices.iterator(); } }); icon.setDefaultValue(new Callable<String>() { @Override public String call() throws Exception { // favor Camel if there is a Camel dependency if (!findCamelArtifacts(project).isEmpty()) { return "camel"; } // popular containers boolean springBoot = hasSpringBoot(project); if (springBoot) { return "spring-boot"; } boolean vertx = hasSpringBoot(project); if (vertx) { return "vertx"; } // match by docker container name if (container.getValue() != null) { for (String choice : icon.getValueChoices()) { if (choice.equals(container.getValue())) { return choice; } } } // use java by default return "java"; } }); group.setDefaultValue(new Callable<String>() { @Override public String call() throws Exception { // use the project name as default value return null; } }); builder.add(profiles).add(icon).add(group).add(container); }
From source file:org.apache.flink.api.java.sampling.RandomSamplerTest.java
private void verifyRandomSamplerDuplicateElements(final RandomSampler<Double> sampler) { List<Double> list = Lists.newLinkedList(new Iterable<Double>() { @Override//from ww w .j a v a 2 s . co m public Iterator<Double> iterator() { return sampler.sample(source.iterator()); } }); Set<Double> set = Sets.newHashSet(list); assertTrue("There should not have duplicate element for sampler without replacement.", list.size() == set.size()); }
From source file:org.apache.blur.kvs.HdfsKeyValueStore.java
private Iterable<Entry<BytesRef, BytesRef>> getIterable(NavigableMap<BytesRef, Value> map) { final Set<Entry<BytesRef, Value>> entrySet = map.entrySet(); return new Iterable<Entry<BytesRef, BytesRef>>() { @Override/*from ww w .ja v a 2s.c om*/ public Iterator<Entry<BytesRef, BytesRef>> iterator() { final Iterator<Entry<BytesRef, Value>> iterator = entrySet.iterator(); return new Iterator<Entry<BytesRef, BytesRef>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<BytesRef, BytesRef> next() { final Entry<BytesRef, Value> e = iterator.next(); return new Entry<BytesRef, BytesRef>() { @Override public BytesRef setValue(BytesRef value) { throw new RuntimeException("Read only."); } @Override public BytesRef getValue() { return e.getValue()._bytesRef; } @Override public BytesRef getKey() { return e.getKey(); } }; } @Override public void remove() { throw new RuntimeException("Read only."); } }; } }; }
From source file:com.aliyun.odps.mapred.local.LocalTaskContext.java
@Override public Iterable<BufferedInputStream> readResourceArchiveAsStream(String resourceName, String relativePath) throws IOException { if (StringUtils.isEmpty(resourceName)) { throw new IOException("Resouce name is empty or null"); }//from w w w.j a v a 2 s .c om File resFile = new File(jobDirecotry.getResourceDir(), resourceName); ; if (!jobDirecotry.hasResource(resourceName)) { String project = SessionState.get().getOdps().getDefaultProject(); try { WareHouse.getInstance().copyResource(project, resourceName, jobDirecotry.getResourceDir(), WareHouse.getInstance().getLimitDownloadRecordCount(), WareHouse.getInstance().getInputColumnSeperator()); } catch (OdpsException e) { } } File resDir = new File(jobDirecotry.getResourceDir(), resourceName + "_decompressed"); ; if (!resDir.exists()) { ArchiveUtils.unArchive(resFile, resDir); } final Collection<File> files = LocalRunUtils.listFiles(resDir, relativePath.trim()); return new Iterable<BufferedInputStream>() { @Override public Iterator<BufferedInputStream> iterator() { return new InputStreamIterator(files.iterator()); } }; }
From source file:com.oltpbenchmark.util.CollectionUtil.java
/** * Wrap an Iterable around an Iterator/*from www. j av a 2 s . c o m*/ * @param <T> * @param it * @return */ public static <T> Iterable<T> iterable(final Iterator<T> it) { return (new Iterable<T>() { @Override public Iterator<T> iterator() { return (it); } }); }
From source file:org.omnaest.utils.structure.iterator.IterableUtils.java
/** * Returns a new instance of an {@link Iterable} which returns the given {@link Iterator} instance * /*from w w w. jav a 2 s. com*/ * @see #valueOf(Iterator, boolean) * @param iterator * {@link Iterator} * @return */ public static <E> Iterable<E> valueOf(final Iterator<E> iterator) { return new Iterable<E>() { @Override public Iterator<E> iterator() { return iterator; } }; }
From source file:com.oltpbenchmark.util.CollectionUtil.java
public static <T> Iterable<T> iterable(final T values[]) { return (new Iterable<T>() { @Override/*from w w w. j a va2 s . c o m*/ public Iterator<T> iterator() { return new Iterator<T>() { private int idx = 0; @Override public boolean hasNext() { return (this.idx < values.length); } @Override public T next() { if (this.idx == values.length) throw new NoSuchElementException(); return values[this.idx++]; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }); }
From source file:oculus.aperture.common.JSONProperties.java
@Override public Iterable<Float> getFloats(String key) { try {/*from w ww . j a v a 2s . co m*/ final JSONArray array = obj.getJSONArray(key); return new Iterable<Float>() { @Override public Iterator<Float> iterator() { return new Iterator<Float>() { private final int n = array.length(); private int i = 0; @Override public boolean hasNext() { return n > i; } @Override public Float next() { try { return (n > i) ? (float) array.getDouble(i++) : null; } catch (JSONException e) { return null; } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; } catch (JSONException e) { return EmptyIterable.instance(); } }
From source file:org.libreplan.business.workingday.IntraDayDate.java
public Iterable<PartialDay> daysUntil(final UntilEnd predicate) { return new Iterable<IntraDayDate.PartialDay>() { @Override//from w w w. j av a 2 s.c o m public Iterator<PartialDay> iterator() { return createIterator(IntraDayDate.this, predicate); } }; }
From source file:com.mongodb.jee.util.BSONHelper.java
/** * Transform the BSON array to iterable DBObject. * //from w w w .j a v a 2 s .c o m * @param list * @return */ public static Iterable<DBObject> toIterable(BasicBSONList list) { final Iterator<DBObject> it = toIterator(list); return new Iterable<DBObject>() { public Iterator<DBObject> iterator() { return it; } }; }