List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:org.jrecruiter.service.DemoServiceTest.java
@Test @Rollback(false)// w w w.j a va 2 s. c o m public void testRestore() { final java.io.InputStream inputStream = DemoServiceTest.class .getResourceAsStream("/org/jrecruiter/core/seeddata/demodata.xml"); final Backup backup = demoService.convertToBackupData(inputStream); for (User user : backup.getUsers()) { final Set<UserToRole> userToRoles = user.getUserToRoles(); Assert.assertTrue("Every user should have at least one role.", !userToRoles.isEmpty()); for (final UserToRole userToRole : userToRoles) { Assert.assertNotNull(userToRole.getRoleName()); } } }
From source file:org.biopax.validator.rules.ComplexAssemblyHasComplexParticipantRule.java
public void check(final Validation validation, ComplexAssembly complexAssembly) { // check if there are any complexes on either side Set<Complex> complexes = new ClassFilterSet<Entity, Complex>(complexAssembly.getParticipant(), Complex.class); if (complexes.isEmpty()) { boolean bound = isBound(complexAssembly.getRight()); if (!bound) bound = isBound(complexAssembly.getLeft()); if (!bound) error(validation, complexAssembly, "complex.not.present", false); }//www . j av a 2 s . co m }
From source file:com.qq.common.WrappedController.java
protected void validate(Object bean, Class<?>... groups) throws ServletRequestBindingException { ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); Validator validator = validatorFactory.getValidator(); Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean, groups); if (!constraintViolations.isEmpty()) { StringBuilder sb = new StringBuilder(); for (ConstraintViolation<Object> constraint : constraintViolations) { sb.append(String.format("%s %s\n", constraint.getPropertyPath(), constraint.getMessage())); }/*from ww w . j a v a 2 s.com*/ throw new ServletRequestBindingException(sb.toString()); } }
From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java
/** * //from w w w . j a va 2s .c o m * @param entity * @param req * @return a Map containing the following attributes with their respective keys: * <ol> * <li>"id": the Id of the BusinessUnit</li> * <li>"name": the name of the BusinessUnit</li> * <li>"description": the description of</li> * <li>"lastModified": a String representation of the last modification date/time, formatted by the {@code ISO_DATE_TIME_FORMATTER} </li> * <li>"parentUri": the URI of the parent Building Block. Key only exists if there is a parent.</li> * <li>"attributes": all attributes of the BusinessUnit</li> * <li>"connectedInformationSystems": all InformationSystemReleases that are connected to the BusinessUnit via at least one BusinessMapping</li> * </ol> */ public static Map<String, Object> convertToMap(BusinessUnit entity, HttpServletRequest req) { Map<String, Object> result = Maps.newHashMap(); result.put("id", entity.getId()); result.put("name", entity.getName()); result.put("description", entity.getDescription()); LocalDateTime modificationTime = new LocalDateTime(entity.getLastModificationTime()); result.put("lastModified", ISO_DATE_TIME_FORMATTER.print(modificationTime)); if (entity.getParent() != null) { String parentUri = URLBuilder.getEntityURL(entity.getParent(), req, URLBuilder.EntityRepresentation.JSON); result.put("parentUri", parentUri); } Set<String> isURIs = Sets.newTreeSet(); for (BusinessMapping bm : entity.getBusinessMappings()) { if (bm.getInformationSystemRelease() != null) { isURIs.add(URLBuilder.getEntityURL(bm.getInformationSystemRelease(), req, URLBuilder.EntityRepresentation.JSON)); } } AttributesComponentModel attributesModel = new AttributesComponentModel(ComponentMode.READ, "") { private static final long serialVersionUID = 1L; @Override public boolean showATG(AttributeTypeGroup atg) { return true; } }; attributesModel.initializeFrom(entity); result.put("attributes", attributesModel.getAtgParts()); if (!isURIs.isEmpty()) { result.put("connectedInformationSystems", isURIs); } return result; }
From source file:com.haulmont.cuba.core.global.filter.QueryFilter.java
public String processQuery(String query, Map<String, Object> paramValues) { Set<String> params = new HashSet<>(); for (Map.Entry<String, Object> entry : paramValues.entrySet()) { if (paramValueIsOk(entry.getValue())) params.add(entry.getKey());//w ww . jav a2 s . co m } query = TemplateHelper.processTemplate(query, paramValues); if (isActual(root, params)) { Condition refined = refine(root, params); if (refined != null) { QueryTransformer transformer = QueryTransformerFactory.createTransformer(query); String where = new FilterJpqlGenerator().generateJpql(refined); if (!StringUtils.isBlank(where)) { Set<String> joins = refined.getJoins(); if (!joins.isEmpty()) { String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString(); transformer.addJoinAndWhere(joinsStr, where); } else { transformer.addWhere(where); } } return transformer.getResult(); } } return query; }
From source file:hr.fer.spocc.automaton.fsm.AbstractNondeterministicFiniteAutomaton.java
@Override public boolean process(T input) { if (getStartState() == null) throw new IllegalStateException("No start state defined"); // za epsilon prijelaz ignoriramo if (input == null) return true; Set<State> nextStates = powerSet(getNextStates(input, powerSet(getCurrentStates()))); setCurrentStates(nextStates);/*from w w w . j a va2s . c o m*/ return !nextStates.isEmpty(); }
From source file:it.units.malelab.ege.util.Utils.java
public static <T> Node<T> expand(T symbol, Grammar<T> grammar, int depth, int maxDepth) { //TODO something not good here on text.bnf if (depth > maxDepth) { return null; }/*from w w w .j av a 2 s .c o m*/ Node<T> node = new Node<>(symbol); List<List<T>> options = grammar.getRules().get(symbol); if (options == null) { return node; } Set<Node<T>> children = new LinkedHashSet<>(); for (List<T> option : options) { Set<Node<T>> optionChildren = new LinkedHashSet<>(); boolean nullNode = false; for (T optionSymbol : option) { Node<T> child = expand(optionSymbol, grammar, depth + 1, maxDepth); if (child == null) { nullNode = true; break; } optionChildren.add(child); } if (!nullNode) { children.addAll(optionChildren); } } if (children.isEmpty()) { return null; } for (Node<T> child : children) { node.getChildren().add(child); } node.propagateParentship(); return node; }
From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Create the root appcontext AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfig.class); rootContext.register(PersistenceConfig.class); // Manage the lifecycle of the root appcontext servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); this.zkLoaderServlet(servletContext); // now the config for the Dispatcher servlet AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(WebMvcConfig.class); // Filters/*from ww w . j ava 2 s .c o m*/ // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/package-summary.html // Enables support for DELETE and PUT request methods with web browser // clients // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/HiddenHttpMethodFilter.html FilterRegistration.Dynamic fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter()); fr.addMappingForUrlPatterns(null, true, "/*"); fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); fr.addMappingForUrlPatterns(null, true, "/*"); // The main Spring MVC servlet. ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(2); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } HttpSessionListener zkCleanUp = new HttpSessionListener(); servletContext.addListener(zkCleanUp); this.logbackServlet(servletContext); this.zkUpdateServlet(servletContext); }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.AccessConfirmationController.java
/** * Request the user confirmation for the resources enabled for the requesting client * @param model/* ww w . j av a 2 s.c o m*/ * @return * @throws Exception */ @RequestMapping("/oauth/confirm_access") public ModelAndView getAccessConfirmation(Map<String, Object> model) throws Exception { AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest"); // load client information given the client credentials obtained from the request ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); ClientAppInfo info = ClientAppInfo.convert(client.getAdditionalInformation()); List<Resource> resources = new ArrayList<Resource>(); Set<String> all = client.getScope(); Set<String> requested = clientAuth.getScope(); if (requested == null || requested.isEmpty()) { requested = all; } else { requested = new HashSet<String>(requested); for (Iterator<String> iterator = requested.iterator(); iterator.hasNext();) { String r = iterator.next(); if (!all.contains(r)) iterator.remove(); } } for (String rUri : requested) { try { Resource r = resourceRepository.findByResourceUri(rUri); // ask the user only for the resources associated to the user role and not managed by this client if (r.getAuthority().equals(AUTHORITY.ROLE_USER) && !clientAuth.getClientId().equals(r.getClientId())) { resources.add(r); } } catch (Exception e) { logger.error("Error reading resource with uri " + rUri + ": " + e.getMessage()); } } model.put("resources", resources); model.put("auth_request", clientAuth); model.put("clientName", info.getName()); return new ModelAndView("access_confirmation", model); }
From source file:com.github.rinde.rinsim.core.pdptw.RandomVehicle.java
@Override protected void tickImpl(TimeLapse time) { if (!time.hasTimeLeft()) { return;/*w w w . jav a2 s .c om*/ } if (!target.isPresent()) { target = findTarget(); } if (target.isPresent()) { if (pm.get().containerContains(this, target.get())) { if (rm.get().getPosition(this).equals(target.get().getDestination())) { pm.get().deliver(this, target.get(), time); } else { rm.get().moveTo(this, target.get().getDestination(), time); } } else { if (pm.get().getParcelState(target.get()) != ParcelState.AVAILABLE) { // somebody got there first target = Optional.absent(); } else if (rm.get().equalPosition(this, target.get())) { pm.get().pickup(this, target.get(), time); } else { rm.get().moveTo(this, target.get(), time); } } } else { final Set<DefaultDepot> depots = rm.get().getObjectsOfType(DefaultDepot.class); if (!depots.isEmpty()) { rm.get().moveTo(this, depots.iterator().next(), time); } } }