List of usage examples for com.google.common.collect Iterators getNext
@Nullable public static <T> T getNext(Iterator<? extends T> iterator, @Nullable T defaultValue)
From source file:org.apache.twill.internal.appmaster.RunnableContainerRequest.java
/** * Remove a resource request and return it. * @return The {@link Resource} and {@link Collection} of {@link RuntimeSpecification} or * {@code null} if there is no more request. *//*from ww w .j a v a2 s. c o m*/ Map.Entry<AllocationSpecification, ? extends Collection<RuntimeSpecification>> takeRequest() { Map.Entry<AllocationSpecification, Collection<RuntimeSpecification>> next = Iterators.getNext(requests, null); return next == null ? null : Maps.immutableEntry(next.getKey(), ImmutableList.copyOf(next.getValue())); }
From source file:org.kitesdk.data.spi.URIPattern.java
public URIPattern(URI uri) { this.pattern = uri; Map<String, String> accumulator = Maps.newHashMap(); if (pattern.isOpaque()) { Iterator<String> pathQuery = PATH_QUERY_SPLITTER.split(pattern.getSchemeSpecificPart()).iterator(); this.patternPath = Iterators.getNext(pathQuery, null); addQuery(Iterators.getNext(pathQuery, null), accumulator); } else {/* w ww. j ava 2 s . co m*/ patternPath = pattern.getPath(); addQuery(pattern.getQuery(), accumulator); addAuthority(pattern, accumulator); } if (pattern.getScheme() != null) { accumulator.put(SCHEME, pattern.getScheme()); } this.defaults = ImmutableMap.copyOf(accumulator); }
From source file:com.android.tools.idea.npw.CommonAssetSetStep.java
@SuppressWarnings("UseJBColor") // Colors are used for the graphics generator, not the plugin UI public CommonAssetSetStep(TemplateWizardState state, @Nullable Project project, @Nullable Module module, @Nullable Icon sidePanelIcon, UpdateListener updateListener, @Nullable VirtualFile invocationTarget) { super(state, project, module, sidePanelIcon, updateListener); myAssetGenerator = new AssetStudioAssetGenerator(state); if (invocationTarget != null && module != null) { AndroidFacet facet = AndroidFacet.getInstance(myModule); if (facet != null) { mySourceProvider = Iterators.getNext( IdeaSourceProvider.getSourceProvidersForFile(facet, invocationTarget, null).iterator(), null);// w w w . ja v a2 s .c o m } } myUpdateQueue = new MergingUpdateQueue("asset.studio", 200, true, null, this, null, false); }
From source file:kn.uni.gis.dataimport.util.GeoUtil.java
public <T> T receiveGeo(final String sql, final GeoFactory<T> factory) { return Iterators.getNext(receiveGeos(sql, factory).iterator(), null); }
From source file:defrac.intellij.sdk.DefracSdkType.java
@Nullable @Override public String suggestHomePath() { return Iterators.getNext(suggestHomePaths().iterator(), null); }
From source file:com.sk89q.worldguard.protection.flags.Flag.java
/** * Given a list of values, choose the best one. * * <p>If there is no "best value" defined, then the first value should * be returned. The default implementation returns the first value. If * an implementation does have a strategy defined, then * {@link #hasConflictStrategy()} should be overridden too.</p> * * @param values A collection of values/*from w w w . j av a2s.co m*/ * @return The chosen value */ @Nullable public T chooseValue(Collection<T> values) { return Iterators.getNext(values.iterator(), null); }
From source file:com.zimbra.common.util.ImageUtil.java
/** * Returns the {@code ImageReader}, or {@code null} if none is available. * @param contentType the MIME content type, or {@code null} * @param filename the filename, or {@code null} *///from w w w. jav a2 s.c o m public static ImageReader getImageReader(String contentType, String filename) { log.debug("Looking up ImageReader for %s, %s", contentType, filename); ImageReader reader = null; if (!StringUtil.isNullOrEmpty(contentType)) { reader = Iterators.getNext(ImageIO.getImageReadersByMIMEType(contentType), null); } if (reader == null && !StringUtil.isNullOrEmpty(filename)) { String ext = FileUtil.getExtension(filename); if (!StringUtil.isNullOrEmpty(ext)) { reader = Iterators.getNext(ImageIO.getImageReadersBySuffix(ext), null); } } log.debug("Returning %s", reader); return reader; }
From source file:kn.uni.gis.softtasks.GisResource.java
License:asdf
private Azimuth getAzimuthToFox(String gameId, Location location) { final AtomicReference<Timestamp> date = new AtomicReference<Timestamp>(); Float next = Iterators.getNext(geoRec.receiveGeos( String.format(Locale.US, "select ST_AZIMUTH(a.poly_geom,ST_POINT(%f,%f))/(2*pi()) * 360, a.timestamp " + "from %s a " + "inner join( " + "select id,player_id,max(timestamp) as t from fox_hunter " + "WHERE id='%s' " + "and player_id='%s' " + "group by id,player_id " + ") fh on fh.id=a.id and fh.player_id=a.player_id and t=a.timestamp;", location.getLon(), location.getLat(), FOX_HUNTER, gameId, FOX_GAMER_ID), new GeoFactory<Float>() { @Override/*from w w w . j a va2 s.c o m*/ public Float createGeo(ResultSet executeQuery) throws SQLException { date.set(executeQuery.getTimestamp(2)); return executeQuery.getFloat(1); } }).iterator(), null); if (next == null) { LOGGER.warn("strange result! for AZIMUTH! {}", gameId); } Azimuth azimuth = new Azimuth(); azimuth.setValue(next == null ? 0f : next); if (date.get() != null) { GregorianCalendar toSet = new GregorianCalendar(); toSet.setTimeInMillis(date.get().getTime()); azimuth.setTimestamp(dataFactory.newXMLGregorianCalendar(toSet)); } return azimuth; }
From source file:com.android.tools.idea.wizard.AssetSetStep.java
@SuppressWarnings("UseJBColor") // Colors are used for the graphics generator, not the plugin UI public AssetSetStep(TemplateWizardState state, @Nullable Project project, @Nullable Module module, @Nullable Icon sidePanelIcon, UpdateListener updateListener, @Nullable VirtualFile invocationTarget) { super(state, project, module, sidePanelIcon, updateListener); myAssetGenerator = new AssetStudioAssetGenerator(state); if (invocationTarget != null && module != null) { AndroidFacet facet = AndroidFacet.getInstance(myModule); if (facet != null) { mySourceProvider = Iterators.getNext( IdeaSourceProvider.getSourceProvidersForFile(facet, invocationTarget, null).iterator(), null);/*w w w . j ava 2 s . c o m*/ } } myUpdateQueue = new MergingUpdateQueue("asset.studio", 200, true, null, this, null, false); register(ATTR_TEXT, myText); register(ATTR_SCALING, myCropRadioButton, Scaling.CROP); register(ATTR_SCALING, myCenterRadioButton, Scaling.CENTER); register(ATTR_SHAPE, myCircleRadioButton, GraphicGenerator.Shape.CIRCLE); register(ATTR_SHAPE, mySquareRadioButton, GraphicGenerator.Shape.SQUARE); register(ATTR_SHAPE, myNoneRadioButton, GraphicGenerator.Shape.NONE); register(ATTR_PADDING, myPaddingSlider); register(ATTR_TRIM, myTrimBlankSpace); register(ATTR_FONT, myFontFamily); register(ATTR_SOURCE_TYPE, myImageRadioButton, AssetStudioAssetGenerator.SourceType.IMAGE); register(ATTR_SOURCE_TYPE, myClipartRadioButton, AssetStudioAssetGenerator.SourceType.CLIPART); register(ATTR_SOURCE_TYPE, myTextRadioButton, AssetStudioAssetGenerator.SourceType.TEXT); register(ATTR_FOREGROUND_COLOR, myForegroundColor); register(ATTR_BACKGROUND_COLOR, myBackgroundColor); register(ATTR_ASSET_TYPE, myAssetTypeComboBox); register(ATTR_ASSET_THEME, myChooseThemeComboBox); register(ATTR_ASSET_NAME, myResourceNameField); myImageFile.addBrowseFolderListener(null, null, null, FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); myForegroundColor.setSelectedColor(Color.BLUE); myBackgroundColor.setSelectedColor(Color.WHITE); for (String font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) { myFontFamily.addItem(new ComboBoxItem(font, font, 1, 1)); if (font.equals(myTemplateState.get(ATTR_FONT))) { myFontFamily.setSelectedIndex(myFontFamily.getItemCount() - 1); } } myChooseClipart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayClipartDialog(); } }); populateComboBox(myAssetTypeComboBox, AssetType.class); populateComboBox(myChooseThemeComboBox, ActionBarIconGenerator.Theme.class); }
From source file:org.kitesdk.data.spi.URIPattern.java
/** * Returns results from parsing a {@link java.net.URI} with this pattern. * If the URI doesn't match the pattern, this will return null. * * @param uri A URI to match against this URIPattern * @return A Map of the pattern's variable names to values from the parsed URI *//* w w w .j a v a 2 s. c om*/ public Map<String, String> getMatch(URI uri) { // verify that the schemes match if (pattern.isAbsolute()) { // if there should be a scheme, make sure it matches if (!pattern.getScheme().equalsIgnoreCase(uri.getScheme())) { return null; } } else if (uri.getScheme() != null) { return null; } Map<String, String> result = Maps.newLinkedHashMap(defaults); if (pattern.isOpaque()) { Iterator<String> pathQuery = PATH_QUERY_SPLITTER.split(uri.getSchemeSpecificPart()).iterator(); if (!addPath(patternPath, Iterators.getNext(pathQuery, null), result)) { return null; } addQuery(Iterators.getNext(pathQuery, null), result); } else if (!uri.isOpaque()) { addAuthority(uri, result); if (patternPath.isEmpty() && !uri.getPath().isEmpty()) { return null; } if (!addPath(patternPath, uri.getPath(), result)) { return null; } addQuery(uri.getQuery(), result); } else { return null; } if (!addComplexMatch(pattern.getFragment(), uri.getFragment(), result)) { return null; } // save this match this.lastMatch = result; // return the new result, so that this is thread-safe return result; }