List of usage examples for com.google.common.collect Iterators forArray
public static <T> UnmodifiableIterator<T> forArray(final T... array)
From source file:org.fcrepo.kernel.utils.iterators.RdfStream.java
/** * Constructor that begins the stream with proffered triples. * * @param triples/* w w w.ja v a 2s . c om*/ */ @SafeVarargs public <T extends Triple> RdfStream(final T... triples) { this(Iterators.forArray(triples)); }
From source file:net.tridentsdk.reflect.Injector.java
/** * Creates a new object which has injectable fields, using the injectable constructor * * @param clazz the class to instantiate * @param args the parameters, not including the injectable classes, in order of declaration * @param <T> the type to return//from w w w .j a v a2 s .co m * @return the new object */ public static <T> T newObject(Class<T> clazz, Object... args) { for (Map.Entry<Constructor, Class<?>[]> entry : findConstructors(clazz).entrySet()) { List<Object> arguments = Lists.newArrayList(); Constructor constructor = entry.getKey(); Class<?>[] constructorParameters = entry.getValue(); PeekingIterator<Object> iterator = Iterators.peekingIterator(Iterators.forArray(args)); if (!checkArray(args, constructorParameters)) continue; for (Class<?> c : constructorParameters) { Producer<?> producer = injectors.get(c); Inject inject = (Inject) constructor.getAnnotation(Inject.class); if (iterator.hasNext()) { if (iterator.peek().getClass() == c) { arguments.add(iterator.next()); continue; } } if (producer == null) { if (iterator.hasNext()) { if (iterator.peek().getClass() == c) { arguments.add(iterator.next()); continue; } } TridentLogger.error(new IllegalArgumentException("Constructor " + clazz.getName() + "(" + Arrays.toString(constructorParameters).replaceAll("class ", "").replaceAll("\\[", "") .replaceAll("\\]", "") + ") " + "does not provide or registered parameter " + c.getName())); return null; } else { if (inject.meta() == Class.class) { arguments.add(producer.produce()); } else { arguments.add(producer.produce(inject.meta())); } } } try { T t = (T) constructor.newInstance(arguments.toArray()); for (Field field : findFields(clazz)) { setField(t, field); } return t; } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { TridentLogger.error(e); return null; } } try { T t = clazz.newInstance(); for (Field field : findFields(clazz)) { setField(t, field); } return t; } catch (InstantiationException | IllegalAccessException e) { TridentLogger.error(e); return null; } }
From source file:org.elasticsearch.action.bulk.BulkResponse.java
@Override public Iterator<BulkItemResponse> iterator() { return Iterators.forArray(responses); }
From source file:org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ImmutableModuleExclusionSet.java
@Override public Iterator<AbstractModuleExclusion> iterator() { return Iterators.forArray(elements); }
From source file:kihira.minicreatures.common.entity.ai.EntityAIIdleBlockChat.java
@Override public void startExecuting() { Block targetBlock = this.miniPlayer.worldObj.getBlock((int) this.targetX, (int) this.targetY, (int) this.targetZ); //Look for some valid chat lines to say about this block String blockName = GameData.getBlockRegistry().getNameForObject(targetBlock); for (int i = 0; i < 10; i++) { String chatLine = "chat.idle.block." + this.miniPlayer.getPersonality().getCurrentMood().name + "." + blockName + "." + i; if (StatCollector.canTranslate(chatLine)) { this.chatLines = Iterators.forArray(StatCollector.translateToLocal(chatLine).split(";")); break; }/*from w w w . j a va2 s .c o m*/ } //If we can't find anything, load default chat if there is a chance too if (this.chatLines == null && this.miniPlayer.getRNG().nextInt(30) == 0) { for (int i = 0; i < 10; i++) { String chatLine = "chat.idle.block.generic." + this.miniPlayer.getPersonality().getCurrentMood().name + "." + i; if (StatCollector.canTranslate(chatLine)) { this.chatLines = Iterators.forArray(StatCollector.translateToLocal(chatLine).split(";")); break; } } } }
From source file:org.kiji.schema.impl.cassandra.CassandraQualifierIterator.java
/** {@inheritDoc} */ @Override//from w w w. j a v a 2s . c om public String next() { if (!hasNext()) { throw new NoSuchElementException(); } final String qualifier = mPageIterator.next(); while (!mPageIterator.hasNext() && mPager.hasNext()) { mPageIterator = Iterators.forArray(mPager.next()); } return qualifier; }
From source file:com.github.rinde.rinsim.scenario.fabrirecht.FabriRechtParser.java
/** * Parse Fabri {@literal &} Recht scenario. * @param coordinateFile The coordinate file. * @param ordersFile The orders file./*from www.j av a 2 s. c o m*/ * @return The scenario. * @throws IOException When parsing fails. */ public static FabriRechtScenario parse(String coordinateFile, String ordersFile) throws IOException { final List<TimedEvent> events = newArrayList(); final BufferedReader coordinateFileReader = new BufferedReader(new FileReader(coordinateFile)); final BufferedReader ordersFileReader = new BufferedReader(new FileReader(ordersFile)); final List<Point> coordinates = newArrayList(); String line; int coordinateCounter = 0; int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; while ((line = coordinateFileReader.readLine()) != null) { final String[] parts = line.split(LINE_SEPARATOR); if (Integer.parseInt(parts[0]) != coordinateCounter) { coordinateFileReader.close(); ordersFileReader.close(); throw new IllegalArgumentException("The coordinate file seems to be in an unrecognized format."); } final int x = Integer.parseInt(parts[1]); final int y = Integer.parseInt(parts[2]); minX = Math.min(x, minX); minY = Math.min(y, minY); maxX = Math.max(x, maxX); maxY = Math.max(y, maxY); final Point pos = new Point(x, y); coordinates.add(pos); if (Integer.parseInt(parts[0]) == 0) { events.add(AddDepotEvent.create(0, pos)); } coordinateCounter++; } coordinateFileReader.close(); final Point min = new Point(minX, minY); final Point max = new Point(maxX, maxY); // Anzahl der Fahrzeuge; Kapazitt; untere Zeitfenstergrenze; obere // Zeitfenstergrenze @Nullable final String firstLineString = ordersFileReader.readLine(); final Iterator<String> firstLine = Iterators.forArray(verifyNotNull(firstLineString).split(LINE_SEPARATOR)); // first contains number of vehicles, but this is not needed firstLine.next(); final int capacity = Integer.parseInt(firstLine.next()); final long startTime = Long.parseLong(firstLine.next()); final long endTime = Long.parseLong(firstLine.next()); final TimeWindow timeWindow = TimeWindow.create(startTime, endTime); events.add(TimeOutEvent.create(endTime)); final VehicleDTO defaultVehicle = VehicleDTO.builder().startPosition(coordinates.get(0)).speed(1d) .capacity(capacity).availabilityTimeWindow(timeWindow).build(); // Nr. des Pickup-Orts; Nr. des Delivery-Orts; untere Zeitfenstergrenze // Pickup; obere Zeitfenstergrenze Pickup; untere Zeitfenstergrenze // Delivery; obere Zeitfenstergrenze Delivery; bentigte Kapazitt; // Anrufzeit; Servicezeit Pickup; Servicezeit Delivery while ((line = ordersFileReader.readLine()) != null) { final Iterator<String> it = Iterators.forArray(line.split(LINE_SEPARATOR)); final Parcel.Builder b = Parcel .builder(coordinates.get(Integer.parseInt(it.next())), coordinates.get(Integer.parseInt(it.next()))) .pickupTimeWindow(TimeWindow.create(Long.parseLong(it.next()), Long.parseLong(it.next()))) .deliveryTimeWindow(TimeWindow.create(Long.parseLong(it.next()), Long.parseLong(it.next()))); // we ignore the capacity it.next(); final int neededCapacity = 1; final ParcelDTO o = b.neededCapacity(neededCapacity).orderAnnounceTime(Long.parseLong(it.next())) .pickupDuration(Long.parseLong(it.next())).deliveryDuration(Long.parseLong(it.next())) .buildDTO(); events.add(AddParcelEvent.create(o)); } ordersFileReader.close(); Collections.sort(events, TimeComparator.INSTANCE); return FabriRechtScenario.create(events, min, max, timeWindow, defaultVehicle); }
From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.builder.OldVersionHelper.java
private URI getCopiedURI(IProject project, IPath relativePath) throws JavaModelException { try {// ww w .ja va 2s. c o m if (!copiedURIMap.containsKey(relativePath)) { IJavaProject javaProject = JavaCore.create(project); IClasspathEntry sourceEntry = Iterators.find( Iterators.forArray(javaProject.getResolvedClasspath(true)), new SourceFolderFinder(relativePath)); IPath outputLocation = sourceEntry.getOutputLocation(); if (outputLocation == null) { outputLocation = javaProject.getOutputLocation(); } IPath path = outputLocation.append(relativePath.makeRelativeTo(sourceEntry.getPath())); URI copiedURI = (project.getWorkspace().getRoot().findMember(path) != null) ? URI.createPlatformResourceURI(path.toString(), true) : null; if (copiedURI != null) { copiedURIMap.put(relativePath, copiedURI); } return copiedURI; } return copiedURIMap.get(relativePath); } catch (NoSuchElementException e) { return null; } }
From source file:org.fcrepo.kernel.utils.iterators.RdfStream.java
/** * Constructor that begins the stream with proffered statements. * * @param statements/*from ww w.j a v a 2 s .c om*/ */ @SafeVarargs public <T extends Statement> RdfStream(final T... statements) { this(Iterators.transform(Iterators.forArray(statements), statement2triple)); }
From source file:org.apache.drill.exec.compile.sig.CodeGeneratorMethod.java
@Override public Iterator<CodeGeneratorArgument> iterator() { return Iterators.forArray(arguments); }