@Override public Map<String, HazelcastSession> findByIndexNameAndIndexValue(String indexName, String indexValue) { if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { return Collections.emptyMap(); } Collection<MapSession> sessions = this.sessions .values(Predicates.equal(PRINCIPAL_NAME_ATTRIBUTE, indexValue)); Map<String, HazelcastSession> sessionMap = new HashMap<>(sessions.size()); for (MapSession session : sessions) { sessionMap.put(session.getId(), new HazelcastSession(session)); } return sessionMap; }
@Test public void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); String principal = "username"; Map<String, HazelcastSession> sessions = this.repository .findByIndexNameAndIndexValue( FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).isEmpty(); verify(this.sessions, times(1)).values(isA(EqualPredicate.class)); verifyZeroInteractions(this.sessions); }
@Test public void findByIndexNameAndIndexValuePrincipalIndexNameFound() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); String principal = "username"; Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused", AuthorityUtils.createAuthorityList("ROLE_USER")); List<MapSession> saved = new ArrayList<>(2); MapSession saved1 = new MapSession(); saved1.setAttribute(SPRING_SECURITY_CONTEXT, authentication); saved.add(saved1); MapSession saved2 = new MapSession(); saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication); saved.add(saved2); given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved); Map<String, HazelcastSession> sessions = this.repository .findByIndexNameAndIndexValue( FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal); assertThat(sessions).hasSize(2); verify(this.sessions, times(1)).values(isA(EqualPredicate.class)); verifyZeroInteractions(this.sessions); }
@Override protected void mapOperation() { map.values(); } }
private Set<Person> getWithNameNaive(String name) { Set<Person> result = new HashSet<Person>(); for (Person person : personMap.values()) { if (person.getName().equals(name)) { result.add(person); } } return result; }
@Override protected Collection<?> doListKeys(String keyPattern) { Assert.hasText(keyPattern, "'keyPattern' must not be empty"); keyPattern = keyPattern.replaceAll("\\*", "%"); SqlPredicate sqlPredicate = new SqlPredicate("__key like " + keyPattern); return this.map.values(sqlPredicate); }
/** * Returns how many execution ids are present for the given job id */ long getExecutionIdCount(long jobId) { return randomIds.values(new FilterExecutionIdByJobIdPredicate(jobId)).size(); }
protected void handleMapValues() { Collection set = getMap().values(); Iterator it = set.iterator(); int count = 0; while (it.hasNext()) { count++; println(it.next()); } println("Total " + count); }
protected void handleMapValues() { Collection set = getMap().values(); Iterator it = set.iterator(); int count = 0; while (it.hasNext()) { count++; println(it.next()); } println("Total " + count); }
private Set<Person> getNotWithName(String name) { Predicate namePredicate = equal("name", name); Predicate predicate = not(namePredicate); return (Set<Person>) personMap.values(predicate); }
@Override public void initialize(Context<String, Integer> context) { super.initialize(context); IMap<Integer, State> states = hazelcastInstance.getMap("states"); for (State s : states.values()) { String abbreviation = s.getAbbreviation(); String name = s.getName(); abbreviationMapping.put(abbreviation, name); } }
@Override public void initialize(Context<String, Integer> context) { super.initialize(context); IMap<Integer, State> states = hazelcastInstance.getMap("states"); for (State s : states.values()) { String abbrevation = s.getAbbreviation(); String name = s.getName(); abbreviationMapping.put(abbrevation, name); } }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<String, Customer> map = hz.getMap("map"); map.put("1", new Customer("peter", true, 36)); map.put("2", new Customer("john", false, 40)); map.put("3", new Customer("roger", true, 20)); Set<Customer> employees = (Set<Customer>) map.values(new SqlPredicate("active AND age < 30")); System.out.println("Employees: " + employees); Hazelcast.shutdownAll(); } }
private Set<Person> getWithNameAndAge(String name, int age) { Predicate namePredicate = equal("name", name); Predicate agePredicate = equal("age", age); Predicate predicate = and(namePredicate, agePredicate); return (Set<Person>) personMap.values(predicate); }
private Set<Person> getWithNameOrAge(String name, int age) { Predicate namePredicate = equal("name", name); Predicate agePredicate = equal("age", age); Predicate predicate = or(namePredicate, agePredicate); return (Set<Person>) personMap.values(predicate); } }
public static void main(String[] args) throws ParseException { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<Integer, Customer> map = hz.getMap("customers"); map.put(1, new Customer("James", "Bond", 1975)); map.put(2, new Customer("Eathen", "Hunt", 1965)); map.put(3, new Customer("Roger", "Moore", 1995)); // we're using a custom attribute 'age' which is provided by the 'AgeExtractor' Set<Customer> customers = (Set<Customer>) map.values(new SqlPredicate("age < 50")); System.out.println("Customers: " + customers); Hazelcast.shutdownAll(); } }
public static void main(String[] args) throws ParseException { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<Integer, Car> map = hz.getMap("cars"); map.put(1, new Car("Audi Q7").setTrip(1000, 3000)); map.put(2, new Car("BMW X5").setTrip(3000, 5000)); map.put(3, new Car("Porsche Cayenne").setTrip(2000, 8000)); // we're using a custom 'tripDistance' attribute which is provided by the 'CarTripDistanceExtractor' Set<Car> cars = (Set<Car>) map.values(new SqlPredicate("tripDistance < 3000")); System.out.println("Cars: " + cars); Hazelcast.shutdownAll(); } }
@TimeStep(prob = 0) public void predicateBuilder(ThreadState state) { int id = state.randomInt(itemCount); EntryObject entryObject = new PredicateBuilder().getEntryObject(); Predicate predicate = entryObject.get("id").equal(id); map.values(predicate); }
private Set<Person> getWithNameAndAgeSimplified(String name, int age) { EntryObject e = new PredicateBuilder().getEntryObject(); Predicate predicate = e.get("name").equal(name).and(e.get("age").equal(age)); return (Set<Person>) personMap.values(predicate); }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<Integer, Person> map = hz.getMap("map"); map.put(1, new Person("Georg", limb("left-leg"), limb("right-leg"))); map.put(2, new Person("Peter", limb("left-hand"), limb("right-hand"))); map.put(3, new Person("Hans", limb("left-leg"), limb("right-leg"))); map.put(4, new Person("Stefanie", limb("left-arm"), limb("right-arm"))); Set<Person> employees = (Set<Person>) map.values(new SqlPredicate("limbs[any].name == right-leg")); System.out.println("People: " + employees); Hazelcast.shutdownAll(); }