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:eionet.meta.service.VocabularyInverseTest.java

/**
 * tests if after deleting an element it is deleted from the other side as well.
 *
 * @throws Exception/*w  ww . j ava2  s  .co m*/
 */
@Test
public void testDeleteReferenceElemFromInverseConcept() throws Exception {

    int checkedOutID = vocabularyService.checkOutVocabularyFolder(4, "taburet");

    VocabularyConcept concept7 = vocabularyService.getVocabularyConcept(checkedOutID, "concept7", false);

    List<List<DataElement>> dataElements = concept7.getElementAttributes();
    List<DataElement> skosRelatedMatch = VocabularyImportBaseHandler
            .getDataElementValuesByName("skos:relatedMatch", dataElements);

    //remove relation:
    skosRelatedMatch.clear();
    vocabularyService.updateVocabularyConcept(concept7);

    //reference elems should not disappear after delete

    VocabularyConcept concept6 = vocabularyService.getVocabularyConcept(3, "concept6", false);

    dataElements = concept6.getElementAttributes();
    List<DataElement> skosNarrowElements = VocabularyImportBaseHandler
            .getDataElementValuesByName("skos:relatedMatch", dataElements);

    Assert.assertEquals("Referred reference elem must still be present after save ", 1,
            skosNarrowElements.size());

    //should remain after checkin
    vocabularyService.checkInVocabularyFolder(checkedOutID, "taburet");

    VocabularyConcept concept6After = vocabularyService.getVocabularyConcept(3, "concept6", false);

    dataElements = concept6After.getElementAttributes();
    skosNarrowElements = VocabularyImportBaseHandler.getDataElementValuesByName("skos:relatedMatch",
            dataElements);

    Assert.assertNull("Referred reference must not be present after checkin", skosNarrowElements);
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestKeyedObjectPool.java

private void clear(final FailingKeyedPoolableObjectFactory factory, final List expectedMethods) {
    factory.getMethodCalls().clear();/* www .j a va2 s.  c  om*/
    expectedMethods.clear();
}

From source file:com.contrastsecurity.ide.eclipse.core.extended.ExtendedContrastSDK.java

public StoryResource getStory(String orgUuid, String traceId) throws IOException, UnauthorizedException {
    InputStream is = null;//from  ww w. jav  a 2 s  . co  m
    InputStreamReader reader = null;
    try {
        String traceUrl = getTraceUrl(orgUuid, traceId);
        is = makeRequest(HttpMethod.GET, traceUrl);
        reader = new InputStreamReader(is);

        String inputString = IOUtils.toString(is, "UTF-8");
        StoryResource story = this.gson.fromJson(inputString, StoryResource.class);
        JsonObject object = (JsonObject) new JsonParser().parse(inputString);
        JsonObject storyObject = (JsonObject) object.get("story");
        if (storyObject != null) {
            JsonArray chaptersArray = (JsonArray) storyObject.get("chapters");
            List<Chapter> chapters = story.getStory().getChapters();
            if (chapters == null) {
                chapters = new ArrayList<>();
            } else {
                chapters.clear();
            }
            for (int i = 0; i < chaptersArray.size(); i++) {
                JsonObject member = (JsonObject) chaptersArray.get(i);
                Chapter chapter = gson.fromJson(member, Chapter.class);
                chapters.add(chapter);
                JsonObject properties = (JsonObject) member.get("properties");
                if (properties != null) {
                    Set<Entry<String, JsonElement>> entries = properties.entrySet();
                    Iterator<Entry<String, JsonElement>> iter = entries.iterator();
                    List<PropertyResource> propertyResources = new ArrayList<>();
                    chapter.setPropertyResources(propertyResources);
                    while (iter.hasNext()) {
                        Entry<String, JsonElement> prop = iter.next();
                        // String key = prop.getKey();
                        JsonElement entryValue = prop.getValue();
                        if (entryValue != null && entryValue.isJsonObject()) {
                            JsonObject obj = (JsonObject) entryValue;
                            JsonElement name = obj.get("name");
                            JsonElement value = obj.get("value");
                            if (name != null && value != null) {
                                PropertyResource propertyResource = new PropertyResource();
                                propertyResource.setName(name.getAsString());
                                propertyResource.setValue(value.getAsString());
                                propertyResources.add(propertyResource);
                            }
                        }
                    }
                }

            }
        }
        return story;
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(reader);
    }
}

From source file:eionet.meta.service.VocabularyInverseTest.java

/**
 * tests if after deletgin an element it is deleted from the oither side as well.
 *
 * @throws Exception/*from   w w w  . j  ava  2  s .  c om*/
 */
@Test
public void testDeleteLocalrefElemFromInverseConcept() throws Exception {

    int checkedOutID = vocabularyService.checkOutVocabularyFolder(3, "taburet");

    VocabularyConcept concept5 = vocabularyService.getVocabularyConcept(checkedOutID, "concept5", false);

    List<List<DataElement>> dataElements = concept5.getElementAttributes();
    List<DataElement> skosBroaderElements = VocabularyImportBaseHandler
            .getDataElementValuesByName("skos:broader", dataElements);

    //remove broader relateion:
    skosBroaderElements.clear();
    vocabularyService.updateVocabularyConcept(concept5);

    //localref elems have to disappear after delete

    VocabularyConcept concept6 = vocabularyService.getVocabularyConcept(checkedOutID, "concept6", false);

    dataElements = concept6.getElementAttributes();
    List<DataElement> skosNarrowElements = VocabularyImportBaseHandler
            .getDataElementValuesByName("skos:narrower", dataElements);

    Assert.assertNull("Referred localref must not be present before checkin", skosNarrowElements);

    //should remain after checkin
    vocabularyService.checkInVocabularyFolder(checkedOutID, "taburet");

    VocabularyConcept concept6After = vocabularyService.getVocabularyConcept(3, "concept6", false);

    dataElements = concept6After.getElementAttributes();
    skosNarrowElements = VocabularyImportBaseHandler.getDataElementValuesByName("skos:narrower", dataElements);

    Assert.assertNull("Referred localref must not be present after checkin", skosNarrowElements);
}

From source file:hoot.services.osm.OsmTestUtils.java

public static Set<Long> createTestWays(final long changesetId, final Set<Long> nodeIds) throws Exception {
    Set<Long> wayIds = new LinkedHashSet<Long>();
    List<Long> wayNodeIds = new ArrayList<Long>();
    final Long[] nodeIdsArr = nodeIds.toArray(new Long[] {});
    Map<String, String> tags = new HashMap<String, String>();

    tags.put("key 1", "val 1");
    tags.put("key 2", "val 2");
    wayNodeIds.add(nodeIdsArr[0]);//from   ww w.j  a va2s.  c  o m
    wayNodeIds.add(nodeIdsArr[1]);
    wayNodeIds.add(nodeIdsArr[4]);
    wayIds.add(Way.insertNew(changesetId, mapId, wayNodeIds, tags, conn));
    tags.clear();
    wayNodeIds.clear();

    wayNodeIds.add(nodeIdsArr[2]);
    wayNodeIds.add(nodeIdsArr[1]);
    wayIds.add(Way.insertNew(changesetId, mapId, wayNodeIds, null, conn));
    wayNodeIds.clear();

    tags.put("key 3", "val 3");
    wayNodeIds.add(nodeIdsArr[0]);
    wayNodeIds.add(nodeIdsArr[1]);
    wayIds.add(Way.insertNew(changesetId, mapId, wayNodeIds, tags, conn));
    tags.clear();
    wayNodeIds.clear();

    return wayIds;
}

From source file:nc.noumea.mairie.appock.services.impl.ServiceServiceImpl.java

@Override
public List<Service> findAllWithActifInactifOrderByLibelle(boolean avecNull) {
    List<Service> result = serviceRepository.findAllByOrderByLibelle();
    List<Service> listeServiceActif = new ArrayList<>();
    List<Service> listeServiceInactif = new ArrayList<>();
    for (Service service : result) {
        chargeLazy(service);/*from  w  ww  .j  a va2s  .c o m*/
        if (service.isActif()) {
            listeServiceActif.add(service);
        } else {
            listeServiceInactif.add(service);
        }
    }
    result.clear();

    Comparator serviceComparator = Comparator
            .comparing((Service service) -> service.getDirection().getPole().getLibelle())
            .thenComparing(service -> service.getDirection().getLibelleCourt())
            .thenComparing(service -> service.getLibelleCourt());

    Collections.sort(listeServiceActif, serviceComparator);
    Collections.sort(listeServiceInactif, serviceComparator);

    result.addAll(listeServiceActif);
    result.addAll(listeServiceInactif);

    if (avecNull) {
        result.add(0, null);
    }

    return result;
}

From source file:org.suren.autotest.web.framework.selenium.action.SeleniumCheck.java

@Override
public void checkByValue(Element element, String value) {
    WebElement parentWebEle = searchStrategyUtils.findStrategy(WebElement.class, element).search(element);
    if (parentWebEle == null) {
        logger.error(String.format("can not found element byText [%s].", value));
        return;/*from w  ww  . j a  va 2  s  . c o  m*/
    }

    List<Locator> locatorList = element.getLocatorList();
    List<Locator> tmpList = new ArrayList<Locator>(locatorList);

    ElementSearchStrategy<WebElement> strategy = context.getBean("zoneSearchStrategy",
            ElementSearchStrategy.class);

    SeleniumValueLocator valueLocator = context.getBean(SeleniumValueLocator.class);
    valueLocator.setHostType("byTagName");
    valueLocator.setHostValue("input");

    locatorList.clear();
    locatorList.add(valueLocator);
    valueLocator.setValue(value);

    WebElement itemWebEle = null;
    try {
        if (strategy instanceof ParentElement) {
            ((ParentElement) strategy).setParent(parentWebEle);
        }

        itemWebEle = strategy.search(element);
        if (itemWebEle != null) {
            if (!itemWebEle.isSelected()) {
                itemWebEle.click();
            }
        }
    } catch (ElementNotVisibleException e) {
        e.printStackTrace();
        logger.error(
                String.format("Element [%s] click error, parent [%s], text [%s].", itemWebEle, element, value));
    } finally {
        //
        locatorList.clear();
        locatorList.addAll(tmpList);

        if (strategy instanceof ParentElement) {
            ((ParentElement) strategy).setParent(null);
        }
    }
}

From source file:com.jaeksoft.searchlib.crawler.file.database.FileManager.java

public int delete(AbstractSearchRequest searchRequest, TaskLog taskLog) throws SearchLibException {
    setCurrentTaskLog(taskLog);//from   w  w w .j a va 2  s.  com
    try {
        int total = 0;
        List<FileItem> itemList = new ArrayList<FileItem>();
        for (;;) {
            itemList.clear();
            getFileList(searchRequest, 0, 1000, itemList);
            if (itemList.size() == 0)
                break;
            List<String> uriList = new ArrayList<String>(itemList.size());
            for (FileItem fileItem : itemList)
                uriList.add(fileItem.getUri());
            dbClient.deleteDocuments(FileItemFieldEnum.INSTANCE.uri.getName(), uriList);
            total += itemList.size();
            taskLog.setInfo(total + " URI(s) deleted");
            if (taskLog.isAbortRequested())
                throw new SearchLibException.AbortException();
        }
        return total;
    } finally {
        resetCurrentTaskLog();
    }
}

From source file:dbconverter.dao.util.ToolKit.java

/**
 * Converts a Mongo result set to JSON and stores the converted data in a 
 * file, prepared for bulk loading into ElasticSearch
 * WARNING: does NOT overwrite the old file
 * @param results The Mongo result set//  w  ww .j  a v a 2  s . com
 * @param queryObject Must contain the index and type of the target
 * @param jsonFileName The name of the file to write converted data to
 * @param writeInterval Determines how frequently to clear local memory
 * @author hightowe
 */
public static void writeMongoResultsToJson(FindIterable<Document> results, QueryObject queryObject,
        String jsonFileName, int writeInterval) {
    List<String> jsonResults = new ArrayList<>();
    int fcount = 0;
    String theIndex = queryObject.getIndexName();
    String theType = queryObject.getTypeName();

    for (Document doc : results) {
        // add a timestamp of when the document was written
        doc.append(TIME_STAMP, getISOTime(TIME_STAMP_FORMAT));
        String jsonDoc = doc.toJson();
        // replace _id field name with MONGO_ID to avoid errors when indexing
        jsonDoc = jsonDoc.replace("_id", MONGO_ID);
        jsonResults.add(jsonDoc);
        fcount++;

        if (fcount % writeInterval == 0) {
            logger.info("Writing JSON document " + Integer.toString(fcount));
            ToolKit.writeToElasticsearchBulkLoadJsonFile(theIndex, theType, jsonFileName, jsonResults);
            jsonResults.clear(); // clear local memory
        }
    }

    logger.info("Writing JSON document " + Integer.toString(fcount));
    ToolKit.writeToElasticsearchBulkLoadJsonFile(theIndex, theType, jsonFileName, jsonResults);

    logger.info("Wrote " + Integer.toString(fcount) + " JSON documents");

}

From source file:forge.limited.BoosterDraftAI.java

/**
 * <p>//from  w  ww.  ja  v a2s. c  om
 * Choose a CardPrinted from the list given.
 * </p>
 *
 * @param chooseFrom
 *            List of CardPrinted
 * @param player
 *            a int.
 * @return a {@link forge.item.PaperCard} object.
 */
public PaperCard choose(final List<PaperCard> chooseFrom, final int player) {
    if (ForgePreferences.DEV_MODE) {
        System.out.println("Player[" + player + "] pack: " + chooseFrom.toString());
    }

    final DeckColors deckCols = this.playerColors.get(player);
    final ColorSet currentChoice = deckCols.getChosenColors();
    final boolean canAddMoreColors = deckCols.canChoseMoreColors();

    final List<Pair<PaperCard, Double>> rankedCards = rankCards(chooseFrom);

    for (final Pair<PaperCard, Double> p : rankedCards) {
        double valueBoost = 0;

        // If a card is not ai playable, somewhat decrease its rating
        if (p.getKey().getRules().getAiHints().getRemAIDecks()) {
            valueBoost = TAKE_BEST_THRESHOLD;
        }

        // if I cannot choose more colors, and the card cannot be played with chosen colors, decrease its rating.
        if (!canAddMoreColors
                && !p.getKey().getRules().getManaCost().canBePaidWithAvaliable(currentChoice.getColor())) {
            valueBoost = TAKE_BEST_THRESHOLD * 3;
        }

        if (valueBoost > 0) {
            p.setValue(p.getValue() + valueBoost);
            //System.out.println(p.getKey() + " is now " + p.getValue());
        }
    }

    double bestRanking = Double.MAX_VALUE;
    PaperCard bestPick = null;
    final List<PaperCard> possiblePick = new ArrayList<PaperCard>();
    for (final Pair<PaperCard, Double> p : rankedCards) {
        final double rating = p.getValue();
        if (rating <= bestRanking + .01) {
            if (rating < bestRanking) {
                // found a better card start a new list
                possiblePick.clear();
                bestRanking = rating;
            }
            possiblePick.add(p.getKey());
        }
    }

    bestPick = Aggregates.random(possiblePick);

    if (canAddMoreColors) {
        deckCols.addColorsOf(bestPick);
    }

    System.out.println("Player[" + player + "] picked: " + bestPick + " ranking of " + bestRanking);
    this.deck.get(player).add(bestPick);

    return bestPick;
}