List of usage examples for com.google.common.collect Maps newHashMapWithExpectedSize
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize)
From source file:org.apache.kylin.engine.mr.common.CuboidStatsReaderUtil.java
public static Map<Long, Long> readCuboidStatsFromSegment(Set<Long> cuboidIds, CubeSegment cubeSegment) throws IOException { if (cubeSegment == null) { logger.warn("The cube segment can not be " + null); return null; }//from www. java2 s. com CubeStatsReader cubeStatsReader = new CubeStatsReader(cubeSegment, null, cubeSegment.getConfig()); if (cubeStatsReader.getCuboidRowEstimatesHLL() == null || cubeStatsReader.getCuboidRowEstimatesHLL().isEmpty()) { logger.info("Cuboid Statistics is not enabled."); return null; } Map<Long, Long> cuboidsWithStatsAll = cubeStatsReader.getCuboidRowEstimatesHLL(); Map<Long, Long> cuboidsWithStats = Maps.newHashMapWithExpectedSize(cuboidIds.size()); for (Long cuboid : cuboidIds) { Long rowEstimate = cuboidsWithStatsAll.get(cuboid); if (rowEstimate == null) { logger.warn("Cannot get the row count stats for cuboid " + cuboid); } else { cuboidsWithStats.put(cuboid, rowEstimate); } } return cuboidsWithStats; }
From source file:com.aipo.container.gadgets.uri.AipoConcatUriManager.java
private ConcatData makeConcatUri(ConcatUri ctx, boolean isAdjacent, String version) { // TODO: Consider per-bundle isAdjacent plus first-bundle direct evaluation if (!isAdjacent && ctx.getType() != Type.JS) { // Split-concat is only supported for JS at the moment. // This situation should never occur due to ConcatLinkRewriter's // implementation. throw new UnsupportedOperationException("Split concatenation only supported for JS"); }/* w w w.j a v a 2 s. c o m*/ UriBuilder uriBuilder = ctx.makeQueryParams(null, version); String concatHost = ContainerToolkit.getHost(containerConfigDbService); String concatPath = getReqVal(ctx.getContainer(), CONCAT_PATH_PARAM); uriBuilder.setAuthority(concatHost); uriBuilder.setPath(concatPath); uriBuilder.setScheme(ContainerToolkit.getScheme()); uriBuilder.addQueryParameter(Param.TYPE.getKey(), ctx.getType().getType()); List<Uri> resourceUris = ctx.getBatch(); Map<Uri, String> snippets = Maps.newHashMapWithExpectedSize(resourceUris.size()); String splitParam = config.getString(ctx.getContainer(), CONCAT_JS_SPLIT_PARAM); boolean doSplit = false; if (!isAdjacent && splitParam != null && !"false".equalsIgnoreCase(splitParam)) { uriBuilder.addQueryParameter(Param.JSON.getKey(), splitParam); doSplit = true; } Integer i = Integer.valueOf(START_INDEX); for (Uri resource : resourceUris) { uriBuilder.addQueryParameter(i.toString(), resource.toString()); i++; if (doSplit) { snippets.put(resource, getJsSnippet(splitParam, resource)); } } return new ConcatData(uriBuilder.toUri(), snippets); }
From source file:org.gradoop.flink.algorithms.fsm.transactional.tle.canonicalization.CanonicalLabeler.java
/** * Creates an adjacency matrix.//ww w . ja v a2 s . c o m * * @param vertices vertices * @param edges edges * @return adjacency matrix */ private Map<Integer, Map<Integer, Set<Integer>>> createAdjacencyMatrix(Map<Integer, String> vertices, Map<Integer, FSMEdge> edges) { Map<Integer, Map<Integer, Set<Integer>>> adjacencyMatrix = Maps.newHashMapWithExpectedSize(vertices.size()); for (Map.Entry<Integer, FSMEdge> edgeEntry : edges.entrySet()) { int edgeId = edgeEntry.getKey(); FSMEdge edge = edgeEntry.getValue(); int sourceId = edge.getSourceId(); int targetId = edge.getTargetId(); addAdjacencyMatrixEntry(adjacencyMatrix, sourceId, edgeId, targetId); if (sourceId != targetId) { addAdjacencyMatrixEntry(adjacencyMatrix, targetId, edgeId, sourceId); } } return adjacencyMatrix; }
From source file:org.eclipse.hawkbit.ui.common.CommonDialogWindow.java
/** * Constructor./*from w w w . j av a 2s. c om*/ * * @param caption * the caption * @param content * the content * @param helpLink * the helpLinks * @param closeListener * the saveDialogCloseListener * @param cancelButtonClickListener * the cancelButtonClickListener * @param layout * the abstract layout * @param i18n * the i18n service */ public CommonDialogWindow(final String caption, final Component content, final String helpLink, final SaveDialogCloseListener closeListener, final ClickListener cancelButtonClickListener, final AbstractLayout layout, final VaadinMessageSource i18n) { checkNotNull(closeListener); this.caption = caption; this.content = content; this.helpLink = helpLink; this.closeListener = closeListener; this.cancelButtonClickListener = cancelButtonClickListener; this.allComponents = getAllComponents(layout); this.orginalValues = Maps.newHashMapWithExpectedSize(allComponents.size()); this.i18n = i18n; init(); }
From source file:org.dishevelled.venn.layout.TernaryVennLayoutImpl.java
/** * Create a new ternary venn layout with the specified parameters. * * @param firstShape shape for the first set, must not be null * @param secondShape shape for the second set, must not be null * @param thirdShape shape for the third set, must not be null * @param firstOnlyLuneCenter lune center for the first only area * @param secondOnlyLuneCenter lune center for the second only area * @param thirdOnlyLuneCenter lune center for the third only area * @param firstSecondLuneCenter lune center for the first second area * @param firstThirdLuneCenter lune center for the first third area * @param secondThirdLuneCenter lune center for the second third area * @param intersectionLuneCenter lune center for the intersection area * @param boundingRectangle bounding rectangle, must not be null *///from w w w. j a va2 s. c o m public TernaryVennLayoutImpl(final Shape firstShape, final Shape secondShape, final Shape thirdShape, final Point2D firstOnlyLuneCenter, final Point2D secondOnlyLuneCenter, final Point2D thirdOnlyLuneCenter, final Point2D firstSecondLuneCenter, final Point2D firstThirdLuneCenter, final Point2D secondThirdLuneCenter, final Point2D intersectionLuneCenter, final Rectangle2D boundingRectangle) { if (firstShape == null) { throw new IllegalArgumentException("firstShape must not be null"); } if (secondShape == null) { throw new IllegalArgumentException("secondShape must not be null"); } if (thirdShape == null) { throw new IllegalArgumentException("thirdShape must not be null"); } if (boundingRectangle == null) { throw new IllegalArgumentException("boundingRectangle must not be null"); } this.firstShape = firstShape; this.secondShape = secondShape; this.thirdShape = thirdShape; this.firstOnlyLuneCenter = firstOnlyLuneCenter; this.secondOnlyLuneCenter = secondOnlyLuneCenter; this.thirdOnlyLuneCenter = thirdOnlyLuneCenter; this.firstSecondLuneCenter = firstSecondLuneCenter; this.firstThirdLuneCenter = firstThirdLuneCenter; this.secondThirdLuneCenter = secondThirdLuneCenter; this.intersectionLuneCenter = intersectionLuneCenter; this.boundingRectangle = boundingRectangle; luneCenters = Maps.newHashMapWithExpectedSize(7); luneCenters.put(toImmutableBitSet(0), this.firstOnlyLuneCenter); luneCenters.put(toImmutableBitSet(1), this.secondOnlyLuneCenter); luneCenters.put(toImmutableBitSet(2), this.thirdOnlyLuneCenter); luneCenters.put(toImmutableBitSet(0, 1), this.firstSecondLuneCenter); luneCenters.put(toImmutableBitSet(0, 2), this.firstThirdLuneCenter); luneCenters.put(toImmutableBitSet(1, 2), this.secondThirdLuneCenter); luneCenters.put(toImmutableBitSet(0, 1, 2), this.intersectionLuneCenter); }
From source file:org.apache.hadoop.hdfs.protocol.datatransfer.sasl.DataTransferSaslUtil.java
/** * Creates SASL properties required for an encrypted SASL negotiation. * * @param encryptionAlgorithm to use for SASL negotation * @return properties of encrypted SASL negotiation *//*from w ww. j a v a2 s . c o m*/ public static Map<String, String> createSaslPropertiesForEncryption(String encryptionAlgorithm) { Map<String, String> saslProps = Maps.newHashMapWithExpectedSize(3); saslProps.put(Sasl.QOP, QualityOfProtection.PRIVACY.getSaslQop()); saslProps.put(Sasl.SERVER_AUTH, "true"); saslProps.put("com.sun.security.sasl.digest.cipher", encryptionAlgorithm); return saslProps; }
From source file:org.matsim.contrib.dvrp.path.OneToManyPathSearch.java
private Map<Id<Node>, ToNode> createToNodes(Link fromLink, Collection<Link> toLinks) { Map<Id<Node>, ToNode> toNodes = Maps.newHashMapWithExpectedSize(toLinks.size()); for (Link toLink : toLinks) { if (toLink != fromLink) { Node toNode = getToNode(toLink); toNodes.putIfAbsent(toNode.getId(), new ToNode(toNode, 0, 0)); }//from www .ja v a 2 s . co m } return toNodes; }
From source file:com.voxelplugineering.voxelsniper.brush.effect.OldBlendBrush.java
@Override public ExecutionResult run(Player player, BrushVars args) { boolean excludeFluid = true; if (args.has(BrushKeys.EXCLUDE_FLUID)) { excludeFluid = args.get(BrushKeys.EXCLUDE_FLUID, Boolean.class).get(); }/*from w ww .jav a 2s. co m*/ Optional<Shape> s = args.get(BrushKeys.SHAPE, Shape.class); if (!s.isPresent()) { return ExecutionResult.abortExecution(); } Optional<Material> m = args.get(BrushKeys.MATERIAL, Material.class); if (!m.isPresent()) { player.sendMessage("You must select a material."); return ExecutionResult.abortExecution(); } Optional<String> kernalShape = args.get(BrushKeys.KERNEL, String.class); Optional<Double> kernalSize = args.get(BrushKeys.KERNEL_SIZE, Double.class); System.out.println("Using strings " + kernalShape.or("empty") + " and " + kernalSize.or(0.0)); double size = kernalSize.or(1.0); String kernelString = kernalShape.or("voxel"); Optional<Shape> se = PrimativeShapeFactory.createShape(kernelString, size); if (!se.isPresent()) { se = Optional.<Shape>of(new CuboidShape(3, 3, 3, new Vector3i(1, 1, 1))); } Optional<Block> l = args.get(BrushKeys.TARGET_BLOCK, Block.class); MaterialShape ms = new ComplexMaterialShape(s.get(), m.get()); World world = player.getWorld(); Location loc = l.get().getLocation(); Shape shape = s.get(); Shape structElem = se.get(); // Extract the location in the world to x0, y0 and z0. for (int x = 0; x < ms.getWidth(); x++) { int x0 = loc.getFlooredX() + x - shape.getOrigin().getX(); for (int y = 0; y < ms.getHeight(); y++) { int y0 = loc.getFlooredY() + y - shape.getOrigin().getY(); for (int z = 0; z < ms.getLength(); z++) { int z0 = loc.getFlooredZ() + z - shape.getOrigin().getZ(); if (!shape.get(x, y, z, false)) { continue; } // Represents a histogram of material occurrences hit by the // structuring element. Map<Material, Integer> mats = Maps.newHashMapWithExpectedSize(10); for (int a = 0; a < structElem.getWidth(); a++) { for (int b = 0; b < structElem.getHeight(); b++) { for (int c = 0; c < structElem.getLength(); c++) { if (!structElem.get(a, b, c, false)) { continue; } int a0 = a - structElem.getOrigin().getX(); int b0 = b - structElem.getOrigin().getY(); int c0 = c - structElem.getOrigin().getZ(); // Discludes the target block from the // calculation. if (!(a0 == 0 && b0 == 0 && c0 == 0)) { // TODO: Use world bounds instead of // hardcoded magical values from Minecraft. int clampedY = Maths.clamp(y0 + b0, 0, 255); Material mat = world.getBlock(x0 + a0, clampedY, z0 + c0).get().getMaterial(); if (mats.containsKey(mat)) { mats.put(mat, mats.get(mat) + 1); } else { mats.put(mat, 1); } } } } } // Select the material which occured the most. int n = 0; Material winner = null; for (Map.Entry<Material, Integer> e : mats.entrySet()) { if (e.getValue() > n && !(excludeFluid && e.getKey().isLiquid())) { winner = e.getKey(); n = e.getValue(); } } // If multiple materials occurred the most, the tie check // will become true. boolean tie = false; for (Map.Entry<Material, Integer> e : mats.entrySet()) { if (e.getValue() == n && !(excludeFluid && e.getKey().isLiquid()) && !e.getKey().equals(winner)) { tie = true; } } // If a tie is found, no change is made. if (!tie) { ms.setMaterial(x, y, z, false, winner); } } } } new ShapeChangeQueue(player, loc, ms).flush(); return ExecutionResult.continueExecution(); }
From source file:com.isotrol.impe3.web20.impl.RatingsServiceImpl.java
/** * @see com.isotrol.impe3.web20.api.RatingsService#getRatingsOfResources(java.lang.String, java.util.List, * com.isotrol.impe3.web20.api.EventFilterDTO) *//*from w w w .j av a2 s.c om*/ @Transactional(rollbackFor = Throwable.class) public Map<String, ResourceRatingDTO> getRatingsOfResources(String serviceId, List<String> resources, EventFilterDTO filter) throws ServiceException { if (filter == null || resources == null) { return null; } final Long groupId = ratingManager.getGroupId(filter); final Map<String, ResourceRatingDTO> ratings = Maps.newHashMapWithExpectedSize(resources.size()); for (String resource : resources) { final ResourceRatingDTO rating = ratingManager.getResource(maps.get(filter), groupId, resource); ratings.put(resource, rating); } return ratings; }
From source file:org.apache.shindig.gadgets.spec.MessageBundle.java
/** * Extracts messages from an element./*w w w. j a v a 2s.c o m*/ * @param element Xml dom containing mesage bundle nodes * @return Immutable map of message keys to values * @throws SpecParserException when invalid xml is parsed */ private ImmutableMap<String, String> parseMessages(Element element) throws SpecParserException { NodeList nodes = element.getElementsByTagName("msg"); Map<String, String> messages = Maps.newHashMapWithExpectedSize(nodes.getLength()); for (int i = 0, j = nodes.getLength(); i < j; ++i) { Element msg = (Element) nodes.item(i); String name = XmlUtil.getAttribute(msg, "name"); if (name == null) { throw new SpecParserException("All message bundle entries must have a name attribute."); } StringWriter sw = new StringWriter(); NodeList msgChildren = msg.getChildNodes(); for (int child = 0; child < msgChildren.getLength(); ++child) { try { if (msgChildren.item(child).getNodeType() == Node.CDATA_SECTION_NODE) { // Workaround to treat CDATA as text. sw.append(msgChildren.item(child).getTextContent()); } else { htmlSerializer.serialize(msgChildren.item(child), sw); } } catch (IOException e) { throw new SpecParserException("Unexpected error getting value of msg node", new XmlException(e)); } } messages.put(name, sw.toString().trim()); } return ImmutableMap.copyOf(messages); }