@Override public boolean equals(Object other) { if (!(other instanceof Perimeter)) { return false; } Perimeter otherPerimeter = (Perimeter) other; return CollectionUtils.isEqualCollection(outsidePlanets, otherPerimeter.getOutsidePlanets()) && CollectionUtils.isEqualCollection(insidePlanets, otherPerimeter.getInsidePlanets()); }
@Test public void basicFullTextQuery() throws Exception { String table = "basicFullTextQuery"; SolrServer server = TestTableCreator.newTable(table) .withRowCount(1) .withRecordsPerRow(2) .withRecordColumns("fam.value", "fam.mvf", "fam.mvf") .create(); SolrQuery query = new SolrQuery("value0-0"); QueryResponse response = server.query(query); assertEquals("We should get our doc back.", 1l, response.getResults().getNumFound()); SolrDocument docResult = response.getResults().get(0); assertEquals("0", docResult.getFieldValue("recordid")); assertEquals("value0-0", docResult.getFieldValue("fam.value")); Collection<Object> mvfVals = docResult.getFieldValues("fam.mvf"); assertTrue( "We should get all our values back[" + mvfVals + "]", CollectionUtils.isEqualCollection(mvfVals, Lists.newArrayList("value0-0", "value0-0"))); removeTable(table); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CRStage that = (CRStage) o; if (fetch_materials != that.fetch_materials) { return false; } if (never_cleanup_artifacts != that.never_cleanup_artifacts) { return false; } if (clean_working_directory != that.clean_working_directory) { return false; } if (approval != null ? !approval.equals(that.approval) : that.approval != null) { return false; } if (jobs != null ? !CollectionUtils.isEqualCollection(jobs, that.jobs) : that.jobs != null) { return false; } if (environment_variables != null ? !CollectionUtils.isEqualCollection(environment_variables, that.environment_variables) : that.environment_variables != null) { return false; } if (name != null ? !name.equals(that.name) : that.name != null) { return false; } return true; }
public void shouldGetValidationViolations() { WebDriver driver = AcceptanceTest.createWebDriver(); HtmlValidatingAsFormPage page = HtmlValidatingAsFormPage.open(driver); List<String> expectedValidationViolations = Arrays.asList( "Constraint Violation Null First Name Message", "Constraint Violation Null Age Message", "Constraint Violation Null Last Name Message"); List<String> actualValidationViolations = page.getValidationViolations(); assert CollectionUtils.isEqualCollection( expectedValidationViolations, actualValidationViolations) : "validation violations didn't match what was expected"; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; SymptomReport that = (SymptomReport) o; if (patientDocId != null ? !patientDocId.equals(that.patientDocId) : that.patientDocId != null) return false; if (symptomIds != null ? !CollectionUtils.isEqualCollection(symptomIds, that.symptomIds) : that.symptomIds != null) return false; return true; }
/** * Show the given entities in a table. * * <p>When dealing with <code>EventList</code> performance is important. This method ensures table * model events are launched just once at the end. * * @param <Q> the type of the rows. * @param tableModel the table model. * @param entities the entities to be shown. * @param attach whether to attach new entities to currents. If <code>false</code> currents are * replaced. * @return <code>true</code> if success and <code>false</code> in other case (i.e.:user rejected * change). */ @SuppressWarnings("unchecked") public static <Q> Boolean showEntities( GlazedTableModel tableModel, final List<Q> entities, final Boolean attach) { Assert.notNull(tableModel, TableUtils.TABLE_MODEL); Assert.notNull(entities, "entities"); Assert.notNull(attach, "attach"); final EventList<Q> eventList = TableUtils.getSource(tableModel); // Proceed only if ... final Boolean proceed; if (attach) { // ... must attach and entities are not contained in eventList or... proceed = !CollectionUtils.isSubCollection(entities, eventList); } else { // ... must replace and entities are not equals to eventList proceed = !CollectionUtils.isEqualCollection(entities, eventList); } if (proceed) { if (TableUtils.LOGGER.isDebugEnabled()) { TableUtils.LOGGER.debug("About to show entities " + entities); } // Avoid notifying in every single change, instead do it at the end final TableModelListener[] listeners = tableModel.getTableModelListeners(); for (final TableModelListener listener : listeners) { tableModel.removeTableModelListener(listener); } SwingUtils.runInEventDispatcherThread( new Runnable() { @Override public void run() { // Update the contents of the event list eventList.getReadWriteLock().writeLock().lock(); try { if (!attach) { eventList.clear(); } eventList.addAll(eventList.size(), CollectionUtils.subtract(entities, eventList)); } finally { // Since Swing is multithread we need to lock before and unlock later // http://sites.google.com/site/glazedlists/documentation/faq eventList.getReadWriteLock().writeLock().unlock(); } } }); // Enable notifying: install listeners again for (final TableModelListener listener : listeners) { tableModel.addTableModelListener(listener); } // Since listeners were uninstalled notification should be explicit tableModel.fireTableDataChanged(); } return proceed; }
/** * Method to enforce security and only allow administrators to modify users. Regular users are * allowed to modify themselves. * * @param method the name of the method executed * @param args the arguments to the method * @param target the target class * @throws Throwable thrown when args[0] is null or not a User object */ public void before(Method method, Object[] args, Object target) throws Throwable { SecurityContext ctx = SecurityContextHolder.getContext(); if (ctx.getAuthentication() != null) { Authentication auth = ctx.getAuthentication(); boolean administrator = false; GrantedAuthority[] roles = auth.getAuthorities(); for (GrantedAuthority role1 : roles) { if (role1.getAuthority().equals(Constants.ADMIN_ROLE)) { administrator = true; break; } } User user = (User) args[0]; AuthenticationTrustResolver resolver = new AuthenticationTrustResolverImpl(); // allow new users to signup - this is OK b/c Signup doesn't allow setting of roles boolean signupUser = resolver.isAnonymous(auth); if (!signupUser) { User currentUser = getCurrentUser(auth); if (user.getId() != null && !user.getId().equals(currentUser.getId()) && !administrator) { log.warn( "Access Denied: '" + currentUser.getUsername() + "' tried to modify '" + user.getUsername() + "'!"); throw new AccessDeniedException(ACCESS_DENIED); } else if (user.getId() != null && user.getId().equals(currentUser.getId()) && !administrator) { // get the list of roles the user is trying add Set<String> userRoles = new HashSet<String>(); if (user.getRoles() != null) { for (Object o : user.getRoles()) { Role role = (Role) o; userRoles.add(role.getName()); } } // get the list of roles the user currently has Set<String> authorizedRoles = new HashSet<String>(); for (GrantedAuthority role : roles) { authorizedRoles.add(role.getAuthority()); } // if they don't match - access denied // regular users aren't allowed to change their roles if (!CollectionUtils.isEqualCollection(userRoles, authorizedRoles)) { log.warn( "Access Denied: '" + currentUser.getUsername() + "' tried to change their role(s)!"); throw new AccessDeniedException(ACCESS_DENIED); } } } else { if (log.isDebugEnabled()) { log.debug("Registering new user '" + user.getUsername() + "'"); } } } }
protected <T> void assertCollectionEquivalent(Collection<T> expected, Collection<T> actual) { assertTrue(CollectionUtils.isEqualCollection(expected, actual)); }