if (!inventory.containsKey(item)) throw new InventoryException("Can't remove something you don't have"); inventory.put(item, inventory.get(item) - 1); if (inventory.get(item) == 0) inventory.remove(item);
public Builder with(Query other) { with(other.fragments); for (Query sub : other.getSubTrees()) { branch().with(sub).done(); } return this; }
/** * @return appends the select candidates to the source path. The only difference between this and {@link #select()} * is that this method returns the extender set up to append path fragments. */ Query.SymmetricExtender hop() { return sourcePath.extend().path().withExact(selectCandidates).path(); }
@Override public Single visitResource(Void parameter) { Tenants.Single tenant = tenants().get(ids.getTenantId()); Resources.Single access; if (ids.getFeedId() == null) { access = tenant.environments().get(ids.getEnvironmentId()).resources() .descendContained(ids.getResourcePath()); } else { access = tenant.feeds().get(ids.getFeedId()).resources().descendContained(ids.getResourcePath()); } return accessInterface.cast(access); }
public static String of(MetadataPack mp, Inventory inventory) { List<Entity<? extends Entity.Blueprint, ?>> all = new ArrayList<>(); all.addAll(inventory.inspect(mp).resourceTypes().getAll().entities()); all.addAll(inventory.inspect(mp).metricTypes().getAll().entities()); return of(all, inventory); }
@Override public Single visitMetricType(Void parameter) { Tenants.Single ten = tenants().get(ids.getTenantId()); return accessInterface.cast(ids.getFeedId() == null ? ten.metricTypes().get(ids.getMetricTypeId()) : ten.feeds().get(ids.getFeedId()).metricTypes() .get(ids.getMetricTypeId())); }
@Override public Single visitResourceType(Void parameter) { Tenants.Single ten = tenants().get(ids.getTenantId()); return accessInterface.cast(ids.getFeedId() == null ? ten.resourceTypes().get(ids.getResourceTypeId()) : ten.feeds().get(ids.getFeedId()).resourceTypes() .get(ids.getResourceTypeId())); }
@SuppressWarnings("unchecked") static <B extends Blueprint, E extends AbstractElement<B, ?>> Class<? extends E> getEntityTypeOf(B blueprint) { return (Class<? extends E>) Inventory.types().byBlueprint(blueprint.getClass()).getElementType(); }
public boolean getFlag(String key, String defaultValue) { return getFlag(Property.builder().withPropertyNameAndSystemProperty(key).build(), defaultValue); }
@Override public Single visitEnvironment(Void parameter) { return accessInterface.cast(tenants().get(ids.getTenantId()).environments() .get(ids.getEnvironmentId())); }
/** * Appends the provided query to the leaves of the current query tree, converting all its fragments to the * current fragment type (determined by the last call to {@link #filter()} or {@link #path()}). * * @param other the query to append * @return this instance */ public SymmetricExtender with(Query other) { onLeaves(this.filters, (builder) -> builder.with(other, converter)); return this; }
/** * @return a new symmetric builder initialized with this query */ public SymmetricExtender extend() { return new SymmetricExtender(asBuilder()); }
/** * If the inventory configuration provided a {@link ResultFilter}, this calls it to tell whether provided element * is applicable. If the result filter is not provided by the configuration, true will always be returned. * * @param result the potential result to be checked for applicability in the result set * @return true or false (!!!) */ protected boolean isApplicable(AbstractElement<?, ?> result) { ResultFilter filter = context.configuration.getResultFilter(); return filter == null || filter.isApplicable(result); }
public Builder with(Query other, Function<Filter, QueryFragment> converter) { with(converter, other.fragments); for (Query sub : other.getSubTrees()) { branch().with(sub, converter).done(); } return this; }
/** * Appends the provided query to the leaves of the current query tree, leaving the type of its fragments as they * originally were. * * @param other the query to append * @return this instance */ public SymmetricExtender withExact(Query other) { onLeaves(this.filters, (builder) -> builder.with(other)); return this; }