List of usage examples for java.lang Math toIntExact
public static int toIntExact(long value)
From source file:com.baifendian.swordfish.webserver.dto.ExecutionFlowDto.java
public ExecutionFlowDto(ExecutionFlow executionFlow) { if (executionFlow != null) { this.scheduleTime = executionFlow.getScheduleTime(); this.execId = executionFlow.getId(); this.projectName = executionFlow.getProjectName(); this.workflowName = executionFlow.getWorkflowName(); this.execType = executionFlow.getType(); this.submitTime = executionFlow.getSubmitTime(); this.startTime = executionFlow.getStartTime(); this.endTime = executionFlow.getEndTime(); this.submitUser = executionFlow.getSubmitUser(); this.proxyUser = executionFlow.getProxyUser(); this.queue = executionFlow.getQueue(); this.status = executionFlow.getStatus(); this.owner = executionFlow.getOwner(); this.extras = executionFlow.getExtras(); this.duration = (startTime == null) ? 0 : Math.toIntExact(((endTime == null) ? System.currentTimeMillis() - startTime.getTime() : endTime.getTime() - startTime.getTime()) / 1000); if (StringUtils.isNotEmpty(executionFlow.getWorkflowData())) { this.data = JsonUtil.parseObject(executionFlow.getWorkflowData(), ExecutionFlowData.class); }/*from w w w . j a v a2s . c om*/ } }
From source file:net.longfalcon.web.AdminUserController.java
@RequestMapping("/admin/user-list") public String userListView(@RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, @RequestParam(value = "ob", required = false) String orderBy, Model model) { if (offset == null) { offset = 0;/*from w ww.j a v a 2s . c om*/ } title = "User List"; List<User> userList = new ArrayList<>(); int pagerTotalItems = Math.toIntExact(userDAO.countUsers()); if (ValidatorUtil.isNull(orderBy)) { userList = userDAO.getUsers(offset, PAGE_SIZE); } else { String propertyName = getOrderByProperty(orderBy); boolean descending = getOrderByOrder(orderBy); if (ValidatorUtil.isNotNull(propertyName)) { userList = userDAO.getUsers(offset, PAGE_SIZE, propertyName, descending); } } model.addAttribute("title", title); model.addAttribute("userList", userList); model.addAttribute("pagerTotalItems", pagerTotalItems); model.addAttribute("pagerOffset", offset); model.addAttribute("pagerItemsPerPage", PAGE_SIZE); model.addAttribute("orderBy", orderBy); return "admin/user-list"; }
From source file:net.openhft.chronicle.timeseries.Columns.java
public static <T> void setAll(LongColumn col, Supplier<T> perThread, LongColumnIndexObjectConsumer<T> consumer) { long length = col.length(); int chunks = Math.toIntExact((length - 1) / CHUNK_SIZE + 1); ForkJoinPool fjp = ForkJoinPool.commonPool(); int procs = Runtime.getRuntime().availableProcessors(); List<ForkJoinTask> tasks = new ArrayList<>(procs); int chunksPerTask = (chunks - 1) / procs + 1; for (int i = 0; i < procs; i++) { int si = i * chunksPerTask; int ei = Math.min(chunks, si + chunksPerTask); tasks.add(fjp.submit(() -> {/*from ww w . j a va 2 s .c om*/ T t = perThread.get(); long first = (long) si * CHUNK_SIZE; int max = (int) Math.min((ei - si) * CHUNK_SIZE, length - first); for (int j = 0; j < max; j++) { consumer.apply(col, first + j, t); } })); } for (ForkJoinTask task : tasks) { task.join(); } }
From source file:com.joyent.manta.client.FindForkJoinPoolFactory.java
/** * Calculates the number of connections to leave reserved so that the * {@link ForkJoinPool} can't allocate them. * * @param maximumConnections maximum number of connections in the HTTP * connection pool * @return fractional value rounded to the nearest integer of the number of * connections to leave reserved *//*from w w w . j a v a 2 s . c o m*/ private static int calculateNumberOfReservedConnections(final int maximumConnections) { final double reserved = maximumConnections * PERCENT_OF_RESERVED_CONNECTIONS; return Math.toIntExact(Math.round(reserved)); }
From source file:org.codice.ddf.admin.query.dev.system.dependency.BundleUtils.java
public List<BundleField> getBundles(List<Integer> bundleIds) { List<BundleField> bundlesFields = new ArrayList<>(); List<Bundle> bundles = getAllBundles(); if (CollectionUtils.isNotEmpty(bundleIds)) { bundles = bundles.stream()/*w w w. j av a2 s . c o m*/ .filter(bundle -> bundleIds.contains(((Long) bundle.getBundleId()).intValue())) .collect(Collectors.toList()); } for (Bundle bundle : bundles) { BundleField newBundleField = new BundleField().bundleName(bundle.getSymbolicName()) .id(Math.toIntExact(bundle.getBundleId())).location(bundle.getLocation()) .state(bundle.getState()); populatePackages(bundle, newBundleField); populateServices(bundle, newBundleField); bundlesFields.add(newBundleField); } return bundlesFields; }
From source file:org.graylog2.bindings.providers.JestClientProvider.java
@Inject public JestClientProvider(@Named("elasticsearch_hosts") List<URI> elasticsearchHosts, @Named("elasticsearch_connect_timeout") Duration elasticsearchConnectTimeout, @Named("elasticsearch_socket_timeout") Duration elasticsearchSocketTimeout, @Named("elasticsearch_idle_timeout") Duration elasticsearchIdleTimeout, @Named("elasticsearch_max_total_connections") int elasticsearchMaxTotalConnections, @Named("elasticsearch_max_total_connections_per_route") int elasticsearchMaxTotalConnectionsPerRoute, @Named("elasticsearch_discovery_enabled") boolean discoveryEnabled, @Named("elasticsearch_discovery_filter") @Nullable String discoveryFilter, @Named("elasticsearch_discovery_frequency") Duration discoveryFrequency, Gson gson) { this.factory = new JestClientFactory(); this.credentialsProvider = new BasicCredentialsProvider(); final List<String> hosts = elasticsearchHosts.stream().map(hostUri -> { if (!Strings.isNullOrEmpty(hostUri.getUserInfo())) { final Iterator<String> splittedUserInfo = Splitter.on(":").split(hostUri.getUserInfo()).iterator(); if (splittedUserInfo.hasNext()) { final String username = splittedUserInfo.next(); final String password = splittedUserInfo.hasNext() ? splittedUserInfo.next() : null; credentialsProvider// w w w .j a va2 s . c om .setCredentials( new AuthScope(hostUri.getHost(), hostUri.getPort(), AuthScope.ANY_REALM, hostUri.getScheme()), new UsernamePasswordCredentials(username, password)); } } return hostUri.toString(); }).collect(Collectors.toList()); final HttpClientConfig.Builder httpClientConfigBuilder = new HttpClientConfig.Builder(hosts) .credentialsProvider(credentialsProvider) .connTimeout(Math.toIntExact(elasticsearchConnectTimeout.toMillis())) .readTimeout(Math.toIntExact(elasticsearchSocketTimeout.toMillis())) .maxConnectionIdleTime(elasticsearchIdleTimeout.getSeconds(), TimeUnit.SECONDS) .maxTotalConnection(elasticsearchMaxTotalConnections) .defaultMaxTotalConnectionPerRoute(elasticsearchMaxTotalConnectionsPerRoute).multiThreaded(true) .discoveryEnabled(discoveryEnabled).discoveryFilter(discoveryFilter) .discoveryFrequency(discoveryFrequency.getSeconds(), TimeUnit.SECONDS).gson(gson); factory.setHttpClientConfig(httpClientConfigBuilder.build()); }
From source file:io.pravega.segmentstore.storage.impl.extendeds3.S3ProxyImpl.java
@Synchronized @Override// www .j ava 2s . c o m public void putObject(String bucketName, String key, Range range, Object content) { byte[] totalByes = new byte[Math.toIntExact(range.getLast() + 1)]; try { if (range.getFirst() != 0) { int bytesRead = client.getObject(bucketName, key).getObject().read(totalByes, 0, Math.toIntExact(range.getFirst())); if (bytesRead != range.getFirst()) { throw new IllegalStateException("Unable to read from the object " + key); } } int bytesRead = ((InputStream) content).read(totalByes, Math.toIntExact(range.getFirst()), Math.toIntExact(range.getLast() + 1 - range.getFirst())); if (bytesRead != range.getLast() + 1 - range.getFirst()) { throw new IllegalStateException("Not able to read from input stream."); } client.putObject(new PutObjectRequest(bucketName, key, (Object) new ByteArrayInputStream(totalByes))); aclMap.put(key, aclMap.get(key).withSize(range.getLast() - 1)); } catch (IOException e) { throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key); } }
From source file:org.codice.ddf.admin.query.dev.system.dependency.BundleUtils.java
private void populatePackages(Bundle bundle, BundleField toPopulate) { for (Map.Entry<String, Bundle> pkgDep : bundleService.getWiredBundles(bundle).entrySet()) { toPopulate.addImportedPackage(new PackageField().pkgName(pkgDep.getKey()) .bundleId(Math.toIntExact(pkgDep.getValue().getBundleId()))); }/*from www .j a v a 2 s . co m*/ String exportPkgHeader = bundle.getHeaders().get(EXPORT_PACKAGE_HEADER); if (StringUtils.isEmpty(exportPkgHeader)) { return; } for (Clause clause : Parser.parseHeader(exportPkgHeader)) { toPopulate.addExportedPackage( new PackageField().pkgName(clause.getName()).bundleId(Math.toIntExact(bundle.getBundleId()))); } }
From source file:net.dv8tion.jda.core.requests.restaction.InviteAction.java
/** * Sets the max age for the invite. Set this to {@code 0} if the invite should never expire. Default is {@code 86400} (24 hours). * {@code null} will reset this to the default value. * * @param maxAge//from w w w . j av a 2 s. c om * The max age for this invite or {@code null} to use the default value. * @param timeUnit * The {@link java.util.concurrent.TimeUnit TimeUnit} type of {@code maxAge}. * * @throws IllegalArgumentException * If maxAge is negative or maxAge is positive and timeUnit is null. * * @return The current InviteAction for chaining. */ @CheckReturnValue public final InviteAction setMaxAge(final Long maxAge, final TimeUnit timeUnit) { if (maxAge == null) return this.setMaxAge(null); Checks.notNegative(maxAge, "maxAge"); Checks.notNull(timeUnit, "timeUnit"); return this.setMaxAge(Math.toIntExact(timeUnit.toSeconds(maxAge))); }
From source file:com.netflix.spinnaker.orca.webhook.config.WebhookConfiguration.java
@Bean public ClientHttpRequestFactory webhookRequestFactory( OkHttpClientConfigurationProperties okHttpClientConfigurationProperties) { X509TrustManager trustManager = webhookX509TrustManager(); SSLSocketFactory sslSocketFactory = getSSLSocketFactory(trustManager); OkHttpClient client = new OkHttpClient.Builder().sslSocketFactory(sslSocketFactory, trustManager).build(); OkHttp3ClientHttpRequestFactory requestFactory = new OkHttp3ClientHttpRequestFactory(client); requestFactory.setReadTimeout(Math.toIntExact(okHttpClientConfigurationProperties.getReadTimeoutMs())); requestFactory/*from ww w . ja v a 2 s . c o m*/ .setConnectTimeout(Math.toIntExact(okHttpClientConfigurationProperties.getConnectTimeoutMs())); return requestFactory; }