Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:com.htmlhifive.tools.jslint.util.ConfigBeanUtil.java

/**
 * ??????????.<br>//from ww w.j ava 2  s . c om
 * TODO getAllOptionFromDefault???...
 * 
 * @return 
 */
public static CheckOption[] getAllJsHintOptionFromDefault() {

    JSHintDefaultOptions[] jsHintOptions = JSHintDefaultOptions.values();
    JSLintDefaultOptions[] jsLintOptions = JSLintDefaultOptions.values();
    Set<CheckOption> optionSet = new HashSet<CheckOption>();
    for (JSHintDefaultOptions option : jsHintOptions) {
        optionSet.add(option.convertToOption());
    }
    for (JSLintDefaultOptions option : jsLintOptions) {
        optionSet.add(option.convertToOption());
    }
    return (CheckOption[]) optionSet.toArray(new CheckOption[optionSet.size()]);
}

From source file:jp.co.nemuzuka.utils.ConvertUtils.java

/**
 * String???./* w  w w  .j a v a2 s.c  o m*/
 * ??SP?
 * 
 * ?
 * ???String?????
 * @param array ?String?
 * @return ?String?
 */
private static String[] createTrimStrArray(String[] array) {
    Set<String> strSet = new LinkedHashSet<String>();

    for (String value : array) {
        String target = StringUtils.trimToEmpty(value);
        if (StringUtils.isEmpty(target)) {
            continue;
        }
        strSet.add(target);
    }
    return strSet.toArray(new String[0]);
}

From source file:io.cortical.retina.model.TestDataHarness.java

/**
 * Create dummy  {@link Fingerprint}./*from www.  j  a v a2s . c om*/
 * 
 * @return dummy fingerprint.
 */
public static Fingerprint createFingerprint() {
    Random random = new Random(SEED);
    Set<Integer> positionSet = new LinkedHashSet<>();
    while (positionSet.size() <= FINGERPRINT_LENGTH) {
        positionSet.add(random.nextInt(MAX_POSITION));
    }

    Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH];
    positionsInteger = positionSet.toArray(positionsInteger);
    sort(positionsInteger);
    return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger));
}

From source file:iddb.core.util.Functions.java

public static String createNameIndex(String name) {
    //      Collection<String> n = NGrams.ngrams(name, Parameters.INDEX_MIN_LENGTH);
    //      n.addAll(NGrams.ngrams(Functions.normalize(name), Parameters.INDEX_MIN_LENGTH));
    //      n.add(Functions.normalize(name));
    //      return Functions.join(new HashSet<String>(n), " ");
    Set<String> n = new HashSet<String>();
    n.add(name.toLowerCase());/*from  ww  w  .  jav  a 2 s .  co m*/
    n.add(normalizeCleanUp(name));
    n.add(normalizeReplace(name));
    n.add(normalize(name));
    return join(n.toArray(new String[0]), " ");
}

From source file:py.una.pol.karaku.test.util.TestUtils.java

/**
 * Retorna la lista de entidades relacionadas a una base.
 * /*www  .j  a  v a  2s .co m*/
 * @param base
 *            entidad base
 * @return array con todas las entidades que se pueden acceder desde base.
 */
public static Class<?>[] getReferencedClasses(Class<?>... base) {

    LOG.info("Scanning for classes with relations with '{}'", base);
    Set<Class<?>> result = new HashSet<Class<?>>(10);
    for (Class<?> clasz : base) {
        result.add(clasz);
        getReferencedClasses(clasz, result);
    }
    LOG.info("Found '{}' classes with relations with '{}'", result.size(), base);
    return result.toArray(new Class<?>[result.size()]);
}

From source file:com.allinfinance.system.util.BeanUtils.java

/**
 * null??//from   w w w.ja v a  2  s.  com
* @param source
* @return
*/
public static String[] getNullPropertyNames(Object source) {
    final BeanWrapper src = new BeanWrapperImpl(source);
    java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();

    Set<String> emptyNames = new HashSet<String>();
    for (java.beans.PropertyDescriptor pd : pds) {
        Object srcValue = src.getPropertyValue(pd.getName());
        if (srcValue == null)
            emptyNames.add(pd.getName());
    }
    String[] result = new String[emptyNames.size()];
    return emptyNames.toArray(result);
}

From source file:io.cortical.retina.model.TestDataHarness.java

/**
 * Create dummy  {@link Fingerprint}.//ww w  . ja  v a2 s .  c om
 * @param sparsity      percentage of on bits
 * @return dummy fingerprint.
 */
public static Fingerprint createFingerprint(double sparsity) {
    Random random = new Random(SEED);
    Set<Integer> positionSet = new LinkedHashSet<>();
    while (positionSet.size() <= ((double) (MAX_POSITION)) * sparsity) {
        positionSet.add(random.nextInt(MAX_POSITION));
    }

    Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH];
    positionsInteger = positionSet.toArray(positionsInteger);
    sort(positionsInteger);
    return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger));
}

From source file:biz.netcentric.cq.tools.actool.helper.AccessControlUtils.java

/** Retrieves the {@link Privilege}s from the specified privilege names.
 *
 * @param accessControlManager The access control manager.
 * @param privilegeNames The privilege names.
 * @return An array of privileges.//  w ww .  j  a  v a 2 s. co m
 * @throws RepositoryException If an error occurs or if {@code privilegeNames} contains an unknown/invalid privilege name. */
public static Privilege[] privilegesFromNames(AccessControlManager accessControlManager,
        String... privilegeNames) throws RepositoryException {
    final Set<Privilege> privileges = new HashSet<Privilege>(privilegeNames.length);
    for (final String privName : privilegeNames) {
        privileges.add(accessControlManager.privilegeFromName(privName));
    }
    return privileges.toArray(new Privilege[privileges.size()]);
}

From source file:ddf.security.common.audit.SecurityLogger.java

private static String getUser(Subject subject) {
    try {//from  ww w  .j  ava 2s . c  o  m
        if (subject == null) {
            subject = ThreadContext.getSubject();
        }
        if (subject == null) {
            javax.security.auth.Subject javaSubject = javax.security.auth.Subject
                    .getSubject(AccessController.getContext());
            if (javaSubject != null) {
                Set<UserPrincipal> userPrincipal = javaSubject.getPrincipals(UserPrincipal.class);
                if (userPrincipal != null && !userPrincipal.isEmpty()) {
                    return userPrincipal.toArray(new UserPrincipal[1])[0].getName();
                }
            }
        } else {
            return SubjectUtils.getName(subject, NO_USER);
        }
    } catch (Exception e) {
        // ignore and return NO_USER
    }
    return NO_USER;
}

From source file:org.eclipse.virgo.ide.facet.core.FacetUtils.java

public static IProject[] getParProjects(IProject project) {
    Set<IProject> bundles = new HashSet<IProject>();
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject candidate : projects) {
        if (FacetUtils.isParProject(candidate)) {
            if (Arrays.asList(getBundleProjects(candidate)).contains(project)) {
                bundles.add(candidate);/*from w w w  .  j a  va 2s.c om*/
            }
        }
    }
    return (IProject[]) bundles.toArray(new IProject[bundles.size()]);
}