List of usage examples for java.util SortedSet size
int size();
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java
@Override public AvailableBlock retrieveTargetBlock(IScheduleOwner owner, Date startDate, Date endDate) { SortedSet<AvailableBlock> expanded = retrieveBlocksForDayInternal(owner, startDate); // truncate startDate and endDate to the second final Date truncatedStart = DateUtils.truncate(startDate, Calendar.MINUTE); final Date truncatedEnd = DateUtils.truncate(endDate, Calendar.MINUTE); if (expanded.size() > 0) { for (Iterator<AvailableBlock> expandedIterator = expanded.iterator(); expandedIterator.hasNext();) { AvailableBlock block = expandedIterator.next(); if (block.getStartTime().equals(truncatedStart)) { if (block.getEndTime().equals(truncatedEnd)) { return block; }/*from ww w .jav a 2 s .c o m*/ // start time matches but end time doesn't // check to see if the next block has matching end if (expandedIterator.hasNext()) { AvailableBlock nextBlock = expandedIterator.next(); if (nextBlock.getEndTime().equals(truncatedEnd)) { // start and end represent a double length block, combine and return AvailableBlock combined = AvailableBlockBuilder.createBlock(block.getStartTime(), nextBlock.getEndTime(), block.getVisitorLimit(), block.getMeetingLocation()); return combined; } } } if (block.getStartTime().after(truncatedStart)) { // iterated past the target block, can short circuit and say we didn't find it return null; } } } // block not found, return null return null; }
From source file:org.paxle.core.filter.impl.FilterManager.java
private String[] getFilterNames(String localeStr, SortedSet<FilterContext> filtersForTarget, boolean inclDisabled) { ArrayList<String> filterNames = new ArrayList<String>(filtersForTarget.size()); for (FilterContext fContext : filtersForTarget) { // getting the filter-service final IFilter<?> filter = fContext.getFilter(); final String PID = fContext.getFilterPID(); // getting additional metadata (if available) IMetaData metadata = null;/* ww w. ja v a 2s. c om*/ if (metaDataTracker.getService() != null) { metadata = ((IMetaDataService) metaDataTracker.getService()).getMetadata(PID, localeStr); } String name = (metadata != null) ? metadata.getName() : filter.getClass().getName(); filterNames.add(name); } return filterNames.toArray(new String[filterNames.size()]); }
From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java
/** * {@inheritDoc}//ww w . j ava 2s . co m */ @Override public void mergeLicenses(LicenseMap licenseMap, String... licenses) { if (licenses.length == 0) { return; } String mainLicense = licenses[0].trim(); SortedSet<MavenProject> mainSet = licenseMap.get(mainLicense); if (mainSet == null) { getLogger().debug("No license [" + mainLicense + "] found, will create it."); mainSet = new TreeSet<MavenProject>(projectComparator); licenseMap.put(mainLicense, mainSet); } int size = licenses.length; for (int i = 1; i < size; i++) { String license = licenses[i].trim(); SortedSet<MavenProject> set = licenseMap.get(license); if (set == null) { getLogger().debug("No license [" + license + "] found, skip this merge."); continue; } getLogger().debug("Merge license [" + license + "] (" + set.size() + " depedencies)."); mainSet.addAll(set); set.clear(); licenseMap.remove(license); } }
From source file:org.tonguetied.datatransfer.importing.JavaFxPropertiesImporterTest.java
/** * Test method for//from ww w . j a v a 2s . co m * {@link JavaFxPropertiesImporter#importData(ImportParameters)}. */ public final void testImportData() throws Exception { final String fileName = "JavaFxImporterTest"; File file = new File(TEST_DATA_DIR, fileName + "." + javafx.getDefaultFileExtension()); byte[] input = FileUtils.readFileToByteArray(file); final Importer importer = ImporterFactory.getImporter(javafx, keywordService, transferRepository); TranslationState expectedState = TranslationState.VERIFIED; ImportParameters parameters = new ImportParameters(); parameters.setData(input); parameters.setTranslationState(expectedState); parameters.setFileName(fileName); importer.importData(parameters); Keyword actual = keywordService.getKeyword("import.test.one"); assertNotNull(actual); SortedSet<Translation> translations = actual.getTranslations(); assertEquals(1, translations.size()); Object[] actualTranslations = actual.getTranslations().toArray(); Translation actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("Value 1", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.two"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertNull(actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.three"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("new value 3", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.four"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertNull(actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.five"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(2, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("value 5 \nnew line", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.six"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("", actualTranslation.getValue()); actual = keywordService.getKeyword("import test seven"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle1, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("?", actualTranslation.getValue()); }
From source file:org.tonguetied.datatransfer.importing.JavaFxPropertiesImporterTest.java
/** * Test method for/*ww w. j a v a 2 s .c o m*/ * {@link JavaFxPropertiesImporter#importData(ImportParameters)}. */ public final void testImportDataWithBundle() throws Exception { final String fileName = "JavaFxImporterTest"; File file = new File(TEST_DATA_DIR, fileName + "." + javafx.getDefaultFileExtension()); byte[] input = FileUtils.readFileToByteArray(file); final Importer importer = ImporterFactory.getImporter(javafx, keywordService, transferRepository); TranslationState expectedState = TranslationState.VERIFIED; ImportParameters parameters = new ImportParameters(); parameters.setData(input); parameters.setTranslationState(expectedState); parameters.setFileName(fileName); parameters.setBundle(bundle2); importer.importData(parameters); Keyword actual = keywordService.getKeyword("import.test.one"); assertNotNull(actual); SortedSet<Translation> translations = actual.getTranslations(); assertEquals(1, translations.size()); Object[] actualTranslations = actual.getTranslations().toArray(); Translation actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("Value 1", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.two"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertNull(actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.three"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(2, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[1]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("new value 3", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.four"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(2, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[1]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertNull(actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.five"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(2, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("value 5 \nnew line", actualTranslation.getValue()); actual = keywordService.getKeyword("import.test.six"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("", actualTranslation.getValue()); actual = keywordService.getKeyword("import test seven"); assertNotNull(actual); translations = actual.getTranslations(); assertEquals(1, translations.size()); actualTranslations = actual.getTranslations().toArray(); actualTranslation = (Translation) actualTranslations[0]; assertEquals(defaultCountry, actualTranslation.getCountry()); assertEquals(defaultLanguage, actualTranslation.getLanguage()); assertEquals(bundle2, actualTranslation.getBundle()); assertEquals(expectedState, actualTranslation.getState()); assertEquals("?", actualTranslation.getValue()); }
From source file:org.apache.accumulo.server.gc.SimpleGarbageCollector.java
private void run() { long tStart, tStop; // Sleep for an initial period, giving the master time to start up and // old data files to be unused if (!offline) { try {/*from ww w. j a va2 s . c o m*/ getZooLock(startStatsService()); } catch (Exception ex) { log.error(ex, ex); System.exit(1); } try { log.debug("Sleeping for " + gcStartDelay + " milliseconds before beginning garbage collection cycles"); Thread.sleep(gcStartDelay); } catch (InterruptedException e) { log.warn(e, e); return; } } Sampler sampler = new CountSampler(100); while (true) { if (sampler.next()) Trace.on("gc"); Span gcSpan = Trace.start("loop"); tStart = System.currentTimeMillis(); try { // STEP 1: gather candidates System.gc(); // make room candidateMemExceeded = false; checkForBulkProcessingFiles = false; Span candidatesSpan = Trace.start("getCandidates"); status.current.started = System.currentTimeMillis(); SortedSet<String> candidates = getCandidates(); status.current.candidates = candidates.size(); candidatesSpan.stop(); // STEP 2: confirm deletes // WARNING: This line is EXTREMELY IMPORTANT. // You MUST confirm candidates are okay to delete Span confirmDeletesSpan = Trace.start("confirmDeletes"); confirmDeletes(candidates); status.current.inUse = status.current.candidates - candidates.size(); confirmDeletesSpan.stop(); // STEP 3: delete files if (safemode) { if (verbose) System.out.println("SAFEMODE: There are " + candidates.size() + " data file candidates marked for deletion.\n" + " Examine the log files to identify them.\n" + " They can be removed by executing: bin/accumulo gc --offline\n" + "WARNING: Do not run the garbage collector in offline mode unless you are positive\n" + " that the accumulo METADATA table is in a clean state, or that accumulo\n" + " has not yet been run, in the case of an upgrade."); log.info("SAFEMODE: Listing all data file candidates for deletion"); for (String s : candidates) log.info("SAFEMODE: " + s); log.info("SAFEMODE: End candidates for deletion"); } else { Span deleteSpan = Trace.start("deleteFiles"); deleteFiles(candidates); log.info("Number of data file candidates for deletion: " + status.current.candidates); log.info("Number of data file candidates still in use: " + status.current.inUse); log.info("Number of successfully deleted data files: " + status.current.deleted); log.info("Number of data files delete failures: " + status.current.errors); deleteSpan.stop(); // delete empty dirs of deleted tables // this can occur as a result of cloning cleanUpDeletedTableDirs(candidates); } status.current.finished = System.currentTimeMillis(); status.last = status.current; status.current = new GcCycleStats(); } catch (Exception e) { log.error(e, e); } tStop = System.currentTimeMillis(); log.info(String.format("Collect cycle took %.2f seconds", ((tStop - tStart) / 1000.0))); if (offline) break; if (candidateMemExceeded) { log.info( "Gathering of candidates was interrupted due to memory shortage. Bypassing cycle delay to collect the remaining candidates."); continue; } // Clean up any unused write-ahead logs Span waLogs = Trace.start("walogs"); try { log.info("Beginning garbage collection of write-ahead logs"); GarbageCollectWriteAheadLogs.collect(fs, status); } catch (Exception e) { log.error(e, e); } waLogs.stop(); gcSpan.stop(); Trace.offNoFlush(); try { long gcDelay = ServerConfiguration.getSystemConfiguration() .getTimeInMillis(Property.GC_CYCLE_DELAY); log.debug("Sleeping for " + gcDelay + " milliseconds"); Thread.sleep(gcDelay); } catch (InterruptedException e) { log.warn(e, e); return; } } }
From source file:org.apache.hadoop.hbase.regionserver.DefaultMobStoreFlusher.java
/** * Flushes the cells in the mob store./*from w w w. j av a 2s. co m*/ * <ol>In the mob store, the cells with PUT type might have or have no mob tags. * <li>If a cell does not have a mob tag, flushing the cell to different files depends * on the value length. If the length is larger than a threshold, it's flushed to a * mob file and the mob file is flushed to a store file in HBase. Otherwise, directly * flush the cell to a store file in HBase.</li> * <li>If a cell have a mob tag, its value is a mob file name, directly flush it * to a store file in HBase.</li> * </ol> * @param snapshot Memstore snapshot. * @param snapshotTimeRangeTracker The time range tracker. * @param cacheFlushId Log cache flush sequence number. * @param scanner The scanner of memstore snapshot. * @param writer The store file writer. * @param status Task that represents the flush operation and may be updated with status. * @param smallestReadPoint Smallest read point. * @return The flushed KeyValue size. * @throws IOException */ protected long performMobFlush(SortedSet<KeyValue> snapshot, TimeRangeTracker snapshotTimeRangeTracker, long cacheFlushId, InternalScanner scanner, StoreFile.Writer writer, MonitoredTask status, long smallestReadPoint) throws IOException { StoreFile.Writer mobFileWriter = null; int compactionKVMax = conf.getInt(HConstants.COMPACTION_KV_MAX, HConstants.COMPACTION_KV_MAX_DEFAULT); long mobKVCount = 0; long time = snapshotTimeRangeTracker.getMaximumTimestamp(); mobFileWriter = mobStore.createWriterInTmp(new Date(time), snapshot.size(), store.getFamily().getCompression(), store.getRegionInfo().getStartKey()); // the target path is {tableName}/.mob/{cfName}/mobFiles // the relative path is mobFiles byte[] fileName = Bytes.toBytes(mobFileWriter.getPath().getName()); long flushed = 0; try { Tag mobSrcTableName = new Tag(MobConstants.MOB_TABLE_NAME_TAG_TYPE, store.getTableName().getName()); List<Cell> cells = new ArrayList<Cell>(); boolean hasMore; do { hasMore = scanner.next(cells, compactionKVMax); if (!cells.isEmpty()) { for (Cell c : cells) { // If we know that this KV is going to be included always, then let us // set its memstoreTS to 0. This will help us save space when writing to // disk. KeyValue kv = KeyValueUtil.ensureKeyValue(c); if (kv.getMvccVersion() <= smallestReadPoint) { // let us not change the original KV. It could be in the memstore // changing its memstoreTS could affect other threads/scanners. kv = kv.shallowCopy(); kv.setMvccVersion(0); } if (kv.getValueLength() <= mobCellValueSizeThreshold || MobUtils.isMobReferenceCell(kv) || kv.getTypeByte() != KeyValue.Type.Put.getCode()) { writer.append(kv); } else { // append the original keyValue in the mob file. mobFileWriter.append(kv); mobKVCount++; // append the tags to the KeyValue. // The key is same, the value is the filename of the mob file KeyValue reference = MobUtils.createMobRefKeyValue(kv, fileName, mobSrcTableName); writer.append(reference); } flushed += MemStore.heapSizeChange(kv, true); } cells.clear(); } } while (hasMore); } finally { status.setStatus("Flushing mob file " + store + ": appending metadata"); mobFileWriter.appendMetadata(cacheFlushId, false); status.setStatus("Flushing mob file " + store + ": closing flushed file"); mobFileWriter.close(); } if (mobKVCount > 0) { // commit the mob file from temp folder to target folder. // If the mob file is committed successfully but the store file is not, // the committed mob file will be handled by the sweep tool as an unused // file. mobStore.commitFile(mobFileWriter.getPath(), targetPath); } else { try { // If the mob file is empty, delete it instead of committing. store.getFileSystem().delete(mobFileWriter.getPath(), true); } catch (IOException e) { LOG.error("Fail to delete the temp mob file", e); } } return flushed; }
From source file:net.sourceforge.fenixedu.domain.Shift.java
public String getShiftTypesCodePrettyPrint() { StringBuilder builder = new StringBuilder(); int index = 0; SortedSet<ShiftType> sortedTypes = getSortedTypes(); for (ShiftType shiftType : sortedTypes) { builder.append(shiftType.getSiglaTipoAula()); index++;/*from w ww . ja va2s.c o m*/ if (index < sortedTypes.size()) { builder.append(", "); } } return builder.toString(); }
From source file:org.jclouds.aws.s3.jets3t.JCloudsS3ServiceLiveTest.java
@Test public void testListAllBucketsImpl() throws InterruptedException, ExecutionException, TimeoutException, S3ServiceException { String bucketName = getContainerName(); try {// www. j av a 2 s . co m // Ensure there is at least 1 bucket in S3 account to list and compare. S3Bucket[] jsBuckets = service.listAllBuckets(); SortedSet<org.jclouds.aws.s3.domain.BucketMetadata> jcBuckets = context.getApi().listOwnedBuckets(); assert jsBuckets.length == jcBuckets.size(); Iterator<org.jclouds.aws.s3.domain.BucketMetadata> jcBucketsIter = jcBuckets.iterator(); for (S3Bucket jsBucket : jsBuckets) { assert jcBucketsIter.hasNext(); org.jclouds.aws.s3.domain.BucketMetadata jcBucket = jcBucketsIter.next(); assert jsBucket.getName().equals(jcBucket.getName()); } } finally { returnContainer(bucketName); } }
From source file:net.sourceforge.fenixedu.domain.Shift.java
public String getShiftTypesCapitalizedPrettyPrint() { StringBuilder builder = new StringBuilder(); int index = 0; SortedSet<ShiftType> sortedTypes = getSortedTypes(); for (ShiftType shiftType : sortedTypes) { builder.append(shiftType.getFullNameTipoAula()); index++;/*from www . j av a2 s . c om*/ if (index < sortedTypes.size()) { builder.append(", "); } } return builder.toString(); }