Example usage for java.util Collection clear

List of usage examples for java.util Collection clear

Introduction

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

Prototype

void clear();

Source Link

Document

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

Usage

From source file:ubic.gemma.persistence.service.common.auditAndSecurity.AuditEventDaoImpl.java

private Map<Auditable, AuditEvent> getLastEvent(final Collection<? extends Auditable> auditables,
        Class<? extends AuditEventType> type) {

    Map<Auditable, AuditEvent> result = new HashMap<>();
    if (auditables.size() == 0)
        return result;

    final Map<AuditTrail, Auditable> atMap = this.getAuditTrailMap(auditables);

    List<String> classes = this.getClassHierarchy(type);

    //language=HQL
    final String queryString = "select trail, ae from AuditTrailImpl trail "
            + "inner join trail.events ae inner join ae.eventType et inner join fetch ae.performer where trail in (:trails) "
            + "and et.class in (:classes) order by ae.date desc, ae.id desc ";

    StopWatch timer = new StopWatch();
    timer.start();//ww  w. j a v a 2s .  c  o m

    Collection<AuditTrail> batch = new ArrayList<>();
    int batchSize = 100;

    for (AuditTrail at : atMap.keySet()) {
        batch.add(at);

        if (batch.size() == batchSize) {
            org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession()
                    .createQuery(queryString);
            queryObject.setParameterList("trails", batch);
            queryObject.setParameterList("classes", classes);
            queryObject.setReadOnly(true);

            List<?> qr = queryObject.list();
            if (qr == null || qr.isEmpty()) {
                batch.clear();
                continue;
            }

            this.putAllQrs(result, qr, atMap);
            batch.clear();
        }
    }

    if (!batch.isEmpty()) {
        org.hibernate.Query queryObject = this.getSessionFactory().getCurrentSession().createQuery(queryString);
        queryObject.setParameterList("trails", batch); // if too many will fail.
        queryObject.setParameterList("classes", classes);
        queryObject.setReadOnly(true);

        List<?> qr = queryObject.list();
        if (qr == null || qr.isEmpty())
            return result;

        this.putAllQrs(result, qr, atMap);
    }

    timer.stop();
    if (timer.getTime() > 500) {
        AbstractDao.log.info("Last event of type " + type.getSimpleName() + " retrieved for "
                + auditables.size() + " items in " + timer.getTime() + "ms");
    }

    return result;
}

From source file:com.screenslicer.core.nlp.Person.java

