Java Code Examples for java.util.Arrays#setAll()

The following examples show how to use java.util.Arrays#setAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaskedSource.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public static TLongSet affectedBlocks(final long[] gridDimensions, final int[] blockSize, final Interval...
		intervals)
{
	final TLongHashSet blocks              = new TLongHashSet();
	final int[]        ones                = IntStream.generate(() -> 1).limit(blockSize.length).toArray();
	final long[]       relevantIntervalMin = new long[blockSize.length];
	final long[]       relevantIntervalMax = new long[blockSize.length];
	for (final Interval interval : intervals)
	{
		Arrays.setAll(relevantIntervalMin, d -> (interval.min(d) / blockSize[d]));
		Arrays.setAll(relevantIntervalMax, d -> (interval.max(d) / blockSize[d]));
		Grids.forEachOffset(
				relevantIntervalMin,
				relevantIntervalMax,
				ones,
				offset -> blocks.add(IntervalIndexer.positionToIndex(offset, gridDimensions))
		                   );
	}

	return blocks;
}
 
Example 2
Source File: SetAllTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
Example 3
Source File: CompanionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void referenceChanged(ReferenceEvent<String> e)
{
	children.sort(Comparators.toStringIgnoreCaseCollator());
	int[] indexes = new int[getChildCount()];
	Arrays.setAll(indexes, i -> i);
	nodesChanged(this, indexes);
}
 
Example 4
Source File: SetAllTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "double")
public void testSetAllDouble(String name, int size, IntToDoubleFunction generator, double[] expected) {
    double[] result = new double[size];
    Arrays.setAll(result, generator);
    assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");

    // ensure fresh array
    result = new double[size];
    Arrays.parallelSetAll(result, generator);
    assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");
}
 
Example 5
Source File: SetAllTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
Example 6
Source File: SetAllTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
Example 7
Source File: S4WindowTinyLfuPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public S4WindowTinyLfuPolicy(double percentMain, S4WindowTinyLfuSettings settings) {
  String name = String.format("sketch.S4WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain));
  this.policyStats = new PolicyStats(name);
  this.admittor = new TinyLfu(settings.config(), policyStats);

  this.maximumSize = settings.maximumSize();
  this.maxMain = (int) (maximumSize * percentMain);
  this.maxWindow = maximumSize - maxMain;
  this.data = new Long2ObjectOpenHashMap<>();
  this.headWindow = Node.sentinel(-1);
  this.levels = settings.levels();
  this.sizeMainQ = new int[levels];
  this.headMainQ = new Node[levels];
  Arrays.setAll(headMainQ, Node::sentinel);
}
 
Example 8
Source File: Main.java    From Java-Coding-Problems with MIT License 5 votes vote down vote up
private static Map<String, Class<?>> fetchMissingGetters(Class<?> clazz) {        

        Map<String, Class<?>> getters = new HashMap<>();

        Field[] fields = clazz.getDeclaredFields();
        String[] names = new String[fields.length];
        Class<?>[] types = new Class<?>[fields.length];
        Arrays.setAll(names, i -> fields[i].getName());
        Arrays.setAll(types, i -> fields[i].getType());

        for (int i = 0; i < names.length; i++) {

            String getterAccessor = fetchIsOrGet(names[i], types[i]);

            try {
                Method getter = clazz.getDeclaredMethod(getterAccessor);
                Class<?> returnType = getter.getReturnType();

                if (!returnType.equals(types[i])
                        || getter.getParameterCount() != 0) {

                    getters.put(names[i], types[i]);
                }
            } catch (NoSuchMethodException ex) {
                getters.put(names[i], types[i]);
                // System.err.println("No getter found for '" + names[i] + "' field");
            }
        }

        return getters;
    }
 
Example 9
Source File: SetAllTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "int")
public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
    int[] result = new int[size];
    Arrays.setAll(result, generator);
    assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");

    // ensure fresh array
    result = new int[size];
    Arrays.parallelSetAll(result, generator);
    assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
}
 
Example 10
Source File: LocalDateArrayEncodingTest.java    From ndbc with Apache License 2.0 5 votes vote down vote up
public LocalDateArrayEncodingTest() {
  super(new LocalDateArrayEncoding(new LocalDateEncoding(UTF8), UTF8), Oid.DATE_ARRAY, LocalDateArrayValue.class,
      r -> {
        final LocalDate[] localDates = new LocalDate[r.nextInt(8)];
        Arrays.setAll(localDates, p -> randomLocalDateTime(r).toLocalDate());
        return new LocalDateArrayValue(localDates);
      }, (a, b) -> Assert.assertArrayEquals(a.get(), b.get()));
}
 
Example 11
Source File: DataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convenience method to extract the relative scale of two levels of a {@link Source} at time {@code t}.
 * @param source Extract relative scale from this source
 * @param t Extract relative scale at this time points
 * @param level source level
 * @param targetLevel target level
 * @return ratio of diagonals of transforms at levels {@code targetLevel} and {@code level} for {@code source} at time {@code t}:
 * scale[targetLevel] / scale[level]
 */
