1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2009 The Guava Authors 3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License. 6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at 7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and 14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License. 15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.base; 18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible; 20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 210888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport java.lang.ref.WeakReference; 220888a09821a98ac0680fad765217302858e70fa4Paul Duffin 23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/** 24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Methods factored out so that they can be emulated differently in GWT. 25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Jesse Wilson 27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson@GwtCompatible(emulated = true) 29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonfinal class Platform { 30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson private Platform() {} 31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** Calls {@link System#nanoTime()}. */ 331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert static long systemNanoTime() { 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return System.nanoTime(); 351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 36bfe2dd089341dcb4c1fb65a5b6b077ad0ebbf6dcDan Egnor 37bfe2dd089341dcb4c1fb65a5b6b077ad0ebbf6dcDan Egnor static CharMatcher precomputeCharMatcher(CharMatcher matcher) { 38bfe2dd089341dcb4c1fb65a5b6b077ad0ebbf6dcDan Egnor return matcher.precomputedInternal(); 39bfe2dd089341dcb4c1fb65a5b6b077ad0ebbf6dcDan Egnor } 400888a09821a98ac0680fad765217302858e70fa4Paul Duffin 410888a09821a98ac0680fad765217302858e70fa4Paul Duffin static <T extends Enum<T>> Optional<T> getEnumIfPresent(Class<T> enumClass, String value) { 420888a09821a98ac0680fad765217302858e70fa4Paul Duffin WeakReference<? extends Enum<?>> ref = Enums.getEnumConstants(enumClass).get(value); 430888a09821a98ac0680fad765217302858e70fa4Paul Duffin return ref == null 440888a09821a98ac0680fad765217302858e70fa4Paul Duffin ? Optional.<T>absent() 450888a09821a98ac0680fad765217302858e70fa4Paul Duffin : Optional.of(enumClass.cast(ref.get())); 460888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson} 48