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:com.hp.autonomy.frontend.find.idol.comparison.ComparisonServiceImpl.java

private String generateDifferenceStateToken(final String firstQueryStateToken,
        final String secondQueryStateToken) throws AciErrorException {
    final QueryRestrictions<String> queryRestrictions = queryRestrictionsBuilderFactory.createBuilder()
            .setQueryText("*").setFieldText("").setMinScore(0)
            .setStateMatchId(Collections.singletonList(firstQueryStateToken))
            .setStateDontMatchId(Collections.singletonList(secondQueryStateToken)).build();

    return documentsService.getStateToken(queryRestrictions, ComparisonController.STATE_TOKEN_MAX_RESULTS,
            false);/*from   w  w w  .j ava  2 s.c  om*/
}

From source file:io.kodokojo.model.Entity.java

public Entity(String name, boolean concrete, User admin) {
    this(null, name, concrete, new ArrayList<>(), Collections.singletonList(admin),
            Collections.singletonList(admin));
}

From source file:mtsar.processors.task.InverseCountAllocatorTest.java

@Before
public void setup() {
    reset(taskDAO);//from w  ww .  ja  v a2  s . c o m
    reset(answerDAO);
    reset(countDAO);
    when(taskDAO.select(eq(Collections.singletonList(1)), anyString()))
            .thenReturn(Collections.singletonList(task1));
    when(taskDAO.select(eq(Collections.singletonList(2)), anyString()))
            .thenReturn(Collections.singletonList(task2));
    when(taskDAO.count(anyString())).thenReturn(tasks.size());
    when(answerDAO.listForWorker(anyInt(), anyString())).thenReturn(Collections.emptyList());
    when(dbi.onDemand(any())).thenReturn(countDAO);
    when(stage.getId()).thenReturn("1");
    when(answer1.getTaskId()).thenReturn(1);
    when(answer2.getTaskId()).thenReturn(2);
    when(answer3.getTaskId()).thenReturn(2);
}

From source file:de.micromata.genome.db.jpa.history.impl.CollectionPropertyConverter.java

@Override
public List<HistProp> convert(IEmgr<?> emgr, HistoryMetaInfo historyMetaInfo, Object entity,
        ColumnMetadata pd) {/* w w  w.j  a va 2  s.com*/
    Collection<?> col = (Collection<?>) pd.getGetter().get(entity);
    if (col == null) {
        return Collections.emptyList();
    }
    EntityMetadata targetEntity = pd.getTargetEntity();
    if (col.isEmpty() == true) {
        HistProp hp = new HistProp();
        hp.setName("");
        if (targetEntity != null) {
            hp.setType(targetEntity.getJavaType().getName());
        } else {
            hp.setType(col.getClass().getName());
        }
        hp.setValue("");
        return Collections.singletonList(hp);
    }

    if (targetEntity != null) {
        List<Object> pks = new ArrayList<>();
        for (Object ob : col) {
            Object pk = targetEntity.getIdColumn().getGetter().get(ob);
            if (pk == null) {
                LOG.warn("Unsaved entity in history");
                return Collections.emptyList();
            }
            pks.add(pk);
        }
        String sval = StringUtils.join(pks, ',');
        HistProp hp = new HistProp();
        hp.setName("");
        hp.setType(targetEntity.getJavaType().getName());
        hp.setValue(sval);
        return Collections.singletonList(hp);
    }

    Map<Long, Class<?>> pkSet = new TreeMap<>();
    int idx = 0;

    for (Object ob : col) {

        if ((ob instanceof DbRecord) == false) {
            LOG.warn("Cannot create collection history on non DbRecord: " + entity.getClass().getName() + "."
                    + pd.getName() + "[" + idx + "]" + ob.getClass().getName());
            continue;
        }
        DbRecord<?> rec = (DbRecord<?>) ob;
        Long lp = rec.getPkAsLong();
        if (lp == null) {
            LOG.warn("History; Unsafed PK in history: " + entity.getClass().getName() + "." + pd.getName() + "["
                    + idx + "]" + ob.getClass().getName());
            continue;
        }
        pkSet.put(lp, ob.getClass());
        ++idx;
    }
    idx = 0;
    List<HistProp> hpret = new ArrayList<>();
    for (Map.Entry<Long, Class<?>> me : pkSet.entrySet()) {
        HistProp hp = new HistProp();
        hp.setName(me.getValue().toString());
        hp.setType(col.getClass().getName() + "<" + me.getValue().getName() + ">");
        hp.setValue(me.getValue().toString());
        hpret.add(hp);
        ++idx;
    }
    return hpret;
}

From source file:org.bozzo.ipplan.web.assembler.ZoneResourceAssemblerTest.java

