static void MultiMapTest() { MultiMap <char, int> map = new MultiMap <char, int>(); Random rand = new Random(); for (int i = 0; i < 25; i++) { char key = (char)rand.Next(65, 71); map.add(key, rand.Next(0, 50)); } map.print(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); int[] items = map.get('A'); for (int i = 0; i < items.Length; i++) { Console.WriteLine(items[i]); } }
/// <summary> /// Given a hazelcast member id and a set of non-null attribute maps, this method builds a discovery representation of a read replica /// (i.e. `Pair<MemberId,ReadReplicaInfo>`). Any missing attributes which are missing for a given hazelcast member id are logged and this /// method will return null. /// </summary> private static Pair <MemberId, ReadReplicaInfo> BuildReadReplicaFromAttrMap(string hzId, IDictionary <string, IMap <string, string> > simpleAttrMaps, MultiMap <string, string> serverGroupsMap, Log log) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IDictionary <string, string> memberAttrs = simpleAttrMaps.SetOfKeyValuePairs().Select(e => Pair.of(e.Key, e.Value.get(hzId))).Where(p => HasAttribute(p, hzId, log)).collect(CollectorsUtil.pairsToMap()); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: if (!memberAttrs.Keys.containsAll(RrAttrKeys)) { return(null); } ICollection <string> memberServerGroups = serverGroupsMap.get(hzId); if (memberServerGroups == null) { log.Warn("Missing attribute %s for read replica with hz id %s", SERVER_GROUPS_MULTIMAP, hzId); return(null); } ClientConnectorAddresses boltAddresses = ClientConnectorAddresses.FromString(memberAttrs[READ_REPLICA_BOLT_ADDRESS_MAP]); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: AdvertisedSocketAddress catchupAddress = socketAddress(memberAttrs[READ_REPLICA_TRANSACTION_SERVER_ADDRESS_MAP], AdvertisedSocketAddress::new); MemberId memberId = new MemberId(System.Guid.Parse(memberAttrs[READ_REPLICA_MEMBER_ID_MAP])); string memberDbName = memberAttrs[READ_REPLICAS_DB_NAME_MAP]; ISet <string> serverGroupSet = asSet(memberServerGroups); ReadReplicaInfo rrInfo = new ReadReplicaInfo(boltAddresses, catchupAddress, serverGroupSet, memberDbName); return(Pair.of(memberId, rrInfo)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") com.hazelcast.core.MultiMap<String,String> serverGroupsMMap = mock(com.hazelcast.core.MultiMap.class); MultiMap <string, string> serverGroupsMMap = mock(typeof(MultiMap)); when(serverGroupsMMap.get(any())).thenReturn(_groups); when(_hzInstance.getMultiMap(anyString())).thenReturn((MultiMap)serverGroupsMMap); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: _rrAttributeMaps = RR_ATTR_KEYS.Select(k => Pair.of(k, (IMap <string, string>)mock(typeof(IMap)))).collect(CollectorsUtil.pairsToMap()); }
internal static void RefreshGroups(HazelcastInstance hazelcastInstance, string memberId, IList <string> groups) { MultiMap <string, string> groupsMap = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP); ICollection <string> existing = groupsMap.get(memberId); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ISet <string> superfluous = existing.Where(t => !groups.Contains(t)).collect(Collectors.toSet()); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: ISet <string> missing = groups.Where(t => !existing.Contains(t)).collect(Collectors.toSet()); missing.forEach(group => groupsMap.put(memberId, group)); superfluous.forEach(group => groupsMap.remove(memberId, group)); }
/** Walk each NFA configuration in this DFA state looking for a conflict * where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with * context conflicting ctx predicts alts i and j. Return an Integer set * of the alternative numbers that conflict. Two contexts conflict if * they are equal or one is a stack suffix of the other or one is * the empty context. * * Use a hash table to record the lists of configs for each state * as they are encountered. We need only consider states for which * there is more than one configuration. The configurations' predicted * alt must be different or must have different contexts to avoid a * conflict. * * Don't report conflicts for DFA states that have conflicting Tokens * rule NFA states; they will be resolved in favor of the first rule. */ protected virtual HashSet<int> GetConflictingAlts() { // TODO this is called multiple times: cache result? //[email protected]("getNondetAlts for DFA state "+stateNumber); HashSet<int> nondeterministicAlts = new HashSet<int>(); // If only 1 NFA conf then no way it can be nondeterministic; // save the overhead. There are many o-a->o NFA transitions // and so we save a hash map and iterator creation for each // state. int numConfigs = nfaConfigurations.Size(); if ( numConfigs <= 1 ) { return null; } // First get a list of configurations for each state. // Most of the time, each state will have one associated configuration. MultiMap<int, NFAConfiguration> stateToConfigListMap = new MultiMap<int, NFAConfiguration>(); for ( int i = 0; i < numConfigs; i++ ) { NFAConfiguration configuration = (NFAConfiguration)nfaConfigurations.Get( i ); int stateI = configuration.state; stateToConfigListMap.Map( stateI, configuration ); } // potential conflicts are states with > 1 configuration and diff alts ICollection<int> states = stateToConfigListMap.Keys.ToArray(); int numPotentialConflicts = 0; foreach ( int stateI in states ) { bool thisStateHasPotentialProblem = false; var configsForState = stateToConfigListMap.get( stateI ); int alt = 0; int numConfigsForState = configsForState.Count; for ( int i = 0; i < numConfigsForState && numConfigsForState > 1; i++ ) { NFAConfiguration c = (NFAConfiguration)configsForState[i]; if ( alt == 0 ) { alt = c.alt; } else if ( c.alt != alt ) { /* [email protected]("potential conflict in state "+stateI+ " configs: "+configsForState); */ // 11/28/2005: don't report closures that pinch back // together in Tokens rule. We want to silently resolve // to the first token definition ala lex/flex by ignoring // these conflicts. // Also this ensures that lexers look for more and more // characters (longest match) before resorting to predicates. // TestSemanticPredicates.testLexerMatchesLongestThenTestPred() // for example would terminate at state s1 and test predicate // meaning input "ab" would test preds to decide what to // do but it should match rule C w/o testing preds. if ( dfa.nfa.grammar.type != GrammarType.Lexer || !dfa.NFADecisionStartState.enclosingRule.Name.Equals( Grammar.ArtificialTokensRuleName ) ) { numPotentialConflicts++; thisStateHasPotentialProblem = true; } } } if ( !thisStateHasPotentialProblem ) { // remove NFA state's configurations from // further checking; no issues with it // (can't remove as it's concurrent modification; set to null) stateToConfigListMap[stateI] = null; } } // a fast check for potential issues; most states have none if ( numPotentialConflicts == 0 ) { return null; } // we have a potential problem, so now go through config lists again // looking for different alts (only states with potential issues // are left in the states set). Now we will check context. // For example, the list of configs for NFA state 3 in some DFA // state might be: // [3|2|[28 18 $], 3|1|[28 $], 3|1, 3|2] // I want to create a map from context to alts looking for overlap: // [28 18 $] -> 2 // [28 $] -> 1 // [$] -> 1,2 // Indeed a conflict exists as same state 3, same context [$], predicts // alts 1 and 2. // walk each state with potential conflicting configurations foreach ( int stateI in states ) { var configsForState = stateToConfigListMap.get( stateI ); // compare each configuration pair s, t to ensure: // s.ctx different than t.ctx if s.alt != t.alt int numConfigsForState = 0; if ( configsForState != null ) { numConfigsForState = configsForState.Count; } for ( int i = 0; i < numConfigsForState; i++ ) { NFAConfiguration s = configsForState[i]; for ( int j = i + 1; j < numConfigsForState; j++ ) { NFAConfiguration t = configsForState[j]; // conflicts means s.ctx==t.ctx or s.ctx is a stack // suffix of t.ctx or vice versa (if alts differ). // Also a conflict if s.ctx or t.ctx is empty if ( s.alt != t.alt && s.context.ConflictsWith( t.context ) ) { nondeterministicAlts.Add( s.alt ); nondeterministicAlts.Add( t.alt ); } } } } if ( nondeterministicAlts.Count == 0 ) { return null; } return nondeterministicAlts; }
/** Walk each NFA configuration in this DFA state looking for a conflict * where (s|i|ctx) and (s|j|ctx) exist, indicating that state s with * context conflicting ctx predicts alts i and j. Return an Integer set * of the alternative numbers that conflict. Two contexts conflict if * they are equal or one is a stack suffix of the other or one is * the empty context. * * Use a hash table to record the lists of configs for each state * as they are encountered. We need only consider states for which * there is more than one configuration. The configurations' predicted * alt must be different or must have different contexts to avoid a * conflict. * * Don't report conflicts for DFA states that have conflicting Tokens * rule NFA states; they will be resolved in favor of the first rule. */ protected virtual HashSet <int> GetConflictingAlts() { // TODO this is called multiple times: cache result? //[email protected]("getNondetAlts for DFA state "+stateNumber); HashSet <int> nondeterministicAlts = new HashSet <int>(); // If only 1 NFA conf then no way it can be nondeterministic; // save the overhead. There are many o-a->o NFA transitions // and so we save a hash map and iterator creation for each // state. int numConfigs = nfaConfigurations.Size(); if (numConfigs <= 1) { return(null); } // First get a list of configurations for each state. // Most of the time, each state will have one associated configuration. MultiMap <int, NFAConfiguration> stateToConfigListMap = new MultiMap <int, NFAConfiguration>(); for (int i = 0; i < numConfigs; i++) { NFAConfiguration configuration = (NFAConfiguration)nfaConfigurations.Get(i); int stateI = configuration.state; stateToConfigListMap.Map(stateI, configuration); } // potential conflicts are states with > 1 configuration and diff alts ICollection <int> states = stateToConfigListMap.Keys.ToArray(); int numPotentialConflicts = 0; foreach (int stateI in states) { bool thisStateHasPotentialProblem = false; var configsForState = stateToConfigListMap.get(stateI); int alt = 0; int numConfigsForState = configsForState.Count; for (int i = 0; i < numConfigsForState && numConfigsForState > 1; i++) { NFAConfiguration c = (NFAConfiguration)configsForState[i]; if (alt == 0) { alt = c.alt; } else if (c.alt != alt) { /* * [email protected]("potential conflict in state "+stateI+ * " configs: "+configsForState); */ // 11/28/2005: don't report closures that pinch back // together in Tokens rule. We want to silently resolve // to the first token definition ala lex/flex by ignoring // these conflicts. // Also this ensures that lexers look for more and more // characters (longest match) before resorting to predicates. // TestSemanticPredicates.testLexerMatchesLongestThenTestPred() // for example would terminate at state s1 and test predicate // meaning input "ab" would test preds to decide what to // do but it should match rule C w/o testing preds. if (dfa.nfa.grammar.type != GrammarType.Lexer || !dfa.NFADecisionStartState.enclosingRule.Name.Equals(Grammar.ArtificialTokensRuleName)) { numPotentialConflicts++; thisStateHasPotentialProblem = true; } } } if (!thisStateHasPotentialProblem) { // remove NFA state's configurations from // further checking; no issues with it // (can't remove as it's concurrent modification; set to null) stateToConfigListMap[stateI] = null; } } // a fast check for potential issues; most states have none if (numPotentialConflicts == 0) { return(null); } // we have a potential problem, so now go through config lists again // looking for different alts (only states with potential issues // are left in the states set). Now we will check context. // For example, the list of configs for NFA state 3 in some DFA // state might be: // [3|2|[28 18 $], 3|1|[28 $], 3|1, 3|2] // I want to create a map from context to alts looking for overlap: // [28 18 $] -> 2 // [28 $] -> 1 // [$] -> 1,2 // Indeed a conflict exists as same state 3, same context [$], predicts // alts 1 and 2. // walk each state with potential conflicting configurations foreach (int stateI in states) { var configsForState = stateToConfigListMap.get(stateI); // compare each configuration pair s, t to ensure: // s.ctx different than t.ctx if s.alt != t.alt int numConfigsForState = 0; if (configsForState != null) { numConfigsForState = configsForState.Count; } for (int i = 0; i < numConfigsForState; i++) { NFAConfiguration s = configsForState[i]; for (int j = i + 1; j < numConfigsForState; j++) { NFAConfiguration t = configsForState[j]; // conflicts means s.ctx==t.ctx or s.ctx is a stack // suffix of t.ctx or vice versa (if alts differ). // Also a conflict if s.ctx or t.ctx is empty if (s.alt != t.alt && s.context.ConflictsWith(t.context)) { nondeterministicAlts.Add(s.alt); nondeterministicAlts.Add(t.alt); } } } } if (nondeterministicAlts.Count == 0) { return(null); } return(nondeterministicAlts); }
internal static IDictionary <MemberId, CoreServerInfo> ToCoreMemberMap(ISet <Member> members, Log log, HazelcastInstance hazelcastInstance) { IDictionary <MemberId, CoreServerInfo> coreMembers = new Dictionary <MemberId, CoreServerInfo>(); MultiMap <string, string> serverGroupsMMap = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP); foreach (Member member in members) { IDictionary <string, string> attrMap = new Dictionary <string, string>(); bool incomplete = false; foreach (string attrKey in CoreAttrKeys) { string attrValue = member.getStringAttribute(attrKey); if (string.ReferenceEquals(attrValue, null)) { log.Warn("Missing member attribute '%s' for member %s", attrKey, member); incomplete = true; } else { attrMap[attrKey] = attrValue; } } if (incomplete) { continue; } //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: CoreServerInfo coreServerInfo = new CoreServerInfo(socketAddress(attrMap[RAFT_SERVER], AdvertisedSocketAddress::new), socketAddress(attrMap[TRANSACTION_SERVER], AdvertisedSocketAddress::new), ClientConnectorAddresses.FromString(attrMap[CLIENT_CONNECTOR_ADDRESSES]), asSet(serverGroupsMMap.get(attrMap[MEMBER_UUID])), attrMap[MEMBER_DB_NAME], member.getBooleanAttribute(REFUSE_TO_BE_LEADER_KEY)); MemberId memberId = new MemberId(System.Guid.Parse(attrMap[MEMBER_UUID])); coreMembers[memberId] = coreServerInfo; } return(coreMembers); }