public static String extractName(String src, boolean strict, boolean dictionaryOnly) {
    NameFinderME nameFinder = new NameFinderME(nameModel);
    String[] sentences = NlpUtil.sentences(src);
    Collection<String> nlpNames = new HashSet<String>();
    Collection<String> nlpFallbacks = new HashSet<String>();
    Collection<String> dictionaryNames = new HashSet<String>();
    Collection<String> dictionaryFallbacks = new HashSet<String>();
    for (int i = 0; i < sentences.length; i++) {
        String[] tokens = NlpUtil.tokensFromSentence(sentences[i]);
        for (int j = 0; j < tokens.length; j++) {
            String first = tokens[j];
            String last = null;/*from  w  w w .  ja  va  2 s .  com*/
            if (j + 1 < tokens.length) {
                last = tokens[j + 1];
            }
            if (isFirstName(first, strict) && isLastName(last) && isFullName(first + " " + last, strict)) {
                dictionaryNames.add(first + " " + last);
            } else if (!strict && isFirstName(first, strict)) {
                dictionaryFallbacks.add(first);
            }
        }
        Span[] spans = nameFinder.find(tokens);
        for (int j = 0; !dictionaryOnly && j < spans.length; j++) {
            List<String> curNames = Arrays.asList(Span.spansToStrings(spans, tokens));
            for (String curName : curNames) {
                if (curName.contains(" ") && isFullName(curName, strict)) {
                    nlpNames.add(curName);
                } else if (isFirstName(curName, strict)) {
                    nlpFallbacks.add(curName);
                }
            }
        }
    }
    if (nlpNames.isEmpty()) {
        nlpNames = nlpFallbacks;
    }
    if (dictionaryNames.isEmpty()) {
        dictionaryNames = dictionaryFallbacks;
    }

    if ((dictionaryOnly || nlpNames.size() != 1) && dictionaryNames.size() != 1) {
        nlpNames.clear();
        nlpFallbacks.clear();
        dictionaryNames.clear();
        dictionaryFallbacks.clear();
        nameFinder.clearAdaptiveData();
        for (int s = 0; s < sentences.length; s++) {
            String[] tokens = sentences[s].split("[\\W\\s]|$|^");
            for (int i = 0; i < tokens.length; i++) {
                String first = tokens[i];
                String last = null;
                if (i + 1 < tokens.length) {
                    last = tokens[i + 1];
                }
                if (isFirstName(first, strict) && isLastName(last) && isFullName(first + " " + last, strict)) {
                    dictionaryNames.add(first + " " + last);
                } else if (!strict && isFirstName(first, strict)) {
                    dictionaryFallbacks.add(first);
                }
            }
            Span[] spans = nameFinder.find(tokens);
            for (int j = 0; !dictionaryOnly && j < spans.length; j++) {
                List<String> curNames = Arrays.asList(Span.spansToStrings(spans, tokens));
                for (String curName : curNames) {
                    if (curName.contains(" ") && isFullName(curName, strict)) {
                        nlpNames.add(curName);
                    } else if (isFirstName(curName, strict)) {
                        nlpFallbacks.add(curName);
                    }
                }
            }
        }
    }
    if (nlpNames.isEmpty()) {
        nlpNames = nlpFallbacks;
    }
    if (dictionaryNames.isEmpty()) {
        dictionaryNames = dictionaryFallbacks;
    }
    if (nlpNames.size() == 1) {
        return nlpNames.iterator().next();
    }
    if (nlpFallbacks.size() == 1) {
        return nlpFallbacks.iterator().next();
    }
    if (dictionaryNames.size() == 1) {
        return dictionaryNames.iterator().next();
    }
    if (dictionaryFallbacks.size() == 1) {
        return dictionaryFallbacks.iterator().next();
    }
    return null;
}

From source file:fr.paris.lutece.plugins.document.web.DocumentServiceJspBean.java

/**
 * Return the html form for portlet selection.
 *
 * @param request The HTTP request// w w  w  . j  a  v  a  2 s .c  o  m
 * @return The html form of the portlet selection page
 */
public String getSelectPortlet(HttpServletRequest request) {
    init(request);

    String strPageId = request.getParameter(PARAMETER_PAGE_ID);

    if ((strPageId == null) || !strPageId.matches(REGEX_ID)) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
    }

    Page page = PageHome.findByPrimaryKey(IntegerUtils.convert(strPageId));

    Collection<Portlet> listPortletsAll = page.getPortlets();
    Collection<Portlet> listPortlets = new ArrayList<Portlet>();

    for (Portlet portlet : listPortletsAll) {
        if (portlet.getPortletTypeId().equals(DocumentListPortletHome.getInstance().getPortletTypeId())) {
            if (StringUtils.isNotBlank(getTypeFilter())) {
                // filter by type
                if (getTypeFilter().equals(((DocumentListPortlet) portlet).getDocumentTypeCode())) {
                    listPortlets.add(portlet);
                }
            } else {
                // no type filter
                listPortlets.add(portlet);
            }
        }
    }

    listPortletsAll.clear();

    Map<String, Object> model = getDefaultModel();

    model.put(MARK_PORTLETS_LIST, listPortlets);

    HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_SELECTOR_PORTLET, _user.getLocale(), model);

    return template.getHtml();
}

From source file:org.apache.openjpa.enhance.PCDataGenerator.java

/**
 * Set the collection of {@link JumpInstruction}s to the given instruction,
 * clearing the collection in the process.
 *///from  w ww  .  ja  va  2s.  c o  m
protected void setTarget(Instruction ins, Collection<Instruction> jumps) {
    for (Iterator<Instruction> it = jumps.iterator(); it.hasNext();)
        ((JumpInstruction) it.next()).setTarget(ins);
    jumps.clear();
}

From source file:com.datatorrent.lib.io.block.AbstractBlockReader.java

/**
 * <b>Note:</b> This partitioner does not support parallel partitioning.<br/><br/>
 * {@inheritDoc}// ww  w.ja  v a  2  s.  c o  m
 */
@SuppressWarnings("unchecked")
@Override
public Collection<Partition<AbstractBlockReader<R, B, STREAM>>> definePartitions(
        Collection<Partition<AbstractBlockReader<R, B, STREAM>>> partitions, PartitioningContext context) {
    if (partitions.iterator().next().getStats() == null) {
        //First time when define partitions is called
        return partitions;
    }
    List<Partition<AbstractBlockReader<R, B, STREAM>>> newPartitions = Lists.newArrayList();

    //Create new partitions
    for (Partition<AbstractBlockReader<R, B, STREAM>> partition : partitions) {
        newPartitions.add(new DefaultPartition<>(partition.getPartitionedInstance()));
    }
    partitions.clear();
    int morePartitionsToCreate = partitionCount - newPartitions.size();
    List<BasicCounters<MutableLong>> deletedCounters = Lists.newArrayList();

    if (morePartitionsToCreate < 0) {
        //Delete partitions
        Iterator<Partition<AbstractBlockReader<R, B, STREAM>>> partitionIterator = newPartitions.iterator();
        while (morePartitionsToCreate++ < 0) {
            Partition<AbstractBlockReader<R, B, STREAM>> toRemove = partitionIterator.next();
            deletedCounters.add(toRemove.getPartitionedInstance().counters);

            LOG.debug("partition removed {}", toRemove.getPartitionedInstance().operatorId);
            partitionIterator.remove();
        }
    } else {
        KryoCloneUtils<AbstractBlockReader<R, B, STREAM>> cloneUtils = KryoCloneUtils.createCloneUtils(this);
        while (morePartitionsToCreate-- > 0) {
            DefaultPartition<AbstractBlockReader<R, B, STREAM>> partition = new DefaultPartition<>(
                    cloneUtils.getClone());
            newPartitions.add(partition);
        }
    }

    DefaultPartition.assignPartitionKeys(Collections.unmodifiableCollection(newPartitions),
            blocksMetadataInput);
    int lPartitionMask = newPartitions.iterator().next().getPartitionKeys().get(blocksMetadataInput).mask;

    //transfer the state here
    for (Partition<AbstractBlockReader<R, B, STREAM>> newPartition : newPartitions) {
        AbstractBlockReader<R, B, STREAM> reader = newPartition.getPartitionedInstance();

        reader.partitionKeys = newPartition.getPartitionKeys().get(blocksMetadataInput).partitions;
        reader.partitionMask = lPartitionMask;
        LOG.debug("partitions {},{}", reader.partitionKeys, reader.partitionMask);
    }
    //transfer the counters
    AbstractBlockReader<R, B, STREAM> targetReader = newPartitions.iterator().next().getPartitionedInstance();
    for (BasicCounters<MutableLong> removedCounter : deletedCounters) {
        addCounters(targetReader.counters, removedCounter);
    }

    return newPartitions;
}

From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java

protected void doSort() {
    Collection<T> collection = getCollection();
    if (collection == null)
        return;/*w w w.  j av a  2 s .  c  o  m*/

    List<T> list = new LinkedList<>(collection);
    list.sort(createEntityComparator());
    collection.clear();
    collection.addAll(list);
}

From source file:ubic.gemma.persistence.service.expression.designElement.CompositeSequenceDaoImpl.java

