List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.glowroot.agent.live.ClasspathCache.java
private static void loadClassNamesFromDirectory(File dir, String prefix, Location location, Multimap<String, Location> newClassNameLocations) throws MalformedURLException { File[] files = dir.listFiles(); if (files == null) { return;//from w w w. j av a 2 s . c o m } for (File file : files) { String name = file.getName(); if (file.isFile() && name.endsWith(".class")) { String className = prefix + name.substring(0, name.lastIndexOf('.')); newClassNameLocations.put(className, location); } else if (file.isDirectory()) { loadClassNamesFromDirectory(file, prefix + name + ".", location, newClassNameLocations); } } }
From source file:jef.tools.collection.CollectionUtils.java
/** * ?/*from w w w.j ava2s .co m*/ * * @param collection * ?? * @param function * ?Key * @return ???Key?Value */ public static <T, A> Multimap<A, T> group(Collection<T> collection, Function<T, A> function) { Assert.notNull(collection); Multimap<A, T> result = ArrayListMultimap.create(); for (T value : collection) { A attrib = function.apply(value); result.put(attrib, value); } return result; }
From source file:org.jetbrains.jet.lang.types.SubstitutionUtils.java
private static void fillInDeepSubstitutor(@NotNull JetType context, @NotNull TypeSubstitutor substitutor, @NotNull Map<TypeConstructor, TypeProjection> substitution, @Nullable Multimap<TypeConstructor, TypeProjection> fullSubstitution) { List<TypeParameterDescriptor> parameters = context.getConstructor().getParameters(); List<TypeProjection> arguments = context.getArguments(); if (parameters.size() != arguments.size()) { throw new IllegalStateException(); }/* w w w. ja v a 2s .c om*/ for (int i = 0; i < arguments.size(); i++) { TypeProjection argument = arguments.get(i); TypeParameterDescriptor typeParameterDescriptor = parameters.get(i); JetType substitute = substitutor.substitute(argument.getType(), Variance.INVARIANT); assert substitute != null; TypeProjection substitutedTypeProjection = new TypeProjection(argument.getProjectionKind(), substitute); substitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection); if (fullSubstitution != null) { fullSubstitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection); } } if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return; for (JetType supertype : context.getConstructor().getSupertypes()) { fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution); } }
From source file:org.prebake.service.tools.JarProcess.java
static byte extractJar(Path cwd, String... argv) throws IOException { int pos = 0;/* w ww . jav a2s .c o m*/ int last = argv.length - 1; Path root = cwd.getRoot(); String jarFile = argv[++pos]; MutableGlobSet globs = new MutableGlobSet(); Multimap<Glob, Path> outRoots = Multimaps.newListMultimap(Maps.<Glob, Collection<Path>>newHashMap(), new Supplier<List<Path>>() { public List<Path> get() { return Lists.newArrayList(); } }); while (pos < last) { String globStr = argv[++pos]; Glob g = Glob.fromString(globStr); String treeRoot = g.getTreeRoot(); if (!"".equals(treeRoot)) { globStr = globStr.substring(treeRoot.length()); if (globStr.startsWith("///")) { globStr = globStr.substring(3); } g = Glob.fromString(globStr); } if (outRoots.get(g).isEmpty()) { globs.add(g); } outRoots.put(g, cwd.resolve(FsUtil.denormalizePath(root, treeRoot))); } ZipInputStream in = new ZipInputStream(cwd.resolve(jarFile).newInputStream()); try { Set<Path> dests = Sets.newLinkedHashSet(); for (ZipEntry e; (e = in.getNextEntry()) != null;) { Path path = root.getFileSystem().getPath(FsUtil.denormalizePath(root, e.getName())); dests.clear(); for (Glob g : globs.matching(path)) { dests.addAll(outRoots.get(g)); } if (e.isDirectory()) { for (Path dest : dests) { mkdirs(dest.resolve(path)); } } else { if (!dests.isEmpty()) { OutputStream[] outs = new OutputStream[dests.size()]; try { Iterator<Path> it = dests.iterator(); for (int i = 0; i < outs.length; ++i) { Path outFile = it.next().resolve(path); mkdirs(outFile.getParent()); outs[i] = outFile.newOutputStream(StandardOpenOption.CREATE_NEW, StandardOpenOption.TRUNCATE_EXISTING); } byte[] buf = new byte[4096]; for (int nRead; (nRead = in.read(buf)) > 0;) { for (OutputStream os : outs) { os.write(buf, 0, nRead); } } } finally { for (OutputStream os : outs) { if (os != null) { Closeables.closeQuietly(os); } } } } in.closeEntry(); } } } finally { in.close(); } return 0; }
From source file:org.jfrog.build.extractor.clientConfiguration.util.PublishedItemsHelper.java
/** * Building a multi map of target paths mapped to their files. * * @param checkoutDir the base directory of which to calculate the given source ant pattern * @param pattern the Ant pattern to calculate the files from * @param targetPath the target path for deployment of a file * @return a Multimap containing the targets as keys and the files as values * @throws IOException in case of any file system exception *//*from w ww .ja va2 s.c o m*/ @Deprecated public static Multimap<String, File> buildPublishingData(File checkoutDir, String pattern, String targetPath) throws IOException { final Multimap<String, File> filePathsMap = HashMultimap.create(); File patternAbsolutePath = getAbsolutePath(checkoutDir, pattern); if (patternAbsolutePath.isFile()) { // The given pattern is an absolute path of just one file, let's add it to our result map filePathsMap.put(targetPath, patternAbsolutePath); } else { Pattern filePattern = null; File patternDir = null; if (patternAbsolutePath.isDirectory()) { // The given pattern is a path to a directory, we need to return all it's content filePattern = Pattern.compile(".*"); patternDir = patternAbsolutePath; } else if (pattern.indexOf('*') >= 0 || pattern.indexOf('?') >= 0) { // We are dealing with complex Ant pattern, need to analyze it File baseTruncationDir = getBaseTruncationDir(patternAbsolutePath); patternDir = baseTruncationDir != null ? baseTruncationDir : checkoutDir; // If the checkout dir is an ancestor of the pattern path then // we cut the checkout dir from the pattern boolean isCheckoutDirAncestor = isAncestor(checkoutDir, patternAbsolutePath); if (isCheckoutDirAncestor) { pattern = pattern.substring( patternDir.getAbsolutePath().length() - checkoutDir.getAbsolutePath().length()); } // If the pattern absolute path starts with the pattern directory path // then we need to cut the pattern to be only the relative path String patternAbsolutePathUrl = patternAbsolutePath.getAbsolutePath(); if (!StringUtils.isBlank(patternAbsolutePathUrl) && patternAbsolutePathUrl.startsWith(patternDir.getAbsolutePath())) { pattern = getRelativePath(patternDir, patternAbsolutePath); } // All done, we can now convert and compile from Ant pattern to regular expression filePattern = Pattern.compile(convertAntToRegexp(pattern)); } // If we successfully converted from Ant pattern to a regular expression // then it's time to collect all our artifacts according to this regular expression if (filePattern != null) { List<File> files = new ArrayList<File>(); collectMatchedFiles(patternDir, patternDir, filePattern, files); for (File file : files) { String fileTargetPath = calculateFileTargetPath(patternDir, file, targetPath); filePathsMap.put(fileTargetPath, file); } } } return filePathsMap; }
From source file:org.jnario.scoping.JnarioExtensionClassNameProvider.java
@Override protected Multimap<Class<?>, Class<?>> simpleComputeExtensionClasses() { Multimap<Class<?>, Class<?>> result = super.simpleComputeExtensionClasses(); result.put(ExampleTable.class, ExampleTableIterators.class); // result.replaceValues(Object.class, ImmutableList.of(Should.class, Each.class, ObjectExtensions.class)); result.put(Object.class, Should.class); result.put(Object.class, Each.class); result.put(String.class, StringConversions.class); result.put(Iterable.class, JnarioIterableExtensions.class); result.put(Iterator.class, JnarioIteratorExtensions.class); return result; }
From source file:com.github.drbookings.ui.controller.BookingEntryMonthBins.java
@Override public Collection<BookingEntryBin<YearMonth>> getBins() { Multimap<YearMonth, BookingEntry> result = ArrayListMultimap.create(); elements.forEach(e -> result.put(YearMonth.from(e.getDate()), e)); Collection<BookingEntryBin<YearMonth>> result2 = new ArrayList<>(); result.asMap().forEach((k, v) -> result2.add(new BookingEntryBin<>(k, v))); return result2; }
From source file:org.napile.compiler.lang.resolve.processors.OverrideResolver.java
public static Multimap<CallableMemberDescriptor, CallableMemberDescriptor> collectSuperMethods( MutableClassDescriptor classDescriptor) { Set<CallableMemberDescriptor> inheritedFunctions = Sets.newLinkedHashSet(); for (NapileType supertype : classDescriptor.getSupertypes()) { for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) { if (descriptor instanceof CallableMemberDescriptor) { CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor; inheritedFunctions.add(memberDescriptor); }/* www . java 2 s . c o m*/ } } // Only those actually inherited Set<CallableMemberDescriptor> filteredMembers = OverridingUtil.filterOverrides(inheritedFunctions); // Group members with "the same" signature Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = CommonSuppliers .newLinkedHashSetHashSetMultimap(); for (CallableMemberDescriptor one : filteredMembers) { if (factoredMembers.values().contains(one)) continue; for (CallableMemberDescriptor another : filteredMembers) { // if (one == another) continue; factoredMembers.put(one, one); if (OverridingUtil.isOverridableBy(one, another) .getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE || OverridingUtil.isOverridableBy(another, one) .getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) { factoredMembers.put(one, another); } } } return factoredMembers; }
From source file:matteroverdrive.data.biostats.BioticStatAttack.java
@Override @SuppressWarnings("unchecked") public Multimap attributes(AndroidPlayer androidPlayer, int level) { Multimap multimap = HashMultimap.create(); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new MOAttributeModifier(modifierID, "Android Attack Damage", getAttackPower(level), 1) .setSaved(false));// www. j a v a2s.com return multimap; }
From source file:matteroverdrive.data.biostats.BioticStatSpeed.java
@Override public Multimap attributes(AndroidPlayer androidPlayer, int level) { Multimap multimap = HashMultimap.create(); multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new MOAttributeModifier(modifierID, "Android Speed", getSpeedModify(level), 2).setSaved(false)); return multimap; }