List of usage examples for com.google.common.collect Maps asConverter
@Beta public static <A, B> Converter<A, B> asConverter(final BiMap<A, B> bimap)
From source file:org.opendaylight.yangtools.yang.data.api.schema.xpath.PrefixConverters.java
/** * Create a prefix {@link Converter} for {@link XPathExpressionException} defined in a particular YANG * {@link Module} .Instantiation requires establishing how a module's imports are mapped to actual modules * and their namespaces. This information is cached and used for improved lookups. * * @param ctx A SchemaContext//from ww w. ja v a 2 s . c o m * @param module Module in which the XPath is defined * @return A new Converter */ public static @Nonnull Converter<String, QNameModule> create(final SchemaContext ctx, final Module module) { // Always check for null ctx Preconditions.checkNotNull(ctx, "Schema context may not be null"); // Use immutable map builder for detection of duplicates (which should never occur) final Builder<String, QNameModule> b = ImmutableBiMap.builder(); b.put(module.getPrefix(), module.getQNameModule()); for (ModuleImport i : module.getImports()) { final Module mod = ctx.findModuleByName(i.getModuleName(), i.getRevision()); Preconditions.checkArgument(mod != null, "Unsatisfied import of %s by module %s", i, module); b.put(i.getPrefix(), mod.getQNameModule()); } return Maps.asConverter(b.build()); }