@Override
public Map<CompositeSequence, Collection<Gene>> getGenes(Collection<CompositeSequence> compositeSequences) {
    Map<CompositeSequence, Collection<Gene>> returnVal = new HashMap<>();

    int BATCH_SIZE = 2000;

    if (compositeSequences.size() == 0)
        return returnVal;

    /*/*w  w  w .j  av a2  s. c  om*/
     * Get the cs->gene mapping
     */
    final String nativeQuery = "SELECT CS, GENE FROM GENE2CS WHERE CS IN (:csids) ";

    for (CompositeSequence cs : compositeSequences) {
        returnVal.put(cs, new HashSet<Gene>());
    }

    List<Object> csGene = new ArrayList<>();
    Session session = this.getSessionFactory().getCurrentSession();
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(nativeQuery);
    queryObject.addScalar("cs", new LongType());
    queryObject.addScalar("gene", new LongType());

    Collection<Long> csIdBatch = new HashSet<>();
    for (CompositeSequence cs : compositeSequences) {
        csIdBatch.add(cs.getId());

        if (csIdBatch.size() == BATCH_SIZE) {
            queryObject.setParameterList("csids", csIdBatch);
            csGene.addAll(queryObject.list());
            session.clear();
            csIdBatch.clear();
        }
    }

    if (csIdBatch.size() > 0) {
        queryObject.setParameterList("csids", csIdBatch);
        csGene.addAll(queryObject.list());
        session.clear();
    }

    StopWatch watch = new StopWatch();
    watch.start();

    int count = 0;
    Collection<Long> genesToFetch = new HashSet<>();
    Map<Long, Collection<Long>> cs2geneIds = new HashMap<>();

    for (Object object : csGene) {
        Object[] ar = (Object[]) object;
        Long cs = (Long) ar[0];
        Long gene = (Long) ar[1];
        if (!cs2geneIds.containsKey(cs)) {
            cs2geneIds.put(cs, new HashSet<Long>());
        }
        cs2geneIds.get(cs).add(gene);
        genesToFetch.add(gene);
    }

    // nothing found?
    if (genesToFetch.size() == 0) {
        returnVal.clear();
        return returnVal;
    }

    if (AbstractDao.log.isDebugEnabled())
        AbstractDao.log.debug("Built cs -> gene map in " + watch.getTime() + " ms; fetching "
                + genesToFetch.size() + " genes.");

    // fetch the genes
    Collection<Long> batch = new HashSet<>();
    Collection<Gene> genes = new HashSet<>();
    String geneQuery = "from Gene g where g.id in ( :gs )";

    org.hibernate.Query geneQueryObject = this.getSessionFactory().getCurrentSession().createQuery(geneQuery)
            .setFetchSize(1000);

    for (Long gene : genesToFetch) {
        batch.add(gene);
        if (batch.size() == BATCH_SIZE) {
            AbstractDao.log.debug("Processing batch ... ");
            geneQueryObject.setParameterList("gs", batch);
            //noinspection unchecked
            genes.addAll(geneQueryObject.list());
            batch.clear();
        }
    }

    if (batch.size() > 0) {
        geneQueryObject.setParameterList("gs", batch);
        //noinspection unchecked
        genes.addAll(geneQueryObject.list());
    }

    if (AbstractDao.log.isDebugEnabled())
        AbstractDao.log.debug("Got information on " + genes.size() + " genes in " + watch.getTime() + " ms");

    Map<Long, Gene> geneIdMap = new HashMap<>();
    for (Gene g : genes) {
        Hibernate.initialize(g);
        Long id = g.getId();
        geneIdMap.put(id, g);
    }

    // fill in the return value.
    for (CompositeSequence cs : compositeSequences) {
        Long csId = cs.getId();
        assert csId != null;
        Collection<Long> genesToAttach = cs2geneIds.get(csId);
        if (genesToAttach == null) {
            // this means there was no gene for that cs; we should remove it from the result
            returnVal.remove(cs);
            continue;
        }
        for (Long geneId : genesToAttach) {
            returnVal.get(cs).add(geneIdMap.get(geneId));
        }
        ++count;
    }

    if (AbstractDao.log.isDebugEnabled())
        AbstractDao.log.debug("Done, " + count + " result rows processed, " + returnVal.size() + "/"
                + compositeSequences.size() + " probes are associated with genes");
    return returnVal;
}

From source file:com.haulmont.cuba.core.sys.EntityManagerImpl.java

/**
 * Copies all property values from source to dest excluding null values.
 *//* w ww . j  av  a2  s  . c om*/
