/** * Appends all of the missing elements from the specified collection to the end of * this list, in the order that they are returned by the * specified collection's Iterator. The behavior of this operation is * undefined if the specified collection is modified while the operation * is in progress. (This implies that the behavior of this call is * undefined if the specified collection is this list, and this * list is nonempty.) * * @param c collection containing elements to be added to this list * @return <tt>true</tt> if this list changed as a result of the call * @since 2.1.0 */ public boolean addMissing(@NonNull Collection<? extends Option> c) { Set<String> existing = new HashSet<String>(); for (Option o: this) { existing.add(o.value); } boolean changed = false; for (Option o : c) { if (!existing.contains(o.value)) { add(o); changed = existing.add(o.value) || changed; } } return changed; } }
/** * Appends all of the missing elements from the specified collection to the end of * this list, in the order that they are returned by the * specified collection's Iterator. The behavior of this operation is * undefined if the specified collection is modified while the operation * is in progress. (This implies that the behavior of this call is * undefined if the specified collection is this list, and this * list is nonempty.) * * @param c collection containing elements to be added to this list * @return <tt>true</tt> if this list changed as a result of the call * @since 2.1.0 */ public boolean addMissing(@NonNull Collection<? extends Option> c) { Set<String> existing = new HashSet<String>(); for (Option o: this) { existing.add(o.value); } boolean changed = false; for (Option o : c) { if (!existing.contains(o.value)) { add(o); changed = existing.add(o.value) || changed; } } return changed; } }
/** * Adds an "empty" credential to signify selection of no credential. * * @return {@code this} for method chaining. * @since 2.1.0 */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> includeEmptyValue() { for (Option a : this) { if (StringUtils.equals("", a.value)) { return this; } } add(0, new Option(Messages.AbstractIdCredentialsListBoxModel_EmptySelection(), "")); return this; }
/** * Adds an "empty" credential to signify selection of no credential. * * @return {@code this} for method chaining. * @since 2.1.0 */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> includeEmptyValue() { for (Option a : this) { if (StringUtils.equals("", a.value)) { return this; } } add(0, new Option(Messages.AbstractIdCredentialsListBoxModel_EmptySelection(), "")); return this; }
/** * Ensures that the current value is present so that the form can be idempotently saved in those cases where the * user saving the form cannot view the current credential * * @param value the current value. * @return {@code this} for method chaining. * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeCurrentValue(@NonNull String value) { if (StringUtils.isEmpty(value)) { return includeEmptyValue(); } for (Option a : this) { if (StringUtils.equals(value, a.value)) { return this; } } // the current should be the first (unless the first is the empty selection int index = isEmpty() ? 0 : "".equals(get(0).value) ? 1 : 0; add(index, new Option(Messages.AbstractIdCredentialsListBoxModel_CurrentSelection(), value)); return this; }
/** * Adds a single credential. * * @param u the credential to add. * @return {@code this} for method chaining. */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> with(@CheckForNull C u) { if (u != null) { add(describe(u), u.getId()); } return this; }
/** * Ensures that the current value is present so that the form can be idempotently saved in those cases where the * user saving the form cannot view the current credential * * @param value the current value. * @return {@code this} for method chaining. * @since 2.1.0 */ public AbstractIdCredentialsListBoxModel<T, C> includeCurrentValue(@NonNull String value) { if (StringUtils.isEmpty(value)) { return includeEmptyValue(); } for (Option a : this) { if (StringUtils.equals(value, a.value)) { return this; } } // the current should be the first (unless the first is the empty selection int index = isEmpty() ? 0 : "".equals(get(0).value) ? 1 : 0; add(index, new Option(Messages.AbstractIdCredentialsListBoxModel_CurrentSelection(), value)); return this; }
/** * Adds a single credential. * * @param u the credential to add. * @return {@code this} for method chaining. */ @NonNull public AbstractIdCredentialsListBoxModel<T, C> with(@CheckForNull C u) { if (u != null) { add(describe(u), u.getId()); } return this; }