List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:com.morphoss.jumble.models.Category.java
/** * /*w w w . ja v a2s . c o m*/ * @param context * required to work * @return the next word of the available ones */ public Word getNextWord(Context context) { ContentValues cv = new ContentValues(); ArrayList<String> tempsolved = CategoryWords.getSolvedWordsFromCategory(context, this); double ratioSolved = (double) tempsolved.size() / (double) words.size(); Log.d(TAG, "size of solved list : " + tempsolved.size()); Log.d(TAG, "size of words list : " + words.size()); Log.d(TAG, "ratio solved : " + ratioSolved); Log.d(TAG, "category selected : " + this.getLocalisedName()); int ratio = (int) (ratioSolved * 100); Log.d(TAG, "ratio :" + ratio); if (this.getLocalisedName() == null) { Log.e(TAG, "error localised name is null :"); } cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, this.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); if (ratio == 0) { context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } else { cv = new ContentValues(); cv.put(JumbleCategoryTable.RATIO, ratio); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { this.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "addratio"), cv, selection, selectionArgs); } Category nextCategory = CategoryGridAdapter.getCategory(getId()); Log.d(TAG, "next category name : " + nextCategory.getLocalisedName()); if (nextCategory.getLocalisedName() != null && ratio == 0) { cv = new ContentValues(); cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } if (!nextCategory.unlocked() && ratio > 20 && nextCategory.getLocalisedName() != null) { Log.d(TAG, "unlocking a new category"); unlockedCategories.add(nextCategory.getLocalisedName()); cv = new ContentValues(); //cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); //cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); cv.put(JumbleCategoryTable.UNLOCK, "1"); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { nextCategory.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "unlockCategory"), cv, selection, selectionArgs); //context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES,cv); nextCategory.setUnlocked(true); } int countEasyWords = wordsEasy.size(); Log.d(TAG, "count of easy words :" + countEasyWords); int countMediumWords = wordsMedium.size(); Log.d(TAG, "count of medium words :" + countMediumWords); int countAdvancedWords = wordsAdvanced.size(); Log.d(TAG, "count of advanced words :" + countAdvancedWords); ArrayList<Word> filteredwords = new ArrayList<Word>(); filteredwords.addAll(wordsEasy); if (filteredwords.size() < 3) filteredwords.addAll(wordsMedium); if (filteredwords.size() < 3) filteredwords.addAll(wordsAdvanced); if (filteredwords.size() == 0) return null; Word word = CategoryWords.getRandomItem(filteredwords); ArrayList<Word> wordList; Log.d(TAG, "the random word is : " + word.getLocalisedWord() + " with level :" + word.getLevel()); switch (word.getLevel()) { case EASY: wordList = wordsEasy; break; case MEDIUM: wordList = wordsMedium; break; case ADVANCED: wordList = wordsAdvanced; break; default: wordList = wordsAdvanced; break; } for (int i = 0; i < wordList.size(); i++) { if (wordList.get(i).equals(word)) { wordList.remove(i); break; } } return word; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.OperatorDeepCopyVisitor.java
@Override public ILogicalOperator visitDataScanOperator(DataSourceScanOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>(); newInputList.addAll(op.getVariables()); return new DataSourceScanOperator(newInputList, op.getDataSource()); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.OperatorDeepCopyVisitor.java
@Override public ILogicalOperator visitUnnestMapOperator(UnnestMapOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>(); newInputList.addAll(op.getVariables()); return new UnnestMapOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()), new ArrayList<Object>(op.getVariableTypes()), op.propagatesInput()); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.visitors.OperatorDeepCopyVisitor.java
@Override public ILogicalOperator visitExternalDataLookupOperator(ExternalDataLookupOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newInputList = new ArrayList<LogicalVariable>(); newInputList.addAll(op.getVariables()); return new ExternalDataLookupOperator(newInputList, deepCopyExpressionRef(op.getExpressionRef()), new ArrayList<Object>(op.getVariableTypes()), op.isPropagateInput(), op.getDataSource()); }
From source file:com.openshift.blog.example.fis.process.CountryProcessor.java
/** * Populate the list of names./* w w w. j a va 2s . co m*/ * * @throws IOException */ private ArrayList<String> populateList() throws IOException { File dataDirectory = new File(dataDirectoryPath); File[] files = dataDirectory.listFiles(getFilenameFilter()); ArrayList<String> list = new ArrayList<>(); for (File dataFile : files) { // Sorry, couldn't be bothered to make a StringBuilder for this. LOG.info("Parsing data from " + dataFile.getAbsolutePath()); String names = FileUtils.readFileToString(dataFile); list.addAll(Arrays.asList(names.split(COMMA))); } return list; }
From source file:gash.router.app.DemoApp.java
/*** * Two parts from two different concurrent threads we receive a file blocks * This constitues a parallel approach for file read *//*from w w w.ja v a2 s.c om*/ public void rearrangeFileBlocks(HashMap<String, ArrayList<ByteString>> partitionedMap, File file) { try { FileOutputStream fOutputStream = new FileOutputStream(file); while (firstHalfValue == true && secondHalfValue == true) { for (String key : partitionedMap.keySet()) { if (key == "firstHalf") { this.firstHalfValue = true; firstHalfChunkList = partitionedMap.get("firstHalf"); } else { this.secondHalfValue = true; partitionedMap.get("secondHalf"); secondHalfChunkList = partitionedMap.get("secondHalf"); } } ; } ArrayList<ByteString> completeChunkList = new ArrayList<ByteString>(); completeChunkList.addAll(firstHalfChunkList); completeChunkList.addAll(secondHalfChunkList); ByteString bs = ByteString.copyFrom(completeChunkList); // File has been created after ordering the two seperate halves/ fOutputStream.write(bs.toByteArray()); fOutputStream.flush(); fOutputStream.close(); } catch (Exception e) { e.printStackTrace(); } System.out.flush(); }
From source file:act.installer.brenda.BrendaChebiOntology.java
/** * This method processes relatioships "is subtype of" to produce a mapping between each application and its main * application, used subsequently (outside of this) to compute each ontology's main application. * @param isSubtypeOfRelationships map {chebi id -> subtype's chebi ids} * @param applicationChebiId main application's chebi id * @return a map {application's chebi id -> related main application's chebi ids} *//* w ww. j a v a 2s . c o m*/ public static Map<String, Set<String>> getApplicationToMainApplicationsMap( Map<String, Set<String>> isSubtypeOfRelationships, String applicationChebiId) { // Compute the set of main applications. These are the ontologies that are subtypes of the ontology 'application'. Set<String> mainApplicationsChebiId = isSubtypeOfRelationships.get(applicationChebiId); // Compute the initial list of applications to visit from the set of main applications. ArrayList<String> applicationsToVisit = new ArrayList<>(mainApplicationsChebiId); // For each main application, map it to a set containing only itself. Map<String, Set<String>> applicationToMainApplicationsMap = applicationsToVisit.stream() .collect(Collectors.toMap(e -> e, Collections::singleton)); // Then visit all applications in a BFS fashion, appending new applications to visit to the applicationsToVisit // and propagating/merging the set of main applications as we progress down the relationship graph. int currentIndex = 0; while (currentIndex < applicationsToVisit.size()) { String currentApplication = applicationsToVisit.get(currentIndex); Set<String> subApplications = isSubtypeOfRelationships.get(currentApplication); if (subApplications != null) { // add all sub-applications to the set of applications to visit applicationsToVisit.addAll(subApplications); for (String subApplication : subApplications) { Set<String> mainApplicationsSet = applicationToMainApplicationsMap.get(subApplication); if (mainApplicationsSet == null) { mainApplicationsSet = new HashSet<>(); applicationToMainApplicationsMap.put(subApplication, mainApplicationsSet); } mainApplicationsSet.addAll(applicationToMainApplicationsMap.get(currentApplication)); } } currentIndex++; } return applicationToMainApplicationsMap; }
From source file:com.lucidtechnics.blackboard.ChangeInfoHistory.java
public synchronized List getTargetHistory(String _targetName) { ArrayList targetHistoryListCopy = new ArrayList(); List targetHistoryList = (List) getTargetNameToTargetListMap().get(_targetName); if (targetHistoryList != null) { targetHistoryListCopy.addAll(targetHistoryList); }/*from ww w. j a va2 s. c om*/ return targetHistoryListCopy; }
From source file:edu.umass.cs.nio.MessageExtractor.java
/** * Note: Use with care. This will change demultiplexing behavior midway, * which is usually not what you want to do. This is typically useful to set * in the beginning.//from w w w . j a v a2 s . co m */ public synchronized void precedePacketDemultiplexer(AbstractPacketDemultiplexer<?> pd) { // we update tmp to not have to lock this structure ArrayList<AbstractPacketDemultiplexer<?>> tmp = new ArrayList<AbstractPacketDemultiplexer<?>>(); tmp.add(pd); tmp.addAll(packetDemuxes); this.packetDemuxes = tmp; }
From source file:Executable.Input.java
/** * Get the VCF data//w w w .j a va 2 s . c om * @return The VCF data * @throws VCF.Exceptions.VCFException If there is a problem with VCF file * or the data in it. * @throws OutputException If there is a problem writing out the immediate * output file (see constructor) */ public VCF getVCF() throws VCFException, OutputException { List<GenotypeChanger> genotypechangers = new ArrayList<>(); genotypechangers.add(new MaxDepthNoReadsChanger(maxdepth)); List<PositionFilter> prefilters = new ArrayList<>(); prefilters.add(new HasDepthFilter()); ArrayList<String> requiredFields = new ArrayList<>(); requiredFields.add("GT"); requiredFields.add("DP"); if (readsformat == null) { requiredFields.add("AD"); } else { requiredFields.addAll(Arrays.asList(readsformat.split(","))); } ArrayList<PositionChanger> positionchangers = new ArrayList<>(); if (readsformat != null) { String[] formats = readsformat.split(","); if (formats.length == 1) { positionchangers.add(new RenameFormatChanger(formats[0], "AD")); } if (formats.length == 2) { positionchangers.add(new StandardizeCountsFormatChanger(formats[0], formats[1])); } } VCF vcf = new VCF(in, prefilters, positionchangers, genotypechangers, filters, requiredFields); if (readsformat != null) { for (String f : readsformat.split(",")) { vcf.getMeta().removeFormat(f); } vcf.getMeta().addFormat("AD", "##FORMAT=<ID=AD,Number=.,Type=Integer,Description=\"Allelic" + " depths for the reference and alternate alleles" + " in the order listed\">"); } if (out != null) { try { vcf.writeFile(out); } catch (IOException ex) { throw new OutputException("Problem writing filtered VCF", ex); } } return vcf; }