Example usage for java.util Collections singletonList

List of usage examples for java.util Collections singletonList

Introduction

In this page you can find the example usage for java.util Collections singletonList.

Prototype

public static <T> List<T> singletonList(T o) 

Source Link

Document

Returns an immutable list containing only the specified object.

Usage

From source file:org.openmrs.web.controller.observation.PersonObsFormController.java

@Override
protected CommandObject formBackingObject(HttpServletRequest request) throws Exception {
    if (!Context.isAuthenticated()) {
        return new CommandObject();
    }/*from  ww  w. ja  v  a  2 s.  c  om*/

    Person person = Context.getPersonService().getPerson(Integer.valueOf(request.getParameter("personId")));
    List<Concept> concepts = null;
    Concept concept = null;
    if (request.getParameter("conceptId") != null) {
        concept = Context.getConceptService().getConcept(Integer.valueOf(request.getParameter("conceptId")));
        concepts = Collections.singletonList(concept);
    }

    ObsService os = Context.getObsService();
    List<Obs> ret = os.getObservations(Collections.singletonList(person), null, concepts, null, null, null,
            null, null, null, null, null, true);
    Collections.sort(ret, new Comparator<Obs>() {

        public int compare(Obs left, Obs right) {
            int temp = left.getConcept().getName().getName().compareTo(right.getConcept().getName().getName());
            if (temp == 0) {
                temp = OpenmrsUtil.compareWithNullAsGreatest(left.getVoided(), right.getVoided());
            }
            if (temp == 0) {
                temp = OpenmrsUtil.compareWithNullAsLatest(left.getObsDatetime(), right.getObsDatetime());
            }
            return temp;
        }

    });
    return new CommandObject(person, concept, ret);
}

From source file:com.whizzosoftware.hobson.dto.task.HobsonTaskDTOTest.java

@Test
public void testToJSON() {
    HobsonTaskDTO dto = new HobsonTaskDTO.Builder("taskLink").name("My Task").description("Task Desc")
            .conditions(Collections.singletonList(new PropertyContainerDTO.Builder("conditionclass1")
                    .containerClass(new PropertyContainerClassDTO.Builder("conditionClassLink").build())
                    .values(Collections.singletonMap("foo", (Object) "bar")).build()))
            .actionSet(new PropertyContainerSetDTO.Builder("actionSetLink")
                    .containers(Collections.singletonList(new PropertyContainerDTO.Builder("pc1").build()))
                    .build())//  w ww . ja  v a 2s  . com
            .build();

    JSONObject json = dto.toJSON();
    assertEquals("taskLink", json.getString("@id"));
    assertEquals("My Task", json.getString("name"));

    assertTrue(json.has("conditions"));
    JSONArray jcs = json.getJSONArray("conditions");
    assertEquals(1, jcs.length());
    JSONObject jct = jcs.getJSONObject(0);
    assertTrue(jct.has("cclass"));
    assertEquals("conditionClassLink", jct.getJSONObject("cclass").getString("@id"));
    assertTrue(jct.has("values"));

    assertTrue(json.has("actionSet"));
    JSONObject jas = json.getJSONObject("actionSet");
    assertTrue(jas.has("@id"));
    assertEquals("actionSetLink", jas.getString("@id"));
    assertTrue(jas.has("actions"));
}

From source file:be.fedict.trust.client.XKMS2ProxySelector.java

@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }/* w  w w . j av  a 2  s . c o  m*/
    List<Proxy> proxyList = this.defaultProxySelector.select(uri);
    return proxyList;
}

From source file:org.drugis.trialverse.security.Account.java

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
    return Collections.singletonList(userRole);
}

From source file:eionet.cr.harvest.util.CsvImportUtil.java

/**
 * Harvests CSV/TSV file./*from   www.java  2s.  co m*/
 *
 * @param subject Subject data object of file location.
 * @param uri file (Source/Graph) uri
 * @param userName user who executed the harvest
 * @return List of warning messages recieved from upload and post harvest scripts
 * @throws Exception if harvest fails
 */
