下面列出了com.google.common.collect.HashBiMap#create ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Map<Set<User>, NotificationMessage> createSingleNotifications( SortedSet<MessagePair> messagePairs )
{
BiMap<Set<User>, NotificationMessage> singleNotificationCollection = HashBiMap.create();
for ( MessagePair messagePair : messagePairs )
{
NotificationMessage notificationMessage = notificationMessageRenderer
.render( messagePair.result, messagePair.template );
notificationMessage.setPriority( getPriority( messagePair.result.getValidationRule().getImportance() ) );
singleNotificationCollection.put( new HashSet<>(), notificationMessage );
resolveRecipients( messagePair )
.forEach( user -> singleNotificationCollection.inverse().get( notificationMessage ).add( user ) );
}
return singleNotificationCollection;
}
@Override
public void afterPropertiesSet() throws Exception {
dbEsBiMapping = HashBiMap.create();
dbEsMapping.forEach((key, value) -> {
String[] keyStrings = StringUtils.split(key, ".");
String[] valueStrings = StringUtils.split(value, ".");
dbEsBiMapping.put(new DatabaseTableModel(keyStrings[0], keyStrings[1]), new IndexTypeModel(valueStrings[0], valueStrings[1]));
});
mysqlTypeElasticsearchTypeMapping = Maps.newHashMap();
mysqlTypeElasticsearchTypeMapping.put("char", data -> data);
mysqlTypeElasticsearchTypeMapping.put("text", data -> data);
mysqlTypeElasticsearchTypeMapping.put("blob", data -> data);
mysqlTypeElasticsearchTypeMapping.put("int", Long::valueOf);
mysqlTypeElasticsearchTypeMapping.put("date", data -> LocalDateTime.parse(data, FORMATTER));
mysqlTypeElasticsearchTypeMapping.put("time", data -> LocalDateTime.parse(data, FORMATTER));
mysqlTypeElasticsearchTypeMapping.put("float", Double::valueOf);
mysqlTypeElasticsearchTypeMapping.put("double", Double::valueOf);
mysqlTypeElasticsearchTypeMapping.put("decimal", Double::valueOf);
}
@Test
public void testJoin() throws Exception {
final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(
collection,
new LinkedList<>(),
Sets.newHashSet("x", "y"),
Sets.newHashSet("x", "y", "opt"),
HashBiMap.create());
// Join on one shared variable
AggregationPipelineQueryNode node = base.clone();
boolean success = node.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")));
Assert.assertTrue(success);
Assert.assertEquals(Sets.newHashSet("x", "y", "c", "opt"), node.getBindingNames());
Assert.assertEquals(Sets.newHashSet("x", "y", "c"), node.getAssuredBindingNames());
Assert.assertEquals(4, node.getPipeline().size());
// Join on multiple shared variables
node = base.clone();
success = node.joinWith(new StatementPattern(new Var("x"), constant(TAKES), new Var("y")));
Assert.assertTrue(success);
Assert.assertEquals(Sets.newHashSet("x", "y", "opt"), node.getBindingNames());
Assert.assertEquals(Sets.newHashSet("x", "y"), node.getAssuredBindingNames());
Assert.assertEquals(5, node.getPipeline().size());
}
@Test(timeout = 5000)
public void testParseAllPluginsOnlyCustomSpecified() throws IOException {
Configuration conf = new Configuration(false);
conf.set(TEST_KEY, TEST_VAL);
UserPayload defaultPayload = TezUtils.createUserPayloadFromConf(conf);
TezUserPayloadProto payloadProto = TezUserPayloadProto.newBuilder()
.setUserPayload(ByteString.copyFrom(defaultPayload.getPayload())).build();
AMPluginDescriptorProto proto = createAmPluginDescriptor(false, false, true, payloadProto);
List<NamedEntityDescriptor> tsDescriptors;
BiMap<String, Integer> tsMap;
List<NamedEntityDescriptor> clDescriptors;
BiMap<String, Integer> clMap;
List<NamedEntityDescriptor> tcDescriptors;
BiMap<String, Integer> tcMap;
// Only plugin, Yarn.
tsDescriptors = Lists.newLinkedList();
tsMap = HashBiMap.create();
clDescriptors = Lists.newLinkedList();
clMap = HashBiMap.create();
tcDescriptors = Lists.newLinkedList();
tcMap = HashBiMap.create();
DAGAppMaster.parseAllPlugins(tsDescriptors, tsMap, clDescriptors, clMap, tcDescriptors, tcMap,
proto, false, defaultPayload);
verifyDescAndMap(tsDescriptors, tsMap, 2, true, TS_NAME,
TezConstants.getTezYarnServicePluginName());
verifyDescAndMap(clDescriptors, clMap, 1, true, CL_NAME);
verifyDescAndMap(tcDescriptors, tcMap, 1, true, TC_NAME);
assertEquals(TS_NAME + CLASS_SUFFIX, tsDescriptors.get(0).getClassName());
assertEquals(CL_NAME + CLASS_SUFFIX, clDescriptors.get(0).getClassName());
assertEquals(TC_NAME + CLASS_SUFFIX, tcDescriptors.get(0).getClassName());
}
public ScatterAgentMetaData(Set<DotAgentInfo> dotAgentInfoSet) {
Objects.requireNonNull(dotAgentInfoSet, "dotAgentInfoSet");
this.metaData = HashBiMap.create(dotAgentInfoSet.size());
int dotAgentInfoId = 1;
for (DotAgentInfo dotAgentInfo : dotAgentInfoSet) {
metaData.put(dotAgentInfo, dotAgentInfoId++);
}
}
public void fixOids(OidProvider oidProvider) {
BiMap<Long, IdEObject> temp = HashBiMap.create();
for (long oid : objects.keySet()) {
fixOids(objects.get(oid), oidProvider, temp);
}
objects = temp;
}
static
private BiMap<String, Parameter> parseParameterRegistry(ParameterList parameterList){
BiMap<String, Parameter> result = HashBiMap.create();
if(!parameterList.hasParameters()){
return result;
}
List<Parameter> parameters = parameterList.getParameters();
for(Parameter parameter : parameters){
result.put(parameter.getName(), parameter);
}
return result;
}
@Test(timeout = 5000)
public void testParseAllPluginsNoneSpecified() throws IOException {
Configuration conf = new Configuration(false);
conf.set(TEST_KEY, TEST_VAL);
UserPayload defaultPayload = TezUtils.createUserPayloadFromConf(conf);
List<NamedEntityDescriptor> tsDescriptors;
BiMap<String, Integer> tsMap;
List<NamedEntityDescriptor> clDescriptors;
BiMap<String, Integer> clMap;
List<NamedEntityDescriptor> tcDescriptors;
BiMap<String, Integer> tcMap;
// No plugins. Non local
tsDescriptors = Lists.newLinkedList();
tsMap = HashBiMap.create();
clDescriptors = Lists.newLinkedList();
clMap = HashBiMap.create();
tcDescriptors = Lists.newLinkedList();
tcMap = HashBiMap.create();
DAGAppMaster.parseAllPlugins(tsDescriptors, tsMap, clDescriptors, clMap, tcDescriptors, tcMap,
null, false, defaultPayload);
verifyDescAndMap(tsDescriptors, tsMap, 1, true, TezConstants.getTezYarnServicePluginName());
verifyDescAndMap(clDescriptors, clMap, 1, true, TezConstants.getTezYarnServicePluginName());
verifyDescAndMap(tcDescriptors, tcMap, 1, true, TezConstants.getTezYarnServicePluginName());
// No plugins. Local
tsDescriptors = Lists.newLinkedList();
tsMap = HashBiMap.create();
clDescriptors = Lists.newLinkedList();
clMap = HashBiMap.create();
tcDescriptors = Lists.newLinkedList();
tcMap = HashBiMap.create();
DAGAppMaster.parseAllPlugins(tsDescriptors, tsMap, clDescriptors, clMap, tcDescriptors, tcMap,
null, true, defaultPayload);
verifyDescAndMap(tsDescriptors, tsMap, 1, true, TezConstants.getTezUberServicePluginName());
verifyDescAndMap(clDescriptors, clMap, 1, true, TezConstants.getTezUberServicePluginName());
verifyDescAndMap(tcDescriptors, tcMap, 1, true, TezConstants.getTezUberServicePluginName());
}
public ASMBlock copy() {
BiMap<String, LabelNode> labels = HashBiMap.create();
Map<LabelNode, LabelNode> labelMap = list.cloneLabels();
for(Entry<String, LabelNode> entry : this.labels.entrySet())
labels.put(entry.getKey(), labelMap.get(entry.getValue()));
return new ASMBlock(list.copy(labelMap), labels);
}
@Test
public void testDuplicates() throws IOException {
assumeTrue(!Shell.WINDOWS);
String GET_ALL_USERS_CMD = "echo \"root:x:0:0:root:/root:/bin/bash\n"
+ "hdfs:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n"
+ "hdfs:x:11502:10788:Grid Distributed File System:/home/hdfs:/bin/bash\n"
+ "hdfs1:x:11501:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n"
+ "hdfs2:x:11502:10787:Grid Distributed File System:/home/hdfs:/bin/bash\n"
+ "bin:x:2:2:bin:/bin:/bin/sh\n"
+ "bin:x:1:1:bin:/bin:/sbin/nologin\n"
+ "daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n"
+ "daemon:x:2:2:daemon:/sbin:/sbin/nologin\""
+ " | cut -d: -f1,3";
String GET_ALL_GROUPS_CMD = "echo \"hdfs:*:11501:hrt_hdfs\n"
+ "mapred:x:497\n"
+ "mapred2:x:497\n"
+ "mapred:x:498\n"
+ "mapred3:x:498\""
+ " | cut -d: -f1,3";
// Maps for id to name map
BiMap<Integer, String> uMap = HashBiMap.create();
BiMap<Integer, String> gMap = HashBiMap.create();
ShellBasedIdMapping.updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
EMPTY_PASS_THROUGH_MAP);
assertEquals(5, uMap.size());
assertEquals("root", uMap.get(0));
assertEquals("hdfs", uMap.get(11501));
assertEquals("hdfs2",uMap.get(11502));
assertEquals("bin", uMap.get(2));
assertEquals("daemon", uMap.get(1));
ShellBasedIdMapping.updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
EMPTY_PASS_THROUGH_MAP);
assertTrue(gMap.size() == 3);
assertEquals("hdfs",gMap.get(11501));
assertEquals("mapred", gMap.get(497));
assertEquals("mapred3", gMap.get(498));
}
private static BiMap<String, GraphQLType> getEnumMap(
Iterable<EnumDescriptor> descriptors, SchemaOptions schemaOptions) {
HashBiMap<String, GraphQLType> mapping = HashBiMap.create();
for (EnumDescriptor enumDescriptor : descriptors) {
mapping.put(
ProtoToGql.getReferenceName(enumDescriptor),
ProtoToGql.convert(enumDescriptor, schemaOptions));
}
return mapping;
}
public static void main(String[] args) {
String[] englishWords = {"one", "two", "three","ball","snow"};
String[] russianWords = {"jeden", "dwa", "trzy", "kula", "snieg"};
// Create Multiset
BiMap<String, String> biMap = HashBiMap.create(englishWords.length);
// Create English-Polish dictionary
int i = 0;
for(String englishWord: englishWords) {
biMap.put(englishWord, russianWords[i]);
i++;
}
// Print count words
System.out.println(biMap); // print {two=dwa, three=trzy, snow=snieg, ball=kula, one=jeden} - in random orders
// Print all unique words
System.out.println(biMap.keySet()); // print [two, three, snow, ball, one] - in random orders
System.out.println(biMap.values()); // print [dwa, trzy, snieg, kula, jeden]- in random orders
// Print translate by words
System.out.println("one = " + biMap.get("one")); // print one = jeden
System.out.println("two = " + biMap.get("two")); // print two = dwa
System.out.println("kula = " + biMap.inverse().get("kula")); // print kula = ball
System.out.println("snieg = " + biMap.inverse().get("snieg")); // print snieg = snow
System.out.println("empty = " + biMap.get("empty")); // print empty = null
// Print count word's pair
System.out.println(biMap.size()); //print 5
}
synchronized private void loadFullUserMap() throws IOException {
BiMap<Integer, String> uMap = HashBiMap.create();
if (OS.startsWith("Mac")) {
updateMapInternal(uMap, "user", MAC_GET_ALL_USERS_CMD, "\\s+",
staticMapping.uidMapping);
} else {
updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":",
staticMapping.uidMapping);
}
uidNameMap = uMap;
lastUpdateTime = Time.monotonicNow();
}
synchronized private void loadFullGroupMap() throws IOException {
BiMap<Integer, String> gMap = HashBiMap.create();
if (OS.startsWith("Mac")) {
updateMapInternal(gMap, "group", MAC_GET_ALL_GROUPS_CMD, "\\s+",
staticMapping.gidMapping);
} else {
updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":",
staticMapping.gidMapping);
}
gidNameMap = gMap;
lastUpdateTime = Time.monotonicNow();
}
public DualKeyHashBiMap(Class<K1> primaryKeyClass, Class<K2> secondaryKeyClass) {
this.primaryKeyClass = primaryKeyClass;
this.secondaryKeyClass = secondaryKeyClass;
this.primaryDelegate = HashBiMap.create();
this.secondaryDelegate = HashBiMap.create();
}
protected void initDataflow(String binaryName) throws IOException, InterruptedException {
if (DL_FOLDER == null) {
extractSouffleBinaries();
}
String DL_EXEC = DL_FOLDER + "/" + binaryName;
varToCode = HashBiMap.create();
instrToCode = HashBiMap.create();
typeToCode = HashBiMap.create();
constToCode = HashBiMap.create();
fixedpoint = new HashMap<>();
offsetToStorageVar = HashBiMap.create();
offsetToMemoryVar = HashBiMap.create();
ruleToSB = HashBiMap.create();
ruleToSB.put("assignVar", new StringBuffer());
ruleToSB.put("assignType", new StringBuffer());
ruleToSB.put("taint", new StringBuffer());
ruleToSB.put("follows", new StringBuffer());
ruleToSB.put("jump", new StringBuffer());
ruleToSB.put("tag", new StringBuffer());
ruleToSB.put("oneBranchTag", new StringBuffer());
ruleToSB.put("join", new StringBuffer());
ruleToSB.put("endIf", new StringBuffer());
ruleToSB.put("mload", new StringBuffer());
ruleToSB.put("mstore", new StringBuffer());
ruleToSB.put("sload", new StringBuffer());
ruleToSB.put("sstore", new StringBuffer());
ruleToSB.put("isStorageVar", new StringBuffer());
ruleToSB.put("sha3", new StringBuffer());
ruleToSB.put("unk", new StringBuffer());
unk = getCode(UNK_CONST_VAL);
appendRule("unk", unk);
log("Souffle Analysis");
File fWORKSPACE = (new File(System.getProperty("java.io.tmpdir"), "souffle-" + UUID.randomUUID()));
if (!fWORKSPACE.mkdir()) {
throw new IOException("Could not create temporary directory");
}
WORKSPACE = fWORKSPACE.getAbsolutePath();
File fWORKSPACE_OUT = new File(WORKSPACE + "_OUT");
if (!fWORKSPACE_OUT.mkdir()) {
throw new IOException("Could not create temporary directory");
}
WORKSPACE_OUT = fWORKSPACE_OUT.getAbsolutePath();
deriveAssignVarPredicates();
deriveAssignTypePredicates();
deriveHeapPredicates();
deriveStorePredicates();
deriveFollowsPredicates();
deriveIfPredicates();
createProgramRulesFile();
log("Number of instructions: " + instrToCode.size());
log("Threshold: " + Config.THRESHOLD_COMPILE);
long start = System.currentTimeMillis();
runCommand(new String[]{DL_EXEC, "-j", Integer.toString(Runtime.getRuntime().availableProcessors()), "-F", WORKSPACE, "-D", WORKSPACE_OUT});
long elapsedTime = System.currentTimeMillis() - start;
String elapsedTimeStr = String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes(elapsedTime),
TimeUnit.MILLISECONDS.toSeconds(elapsedTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(elapsedTime))
);
log(elapsedTimeStr);
}
private EurostagDictionary(Map<String, String> iidmId2esgId, EurostagEchExportConfig config) {
Objects.requireNonNull(iidmId2esgId);
Objects.requireNonNull(config);
this.iidmId2esgId = HashBiMap.create(iidmId2esgId);
this.config = config;
}
@Override
public void grant(
UsergridAuthorizationInfo info,
EntityManagerFactory emf,
ManagementService management,
TokenService tokens) {
// AdminUserPrincipals are through basic auth and sessions
// They have access to organizations and organization
// applications
UserInfo user = this.getUser();
Map<UUID, String> organizationSet = HashBiMap.create();
Map<UUID, String> applicationSet = HashBiMap.create();
OrganizationInfo organization = null;
ApplicationInfo application = null;
boolean superUserEnabled = false;
final String s = management.getProperties().getProperty(
AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_ALLOWED);
if ( s != null && "true".equalsIgnoreCase(s.trim())) {
superUserEnabled = true;
}
String superUser = management.getProperties().getProperty(
AccountCreationProps.PROPERTIES_SYSADMIN_LOGIN_NAME);
if ( superUserEnabled && ( superUser != null ) && superUser.equals( user.getUsername() ) ) {
// The system user has access to everything
role(info, Realm.ROLE_SERVICE_ADMIN);
role(info, Realm.ROLE_ORGANIZATION_ADMIN);
role(info, Realm.ROLE_APPLICATION_ADMIN);
role(info, Realm.ROLE_ADMIN_USER);
grant(info, "system:access");
grant(info, "organizations:admin,access,get,put,post,delete:*");
grant(info, "applications:admin,access,get,put,post,delete:*");
grant(info, "organizations:admin,access,get,put,post,delete:*:/**");
grant(info, "applications:admin,access,get,put,post,delete:*:/**");
grant(info, "users:access:*");
grant(info, SubjectUtils.getPermissionFromPath(emf.getManagementAppId(), "access"));
grant(info, SubjectUtils.getPermissionFromPath(emf.getManagementAppId(), "get,put,post,delete", "/**"));
// don't need to load organizations here for superuser/sysadmin because it has access to everything
}
else {
// For regular service users, we find what organizations
// they're associated with
// An service user can be associated with multiple
// organizations
grant( info, getPermissionFromPath( emf.getManagementAppId(), "access" ) );
// admin users cannot access the management app directly
// so open all permissions
grant( info, getPermissionFromPath(emf.getManagementAppId(), "get,put,post,delete", "/**") );
role(info, Realm.ROLE_ADMIN_USER);
try {
Map<UUID, String> userOrganizations = management.getOrganizationsForAdminUser(user.getUuid());
if ( userOrganizations != null ) {
for ( UUID id : userOrganizations.keySet() ) {
grant( info, "organizations:admin,access,get,put,post,delete:" + id );
}
organizationSet.putAll( userOrganizations );
Map<UUID, String> userApplications =
management.getApplicationsForOrganizations( userOrganizations.keySet() );
if ( ( userApplications != null ) && !userApplications.isEmpty() ) {
grant( info, "applications:admin,access,get,put,post,delete:" + StringUtils
.join(userApplications.keySet(), ',') );
applicationSet.putAll( userApplications );
}
role( info, Realm.ROLE_ORGANIZATION_ADMIN );
role( info, Realm.ROLE_APPLICATION_ADMIN );
}
}
catch ( Exception e ) {
logger.error( "Unable to construct admin user permissions", e );
}
}
info.setOrganization(organization);
info.addOrganizationSet(organizationSet);
info.setApplication(application);
info.addApplicationSet(applicationSet);
}
private Map<String, BiMap<String, String>> parsePreviousResults(
String serializedMap) {
//
// The expected format looks like this:
//
// [generatorName]
// someId:someFile:theLine:theColumn
//
//
if (serializedMap == null || serializedMap.isEmpty()) {
return Collections.emptyMap();
}
Map<String, BiMap<String, String>> resultMap = Maps.newHashMap();
BufferedReader reader = new BufferedReader(new StringReader(serializedMap));
BiMap<String, String> currentSectionMap = null;
String line;
int lineIndex = 0;
try {
while ((line = reader.readLine()) != null) {
lineIndex++;
if (line.isEmpty()) {
continue;
}
if (line.charAt(0) == '[') {
String currentSection = line.substring(1, line.length() - 1);
currentSectionMap = resultMap.get(currentSection);
if (currentSectionMap == null) {
currentSectionMap = HashBiMap.create();
resultMap.put(currentSection, currentSectionMap);
} else {
reportInvalidLine(line, lineIndex);
return Collections.emptyMap();
}
} else {
int split = line.indexOf(':');
if (split != -1) {
String name = line.substring(0, split);
String location = line.substring(split + 1, line.length());
currentSectionMap.put(name, location);
} else {
reportInvalidLine(line, lineIndex);
return Collections.emptyMap();
}
}
}
} catch (IOException e) {
JSError.make(INVALID_GENERATOR_ID_MAPPING, e.getMessage());
}
return resultMap;
}
/**
* Constructor.
*
* @param resolver
* The resolver that consumes values
*/
public ScatterStringConsumer(IStringResolver<Object> resolver) {
fResolver = resolver;
fMap = HashBiMap.create();
}