static double[] getRelativeScales(
		final Source<?> source,
		final int t,
		final int level,
		final int targetLevel)
{
	final double[] scale       = getScale(source, t, level);
	final double[] targetScale = getScale(source, t, targetLevel);
	Arrays.setAll(targetScale, d -> targetScale[d] / scale[d]);
	return targetScale;
}
 
Example 12
Source File: DoomStatus.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
/** MAES: this WAS NOT in the original. 
 *  Remember to call it!
 */
protected final void initNetGameStuff() {
    //this.netbuffer = new doomdata_t();
    this.doomcom = new doomcom_t();
    this.netcmds = new ticcmd_t[MAXPLAYERS][BACKUPTICS];

    Arrays.setAll(localcmds, i -> new ticcmd_t());
    for (int i = 0; i < MAXPLAYERS; i++) {
        Arrays.setAll(netcmds[i], j -> new ticcmd_t());
    }
}
 
Example 13
Source File: BooleanArrayEncodingTest.java    From ndbc with Apache License 2.0 5 votes vote down vote up
public BooleanArrayEncodingTest() {
  super(new BooleanArrayEncoding(new BooleanEncoding(UTF8), UTF8), Oid.BOOL_ARRAY, BooleanArrayValue.class, r -> {
    final Boolean[] booleans = new Boolean[r.nextInt(8)];
    Arrays.setAll(booleans, g -> r.nextBoolean());
    return new BooleanArrayValue(booleans);
  }, (a, b) -> Assert.assertArrayEquals(a.get(), b.get()));
}
 
Example 14
Source File: ExportDialog.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void refreshFiles()
{
	String outputSheetsDir;
	SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
	IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
	IOFileFilter prefixFilter;
	String defaultSheet = null;
	String outputSheetDirectory = SettingsHandler.getGameAsProperty().get().getOutputSheetDirectory();
	if (outputSheetDirectory == null)
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + sheetFilter.getPath();
	}
	else
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + outputSheetDirectory + "/"
			+ sheetFilter.getPath();
	}

	if (partyBox.isSelected())
	{
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.PARTY_TEMPLATE_PREFIX);
	}
	else
	{
		CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
		defaultSheet = character.getDefaultOutputSheet(sheetFilter == SheetFilter.PDF);
		if (StringUtils.isEmpty(defaultSheet))
		{
			defaultSheet = outputSheetsDir + "/"
				+ SettingsHandler.getGameAsProperty().get().getOutputSheetDefault(sheetFilter.getTag());
		}
	}
	IOFileFilter filter = FileFilterUtils.and(prefixFilter, ioFilter);
	List<File> files = FileFilterUtils.filterList(filter, allTemplates);
	Collections.sort(files);

	URI osPath = new File(outputSheetsDir).toURI();
	URI[] uriList = new URI[files.size()];
	Arrays.setAll(uriList, i -> osPath.relativize(files.get(i).toURI()));
	fileList.setListData(uriList);
	if (StringUtils.isNotEmpty(defaultSheet))
	{
		URI defaultPath = new File(defaultSheet).toURI();
		fileList.setSelectedValue(osPath.relativize(defaultPath), true);
	}
}
 
Example 15
Source File: TestPagesIndex.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Page somePage(List<Type> types)
{
    int[] initialValues = new int[types.size()];
    Arrays.setAll(initialValues, i -> 100 * i);
    return createSequencePage(types, 7, initialValues);
}
 
