Example usage for java.util Collections singletonMap

List of usage examples for java.util Collections singletonMap

Introduction

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

Prototype

public static <K, V> Map<K, V> singletonMap(K key, V value) 

Source Link

Document

Returns an immutable map, mapping only the specified key to the specified value.

Usage

From source file:de.hybris.platform.basecommerce.util.BaseCommerceBaseTest.java

protected OrderModel getOrderForCode(final String orderCode) {
    final DefaultGenericDao defaultGenericDao = new DefaultGenericDao(OrderModel._TYPECODE);
    defaultGenericDao.setFlexibleSearchService(flexibleSearchService);
    final List<OrderModel> orders = defaultGenericDao
            .find(Collections.singletonMap(OrderModel.CODE, orderCode));
    Assert.assertFalse(orders.isEmpty());
    final OrderModel orderModel = orders.get(0);
    Assert.assertNotNull("Order should have been loaded from database", orderModel);
    return orderModel;
}

From source file:net.javacrumbs.springws.test.helper.MessageValidatorTest.java

@Test
public void testAssertThatOk() throws Exception {
    WebServiceMessage message = createMessage("xml/valid-message.xml");
    Map<String, String> nsMap = Collections.singletonMap("ns", "http://www.example.org/schema");
    new MessageValidator(message).useNamespaceMapping(nsMap).assertXPath("//ns:number=0");
}

From source file:com.sillelien.dollar.api.types.AbstractDollarSingleValue.java

@NotNull
public <K extends Comparable<K>, V> ImmutableMap<K, V> toJavaMap() {
    return ImmutableMap.copyOf(Collections.singletonMap((K) "value", (V) value));
}

From source file:com.cognifide.aet.job.common.comparators.source.SourceComparator.java

@Override
@SuppressWarnings("unchecked")
public final ComparatorStepResult compare() throws ProcessingException {
    final ComparatorStepResult result;
    try {/*w  w  w.ja  v a 2s.c o m*/
        String patternSource = formatCode(
                artifactsDAO.getArtifactAsString(properties, properties.getPatternId()));
        String dataSource = formatCode(
                artifactsDAO.getArtifactAsString(properties, properties.getCollectedId()));

        for (DataFilterJob<String> dataFilterJob : dataFilterJobs) {
            LOGGER.info("Starting {}. Company: {} Project: {}", dataFilterJob.getInfo(),
                    properties.getCompany(), properties.getProject());

            dataSource = dataFilterJob.modifyData(dataSource);

            LOGGER.info("Successfully ended data modifications using  {}. Company: {} Project: {}",
                    dataFilterJob.getInfo(), properties.getCompany(), properties.getProject());

            patternSource = dataFilterJob.modifyPattern(patternSource);

            LOGGER.info("Successfully ended pattern modifications using {}. Company: {} Project: {}",
                    dataFilterJob.getInfo(), properties.getCompany(), properties.getProject());
        }

        if (StringUtils.isNotBlank(patternSource)) {
            boolean compareTrimmedLines = shouldCompareTrimmedLines(sourceCompareType);
            final List<ResultDelta> deltas = diffParser.generateDiffs(patternSource, dataSource,
                    compareTrimmedLines);
            if (deltas.isEmpty()) {
                result = new ComparatorStepResult(null, ComparatorStepResult.Status.PASSED, false);
            } else {
                result = new ComparatorStepResult(
                        artifactsDAO.saveArtifactInJsonFormat(properties,
                                Collections.singletonMap("differences", deltas)),
                        ComparatorStepResult.Status.FAILED, true);
                result.addData("formattedPattern", artifactsDAO.saveArtifact(properties, patternSource));
                result.addData("formattedSource", artifactsDAO.saveArtifact(properties, dataSource));
                result.addData("sourceCompareType", sourceCompareType.name());
            }
        } else {
            result = new ComparatorStepResult(null, ComparatorStepResult.Status.PASSED);
        }
    } catch (Exception e) {
        throw new ProcessingException(e.getMessage(), e);
    }

    return result;
}

