Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

In this page you can find the example usage for java.util List clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:com.flexive.war.javascript.tree.ContentTreeWriter.java

private void writeContentNode(FxEnvironment environment, TreeNodeWriter writer, FxTreeNode node,
        Map<String, Object> properties, List<String> actionsDisabled, boolean pathMode) throws IOException {
    final boolean liveTreeEnabled;
    try {/* w ww.j  a v  a  2 s .  com*/
        liveTreeEnabled = EJBLookup.getConfigurationEngine().get(SystemParameters.TREE_LIVE_ENABLED);
    } catch (FxApplicationException e) {
        throw e.asRuntimeException();
    }
    properties.clear();
    actionsDisabled.clear();
    properties.put("objectId", node.getId());
    properties.put("widgetId", "node_" + node.getId());
    properties.put("isDirty", liveTreeEnabled && node.isDirty());
    properties.put("mayEdit", node.isMayEdit());

    final boolean locked = isLocked(node);
    properties.put("locked", locked);

    if (node.hasReference()) {
        properties.put("referenceId", node.getReference().getId());
        properties.put("referenceTypeId", node.getReferenceTypeId());
    }

    setAllowedActions(actionsDisabled, node, liveTreeEnabled);
    if (actionsDisabled.size() > 0) {
        properties.put("actionsDisabled", actionsDisabled);
    }

    final String docType;
    if (locked) {
        docType = node.getLock().getUserId() == FxContext.getUserTicket().getUserId() ? DOCTYPE_LOCKED_OWN
                : DOCTYPE_LOCKED;
    } else if (node.getReferenceTypeId() != -1) {
        docType = DOCTYPE_CONTENT + node.getReferenceTypeId();
    } else {
        docType = DOCTYPE_NODE;
    }
    final String label = pathMode ? node.getName() : node.getLabel().getBestTranslation();
    properties.put("nodeText", label);
    if (node.isLeaf()) {
        writer.writeNode(new Node(String.valueOf(node.getId()), label, docType, properties));
    } else {
        if (node.getChildren().size() == 0 && node.getDirectChildCount() > 0) {
            properties.put("isFolder", true);
        }
        if (environment.getType(node.getReferenceTypeId()).isDerivedFrom(FxType.FOLDER)) {
            properties.put("isFolderType", true);
        }
        writer.startNode(new Node(String.valueOf(node.getId()), label + " [" + node.getDirectChildCount() + "]",
                docType, properties));
        writer.startChildren();
        int count = 0;
        for (FxTreeNode child : node.getChildren()) {
            writeContentNode(environment, writer, child, properties, actionsDisabled, pathMode);
            if (node.getId() != FxTreeNode.ROOT_NODE && ++count > MAX_CHILD_NODES) {
                // render placeholder, skip rest of nodes
                writer.writeNode(new Node("-1", "...", DOCTYPE_CONTENT, new HashMap<String, Object>(0)));
                break;
            }
        }
        writer.closeChildren();
        writer.closeNode();
    }
}

From source file:net.sf.clickclick.control.BooleanSelect.java

/**
 * Options are added to the Select control. Make sure you call
 * super.onInit() if you override this method.
 *//*  ww  w.j av  a2 s .c  o m*/
@Override
public void onInit() {
    List optionList = getOptionList();

    // Being called more than once? We could keep the existing options,
    // but they might have changed
    if (optionList.size() > 0) {
        optionList.clear();
    }

    if (tristate) {
        add(new StyledOption("", "unset", getOptionLabelUnset()));
    }
    add(new StyledOption(Boolean.TRUE.toString(), "true", getOptionLabelTrue()));

    add(new StyledOption(Boolean.FALSE.toString(), "false", getOptionLabelFalse()));

    super.onInit();
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java

private void genCandidates(IOptimizationContext context) throws AlgebricksException {
    List<List<Mutable<ILogicalOperator>>> previousEquivalenceClasses = new ArrayList<List<Mutable<ILogicalOperator>>>();
    while (equivalenceClasses.size() > 0) {
        previousEquivalenceClasses.clear();
        for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
            List<Mutable<ILogicalOperator>> candidatesCopy = new ArrayList<Mutable<ILogicalOperator>>();
            candidatesCopy.addAll(candidates);
            previousEquivalenceClasses.add(candidatesCopy);
        }/*from  w  w  w . j  a  va2s. c om*/
        List<Mutable<ILogicalOperator>> currentLevelOpRefs = new ArrayList<Mutable<ILogicalOperator>>();
        for (List<Mutable<ILogicalOperator>> candidates : equivalenceClasses) {
            if (candidates.size() > 0) {
                for (Mutable<ILogicalOperator> opRef : candidates) {
                    List<Mutable<ILogicalOperator>> refs = childrenToParents.get(opRef);
                    if (refs != null)
                        currentLevelOpRefs.addAll(refs);
                }
            }
            if (currentLevelOpRefs.size() == 0)
                continue;
            candidatesGrow(currentLevelOpRefs, candidates);
        }
        if (currentLevelOpRefs.size() == 0)
            break;
        prune(context);
    }
    if (equivalenceClasses.size() < 1 && previousEquivalenceClasses.size() > 0) {
        equivalenceClasses.addAll(previousEquivalenceClasses);
        prune(context);
    }
}

