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:Main.java

/** Returns a list of available camera flash modes. If the Android API doesn't support getting flash modes (requires 2.0 or later),
 * returns a list with a single element of "off", corresponding to Camera.Parameters.FLASH_MODE_OFF.
 *//* w  ww.  j  a  v  a 2s.c om*/
public static List<String> getFlashModes(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModesMethod = params.getClass().getMethod("getSupportedFlashModes");
        @SuppressWarnings("unchecked")
        List<String> result = (List<String>) flashModesMethod.invoke(params);
        if (result != null)
            return result;
    } catch (Exception ignored) {
    }
    return Collections.singletonList("off");
}

From source file:Main.java

public static void signEmbeded(Node doc, String uri, PrivateKey privKey, PublicKey pubKey)
        throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, KeyException, MarshalException,
        XMLSignatureException {/*from   w  ww.j  a v  a 2 s.  co m*/

    XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");

    Reference ref = fac.newReference(uri, fac.newDigestMethod(DigestMethod.SHA1, null),
            Collections.singletonList(fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null)),
            null, null);

    // Create the SignedInfo
    String method = SignatureMethod.RSA_SHA1; // default

    if ("DSA".equals(privKey.getAlgorithm()))
        method = SignatureMethod.DSA_SHA1;

    SignedInfo si = fac.newSignedInfo(fac.newCanonicalizationMethod(CanonicalizationMethod.INCLUSIVE, // Default canonical
            (C14NMethodParameterSpec) null), fac.newSignatureMethod(method, null),
            Collections.singletonList(ref));

    KeyInfoFactory kif = fac.getKeyInfoFactory();
    KeyValue kv = kif.newKeyValue(pubKey);

    // Create a KeyInfo and add the KeyValue to it
    List<XMLStructure> kidata = new ArrayList<XMLStructure>();
    kidata.add(kv);
    KeyInfo ki = kif.newKeyInfo(kidata);

    // Create a DOMSignContext and specify the PrivateKey and
    // location of the resulting XMLSignature's parent element
    DOMSignContext dsc = new DOMSignContext(privKey, doc);

    // Create the XMLSignature (but don't sign it yet)
    XMLSignature signature = fac.newXMLSignature(si, ki);

    // Marshal, generate (and sign) the enveloped signature
    signature.sign(dsc);

}

From source file:Main.java

public static <E> ArrayList<E> newSingletonArrayList(E element) {
    return new ArrayList<>(Collections.singletonList(element));
}

From source file:Main.java

public static List<Object> contextAsList(Object context) {
    if (context instanceof Iterable<?>) {
        List<Object> list = new ArrayList<>();
        ((Iterable<?>) context).forEach(value -> list.add(value));
        return list;
    }//  w ww .j  a  v a  2s .c o m

    return Collections.singletonList(context);
}

From source file:Main.java

public static List getList(Object... objs) {
    if (objs.length == 0) {
        return Collections.emptyList();
    } else if (objs.length == 1) {
        return Collections.singletonList(objs[0]);
    } else {/* ww  w. j  ava 2 s .c o m*/
        return new ArrayList(Arrays.asList(objs));
    }
}

From source file:Main.java

static <E> List<E> getList(List<E> orig, Class<E> elemType) {
    if (orig == null || orig.isEmpty()) {
        return Collections.emptyList();
    } else if (orig.size() == 1) {
        return Collections.singletonList(orig.get(0));
    } else {//from  w ww .  jav a2  s .  com
        return Collections.unmodifiableList(Arrays.asList(orig.toArray(createArray(elemType, orig.size()))));
    }
}

From source file:Main.java

private static SignedInfo createSignedInfo(final String algorithm,
        final SignatureMethodParameterSpec methodParamSpec, final String signatureId, final String referenceUri)
        throws SignatureException {
    try {//from   w  w  w  .ja v a2s.co  m
        final CanonicalizationMethod canonicalizationMethod = getXMLSignatureFactory()
                .newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (XMLStructure) null);
        final SignatureMethod signatureMethod = getXMLSignatureFactory().newSignatureMethod(algorithm,
                methodParamSpec);
        return getXMLSignatureFactory().newSignedInfo(canonicalizationMethod, signatureMethod,
                Collections.singletonList(createReference(referenceUri)), signatureId);
    } catch (final Exception e) {
        throw new SignatureException("Error creating signed info", e);
    }
}

From source file:com.github.vatbub.tictactoe.NameList.java

public static String getNextName() {
    RandomUser.RandomUserSpec randomUserSpec = new RandomUser.RandomUserSpec();
    randomUserSpec.setNationalities(Collections.singletonList(Nationality.getFromCurrentDefaultLocale()));
    RandomUser randomUser = Generator.generateRandomUser(randomUserSpec);
    return WordUtils.capitalize(randomUser.getName().getFirstName() + " " + randomUser.getName().getLastName());
}

From source file:Main.java

/**
 * @return <code>coll</code> if it is non-null and non-empty. Otherwise,
 * returns a list with a single null value.
 *///from  w  ww.j  a va  2  s  .co m
private static Collection<String> emptyAsSingletonNull(Collection<String> coll) {
    if (coll == null || coll.isEmpty()) {
        return Collections.singletonList(null);
    } else {
        return coll;
    }
}

From source file:Main.java

public static <T> List<List<T>> innerJoin(List<T> l1, List<T> l2, BiFunction<T, T, T> function) {
    if (l1 == null || l2 == null) {
        throw new NullPointerException("inner join arrays must not be null");
    }/*  w w  w . jav  a2  s .c o m*/

    if (l1.isEmpty() && l2.isEmpty()) {
        return Collections.emptyList();
    } else if (l1.isEmpty()) {
        return Collections.singletonList(l2);
    } else if (l2.isEmpty()) {
        return Collections.singletonList(l1);
    }

    List<List<T>> result = new ArrayList<>(l1.size() * l2.size());
    l1.stream().forEach(t1 -> {
        List<T> l = new ArrayList<>();
        l2.stream().forEach(t2 -> l.add(function.apply(t1, t2)));
        result.add(l);
    });
    return result;
}