All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.common.collect.super.com.google.common.collect.Platform Maven / Gradle / Ivy

Go to download

Guava is a suite of core and expanded libraries that include utility classes, google's collections, io classes, and much much more. This project includes GWT-friendly sources.

There is a newer version: 33.1.0-jre
Show newest version
/*
 * Copyright (C) 2008 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.collect;

import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

/**
 * Minimal GWT emulation of {@code com.google.common.collect.Platform}.
 *
 * 

This .java file should never be consumed by javac. * * @author Hayward Chan */ final class Platform { static Map newHashMapWithExpectedSize(int expectedSize) { return Maps.newHashMapWithExpectedSize(expectedSize); } static Map newLinkedHashMapWithExpectedSize(int expectedSize) { return Maps.newLinkedHashMapWithExpectedSize(expectedSize); } static Set newHashSetWithExpectedSize(int expectedSize) { return Sets.newHashSetWithExpectedSize(expectedSize); } static Set newLinkedHashSetWithExpectedSize(int expectedSize) { return Sets.newLinkedHashSetWithExpectedSize(expectedSize); } /** * Returns the platform preferred map implementation that preserves insertion order when used only * for insertions. */ static Map preservesInsertionOrderOnPutsMap() { return Maps.newLinkedHashMap(); } /** * Returns the platform preferred set implementation that preserves insertion order when used only * for insertions. */ static Set preservesInsertionOrderOnAddsSet() { return Sets.newLinkedHashSet(); } static T[] newArray(T[] reference, int length) { T[] clone = Arrays.copyOf(reference, 0); resizeArray(clone, length); return clone; } private static void resizeArray(Object array, int newSize) { ((NativeArray) array).setLength(newSize); } /** Equivalent to Arrays.copyOfRange(source, from, to, arrayOfType.getClass()). */ static T[] copy(Object[] source, int from, int to, T[] arrayOfType) { T[] result = newArray(arrayOfType, to - from); System.arraycopy(source, from, result, 0, to - from); return result; } // TODO(user): Move this logic to a utility class. @JsType(isNative = true, name = "Array", namespace = JsPackage.GLOBAL) private interface NativeArray { @JsProperty void setLength(int length); } static MapMaker tryWeakKeys(MapMaker mapMaker) { return mapMaker; } static int reduceIterationsIfGwt(int iterations) { return iterations / 10; } static int reduceExponentIfGwt(int exponent) { return exponent / 2; } private Platform() {} }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy