Java Code Examples for java.util.Collections#fill()

The following examples show how to use java.util.Collections#fill() . 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: ReplaceAllElementsOfArrayListExample.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    //create a ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to ArrayList
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("D");

/*
  To replace all elements of Java ArrayList with specified element use,
  static void fill(List list, Object element) method of Collections class.
*/

    System.out.println("Before replacement, ArrayList contains : " + arrayList);

    Collections.fill(arrayList, "REPLACED");

    System.out.println("After replacement, ArrayList contains : " + arrayList);
}
 
Example 2
Source File: ReplaceAllElementsOfVectorExample.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("A");
    v.add("B");
    v.add("D");

/*
  To replace all elements of Java Vector with specified element use,
  static void fill(List list, Object element) method of Collections class.
*/

    System.out.println("Before replacement, Vector contains : " + v);

    Collections.fill(v, "REPLACED");

    System.out.println("After replacement, Vector contains : " + v);
}
 
Example 3
Source File: StackMoveOptimizationPhase.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void replaceStackMoves(List<LIRInstruction> instructions) {
    int size = dst.size();
    if (size > 1) {
        AMD64MultiStackMove multiMove = new AMD64MultiStackMove(dst.toArray(new AllocatableValue[size]), src.toArray(new AllocatableValue[size]), reg, slot);
        // replace first instruction
        instructions.set(begin, multiMove);
        // and null out others
        Collections.fill(instructions.subList(begin + 1, begin + size), null);
        // removed
        removed = true;
        eliminatedBackup.add(size - 1);
    }
    // reset
    dst.clear();
    src.clear();
    begin = NONE;
    reg = null;
    slot = null;
}
 
Example 4
Source File: List.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
	selectedIndex = position;
	switch (listType) {
		case IMPLICIT:
			fireCommandAction(selectCommand, List.this);
			break;
		case EXCLUSIVE:
			if (position >= 0 && position < selected.size()) {
				Collections.fill(selected, Boolean.FALSE);
				selected.set(position, Boolean.TRUE);
			}
			break;
		case MULTIPLE:
			if (position >= 0 && position < selected.size()) {
				selected.set(position, !selected.get(position));
			}
			break;
	}
	adapter.notifyDataSetChanged();
}
 
Example 5
Source File: LoginStorage.java    From HeavenMS with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean registerLogin(int accountId) {
    List<Long> accHist = loginHistory.get(accountId);
    if (accHist == null) {
        accHist = new LinkedList<Long>();
        loginHistory.put(accountId, accHist);
    }
    
    synchronized (accHist) {
        if (accHist.size() > YamlConfig.config.server.MAX_ACCOUNT_LOGIN_ATTEMPT) {
            long blockExpiration = Server.getInstance().getCurrentTime() + YamlConfig.config.server.LOGIN_ATTEMPT_DURATION;
            Collections.fill(accHist, blockExpiration);

            return false;
        }
        
        accHist.add(Server.getInstance().getCurrentTime() + YamlConfig.config.server.LOGIN_ATTEMPT_DURATION);
        return true;
    }
}
 
Example 6
Source File: ToggleComponentsArrayAdapter.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
public ToggleComponentsArrayAdapter(Context context, int resource, List<ResolveInfo> objects) {
    super(context, resource, objects);
    mPackageManager = context.getPackageManager();
    mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(
            Context.DEVICE_POLICY_SERVICE);
    // Init mIsComponentCheckedList
    mIsComponentCheckedList = new ArrayList<>(Arrays.asList(new Boolean[objects.size()]));
    Collections.fill(mIsComponentCheckedList, Boolean.FALSE);
}
 