protected void deepCopyIgnoringNulls(Entity source, Entity dest, Set<Entity> visited) {
    if (visited.contains(source))
        return;
    visited.add(source);

    MetadataTools metadataTools = metadata.getTools();
    for (MetaProperty srcProperty : source.getMetaClass().getProperties()) {
        String name = srcProperty.getName();

        if (!PersistenceHelper.isLoaded(source, name)) {
            continue;
        }

        if (srcProperty.isReadOnly()) {
            continue;
        }

        Object value = source.getValue(name);
        if (value == null) {
            continue;
        }

        if (srcProperty.getRange().isClass() && !metadataTools.isEmbedded(srcProperty)) {
            if (!metadataTools.isOwningSide(srcProperty))
                continue;

            Class refClass = srcProperty.getRange().asClass().getJavaClass();
            if (!metadataTools.isPersistent(refClass))
                continue;

            if (srcProperty.getRange().getCardinality().isMany()) {
                if (!metadataTools.isOwningSide(srcProperty))
                    continue;
                //noinspection unchecked
                Collection<Entity> srcCollection = (Collection) value;
                Collection<Entity> dstCollection = dest.getValue(name);
                if (dstCollection == null)
                    throw new RuntimeException("Collection is null: " + srcProperty);
                boolean equal = srcCollection.size() == dstCollection.size();
                if (equal) {
                    if (srcProperty.getRange().isOrdered()) {
                        equal = Arrays.equals(srcCollection.toArray(), dstCollection.toArray());
                    } else {
                        equal = CollectionUtils.isEqualCollection(srcCollection, dstCollection);
                    }
                }
                if (!equal) {
                    dstCollection.clear();
                    for (Entity srcRef : srcCollection) {
                        Entity reloadedRef = findOrCreate(refClass, srcRef.getId());
                        dstCollection.add(reloadedRef);
                        deepCopyIgnoringNulls(srcRef, reloadedRef, visited);
                    }
                }
            } else {
                Entity srcRef = (Entity) value;
                Entity destRef = dest.getValue(name);
                if (srcRef.equals(destRef)) {
                    deepCopyIgnoringNulls(srcRef, destRef, visited);
                } else {
                    Entity reloadedRef = findOrCreate(refClass, srcRef.getId());
                    dest.setValue(name, reloadedRef);
                    deepCopyIgnoringNulls(srcRef, reloadedRef, visited);
                }
            }
        } else if (metadataTools.isEmbedded(srcProperty)) {
            Entity srcRef = (Entity) value;
            Entity destRef = dest.getValue(name);
            if (destRef != null) {
                deepCopyIgnoringNulls(srcRef, destRef, visited);
            } else {
                Entity newRef = (Entity) metadata.create(srcProperty.getRange().asClass().getJavaClass());
                dest.setValue(name, newRef);
                deepCopyIgnoringNulls(srcRef, newRef, visited);
            }
        } else {
            dest.setValue(name, value);
        }
    }
}

From source file:org.jactr.entry.iterative.IterativeMain.java

