List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize)
From source file:com.android.tools.lint.checks.ServiceCastDetector.java
@NonNull private static Map<String, String> getServiceMap() { if (sServiceMap == null) { final int EXPECTED_SIZE = 49; sServiceMap = Maps.newHashMapWithExpectedSize(EXPECTED_SIZE); sServiceMap.put("ACCESSIBILITY_SERVICE", "android.view.accessibility.AccessibilityManager"); sServiceMap.put("ACCOUNT_SERVICE", "android.accounts.AccountManager"); sServiceMap.put("ACTIVITY_SERVICE", "android.app.ActivityManager"); sServiceMap.put("ALARM_SERVICE", "android.app.AlarmManager"); sServiceMap.put("APPWIDGET_SERVICE", "android.appwidget.AppWidgetManager"); sServiceMap.put("APP_OPS_SERVICE", "android.app.AppOpsManager"); sServiceMap.put("AUDIO_SERVICE", "android.media.AudioManager"); sServiceMap.put("BATTERY_SERVICE", "android.os.BatteryManager"); sServiceMap.put("BLUETOOTH_SERVICE", "android.bluetooth.BluetoothManager"); sServiceMap.put("CAMERA_SERVICE", "android.hardware.camera2.CameraManager"); sServiceMap.put("CAPTIONING_SERVICE", "android.view.accessibility.CaptioningManager"); sServiceMap.put("CLIPBOARD_SERVICE", "android.text.ClipboardManager"); sServiceMap.put("CONNECTIVITY_SERVICE", "android.net.ConnectivityManager"); sServiceMap.put("CONSUMER_IR_SERVICE", "android.hardware.ConsumerIrManager"); sServiceMap.put("DEVICE_POLICY_SERVICE", "android.app.admin.DevicePolicyManager"); sServiceMap.put("DISPLAY_SERVICE", "android.hardware.display.DisplayManager"); sServiceMap.put("DOWNLOAD_SERVICE", "android.app.DownloadManager"); sServiceMap.put("DROPBOX_SERVICE", "android.os.DropBoxManager"); sServiceMap.put("INPUT_METHOD_SERVICE", "android.view.inputmethod.InputMethodManager"); sServiceMap.put("INPUT_SERVICE", "android.hardware.input.InputManager"); sServiceMap.put("JOB_SCHEDULER_SERVICE", "android.app.job.JobScheduler"); sServiceMap.put("KEYGUARD_SERVICE", "android.app.KeyguardManager"); sServiceMap.put("LAUNCHER_APPS_SERVICE", "android.content.pm.LauncherApps"); sServiceMap.put("LAYOUT_INFLATER_SERVICE", "android.view.LayoutInflater"); sServiceMap.put("LOCATION_SERVICE", "android.location.LocationManager"); sServiceMap.put("MEDIA_PROJECTION_SERVICE", "android.media.projection.MediaProjectionManager"); sServiceMap.put("MEDIA_ROUTER_SERVICE", "android.media.MediaRouter"); sServiceMap.put("MEDIA_SESSION_SERVICE", "android.media.session.MediaSessionManager"); sServiceMap.put("NFC_SERVICE", "android.nfc.NfcManager"); sServiceMap.put("NOTIFICATION_SERVICE", "android.app.NotificationManager"); sServiceMap.put("NSD_SERVICE", "android.net.nsd.NsdManager"); sServiceMap.put("POWER_SERVICE", "android.os.PowerManager"); sServiceMap.put("PRINT_SERVICE", "android.print.PrintManager"); sServiceMap.put("RESTRICTIONS_SERVICE", "android.content.RestrictionsManager"); sServiceMap.put("SEARCH_SERVICE", "android.app.SearchManager"); sServiceMap.put("SENSOR_SERVICE", "android.hardware.SensorManager"); sServiceMap.put("STORAGE_SERVICE", "android.os.storage.StorageManager"); sServiceMap.put("TELECOM_SERVICE", "android.telecom.TelecomManager"); sServiceMap.put("TELEPHONY_SERVICE", "android.telephony.TelephonyManager"); sServiceMap.put("TEXT_SERVICES_MANAGER_SERVICE", "android.view.textservice.TextServicesManager"); sServiceMap.put("TV_INPUT_SERVICE", "android.media.tv.TvInputManager"); sServiceMap.put("UI_MODE_SERVICE", "android.app.UiModeManager"); sServiceMap.put("USB_SERVICE", "android.hardware.usb.UsbManager"); sServiceMap.put("USER_SERVICE", "android.os.UserManager"); sServiceMap.put("VIBRATOR_SERVICE", "android.os.Vibrator"); sServiceMap.put("WALLPAPER_SERVICE", "com.android.server.WallpaperService"); sServiceMap.put("WIFI_P2P_SERVICE", "android.net.wifi.p2p.WifiP2pManager"); sServiceMap.put("WIFI_SERVICE", "android.net.wifi.WifiManager"); sServiceMap.put("WINDOW_SERVICE", "android.view.WindowManager"); assert sServiceMap.size() == EXPECTED_SIZE : sServiceMap.size(); }/*from www .ja va 2 s . c o m*/ return sServiceMap; }
From source file:org.matsim.contrib.dvrp.trafficmonitoring.DvrpOfflineTravelTimeEstimator.java
public DvrpOfflineTravelTimeEstimator(TravelTime initialTT, TravelTime observedTT, Network network, TravelTimeCalculatorConfigGroup ttCalcConfig, double travelTimeEstimationAlpha) { this.observedTT = observedTT; this.network = network; alpha = travelTimeEstimationAlpha;/*from ww w .j a va 2 s .c o m*/ if (alpha > 1 || alpha <= 0) { throw new IllegalArgumentException("travelTimeEstimationAlpha must be in (0,1]"); } interval = ttCalcConfig.getTraveltimeBinSize(); intervalCount = TimeBinUtils.getTimeBinCount(ttCalcConfig.getMaxTime(), interval); linkTTs = Maps.newHashMapWithExpectedSize(network.getLinks().size()); init(initialTT); }
From source file:chibill.DeobLoader.loader.Remappers.java
public void setupLoadOnly(String deobfFileName, boolean loadAll) { try {/*from w ww. ja v a 2s .c o m*/ File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); CharSource srgSource = zis.asCharSource(Charsets.UTF_8); List<String> srgList = srgSource.readLines(); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); } else if ("MD".equals(typ) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); } catch (IOException ioe) { } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
From source file:org.elasticsearch.common.settings.ImmutableSettings.java
@Override public Map<String, Object> getAsStructuredMap() { Map<String, Object> map = Maps.newHashMapWithExpectedSize(2); for (Map.Entry<String, String> entry : settings.entrySet()) { processSetting(map, "", entry.getKey(), entry.getValue()); }/*from w ww . j ava2 s . c om*/ for (Map.Entry<String, Object> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> valMap = (Map<String, Object>) entry.getValue(); entry.setValue(convertMapsToArrays(valMap)); } } return map; }
From source file:com.android.build.gradle.internal.LintGradleClient.java
/** * Given a list of results from separate variants, merge them into a single * list of warnings, and mark their/* w ww . j av a2 s . c o m*/ * @param warningMap a map from variant to corresponding warnings * @param project the project model * @return a merged list of issues */ @NonNull public static List<Warning> merge(@NonNull Map<Variant, List<Warning>> warningMap, @NonNull AndroidProject project) { // Easy merge? if (warningMap.size() == 1) { return warningMap.values().iterator().next(); } int maxCount = 0; for (List<Warning> warnings : warningMap.values()) { int size = warnings.size(); maxCount = Math.max(size, maxCount); } if (maxCount == 0) { return Collections.emptyList(); } int totalVariantCount = project.getVariants().size(); List<Warning> merged = Lists.newArrayListWithExpectedSize(2 * maxCount); // Map fro issue to message to line number to file name to canonical warning Map<Issue, Map<String, Map<Integer, Map<String, Warning>>>> map = Maps .newHashMapWithExpectedSize(2 * maxCount); for (Map.Entry<Variant, List<Warning>> entry : warningMap.entrySet()) { Variant variant = entry.getKey(); List<Warning> warnings = entry.getValue(); for (Warning warning : warnings) { Map<String, Map<Integer, Map<String, Warning>>> messageMap = map.get(warning.issue); if (messageMap == null) { messageMap = Maps.newHashMap(); map.put(warning.issue, messageMap); } Map<Integer, Map<String, Warning>> lineMap = messageMap.get(warning.message); if (lineMap == null) { lineMap = Maps.newHashMap(); messageMap.put(warning.message, lineMap); } Map<String, Warning> fileMap = lineMap.get(warning.line); if (fileMap == null) { fileMap = Maps.newHashMap(); lineMap.put(warning.line, fileMap); } String fileName = warning.file != null ? warning.file.getName() : "<unknown>"; Warning canonical = fileMap.get(fileName); if (canonical == null) { canonical = warning; fileMap.put(fileName, canonical); canonical.variants = Sets.newHashSet(); canonical.gradleProject = project; merged.add(canonical); } canonical.variants.add(variant); } } // Clear out variants on any nodes that define all for (Warning warning : merged) { if (warning.variants != null && warning.variants.size() == totalVariantCount) { // If this error is present in all variants, just clear it out warning.variants = null; } } Collections.sort(merged); return merged; }
From source file:com.opengamma.master.position.impl.AbstractMasterPositionSource.java
/** * Converts a manageable node to a source node. * * @param manNode the manageable node, not null * @param sourceNode the source node, not null * @param versionCorrection the version/correction time for resolving the constituent positions, not null *///from w w w . j a v a 2s . c o m protected void convertNode(final ManageablePortfolioNode manNode, final SimplePortfolioNode sourceNode, final VersionCorrection versionCorrection) { final PositionSearchRequest positionSearch = new PositionSearchRequest(); final Map<ObjectId, Position> positionCache; final int positionCount = populatePositionSearchRequest(positionSearch, manNode); if (positionCount > 0) { positionCache = Maps.newHashMapWithExpectedSize(positionCount); positionSearch.setVersionCorrection(versionCorrection); Collection<Position> positions = positions(positionSearch); if (positions != null) { for (Position position : positions) { positionCache.put(position.getUniqueId().getObjectId(), position); } } } else { positionCache = null; } convertNode(manNode, sourceNode, positionCache); }
From source file:com.twitter.ambrose.hive.AmbroseHivePreHook.java
/** * Waiting <tt>ambrose.wf.between.sleep.seconds</tt> before processing the * next statement (workflow) in the submitted script * // ww w .j ava 2s .c o m * @param hookContext * @param reporter * @param queryId */ private void waitBetween(HookContext hookContext, EmbeddedAmbroseHiveProgressReporter reporter, String queryId) { Configuration conf = hookContext.getConf(); boolean justStarted = conf.getBoolean(SCRIPT_STARTED_PARAM, true); if (justStarted) { conf.setBoolean(SCRIPT_STARTED_PARAM, false); } else { // sleeping between workflows int sleepTimeMs = conf.getInt(WF_BETWEEN_SLEEP_SECS_PARAM, 10); try { LOG.info("One workflow complete, sleeping for " + sleepTimeMs + " sec(s) before moving to the next one if exists. Hit ctrl-c to exit."); Thread.sleep(sleepTimeMs * 1000L); //send progressbar reset event Map<WorkflowProgressField, String> eventData = Maps.newHashMapWithExpectedSize(1); eventData.put(WorkflowProgressField.workflowProgress, "0"); reporter.pushEvent(queryId, new Event.WorkflowProgressEvent(eventData)); reporter.saveEventStack(); reporter.reset(); } catch (InterruptedException e) { LOG.warn("Sleep interrupted", e); } } }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.functions.ElementsFromEmbedding.java
/** * Constructor./*from w w w . j a va2s .c om*/ * * @param epgmGraphHeadFactory EPGM graph head factory * @param epgmVertexFactory EPGM vertex factory * @param epgmEdgeFactory EPGM edge factory * @param embeddingMetaData meta data for the embedding * @param sourceTargetVariables source and target vertex variables by edge variable */ public ElementsFromEmbedding(EPGMGraphHeadFactory<GraphHead> epgmGraphHeadFactory, EPGMVertexFactory<Vertex> epgmVertexFactory, EPGMEdgeFactory<Edge> epgmEdgeFactory, EmbeddingMetaData embeddingMetaData, Map<String, Pair<String, String>> sourceTargetVariables) { this(epgmGraphHeadFactory, epgmVertexFactory, epgmEdgeFactory, embeddingMetaData, sourceTargetVariables, Maps.newHashMapWithExpectedSize(0)); }
From source file:com.attribyte.essem.MGraphResponseGenerator.java
protected void parseGraph(JsonNode sourceParent, List<String> fields, EnumSet<Option> options, RateUnit rateUnit, ArrayNode targetGraph) { DateTimeFormatter parser = ISODateTimeFormat.basicDateTime(); SimpleDateFormat formatter = new SimpleDateFormat(DT_FORMAT); Map<MetricKey, List<ObjectNode>> outputGraphs = Maps.newHashMapWithExpectedSize(4); JsonNode hitsObj = sourceParent.get("hits"); if (hitsObj != null) { JsonNode hitsArr = hitsObj.get("hits"); if (hitsArr != null) { for (JsonNode hitObj : hitsArr) { JsonNode fieldsObj = hitObj.get("fields"); if (fieldsObj != null) { ObjectNode outObj = mapper.createObjectNode(); DateTime timestamp = parser.parseDateTime(getStringField(fieldsObj, "ts")); outObj.put("timestamp", timestamp.getMillis()); outObj.put("date", formatter.format(timestamp.getMillis())); MetricKey key = new MetricKey(getStringField(fieldsObj, "name"), getStringField(fieldsObj, "application"), getStringField(fieldsObj, "host"), getStringField(fieldsObj, "instance")); Iterator<Map.Entry<String, JsonNode>> fieldIter = fieldsObj.fields(); while (fieldIter.hasNext()) { Map.Entry<String, JsonNode> currField = fieldIter.next(); if (!graphIgnoreProperties.contains(currField.getKey())) { JsonNode currValueNode = currField.getValue(); if (currValueNode.isArray() && currValueNode.size() > 0) { setFieldValue(rateUnit, outObj, currField.getKey(), currValueNode.get(0)); } else if (!currValueNode.isArray()) { setFieldValue(rateUnit, outObj, currField.getKey(), currValueNode); }//from www . j av a 2 s. co m } } List<ObjectNode> graph = outputGraphs.get(key); if (graph == null) { graph = Lists.newArrayListWithExpectedSize(1024); outputGraphs.put(key, graph); } graph.add(outObj); } } } } if (outputGraphs.size() == 1) { List<ObjectNode> graphNodes = outputGraphs.values().iterator().next(); for (ObjectNode outObj : graphNodes) { targetGraph.add(outObj); } } else { for (Map.Entry<MetricKey, List<ObjectNode>> graphEntry : outputGraphs.entrySet()) { MetricKey key = graphEntry.getKey(); ObjectNode outputGraphNode = targetGraph.addObject(); outputGraphNode.put("name", key.name); outputGraphNode.put("application", key.application); outputGraphNode.put("host", key.host); outputGraphNode.put("instance", key.instance); ArrayNode currOutputGraph = outputGraphNode.putArray("graph"); for (ObjectNode outObj : graphEntry.getValue()) { currOutputGraph.add(outObj); } } } }
From source file:com.torodb.mongodb.commands.impl.diagnostic.CollStatsImplementation.java
@Override public Status<CollStatsReply> apply(Request req, Command<? super CollStatsArgument, ? super CollStatsReply> command, CollStatsArgument arg, MongodTransaction context) {//from ww w. ja va 2 s . c o m String collection = arg.getCollection(); CollStatsReply.Builder replyBuilder = new CollStatsReply.Builder(req.getDatabase(), collection); if (NamespaceUtil.isSystem(collection)) { //TODO (matteom): support stats on system collections logger.warn("Requested stats on the system collection " + collection + ". ToroDB does not support stats for system " + "collections yet"); Stream<CollectionInfo> collectionsInfo = context.getTorodTransaction() .getCollectionsInfo(req.getDatabase()); replyBuilder.setCount(collectionsInfo.count()).setSize(0).setStorageSize(0).setCustomStorageStats(null) .setIndexDetails(DefaultBsonValues.EMPTY_DOC).setScale(arg.getScale()) .setSizeByIndex(Collections.<String, Number>emptyMap()).setCapped(false); } else { try { CollectionInfo collectionInfo = context.getTorodTransaction().getCollectionInfo(req.getDatabase(), arg.getCollection()); if (collectionInfo.isCapped()) { replyBuilder.setCapped(true).setMaxIfCapped(collectionInfo.getMaxIfCapped()); } else { replyBuilder.setCapped(false); } } catch (CollectionNotFoundException ignore) { //Nothing to do if the collection does not exist } replyBuilder.setCapped(false).setScale(arg.getScale()); int scale = replyBuilder.getScale(); //TODO (matteom): add index stats Collection<? extends NamedToroIndex> indexes = ImmutableList.of(); Map<String, Long> sizeByMap = Maps.newHashMapWithExpectedSize(indexes.size()); replyBuilder.setSizeByIndex(sizeByMap); replyBuilder.setCount(context.getTorodTransaction().countAll(req.getDatabase(), collection)); replyBuilder .setSize(context.getTorodTransaction().getDocumentsSize(req.getDatabase(), collection) / scale); replyBuilder.setStorageSize( context.getTorodTransaction().getCollectionSize(req.getDatabase(), collection) / scale); } return Status.ok(replyBuilder.build()); }