List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:com.yahoo.bullet.parsing.RuleUtils.java
@SafeVarargs public static String makeMap(Pair<String, String>... pairs) { StringBuilder builder = new StringBuilder(); builder.append("{"); String delimiter = ""; for (Pair<String, String> pair : pairs) { builder.append(delimiter).append("'").append(pair.getKey()).append("'").append(" : '") .append(pair.getValue()).append("'"); delimiter = ", "; }/*from w w w .jav a2 s . c o m*/ builder.append("}"); return builder.toString(); }
From source file:com.galenframework.parser.GalenPageActionReader.java
private static GalenPageAction checkActionFrom(String[] args, String originalText) { CommandLineReader reader = new CommandLineReader(args); String specPath = null;//from w w w . j a va 2 s .co m List<String> includedTags = new LinkedList<>(); List<String> excludedTags = new LinkedList<>(); Map<String, Object> jsVariables = new HashMap<>(); //Skipping the check action name reader.skipArgument(); while (reader.hasNext()) { if (!reader.isNextArgument()) { specPath = reader.readNext(); } else { Pair<String, String> argument = reader.readArgument(); if (argument.getKey().equals("include")) { includedTags.addAll(readTags(argument.getValue())); } else if (argument.getKey().equals("exclude")) { excludedTags.addAll(readTags(argument.getValue())); } else if (argument.getKey().startsWith("V")) { String varName = argument.getKey().substring(1); String varValue = argument.getValue(); jsVariables.put(varName, varValue); } else { throw new SyntaxException("Unknown argument: " + argument.getKey()); } } } if (specPath == null || specPath.isEmpty()) { throw new SyntaxException("Missing spec path"); } return new GalenPageActionCheck().withSpec(specPath).withIncludedTags(includedTags) .withExcludedTags(excludedTags).withJsVariables(jsVariables); }
From source file:alfio.util.TemplateManager.java
public static String translate(String template, Locale locale, MessageSource messageSource) { StringBuilder sb = new StringBuilder(template.length()); AST ast = new AST(); ParserState state = ParserState.START; int idx = 0;/*from www . j a v a 2 s. com*/ while (true) { Pair<ParserState, Integer> stateAndIdx = state.next(template, idx, ast); state = stateAndIdx.getKey(); idx = stateAndIdx.getValue(); if (state == ParserState.END) { break; } } ast.visit(sb, locale, messageSource); return sb.toString(); }
From source file:fr.landel.utils.commons.MapUtils2.java
/** * Create a map from {@code objects}./* w w w . j a va 2s .c o m*/ * * <pre> * Map<String, String> map = MapUtils2.newMap(TreeMap::new, Pair.of("key1", "value1"), Pair.of("key2", "value2")); * * // equivalent * Map<String, String> map = new TreeMap<>(); * map.put("key1", "value1"); * map.put("key2", "value2"); * </pre> * * @param mapProvider * map constructor supplier * @param objects * objects pair to put in the new {@link Map} * @param <K> * the type of map key * @param <V> * the type of map value * @param <M> * the type of map * @return the new {@link Map} * @throws NullPointerException * if {@code mapProvider} is {@code null} * @throws IllegalArgumentException * if {@code objects} is {@code null} or empty */ @SafeVarargs public static <K, V, M extends Map<K, V>> M newMap(final Supplier<M> mapProvider, Pair<K, V>... objects) { Objects.requireNonNull(mapProvider); ObjectUtils.requireNonNull(objects, ERROR_OBJECTS_SUPPLIER); final M map = mapProvider.get(); for (Pair<K, V> pair : objects) { map.put(pair.getKey(), pair.getValue()); } return map; }
From source file:net.minecraftforge.items.VanillaInventoryCodeHooks.java
/** * Copied from TileEntityHopper#transferItemsOut and added capability support *///from ww w. j a va 2 s. c om public static boolean insertHook(TileEntityHopper hopper) { EnumFacing hopperFacing = BlockHopper.getFacing(hopper.getBlockMetadata()); Pair<IItemHandler, Object> destinationResult = getItemHandler(hopper, hopperFacing); if (destinationResult == null) { return false; } else { IItemHandler itemHandler = destinationResult.getKey(); Object destination = destinationResult.getValue(); if (isFull(itemHandler)) { return false; } else { for (int i = 0; i < hopper.getSizeInventory(); ++i) { if (!hopper.getStackInSlot(i).isEmpty()) { ItemStack originalSlotContents = hopper.getStackInSlot(i).copy(); ItemStack insertStack = hopper.decrStackSize(i, 1); ItemStack remainder = putStackInInventoryAllSlots(hopper, destination, itemHandler, insertStack); if (remainder.isEmpty()) { return true; } hopper.setInventorySlotContents(i, originalSlotContents); } } return false; } } }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdDiscovery.java
private static Map<UpnpIgdDevice, byte[]> getRootXmlForEachDevice(Set<UpnpIgdDevice> devices) throws InterruptedException { Map<UpnpIgdDevice, byte[]> serviceRoots = new HashMap(); ExecutorService executorService = null; try {/*from w w w . j a va 2 s . c o m*/ int maximumPoolSize = (int) ((double) Runtime.getRuntime().availableProcessors() / (1.0 - 0.95)); executorService = new ThreadPoolExecutor(0, maximumPoolSize, 1, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); List<HttpRequestCallable<UpnpIgdDevice>> tasks = new LinkedList<>(); for (UpnpIgdDevice device : devices) { tasks.add(new HttpRequestCallable<>(device.getUrl(), device)); } List<Future<Pair<UpnpIgdDevice, byte[]>>> results = executorService.invokeAll(tasks); for (Future<Pair<UpnpIgdDevice, byte[]>> result : results) { try { Pair<UpnpIgdDevice, byte[]> data = result.get(); serviceRoots.put(data.getKey(), data.getValue()); } catch (InterruptedException | ExecutionException | CancellationException e) { // NOPMD // do nothing, skip } } } finally { if (executorService != null) { executorService.shutdownNow(); } } return serviceRoots; }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdDiscovery.java
private static Map<UpnpIgdServiceReference, byte[]> getServiceDescriptions( Set<UpnpIgdServiceReference> services) throws InterruptedException { Map<UpnpIgdServiceReference, byte[]> serviceXmls = new HashMap(); ExecutorService executorService = null; try {//from ww w .j av a 2 s .co m int maximumPoolSize = (int) ((double) Runtime.getRuntime().availableProcessors() / (1.0 - 0.95)); executorService = new ThreadPoolExecutor(0, maximumPoolSize, 1, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); List<HttpRequestCallable<UpnpIgdServiceReference>> tasks = new LinkedList<>(); for (UpnpIgdServiceReference service : services) { tasks.add(new HttpRequestCallable<>(service.getScpdUrl(), service)); } List<Future<Pair<UpnpIgdServiceReference, byte[]>>> results = executorService.invokeAll(tasks); for (Future<Pair<UpnpIgdServiceReference, byte[]>> result : results) { try { Pair<UpnpIgdServiceReference, byte[]> data = result.get(); serviceXmls.put(data.getKey(), data.getValue()); } catch (InterruptedException | ExecutionException | CancellationException e) { // NOPMD // do nothing, skip } } } finally { if (executorService != null) { executorService.shutdownNow(); } } return serviceXmls; }
From source file:com.helion3.prism.api.query.QueryBuilder.java
/** * Builds a {@link Query} by parsing an array of arguments. * * @param parameters String[] Parameter:value list * @return {@link Query} Database query object *//* ww w .j a v a 2s .c o m*/ public static CompletableFuture<Query> fromArguments(QuerySession session, @Nullable String[] arguments) throws ParameterException { checkNotNull(session); Query query = new Query(); CompletableFuture<Query> future = new CompletableFuture<Query>(); // Track all parameter pairs Map<String, String> definedParameters = new HashMap<String, String>(); if (arguments.length > 0) { List<ListenableFuture<?>> futures = new ArrayList<ListenableFuture<?>>(); for (String arg : arguments) { Optional<ListenableFuture<?>> listenable; if (flagPattern.matcher(arg).matches()) { listenable = parseFlagFromArgument(session, query, arg); } else { // Get alias/value pair Pair<String, String> pair = getParameterKeyValue(arg); // Parse for handler listenable = parseParameterFromArgument(session, query, pair); // Add to list of defined definedParameters.put(pair.getKey(), pair.getValue()); } if (listenable.isPresent()) { futures.add(listenable.get()); } } if (!futures.isEmpty()) { ListenableFuture<List<Object>> combinedFuture = Futures.allAsList(futures); combinedFuture.addListener(new Runnable() { @Override public void run() { future.complete(query); } }, MoreExecutors.sameThreadExecutor()); } else { future.complete(query); } } else { future.complete(query); } if (Prism.getConfig().getNode("defaults", "enabled").getBoolean()) { // Require any parameter defaults String defaultsUsed = ""; for (ParameterHandler handler : Prism.getParameterHandlers()) { boolean aliasFound = false; for (String alias : handler.getAliases()) { if (definedParameters.containsKey(alias)) { aliasFound = true; break; } } if (!aliasFound) { Optional<Pair<String, String>> pair = handler.processDefault(session, query); if (pair.isPresent()) { defaultsUsed += pair.get().getKey() + ":" + pair.get().getValue() + " "; } } } // @todo should move this if (!defaultsUsed.isEmpty()) { session.getCommandSource().get().sendMessage( Format.subduedHeading(Text.of(String.format("Defaults used: %s", defaultsUsed)))); } } return future; }
From source file:net.minecraftforge.items.VanillaInventoryCodeHooks.java
/** * Copied from BlockDropper#dispense and added capability support *//*w w w . jav a 2 s. c om*/ public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, @Nonnull ItemStack stack) { EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING); BlockPos blockpos = pos.offset(enumfacing); Pair<IItemHandler, Object> destinationResult = getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite()); if (destinationResult == null) { return true; } else { IItemHandler itemHandler = destinationResult.getKey(); Object destination = destinationResult.getValue(); ItemStack dispensedStack = stack.copy().splitStack(1); ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack); if (remainder.isEmpty()) { remainder = stack.copy(); remainder.shrink(1); } else { remainder = stack.copy(); } dropper.setInventorySlotContents(slot, remainder); return false; } }
From source file:blusunrize.immersiveengineering.client.render.TileRenderAutoWorkbench.java
public static BlueprintLines getBlueprintDrawable(ItemStack stack, World world) { if (stack.isEmpty()) return null; EntityPlayer player = ClientUtils.mc().player; ArrayList<BufferedImage> images = new ArrayList<>(); try {//from w ww .ja va2s .c o m IBakedModel ibakedmodel = ClientUtils.mc().getRenderItem().getItemModelWithOverrides(stack, world, player); HashSet<String> textures = new HashSet(); Collection<BakedQuad> quads = ibakedmodel.getQuads(null, null, 0); for (BakedQuad quad : quads) if (quad != null && quad.getSprite() != null) textures.add(quad.getSprite().getIconName()); for (String s : textures) { ResourceLocation rl = new ResourceLocation(s); rl = new ResourceLocation(rl.getNamespace(), String.format("%s/%s%s", "textures", rl.getPath(), ".png")); IResource resource = ClientUtils.mc().getResourceManager().getResource(rl); BufferedImage bufferedImage = TextureUtil.readBufferedImage(resource.getInputStream()); if (bufferedImage != null) images.add(bufferedImage); } } catch (Exception e) { } if (images.isEmpty()) return null; ArrayList<Pair<TexturePoint, TexturePoint>> lines = new ArrayList(); HashSet testSet = new HashSet(); HashMultimap<Integer, TexturePoint> area = HashMultimap.create(); int wMax = 0; for (BufferedImage bufferedImage : images) { Set<Pair<TexturePoint, TexturePoint>> temp_lines = new HashSet<>(); int w = bufferedImage.getWidth(); int h = bufferedImage.getHeight(); if (h > w) h = w; if (w > wMax) wMax = w; for (int hh = 0; hh < h; hh++) for (int ww = 0; ww < w; ww++) { int argb = bufferedImage.getRGB(ww, hh); float r = (argb >> 16 & 255) / 255f; float g = (argb >> 8 & 255) / 255f; float b = (argb & 255) / 255f; float intesity = (r + b + g) / 3f; int alpha = (argb >> 24) & 255; if (alpha > 0) { boolean added = false; //Check colour sets for similar colour to shade it later TexturePoint tp = new TexturePoint(ww, hh, w); if (!testSet.contains(tp)) { for (Integer key : area.keySet()) { for (TexturePoint p : area.get(key)) { float mod = w / (float) p.scale; int pColour = bufferedImage.getRGB((int) (p.x * mod), (int) (p.y * mod)); float dR = (r - (pColour >> 16 & 255) / 255f); float dG = (g - (pColour >> 8 & 255) / 255f); float dB = (b - (pColour & 255) / 255f); double delta = Math.sqrt(dR * dR + dG * dG + dB * dB); if (delta < .25) { area.put(key, tp); added = true; break; } } if (added) break; } if (!added) area.put(argb, tp); testSet.add(tp); } //Compare to direct neighbour for (int i = 0; i < 4; i++) { int xx = (i == 0 ? -1 : i == 1 ? 1 : 0); int yy = (i == 2 ? -1 : i == 3 ? 1 : 0); int u = ww + xx; int v = hh + yy; int neighbour = 0; float delta = 1; boolean notTransparent = false; if (u >= 0 && u < w && v >= 0 && v < h) { neighbour = bufferedImage.getRGB(u, v); notTransparent = ((neighbour >> 24) & 255) > 0; if (notTransparent) { float neighbourIntesity = ((neighbour >> 16 & 255) + (neighbour >> 8 & 255) + (neighbour & 255)) / 765f; float intesityDelta = Math.max(0, Math.min(1, Math.abs(intesity - neighbourIntesity))); float rDelta = Math.max(0, Math.min(1, Math.abs(r - (neighbour >> 16 & 255) / 255f))); float gDelta = Math.max(0, Math.min(1, Math.abs(g - (neighbour >> 8 & 255) / 255f))); float bDelta = Math.max(0, Math.min(1, Math.abs(b - (neighbour & 255) / 255f))); delta = Math.max(intesityDelta, Math.max(rDelta, Math.max(gDelta, bDelta))); delta = delta < .25 ? 0 : delta > .4 ? 1 : delta; } } if (delta > 0) { Pair<TexturePoint, TexturePoint> l = Pair.of( new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 0), hh + (i == 2 ? 0 : i == 3 ? 1 : 0), w), new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 1), hh + (i == 2 ? 0 : i == 3 ? 1 : 1), w)); temp_lines.add(l); } } } } lines.addAll(temp_lines); } ArrayList<Integer> lumiSort = new ArrayList<>(area.keySet()); Collections.sort(lumiSort, (rgb1, rgb2) -> Double.compare(getLuminance(rgb1), getLuminance(rgb2))); HashMultimap<ShadeStyle, Point> complete_areaMap = HashMultimap.create(); int lineNumber = 2; int lineStyle = 0; for (Integer i : lumiSort) { complete_areaMap.putAll(new ShadeStyle(lineNumber, lineStyle), area.get(i)); ++lineStyle; lineStyle %= 3; if (lineStyle == 0) lineNumber += 1; } Set<Pair<Point, Point>> complete_lines = new HashSet<>(); for (Pair<TexturePoint, TexturePoint> line : lines) { TexturePoint p1 = line.getKey(); TexturePoint p2 = line.getValue(); complete_lines.add(Pair.of( new Point((int) (p1.x / (float) p1.scale * wMax), (int) (p1.y / (float) p1.scale * wMax)), new Point((int) (p2.x / (float) p2.scale * wMax), (int) (p2.y / (float) p2.scale * wMax)))); } return new BlueprintLines(wMax, complete_lines, complete_areaMap); }