@Override protected String renderNullSafe(E object) { return object.getName(); } }
@Override public boolean test(Nameable entity) { return Objects.equals(name, entity.getName()); } }
public SafeHtml getName(T item) { String result = ""; if (item instanceof Nameable) { result = ((Nameable)item).getName(); } return SafeHtmlUtils.fromString(result); }
public static <T> List<T> findItemByName(String name, SearchableListModel<?, T> model) { Collection<T> items = model.getItems(); List<T> namedItems = null; if (items != null) { namedItems = items.stream().filter(item -> item instanceof Nameable && name.equals(((Nameable)item).getName())).collect(Collectors.toList()); } return namedItems; } }
protected Map<String, String> getFragmentParamsFromEntity(T item) { Map<String, String> result = new HashMap<>(); if (item != null) { result.put(FragmentParams.NAME.getName(), ((Nameable) item).getName()); } return result; }
protected SafeHtml getName(T item) { String result = ""; if (item instanceof Nameable) { result = ((Nameable)item).getName(); } return SafeHtmlUtils.fromString(result); }
/** * Map entity's name to entity object. A lot of logic code does filtering of data from 2 collections by quad * iterating over them. Common scenario: entity Parent.name is represent in Child.parentName. Given * List<Parent> and List<Child>, find each child that has parents in List<Parent> * <code> * List<Parent> parents = ... * List<Child> childs = ... * Map<String, Parent> parentsByName = Entities.byName(parents) * for (Child c : childs) { * if(parents.contatinsKey(c.getParentName())) { * doThis(); * } * } * } * </code> */ public static <E extends Nameable> Map<String, E> entitiesByName(Collection<E> entities) { if (entities != null) { Map<String, E> map = new HashMap<>(); for (E e : entities) { map.put(e.getName(), e); } return map; } else { return Collections.emptyMap(); } }
/** * Replace a property defined within a message with a bounded number of elements of {@link Nameable}.<br> * In addition, if a counter appears in the message, it will be replaced with the elements size:<br> * <ul> * <li>The elements' size property name is expected to be {propertyName}_COUNTER</li> * </ul> * * @param propertyName * the property name which represents the collection * @param items * the collection of items to be shown in the message * @return a mutable collection contains two elements:<br> * <ul> * <li>The property name and its replacement items.</li> * <li>The property counter name and the items size.</li> * </ul> */ public static <T extends Nameable> Collection<String> replaceWithNameable(String propertyName, Collection<T> items) { List<Object> printedItems = new ArrayList<>(items.size()); for (Nameable itemName : items) { printedItems.add(itemName.getName()); } return replaceWith(propertyName, printedItems); }
public BusinessEntityMap(Collection<E> entities) { entitiesByName = new HashMap<>(); entitiesById = new HashMap<>(); if (entities != null) { int nullValuedNames = 0; int nullValuedIds = 0; int nonNullEntities = 0; for (E e : entities) { if (e == null) { continue; } nonNullEntities++; if (e.getName() == null) { nullValuedNames++; } else { entitiesByName.put(e.getName(), e); } if (e.getId() == null) { nullValuedIds++; } else { entitiesById.put(e.getId(), e); } } if (entitiesByName.size() + nullValuedNames < nonNullEntities || entitiesById.size() + nullValuedIds < nonNullEntities) { throw new IllegalArgumentException("duplicates in input."); } } }
protected void handleSetMessageQueryResult(FrontendMultipleQueryAsyncResult result) { Map<String, String> entitiesAndQos = new HashMap<>(); setHelpTag(getRemoveQosHelpTag()); setHashName(getRemoveQosHashName()); int index = 0; for (QueryReturnValue returnValue : result.getReturnValues()) { for (Nameable entity : (List<Nameable>) returnValue.getReturnValue()) { entitiesAndQos.put(entity.getName(), sourceListModel.getSelectedItems() .get(index) .getName()); } index++; } if (entitiesAndQos.isEmpty()) { ArrayList<String> list = new ArrayList<>(); for (T item : sourceListModel.getSelectedItems()) { list.add(item.getName()); } setItems(list); } else { setMessage(getRemoveQosMessage(entitiesAndQos.size())); ArrayList<String> list = new ArrayList<>(); for (Entry<String, String> item : entitiesAndQos.entrySet()) { list.add(item.getKey() + " (" + item.getValue() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } setItems(list); } }
protected void handleSetMessageQueryResult(FrontendMultipleQueryAsyncResult result) { setHelpTag(getRemoveQosHelpTag()); setHashName(getRemoveQosHashName()); int index = 0; int numberOfTimesUsedByDiskProfiles = 0; ArrayList<String> list = new ArrayList<>(); for (QueryReturnValue returnValue : result.getReturnValues()) { List<Nameable> diskProfileEntities = returnValue.getReturnValue(); String qosName = sourceListModel.getSelectedItems().get(index).getName(); if (diskProfileEntities.size() == 0) { list.add(qosName); } else { numberOfTimesUsedByDiskProfiles += diskProfileEntities.size(); List<String> diskProfileNames = new ArrayList<>(); for (Nameable diskProfileEntity : diskProfileEntities) { String diskProfileName = diskProfileEntity.getName(); diskProfileNames.add(diskProfileName); } String diskProfileNamesAsString = String.join(", ", diskProfileNames); //$NON-NLS-1$ list.add(ConstantsManager.getInstance().getMessages().removeStorageQoSItem(qosName, diskProfileNamesAsString)); } index++; } setMessage(getRemoveQosMessage(numberOfTimesUsedByDiskProfiles)); setItems(list); }