/** * Check whether mapping is present for name. * * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction * * @return true if present, false otherwise */ public synchronized boolean containsIndex(final String name, final MappingContext mappingContext) { return mappingContext.read(getMappingIid(name)).isPresent(); }
/** * Remove mapping from current context * * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void removeName(final String name, final MappingContext mappingContext) { mappingContext.delete(getMappingIid(name)); }
/** * Returns index value associated with the given name. * * @param name the name whose associated index value is to be returned * @param mappingContext mapping context providing context data for current transaction * * @return integer index value matching supplied name * @throws IllegalArgumentException if name was not found */ public synchronized int getIndex(final String name, final MappingContext mappingContext) { final Optional<Mapping> read = mappingContext.read(getMappingIid(name)); checkArgument(read.isPresent(), "No mapping stored for name: %s", name); return read.get().getIndex(); }
/** * Add mapping to current context * * @param index index of a mapped item * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void addName(final int index, final String name, final MappingContext mappingContext) { final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = getMappingIid(name); mappingContext.put(mappingIid, new MappingBuilder().setIndex(index).setName(name).build()); }