jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px"); this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px"); return this; }
public ObservableConcatMap(ObservableSource<T> source, Function<? super T, ? extends ObservableSource<? extends U>> mapper, int bufferSize, ErrorMode delayErrors) { super(source); this.mapper = mapper; this.delayErrors = delayErrors; this.bufferSize = Math.max(8, bufferSize); }
long longSize() { Segment<K, V>[] segments = this.segments; long sum = 0; for (int i = 0; i < segments.length; ++i) { sum += Math.max(0, segments[i].count); // see https://github.com/google/guava/issues/2108 } return sum; }
@Override public int size() { return Math.max(0, super.size() + delta); } };
static int closedTableSize(int expectedEntries, double loadFactor) { // Get the recommended table size. // Round down to the nearest power of 2. expectedEntries = Math.max(expectedEntries, 2); int tableSize = Integer.highestOneBit(expectedEntries); // Check to make sure that we will not exceed the maximum load factor. if (expectedEntries > (int) (loadFactor * tableSize)) { tableSize <<= 1; return (tableSize > 0) ? tableSize : MAX_TABLE_SIZE; } return tableSize; }
MergeSubscriber(Subscriber<? super U> actual, Function<? super T, ? extends Publisher<? extends U>> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { this.downstream = actual; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; this.bufferSize = bufferSize; this.scalarLimit = Math.max(1, maxConcurrency >> 1); subscribers.lazySet(EMPTY); }
private AvlNode<E> addRightChild(E e, int count) { right = new AvlNode<E>(e, count); successor(this, right, succ); height = Math.max(2, height); distinctElements++; totalCount += count; return this; }
private AvlNode<E> addLeftChild(E e, int count) { left = new AvlNode<E>(e, count); successor(pred, left, this); height = Math.max(2, height); distinctElements++; totalCount += count; return this; }
/** * Reserves next ticket and returns the wait time that the caller must wait for. * * @return the required wait time, never negative */ final long reserveAndGetWaitLength(int permits, long nowMicros) { long momentAvailable = reserveEarliestAvailable(permits, nowMicros); return max(momentAvailable - nowMicros, 0); }
@Override protected Set<String> create(String[] elements) { ImmutableSet.Builder<String> builder = ImmutableSet.builderWithExpectedSize(Math.max(0, Sets.newHashSet(elements).size() - 1)); for (String e : elements) { builder.add(e); } return builder.build(); } }
@Override int maxEncodedSize(int bytes) { int unseparatedSize = delegate.maxEncodedSize(bytes); return unseparatedSize + separator.length() * divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR); }
/** Pseudoconstructor for serialization support. */ void init(int expectedSize, float loadFactor) { Preconditions.checkArgument(expectedSize >= 0, "Initial capacity must be non-negative"); Preconditions.checkArgument(loadFactor > 0, "Illegal load factor"); int buckets = Hashing.closedTableSize(expectedSize, loadFactor); this.table = newTable(buckets); this.loadFactor = loadFactor; this.elements = new Object[expectedSize]; this.entries = newEntries(expectedSize); this.threshold = Math.max(1, (int) (buckets * loadFactor)); }
public SpscLinkedArrayQueue(final int bufferSize) { int p2capacity = Pow2.roundToPowerOfTwo(Math.max(8, bufferSize)); int mask = p2capacity - 1; AtomicReferenceArray<Object> buffer = new AtomicReferenceArray<Object>(p2capacity + 1); producerBuffer = buffer; producerMask = mask; adjustLookAheadStep(p2capacity); consumerBuffer = buffer; consumerMask = mask; producerLookAhead = mask - 1; // we know it's all empty to start with soProducerIndex(0L); }
@Override public int count(@Nullable Object element) { int count1 = multiset1.count(element); return (count1 == 0) ? 0 : Math.max(0, count1 - multiset2.count(element)); }
private static long worstCaseQueryOperations(Map<?, ?> map, CallsCounter counter) { long worstCalls = 0; for (Object k : map.keySet()) { counter.zero(); Object unused = map.get(k); worstCalls = Math.max(worstCalls, counter.total()); } return worstCalls; } }
private long measureTotalTimeMillis(RateLimiter rateLimiter, int permits, Random random) { long startTime = stopwatch.instant; while (permits > 0) { int nextPermitsToAcquire = Math.max(1, random.nextInt(permits)); permits -= nextPermitsToAcquire; rateLimiter.acquire(nextPermitsToAcquire); } rateLimiter.acquire(1); // to repay for any pending debt return NANOSECONDS.toMillis(stopwatch.instant - startTime); }
@MapFeature.Require(SUPPORTS_REMOVE) public void testKeysRemove() { int original = multimap().keys().remove(k0(), 1); assertEquals(Math.max(original - 1, 0), multimap().get(k0()).size()); }
@Override public Publisher<Integer> createPublisher(long elements) { return Flowable.range(1, Math.max(0, (int)elements - 1)) .concatWith(Single.just((int)elements)) ; } }
@Override public Publisher<Integer> createPublisher(long elements) { return Flowable.range(1, Math.max(0, (int)elements - 1)) .concatWith(Maybe.just((int)elements)) ; } }
private static long worstCaseQueryOperations(Multiset<?> multiset, CallsCounter counter) { long worstCalls = 0; for (Object k : multiset.elementSet()) { counter.zero(); int unused = multiset.count(k); worstCalls = Math.max(worstCalls, counter.total()); } return worstCalls; } }