/** * Returns the value of a scoped, namespace-constrained key, if it * exists within this collection. * * @param key The key to look up. * @param namespace The namespace to constrain the search to. * @return The value indexed by the key, or {@code null} if it doesn't * exist. */ public Input get(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); return retrieveInput((String)key, namespace); }
/** * Determines whether a scoped, namespace-constrained key * exists within this collection. * * @param key The key to look up. * @param namespace The namespace to constrain the search to. * @return {@code true} if the key exists, {@code false} if not. */ public boolean containsKey(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); LinkedList<T> entities = items.get(key); if (entities == null || entities.size() == 0) return false; String pathMatcher = service.fullpath("", namespace); for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { return true; } } return false; }
/** * {@inheritDoc} */ @Override public Input remove( String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); Input input = retrieveInput(key, namespace); if (input != null) { input.remove(); } return input; }
/** * Gets a the value of a scoped, namespace-constrained key, if it exists * within this collection. * * @param key The key to look up. * @param namespace The namespace to constrain the search to. * @return The value indexed by the key, or {@code null} if it doesn't * exist. */ public T get(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); LinkedList<T> entities = items.get(key); if (entities == null || entities.size() == 0) return null; String pathMatcher = service.fullpath("", namespace); for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { return entity; } } return null; }
private Input retrieveInput(String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); // Because scripted input names are not 1:1 with the original name // (they are the absolute path on the Splunk instance followed by // the original name), we will iterate over the entities in the list, // and if we find one that matches, return it. String pathMatcher = service.fullpath("", namespace); Set<Entry<String, LinkedList<Input>>> set = items.entrySet(); for (Entry<String, LinkedList<Input>> entry: set) { String entryKey = entry.getKey(); LinkedList<Input> entryValue = entry.getValue(); InputKind kind = entryValue.get(0).getKind(); if (InputCollection.matchesInputName(kind, key, entryKey)) { for (Input entity: entryValue) { if (entity.path.startsWith(pathMatcher)) { return entity; } } } } return null; } }
/** * Removes an entity from this collection, with a namespace restriction. * * @param key The name of the entity to remove. * @param namespace The namespace restriction within the collection. * @return This collection. */ public T remove(String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); if (!containsKey(key)) return null; LinkedList<T> entities = items.get(key); String pathMatcher = service.fullpath("", namespace); if (entities == null || entities.size() == 0) return null; for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { entity.remove(); // By invalidating, any access to items will get refreshed invalidate(); return entity; } } return null; } }