List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:org.apache.mina.util.CircularQueue.java
@Override public void clear() { if (!isEmpty()) { Arrays.fill(items, null); first = 0;//from ww w . ja v a 2s . com last = 0; full = false; shrinkIfNeeded(); } }
From source file:egat.cli.replicatordynamics.ReplicatorDynamicsCommandHandler.java
protected void processSymmetricGame(MutableSymmetricGame game) throws CommandProcessingException { try {// w ww .j a v a 2 s .co m PrintStream printStream = null; if (verbose) { printStream = System.err; } SymmetricReplicatorDynamics symmetricReplicatorDynamics = new SymmetricReplicatorDynamics(tolerance, maxIteration, printStream); Strategy strategy = symmetricReplicatorDynamics.run(game, null); Player[] players = game.players().toArray(new Player[0]); Strategy[] strategies = new Strategy[players.length]; Arrays.fill(strategies, strategy); ProfileWriter writer = new ProfileWriter(System.out); try { writer.write(Games.createProfile(players, strategies)); } catch (IOException e) { throw new CommandProcessingException(e); } } catch (NonexistentPayoffException e) { System.err.println(String.format("Could not calculate regret. %s", e.getMessage())); } }
From source file:com.cloudera.oryx.common.collection.LongFloatMap.java
/** * Creates a new {@code LongFloatMap} with given initial capacity. * * @param initialCapacity initial capacity *///from w w w. ja v a 2 s . c o m public LongFloatMap(int initialCapacity) { Preconditions.checkArgument(initialCapacity >= 0, "initialCapacity must be at least 0"); Preconditions.checkArgument(initialCapacity < MAX_SIZE, "initialCapacity must be less than " + MAX_SIZE); int hashSize = RandomUtils.nextTwinPrime((int) (LOAD_FACTOR * initialCapacity) + 1); keys = new long[hashSize]; Arrays.fill(keys, KEY_NULL); values = new float[hashSize]; Arrays.fill(values, VALUE_NULL); }
From source file:it.geosolutions.geostore.core.security.password.SecurityUtils.java
/** * Applies a permutation. /* w w w .jav a 2 s . c o m*/ * * @param base source array * @param times number of repetitions * @param perm the permutation */ public static char[] permute(char[] base, int times, int[] perm) { char[][] working = new char[2][base.length]; System.arraycopy(base, 0, working[0], 0, base.length); for (int j = 0; j < times; j++) { int source = j % 2; int target = (j + 1) % 2; for (int i = 0; i < working[source].length; i++) working[target][perm[i]] = working[source][i]; } char[] result = working[1].clone(); Arrays.fill(working[0], '0'); Arrays.fill(working[1], '0'); return result; }
From source file:model.LP.java
/** * Initializes a linear program./*from www. j a va 2s.c o m*/ * <p> * n being the number of variables and m being the number of constraints, * this {@code constructor} does the following: * <p><blockquote><pre> * B is set to the identity matrix of dimension m. * * The indices of the basic and non-basic variables are set to * 0..n-1 and n-1..n+m-1, respectively. * * The slack variables are called w1..wm. * </pre></blockquote<p> * * @param N * A {@code Matrix} with the coefficients * of the non-basic variables. * @param b * A {@code Matrix} with the upper bounds on * the constraints in the original program. * @param c * A {@code Matrix} with the coefficients of the * decision variables in the original program. * @param x * A {@code HashMap} mapping the indices of the * basic and non-basic variables to their names. */ public LP(FieldMatrix<BigFraction> N, FieldVector<BigFraction> b, FieldVector<BigFraction> c, HashMap<Integer, String> x) { this(null, N, b, c, null, N.copy(), b.copy(), c.mapMultiply(BigFraction.MINUS_ONE).copy(), x, new int[N.getRowDimension()], new int[N.getColumnDimension()]); /* Create an identity matrix of BigFraction's */ int m = N.getRowDimension(); BigFraction[][] Bd = new BigFraction[m][m]; for (int i = 0; i < m; i++) { Arrays.fill(Bd[i], BigFraction.ZERO); Bd[i][i] = BigFraction.ONE; } FieldMatrix<BigFraction> B = new Array2DRowFieldMatrix<BigFraction>(Bd); this.B = B; this.B_ = B.copy(); for (int i = 0; i < Ni.length; i++) Ni[i] = i; for (int i = 0; i < Bi.length; i++) { Bi[i] = i + Ni.length; x.put(Bi[i], "w" + (i + 1)); } }
From source file:components.PasswordDemo.java
/** * Checks the passed-in array against the correct password. * After this method returns, you should invoke eraseArray * on the passed-in array.//from w ww .ja va 2s . c o m */ private static boolean isPasswordCorrect(char[] input) { boolean isCorrect = true; char[] correctPassword = { 'b', 'u', 'g', 'a', 'b', 'o', 'o' }; if (input.length != correctPassword.length) { isCorrect = false; } else { isCorrect = Arrays.equals(input, correctPassword); } //Zero out the password. Arrays.fill(correctPassword, '0'); return isCorrect; }
From source file:edu.utah.further.core.api.collections.ArrayUtil.java
/** * @param size/*from w w w. j av a2 s .c o m*/ * @param fillValue * @return */ public static byte[] newByteVector(final int size, final byte fillValue) { final byte[] a = new byte[size]; Arrays.fill(a, fillValue); return a; }
From source file:com.kegare.caveworld.world.ChunkProviderDeepCaveworld.java
@Override public Chunk provideChunk(int chunkX, int chunkZ) { random.setSeed(chunkX * 341873128712L + chunkZ * 132897987541L); int worldHeight = worldObj.provider.getActualHeight(); BiomeGenBase biome = worldObj.getWorldChunkManager().getBiomeGenAt(chunkX * 16, chunkZ * 16); Block[] blocks = new Block[65536]; byte[] metadata = new byte[65536]; ICaveBiome entry = CaveworldAPI.getCaveBiome(biome); Block block = entry.getTerrainBlock().getBlock(); int meta = entry.getTerrainBlock().getMetadata(); Arrays.fill(blocks, block); Arrays.fill(metadata, (byte) meta); if (Config.generateDeepCaves) { caveGenerator.func_151539_a(this, worldObj, chunkX, chunkZ, blocks); }// ww w.jav a2 s . c om if (Config.generateUnderCaves) { underCaveGenerator.func_151539_a(this, worldObj, chunkX, chunkZ, blocks); } int i; boolean flag = random.nextInt(100) == 0; for (int x = 0; x < 16; ++x) { for (int z = 0; z < 16; ++z) { i = (x * 16 + z) * 256; blocks[i] = Blocks.bedrock; blocks[i + worldHeight - 1] = block; if (!entry.getTerrainBlock().equals(entry.getTopBlock())) { for (int y = 1; y < worldHeight - 2; ++y) { if (blocks[i + y] != null) { if (blocks[i + y + 1] == null) { blocks[i + y] = entry.getTopBlock().getBlock(); metadata[i + y] = (byte) entry.getTopBlock().getMetadata(); } else if (blocks[i + y - 1] == null && flag && random.nextInt(30) == 0) { blocks[i + y] = Blocks.web; metadata[i + y] = 0; } } } } for (int y = 255; y >= worldHeight; --y) { blocks[i + y] = null; } } } for (i = 0; meta != 0 && i < blocks.length; ++i) { if (blocks[i] != block) { metadata[i] = 0; } } Chunk chunk = new Chunk(worldObj, blocks, metadata, chunkX, chunkZ); byte[] biomes = new byte[256]; Arrays.fill(biomes, (byte) biome.biomeID); chunk.setBiomeArray(biomes); chunk.resetRelightChecks(); try { provideChunkTFC(chunk); } catch (NoSuchMethodError e) { } return chunk; }
From source file:com.github.lindenb.jvarkit.tools.misc.AddLinearIndexToBed.java
@Override public Collection<Throwable> call() throws Exception { if (refFile == null) { return wrapException("Reference file undefined"); }//from ww w . j a v a 2s . com PrintStream out = null; try { final List<String> args = this.getInputFiles(); this.dictionary = new SAMSequenceDictionaryFactory().load(refFile); this.tid2offset = new long[this.dictionary.size()]; Arrays.fill(this.tid2offset, 0L); for (int i = 1; i < this.dictionary.size(); ++i) { this.tid2offset[i] = this.tid2offset[i - 1] + this.dictionary.getSequence(i - 1).getSequenceLength(); } out = openFileOrStdoutAsPrintStream(); if (args.isEmpty()) { LOG.info("reading stdin"); doWork(stdin(), out); } else { for (final String arg : args) { LOG.info("opening " + arg); InputStream in = IOUtils.openURIForReading(arg); doWork(in, stdout()); CloserUtil.close(out); } } return RETURN_OK; } catch (Exception err) { return wrapException(err); } finally { CloserUtil.close(out); dictionary = null; tid2offset = null; } }
From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java
/** * Creates and returns an array of length {@code n} with all values set to {@code value}. * * @param value The value to be filled./*from w w w. java 2 s.c om*/ * @param n The desired length of the array. * @return An array of length {@code n} with all values set to {@code value} */ public static double[] repeat(double value, int n) { // Initialize the return array: double[] retval = new double[n]; // Fill the array: Arrays.fill(retval, value); // Done, return the filled array: return retval; }