private static int rescaleFactor(long fromScale, long toScale) { return max(0, (int) toScale - (int) fromScale); }
public void increment( int typeId ) { if ( typeId >= counts.length ) { counts = Arrays.copyOf( counts, max( counts.length * 2, typeId + 1 ) ); } counts[typeId]++; if ( typeId > highestTypeId ) { highestTypeId = typeId; } }
@Override public int processors( int delta ) { targetNumberOfProcessors = max( 1, min( targetNumberOfProcessors + delta, maxProcessors ) ); return targetNumberOfProcessors; }
private static int highestLabelId( Labels[] data ) { int highest = 0; for ( Labels labels : data ) { highest = Integer.max( highest, labels.labelId ); } return highest; }
/** * Ensures that an integer is within a given range. * * @param i The number to check. * @param min The minimum value to return. * @param max The maximum value to return. * @return {@code i} if the number is between {@code min} and {@code max}, * {@code min} if {@code i} is less than the minimum, * {@code max} if {@code i} is greater than the maximum. */ private static int intRange(int i, int min, int max) { return Integer.min(Integer.max(min, i), max); }
private synchronized void closeClient() { if ( --opened == 0 ) { int highestTypeId = 0; for ( Client client : clients ) { highestTypeId = max( highestTypeId, client.highestTypeId ); } long[] counts = new long[highestTypeId + 1]; for ( Client client : clients ) { client.addTo( counts ); } typeCounts = new RelationshipTypeCount[counts.length]; for ( int i = 0; i < counts.length; i++ ) { typeCounts[i] = new RelationshipTypeCount( i, counts[i] ); } Arrays.sort( typeCounts ); } }
private Number getLowerBound(double error, List<? extends Number> rows, double percentile) { int medianIndex = (int) (rows.size() * percentile); int marginOfError = (int) (rows.size() * error / 2); return rows.get(max(medianIndex - marginOfError, 0)); }
requestedNumber = max( 1, requestedNumber ); if ( requestedNumber < processors.length )
@Override public int processors( int delta ) { if ( delta > 0 ) { numberOfProcessors = min( numberOfProcessors + delta, maxProcessors ); } else if ( delta < 0 ) { numberOfProcessors = max( 1, numberOfProcessors + delta ); } return numberOfProcessors; }
int rlen = min(max(segLen, r.length), r.length); int oversize = r.length - segLen; System.arraycopy(
result.put("slotsUsed", supervisorSummary.get_num_used_workers()); result.put("slotsFree", Integer.max(supervisorSummary.get_num_workers() - supervisorSummary.get_num_used_workers(), 0)); Map<String, Double> totalResources = supervisorSummary.get_total_resources();
@Test public void shouldAddLabels() throws Exception { // GIVEN ControlledInserter inserter = new ControlledInserter(); long[] expected = new long[NODE_COUNT]; try ( NativeLabelScanWriter writer = new NativeLabelScanWriter( max( 5, NODE_COUNT / 100 ), NativeLabelScanWriter.EMPTY ) ) { writer.initialize( inserter ); // WHEN for ( int i = 0; i < NODE_COUNT * 3; i++ ) { NodeLabelUpdate update = randomUpdate( expected ); writer.write( update ); } } // THEN for ( int i = 0; i < LABEL_COUNT; i++ ) { long[] expectedNodeIds = nodesWithLabel( expected, i ); long[] actualNodeIds = asArray( new LabelScanValueIterator( inserter.nodesFor( i ), new ArrayList<>(), NO_ID ) ); assertArrayEquals( "For label " + i, expectedNodeIds, actualNodeIds ); } }
private void addComment(ST tmplt, ElementDefinition ed) { if(withComments && ed.hasShort() && !ed.getId().startsWith("Extension.")) { int nspaces; char[] sep; nspaces = Integer.max(COMMENT_COL - tmplt.add("comment", "#").render().indexOf('#'), MIN_COMMENT_SEP); tmplt.remove("comment"); sep = new char[nspaces]; Arrays.fill(sep, ' '); ArrayList<String> comment_lines = split_text(ed.getShort().replace("\n", " "), MAX_CHARS); StringBuilder comment = new StringBuilder("# "); char[] indent = new char[COMMENT_COL]; Arrays.fill(indent, ' '); for(int i = 0; i < comment_lines.size();) { comment.append(comment_lines.get(i++)); if(i < comment_lines.size()) comment.append("\n" + new String(indent) + "# "); } tmplt.add("comment", new String(sep) + comment.toString()); } else { tmplt.add("comment", " "); } }
public void increment( int typeId ) { if ( typeId >= counts.length ) { counts = Arrays.copyOf( counts, max( counts.length * 2, typeId + 1 ) ); } counts[typeId]++; if ( typeId > highestTypeId ) { highestTypeId = typeId; } }
private void removeDuplicatesWithOlder(TimelinePage<T> page, int indExistingPage) { for (int ind = Integer.max(indExistingPage, 0); ind < pages.size(); ind++) { pages.get(ind).items.removeAll(page.items); } }
private int computePadding(String gunk, Map<String, Property> properties) { int maxLen = 0; for (Map.Entry<String, Property> entry: properties.entrySet()) { maxLen = max(maxLen, entry.getKey().length() + 1 + gunk.length()); } return maxLen; }
@Override public int processors( int delta ) { targetNumberOfProcessors = max( 1, min( targetNumberOfProcessors + delta, maxProcessors ) ); return targetNumberOfProcessors; }
PaginationHelper(Collection<T> items, int offset, int limit) { Objects.requireNonNull(items, "items can't be empty/null"); this.items = new ArrayList<>(items); this.maxSize = items.size(); // If limit is negative then limit is effectively the maxSize, else the smaller one out of limit and maxSize int adjustedLimit = limit < 0 ? maxSize : Integer.min(maxSize, limit); // Page starting can only be between zero and adjustedLimit pageStart = Integer.max(0, offset); // Page end can't exceed the maxSize pageEnd = Integer.min(adjustedLimit + pageStart, maxSize); }
private Number getLowerBound(double error, List<? extends Number> rows, double percentile) { int medianIndex = (int) (rows.size() * percentile); int marginOfError = (int) (rows.size() * error / 2); return rows.get(max(medianIndex - marginOfError, 0)); }
@Override public int getApplicationStartedOrder() { int elasticOrder = ((DefaultComponent) Framework.getRuntime().getComponent( "org.nuxeo.elasticsearch.ElasticSearchComponent")).getApplicationStartedOrder(); int uidgenOrder = ((DefaultComponent) Framework.getRuntime().getComponent( "org.nuxeo.ecm.core.uidgen.UIDGeneratorService")).getApplicationStartedOrder(); return Integer.max(elasticOrder, uidgenOrder) + 1; }