List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:org.grails.plugin.google.drive.GoogleDrive.java
static Credential authorize(String clientId, String clientSecret, String credentialsPath, String credentialStore, HttpTransport httpTransport, JsonFactory jsonFactory) throws IOException { GoogleClientSecrets.Details installedDetails = new GoogleClientSecrets.Details(); installedDetails.setClientId(clientId); installedDetails.setClientSecret(clientSecret); GoogleClientSecrets clientSecrets = new GoogleClientSecrets(); clientSecrets.setInstalled(installedDetails); FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new java.io.File(credentialsPath)); DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialStore); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE)).setCredentialDataStore(datastore) .build();//from w ww . ja v a 2s . c om return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.novartis.pcs.ontology.rest.servlet.GraphServlet.java
private String getExpectedMediaType(HttpServletRequest request) { String mediaType = null;/*from w ww . j a v a2s. c o m*/ String acceptHeader = request.getHeader("Accept"); if (acceptHeader != null) { mediaType = StringUtils .trimToNull(MIMEParse.bestMatch(Collections.singleton(MEDIA_TYPE_SVG), acceptHeader)); } return mediaType; }
From source file:de.hybris.platform.print.facades.impl.DefaultPrintCollaborationFacadeTest.java
/** * Filter comment list by TYPE COMMENT//from ww w .j ava 2 s .c o m */ @Test public void testFilterByTypeComment() { final FilterCondition<CommentType> filterCondition = new AbstractFilterCondition<CommentType>() { @Override public String getFilterBy() { return "TYPE"; } }; filterCondition.setValues(Collections.singleton(CommentType.COMMENT)); final Collection<CommentModel> filteredCommentList = printCollaborationFacade.filterAndSortComments( Collections.<FilterCondition>singletonList(filterCondition), Collections.<SortCondition>emptyList(), getCommentModelList()); assertThat(filteredCommentList).isNotEmpty(); assertThat(filteredCommentList).containsOnly(getCommentModel()); }
From source file:musite.prediction.feature.disorder.DisorderTest.java
@Test public void extractMean() throws IOException { // String xml = "testData/musite-test.xml"; String xml = "data/Uniprot/uniprot_sprot.201009.ptm.musite.with.disorder.xml"; ProteinsXMLReader reader = DisorderUtil.getDisorderXMLReader(); Proteins proteins = MusiteIOUtil.read(reader, xml); TTest ttest = new TTestImpl(); StandardDeviation std = new StandardDeviation(); Map<AminoAcid, double[]> mapAAScores = new EnumMap<AminoAcid, double[]>(AminoAcid.class); for (AminoAcid aa : AminoAcid.values()) { List<Double> scores = new ArrayList<Double>(); Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Protein protein = it.next(); List<Double> dis = DisorderUtil.extractDisorder(protein, aa); if (dis != null) scores.addAll(dis);//from w w w. j a v a 2 s .c o m } mapAAScores.put(aa, list2array(scores)); // System.out.print(aa.toString()+":"); // System.out.println(""+average(scores)+"("+scores.size()+")"); } Map<String, AminoAcid> mapKeyAA = getMapKeywordAminoAcid(); for (PTM ptm : PTM.values()) { Set<String> keywords = ptm.getUniprotKeywords(); for (String keyword : keywords) { AnnotationFilter filter = ResidueAnnotationUtil.createAnnotationFilter("keyword", Collections.singleton(keyword), true); double[] scores; { List<Double> list = new ArrayList<Double>(); Iterator<Protein> it = proteins.proteinIterator(); while (it.hasNext()) { Protein protein = it.next(); List<Double> dis = DisorderUtil.extractDisorder(protein, ptm, filter); if (dis != null) list.addAll(dis); } scores = list2array(list); } System.out.print(ptm.toString()); System.out.print("\t" + keyword); if (scores.length == 0) System.out.println("\tno_site"); else { System.out.print("\t" + scores.length); double mean = StatUtils.mean(scores); System.out.print("\t" + mean); System.out.print("\t" + std.evaluate(scores, mean)); AminoAcid aa = mapKeyAA.get(keyword); double[] bg = mapAAScores.get(aa); System.out.print("\t" + aa.toString()); System.out.print("\t" + bg.length); mean = StatUtils.mean(bg); System.out.print("\t" + mean); System.out.print("\t" + std.evaluate(bg, mean)); double pvalue = -1.0; try { pvalue = ttest.tTest(scores, bg); } catch (Exception e) { // e.printStackTrace(); } if (pvalue != -1.0) System.out.print("\t" + pvalue); System.out.println(); } } } }
From source file:com.googlesource.gerrit.plugins.github.wizard.AccountController.java
private void setAccountIdentity(IdentifiedUser user, HttpServletRequest req) throws ServletException { String fullName = req.getParameter("fullname"); String email = req.getParameter("email"); try {/* www .j av a 2 s. c o m*/ Id accountId = user.getAccountId(); AuthResult result = accountManager.link(accountId, AuthRequest.forEmail(email)); log.debug("Account {} linked to email {}: result = {}", accountId, email, result); Account a = dbProvider.get().accounts().get(accountId); a.setPreferredEmail(email); a.setFullName(fullName); dbProvider.get().accounts().update(Collections.singleton(a)); log.debug("Account {} updated with preferredEmail = {} and fullName = {}", accountId, email, fullName); accountCache.evict(accountId); log.debug("Account cache evicted for {}", accountId); } catch (AccountException | OrmException e) { throw new ServletException("Cannot associate email '" + email + "' to current user '" + user + "'", e); } }
From source file:com.nesscomputing.cache.NamespacedCache.java
/** * Clear a single key * @see NessCache#clear(String, java.util.Collection) */ public void clear(String key) { clear(Collections.singleton(key)); }
From source file:io.lavagna.service.SearchServiceTest.java
@Before public void prepare() { userRepository.createUser("test", "test", null, null, true); userRepository.createUser("test", "test-no-access", null, null, true); user = userRepository.findUserByName("test", "test"); userWithNoAccess = userRepository.findUserByName("test", "test-no-access"); Role r = new Role("TEST"); permissionService.createRole(r);/*from w w w. j av a2 s . com*/ permissionService.updatePermissionsToRole(r, EnumSet.of(Permission.READ)); permissionService.assignRolesToUsers(Collections.singletonMap(r, Collections.singleton(user.getId()))); userWithPermissions = new UserWithPermission(user, permissionService.findBasePermissionByUserId(user.getId()), Collections.<String, Set<Permission>>emptyMap(), Collections.<Integer, Set<Permission>>emptyMap()); userWithNoAccessPermission = new UserWithPermission(userWithNoAccess, permissionService.findBasePermissionByUserId(userWithNoAccess.getId()), Collections.<String, Set<Permission>>emptyMap(), Collections.<Integer, Set<Permission>>emptyMap()); project = projectService.create("test search", "TEST-SRC", "desc"); board = boardRepository.createNewBoard("TEST-SEARCH", "TEST-SRC", "desc", project.getId()); List<BoardColumnDefinition> columnDefinitions = projectService .findColumnDefinitionsByProjectId(project.getId()); for (BoardColumnDefinition bcd : columnDefinitions) { if (bcd.getValue() == ColumnDefinition.OPEN) { column = boardColumnRepository.addColumnToBoard("test", bcd.getId(), BoardColumnLocation.BOARD, board.getId()); } else if (bcd.getValue() == ColumnDefinition.CLOSED) { closedColumn = boardColumnRepository.addColumnToBoard("test", bcd.getId(), BoardColumnLocation.BOARD, board.getId()); } } }
From source file:org.jasig.services.persondir.support.AdditionalDescriptorsPersonAttributeDao.java
/** * Returns an empty <code>Set</code>, per the API documentation, because we * don't use any attributes in queries.//from w w w . ja va 2 s . c o m */ public Set<String> getAvailableQueryAttributes() { final IUsernameAttributeProvider usernameAttributeProvider = super.getUsernameAttributeProvider(); return Collections.singleton(usernameAttributeProvider.getUsernameAttribute()); }
From source file:org.openmrs.module.radiologyapp.RadiologyServiceComponentTest.java
@Test public void placeRadiologyRequistion_shouldPlaceARadiologyRequisition() throws Exception { Patient patient = patientService.getPatient(6); Visit visit = visitService.getVisit(4); // sanity check Assert.assertEquals(0, encounterService.getEncountersByPatient(patient).size()); RadiologyRequisition requisition = new RadiologyRequisition(); requisition.setPatient(patient);//w w w.ja v a 2 s. co m requisition.setStudies(Collections.singleton(conceptService.getConcept(18))); requisition.setUrgency(Order.Urgency.STAT); requisition.setRequestedBy(providerService.getProvider(1)); requisition.setRequestedOn(new Date()); requisition.setRequestedFrom(locationService.getLocation(1)); requisition.setVisit(visit); requisition.setCreatinineLevel(1.8); requisition.setCreatinineTestDate(new DateTime(2014, 1, 1, 20, 0, 0, 0).toDate()); radiologyService.placeRadiologyRequisition(requisition); List<Encounter> encounters = encounterService.getEncountersByPatient(patient); Assert.assertEquals(1, encounters.size()); Assert.assertEquals(visit, encounters.get(0).getVisit()); Set<Order> orders = encounters.get(0).getOrders(); Assert.assertEquals(1, orders.size()); Set<Obs> obs = encounters.get(0).getObs(); Assert.assertEquals(1, obs.size()); }
From source file:com.alibaba.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar.java
private void registerDubboConfigBeans(String prefix, Class<? extends AbstractConfig> configClass, boolean multiple, BeanDefinitionRegistry registry) { PropertySources propertySources = environment.getPropertySources(); Map<String, String> properties = getSubProperties(propertySources, prefix); if (CollectionUtils.isEmpty(properties)) { if (log.isDebugEnabled()) { log.debug("There is no property for binding to dubbo config class [" + configClass.getName() + "] within prefix [" + prefix + "]"); }// w w w .j a v a 2s . c om return; } Set<String> beanNames = multiple ? resolveMultipleBeanNames(prefix, properties) : Collections.singleton(resolveSingleBeanName(configClass, properties, registry)); for (String beanName : beanNames) { registerDubboConfigBean(beanName, configClass, registry); MutablePropertyValues propertyValues = resolveBeanPropertyValues(beanName, multiple, properties); registerDubboConfigBindingBeanPostProcessor(beanName, propertyValues, registry); } }