List of usage examples for com.google.common.collect Ranges closed
public static <C extends Comparable<?>> Range<C> closed(C paramC1, C paramC2)
From source file:com.sk89q.worldguard.blacklist.target.TargetMatcherParser.java
private Predicate<Short> parseRange(String input) throws TargetMatcherParseException { input = input.trim();/*from ww w . jav a 2 s.c o m*/ Matcher matcher; matcher = LESS_THAN_PATTERN.matcher(input); if (matcher.matches()) { return Ranges.atMost(Short.parseShort(matcher.group(1))); } matcher = GREATER_THAN_PATTERN.matcher(input); if (matcher.matches()) { return Ranges.atLeast(Short.parseShort(matcher.group(1))); } matcher = RANGE_PATTERN.matcher(input); if (matcher.matches()) { return Ranges.closed(Short.parseShort(matcher.group(1)), Short.parseShort(matcher.group(2))); } try { short s = Short.parseShort(input); return Ranges.closed(s, s); } catch (NumberFormatException e) { throw new TargetMatcherParseException("Unknown data value range: " + input); } }
From source file:com.datatorrent.demos.mobile.Application.java
private void configure(DAG dag, Configuration conf) { //dag.setAttribute(DAG.CONTAINERS_MAX_COUNT, 1); if (StreamingApplication.Environment.CLUSTER == conf.getEnum(StreamingApplication.ENVIRONMENT, StreamingApplication.Environment.LOCAL)) { // settings only affect distributed mode AttributeMap attributes = dag.getAttributes(); if (attributes.get(DAGContext.CONTAINER_MEMORY_MB) == null) { attributes.put(DAGContext.CONTAINER_MEMORY_MB, 2048); }//ww w . j ava 2s. com if (attributes.get(DAGContext.MASTER_MEMORY_MB) == null) { attributes.put(DAGContext.MASTER_MEMORY_MB, 1024); } } else if (StreamingApplication.Environment.LOCAL == conf.getEnum(StreamingApplication.ENVIRONMENT, StreamingApplication.Environment.CLUSTER)) { } String phoneRange = conf.get(P_phoneRange, null); if (phoneRange != null) { String[] tokens = phoneRange.split("-"); if (tokens.length != 2) { throw new IllegalArgumentException("Invalid range: " + phoneRange); } this.phoneRange = Ranges.closed(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1])); } System.out.println("Phone range: " + this.phoneRange); }
From source file:org.cloudsmith.geppetto.common.stats.IntegerCluster.java
public List<Range<Integer>> toListOfRanges() { lazyCluster();/*from w w w. ja v a2s. com*/ List<Range<Integer>> result = Lists.newArrayListWithExpectedSize(clusterList.size()); for (ClusterNode n : clusterList) { result.add(Ranges.closed(n.min(), n.max())); } return result; }
From source file:org.shininet.bukkit.itemrenamer.ItemRenamerCommands.java
private int getItemID(Deque<String> args) { try {//from w ww. j a v a 2 s. c o m List<Integer> result = ConfigParsers.getIntegers(args, 1, Ranges.closed(0, 4096)); if (result.size() == 1) { return result.get(0); } else { throw new CommandErrorException("Cannot find item ID."); } } catch (IllegalArgumentException e) { throw new CommandErrorException(e.getMessage(), e); } }