List of usage examples for com.google.common.collect Iterables all
public static <T> boolean all(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.che.ide.actions.DeleteItemAction.java
/** {@inheritDoc} */ @Override//from w w w . j av a 2 s . c o m public void actionPerformed(ActionEvent e) { final Selection<?> selection = selectionAgent.getSelection(); if (selection == null || selection.isEmpty()) { throw new IllegalStateException("Nodes weren't found in the selection agent"); } if (Iterables.all(selection.getAllElements(), isResourceBasedNode())) { final List<ResourceBasedNode<?>> nodes = Lists .newArrayList(Iterables.transform(selection.getAllElements(), castNode())); Node selectedNode = nodes.get(0); Node parentNode = selectedNode.getParent(); deleteNodeHandler.deleteAll(nodes, true).then(synchronizeProjectView(parentNode)) .then(actionComplete(nodes)); } }
From source file:com.eucalyptus.cluster.callback.StateUpdateHandler.java
@Override public void fireEvent(Event event) { if (this.timedTrigger(event)) { Iterables.all(callbackMap.keySet(), new Predicate<Class>() { @Override/*from w ww . ja v a 2 s. com*/ public boolean apply(Class arg0) { if (StateUpdateHandler.this.inflightMap.get(arg0).compareAndSet(false, true)) { //TODO: RELEASE: wrap this up here. } return false; } }); } }
From source file:google.registry.model.ofy.Ofy.java
/** * Delete, augmented to enroll the deleted entities in a commit log. * * <p>We only allow this in transactions so commit logs can be written in tandem with the delete. *//*from w w w . j a v a 2 s . c om*/ public Deleter delete() { return new AugmentedDeleter() { @Override protected void handleDeletion(Iterable<Key<?>> keys) { assertInTransaction(); checkState(Iterables.all(keys, notNull()), "Can't delete a null key."); checkProhibitedAnnotations(keys, NotBackedUp.class, VirtualEntity.class); TRANSACTION_INFO.get().putDeletes(keys); } }; }
From source file:org.obiba.onyx.quartz.editor.widget.attributes.AttributesEditPanel.java
private void validate(Form<?> form, Attributable ao, FactorizedAttribute famo) { if (Strings.isNullOrEmpty(nameField.getValue())) { form.error(new StringResourceModel("FieldNameRequired", this, null).getObject()); }//from w w w .j a v a 2 s . c o m boolean allEmpty = Iterables.all(famo.getValues().values(), new Predicate<IModel<String>>() { @Override public boolean apply(@Nullable IModel<String> input) { return Strings.isNullOrEmpty(input.getObject()); } }); if (allEmpty) { form.error(new StringResourceModel("MustProvideValue", this, null).getObject()); } if ((namespaceField.getValue().equals(initialNamespace) && nameField.getValue().equals(initialName)) == false) { if (ao.containsAttribute(namespaceField.getValue(), nameField.getValue())) { form.error(new StringResourceModel("AttributeAlreadyExists", this, null).getObject()); } } }
From source file:com.eucalyptus.tags.TagManager.java
public CreateTagsResponseType createTags(final CreateTagsType request) throws EucalyptusCloudException { final CreateTagsResponseType reply = request.getReply(); reply.set_return(false); final Context context = Contexts.lookup(); final UserFullName userFullName = context.getUserFullName(); final AccountFullName accountFullName = userFullName.asAccountFullName(); final List<String> resourceIds = Objects.firstNonNull(request.getResourcesSet(), Collections.<String>emptyList()); final List<ResourceTag> resourceTags = Objects.firstNonNull(request.getTagSet(), Collections.<ResourceTag>emptyList()); for (final ResourceTag resourceTag : resourceTags) { final String key = resourceTag.getKey(); final String value = Strings.nullToEmpty(resourceTag.getValue()).trim(); if (Strings.isNullOrEmpty(key) || key.trim().length() > 128 || isReserved(key)) { throw new InvalidParameterValueException( "Invalid key (max length 128, must not be empty, reserved prefixes " + reservedPrefixes + "): " + key); }/*from w w w . jav a 2 s.co m*/ if (value.length() > 256 || isReserved(key)) { throw new InvalidParameterValueException( "Invalid value (max length 256, reserved prefixes " + reservedPrefixes + "): " + value); } } if (resourceTags.size() > 0 && resourceIds.size() > 0) { final Predicate<Void> creator = new Predicate<Void>() { @Override public boolean apply(final Void v) { final List<CloudMetadata> resources = Lists.transform(resourceIds, resourceLookup(true)); if (!Iterables.all(resources, Predicates.and(Predicates.notNull(), typeSpecificFilters(), permissionsFilter()))) { return false; } for (final CloudMetadata resource : resources) { for (final ResourceTag resourceTag : resourceTags) { final String key = Strings.nullToEmpty(resourceTag.getKey()).trim(); final String value = Strings.nullToEmpty(resourceTag.getValue()).trim(); TagSupport.fromResource(resource).createOrUpdate(resource, userFullName, key, value); } if (TagSupport.fromResource(resource).count(resource, accountFullName) > MAX_TAGS_PER_RESOURCE) { throw new TagLimitException(); } } return true; } }; try { reply.set_return(Entities.asTransaction(Tag.class, creator).apply(null)); } catch (TagLimitException e) { throw new TagLimitExceededException(); } catch (RuntimeException e) { handleException(e); } } return reply; }
From source file:org.obiba.onyx.quartz.editor.questionnaire.QuestionnairePanel.java
public QuestionnairePanel(String id, final IModel<Questionnaire> model, boolean newQuestionnaire) { super(id, model); final Questionnaire questionnaire = model.getObject(); add(CSSPackageResource.getHeaderContribution(QuestionnairePanel.class, "QuestionnairePanel.css")); feedbackPanel = new FeedbackPanel("content"); feedbackWindow = new FeedbackWindow("feedback"); feedbackWindow.setOutputMarkupId(true); add(feedbackWindow);/*from w w w.j a va 2 s. c om*/ Form<Questionnaire> form = new Form<Questionnaire>("form", model); add(form); TextField<String> name = new TextField<String>("name", new PropertyModel<String>(form.getModel(), "name")); name.setLabel(new ResourceModel("Name")); name.setEnabled(newQuestionnaire); name.add(new RequiredFormFieldBehavior()); name.add(new PatternValidator(QuartzEditorPanel.ELEMENT_NAME_PATTERN)); name.add(new AbstractValidator<String>() { @Override protected void onValidate(final IValidatable<String> validatable) { boolean isNewName = Iterables.all(questionnaireBundleManager.bundles(), new Predicate<QuestionnaireBundle>() { @Override public boolean apply(QuestionnaireBundle input) { return !input.getName().equals(validatable.getValue()); } }); if (!isNewName && !validatable.getValue().equals(questionnaire.getName())) { error(validatable, "NameAlreadyExist"); } } }); form.add(name).add(new SimpleFormComponentLabel("nameLabel", name)) .add(new HelpTooltipPanel("nameHelp", new ResourceModel("Name.Tooltip"))); TextField<String> version = new TextField<String>("version", new PropertyModel<String>(form.getModel(), "version")); version.setLabel(new ResourceModel("Version")); version.add(new RequiredFormFieldBehavior()); form.add(version).add(new SimpleFormComponentLabel("versionLabel", version)); CheckBox commentable = new CheckBox("commentable", new PropertyModel<Boolean>(questionnaire, "commentable")); commentable.setLabel(new ResourceModel("Commentable")); form.add(commentable); form.add(new SimpleFormComponentLabel("commentableLabel", commentable)); form.add(new HelpTooltipPanel("commentableHelp", new ResourceModel("Commentable.Tooltip"))); QuestionnaireFinder.getInstance(questionnaire).buildQuestionnaireCache(); guessUIType(questionnaire); RadioGroup<String> uiType = new RadioGroup<String>("uiType", new PropertyModel<String>(form.getModel(), "uiType")); uiType.setLabel(new ResourceModel("UIType")); uiType.setRequired(true); form.add(uiType); Radio<String> standardUiType = new Radio<String>("standard", new Model<String>(Questionnaire.STANDARD_UI)); standardUiType.setLabel(new ResourceModel("UIType.standard")); uiType.add(standardUiType).add(new SimpleFormComponentLabel("standardLabel", standardUiType)); Radio<String> simplifiedUiType = new Radio<String>("simplified", new Model<String>(Questionnaire.SIMPLIFIED_UI)); simplifiedUiType.setLabel(new ResourceModel("UIType.simplified")); uiType.add(simplifiedUiType).add(new SimpleFormComponentLabel("simplifiedLabel", simplifiedUiType)); form.add(new HelpTooltipPanel("uiHelp", new ResourceModel("UIType.Tooltip"))); form.add(new HelpTooltipPanel("labelsHelp", new ResourceModel("LanguagesProperties.Tooltip"))); Map<String, IModel<String>> labelsTooltips = new HashMap<String, IModel<String>>(); labelsTooltips.put("label", new ResourceModel("Questionnaire.Tooltip.label")); labelsTooltips.put("description", new ResourceModel("Questionnaire.Tooltip.description")); labelsTooltips.put("labelNext", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelPrevious", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelStart", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelFinish", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelInterrupt", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelResume", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelCancel", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); localePropertiesModel = new Model<LocaleProperties>( newQuestionnaire ? LocaleProperties.createForNewQuestionnaire(questionnaire) : localePropertiesUtils.load(questionnaire, questionnaire)); final LabelsPanel labelsPanel = new LabelsPanel("labels", localePropertiesModel, model, feedbackPanel, feedbackWindow, labelsTooltips, null); form.add(labelsPanel); final Locale userLocale = Session.get().getLocale(); IChoiceRenderer<Locale> renderer = new IChoiceRenderer<Locale>() { @Override public String getIdValue(Locale locale, int index) { return locale.toString(); } @Override public Object getDisplayValue(Locale locale) { return locale.getDisplayLanguage(userLocale); } }; IModel<List<Locale>> localeChoices = new LoadableDetachableModel<List<Locale>>() { @Override protected List<Locale> load() { List<Locale> locales = new ArrayList<Locale>(); for (String language : Locale.getISOLanguages()) { locales.add(new Locale(language)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayLanguage(userLocale) .compareTo(locale2.getDisplayLanguage(userLocale)); } }); return locales; } }; Palette<Locale> localesPalette = new Palette<Locale>("languages", new PropertyModel<List<Locale>>(model.getObject(), "locales"), localeChoices, renderer, 5, false) { @Override protected Recorder<Locale> newRecorderComponent() { Recorder<Locale> recorder = super.newRecorderComponent(); recorder.setLabel(new ResourceModel("Languages")); recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { LocaleProperties localeProperties = localePropertiesModel.getObject(); Collection<Locale> selectedLocales = getModelCollection(); @SuppressWarnings("unchecked") Collection<Locale> removedLocales = CollectionUtils.subtract(localeProperties.getLocales(), selectedLocales); for (Locale locale : removedLocales) { localeProperties.removeLocale(questionnaire, locale); } for (Locale locale : selectedLocales) { if (!localeProperties.getLocales().contains(locale)) { localeProperties.addLocale(questionnaire, locale); } } labelsPanel.onModelChange(target); } }); return recorder; } }; form.add(localesPalette); form.add(new SaveCancelPanel("saveCancel", form) { @Override protected void onSave(AjaxRequestTarget target, Form<?> form1) { try { if (questionnaire.getLocales().isEmpty()) { error(new StringResourceModel("LanguagesRequired", QuestionnairePanel.this, null) .getString()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); return; } prepareSave(target, questionnaire); questionnairePersistenceUtils.persist(questionnaire, localePropertiesModel.getObject()); QuestionnairePanel.this.onSave(target, questionnaire); } catch (Exception e) { log.error("Cannot persist questionnaire", e); error("Cannot persist questionnaire: " + e.getMessage()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } } @Override protected void onCancel(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { QuestionnairePanel.this.onCancel(target); } @Override protected void onError(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } }); }
From source file:com.eucalyptus.address.Addresses.java
private static AbstractSystemAddressManager getProvider() { final boolean hasAddressing = Iterables.all(Clusters.getInstance().listValues(), new Predicate<Cluster>() { @Override/*from w w w. j av a 2 s. c o m*/ public boolean apply(Cluster arg0) { return arg0.getState().isAddressingInitialized() && arg0.getState().hasPublicAddressing(); } }); Class<? extends AbstractSystemAddressManager> newManager; if (AddressingConfiguration.getInstance().getDoDynamicPublicAddresses()) { newManager = DynamicSystemAddressManager.class; } else { newManager = StaticSystemAddressManager.class; } if (Addresses.systemAddressManager == null) { systemAddressManager = Classes.newInstance(newManager); } else if (!newManager.equals(systemAddressManager.getClass())) { final AbstractSystemAddressManager oldMgr = systemAddressManager; systemAddressManager = Classes.newInstance(newManager); systemAddressManager.inheritReservedAddresses(oldMgr.getReservedAddresses()); } else { return systemAddressManager; } LOG.info("Setting the address manager to be: " + newManager.getSimpleName()); return systemAddressManager; }
From source file:com.eviware.loadui.ui.fx.views.workspace.CreateNewAgentDialog.java
private boolean validateName(final String name) { if (Strings.isNullOrEmpty(name)) { return false; }// w ww. ja v a2 s . c om return Iterables.all(workspace.getAgents(), new Predicate<AgentItem>() { @Override public boolean apply(AgentItem agent) { return !Objects.equal(name, agent.getLabel()); } }); }
From source file:com.facebook.presto.orc.checkpoint.Checkpoints.java
public static Map<StreamId, StreamCheckpoint> getStreamCheckpoints(Set<Integer> columns, List<OrcType> columnTypes, CompressionKind compressionKind, int rowGroupId, List<ColumnEncoding> columnEncodings, Map<StreamId, Stream> streams, Map<Integer, List<RowGroupIndex>> columnIndexes) throws InvalidCheckpointException { ImmutableSetMultimap.Builder<Integer, StreamKind> streamKindsBuilder = ImmutableSetMultimap.builder(); for (Stream stream : streams.values()) { streamKindsBuilder.put(stream.getColumn(), stream.getStreamKind()); }/*from w w w . j ava 2 s . c om*/ SetMultimap<Integer, StreamKind> streamKinds = streamKindsBuilder.build(); ImmutableMap.Builder<StreamId, StreamCheckpoint> checkpoints = ImmutableMap.builder(); for (int column : columns) { List<Integer> positionsList = columnIndexes.get(column).get(rowGroupId).getPositions(); ColumnEncodingKind columnEncoding = columnEncodings.get(column).getColumnEncodingKind(); OrcTypeKind columnType = columnTypes.get(column).getOrcTypeKind(); Set<StreamKind> availableStreams = streamKinds.get(column); ColumnPositionsList columnPositionsList = new ColumnPositionsList(column, columnType, positionsList); switch (columnType) { case BOOLEAN: checkpoints.putAll(getBooleanColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList)); break; case BYTE: checkpoints.putAll( getByteColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList)); break; case SHORT: case INT: case LONG: case DATE: checkpoints.putAll(getLongColumnCheckpoints(column, columnEncoding, compressionKind, availableStreams, columnPositionsList)); break; case FLOAT: checkpoints.putAll( getFloatColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList)); break; case DOUBLE: checkpoints.putAll( getDoubleColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList)); break; case TIMESTAMP: checkpoints.putAll(getTimestampColumnCheckpoints(column, columnEncoding, compressionKind, availableStreams, columnPositionsList)); break; case BINARY: case STRING: checkpoints.putAll(getSliceColumnCheckpoints(column, columnEncoding, compressionKind, availableStreams, columnPositionsList)); break; case LIST: case MAP: checkpoints.putAll(getListOrMapColumnCheckpoints(column, columnEncoding, compressionKind, availableStreams, columnPositionsList)); break; case STRUCT: checkpoints.putAll( getStructColumnCheckpoints(column, compressionKind, availableStreams, columnPositionsList)); break; case DECIMAL: case CHAR: case VARCHAR: case UNION: throw new IllegalArgumentException("Unsupported column type " + columnType); } // The DWRF code is not meticulous in the handling of checkpoints. It appears that for the first row group // it will write checkpoints for all streams, but in other cases it will write only the streams that exist. // We detect this case by checking that all offsets in the initial position list are zero, and if so, we // clear the extra offsets if (columnPositionsList.hasNextPosition() && !Iterables.all(positionsList, equalTo(0))) { throw new InvalidCheckpointException(format( "Column %s, of type %s, contains %s offset positions, but only %s positions were consumed", column, columnType, positionsList.size(), columnPositionsList.getIndex())); } } return checkpoints.build(); }
From source file:ca.cutterslade.match.scheduler.SadFaceFactor.java
boolean allByes(ImmutableSet<Team> match) { return Iterables.all(match, Team.BYE_PREDICATE); }