From source file:HashTagSegmenter.java

private List<String> segment(String text) {
    List<String> segments = new ArrayList<String>();
    String currentSegment = "";
    StringBuilder trimmedText = new StringBuilder(text);
    StringBuilder finalText = new StringBuilder(text);
    boolean foundLastWord = true;

    while (trimmedText.length() >= 0) {

        // returns text if text is empty or the last word is not found
        if ((trimmedText.length() == 0 && segments.size() == 0) || foundLastWord == false) {
            segments.clear();
            segments.add(text);//from   w  ww . j a va 2 s . c om
            return segments;
        }
        // returns the segments if crude segment text has no more characters
        else if (trimmedText.length() == 0 && segments.size() > 0) {
            return segments;
        }
        // segments the crude segment text if not empty
        else if (trimmedText.length() > 0) {

            // adds text to segments list if text exists in Hashtable
            if (wordHashTable.containsKey(trimmedText.toString())) {

                // stores the segment for easy removal
                currentSegment = trimmedText.toString();

                // newText only contains the key, adds it to list
                segments.add(currentSegment);

                // deletes the current segment from front of finalText
                finalText = new StringBuilder(finalText.delete(0, currentSegment.length()));

                // resets newText
                trimmedText = new StringBuilder(finalText.toString());

            }
            // trims last letter of crude segment text if key doesn't exist
            else {

                trimmedText = trimmedText.deleteCharAt(trimmedText.length() - 1);

                if (trimmedText.length() == 0) {
                    foundLastWord = false;
                }
            }

        }

    }

    // returns null if unable to segment
    return null;

}

From source file:com.floreantpos.ui.dialog.DiscountSelectionDialog.java

