下面列出了com.google.common.collect.Multimap#entries ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
Space(Multimap<Method, MetadataHandler> providerMap) {
this.providerMap = ImmutableMultimap.copyOf(providerMap);
// Find the distinct set of RelNode classes handled by this provider,
// ordered base-class first.
for (Map.Entry<Method, MetadataHandler> entry : providerMap.entries()) {
final Method method = entry.getKey();
final MetadataHandler provider = entry.getValue();
for (final Method handlerMethod : provider.getClass().getMethods()) {
if (couldImplement(handlerMethod, method)) {
@SuppressWarnings("unchecked") final Class<RelNode> relNodeClass =
(Class<RelNode>) handlerMethod.getParameterTypes()[0];
classes.add(relNodeClass);
handlerMap.put(Pair.of(relNodeClass, method), handlerMethod);
}
}
}
}
private boolean assertExpectedTfRecords(Multimap<String,Pair<String,Integer>> expectedTfValues, Multimap<BulkIngestKey,Value> tfEntries,
StringBuilder errorMessage) {
for (Map.Entry<String,Pair<String,Integer>> entry : expectedTfValues.entries()) {
Text expectedColf = new Text(TF);
Text expectedColq = new Text(TEST_TYPE + INTRA_COL_DELIMETER + TEST_UUID + INTRA_COL_DELIMETER + entry.getValue().getLeft() + INTRA_COL_DELIMETER
+ entry.getKey());
int count = entry.getValue().getRight().intValue();
byte[] expectedValue = {(byte) 24, (byte) count};
Collection<Value> values = assertContainsKey(SHARD_ID, SHARD_TABLE_NAME, expectedColf, expectedColq, tfEntries);
if (values != null) {
for (Value value : values) {
if (Arrays.equals(value.get(), expectedValue)) {
return true;
}
}
errorMessage.append("Expected TF record ").append(expectedColf).append(":").append(expectedColq).append(" with value: ").append(count)
.append(" not found.");
return false;
}
}
errorMessage.append("No expected TF records found. Expected: ").append(expectedTfValues.toString());
return false;
}
private static MediaType create(String type, String subtype, Multimap<String, String> parameters) {
checkNotNull(type);
checkNotNull(subtype);
checkNotNull(parameters);
String normalizedType = normalizeToken(type);
String normalizedSubtype = normalizeToken(subtype);
checkArgument(!WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype),
"A wildcard type cannot be used with a non-wildcard subtype");
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
for (Entry<String, String> entry : parameters.entries()) {
String attribute = normalizeToken(entry.getKey());
builder.put(attribute, normalizeParameterValue(attribute, entry.getValue()));
}
MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build());
// Return one of the constants if the media type is a known type.
return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
private static void checkAssetModulesHaveNoDependencies(
Multimap<String, String> moduleDependenciesMap,
ImmutableMap<String, BundleModule> modulesByName) {
for (Entry<String, String> dependencyEntry : moduleDependenciesMap.entries()) {
String moduleName = dependencyEntry.getKey();
String moduleDepName = dependencyEntry.getValue();
boolean moduleIsAsset = isAssetModule(modulesByName, moduleName);
boolean moduleDepIsAsset = isAssetModule(modulesByName, moduleDepName);
if (!moduleDepName.equals(BASE_MODULE_NAME.getName())
&& (moduleIsAsset || moduleDepIsAsset)) {
throw InvalidBundleException.builder()
.withUserMessage(
"Module '%s' cannot depend on module '%s' because one of them is an asset pack.",
moduleName, moduleDepName)
.build();
}
}
}
private static List<LinkedKeyBinding> findLinkedBindingsToRemove(final ConfigurationContext context,
final List<Class<?>> extensions,
final Multimap<Key, LinkedKeyBinding> links) {
// try to recognize extensions in links
for (Map.Entry<Key, LinkedKeyBinding> entry : links.entries()) {
final Key key = entry.getKey();
final Class type = key.getTypeLiteral().getRawType();
final LinkedKeyBinding binding = entry.getValue();
if (!isPossibleExtension(key)) {
continue;
}
// try to detect extension in linked type (binding already analyzed so no need to count)
if (!extensions.contains(type) && ExtensionsSupport.registerExtensionBinding(context, type,
binding, BindingUtils.getTopDeclarationModule(binding))) {
LOGGER.debug("Extension detected from guice link binding: {}", type.getSimpleName());
extensions.add(type);
}
}
// find disabled bindings (already removed)
// for extensions recognized from links above imagine as we removed some (not existing) bindings
final List<Key> removedExtensions = extensions.stream()
.filter(it -> !context.isExtensionEnabled(it))
.map(Key::get)
.collect(Collectors.toList());
return removeChains(removedExtensions, links);
}
Multimap<String, Object> resolveCuries(Multimap<String, Object> paramMap) {
Multimap<String, Object> map = ArrayListMultimap.create();
for (Entry<String, Object> entry: paramMap.entries()) {
if (entry.getValue() instanceof String) {
Optional<String> iri = curieUtil.getIri((String)entry.getValue());
if (iri.isPresent()) {
map.put(entry.getKey(), iri.get());
} else {
map.put(entry.getKey(), entry.getValue());
}
} else {
map.put(entry.getKey(), entry.getValue());
}
}
return map;
}
private static MediaType create(
String type, String subtype, Multimap<String, String> parameters) {
checkNotNull(type);
checkNotNull(subtype);
checkNotNull(parameters);
String normalizedType = normalizeToken(type);
String normalizedSubtype = normalizeToken(subtype);
checkArgument(
!WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype),
"A wildcard type cannot be used with a non-wildcard subtype");
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
for (Entry<String, String> entry : parameters.entries()) {
String attribute = normalizeToken(entry.getKey());
builder.put(attribute, normalizeParameterValue(attribute, entry.getValue()));
}
MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build());
// Return one of the constants if the media type is a known type.
return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
protected JoinDesc buildJoin(RexCall condition) {
Multimap<TblColRef, TblColRef> joinColumns = HashMultimap.create();
translateJoinColumn(condition, joinColumns);
List<String> pks = new ArrayList<String>();
List<TblColRef> pkCols = new ArrayList<TblColRef>();
List<String> fks = new ArrayList<String>();
List<TblColRef> fkCols = new ArrayList<TblColRef>();
for (Map.Entry<TblColRef, TblColRef> columnPair : joinColumns.entries()) {
TblColRef fromCol = columnPair.getKey();
TblColRef toCol = columnPair.getValue();
fks.add(fromCol.getName());
fkCols.add(fromCol);
pks.add(toCol.getName());
pkCols.add(toCol);
}
JoinDesc join = new JoinDesc();
join.setForeignKey(fks.toArray(COLUMN_ARRAY_MARKER));
join.setForeignKeyColumns(fkCols.toArray(new TblColRef[fkCols.size()]));
join.setPrimaryKey(pks.toArray(COLUMN_ARRAY_MARKER));
join.setPrimaryKeyColumns(pkCols.toArray(new TblColRef[pkCols.size()]));
join.sortByFK();
return join;
}
@Override
public List<Multimap<List<Object>, Object>> merge(List<Multimap<List<Object>, Object>> accumulatedValue1, List<Multimap<List<Object>, Object>> accumulatedValue2)
{
for (int i = 0; i < 2; i++) {
Multimap<List<Object>, Object> mMap1 = accumulatedValue1.get(i);
Multimap<List<Object>, Object> mMap2 = accumulatedValue2.get(i);
for (Map.Entry<List<Object>, Object> entry : mMap2.entries()) {
mMap1.put(entry.getKey(),entry.getValue());
}
}
return accumulatedValue1;
}
/**
*
* @param fromDirectory
* @param toDirectory
* @param isIncluded
* @param segments
* the partition percentages to be used in the split, along with
* the name of the folders to be created.
* @param weightingFunction
* the function that returns the weight of each file in the split
*/
public static void splitFiles(final File fromDirectory,
final File toDirectory, final Map<String, Double> segments,
final IOFileFilter isIncluded,
final Function<File, Double> weightingFunction) {
final Collection<File> fromFiles = FileUtils.listFiles(fromDirectory,
isIncluded, DirectoryFileFilter.DIRECTORY);
final Map<File, Double> fileWeights = Maps.newHashMap();
for (final File f : fromFiles) {
fileWeights.put(f, weightingFunction.apply(f));
}
final Multimap<String, File> fileSplit = SampleUtils.randomPartition(
fileWeights, segments);
// Start copying
final String pathSeparator = System.getProperty("file.separator");
for (final Entry<String, File> file : fileSplit.entries()) {
final File targetFilename = new File(toDirectory.getAbsolutePath()
+ pathSeparator + file.getKey() + pathSeparator
+ file.getValue().getName());
try {
FileUtils.copyFile(file.getValue(), targetFilename);
} catch (final IOException e) {
LOGGER.severe("Failed to copy " + file.getValue() + " to "
+ targetFilename);
}
}
}
public Multimap<String,NormalizedContentInterface> normalize(Multimap<String,String> fields) {
Multimap<String,NormalizedContentInterface> eventFields = HashMultimap.create();
for (Entry<String,String> field : fields.entries()) {
eventFields.put(field.getKey(), new NormalizedFieldAndValue(field.getKey(), field.getValue()));
}
return normalizeMap(eventFields);
}
@SuppressWarnings("unchecked")
private static void remapAccessTransformer(IClassTransformer t) {
Multimap<String, ?> modifiers = (Multimap<String, ?>) get(f_modifiers, t);
Multimap<String, Object> t_modifiers = HashMultimap.create();
for (Entry<String, ?> entry : modifiers.entries()) {
Object mod = entry.getValue();
String m_owner = entry.getKey().replace('.', '/');
String m_name = (String) get(f_Modifier_name, mod);
String m_desc = ((String) get(f_Modifier_desc, mod)).replace('.', '/');
ObfMapping map;
if (m_name.equals("*")) {
map = new ObfMapping(m_owner);
map.s_name = m_name;
map.s_desc = m_desc;
} else {
try {
map = new ObfMapping(m_owner, m_name, m_desc).toClassloading();
} catch (Exception e) {
new Object();
continue;
}
}
set(f_Modifier_name, mod, map.s_name);
set(f_Modifier_desc, mod, map.s_desc);
t_modifiers.put(map.javaClass(), mod);
}
set(f_modifiers, t, t_modifiers);
}
public void addFieldsToDatatypes(Multimap<String,String> fieldsToDatatype) {
getMetadata().allFields.addAll(fieldsToDatatype.keySet());
for (Map.Entry<String,String> field : fieldsToDatatype.entries()) {
try {
this.dataTypes.put(field.getKey(), Class.forName(field.getValue()).asSubclass(Type.class).newInstance());
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
this.fieldsToDatatype.putAll(fieldsToDatatype);
}
}
}
private static JSONObject toJson(Multimap<String, String> headers) {
if (headers != null && headers.size() > 0) {
JSONObject json = new JSONObject();
for (Map.Entry<String, String> entry : headers.entries()) {
json.put(entry.getKey(), entry.getValue());
}
return json;
}
return null;
}
/**
* Helper method to create a new graph.
*
* @param <T>
* node type
* @param graph
* graph as multiset where values represent targets of edges with key as source
* @return graph
*/
public static <T> Graph<T> create(final Multimap<T, T> graph) {
Graph<T> g = new Graph<T>();
for (Map.Entry<T, T> entry : graph.entries()) {
T from = entry.getKey();
T to = entry.getValue();
g.addNode(from);
g.addNode(to);
g.addEdge(from, to);
}
return g;
}
private void synchronizeForwards(Table targetTable, Set<String> targetColumns) throws SQLException {
log.info("Creating forward sync function for table: {}...", targetTable.getName());
try (Connection connection = backend.connect()) {
Catalog catalog = state.getCatalog();
Multimap<TableRef, TableRef> tableMapping = state.getRefLog().getTableMapping(from, to);
for (Entry<TableRef, TableRef> entry : tableMapping.entries()) {
if (entry.getValue().getRefId().equals(targetTable.getName())) {
TableRef source = entry.getKey();
TableRef target = entry.getValue();
ensureSyncFunctionExists(connection, refLog, source, target, catalog, targetColumns);
}
}
}
}
@Override
protected void flush(Multimap<BulkIngestKey,Value> entries, TaskInputOutputContext<?,?,Text,Mutation> context) throws IOException, InterruptedException {
for (Map.Entry<BulkIngestKey,Value> entry : entries.entries()) {
writeToContext(context, entry);
}
}
final void evaluateRenamings(final Multimap<Scope, String> m,
final File file) {
final ResultObject[] fileResults = new ResultObject[ScopeType.values().length];
for (int i = 0; i < fileResults.length; i++) {
fileResults[i] = new ResultObject();
}
for (final Entry<Scope, String> variable : m.entries()) {
try {
evaluateSingleRenaming(fileResults, variable);
} catch (final Throwable e) {
LOGGER.warning("Failed to evaluate renaming " + variable + " "
+ ExceptionUtils.getFullStackTrace(e));
}
}
for (int i = 0; i < fileResults.length; i++) {
data[i].accumulate(fileResults[i]);
}
if (PER_FILE_STATS) {
final StringBuffer buf = new StringBuffer();
buf.append(file.getAbsolutePath());
buf.append("\t");
long tp0 = 0;
long allSum = 0;
for (int i = 0; i < ScopeType.values().length; i++) {
final long[] tpScope = data[i].recallAtRank[i];
tp0 += tpScope[0];
final long allScope = data[i].count;
allSum += allScope;
buf.append(data[i].nGaveSuggestions[0]);
buf.append("\t");
}
buf.append(((double) tp0) / allSum);
buf.append("\n");
appendToStatsFile(buf);
}
}
public Result execute( Result result, int nr ) throws KettleException {
List<RowMetaAndData> resultRows = result.getRows();
int numberOfErrFiles = 0;
result.setResult( false );
result.setNrErrors( 1 );
if ( argFromPrevious && log.isDetailed() ) {
logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFiles.FoundPreviousRows", String
.valueOf( ( resultRows != null ? resultRows.size() : 0 ) ) ) );
}
//Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
if ( parentJobMeta.getNamedClusterEmbedManager() != null ) {
parentJobMeta.getNamedClusterEmbedManager()
.passEmbeddedMetastoreKey( this, parentJobMeta.getEmbeddedMetastoreProviderKey() );
}
Multimap<String, String> pathToMaskMap = populateDataForJobExecution( resultRows );
for ( Map.Entry<String, String> pathToMask : pathToMaskMap.entries() ) {
final String filePath = environmentSubstitute( pathToMask.getKey() );
if ( filePath.trim().isEmpty() ) {
// Relative paths are permitted, and providing an empty path means deleting all files inside a root pdi-folder.
// It is much more likely to be a mistake than a desirable action, so we don't delete anything (see PDI-15181)
if ( log.isDetailed() ) {
logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFiles.NoPathProvided" ) );
}
} else {
final String fileMask = environmentSubstitute( pathToMask.getValue() );
if ( parentJob.isStopped() ) {
break;
}
if ( !processFile( filePath, fileMask, parentJob ) ) {
numberOfErrFiles++;
}
}
}
if ( numberOfErrFiles == 0 ) {
result.setResult( true );
result.setNrErrors( 0 );
} else {
result.setNrErrors( numberOfErrFiles );
result.setResult( false );
}
return result;
}
private void assertCompilationResultIs(
Multimap<Diagnostic.Kind, Pattern> expectedDiagnostics,
List<String> testSourceCode) throws IOException {
assertFalse(testSourceCode.isEmpty());
StringWriter compilerOut = new StringWriter();
List<String> options = ImmutableList.of(
"-sourcepath", tmpDir.getPath(),
"-d", tmpDir.getPath(),
"-processor", RetroFacebookProcessor.class.getName(),
"-Xlint");
javac.getTask(compilerOut, fileManager, diagnosticCollector, options, null, null);
// This doesn't compile anything but communicates the paths to the JavaFileManager.
// Convert the strings containing the source code of the test classes into files that we
// can feed to the compiler.
List<String> classNames = Lists.newArrayList();
List<JavaFileObject> sourceFiles = Lists.newArrayList();
for (String source : testSourceCode) {
ClassName className = ClassName.extractFromSource(source);
File dir = new File(tmpDir, className.sourceDirectoryName());
dir.mkdirs();
assertTrue(dir.isDirectory()); // True if we just made it, or it was already there.
String sourceName = className.simpleName + ".java";
Files.write(source, new File(dir, sourceName), Charsets.UTF_8);
classNames.add(className.fullName());
JavaFileObject sourceFile = fileManager.getJavaFileForInput(
StandardLocation.SOURCE_PATH, className.fullName(), Kind.SOURCE);
sourceFiles.add(sourceFile);
}
assertEquals(classNames.size(), sourceFiles.size());
// Compile the classes.
JavaCompiler.CompilationTask javacTask = javac.getTask(
compilerOut, fileManager, diagnosticCollector, options, classNames, sourceFiles);
boolean compiledOk = javacTask.call();
// Check that there were no compilation errors unless we were expecting there to be.
// We ignore "notes", typically debugging output from the annotation processor
// when that is enabled.
Multimap<Diagnostic.Kind, String> diagnostics = ArrayListMultimap.create();
for (Diagnostic<?> diagnostic : diagnosticCollector.getDiagnostics()) {
boolean ignore = (diagnostic.getKind() == Diagnostic.Kind.NOTE
|| (diagnostic.getKind() == Diagnostic.Kind.WARNING
&& diagnostic.getMessage(null).contains(
"No processor claimed any of these annotations")));
if (!ignore) {
diagnostics.put(diagnostic.getKind(), diagnostic.getMessage(null));
}
}
assertEquals(diagnostics.containsKey(Diagnostic.Kind.ERROR), !compiledOk);
assertEquals("Diagnostic kinds should match: " + diagnostics,
expectedDiagnostics.keySet(), diagnostics.keySet());
for (Map.Entry<Diagnostic.Kind, Pattern> expectedDiagnostic : expectedDiagnostics.entries()) {
Collection<String> actualDiagnostics = diagnostics.get(expectedDiagnostic.getKey());
assertTrue("Diagnostics should contain " + expectedDiagnostic + ": " + diagnostics,
Iterables.any(actualDiagnostics, Predicates.contains(expectedDiagnostic.getValue())));
}
}