List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:com.devicehive.util.HiveValidator.java
/** * Validates object representation./*from w w w. j av a 2 s. c o m*/ * * @param object Object that should be validated * @throws HiveException if there is any constraint violations. */ public <T> void validate(T object) { Set<ConstraintViolation<?>> violations = new HashSet<>(validator.validate(object)); if (!violations.isEmpty()) { String response = buildMessage(violations); throw new HiveException(response, BAD_REQUEST.getStatusCode()); } }
From source file:org.commonjava.maven.atlas.graph.spi.neo4j.io.Conversions.java
@SuppressWarnings("incomplete-switch") public static void toRelationshipProperties(final ProjectRelationship<?, ?> rel, final Relationship relationship) { relationship.setProperty(INDEX, rel.getIndex()); String[] srcs = toStringArray(rel.getSources()); Logger logger = LoggerFactory.getLogger(Conversions.class); logger.debug("Storing rel: {}\nwith sources: {}\n in property: {}\nRelationship: {}", rel, Arrays.toString(srcs), SOURCE_URI, relationship); relationship.setProperty(SOURCE_URI, srcs); relationship.setProperty(POM_LOCATION_URI, rel.getPomLocation().toString()); relationship.setProperty(IS_INHERITED, rel.isInherited()); switch (rel.getType()) { case BOM://from ww w.j a v a2 s. c om relationship.setProperty(IS_MIXIN, rel.isMixin()); break; case DEPENDENCY: { final DependencyRelationship specificRel = (DependencyRelationship) rel; toRelationshipProperties((ArtifactRef) rel.getTarget(), relationship); relationship.setProperty(IS_MANAGED, specificRel.isManaged()); relationship.setProperty(SCOPE, specificRel.getScope().realName()); relationship.setProperty(OPTIONAL, specificRel.isOptional()); final Set<ProjectRef> excludes = specificRel.getExcludes(); if (excludes != null && !excludes.isEmpty()) { final StringBuilder sb = new StringBuilder(); for (final ProjectRef exclude : excludes) { if (sb.length() > 0) { sb.append(","); } sb.append(exclude.getGroupId()).append(":").append(exclude.getArtifactId()); } relationship.setProperty(EXCLUDES, sb.toString()); } break; } case PLUGIN_DEP: { toRelationshipProperties((ArtifactRef) rel.getTarget(), relationship); final PluginDependencyRelationship specificRel = (PluginDependencyRelationship) rel; final ProjectRef plugin = specificRel.getPlugin(); relationship.setProperty(PLUGIN_ARTIFACT_ID, plugin.getArtifactId()); relationship.setProperty(PLUGIN_GROUP_ID, plugin.getGroupId()); relationship.setProperty(IS_MANAGED, specificRel.isManaged()); break; } case PLUGIN: { final PluginRelationship specificRel = (PluginRelationship) rel; relationship.setProperty(IS_MANAGED, specificRel.isManaged()); relationship.setProperty(IS_REPORTING_PLUGIN, specificRel.isReporting()); break; } } }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java
@Override public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject();//from w ww .jav a2 s.c o m jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); } Date expiration = token.getExpiration(); if (expiration != null) { long now = System.currentTimeMillis(); jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); } Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { StringBuffer scopes = new StringBuffer(); for (String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + ""); scopes.append(s); scopes.append(" "); } jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); } Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (String key : additionalInformation.keySet()) { jgen.writeObjectField(key, additionalInformation.get(key)); } jgen.writeEndObject(); }
From source file:com.thoughtworks.inproctester.htmlunit.InProcessWebConnection.java
private void addCookiesToRequest(InProcRequest httpTester) { Set<Cookie> cookies = cookieManager.getCookies(); if (!cookies.isEmpty()) { List<String> cookieStrings = new ArrayList<String>(); for (Cookie cookie : cookies) { cookieStrings.add(cookie.getName() + "=" + cookie.getValue()); }/* w ww .ja va 2s.c o m*/ String cookieHeaderValue = StringUtils.join(cookieStrings, "; "); httpTester.addHeader("Cookie", cookieHeaderValue); } }
From source file:springfox.documentation.spring.web.readers.operation.ApiOperationReader.java
private Set<RequestMethod> supportedMethods(Set<RequestMethod> requestMethods) { return requestMethods == null || requestMethods.isEmpty() ? allRequestMethods : requestMethods; }
From source file:org.syncope.core.persistence.validation.entity.EntityValidationInterceptor.java
/** * Validate bean prior saving to DB./* ww w . jav a 2s . com*/ * * @param pjp Aspect's ProceedingJoinPoint * @return DAO method's return value * @throws Throwable if anything goes wrong */ @Around("execution(* org.syncope.core.persistence.dao..*.save(..))") public final Object save(final ProceedingJoinPoint pjp) throws Throwable { Set<ConstraintViolation<Object>> violations = validator.validate(pjp.getArgs()[0]); if (!violations.isEmpty()) { LOG.error("Bean validation errors found: {}", violations); throw new InvalidEntityException(pjp.getArgs()[0].getClass().getSimpleName(), violations); } return pjp.proceed(); }
From source file:net.jetrix.commands.IgnoreCommand.java
public void execute(CommandMessage message) { // get the user sending this command Client client = (Client) message.getSource(); User user = client.getUser();//from w w w . j a v a 2 s. c om // prepare the response PlineMessage response = new PlineMessage(); if (message.getParameterCount() == 0) { // display the ignore list Set ignoredUsers = user.getIgnoredUsers(); if (ignoredUsers.isEmpty()) { response.setKey("command.ignore.empty"); } else { response.setKey("command.ignore.list", StringUtils.join(ignoredUsers.iterator(), ", ")); } } else { // get the name of the (un)ignored player Client target = message.getClientParameter(0); String name = target != null ? target.getUser().getName() : message.getParameter(0); // add or remove the name from the ignore list if (user.ignores(name)) { user.unignore(name); response.setKey("command.ignore.removed", name); } else { user.ignore(name); response.setKey("command.ignore.added", name); } } // send the response client.send(response); }
From source file:net.maritimecloud.identityregistry.validators.DeviceValidatorTests.java
@Test public void validateValidDevice() { Device validDevice = new Device(); validDevice.setMrn("urn:mrn:mcl:device:testorg:test-device1"); validDevice.setName("Test Device"); Set<ConstraintViolation<Device>> violations = validator.validate(validDevice); assertTrue(violations.isEmpty()); }
From source file:net.orpiske.tcs.service.config.WebAppInitializer.java
private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) { AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MVCConfig.class); mvcContext.setParent(rootContext);//from w w w . ja v a2 s. c o m ServletRegistration.Dynamic appServlet = servletContext.addServlet("webservice", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(1); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("'webservice' cannot be mapped to '/'"); } }
From source file:org.osiam.client.helper.ScopeSerializer.java
@Override public void serialize(Set<Scope> value, JsonGenerator jgen, SerializerProvider provider) throws IOException { if (value != null && !value.isEmpty()) { StringBuilder scopeResult = new StringBuilder(); for (Scope scope : value) { scopeResult.append(scope).append(" "); }//from w ww .j av a 2s . c o m jgen.writeString(scopeResult.toString().trim()); } }