public void iteration(final int index, int total, Document environment, URL envURL,
        final Collection<IIterativeRunListener> listeners, final PrintWriter log)
        throws TerminateIterativeRunException {

    ExecutorServices.initialize();/*  w  ww. j  ava2 s . c  om*/

    if (LOGGER.isDebugEnabled()) {
        long totalMem = Runtime.getRuntime().totalMemory();
        long freeMem = Runtime.getRuntime().freeMemory();
        LOGGER.debug("Running iteration " + index + "/" + total + " [" + freeMem / 1024 + "k free : "
                + (totalMem - freeMem) / 1024 + "k used of " + totalMem / 1024 + "k]");
    }

    for (IIterativeRunListener listener : listeners)
        try {
            listener.preLoad(index, total);
        } catch (Exception e) {
            LOGGER.error("listener " + listener + " threw an exception ", e);
        }

    /*
     * first we use the environment to load all the model descriptors
     */
    EnvironmentParser ep = new EnvironmentParser();
    Collection<CommonTree> modelDescriptors = ep.getModelDescriptors(environment, envURL);

    for (IIterativeRunListener listener : listeners)
        try {
            listener.preBuild(index, total, modelDescriptors);
        } catch (TerminateIterativeRunException tire) {
            throw tire;
        } catch (Exception e) {
            LOGGER.error("listener " + listener + " threw an exception ", e);
        }

    /*
     * now we actually do that vodoo that we do to set up the environment this
     * will build the models, instruments, and set up common reality..
     */
    ep.process(environment, modelDescriptors);

    modelDescriptors.clear();

    ACTRRuntime runtime = ACTRRuntime.getRuntime();

    Collection<IModel> models = runtime.getModels();

    for (IModel model : models)
        model.addListener(new ModelListenerAdaptor() {

            long startTime = 0;

            long simStartTime = 0;

            boolean closed = false;

            @Override
            public void modelStarted(ModelEvent event) {
                startTime = event.getSystemTime();
                simStartTime = (long) (event.getSimulationTime() * 1000);
            }

            protected String header(ModelEvent event) {
                StringBuilder sb = new StringBuilder("  <model name=\"");
                sb.append(event.getSource()).append("\" simulated=\"");
                sb.append(duration(simStartTime, (long) (event.getSimulationTime() * 1000)));
                sb.append("\" actual=\"");
                sb.append(duration(startTime, event.getSystemTime()));
                sb.append("\" factor=\"");

                double factor = (event.getSimulationTime() * 1000 - simStartTime)
                        / (event.getSystemTime() - startTime);
                NumberFormat format = NumberFormat.getNumberInstance();
                format.setMaximumFractionDigits(3);
                sb.append(format.format(factor)).append("\"");
                return sb.toString();
            }

            @Override
            public void modelStopped(ModelEvent event) {
                if (!closed)
                    synchronized (log) {
                        log.println(header(event) + "/>");
                    }
            }

            @Override
            public void exceptionThrown(ModelEvent event) {
                synchronized (log) {
                    closed = true;
                    log.println(header(event) + ">");
                    event.getException().printStackTrace(log);
                    log.println("  </model>");

                    for (IIterativeRunListener listener : listeners)
                        try {
                            listener.exceptionThrown(index, event.getSource(), event.getException());
                        } catch (TerminateIterativeRunException tire) {

                        }

                    /*
                     * from here we try to stop the runtime, but do not block.. that
                     * would be disasterous
                     */
                    IController controller = ACTRRuntime.getRuntime().getController();
                    controller.stop();
                }
            }

        }, ExecutorServices.INLINE_EXECUTOR);

    for (IIterativeRunListener listener : listeners)
        try {
            listener.preRun(index, total, models);
        } catch (TerminateIterativeRunException tire) {
            throw tire;
        } catch (Exception e) {
            LOGGER.error("listener " + listener + " threw an exception ", e);
        }

    try {
        /*
         * start 'er up!
         */
        IController controller = runtime.getController();

        /*
         * we do the model check in case the listener is monkeying around with the
         * models (adding, removing) the controller will not ever complete if no
         * models are executed.
         */
        if (models.size() != 0)
            try {
                controller.start().get();
                controller.complete().get();
            } catch (InterruptedException ie) {
                LOGGER.error("Interrupted while waiting for completion", ie);
            }

        /*
         * all done - time to notify and clean up
         */
        for (IIterativeRunListener listener : listeners)
            try {
                listener.postRun(index, total, models);
            } catch (TerminateIterativeRunException tire) {
                throw tire;
            } catch (Exception e) {
                LOGGER.error("listener " + listener + " threw an exception ", e);
            }
    } catch (TerminateIterativeRunException tire) {
        throw tire;
    } catch (Throwable e) {
        throw new RuntimeException("Failed to run iteration " + index + " ", e);
    } finally {
        cleanUp(runtime);
    }
}

From source file:org.apache.shindig.gadgets.http.HttpResponseBuilder.java

public HttpResponseBuilder setEncoding(Charset charset) {
    Collection<String> values = headers.get("Content-Type");
    if (!values.isEmpty()) {
        String contentType = values.iterator().next();
        StringBuilder newContentTypeBuilder = new StringBuilder("");
        // Remove previously set charset:
        String[] parts = StringUtils.split(contentType, ';');
        for (String part : parts) {
            if (!part.contains("charset=")) {
                if (newContentTypeBuilder.length() > 0) {
                    newContentTypeBuilder.append("; ");
                }/*from  w  ww  .  j  av a  2  s  .c  o  m*/
                newContentTypeBuilder.append(part);
            }
        }
        if (charset != null) {
            if (newContentTypeBuilder.length() > 0) {
                newContentTypeBuilder.append("; ");
            }
            newContentTypeBuilder.append("charset=").append(charset.name());
        }
        values.clear();
        String newContentType = newContentTypeBuilder.toString();
        values.add(newContentType);
        if (!(values.size() == 1 && !contentType.equals(newContentType))) {
            incrementNumChanges();
        }
    }
    return this;
}