Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:org.powertac.samplebroker.PortfolioManagerTest.java

/**
 * Test customer boot data//  w w  w  . j  av a 2s  .com
 */
@Test
public void testCustomerBootstrap() {
    // set up a competition
    CustomerInfo podunk = new CustomerInfo("Podunk", 3);
    customerRepo.add(podunk);
    CustomerInfo midvale = new CustomerInfo("Midvale", 1000);
    customerRepo.add(midvale);
    // create a Timeslot for use by the bootstrap data
    Timeslot ts0 = new Timeslot(8 * 24, baseTime.plus(TimeService.DAY * 8));
    when(timeslotRepo.currentTimeslot()).thenReturn(ts0);
    // send to broker and check
    double[] podunkData = new double[7 * 24];
    Arrays.fill(podunkData, 3.6);
    double[] midvaleData = new double[7 * 24];
    Arrays.fill(midvaleData, 1600.0);
    CustomerBootstrapData boot = new CustomerBootstrapData(podunk, PowerType.CONSUMPTION, podunkData);
    portfolioManagerService.handleMessage(boot);
    boot = new CustomerBootstrapData(midvale, PowerType.CONSUMPTION, midvaleData);
    portfolioManagerService.handleMessage(boot);
    double[] podunkUsage = portfolioManagerService.getRawUsageForCustomer(podunk).get(PowerType.CONSUMPTION);
    assertNotNull("podunk usage is recorded", podunkUsage);
    assertEquals("correct usage value for podunk", 1.2, podunkUsage[23], 1e-6);
    double[] midvaleUsage = portfolioManagerService.getRawUsageForCustomer(midvale).get(PowerType.CONSUMPTION);
    assertNotNull("midvale usage is recorded", midvaleUsage);
    assertEquals("correct usage value for midvale", 1.6, midvaleUsage[27], 1e-6);
}

From source file:com.ichi2.libanki.Note.java