public static List<String> harvestTableFile(SubjectDTO subject, String uri, String userName) throws Exception {

    List<String> warningMessages = new ArrayList<String>();

    String fileUri = uri;
    String fileLabel = subject.getObjectValue(Predicates.RDFS_LABEL);
    FileType fileType = FileType.valueOf(subject.getObjectValue(Predicates.CR_MEDIA_TYPE));
    String objectsType = subject.getObjectValue(Predicates.CR_OBJECTS_TYPE);
    String publisher = subject.getObjectValue(Predicates.DCTERMS_PUBLISHER);
    String license = subject.getObjectValue(Predicates.DCTERMS_RIGHTS);
    String attribution = subject.getObjectValue(Predicates.DCTERMS_BIBLIOGRAPHIC_CITATION);
    String source = subject.getObjectValue(Predicates.DCTERMS_SOURCE);
    long fileSize = Long.parseLong(subject.getObjectValue(Predicates.CR_BYTE_SIZE));
    Collection<String> uniqueColumns = subject.getObjectValues(Predicates.CR_OBJECTS_UNIQUE_COLUMN);

    String folderUri = StringUtils.substringBeforeLast(uri, "/");
    String relativeFilePath = FolderUtil.extractPathInUserHome(fileUri);

    // Clear graph
    DAOFactory.get().getDao(HarvestSourceDAO.class).removeHarvestSources(Collections.singletonList(uri));

    CsvImportHelper helper = new CsvImportHelper(new ArrayList<String>(uniqueColumns), fileUri, fileLabel,
            fileType, objectsType, publisher, license, attribution, source);

    // Store file as new source, but don't harvest it
    helper.insertFileMetadataAndSource(fileSize, userName);

    // Add metadata about user folder update
    helper.linkFileToFolder(folderUri, userName);

    // Parse and insert triples from file to triplestore
    CSVReader csvReader = helper.createCSVReader(folderUri, relativeFilePath, userName, true);

    try {
        csvReader = helper.createCSVReader(folderUri, relativeFilePath, userName, true);
        helper.extractObjects(csvReader);
        helper.saveWizardInputs();

        // Run data linking scripts
        try {
            List<String> warnings = helper.runScripts();
            if (warnings.size() > 0) {
                for (String w : warnings) {
                    warningMessages.add(w);
                }
            }
        } catch (Exception e) {
            LOGGER.error("Failed to run data linking scripts", e);
            warningMessages.add("Failed to run data linking scripts: " + e.getMessage());
        }
    } catch (Exception e) {
        LOGGER.error("Exception while reading uploaded file", e);
        warningMessages.add("Exception while reading uploaded file: " + e.getMessage());
    } finally {
        CsvImportHelper.close(csvReader);
    }

    return warningMessages;
}

From source file:com.acmemotors.rest.Main.java

@Bean
PoolFactoryBean poolFactoryBean(@Value("${gf.server.port}") int serverPort,
        @Value("${gf.server.host}") String serverHost) throws Exception {
    PoolFactoryBean factoryBean = new PoolFactoryBean();
    factoryBean.setName("my-pool");
    factoryBean.setServers(Collections.singletonList(new InetSocketAddress(serverHost, serverPort)));
    factoryBean.afterPropertiesSet();//from w ww.j a  v a 2  s .c  o  m
    return factoryBean;
}

From source file:com.yimidida.shards.strategy.exit.impl.AvgResultsExitOperation.java

public List<Object> apply(List<Object> results) {
    List<Object> nonNullResults = ExitOperationUtils.getNonNullList(results);
    Double total = null;//from   ww  w. j a v a  2s .com
    int numResults = 0;
    for (Object result : nonNullResults) {
        /**
         * We expect all entries to be Object arrays. the first entry in the
         * array is the average (a double) the second entry in the array is
         * the number of rows that were examined to arrive at the average.
         */
        Pair<Double, Integer> pair = getResultPair(result);
        Double shardAvg = pair.first;
        if (shardAvg == null) {
            // if there's no result from this shard it doesn't go into the
            // calculation. This is consistent with how avg is implemented
            // in the database
            continue;
        }
        int shardResults = pair.second;
        Double shardTotal = shardAvg * shardResults;
        if (total == null) {
            total = shardTotal;
        } else {
            total += shardTotal;
        }
        numResults += shardResults;
    }
    if (numResults == 0 || total == null) {
        return Collections.singletonList(null);
    }
    return Collections.<Object>singletonList(total / numResults);
}

From source file:com.cloudera.cdk.morphline.json.ReadJsonBuilder.java

@Override
public Collection<String> getNames() {
    return Collections.singletonList("readJson");
}

From source file:com.employee.scheduler.nurserostering.solver.move.EmployeeChangeMove.java

public Collection<? extends Object> getPlanningEntities() {
    return Collections.singletonList(shiftAssignment);
}

From source file:com.hp.autonomy.aci.content.identifier.reference.Reference.java

@Override
public Iterator<Reference> iterator() {
    // Should probably rewrite this to use a custom iterator
    return Collections.singletonList(this).iterator();
}