Example 16
Source File: IntersectingSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public <D extends IntegerType<D>, T extends Type<T>, B extends BooleanType<B>> IntersectingSourceState(
		final ThresholdingSourceState<?, ?> thresholded,
		final ConnectomicsLabelState<D, T> labels,
		final Composite<ARGBType, ARGBType> composite,
		final String name,
		final SharedQueue queue,
		final int priority,
		final Group meshesGroup,
		final ObjectProperty<ViewFrustum> viewFrustumProperty,
		final ObjectProperty<AffineTransform3D> eyeToWorldTransformProperty,
		final ObservableBooleanValue viewerEnabled,
		final ExecutorService manager,
		final HashPriorityQueueBasedTaskExecutor<MeshWorkerPriority> workers) {
	// TODO use better converter
	super(
			makeIntersect(thresholded, labels, queue, priority, name),
			new ARGBColorConverter.Imp0<>(0, 1),
			composite,
			name,
			// dependsOn:
			thresholded,
			labels);
	final DataSource<UnsignedByteType, VolatileUnsignedByteType> source = getDataSource();

	final MeshManagerWithAssignmentForSegments segmentMeshManager = labels.getMeshManager();

	this.labelsMeshesEnabledAndMeshesEnabled = Bindings.createBooleanBinding(
			() -> meshesEnabled.get() && segmentMeshManager.getManagedSettings().meshesEnabledProperty().get(),
			meshesEnabled,
			segmentMeshManager.getManagedSettings().meshesEnabledProperty());

	final BiFunction<TLongHashSet, Double, Converter<UnsignedByteType, BoolType>> getMaskGenerator = (l, minLabelRatio) -> (s, t) -> t.set(s.get() > 0);
	final SegmentMeshCacheLoader<UnsignedByteType>[] loaders = new SegmentMeshCacheLoader[getDataSource().getNumMipmapLevels()];
	Arrays.setAll(loaders, d -> new SegmentMeshCacheLoader<>(
			() -> getDataSource().getDataSource(0, d),
			getMaskGenerator,
			getDataSource().getSourceTransformCopy(0, d)));
	final GetMeshFor.FromCache<TLongHashSet> getMeshFor = GetMeshFor.FromCache.fromPairLoaders(loaders);

	this.fragmentsInSelectedSegments = new FragmentsInSelectedSegments(labels.getSelectedSegments());

	this.meshManager = new MeshManagerWithSingleMesh<>(
			source,
			getGetBlockListFor(segmentMeshManager.getLabelBlockLookup()),
			new WrappedGetMeshFromCache(getMeshFor),
			viewFrustumProperty,
			eyeToWorldTransformProperty,
			manager,
			workers,
			new MeshViewUpdateQueue<>());
	this.meshManager.viewerEnabledProperty().bind(viewerEnabled);
	final ObjectBinding<Color> colorProperty = Bindings.createObjectBinding(
			() -> Colors.toColor(this.converter().getColor()),
			this.converter().colorProperty());
	this.meshManager.colorProperty().bind(colorProperty);
	meshesGroup.getChildren().add(this.meshManager.getMeshesGroup());
	this.meshManager.getSettings().bindBidirectionalTo(segmentMeshManager.getSettings());
	this.meshManager.getRendererSettings().meshesEnabledProperty().bind(labelsMeshesEnabledAndMeshesEnabled);
	this.meshManager.getRendererSettings().blockSizeProperty().bind(segmentMeshManager.getRendererSettings().blockSizeProperty());
	this.meshManager.getRendererSettings().setShowBlockBounadries(false);
	this.meshManager.getRendererSettings().frameDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().frameDelayMsecProperty());
	this.meshManager.getRendererSettings().numElementsPerFrameProperty().bind(segmentMeshManager.getRendererSettings().numElementsPerFrameProperty());
	this.meshManager.getRendererSettings().sceneUpdateDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().sceneUpdateDelayMsecProperty());

	thresholded.getThreshold().minValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes(); });
	thresholded.getThreshold().maxValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes(); });

	fragmentsInSelectedSegments.addListener(obs -> refreshMeshes());
}
 
Example 17
Source File: BackpressureIntegrationTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static NumberProto.Number protoNum(int i) {
    Integer[] ints = new Integer[32 * 1024];
    Arrays.setAll(ints, operand -> i);

    return NumberProto.Number.newBuilder().addAllNumber(Arrays.asList(ints)).build();
}
 
Example 18
Source File: CommitCanvasN5Test.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static long[] divideBy(final long[] divident, final int[] divisor, final long minValue) {
	final long[] quotient = new long[divident.length];
	Arrays.setAll(quotient, d -> Math.max(divident[d] / divisor[d] + (divident[d] % divisor[d] == 0 ? 0 : 1), minValue));
	return quotient;
}
 
Example 19
Source File: AddressDivisionGroupingBase.java    From IPAddress with Apache License 2.0 4 votes vote down vote up
@Override
public String[] getDivisionStrings() {
	String result[] = new String[getDivisionCount()];
	Arrays.setAll(result, i -> getDivision(i).getWildcardString());
	return result;
}
 
Example 20
Source File: EncoderTest.java    From bt with Apache License 2.0 3 votes vote down vote up
@Test
public void testSorting() {
	Map<String, Object> root = new LinkedHashMap<>();
	
	String[] keys = new String[256];
	
	Arrays.setAll(keys, (i) -> buf2str(ByteBuffer.wrap(new byte[] {(byte) i})));
	// clone to shuffle independently of original order
	List<String> keyList = Arrays.asList(keys);
	List<String> shuffledKeys = Arrays.asList(keys.clone());
	Collections.shuffle(shuffledKeys);
	
	shuffledKeys.forEach(s -> root.put(s, 1L));
	
	BEncoder enc = new BEncoder();
	ByteBuffer out = enc.encode(root, 2048);
	
	StringBuilder reference = new StringBuilder();
	
	reference.append("d");
	
	keyList.forEach(str -> {
		reference.append("1:");
		reference.append(str);
		reference.append("i1e");
	});
	
	
	reference.append("e");
	
	
	
	assertEquals(str2buf(reference.toString()), out);
}