List of usage examples for java.util Arrays fill
public static void fill(Object[] a, Object val)
From source file:bftsmart.paxosatwar.executionmanager.Round.java
/** * Creates a new instance of Round for acceptors * @param parent Execution to which this round belongs * @param number Number of the round//from ww w .j a va2s. c o m * @param timeout Timeout duration for this round */ protected Round(ServerViewManager manager, Execution parent, int number) { this.execution = parent; this.number = number; this.manager = manager; this.proof = new HashSet<PaxosMessage>(); //ExecutionManager manager = execution.getManager(); this.lastView = manager.getCurrentView(); this.me = manager.getStaticConf().getProcessId(); //int[] acceptors = manager.getAcceptors(); int n = manager.getCurrentViewN(); weakSetted = new boolean[n]; strongSetted = new boolean[n]; Arrays.fill(weakSetted, false); Arrays.fill(strongSetted, false); if (number == 0) { this.weak = new byte[n][]; this.strong = new byte[n][]; Arrays.fill((Object[]) weak, null); Arrays.fill((Object[]) strong, null); } else { Round previousRound = execution.getRound(number - 1, manager); this.weak = previousRound.getWeak(); this.strong = previousRound.getStrong(); } }
From source file:jp.gr.java_conf.ka_ka_xyz.processor.AnnotationProcessor.java
@Override protected int[] mapColumnsToProperties(ResultSetMetaData rsmd, PropertyDescriptor[] props) throws SQLException { int cols = rsmd.getColumnCount(); int columnToProperty[] = new int[cols + 1]; Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND); for (int col = 1; col <= cols; col++) { String columnName = rsmd.getColumnLabel(col); for (int i = 0; i < props.length; i++) { if (equalsColumnAnnotation(columnName, props[i].getName())) { columnToProperty[col] = i; break; }/*from www . j av a 2 s . co m*/ } } return columnToProperty; }
From source file:com.amazonaws.services.kinesis.clientlibrary.lib.worker.ExceptionThrowingLeaseManager.java
/** * Reset all parameters used for throwing exception. *//*from w w w . ja va2 s . c o m*/ void clearLeaseManagerThrowingExceptionScenario() { Arrays.fill(leaseManagerMethodCallingCount, 0); this.methodThrowingException = ExceptionThrowingLeaseManagerMethods.NONE; this.timeThrowingException = Integer.MAX_VALUE; }
From source file:com.blackducksoftware.integration.hub.bamboo.config.HubServerConfigSerializable.java
public static String getMaskedString(final int length) { if (length == 0) { return null; }//from w w w .j a v a 2 s . c o m final char[] array = new char[length]; Arrays.fill(array, '*'); return new String(array); }
From source file:components.PasswordDemo.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (OK.equals(cmd)) { //Process the password. char[] input = passwordField.getPassword(); if (isPasswordCorrect(input)) { JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password."); } else {/*from www. j av a2s . com*/ JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message", JOptionPane.ERROR_MESSAGE); } //Zero out the possible password, for security. Arrays.fill(input, '0'); passwordField.selectAll(); resetFocus(); } else { //The user has asked for help. JOptionPane.showMessageDialog(controllingFrame, "You can get the password by searching this example's\n" + "source code for the string \"correctPassword\".\n" + "Or look at the section How to Use Password Fields in\n" + "the components section of The Java Tutorial."); } }
From source file:com.unister.semweb.drums.bucket.hashfunction.RangeHashFunction.java
/** * This constructor instantiates a new {@link RangeHashFunction} with the given number of ranges. It tries to size * all ranges equally within the complete available space of numbers. * /*from w w w . j av a2 s .co m*/ * @param ranges * the number of ranges * @param keySize * the size in bytes of the key * @param hashFunctionFilename * the filename of the file, where to store the hash-function */ public RangeHashFunction(int ranges, int keySize, String hashFunctionFilename) { this.hashFunctionFile = hashFunctionFilename; this.buckets = ranges; byte[] max = new byte[keySize], min = new byte[keySize]; Arrays.fill(max, (byte) -1); this.initHashFunction(min, max, ranges); }
From source file:altermarkive.uploader.Config.java
@SuppressWarnings("unused") public int[] initiate(int[] types, String[] vendors, String[] names, int[] delays, float[] resolutions, int[] sizes) { SparseIntArray indices = new SparseIntArray(); for (int i = MIN_TYPE; i <= MAX_TYPE; i++) { indices.put(i, 0);// w w w. j a v a 2 s . co m } int[] periods = new int[types.length]; Arrays.fill(periods, 0); for (int i = 0; i < types.length; i++) { String identifier = String.format("%d, %s, %s", types[i], vendors[i], names[i]); if (types[i] < MIN_TYPE || MAX_TYPE < types[i] || sizes[i] == 0) { String message = String.format("Ignored sensor: %s", identifier); Log.i(TAG, message); continue; } // Find the period and update sensor index int index = indices.get(types[i]); periods[i] = sampling(types[i], index); indices.put(types[i], index + 1); // Update the name of the sensor naming(types[i], index, names[i]); // Clip period based on minimum delay reported if (0 < periods[i]) { periods[i] = Math.max(periods[i], delays[i] / 1000); String message = String.format("The period for sensor #%d (%s) is %d", i, identifier, periods[i]); Log.i(TAG, message); } } sampler.data().initiate(sizes, periods, storing()); try { String report = Report.report(sampler.context(), types, vendors, names, resolutions, delays, null, null); Storage.writeText("device.json", report); } catch (JSONException exception) { String trace = Log.getStackTraceString(exception); String message = String.format("Failed to report on device specification:\n%s", trace); Log.e(TAG, message); } return periods; }
From source file:com.opengamma.analytics.math.statistics.leastsquare.NonLinearLeastSquare.java
/** * Use this when the model is in the ParameterizedFunction form and analytic parameter sensitivity is not available * @param x Set of measurement points// www .j av a 2 s . c o m * @param y Set of measurement values * @param func The model in ParameterizedFunction form (i.e. takes measurement points and a set of parameters and returns a model value) * @param startPos Initial value of the parameters * @return A LeastSquareResults object */ public LeastSquareResults solve(final DoubleMatrix1D x, final DoubleMatrix1D y, final ParameterizedFunction<Double, DoubleMatrix1D, Double> func, final DoubleMatrix1D startPos) { Validate.notNull(x, "x"); Validate.notNull(y, "y"); final int n = x.getNumberOfElements(); Validate.isTrue(y.getNumberOfElements() == n, "y wrong length"); final double[] sigmas = new double[n]; Arrays.fill(sigmas, 1); //emcleod 31-1-2011 arbitrary value for now return solve(x, y, new DoubleMatrix1D(sigmas), func, startPos); }
From source file:com.netflix.imfutility.ttmltostl.stl.StlGsiTest.java
@Test public void testGsiAll() throws Exception { TimedTextObject tto = StlTestUtil.buildTto("10:00:15:10", "10:00:16:00", "text1", "10:00:16:00", "10:00:17:00", "text2", "10:00:17:00", "10:01:20:00", "text3"); byte[][] stl = StlTestUtil.build(tto, StlTestUtil.getMetadataXml()); byte[] gsi = stl[0]; assertArrayEquals(new byte[] { 0x38, 0x35, 0x30, // 850 0x53, 0x54, 0x4c, 0x32, 0x35, 0x2e, 0x30, 0x31, // STL25.01 0x31, // 1 - teletext 0x30, 0x30, // 00 - latin 0x30, 0x39 // 09 - English }, Arrays.copyOfRange(gsi, 0, 16)); assertArrayEquals(new byte[] { 0x50, 0x72, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x6d, 0x65, // 'Programme' as in metadata.xml 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Arrays.copyOfRange(gsi, 16, 48)); assertArrayEquals(new byte[] { 0x45, 0x70, 0x69, 0x73, 0x6f, 0x64, 0x65, // 'Episode' as in metadata.xml 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Arrays.copyOfRange(gsi, 48, 80)); byte[] translated = new byte[128]; Arrays.fill(translated, (byte) 0x20); assertArrayEquals(translated, Arrays.copyOfRange(gsi, 80, 208)); byte[] slr = new byte[16]; Arrays.fill(slr, (byte) 0x20); assertArrayEquals(slr, Arrays.copyOfRange(gsi, 208, 224)); assertArrayEquals(new byte[] { 0x31, 0x36, 0x30, 0x37, 0x30, 0x38 // creation date as in metadata.xml: }, Arrays.copyOfRange(gsi, 224, 230)); assertArrayEquals(new byte[] { 0x31, 0x36, 0x30, 0x37, 0x30, 0x38 // revision date as in metadata.xml: }, Arrays.copyOfRange(gsi, 230, 236)); assertArrayEquals(new byte[] { 0x30, 0x31 // revision number = 01 }, Arrays.copyOfRange(gsi, 236, 238)); assertArrayEquals(new byte[] { 0x30, 0x30, 0x30, 0x30, 0x34 // number of tti blocks - 3 + subtitle zero = 4 }, Arrays.copyOfRange(gsi, 238, 243)); assertArrayEquals(new byte[] { 0x30, 0x30, 0x30, 0x30, 0x34 // number of subtitles - 3 + subtitle zero = 4 }, Arrays.copyOfRange(gsi, 243, 248)); assertArrayEquals(new byte[] { 0x30, 0x30, 0x31 // number of subtitle groups - 1 }, Arrays.copyOfRange(gsi, 248, 251)); assertArrayEquals(new byte[] { 0x35, 0x38 // number of displayable chars - 58 }, Arrays.copyOfRange(gsi, 251, 253)); assertArrayEquals(new byte[] { 0x31, 0x31 // number of displayable rows - 11 }, Arrays.copyOfRange(gsi, 253, 255)); assertArrayEquals(new byte[] { 0x31 // tc status - 1 }, Arrays.copyOfRange(gsi, 255, 256)); assertArrayEquals(new byte[] { 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x30 // start time of program: 10:00:00:20 (as in metadata.xml) }, Arrays.copyOfRange(gsi, 256, 264)); assertArrayEquals(new byte[] { 0x31, 0x30, 0x30, 0x30, 0x31, 0x35, 0x31, 0x30 // start time of subtitles: 10:00:15:10 (as in metadata.xml) }, Arrays.copyOfRange(gsi, 264, 272)); assertArrayEquals(new byte[] { 0x31 // number of disks - 1 }, Arrays.copyOfRange(gsi, 272, 273)); assertArrayEquals(new byte[] { 0x31 // disk seq number - 1 }, Arrays.copyOfRange(gsi, 273, 274)); assertArrayEquals(new byte[] { 0x47, 0x42, 0x52 // country - GBR }, Arrays.copyOfRange(gsi, 274, 277)); assertArrayEquals(new byte[] { 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x6f, 0x72, // Publisher: Originator (as in metadata.xml) 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Arrays.copyOfRange(gsi, 277, 309)); assertArrayEquals(new byte[] { 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, // Editor: Distributor (as in metadata.xml) 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Arrays.copyOfRange(gsi, 309, 341)); assertArrayEquals(new byte[] { 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x40, // Contact: account@myemail.com (as in metadata.xml) 0x6d, 0x79, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Arrays.copyOfRange(gsi, 341, 373)); byte[] spare = new byte[651]; Arrays.fill(spare, (byte) 0x20); assertArrayEquals(spare, Arrays.copyOfRange(gsi, 373, 1024)); }
From source file:com.albert.util.StringUtilCommon.java
/** * right pad string with char c.//from w w w .ja v a 2s .c o m * * @param s * @param n * @param c * @return String */ public static String rPad(String s, int n, char c) { if (s == null) { return s; } int add = n - s.length(); if (add <= 0) { return s; } StringBuffer str = new StringBuffer(s); char[] ch = new char[add]; Arrays.fill(ch, c); str.append(ch); return str.toString(); }