/** * Creates a subset of this list using the given filter. * * @param filter the product node filter to be used, if <code>null</code> a clone of this list is created * * @return the subset */ public ProductNodeList<T> createSubset(ProductNodeFilter<T> filter) { ProductNodeList<T> list = new ProductNodeList<T>(); for (int i = 0; i < size(); i++) { T node = getAt(i); if (filter.accept(node)) { list.add(node); } } return list; }
/** * @param displayName the display name * @return the product node with the given display name. */ public T getByDisplayName(final String displayName) { return nodeList.getByDisplayName(displayName); }
/** * Returns the display names of all products currently managed. * * @return an array containing the display names, never <code>null</code>, but the array can have zero length * @see ProductNode#getDisplayName() */ public String[] getNodeDisplayNames() { return nodeList.getDisplayNames(); }
/** * Releases all of the resources used by this object instance and all of its owned children. Its primary use is to * allow the garbage collector to perform a vanilla job. * <p/> * <p>This method should be called only if it is for sure that this object instance will never be used again. The * results of referencing an instance of this class after a call to <code>dispose()</code> are undefined. */ public final void dispose() { for (int i = 0; i < size(); i++) { getAt(i).dispose(); } removeAll(); disposeRemovedList(); }
final ProductNodeList<MetadataElement> metadataElementBackup = new ProductNodeList<>(); if (!saveProductHeaders) { String[] headerNames = new String[]{ for (String headerName : headerNames) { MetadataElement element = metadataRoot.getElement(headerName); metadataElementBackup.add(element); metadataRoot.removeElement(element); metadataElementBackup.add(element); metadataRoot.removeElement(element); if (name.endsWith("ADS") || name.endsWith("Ads") || name.endsWith("ads")) { final MetadataElement element = metadataRoot.getElement(name); metadataElementBackup.add(element); metadataRoot.removeElement(element); } else { if (metadataRoot != null) { final MetadataElement[] elementsArray = new MetadataElement[metadataElementBackup.size()]; metadataElementBackup.toArray(elementsArray); for (final MetadataElement metadataElement : elementsArray) { metadataRoot.addElement(metadataElement);
public void testAddAndRemoveAndSize() { assertEquals(_nodeList.size(), 0); _nodeList.add(_attribute1); assertEquals(_nodeList.size(), 1); _nodeList.add(_attribute2); assertEquals(_nodeList.size(), 2); _nodeList.add(_attribute3); assertEquals(_nodeList.size(), 3); _nodeList.add(_attribute4); assertEquals(_nodeList.size(), 4); _nodeList.remove(_attribute1); assertEquals(_nodeList.size(), 3); _nodeList.removeAll(); assertEquals(_nodeList.size(), 0); }
/** * Gets the index of the node with the given name. The method performs a case insensitive search. * * @param name the name of the node, must not be <code>null</code> * * @return the index of the node with the given name or <code>-1</code> if a node with the given name is not * contained in this list * * @throws IllegalArgumentException if the name is <code>null</code> */ public final int indexOf(String name) { Guardian.assertNotNull("name", name); int n = size(); for (int i = 0; i < n; i++) { if (getAt(i).getName().equalsIgnoreCase(name)) { return i; } } return -1; }
private void openBandArithmeticDialog(final VisatApp visatApp, final String helpId) { final Product[] prods = visatApp.getProductManager().getProducts(); final ProductNodeList<Product> products = new ProductNodeList<Product>(); for (Product prod : prods) { products.add(prod); } BandMathsDialog bandMathsDialog = new BandMathsDialog(visatApp, visatApp.getSelectedProduct(), products, helpId); bandMathsDialog.show(); } }
/** * @return The number of products in this product manager. */ public int getProductCount() { return productList.size(); }
private Product newProductImpl() { if (getProductManager().getProductCount() == 0) { return null; } final ProductNodeList<Product> products = new ProductNodeList<>(); products.copyInto(getProductManager().getProducts()); final Product selectedProduct = getSelectedProduct(); if (selectedProduct == null) { return null; } final int selectedSourceIndex = products.indexOf(selectedProduct); final NewProductDialog dialog = new NewProductDialog(getMainFrame(), products, selectedSourceIndex, false); if (dialog.show() != NewProductDialog.ID_OK) { return null; } final Product product = dialog.getResultProduct(); if (product != null) { addProduct(product); updateState(); } else if (dialog.getException() != null) { showErrorDialog("The product subset could not be created:\n" + dialog.getException().getMessage()); } return product; }
/** * Tests if this list contains a node with the given name. * * @param name the name of the node, must not be <code>null</code> * * @return true if this list contains a node with the given name. * * @throws IllegalArgumentException if the name is <code>null</code> */ public final boolean contains(String name) { return indexOf(name) >= 0; }
boolean enableSourceProduct; if (editProduct == null) { valueSet = sourceProducts.getDisplayNames(); Product product = (Product) sourceProducts.getAt(selectedProductIndex); prodName = createNewProductName(valueSet.length > 0 ? product.getName() : ""); prodDesc = "";
/** * Removes the given product from this product manager if it exists. * * @param product the product to be removed, ignored if <code>null</code> * @return true, if the product was removed */ public boolean removeProduct(Product product) { if (product != null) { int index = productList.indexOf(product); if (index >= 0) { if (productList.remove(product)) { productList.clearRemovedList(); product.removeProductNodeListener(productNodeNameChangeListener); product.resetRefNo(); clearProductManager(product); fireEvent(product, PRODUCT_REMOVED); return true; } } } return false; }
/** * Gets the product at the given index. * * @param index the index * @return The product at the given index. */ public Product getProduct(int index) { return productList.getAt(index); }
/** * Copies the product nodes of this product node list into the specified array. The array must be big enough to hold * all the product nodes in this product node list, else an <tt>IndexOutOfBoundsException</tt> is thrown. * * @param array the array into which the product nodes get copied. * * @throws NullPointerException if the given array is null. * @throws IndexOutOfBoundsException if the given array is to small. */ public final void copyInto(T[] array) { for (T node : array) { add(node); } }
/** * Returns an array of all products currently managed. * * @return an array containing the products, never <code>null</code>, but the array can have zero length */ public ProductNode[] toArray() { return nodeList.toArray(); }
/** * Constructs an product manager with an empty list of products. */ public ProductManager() { productList = new ProductNodeList<Product>(); productNodeNameChangeListener = new ProductNodeNameChangeListener(); }
/** * Tests whether a product with the given name is contained in this list. * * @param name the product name * @return true, if so */ public boolean containsProduct(String name) { return productList.contains(name); }
/** * @param name The product name. * @return The product with the given name. */ public Product getProduct(String name) { return productList.get(name); }
private Product[] getCompatibleProducts() { List<Product> compatibleProducts = new ArrayList<Product>(productsList.size()); compatibleProducts.add(targetProduct); final float geolocationEps = getGeolocationEps(); Debug.trace("BandMathsDialog.geolocationEps = " + geolocationEps); Debug.trace("BandMathsDialog.getCompatibleProducts:"); Debug.trace(" comparing: " + targetProduct.getName()); for (int i = 0; i < productsList.size(); i++) { final Product product = productsList.getAt(i); if (targetProduct != product) { Debug.trace(" with: " + product.getDisplayName()); final boolean isCompatibleProduct = targetProduct.isCompatibleProduct(product, geolocationEps); Debug.trace(" result: " + isCompatibleProduct); if (isCompatibleProduct) { compatibleProducts.add(product); } } } return compatibleProducts.toArray(new Product[compatibleProducts.size()]); }