@Test
public void toResources_with_singleton_array_should_return_a_singleton_array() {
    Zone zone = new Zone();
    zone.setId(1L);//from w  w  w . java  2 s  .co  m
    zone.setDescription("Test description");
    zone.setInfraId(1);
    zone.setIp(0xC0A80001L);
    List<ZoneResource> resources = this.assembler.toResources(Collections.singletonList(zone));
    Assert.assertNotNull(resources);
    Assert.assertEquals(1, resources.size());
    Assert.assertTrue(ResourceSupport.class.isAssignableFrom(resources.get(0).getClass()));
}

From source file:it.geosolutions.geobatch.services.jmx.JMXConsumerManager.java

public JMXConsumerManager(Map<String, String> configuration, ServiceManager manager) throws Exception {
    super();//  www. j  av a 2s.  c  o m
    if (configuration == null)
        throw new IllegalArgumentException(
                "Unable to build the " + JMXConsumerManager.class + " using a null configuration");

    this.configurations = Collections.singletonList(configuration);

    this.manager = manager;

    this.uuid = manager.createConsumer(configuration);
}

From source file:ch.cern.db.flume.source.SpoolDirectorySourceTest.java

@Test
public void readWhenClosed() throws SQLException, InterruptedException, EventDeliveryException, IOException {

    Context context = new Context();
    context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY, spoolDir.getAbsolutePath());

    SpoolDirectorySource source = new SpoolDirectorySource();
    source.configure(context);//from ww  w . j  a v  a 2 s  .  c  o  m

    Map<String, String> channelContext = new HashMap<String, String>();
    channelContext.put("capacity", "100");
    channelContext.put("keep-alive", "0"); // for faster tests
    Channel channel = new MemoryChannel();
    Configurables.configure(channel, new Context(channelContext));

    ChannelSelector rcs = new ReplicatingChannelSelector();
    rcs.setChannels(Collections.singletonList(channel));
    ChannelProcessor chp = new ChannelProcessor(rcs);
    source.setChannelProcessor(chp);

    source.start();

    //Create file and close it
    PrintWriter file1 = new PrintWriter(new File(spoolDir, "file1"), "UTF-8");
    file1.println("file1-line1");
    file1.println("file1-line2");
    file1.close();

    Thread.sleep(2000);

    channel.getTransaction().begin();

    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals("file1-line1", new String(event.getBody()));
    event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals("file1-line2", new String(event.getBody()));
    event = channel.take();
    Assert.assertNull(event);

    channel.getTransaction().commit();
    channel.getTransaction().close();

    //Create file and leave it open
    PrintWriter file2 = new PrintWriter(new File(spoolDir, "file2"), "UTF-8");
    file2.println("file2-line1");
    file2.println("file2-line2");

    Thread.sleep(2000);

    channel.getTransaction().begin();
    event = channel.take();
    Assert.assertNull(event);
    channel.getTransaction().commit();
    channel.getTransaction().close();

    //Once file is closed, it must be processed
    file2.close();
    file2.flush();

    Thread.sleep(3000);

    channel.getTransaction().begin();

    event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals("file2-line1", new String(event.getBody()));
    event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals("file2-line2", new String(event.getBody()));
    event = channel.take();
    Assert.assertNull(event);

    channel.getTransaction().commit();
    channel.getTransaction().close();

    source.stop();
}

From source file:io.cloudslang.lang.compiler.modeller.transformers.JavaActionTransformer.java

@Override
public List<Scope> getScopes() {
    return Collections.singletonList(Scope.ACTION);
}

From source file:jails.http.converter.ResourceHttpMessageConverter.java

public List<MediaType> getSupportedMediaTypes() {
    return Collections.singletonList(MediaType.ALL);
}

From source file:ch.ralscha.extdirectspring.bean.ExtDirectFormPostResultTest.java

@Test
public void testExtDirectFormPostResultBindingResult() {
    BindingResult br = new TestBindingResult(Collections.<FieldError>emptyList());
    ExtDirectFormPostResult result = new ExtDirectFormPostResult(br);
    assertThat(result.getResult()).hasSize(1).contains(MapEntry.entry("success", Boolean.TRUE));

    FieldError error = new FieldError("testobject", "field1", "message");
    br = new TestBindingResult(Collections.singletonList(error));
    result = new ExtDirectFormPostResult(br);
    assertThat(result.getResult()).hasSize(2).contains(MapEntry.entry("success", Boolean.FALSE));
    Map<String, List<String>> errors = (Map<String, List<String>>) result.getResult().get("errors");
    assertThat(errors).isNotNull().hasSize(1);
    assertThat(errors.get("field1")).containsExactly("message");
}