Platform.java revision 30e2c24b056542f3b1b438aeb798305d1226d0c8
18b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira/* 28b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Copyright (C) 2009 Google Inc. 38b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * 48b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Licensed under the Apache License, Version 2.0 (the "License"); 58b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * you may not use this file except in compliance with the License. 68b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * You may obtain a copy of the License at 78b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * 88b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * http://www.apache.org/licenses/LICENSE-2.0 98b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * 108b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Unless required by applicable law or agreed to in writing, software 118b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * distributed under the License is distributed on an "AS IS" BASIS, 128b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * See the License for the specific language governing permissions and 148b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * limitations under the License. 158b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */ 168b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 1730e2c24b056542f3b1b438aeb798305d1226d0c8Andy Huangpackage com.android.mail.lib.base; 188b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 198b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 208b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira/** 218b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Methods factored out so that they can be emulated differently in GWT. 228b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * 238b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @author Jesse Wilson 248b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */ 258b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereirafinal class Platform { 268b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira private Platform() {} 278b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 288b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira /** 298b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Calls {@link Class#isInstance(Object)}. 308b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * 318b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * <p>This method is not supported in GWT yet. 328b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */ 338b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira static boolean isInstance(Class<?> clazz, Object obj) { 348b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira return clazz.isInstance(obj); 358b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira } 368b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 378b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira /** Returns a thread-local 1024-char array. */ 388b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira static char[] charBufferFromThreadLocal() { 398b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira return DEST_TL.get(); 408b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira } 418b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 428b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira /** 438b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * A thread-local destination buffer to keep us from creating new buffers. 448b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * The starting size is 1024 characters. If we grow past this we don't 458b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * put it back in the threadlocal, we just keep going and grow as needed. 468b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */ 478b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira private static final ThreadLocal<char[]> DEST_TL = new ThreadLocal<char[]>() { 488b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira @Override 498b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira protected char[] initialValue() { 508b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira return new char[1024]; 518b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira } 528b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira }; 538b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira 548b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira static CharMatcher precomputeCharMatcher(CharMatcher matcher) { 558b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira return matcher.precomputedInternal(); 568b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira } 578b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira} 58