1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect.testing.testers; 18 19 import com.google.common.annotations.GwtCompatible; 20 import com.google.gwt.core.client.GWT; 21 22 /** 23 * The emulation source used in GWT. 24 * 25 * @author Hayward Chan 26 */ 27 @GwtCompatible(emulated = true) 28 final class Platform { 29 30 // Use fewer steps in the ListIteratorTester in ListListIteratorTester because it's slow in prod 31 // mode. 32 static int listListIteratorTesterNumIterations() { 33 // TODO(hhchan): It's 4 in java. Figure out why even 3 is too slow in prod mode. 34 return GWT.isProdMode() ? 2 : 4; 35 } 36 37 // Use fewer steps in the IteratorTester in CollectionIteratorTester because it's slow in prod 38 // mode.. 39 static int collectionIteratorTesterNumIterations() { 40 return GWT.isProdMode() ? 3 : 5; 41 } 42 43 // TODO: Consolidate different copies in one single place. 44 static String format(String template, Object... args) { 45 // start substituting the arguments into the '%s' placeholders 46 StringBuilder builder = new StringBuilder( 47 template.length() + 16 * args.length); 48 int templateStart = 0; 49 int i = 0; 50 while (i < args.length) { 51 int placeholderStart = template.indexOf("%s", templateStart); 52 if (placeholderStart == -1) { 53 break; 54 } 55 builder.append(template.substring(templateStart, placeholderStart)); 56 builder.append(args[i++]); 57 templateStart = placeholderStart + 2; 58 } 59 builder.append(template.substring(templateStart)); 60 61 // if we run out of placeholders, append the extra args in square braces 62 if (i < args.length) { 63 builder.append(" ["); 64 builder.append(args[i++]); 65 while (i < args.length) { 66 builder.append(", "); 67 builder.append(args[i++]); 68 } 69 builder.append("]"); 70 } 71 72 return builder.toString(); 73 } 74 75 private Platform() {} 76 } 77