Example 7
Source File: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, String query) throws SQLException {
    super(connection);
    this.query = query;
    this.statement = parseStatement(query);
    this.parameterCount = statement.getBindCount();
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 8
Source File: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, PhoenixStatementParser parser) throws SQLException, IOException {
    super(connection);
    this.statement = parser.nextStatement(new ExecutableNodeFactory());
    if (this.statement == null) { throw new EOFException(); }
    this.query = null; // TODO: add toString on SQLStatement
    this.parameterCount = statement.getBindCount();
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 9
Source File: ClientInventoryUpdate.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void send(EntityPlayer player) {
    if(mode == 1)
        Collections.fill(player.inventoryContainer.inventoryItemStacks, null);
    else if(mode == 2) {
        // Inventory slots: http://hydra-media.cursecdn.com/minecraft.gamepedia.com/8/8c/Items_slot_number.JPG?version=8c2b6c3bebb8855b34f07f232a9e6d6f
        int inventorySlot = player.inventory.currentItem;

        // Container slots: http://wiki.vg/images/1/13/Inventory-slots.png
        int containerSlot = inventorySlot < 9? 36 + inventorySlot : inventorySlot;
        player.inventoryContainer.inventoryItemStacks.set(containerSlot, null);
    }
    player.inventoryContainer.detectAndSendChanges();
}
 
Example 10
Source File: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, String query) throws SQLException {
    super(connection);
    this.query = query;
    this.statement = parseStatement(query);
    this.parameterCount = statement.getBindCount();
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 11
Source File: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, PhoenixStatementParser parser) throws SQLException,
        IOException {
    super(connection);
    this.statement = parser.nextStatement(new ExecutableNodeFactory());
    if (this.statement == null) { throw new EOFException(); }
    this.query = null; // TODO: add toString on SQLStatement
    this.parameterCount = statement.getBindCount();
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 12
Source File: PhoenixPreparedStatement.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, PhoenixStatementParser parser) throws SQLException,
        IOException {
    super(connection);
    this.statement = parser.nextStatement(new ExecutableNodeFactory());
    if (this.statement == null) { throw new EOFException(); }
    this.query = null; // TODO: add toString on SQLStatement
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 13
Source File: EndTableFlusher.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void flushInto(final XMLUtil xmlUtil, final ZipUTF8Writer writer) throws IOException {
    for (final TableRowImpl row : this.rows) {
        TableRowImpl.appendXMLToTable(row, xmlUtil, writer);
    }
    // free rows
    Collections.fill(this.rows, null);
    this.appender.appendPostamble(writer);
}
 
Example 14
Source File: RowsFlusher.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void flushInto(final XMLUtil xmlUtil, final ZipUTF8Writer writer) throws IOException {
    // flush rows
    for (final TableRowImpl row : this.rows) {
        if (row == null) {
            throw new IllegalArgumentException();
        }
        row.appendXMLToTable(xmlUtil, writer);
    }
    // free rows
    Collections.fill(this.rows, null);
}
 
Example 15
Source File: PreprocessedRowsFlusher.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an new rows flusher
 * Warning, consume the rows by removing the refs.
 *
 * @param xmlUtil   an util
 * @param tableRows a view on the rows
 * @return the flusher
 * @throws IOException if an I/O error occurs
 */
public static PreprocessedRowsFlusher create(final XMLUtil xmlUtil,
                                             final List<TableRowImpl> tableRows)
        throws IOException {
    // create a char sequence
    final StringBuilder sb = new StringBuilder(STRING_BUILDER_SIZE);
    for (final TableRowImpl row : tableRows) {
        TableRowImpl.appendXMLToTable(row, xmlUtil, sb);
    }
    // free rows
    Collections.fill(tableRows, null);

    return new PreprocessedRowsFlusher(sb);
}
 
Example 16
Source File: OffHeapHashTableImpl.java    From HaloDB with Apache License 2.0 5 votes vote down vote up
public void close() {
    closed = true;
    for (Segment map : segments) {
        map.release();
    }
    Collections.fill(segments, null);

    if (logger.isDebugEnabled()) {
        logger.debug("Closing OHC instance");
    }
}
 
Example 17
Source File: PhoenixPreparedStatement.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PhoenixPreparedStatement(PhoenixConnection connection, String query) throws SQLException {
    super(connection);
    this.query = query;
    this.statement = parseStatement(query);
    this.parameters = Arrays.asList(new Object[statement.getBindCount()]);
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 18
Source File: PhoenixPreparedStatement.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void clearParameters() throws SQLException {
    Collections.fill(parameters, BindManager.UNBOUND_PARAMETER);
}
 
Example 19
Source File: RawDataDiceView.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public void clearData() {
    Collections.fill(data, Dice.One);
}
 
Example 20
Source File: RawDataBinaryView.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public void clearData(){
    Collections.fill(data, Boolean.FALSE);
}