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:net.ageto.gyrex.persistence.liquibase.LiquibaseSchemaSupport.java

@Override
public RepositoryContentType[] getSupportedContentTypes() {
    final Set<RepositoryContentType> set = changeLogsByContentTypeMap.keySet();
    return set.toArray(new RepositoryContentType[set.size()]);
}

From source file:com.miapc.ipudong.Application.java

@Bean
public RestTemplate getRestTemplate() {
    SSLContext sslcontext = null;
    Set<KeyManager> keymanagers = new LinkedHashSet<>();
    Set<TrustManager> trustmanagers = new LinkedHashSet<>();
    try {//  ww  w. j a  v a 2  s  . c  om
        trustmanagers.add(new HttpsTrustManager());
        KeyManager[] km = keymanagers.toArray(new KeyManager[keymanagers.size()]);
        TrustManager[] tm = trustmanagers.toArray(new TrustManager[trustmanagers.size()]);
        sslcontext = SSLContexts.custom().build();
        sslcontext.init(km, tm, new SecureRandom());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
            SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    HttpClientBuilder httpClientBuilder = HttpClients.custom();
    httpClientBuilder.setSSLSocketFactory(factory);
    // ?3?
    httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
    // ????Keep-Alive
    httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    List<Header> headers = new ArrayList<>();
    headers.add(new BasicHeader("User-Agent",
            "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
    headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
    headers.add(new BasicHeader("Accept-Language", "zh-CN"));
    headers.add(new BasicHeader("Connection", "Keep-Alive"));
    headers.add(new BasicHeader("Authorization", "reslibu"));
    httpClientBuilder.setDefaultHeaders(headers);
    CloseableHttpClient httpClient = httpClientBuilder.build();
    if (httpClient != null) {
        // httpClient??RequestConfig
        HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(
                httpClient);
        // 
        clientHttpRequestFactory.setConnectTimeout(60 * 1000);
        // ???SocketTimeout
        clientHttpRequestFactory.setReadTimeout(5 * 60 * 1000);
        // ????
        clientHttpRequestFactory.setConnectionRequestTimeout(5000);
        // ?truePOSTPUT????false?
        // clientHttpRequestFactory.setBufferRequestBody(false);
        // ?
        List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
        messageConverters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
        messageConverters.add(new MappingJackson2HttpMessageConverter());
        messageConverters.add(new FormHttpMessageConverter());
        messageConverters.add(new MappingJackson2XmlHttpMessageConverter());

        RestTemplate restTemplate = new RestTemplate(messageConverters);
        restTemplate.setRequestFactory(clientHttpRequestFactory);
        restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
        return restTemplate;
    } else {
        return null;
    }

}

From source file:jp.co.nemuzuka.dao.ProjectDao.java

/**
 * List?./*ww w  . j ava 2 s  .  com*/
 * @param keys key?
 * @return 
 */
public List<ProjectModel> getList(Key... keys) {
    ProjectModelMeta e = (ProjectModelMeta) getModelMeta();
    Set<FilterCriterion> filterSet = new HashSet<FilterCriterion>();
    if (keys != null && keys.length != 0) {
        filterSet.add(e.key.in(keys));
    } else {
        return new ArrayList<ProjectModel>();
    }
    return Datastore.query(e).filter(filterSet.toArray(new FilterCriterion[0])).sortInMemory(e.key.asc)
            .asList();
}

From source file:com.insightml.data.AnonymousFeaturesConfig.java

private IFeatureProvider<S> fromExamples(final Iterable<S> examples,
        final Function<S, Features> simpleFeaturesProvider, final double defaultValue) {
    final Set<String> names = new LinkedHashSet<>();
    for (final S example : examples) {
        for (final DoublePair<String> feat : simpleFeaturesProvider.apply(example)) {
            names.add(feat.getKey());/*from   ww w.ja v a  2 s  .  co m*/
        }
    }
    return provider(names.toArray(new String[names.size()]), simpleFeaturesProvider, defaultValue);
}

From source file:org.trpr.platform.servicefw.impl.spring.SpringServicesContainer.java

/**
 * Interface method implementation//from  w w w .  j  a v  a 2 s.c om
 * @see ServiceContainer#getAllLocalServices()
 */
public ServiceKey[] getAllLocalServices() {
    Set<ServiceKey> serviceKeys = serviceInfos.keySet();
    return (ServiceKey[]) (serviceKeys.toArray(new ServiceKey[serviceKeys.size()]));
}

From source file:com.opengamma.financial.analytics.model.equity.option.EquityOptionBlackVegaMatrixFunction.java

@Override
protected Set<ComputedValue> computeValues(final InstrumentDerivative derivative,
        final StaticReplicationDataBundle market, final FunctionInputs inputs,
        final Set<ValueRequirement> desiredValues, final ComputationTargetSpecification targetSpec,
        final ValueProperties resultProperties) {
    final ValueSpecification resultSpec = new ValueSpecification(getValueRequirementNames()[0], targetSpec,
            resultProperties);//from  w  w  w .  j a va  2s  . com
    final NodalDoublesSurface vegaSurface = CALCULATOR.calcBlackVegaForEntireSurface(derivative, market, SHIFT);
    final Double[] xValues;
    final Double[] yValues;
    if (market.getVolatilitySurface() instanceof BlackVolatilitySurfaceMoneynessFcnBackedByGrid) {
        final BlackVolatilitySurfaceMoneynessFcnBackedByGrid volDataBundle = (BlackVolatilitySurfaceMoneynessFcnBackedByGrid) market
                .getVolatilitySurface();
        xValues = ArrayUtils.toObject(volDataBundle.getGridData().getExpiries());
        final double[][] strikes2d = volDataBundle.getGridData().getStrikes();
        final Set<Double> strikeSet = new HashSet<>();
        for (final double[] element : strikes2d) {
            strikeSet.addAll(Arrays.asList(ArrayUtils.toObject(element)));
        }
        yValues = strikeSet.toArray(new Double[] {});
    } else {
        xValues = vegaSurface.getXData();
        yValues = vegaSurface.getYData();
    }

    final Set<Double> xSet = new HashSet<>(Arrays.asList(xValues));
    final Set<Double> ySet = new HashSet<>(Arrays.asList(yValues));
    final Double[] uniqueX = xSet.toArray(new Double[0]);
    final String[] expLabels = new String[uniqueX.length];
    // Format the expiries for display
    for (int i = 0; i < uniqueX.length; i++) {
        uniqueX[i] = roundTwoDecimals(uniqueX[i]);
        expLabels[i] = VegaMatrixUtils.getFXVolatilityFormattedExpiry(uniqueX[i]);
    }
    final Double[] uniqueY = ySet.toArray(new Double[0]);
    final double[][] values = new double[ySet.size()][xSet.size()];
    int i = 0;
    for (final Double x : xSet) {
        int j = 0;
        for (final Double y : ySet) {
            double vega;
            try {
                vega = vegaSurface.getZValue(x, y);
            } catch (final IllegalArgumentException e) {
                vega = 0;
            }
            values[j++][i] = vega;
        }
        i++;
    }
    final DoubleLabelledMatrix2D matrix = new DoubleLabelledMatrix2D(uniqueX, expLabels, uniqueY, uniqueY,
            values);
    return Collections.singleton(new ComputedValue(resultSpec, matrix));
}

From source file:eu.supersede.fe.multitenant.MultiTenancyJpaConfiguration.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
    if (dataSource == null) {
        return null;
    }//from   w w  w  .j  ava  2  s  .c o  m

    Map<String, Object> hibernateProps = new LinkedHashMap<>();
    hibernateProps.putAll(jpaProperties.getHibernateProperties(dataSource));

    hibernateProps.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
    hibernateProps.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
    hibernateProps.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
    hibernateProps.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect");

    String HBM2DDL_AUTO = env.getProperty(HBM2DDL_AUTO_PROPERTY);

    if (HBM2DDL_AUTO != null) {
        hibernateProps.put(Environment.HBM2DDL_AUTO, HBM2DDL_AUTO);
    }

    Set<String> packages = new HashSet<>();
    String[] tmp = MODELS_PACKAGES.split(",");

    for (String t : tmp) {
        packages.add(t.trim());
    }

    packages.add("eu.supersede.fe.notification.model");

    return builder.dataSource(dataSource).packages(packages.toArray(new String[packages.size()]))
            .properties(hibernateProps).jta(false).build();
}

From source file:org.tester.app.sample.AppUiTopovMessageHandler.java

private void initLinkSet() {
    Set<Link> links = new HashSet<>();
    for (Link link : linkService.getActiveLinks()) {
        links.add(link);//from  ww w.j a va  2 s  .com
    }
    linkSet = links.toArray(new Link[links.size()]);
    log.debug("initialized link set to {}", linkSet.length);
}

From source file:net.sf.morph.transform.converters.TextToEnumConverter.java

/**
 * {@inheritDoc}//from   w w  w. j  a v a  2 s.  c  o  m
 */
protected Class[] getSourceClassesImpl() throws Exception {
    if (ENUM_TYPE == null) {
        return ArrayUtils.EMPTY_CLASS_ARRAY;
    }
    Set result = ContainerUtils.createOrderedSet();
    result.add(ENUM_TYPE);
    result.addAll(Arrays.asList(getTextConverter().getSourceClasses()));
    result.add(null);
    return (Class[]) result.toArray(new Class[result.size()]);
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected JSONObject doInBackground(Void... params) {
    Set<String> set = new HashSet<>();
    JSONObject response = null;/* ww  w  .j  av a 2  s.  c om*/
    for (int x : mMap.keySet()) {
        set.add(mMap.get(x));
    }
    try {
        response = App.getPairInfo(set.toArray(new String[set.size()]));
        response = response == null ? new JSONObject() : response;
        Context context = mContext.get();
        if (context == null) {
            return null;
        }
        DBWorker dbWorker = DBWorker.getInstance(context);
        String[] columns = { "pair", "last" };
        Cursor cursor = dbWorker.pullWidgetData(columns);
        Map<String, Double> values = new HashMap<>();
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                values.put(cursor.getString(cursor.getColumnIndex(columns[0])),
                        cursor.getDouble(cursor.getColumnIndex(columns[1])));
                cursor.moveToNext();
            }
        }
        cursor.close();
        for (@SuppressWarnings("unchecked")
        Iterator<String> x = response.keys(); x.hasNext();) {
            String pair = x.next();
            String pairInDB = pair.replace("_", "/").toUpperCase(Locale.US);
            ContentValues cv = new ContentValues(4);
            double last = response.getJSONObject(pair).getDouble("last");
            double sell = response.getJSONObject(pair).getDouble("sell");
            double buy = response.getJSONObject(pair).getDouble("buy");
            cv.put("last", last);
            cv.put("buy", buy);
            cv.put("sell", sell);
            if (values.containsKey(pairInDB)) {
                if (last >= values.get(pairInDB)) {
                    response.getJSONObject(pair).put("color", "green");
                } else {
                    response.getJSONObject(pair).put("color", "red");
                }
            } else {
                response.getJSONObject(pair).put("color", "green");
            }

            int result = dbWorker.updateWidgetData(cv, pair.replace("_", "/").toUpperCase(Locale.US));
            if (result == 0) {
                cv.put("pair", pair.replace("_", "/").toUpperCase(Locale.US));
                dbWorker.insertToWidgetData(cv);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return response;
}