List of usage examples for java.util Collections nCopies
public static <T> List<T> nCopies(int n, T o)
From source file:org.um.feri.ears.problems.constrained.TLBOBenchmarkFunction1.java
public TLBOBenchmarkFunction1() { super(13, 9); minimum = true;//from w w w . j av a2 s . c om max_constraints = new Double[numberOfConstraints]; min_constraints = new Double[numberOfConstraints]; count_constraints = new Double[numberOfConstraints]; sum_constraints = new Double[numberOfConstraints]; normalization_constraints_factor = new Double[numberOfConstraints]; upperLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 0.0)); lowerLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 0.0)); for (int i = 0; i < 9; i++) { lowerLimit.set(i, 0.0); upperLimit.set(i, 1.0); } for (int i = 9; i < 12; i++) { lowerLimit.set(i, 0.0); upperLimit.set(i, 100.0); } lowerLimit.set(12, 0.0); upperLimit.set(12, 1.0); name = "TLBOBenchmarkFunction1 (TP7) cec-g01"; // System.out.println(Arrays.toString(interval)+"\n"+Arrays.toString(intervalL)); }
From source file:com.github.rinde.rinsim.pdptw.common.WrappedGraphUITest.java
/** * Tests that {@link GraphRoadModelRenderer} can render a * {@link PDPGraphRoadModel}.//from w w w .jav a 2 s . c om */ @Test public void test() { final Graph<LengthData> g = new TableGraph<>(); Graphs.addBiPath(g, N, NE, E, SE, S, SW, W, NW, N); Graphs.addBiPath(g, N, C, S); Graphs.addBiPath(g, NE, C, SW); Graphs.addBiPath(g, NW, C, SE); Graphs.addBiPath(g, E, C, W); final Scenario.Builder b = Scenario.builder() .addModel(PDPGraphRoadModel.builderForGraphRm(RoadModelBuilders.staticGraph(g))) .addModel(DefaultPDPModel.builder()).addEvents(Collections.nCopies(10, AddVehicleEvent.create(-1, VehicleDTO.builder().startPosition(C).build()))); final int endTime = 3 * 60 * 60 * 1000; final RandomGenerator rng = new MersenneTwister(123); for (int i = 0; i < 20; i++) { final long announceTime = rng.nextInt(DoubleMath.roundToInt(endTime * .8, RoundingMode.FLOOR)); b.addEvent(AddParcelEvent.create(Parcel.builder(g.getRandomNode(rng), g.getRandomNode(rng)) .orderAnnounceTime(announceTime).pickupTimeWindow(TimeWindow.create(announceTime, endTime)) .deliveryTimeWindow(TimeWindow.create(announceTime, endTime)).neededCapacity(0).buildDTO())); } b.addEvent(TimeOutEvent.create(endTime)).scenarioLength(endTime) .setStopCondition(StopConditions.limitedTime(endTime)); final Simulator sim = Simulator.builder() .addModel(ScenarioController.builder(b.build()) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler()) .withEventHandler(TimeOutEvent.class, TimeOutEvent.ignoreHandler()) .withEventHandler(AddVehicleEvent.class, new TimedEventHandler<AddVehicleEvent>() { @Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI simulator) { simulator.register(new RandomVehicle(event.getVehicleDTO())); } })) .addModel(View.builder().withTitleAppendix("Wrapped GraphRoadModel UI test") .with(GraphRoadModelRenderer.builder().withMargin(1)).with(RoadUserRenderer.builder()) .withSimulatorEndTime(30 * 1000).withAutoPlay().withAutoClose()) .build(); sim.start(); }
From source file:net.sf.jabref.logic.util.io.FileUtil.java
/** * Creates the minimal unique path substring for each file among multiple file paths. * * @param paths the file paths//from ww w . ja va 2s. c o m * @return the minimal unique path substring for each file path */ public static List<String> uniquePathSubstrings(List<String> paths) { List<Stack<String>> stackList = new ArrayList<>(paths.size()); // prepare data structures for (String path : paths) { List<String> directories = Arrays.asList(path.split(Pattern.quote(File.separator))); Stack<String> stack = new Stack<>(); stack.addAll(directories); stackList.add(stack); } List<String> pathSubstrings = new ArrayList<>(Collections.nCopies(paths.size(), "")); // compute shortest folder substrings while (!stackList.stream().allMatch(Vector::isEmpty)) { for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (tempString.isEmpty() && !stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop()); } else if (!stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop() + File.separator + tempString); } } for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (Collections.frequency(pathSubstrings, tempString) == 1) { stackList.get(i).clear(); } } } return pathSubstrings; }
From source file:Transform.java
private static String relative(String path) { return StringUtils.join(Collections.nCopies(path.split("/").length, ".."), "/") + "/"; }
From source file:com.syncnapsis.data.model.MessengerContact.java
@Transient @Override public List<User> getOwners() { return Collections.nCopies(1, getUser()); }
From source file:edu.stanford.slac.archiverappliance.PB.data.LargePBLineTest.java
@Test public void testLargeLines() throws Exception { // We create vector doubles with a large number of elements; write it out and then test the read. String pvName = ConfigServiceForTests.ARCH_UNIT_TEST_PVNAME_PREFIX + "LargeLineTest" + largeLineTest.getPartitionGranularity(); ArchDBRTypes type = ArchDBRTypes.DBR_WAVEFORM_DOUBLE; short year = TimeUtils.getCurrentYear(); for (int i = 1; i < 7200; i++) { try (BasicContext context = new BasicContext()) { ArrayListEventStream strm = new ArrayListEventStream(1024, new RemotableEventStreamDesc(type, pvName, year)); DBR_TIME_Double retvd = new DBR_TIME_Double(ArrayUtils .toPrimitive(Collections.nCopies(i, Math.sin(i * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(new gov.aps.jca.dbr.TimeStamp(TimeUtils.getStartOfCurrentYearInSeconds() + i)); retvd.setSeverity(1);//from ww w . j a v a2s . c o m retvd.setStatus(0); strm.add(new PBVectorDouble(retvd)); largeLineTest.appendData(context, pvName, strm); } catch (Exception ex) { logger.error("Exception appending data " + i, ex); fail(ex.getMessage()); } } Path[] allPaths = PlainPBPathNameUtility.getAllPathsForPV(new ArchPaths(), largeLineTest.getRootFolder(), pvName, ".pb", largeLineTest.getPartitionGranularity(), CompressionMode.NONE, configService.getPVNameToKeyConverter()); assertTrue("testLargeLines returns null for getAllFilesForPV for " + pvName, allPaths != null); assertTrue("testLargeLines returns empty array for getAllFilesForPV for " + pvName, allPaths.length > 0); for (Path destPath : allPaths) { try { PBFileInfo info = new PBFileInfo(destPath); info.getLastEventEpochSeconds(); assertTrue("File validation failed for " + destPath.toAbsolutePath().toString(), ValidatePBFile.validatePBFile(destPath, false)); } catch (Exception ex) { logger.error("Exception parsing file" + destPath.toAbsolutePath().toString(), ex); fail(ex.getMessage()); } } }
From source file:org.deeplearning4j.examples.StackSequenceRecordReader.java
@Override public List<Writable> next() { featureMasks = new ArrayList<Double>(Collections.nCopies(timeSteps.size(), 0.0)); labelMasks = new ArrayList<Double>(Collections.nCopies(timeSteps.size(), 0.0)); List<Writable> writable = new ArrayList<Writable>(); List<Path> paths = sequenceStack.pop(); DataInputStream in = null;//from w ww . ja va 2 s .com for (Path p : paths) { try { in = fs.open(p); URI uri = p.toUri(); String pathParts[] = uri.toString().split("_"); String currStep = pathParts == null || pathParts.length < 3 ? "" : pathParts[2]; int index = timeSteps.indexOf(currStep); index = index < 0 ? timeSteps.size() - 1 : index; List<String> seq = new ArrayList<String>(); List<List<Writable>> steps = csvRecordReader.sequenceRecord(uri, in); if (!CollectionUtils.isEmpty(steps)) { for (List<Writable> instance : steps) { if (timeIndex >= 1 && timeIndex <= instance.size()) { seq.add(instance.get(timeIndex - 1).toString()); if (timeIndex - 1 > 0) writable.addAll(instance.subList(0, timeIndex - 1)); writable.addAll(instance.subList(timeIndex, instance.size())); } else { writable.addAll(instance); } } if (!seq.isEmpty()) { String maxIndex = seq.get(0); for (int i = 0; i < seq.size(); i++) { if (Integer.parseInt(seq.get(i)) > Integer.parseInt(maxIndex)) maxIndex = seq.get(i); featureMasks.set(timeSteps.indexOf(seq.get(i)), 1.0); } labelMasks.set(timeSteps.indexOf(maxIndex), timeSteps.get(timeSteps.size() - 1) == maxIndex || paths.size() == 1 ? 1.0 : 0.0); } else { featureMasks.set(index, 1.0); labelMasks.set(index, timeSteps.get(timeSteps.size() - 1) == currStep || paths.size() == 1 ? 1.0 : 0.0); } } } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); } finally { if (in != null) { IOUtils.closeQuietly(in); } } } return writable; }
From source file:storm.lrb.bolt.LastAverageSpeedBolt.java
@Override public void execute(Tuple tuple) { int minuteOfTuple = tuple.getIntegerByField(TopologyControl.MINUTE_FIELD_NAME); int xway = tuple.getIntegerByField(TopologyControl.XWAY_FIELD_NAME); int seg = tuple.getIntegerByField(TopologyControl.SEGMENT_FIELD_NAME); int dir = tuple.getIntegerByField(TopologyControl.DIRECTION_FIELD_NAME); int carcnt = tuple.getIntegerByField(TopologyControl.CAR_COUNT_FIELD_NAME); double avgs = tuple.getDoubleByField(TopologyControl.AVERAGE_SPEED_FIELD_NAME); Triple<Integer, Integer, Integer> segmentKey = new MutableTriple<Integer, Integer, Integer>(xway, seg, dir); List<Double> latestAvgSpeeds = this.listOfavgs.get(segmentKey); List<Integer> latestCarCnt = this.listOfVehicleCounts.get(segmentKey); if (latestAvgSpeeds == null) { // initialize the list for the full time so we can use the indices to keep track of time/speed latestAvgSpeeds = new ArrayList<Double>(Collections.nCopies(TOTAL_MINS, 0.0));// new ArrayList<Double>(); this.listOfavgs.put(segmentKey, latestAvgSpeeds); }/*from www. j a v a2s . c om*/ latestAvgSpeeds.add(minuteOfTuple, avgs); if (latestCarCnt == null) { latestCarCnt = new ArrayList<Integer>(Collections.nCopies(TOTAL_MINS, 0)); this.listOfVehicleCounts.put(segmentKey, latestCarCnt); } latestCarCnt.add(minuteOfTuple, carcnt); this.emitLav(segmentKey, latestCarCnt, latestAvgSpeeds, minuteOfTuple); this.collector.ack(tuple); }
From source file:io.hops.experiments.benchmarks.blockreporting.TinyDatanode.java
TinyDatanode(BlockReportingNameNodeSelector nameNodeSelector, int dnIdx, int blockCapacity) throws IOException { this.dnIdx = dnIdx; this.blocks = new ArrayList<Block>(Collections.nCopies(blockCapacity, (Block) null)); this.nrBlocks = 0; this.nameNodeSelector = nameNodeSelector; }
From source file:org.jtalks.jcommune.service.transactional.TransactionalTopicFetchServiceTest.java
@Test public void testGetAllTopicsPastLastDay() throws NotFoundException { String pageNumber = "1"; int pageSize = 20; List<Topic> expectedList = Collections.nCopies(2, new Topic(user, "title")); Page<Topic> expectedPage = new PageImpl<>(expectedList); when(topicDao.getTopicsUpdatedSince(Matchers.<DateTime>any(), Matchers.<PageRequest>any(), eq(user))) .thenReturn(expectedPage);//from ww w. ja va 2 s .c om user.setPageSize(pageSize); when(userService.getCurrentUser()).thenReturn(user); Page<Topic> actualPage = topicFetchService.getRecentTopics(pageNumber); assertNotNull(actualPage); assertEquals(expectedPage, actualPage); verify(topicDao).getTopicsUpdatedSince(Matchers.<DateTime>any(), Matchers.<PageRequest>any(), eq(user)); }