@Override
public void doOk() {
    List<TicketDiscount> couponAndDiscounts = ticket.getDiscounts();
    if (couponAndDiscounts == null)
        couponAndDiscounts = new ArrayList<TicketDiscount>();
    if (!CollectionUtils.isEqualCollection(couponAndDiscounts, addedTicketDiscounts.values())) {
        couponAndDiscounts.clear();

        for (TicketDiscount ticketDiscount : addedTicketDiscounts.values()) {
            ticket.addTodiscounts(ticketDiscount);
        }//from   w w  w  . jav  a 2 s  . c om
    }

    for (Iterator iterator = ticket.getTicketItems().iterator(); iterator.hasNext();) {
        TicketItem ticketItem = (TicketItem) iterator.next();
        for (Iterator iterator2 = ticketItem.getDiscounts().iterator(); iterator2.hasNext();) {
            TicketItemDiscount ticketItemDiscount = (TicketItemDiscount) iterator2.next();
            if (clearTicketItemDiscounts.contains((Integer) ticketItemDiscount.getDiscountId())) {
                iterator2.remove();
            }

        }
    }

    for (TicketItem ticketItem : ticket.getTicketItems()) {
        for (DiscountButton discountButton : buttonMap.values()) {
            if (discountButton.ticketItems.contains(ticketItem)) {
                ticketItem.getDiscounts()
                        .add(MenuItem.convertToTicketItemDiscount(discountButton.discount, ticketItem));
            }
        }
    }

    setCanceled(false);
    dispose();
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3CompositeEntityRepositoryTest.java

@Test
public void testFindAll() throws InterruptedException {
    List<EmbeddedEntity> keys = Lists.newArrayList();
    Iterable<CompositeEntity> result = null;

    CompositeEntity entity1 = new CompositeEntity();
    entity1.setKey(new EmbeddedEntity("sharedPrimaryKey", 0L, 0.0f));
    entity1.setaString("alpha");
    entity1.setaUuid(UUID.randomUUID());
    repository.save(entity1);//from  w  ww  .  j  a v  a2  s .  c om
    assertTrue(repository.exists(new EmbeddedEntity("sharedPrimaryKey", 0L, 0.0f)));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey"));
    result = repository.findAll(keys);
    assertEquals(1, Iterables.size(result));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey", 0L));
    result = repository.findAll(keys);
    assertEquals(1, Iterables.size(result));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey", 0L, 0.0f));
    result = repository.findAll(keys);
    assertEquals(1, Iterables.size(result));

    CompositeEntity entity2 = new CompositeEntity();
    entity2.setKey(new EmbeddedEntity("sharedPrimaryKey", 0L, 1.0f));
    entity2.setaString("beta");
    entity2.setaUuid(UUID.randomUUID());
    repository.save(entity2);
    assertTrue(repository.exists(new EmbeddedEntity("sharedPrimaryKey", 0L, 1.0f)));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey"));
    result = repository.findAll(keys);
    assertEquals(2, Iterables.size(result));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey", 0L));
    result = repository.findAll(keys);
    assertEquals(2, Iterables.size(result));

    keys.clear();
    keys.add(new EmbeddedEntity("sharedPrimaryKey", 0L, 1.0f));
    result = repository.findAll(keys);
    assertEquals(1, Iterables.size(result));
}

From source file:org.canova.api.records.reader.impl.SVMRecordWriterTest.java

@Test
public void testWriter() throws Exception {
    InputStream is = new ClassPathResource("iris.dat").getInputStream();
    assumeNotNull(is);/*from   w ww  . j  a va  2s.c om*/
    File tmp = new File("iris.txt");
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmp));
    IOUtils.copy(is, bos);
    bos.flush();
    bos.close();
    InputSplit split = new FileSplit(tmp);
    tmp.deleteOnExit();
    RecordReader reader = new CSVRecordReader();
    List<Collection<Writable>> records = new ArrayList<>();
    reader.initialize(split);
    while (reader.hasNext()) {
        Collection<Writable> record = reader.next();
        assertEquals(5, record.size());
        records.add(record);
    }

    assertEquals(150, records.size());
    File out = new File("iris_out.txt");
    out.deleteOnExit();
    RecordWriter writer = new SVMLightRecordWriter(out, true);
    for (Collection<Writable> record : records)
        writer.write(record);

    writer.close();
    records.clear();

    RecordReader svmReader = new SVMLightRecordReader();
    InputSplit svmSplit = new FileSplit(out);
    svmReader.initialize(svmSplit);
    assertTrue(svmReader.hasNext());
    while (svmReader.hasNext()) {
        Collection<Writable> record = svmReader.next();
        assertEquals(5, record.size());
        records.add(record);
    }
    assertEquals(150, records.size());
}

From source file:forge.game.mana.ManaPool.java

public final void refundManaPaid(final SpellAbility sa) {
    // Send all mana back to your mana pool, before accounting for it.
    final List<Mana> manaPaid = sa.getPayingMana();

    // move non-undoable paying mana back to floating
    if (sa.getHostCard() != null) {
        sa.getHostCard().setCanCounter(true);
    }//w ww  .ja  va  2 s.  c  om
    for (final Mana m : manaPaid) {
        addMana(m);
    }
    manaPaid.clear();

    List<SpellAbility> payingAbilities = sa.getPayingManaAbilities();
    for (final SpellAbility am : payingAbilities) {
        // undo paying abilities if we can
        am.undo();
    }

    for (final SpellAbility am : payingAbilities) {
        // Recursively refund abilities that were used.
        refundManaPaid(am);
    }

    payingAbilities.clear();

    // update battlefield of activating player - to redraw cards used to pay mana as untapped
    Player p = sa.getActivatingPlayer();
    p.getGame().fireEvent(new GameEventZone(ZoneType.Battlefield, p, EventValueChangeType.ComplexUpdate, null));
}

From source file:tasly.greathealth.thirdparty.inventory.services.impl.AbstractStoreItemService.java

@Override
public List<StoreSku> prepareData(final List<ProductOms> pos) {
    // get the productTm List from memory
    final List<StoreSku> tms = storeSkuConvertor.getListFromInternalMemory();
    tms.clear();
    List<StoreSku> skus = new ArrayList<StoreSku>();
    /**//from   w  ww.j av  a2 s .co  m
     * if the memory has data, update the quantity directly
     * else convert the data
     */
    if (tms.isEmpty()) {
        // get all the otc products information from tmall
        Log.info("?:??...");
        final List<StoreSku> otcItems = this.getItemsFromStore();

        if (!otcItems.isEmpty()) {
            Log.info("?:otc??" + otcItems.size());
            // final Map<String, List<Sku>> itemsMap = new HashMap<String, List<Sku>>();
            // itemsMap.put(storeName, otcItems);

            // comvert the data to prodcutTm list
            Log.info("?: ???...");
            skus = storeSkuConvertor.convertData(otcItems, pos);
        }
    }
    return skus;
}