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.comphenix.protocol.compat.guava.Guava10.java
@Override public <C extends Comparable<C>> Range<C> closedRange(C lower, C upper) { return Ranges.closed(lower, upper); }
From source file:pl.porannajava.javnysejm.DeputyCommittee.java
protected DeputyCommittee(Map<String, String> properties) { this.committeeId = StringConverter.getInteger(properties.get("komisja_id")); LocalDate fromDate = StringConverter.getDate(properties.get("od")); LocalDate toDate = null;/*from w w w. j a va 2 s .c o m*/ try { toDate = StringConverter.getDate(properties.get("do")); } catch (IllegalFieldValueException e) { // nothing to do. // trying to catch "0000-00-00" date } if (toDate != null) { this.interval = Ranges.closed(fromDate, toDate); } else { this.interval = Ranges.atLeast(fromDate); } this.function = StringConverter.getUnescapedString(properties.get("funkcja")); }
From source file:com.github.fhirschmann.clozegen.lib.util.CollectionUtils.java
/** * Returns a view of a list made up of the n adjacent neighbors of an element * and the element itself./* w ww . j av a2s. co m*/ * <p> * For example, assuming the list is something like [1, 2, 3, 4, 5, 6], * then getAdjacentTo(3, 1) will yield [2, 3, 4]. * </p> * <p> * The returned list is backed by this list, so non-structural changes in the * returned list are reflected in this list, and vice-versa. The returned list * supports all of the optional list operations supported by this list. * </p> * <p> * * @param <T> the type of the list elements * @param list the list to use * @param index the index of the element to get the adjacent neighbors for * @param num the number of neighbors (on each side) to include * @return a view based on the specified parameters */ public static <T> List<T> getAdjacentTo(final List<T> list, final int index, final int num) { /* The num adjacent neighbors of an element intersected with the list's bounds */ final Range<Integer> range = Ranges.closed(index - num, index + num) .intersection(Ranges.closed(0, list.size() - 1)); return list.subList(range.lowerEndpoint(), range.upperEndpoint() + 1); }
From source file:org.apache.provisionr.api.network.RuleBuilder.java
public RuleBuilder ports(int lowerPort, int upperPort) { return ports(Ranges.closed(lowerPort, upperPort)); }
From source file:com.github.nethad.clustermeister.provisioning.rmi.RmiInfrastructure.java
private boolean isValidPort(int port) { return Ranges.closed(MIN_PORT, MAX_PORT).apply(port); }
From source file:io.TileSetBuilderWesnoth.java
public HexTileSet read() { Map<OctDirection, TerrainType> borders = new HashMap<>(); HexTileSet ts = new HexTileSet(72, 72, 36); ts.addImage(loadImage("foreground.png"), 0, 0, 0, 0); ts.setCursorTileIndex(0);//from w ww. j a va2 s. c om ts.setInvalidTileIndex(0); ts.addImage(loadImage("grass", "green.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green2.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green3.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green4.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green5.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green6.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green7.png"), 0, 0, 0, 0); ts.addImage(loadImage("grass", "green8.png"), 0, 0, 0, 0); ts.defineTerrain(Ranges.closed(1, 8).asSet(DiscreteDomains.integers()), TerrainType.GRASS, borders); ts.addImage(loadImage("water", "coast-tropical-A01.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A02.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A03.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A04.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A05.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A06.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A07.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A08.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A09.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A10.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A11.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A12.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A13.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A14.png"), 0, 0, 0, 0); ts.addImage(loadImage("water", "coast-tropical-A15.png"), 0, 0, 0, 0); ts.defineTerrain(Ranges.closed(9, 23).asSet(DiscreteDomains.integers()), TerrainType.WATER, borders); ts.addImage(loadImage("sand", "desert.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert2.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert3.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert4.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert5.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert6.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert7.png"), 0, 0, 0, 0); ts.addImage(loadImage("sand", "desert8.png"), 0, 0, 0, 0); ts.defineTerrain(Ranges.closed(24, 31).asSet(DiscreteDomains.integers()), TerrainType.SAND, borders); ts.addImage(loadImage("forest", "forested-deciduous-summer-hills-tile.png"), 0, 0, 0, 0); ts.addImage(loadImage("forest", "forested-hills-tile.png"), 0, 0, 0, 0); ts.defineTerrain(Ranges.closed(32, 33).asSet(DiscreteDomains.integers()), TerrainType.FOREST, borders); ts.addImage(loadImage("hills", "regular.png"), 0, 0, 0, 0); ts.addImage(loadImage("hills", "regular2.png"), 0, 0, 0, 0); ts.addImage(loadImage("hills", "regular3.png"), 0, 0, 0, 0); ts.defineTerrain(Ranges.closed(34, 36).asSet(DiscreteDomains.integers()), TerrainType.MOUNTAIN, borders); ts.addImage(loadImage("grid.png"), 0, 0, 0, 0); ts.setGridTileIndex(37); return ts; }
From source file:org.kitesdk.examples.staging.GenerateSimpleLogs.java
@Override public int run(String[] args) throws Exception { // going to generate a lot of random log messages final Random rand = new Random(); // open the repository final DatasetRepository repo = DatasetRepositories.open("repo:file:/tmp/data"); // data is written to the staging dataset final Dataset<GenericRecord> staging = repo.load("logs_staging"); final DatasetWriter<GenericRecord> writer = staging.newWriter(); // this is going to build our simple log records final GenericRecordBuilder builder = new GenericRecordBuilder(staging.getDescriptor().getSchema()); // generate timestamps 1 second apart starting... now final Calendar now = Calendar.getInstance(); final long yesterday = now.getTimeInMillis() - DAY_IN_MILLIS; try {//from w w w . j a va 2s. c o m writer.open(); // generate 15,000 messages, each 5 seconds apart, starting 24 hours ago // this is a little less than 24 hours worth of messages for (int second : Ranges.closed(0, 15000).asSet(DiscreteDomains.integers())) { LOG.info("Generating log message " + second); builder.set("timestamp", yesterday + second * 5000); builder.set("component", "GenerateSimpleLogs"); int level = rand.nextInt(LOG_LEVELS.length); builder.set("level", LOG_LEVELS[level]); builder.set("message", LOG_MESSAGES[level]); writer.write(builder.build()); } } finally { writer.flush(); writer.close(); } return 0; }
From source file:com.cloudera.cdk.examples.staging.GenerateSimpleLogs.java
@Override public int run(String[] args) throws Exception { // going to generate a lot of random log messages final Random rand = new Random(); // open the repository final DatasetRepository repo = DatasetRepositories.open("repo:file:/tmp/data"); // data is written to the staging dataset final Dataset<GenericRecord> staging = repo.load("logs-staging"); final DatasetWriter<GenericRecord> writer = staging.newWriter(); // this is going to build our simple log records final GenericRecordBuilder builder = new GenericRecordBuilder(staging.getDescriptor().getSchema()); // generate timestamps 1 second apart starting... now final Calendar now = Calendar.getInstance(); final long yesterday = now.getTimeInMillis() - DAY_IN_MILLIS; try {/*from w w w. j a v a 2 s . c om*/ writer.open(); // generate 15,000 messages, each 5 seconds apart, starting 24 hours ago // this is a little less than 24 hours worth of messages for (int second : Ranges.closed(0, 15000).asSet(DiscreteDomains.integers())) { LOG.info("Generating log message " + second); builder.set("timestamp", yesterday + second * 5000); builder.set("component", "GenerateSimpleLogs"); int level = rand.nextInt(LOG_LEVELS.length); builder.set("level", LOG_LEVELS[level]); builder.set("message", LOG_MESSAGES[level]); writer.write(builder.build()); } } finally { writer.flush(); writer.close(); } return 0; }
From source file:com.github.fhirschmann.clozegen.gui.ClozeTestPane.java
/** * Toggles the gap at the current caret position on or off. */// w w w . j av a 2 s.c o m public void toggleGap() { Matcher matcher = IntermediateFormat.PATTERN.matcher(getText()); int pos = getCaretPosition(); while (matcher.find()) { if (Ranges.closed(matcher.start(), matcher.end()).contains(pos)) { if (matcher.group(3).equals("")) { setText(getText().substring(0, matcher.end()) + "d" + getText().substring(matcher.end())); } else { setText(getText().substring(0, matcher.end() - 1) + getText().substring(matcher.end())); } setCaretPosition(pos); update(); } } }
From source file:com.datatorrent.demos.mobile.ApplicationAlert.java
private void configure(DAG dag, Configuration conf) { dag.setAttribute(DAG.CONTAINERS_MAX_COUNT, 1); if (LAUNCHMODE_YARN.equals(conf.get(DAG.LAUNCH_MODE))) { // settings only affect distributed mode // settings only affect distributed mode AttributeMap attributes = dag.getAttributes(); if (attributes.get(DAGContext.CONTAINER_MEMORY_MB) == null) { attributes.put(DAGContext.CONTAINER_MEMORY_MB, 2048); }// w w w. ja v a 2s. c om if (attributes.get(DAGContext.MASTER_MEMORY_MB) == null) { attributes.put(DAGContext.MASTER_MEMORY_MB, 1024); } if (attributes.get(DAGContext.CONTAINERS_MAX_COUNT) == null) { attributes.put(DAGContext.CONTAINERS_MAX_COUNT, 1); } } else if (LAUNCHMODE_LOCAL.equals(conf.get(DAG.LAUNCH_MODE))) { } 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); }