/** * Returns the element at the provided position in this iterable. * In order to return the element, an iterator needs to be traversed * up to the requested position. * * @param position the position of the element to return * @return the element * @throws IndexOutOfBoundsException if the provided position is outside the * valid range of this iterable: [0, size) */ public E get(final int position) { return IterableUtils.get(iterable, position); }
/** * Shortcut for {@code get(iterator, 0)}. * <p> * Returns the <code>first</code> value in the <code>iterable</code>'s {@link Iterator}, throwing * <code>IndexOutOfBoundsException</code> if there is no such element. * </p> * <p> * If the {@link Iterable} is a {@link List}, then it will use {@link List#get(int)}. * </p> * * @param <T> the type of object in the {@link Iterable}. * @param iterable the {@link Iterable} to get a value from, may be null * @return the first object * @throws IndexOutOfBoundsException if the request is invalid * @since 4.2 */ public static <T> T first(final Iterable<T> iterable) { return get(iterable, 0); }
/** * Returns the <code>index</code>-th value in the <code>iterable</code>'s {@link Iterator}, throwing * <code>IndexOutOfBoundsException</code> if there is no such element. * <p> * If the {@link Iterable} is a {@link List}, then it will use {@link List#get(int)}. * * @param iterable the {@link Iterable} to get a value from * @param index the index to get * @param <T> the type of object in the {@link Iterable}. * @return the object at the specified index * @throws IndexOutOfBoundsException if the index is invalid * @deprecated since 4.1, use {@code IterableUtils.get(Iterable, int)} instead */ @Deprecated public static <T> T get(final Iterable<T> iterable, final int index) { return IterableUtils.get(iterable, index); }
} else if (object instanceof Iterable<?>) { final Iterable<?> iterable = (Iterable<?>) object; return IterableUtils.get(iterable, i); } else if (object instanceof Enumeration<?>) { final Enumeration<?> it = (Enumeration<?>) object;
@Override public String getTranslatedName() { Collection<?> translated = getTranslatedValues(NAME_KEY); if (CollectionUtils.isEmpty(translated)) { return null; } return (String) IterableUtils.get(translated, 0); }
@Override public String getTranslatedDescription() { Collection<?> translated = getTranslatedValues(DESCRIPTION_KEY); if (CollectionUtils.isEmpty(translated)) { return null; } return (String) IterableUtils.get(translated, 0); }
/** * For property predicates, gets the single object connected from the specified subject, if any. If this isn't a * *-to-one predicate, and multiple objects are connected from the subject, {@code null} is returned. * * @param subject the subject to get the property from * @return an object, or {@code null} if not set */ @Nullable default O get(@Nonnull S subject) { if (subject == null) { throw new IllegalArgumentException(); } Collection<O> objects = this.getAllConnections(subject); if (objects.size() == 1) { return IterableUtils.get(objects, 0); } return null; }
/** * @param method the method * @param searchTopMethod search for top most overridden method * @return the corresponding element name */ public static String getElementName(Method method, boolean searchTopMethod) { Method topMethod = method; if (searchTopMethod) { // Get top most method declaration Set<Method> hierarchy = MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE); topMethod = IterableUtils.get(hierarchy, hierarchy.size() - 1); } // Get element name from method return getElementName(topMethod); }
protected void selectAttachmentDialog(SendingMessage message) { openLookup("sys$SendingMessage.attachments", items -> { if (items.size() == 1) { exportFile((SendingAttachment) IterableUtils.get(items, 0)); } }, OpenType.DIALOG, ParamsMap.of("message", message)); }
/** * Gets a unique storage from the given business object data. The given business object data must have one and only one storage unit with a storage, * otherwise this method throws an exception. * * @param businessObjectDataEntity the business object data entity * * @return the unique storage entity */ private StorageEntity getUniqueStorage(BusinessObjectDataEntity businessObjectDataEntity) { Collection<StorageUnitEntity> targetStorageUnits = businessObjectDataEntity.getStorageUnits(); Assert.notEmpty(targetStorageUnits, "No storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); Assert.isTrue(targetStorageUnits.size() == 1, "More than 1 storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); return IterableUtils.get(targetStorageUnits, 0).getStorage(); }
/** * Gets a unique storage from the given business object data. The given business object data must have one and only one storage unit with a storage, * otherwise this method throws an exception. * * @param businessObjectDataEntity the business object data entity * * @return the unique storage entity */ private StorageEntity getUniqueStorage(BusinessObjectDataEntity businessObjectDataEntity) { Collection<StorageUnitEntity> targetStorageUnits = businessObjectDataEntity.getStorageUnits(); Assert.notEmpty(targetStorageUnits, "No storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); Assert.isTrue(targetStorageUnits.size() == 1, "More than 1 storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\"."); return IterableUtils.get(targetStorageUnits, 0).getStorage(); }
@Override public boolean isPermitted() { if (super.isPermitted()) { Set<ChartSeries> items = seriesTable.getSelected(); if (!CollectionUtils.isEmpty(items) && items.size() == 1) { Integer order = (IterableUtils.get(items, 0)).getOrder(); if (order != null) { return up ? order > 1 : order < seriesDs.size(); } } } return false; } }
@Override public void actionPerform(Component component) { ChartSeries selected = seriesTable.getSingleSelected(); //noinspection ConstantConditions Integer currentOrder = selected.getOrder(); Integer newOrder = up ? currentOrder - 1 : currentOrder + 1; Collection<ChartSeries> items = seriesDs.getItems(); ChartSeries changing = IterableUtils.get(items, currentOrder - 1); ChartSeries neighbor = IterableUtils.get(items, newOrder - 1); changing.setOrder(newOrder); neighbor.setOrder(currentOrder); sortSeriesByOrder(); }
@Test public void testRemovingAllWillNotRemoveLast() { // setup Set<Security> values = EnumUtils.values(Security.class); // execute IterableUtils.forEach(values, new ToggleClosure()); // validate IterableUtils.forEachButLast(values, new RemovedClosure()); assertTrue(fixture.contains(IterableUtils.get(values, values.size() - 1))); }
@Test public void testRemovingAllWillNotRemoveLast() { // setup Set<WiFiBand> values = EnumUtils.values(WiFiBand.class); // execute IterableUtils.forEach(values, new ToggleClosure()); // validate IterableUtils.forEachButLast(values, new RemovedClosure()); assertTrue(fixture.contains(IterableUtils.get(values, values.size() - 1))); }
@Test public void testRemovingAllWillNotRemoveLast() { // setup Set<Strength> values = EnumUtils.values(Strength.class); // execute IterableUtils.forEach(values, new ToggleClosure()); // validate IterableUtils.forEachButLast(values, new RemovedClosure()); assertTrue(fixture.contains(IterableUtils.get(values, values.size() - 1))); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdatedAttributeNamesEqualIgnoreCase() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper .updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME.toUpperCase(), result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueNotUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeAdded() { // Create a list of attributes. List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE)); // Create a business object data entity without attributes. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setAttributes(new ArrayList<>()); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(businessObjectDataEntity, businessObjectDataAttributeEntity.getBusinessObjectData()); assertEquals(ATTRIBUTE_NAME, businessObjectDataAttributeEntity.getName()); assertEquals(ATTRIBUTE_VALUE, businessObjectDataAttributeEntity.getValue()); }