public Note(Collection col, JSONObject model, Long id) {
    assert !(model != null && id != null);
    mCol = col;//from w w w .j  a  v  a  2  s . c  o  m
    if (id != null) {
        mId = id;
        load();
    } else {
        mId = Utils.timestampID(mCol.getDb(), "notes");
        mGuId = Utils.guid64();
        mModel = model;
        try {
            mMid = model.getLong("id");
            mTags = new ArrayList<String>();
            mFields = new String[model.getJSONArray("flds").length()];
            Arrays.fill(mFields, "");
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        mFlags = 0;
        mData = "";
        mFMap = mCol.getModels().fieldMap(mModel);
        mScm = mCol.getScm();
    }
}

From source file:bftsmart.consensus.Round.java

/**
 * Creates a new instance of Round for acceptors
 * @param parent Execution to which this round belongs
 * @param number Number of the round/*w ww.j a va 2 s . c  om*/
 * @param timeout Timeout duration for this round
 */
public Round(ServerViewController controller, Execution parent, int number) {
    this.execution = parent;
    this.number = number;
    this.controller = controller;
    this.proof = new HashSet<PaxosMessage>();
    //ExecutionManager manager = execution.getManager();

    this.lastView = controller.getCurrentView();
    this.me = controller.getStaticConf().getProcessId();

    //int[] acceptors = manager.getAcceptors();
    int n = controller.getCurrentViewN();

    writeSetted = new boolean[n];
    acceptSetted = new boolean[n];

    Arrays.fill(writeSetted, false);
    Arrays.fill(acceptSetted, false);

    if (number == 0) {
        this.write = new byte[n][];
        this.accept = new byte[n][];

        Arrays.fill((Object[]) write, null);
        Arrays.fill((Object[]) accept, null);
    } else {
        Round previousRound = execution.getRound(number - 1, controller);

        this.write = previousRound.getWrite();
        this.accept = previousRound.getAccept();
    }
}

From source file:bftsmart.consensus.Epoch.java

/**
 * Creates a new instance of Epoch for acceptors
 * @param controller//w  w w. ja v a  2 s. c o m
 * @param parent Consensus to which this epoch belongs
 * @param timestamp Timestamp of the epoch
 */
public Epoch(ServerViewController controller, Consensus parent, int timestamp) {
    this.consensus = parent;
    this.timestamp = timestamp;
    this.controller = controller;
    this.proof = new HashSet<>();
    //ExecutionManager manager = consensus.getManager();

    this.lastView = controller.getCurrentView();
    this.me = controller.getStaticConf().getProcessId();

    //int[] acceptors = manager.getAcceptors();
    int n = controller.getCurrentViewN();

    writeSetted = new boolean[n];
    acceptSetted = new boolean[n];

    Arrays.fill(writeSetted, false);
    Arrays.fill(acceptSetted, false);

    if (timestamp == 0) {
        this.write = new byte[n][];
        this.accept = new byte[n][];

        Arrays.fill((Object[]) write, null);
        Arrays.fill((Object[]) accept, null);
    } else {
        Epoch previousEpoch = consensus.getEpoch(timestamp - 1, controller);

        this.write = previousEpoch.getWrite();
        this.accept = previousEpoch.getAccept();
    }
}

From source file:com.espertech.esper.epl.parse.ASTUtil.java

public static void dumpAST(PrintWriter printer, Tree ast, int ident) {
    char[] identChars = new char[ident];
    Arrays.fill(identChars, ' ');

    if (ast == null) {
        renderNode(identChars, null, printer);
        return;/*w  w  w .  jav a  2 s .c  o m*/
    }
    for (int i = 0; i < ast.getChildCount(); i++) {
        Tree node = ast.getChild(i);
        if (node == null) {
            throw new NullPointerException("Null AST node");
        }
        renderNode(identChars, node, printer);
        dumpAST(printer, node, ident + 2);
    }
}

From source file:au.com.jwatmuff.eventmanager.export.CSVExporter.java

public static void generatePlayerList(Database database, OutputStream out) {
    Collection<Player> players = database.findAll(Player.class, PlayerDAO.ALL);
    PrintStream ps = new PrintStream(out);

    Object[] columns = new Object[] { "id", "First Name", "Last Name", "Sex", "Grade", "DOB", "Team",
            "Home Number", "Work Number", "Mobile Number", "Street", "City", "Postcode", "State", "Email",
            "Emergency Name", "Emergency Phone", "Emergency Mobile", "Medical Conditions", "Medical Info",
            "Injury Info" };

    outputRow(columns, ps);//from   w w w. j  ava2  s  .  com

    for (Player player : players) {
        Object[] fields1 = new Object[] { player.getVisibleID(), player.getFirstName(), player.getLastName(),
                player.getGender(), player.getGrade(), dateFormat.format(player.getDob()), player.getTeam() };

        PlayerDetails details = database.get(PlayerDetails.class, player.getDetailsID());
        Object[] fields2;
        if (details != null) {
            fields2 = new Object[] { details.getHomeNumber(), details.getWorkNumber(),
                    details.getMobileNumber(), details.getStreet(), details.getCity(), details.getPostcode(),
                    details.getState(), details.getEmail(), details.getEmergencyName(),
                    details.getEmergencyPhone(), details.getEmergencyMobile(), details.getMedicalConditions(),
                    details.getMedicalInfo(), details.getInjuryInfo() };
        } else {
            fields2 = new Object[14];
            Arrays.fill(fields2, null);
        }

        outputRow(ArrayUtils.addAll(fields1, fields2), ps);
    }
}

From source file:ch.cyberduck.cli.TerminalLoginCallback.java

@Override
public Credentials prompt(final Host bookmark, final String username, final String title, final String reason,
        final LoginOptions options) throws LoginCanceledException {
    console.printf("%n%s", new StringAppender().append(title).append(reason));
    try {// w w w .jav a  2s  .  c om
        final Credentials credentials = new Credentials(username);
        if (options.user) {
            if (StringUtils.isBlank(credentials.getUsername())) {
                final String user = console.readLine("%n%s: ", options.getUsernamePlaceholder());
                credentials.setUsername(user);
            } else {
                final String user = console.readLine("%n%s (%s): ", options.getUsernamePlaceholder(),
                        credentials.getUsername());
                if (StringUtils.isNotBlank(user)) {
                    credentials.setUsername(user);
                }
            }
            console.printf("Login as %s", credentials.getUsername());
        }
        if (options.password) {
            final char[] input = console.readPassword("%n%s: ", options.getPasswordPlaceholder());
            credentials.setPassword(String.valueOf(input));
            Arrays.fill(input, ' ');
        }
        return credentials;
    } catch (ConnectionCanceledException e) {
        throw new LoginCanceledException(e);
    }
}

From source file:com.almende.eve.algorithms.DAAValueBean.java

/**
 * Generate the random array to represent this value;.
 *
 * @param value//from   w  w w. j a  v a 2s. co  m
 *            the value
 * @return the value bean
 */
public DAAValueBean generate(final double value) {
    if (value <= 0.0) {
        Arrays.fill(valueArray, Double.MAX_VALUE);
    } else {
        for (int i = 0; i < width; i++) {
            Double expRand = -Math.log(Math.random()) / value;
            valueArray[i] = expRand;
        }
        // Noise cancelation:
        final Double mean = computeMean();
        final Double goal = 1.0 / value;
        offset = goal / mean;
        for (int i = 0; i < width; i++) {
            valueArray[i] = valueArray[i] * offset;
        }
    }
    return this;
}

From source file:com.example.android.vault.EncryptedDocumentTest.java

public void testGiantMetadataAndContents() throws Exception {
    // try with content size of prime number >1MB
    final byte[] content = new byte[1298047];
    Arrays.fill(content, (byte) 0x42);
    testMetadataAndContents(content);/*from w w w .j a  va 2 s . c  om*/
}

From source file:com.albert.util.StringUtilCommon.java

/**
 * Left pad string with char c.//from w w w. ja  v a  2 s. co  m
 * 
 * @param s
 * @param n
 * @param c
 * @return String
 */
public static String lPad(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.insert(0, ch);

    return str.toString();
}