From source file:edu.umich.flowfence.common.TaintSet.java

private TaintSet(ComponentName singleTaint, float singleAmount) {
    taints = Collections.singletonMap(Objects.requireNonNull(singleTaint), singleAmount);
}

From source file:com.thoughtworks.go.server.service.BackupScheduler.java

private JobDataMap jobDataMap() {
    return new JobDataMap(Collections.singletonMap(ScheduleBackupQuartzJob.BACKUP_SCHEDULER_KEY, this));
}

From source file:com.example.app.profile.model.client.ClientDAO.java

/**
 * Create client profile type profile type.
 *
 * @param progId the prog id//from ww  w.  j  ava2s  .co m
 *
 * @return the profile type
 */
public ProfileType createClientProfileType(@Nullable String progId) {
    ProfileType pt = new ProfileType();
    TransientLocalizedObjectKey tlok = new TransientLocalizedObjectKey(
            Collections.singletonMap(Locale.ENGLISH, "Client PT"));

    pt.setName(tlok);
    pt.setProgrammaticIdentifier(
            isEmptyString(progId) ? GloballyUniqueStringGenerator.getUniqueString() : progId);

    pt.getMembershipTypeSet().add(
            _companyDAO.createMembershipType(pt, MembershipTypeInfo.SystemAdmin, () -> _mop.getOperations()));

    return pt;
}

From source file:ru.mystamps.web.dao.impl.JdbcCountryDao.java

@Override
public long countAddedSince(Date date) {
    return jdbcTemplate.queryForObject(countCountriesAddedSinceSql, Collections.singletonMap("date", date),
            Long.class);
}

From source file:com.logsniffer.reader.grok.GrokTest.java

@Test
public void testBasePatternSet() throws GrokException, IOException {
    GroksRegistry r = new GroksRegistry();
    r.registerPatternBlocks(Collections.singletonMap("base",
            IOUtils.readLines(getClass().getResourceAsStream("/grok-patterns/base")).toArray(new String[0])));
    String sysLogLine = "Nov  1 21:14:23 <1.3> localhost kernel: pid 84558 (expect), uid 30206: exited on signal 3";
    Grok syslogGrok = Grok.compile(r,//  www  .  j  a  v  a 2s.  co m
            "%{SYSLOGBASE} pid %{NUMBER:pid} \\(%{WORD:program2}\\), uid %{NUMBER:uid}: exited on signal %{NUMBER:signal}");
    GrokMatcher m = syslogGrok.matcher(sysLogLine);
    assertEquals(true, m.matches());
    assertEquals("Nov  1 21:14:23", m.group("timestamp"));
    assertEquals("1", m.group("facility"));
    assertEquals("3", m.group("priority"));
    assertEquals("localhost", m.group("logsource"));
    assertEquals("kernel", m.group("program"));
    assertEquals("expect", m.group("program2"));
    assertEquals("30206", m.group("uid"));
    assertEquals("3", m.group("signal"));
    assertEquals("84558", m.group("pid"));
}

From source file:Main.java

/**
 * Copies the given {@link Map} into a new {@link Map}.<br>
 * //from  www .jav  a  2s.  c o m
 * @param <A>
 *            the type of the keys of the map
 * @param <B>
 *            the type of the values of the map
 * @param data
 *            the given map
 * @return If the given map was empty, a {@link Collections#emptyMap()} is
 *         returned<br>
 *         If the given map contained only one entry, a
 *         {@link Collections#singletonMap(Object, Object)}, containing
 *         said entry, is returned <br>
 *         If the given map contained more than one element, a
 *         {@link Collections#unmodifiableMap(Map)}, containing the entries
 *         of the given map, is returned.
 */
public static <A, B> Map<A, B> copy(Map<A, B> data) {
    final int size = data.size();

    switch (size) {
    case 0:
        return Collections.emptyMap();
    case 1:
        final A key = data.keySet().iterator().next();
        return Collections.singletonMap(key, data.get(key));
    default:
        return Collections.unmodifiableMap(new HashMap<A, B>(data));
    }
}