List of usage examples for java.util Collections emptySet
@SuppressWarnings("unchecked") public static final <T> Set<T> emptySet()
From source file:nu.yona.server.test.util.JUnitUtil.java
public static User createUserEntity(String firstName, String lastName, String mobileNumber, String nickname) { MessageSource anonymousMessageSource = MessageSource.createInstance(); UserAnonymized johnAnonymized = UserAnonymized.createInstance(anonymousMessageSource.getDestination(), Collections.emptySet()); UserAnonymized.getRepository().save(johnAnonymized); byte[] initializationVector = CryptoSession.getCurrent().generateInitializationVector(); MessageSource namedMessageSource = MessageSource.createInstance(); UserPrivate userPrivate = UserPrivate.createInstance(firstName, lastName, nickname, johnAnonymized.getId(), anonymousMessageSource.getId(), namedMessageSource); User user = new User(UUID.randomUUID(), initializationVector, mobileNumber, userPrivate, namedMessageSource.getDestination()); return User.getRepository().save(user); }
From source file:co.runrightfast.core.application.services.healthchecks.impl.HealthChecksServiceImpl.java
@Override public Set<String> getHealthCheckNames(final String registryName) { checkArgument(isNotBlank(registryName)); if (!SharedHealthCheckRegistries.names().contains(registryName)) { return Collections.emptySet(); }//from www . j a va 2 s . com return SharedHealthCheckRegistries.getOrCreate(registryName).getNames(); }
From source file:edu.cornell.mannlib.vitro.webapp.auth.identifier.common.CommonIdentifierBundleFactory.java
/** * If the user is logged in, create an identifier that shows his URI. *//*from w ww . j a v a2 s . c o m*/ private Collection<? extends Identifier> createUserIdentifiers(HttpServletRequest req) { LoginStatusBean bean = LoginStatusBean.getBean(req); if (bean.isLoggedIn()) { return Collections.singleton(new IsUser(bean.getUserURI())); } else { return Collections.emptySet(); } }
From source file:com.redhat.red.offliner.ftest.SingleFoloRecordDownloadFTest.java
/** * In general, we should only have one test method per functional test. This allows for the best parallelism when we * execute the tests, especially if the setup takes some time. * * @throws Exception In case anything (anything at all) goes wrong! *///www.j a va2 s . com @Test public void run() throws Exception { // We only need one repo server. TestRepositoryServer server = newRepositoryServer(); // Generate some test content byte[] content = contentGenerator.newBinaryContent(1024); TrackedContentEntryDTO dto = contentGenerator.newRemoteContentEntry(new StoreKey(StoreType.remote, "test"), "jar", server.getBaseUri(), content); TrackedContentDTO record = new TrackedContentDTO(new TrackingKey("test-record"), Collections.emptySet(), Collections.singleton(dto)); String path = dto.getPath(); // Register the generated content by writing it to the path within the repo server's dir structure. // This way when the path is requested it can be downloaded instead of returning a 404. server.registerContent(path, content); server.registerContent(path + Main.SHA_SUFFIX, sha1Hex(content)); server.registerContent(path + Main.MD5_SUFFIX, md5Hex(content)); // Write the plaintext file we'll use as input. File foloRecord = temporaryFolder.newFile("folo." + getClass().getSimpleName() + ".json"); FileUtils.write(foloRecord, objectMapper.writeValueAsString(record)); Options opts = new Options(); opts.setBaseUrls(Collections.singletonList(server.getBaseUri())); // Capture the downloads here so we can verify the content. File downloads = temporaryFolder.newFolder(); opts.setDownloads(downloads); opts.setLocations(Collections.singletonList(foloRecord.getAbsolutePath())); // run `new Main(opts).run()` and return the Main instance so we can query it for errors, etc. Main finishedMain = run(opts); assertThat("Wrong number of downloads logged. Should have been 3 including checksums.", finishedMain.getDownloaded(), equalTo(3)); assertThat("Errors should be empty!", finishedMain.getErrors().isEmpty(), equalTo(true)); File downloaded = new File(downloads, path); assertThat("File: " + path + " doesn't seem to have been downloaded!", downloaded.exists(), equalTo(true)); assertThat("Downloaded file: " + path + " contains the wrong content!", FileUtils.readFileToByteArray(downloaded), equalTo(content)); }
From source file:com.twinsoft.convertigo.engine.admin.services.roles.Add.java
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception { String username = request.getParameter("username"); String password = request.getParameter("password"); String[] roles = request.getParameterValues("roles"); Element root = document.getDocumentElement(); Element response = document.createElement("response"); try {//w ww . j a v a 2s. c o m if (StringUtils.isBlank(username)) { throw new IllegalArgumentException("Blank username not allowed"); } if (StringUtils.isBlank(password)) { throw new IllegalArgumentException("Blank password not allowed"); } if (Engine.authenticatedSessionManager.hasUser(username)) { throw new IllegalArgumentException("User '" + username + "' already exists"); } Set<Role> set; if (roles == null) { set = Collections.emptySet(); } else { set = new HashSet<Role>(roles.length); for (String role : roles) { set.add(Role.valueOf(role)); } } Engine.authenticatedSessionManager.setUser(username, DigestUtils.md5Hex(password), set); response.setAttribute("state", "success"); response.setAttribute("message", "User '" + username + "' have been successfully declared!"); } catch (Exception e) { Engine.logAdmin.error("Error during adding the user!\n" + e.getMessage()); response.setAttribute("state", "error"); response.setAttribute("message", "Error during adding the user!\n" + e.getMessage()); } root.appendChild(response); }
From source file:org.cloudfoundry.identity.uaa.authentication.AuthzAuthenticationRequest.java
@Override public Collection<? extends GrantedAuthority> getAuthorities() { if (null != info.get("authorities")) { Collection<ExtendedUaaAuthority> returnAuthorities = new LinkedHashSet(); String[] authorities = StringUtils.commaDelimitedListToStringArray(info.get("authorities")); for (String authority : authorities) { returnAuthorities.add(new ExtendedUaaAuthority(authority, null)); }/*from w w w .ja v a 2 s . c o m*/ return returnAuthorities; } else { return Collections.emptySet(); } }
From source file:com.vmware.identity.saml.idm.IdmPrincipalAttributesExtractor.java
@Override public Collection<PrincipalAttributeDefinition> getAllAttributeDefinitions() throws SystemException { Collection<Attribute> allAttributeDefinitions = Collections.emptySet(); try {/*from ww w . ja va 2 s . c om*/ allAttributeDefinitions = idmClient.getAttributeDefinitions(tenantName); } catch (Exception e) { throw new SystemException(e); } Set<PrincipalAttributeDefinition> result = Collections.emptySet(); if (allAttributeDefinitions != null) { log.trace("{} attribute definitions retrieved", allAttributeDefinitions.size()); result = new HashSet<PrincipalAttributeDefinition>(allAttributeDefinitions.size()); for (Attribute attrDefinition : allAttributeDefinitions) { if (attrDefinition == null || attrDefinition.getName() == null || attrDefinition.getNameFormat() == null) { throw new IllegalStateException("Missing or invalid attribute definition!"); } final PrincipalAttributeDefinition newDef = new PrincipalAttributeDefinition( attrDefinition.getName(), attrDefinition.getNameFormat(), attrDefinition.getFriendlyName()); result.add(newDef); log.trace("An attribute definition {} retrieved.", newDef); } } return result; }
From source file:org.shredzone.cilla.service.search.strategy.AbstractSearchStrategy.java
@SuppressWarnings("unchecked") @Override/*from ww w.j av a 2 s. com*/ public Set<Integer> fetchPageDays(SearchResultImpl result, Calendar calendar) throws CillaServiceException { if (calendar == null) { return Collections.emptySet(); } Calendar start = DateUtils.beginningOfMonth(calendar); Calendar end = DateUtils.beginningOfNextMonth(calendar); Criteria crit = createCriteria(result); crit.add(Restrictions.ge(pageOrder.getColumn(), start.getTime())); crit.add(Restrictions.lt(pageOrder.getColumn(), end.getTime())); // Sadly there is no HQL function to get the calendary day of a timestamp, // so we have to do all the hard work ourselves, to avoid SQL dialects. :( crit.setProjection(Projections.property(pageOrder.getColumn())); Calendar cal = Calendar.getInstance(calendar.getTimeZone()); Set<Integer> daysResult = new HashSet<>(); for (Date day : (List<Date>) crit.list()) { cal.setTime(day); daysResult.add(cal.get(Calendar.DAY_OF_MONTH)); } return daysResult; }
From source file:net.duckling.ddl.web.sync.JsonResponse.java
public static void startSession(HttpServletResponse response, String sessionId, Set<Integer> chunkMap, int chunkSize) { Map<String, Object> map = new HashMap<String, Object>(); map.put("session_id", sessionId); if (chunkMap == null) { chunkMap = Collections.emptySet(); }/*from ww w . j ava2s . co m*/ map.put("chunk_map", chunkMap); if (chunkSize != 0) { map.put("chunk_size", String.valueOf(chunkSize)); } JsonUtil.writeJSONObject(response, new Result<Map<String, Object>>(map)); }
From source file:com.codefollower.lealone.omid.tso.Uncommited.java
public Set<Long> raiseLargestDeletedTransaction(long id) { if (firstUncommitedAbsolute > getAbsolutePosition(id)) return Collections.emptySet(); int maxBucket = getRelativePosition(id); Set<Long> aborted = new TreeSet<Long>(); for (int i = firstUncommitedBucket; i != maxBucket; i = (i + 1) % BKT_NUMBER) { Bucket bucket = buckets[i];/*from w w w. j av a 2 s . co m*/ if (bucket != null) { aborted.addAll(bucket.abortAllUncommited()); buckets[i] = null; } } Bucket bucket = buckets[maxBucket]; if (bucket != null) { aborted.addAll(bucket.abortUncommited(id)); } increaseFirstUncommitedBucket(); return aborted; }