List of usage examples for java.util Collections nCopies
public static <T> List<T> nCopies(int n, T o)
From source file:org.apache.flink.runtime.taskexecutor.slot.TaskSlotTableTest.java
/** * Tests that one can can mark allocated slots as active. *//*from w ww. jav a 2s . c o m*/ @Test public void testTryMarkSlotActive() throws SlotNotFoundException { final TaskSlotTable taskSlotTable = createTaskSlotTable(Collections.nCopies(3, ResourceProfile.UNKNOWN)); try { taskSlotTable.start(new TestingSlotActionsBuilder().build()); final JobID jobId1 = new JobID(); final AllocationID allocationId1 = new AllocationID(); taskSlotTable.allocateSlot(0, jobId1, allocationId1, SLOT_TIMEOUT); final AllocationID allocationId2 = new AllocationID(); taskSlotTable.allocateSlot(1, jobId1, allocationId2, SLOT_TIMEOUT); final AllocationID allocationId3 = new AllocationID(); final JobID jobId2 = new JobID(); taskSlotTable.allocateSlot(2, jobId2, allocationId3, SLOT_TIMEOUT); taskSlotTable.markSlotActive(allocationId1); assertThat(taskSlotTable.isAllocated(0, jobId1, allocationId1), is(true)); assertThat(taskSlotTable.isAllocated(1, jobId1, allocationId2), is(true)); assertThat(taskSlotTable.isAllocated(2, jobId2, allocationId3), is(true)); assertThat(IteratorUtils.toList(taskSlotTable.getActiveSlots(jobId1)), is(equalTo(Arrays.asList(allocationId1)))); assertThat(taskSlotTable.tryMarkSlotActive(jobId1, allocationId1), is(true)); assertThat(taskSlotTable.tryMarkSlotActive(jobId1, allocationId2), is(true)); assertThat(taskSlotTable.tryMarkSlotActive(jobId1, allocationId3), is(false)); assertThat(Sets.newHashSet(taskSlotTable.getActiveSlots(jobId1)), is(equalTo(new HashSet<>(Arrays.asList(allocationId2, allocationId1))))); } finally { taskSlotTable.stop(); } }
From source file:es.udc.gii.common.eaf.algorithm.population.multiobjective.MONSGA2Individual.java
public void translateObjective(int objective, double value) { if (translatedObjectives.isEmpty()) translatedObjectives = new ArrayList<Double>(Collections.nCopies(this.getObjectives().size(), 0.0)); translatedObjectives.set(objective, this.getObjectives().get(objective).doubleValue() - value); }
From source file:org.commonreality.participant.impl.RequestableEfferentObjectManager.java
/** * /* www. j a v a 2s . c om*/ */ public RequestableEfferentObjectManager(IParticipant participant) { _participant = participant; _delegate = new RequestableObjectManagerDelegate(participant, 5) { @Override protected Collection<? extends IIdentifier> createTemplates(Object key) { return Collections.nCopies(10, new BasicSensoryIdentifier("", IIdentifier.Type.EFFERENT, _participant.getIdentifier(), _participant.getIdentifier(), (IIdentifier) key)); } @Override protected Object getKey(IIdentifier freeIdentifier) { if (freeIdentifier.getType() != IIdentifier.Type.EFFERENT) return null; return ((ISensoryIdentifier) freeIdentifier).getAgent(); } }; }
From source file:org.commonreality.participant.impl.RequestableAfferentObjectManager.java
/** * /* w ww. j a v a 2s. c o m*/ */ public RequestableAfferentObjectManager(IParticipant participant) { _participant = participant; _delegate = new RequestableObjectManagerDelegate(participant, 5) { @Override protected Collection<? extends IIdentifier> createTemplates(Object key) { return Collections.nCopies(10, new BasicSensoryIdentifier("", IIdentifier.Type.AFFERENT, _participant.getIdentifier(), _participant.getIdentifier(), (IIdentifier) key)); } @Override protected Object getKey(IIdentifier freeIdentifier) { if (freeIdentifier.getType() != IIdentifier.Type.AFFERENT) return null; return ((ISensoryIdentifier) freeIdentifier).getAgent(); } }; }
From source file:org.apache.nifi.toolkit.cli.impl.result.writer.DynamicTableWriter.java
@Override public void write(final Table table, final PrintStream output) { if (table == null) { throw new IllegalArgumentException("Table cannot be null"); }/*from w w w . j a v a 2 s .co m*/ if (output == null) { throw new IllegalArgumentException("Output cannot be null"); } if (table.getColumns().isEmpty()) { throw new IllegalArgumentException("Table has no columns to write"); } output.println(); final List<TableColumn> columns = table.getColumns(); final List<String[]> rows = table.getRows(); final int numColumns = columns.size(); final Integer[] columnLengths = determineColumnLengths(columns, rows); final List<String> columnNames = columns.stream().map(c -> c.getName()).collect(Collectors.toList()); final Object[] columnLengthsObj = Arrays.copyOf(columnLengths, numColumns, Object[].class); final Object[] columnNamesObj = columnNames.toArray(new Object[numColumns]); final String columnsPatternFormat = String.join("", Collections.nCopies(numColumns, "%%-%ds ")); final String columnsPattern = String.format(columnsPatternFormat, columnLengthsObj); // format the header line which will include the column names final String header = String.format(columnsPattern, columnNamesObj); output.println(header); // a little clunky way to dynamically create a nice header line, but at least no external dependency final Object[] headerLineValues = new Object[numColumns]; for (int i = 0; i < numColumns; i++) { int length = columnLengths[i]; headerLineValues[i] = String.join("", Collections.nCopies(length, "-")); } final String headerLine = String.format(columnsPattern, headerLineValues); output.println(headerLine); // format the rows and print them for (String[] row : rows) { // convert the row to an Object[] for the String.format and also abbreviate any values final Object[] rowValues = new Object[row.length]; for (int i = 0; i < row.length; i++) { final TableColumn column = columns.get(i); if (column.isAbbreviated()) { rowValues[i] = StringUtils.abbreviate(row[i], columnLengths[i]); } else { rowValues[i] = row[i]; } } final String rowString = String.format(columnsPattern, rowValues); output.println(rowString); } output.println(); output.flush(); }
From source file:org.commonreality.participant.impl.RequestableRealObjectManager.java
/** * //ww w . j ava2 s . c om */ public RequestableRealObjectManager(IParticipant participant) { _participant = participant; _delegate = new RequestableObjectManagerDelegate(participant, 5) { @Override protected Collection<? extends IIdentifier> createTemplates(Object key) { return Collections.nCopies(10, new BasicIdentifier("", IIdentifier.Type.OBJECT, _participant.getIdentifier())); } @Override protected Object getKey(IIdentifier freeIdentifier) { if (freeIdentifier.getType() != IIdentifier.Type.OBJECT) return null; return _participant; } }; }
From source file:org.um.feri.ears.problems.unconstrained.ProblemB2.java
public ProblemB2() { super(2, 0);//from www .j av a2s . co m lowerLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, -50.0)); upperLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 50.0)); name = "B2 function"; }
From source file:org.um.feri.ears.problems.unconstrained.ProblemBranin.java
public ProblemBranin() { super(2, 0);// w w w . ja v a 2s . c o m lowerLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 0.0)); upperLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 0.0)); lowerLimit.set(0, -5.0); upperLimit.set(0, 10.0); lowerLimit.set(1, 0.0); //diff than in paper upperLimit.set(1, 15.0); name = "Branin function"; }
From source file:org.um.feri.ears.problems.unconstrained.ProblemBooth.java
public ProblemBooth() { super(2, 0);// www .j av a 2s.c om lowerLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, -50.0)); upperLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 50.0)); name = "Booth function"; }
From source file:org.um.feri.ears.problems.unconstrained.ProblemDeJong.java
public ProblemDeJong() { super(2, 0);/*from w w w . j a v a2 s. co m*/ lowerLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, -2.048)); upperLimit = new ArrayList<Double>(Collections.nCopies(numberOfDimensions, 2.048)); name = "De Jong"; this.minimum = false; //search maximum }