List of usage examples for java.util SortedSet isEmpty
boolean isEmpty();
From source file:org.zanata.client.commands.pull.RawPullCommand.java
@Override public void run() throws IOException { PullCommand.logOptions(log, getOpts()); if (getOpts().isDryRun()) { log.info("DRY RUN: no permanent changes will be made"); }/* www .j a v a2 s. c o m*/ log.warn("Using EXPERIMENTAL project type 'file'."); LocaleList locales = getOpts().getLocaleMapList(); if (locales == null) { throw new ConfigException("no locales specified"); } RawPullStrategy strat = new RawPullStrategy(); strat.setPullOptions(getOpts()); List<String> docNamesForModule = getQualifiedDocNamesForCurrentModuleFromServer(); SortedSet<String> localDocNames = new TreeSet<String>(docNamesForModule); SortedSet<String> docsToPull = localDocNames; if (getOpts().getFromDoc() != null) { if (!localDocNames.contains(getOpts().getFromDoc())) { log.error("Document with id {} not found, unable to start pull from unknown document. Aborting.", getOpts().getFromDoc()); // FIXME should this be throwing an exception to properly abort? // need to see behaviour with modules return; } docsToPull = localDocNames.tailSet(getOpts().getFromDoc()); int numSkippedDocs = localDocNames.size() - docsToPull.size(); log.info("Skipping {} document(s) before {}.", numSkippedDocs, getOpts().getFromDoc()); } // TODO compare docNamesForModule with localDocNames, offer to delete // obsolete translations from filesystem if (docsToPull.isEmpty()) { log.info("No documents in remote module: {}; nothing to do", getOpts().getCurrentModule()); return; } else { log.info("Source documents on server:"); for (String docName : localDocNames) { if (docsToPull.contains(docName)) { log.info(" {}", docName); } else { log.info("(to skip) {}", docName); } } } log.info("Pulling {} of {} docs for this module from the server", docsToPull.size(), localDocNames.size()); log.debug("Doc names: {}", localDocNames); PushPullType pullType = getOpts().getPullType(); boolean pullSrc = pullType == PushPullType.Both || pullType == PushPullType.Source; boolean pullTarget = pullType == PushPullType.Both || pullType == PushPullType.Trans; if (needToGetStatistics(pullTarget)) { log.info( "Setting minimum document completion percentage may potentially increase the processing time."); } if (pullSrc) { log.warn("Pull Type set to '" + pullType + "': existing source-language files may be overwritten/deleted"); confirmWithUser( "This will overwrite/delete any existing documents and translations in the above directories.\n"); } else { confirmWithUser("This will overwrite/delete any existing translations in the above directory.\n"); } Optional<Map<String, Map<LocaleId, TranslatedPercent>>> optionalStats = prepareStatsIfApplicable(pullTarget, locales); for (String qualifiedDocName : docsToPull) { // TODO add filtering by file type? e.g. pull all dtd documents // only. try { String localDocName = unqualifiedDocName(qualifiedDocName); if (pullSrc) { Response response; try { response = fileResourceClient.downloadSourceFile(getOpts().getProj(), getOpts().getProjectVersion(), FileResource.FILETYPE_RAW_SOURCE_DOCUMENT, qualifiedDocName); InputStream srcDoc = response.readEntity(InputStream.class); if (srcDoc != null) { try { strat.writeSrcFile(localDocName, srcDoc); } finally { srcDoc.close(); } } } catch (ResponseProcessingException e) { if (e.getResponse().getStatus() == 404) { log.warn("No source document file is available for [{}]. Skipping.", qualifiedDocName); } else { throw e; } } } if (pullTarget) { String fileExtension; if (getOpts().getIncludeFuzzy()) { fileExtension = FileResource.FILETYPE_TRANSLATED_APPROVED_AND_FUZZY; } else { fileExtension = FileResource.FILETYPE_TRANSLATED_APPROVED; } List<LocaleId> skippedLocales = Lists.newArrayList(); for (LocaleMapping locMapping : locales) { LocaleId locale = new LocaleId(locMapping.getLocale()); if (shouldPullThisLocale(optionalStats, localDocName, locale)) { pullDocForLocale(strat, qualifiedDocName, localDocName, fileExtension, locMapping, locale); } else { skippedLocales.add(locale); } } if (!skippedLocales.isEmpty()) { log.info( "Translation file for document {} for locales {} are skipped due to insufficient completed percentage", localDocName, skippedLocales); } } } catch (IOException | RuntimeException e) { log.error( "Operation failed: " + e.getMessage() + "\n\n" + " To retry from the last document, please add the option: {}\n", getOpts().buildFromDocArgument(qualifiedDocName)); throw new RuntimeException(e.getMessage(), e); } } }
From source file:org.apache.hadoop.hbase.regionserver.Memcache.java
/** * //from w w w. j a v a2 s .c om * @param set * @param sget * @param result * @return -1 if error ,0 if not ready and 1 if ready */ private int internalGetRow(SortedSet<KeyValue> set, ServerGet sget, List<KeyValue> result, boolean multiFamily) throws IOException { if (set.isEmpty()) { return 0; } //Getting only the things that are related to this row //TODO add family and column in the future, right now it just adds //complexity since you need the first column and/or ts and maybe there is //no column to look for yet as in the cases of getFamilies and getTop set = set.tailSet(new KeyValue(sget.getRow())); //TODO have to remember to check the order of the set, so that tailSet //returns the things that are smaller and not bigger int retCode = 0; // The cases that we need at this level: //0 next //1 include //2 next store //3 done for (KeyValue kv : set) { retCode = sget.compareTo(kv, multiFamily); switch (retCode) { //Do not include in result, look at next kv case 0: break; //Include in result case 1: result.add(kv); break; //Go to next storefile case 2: return 0; //Done, early out case 3: return 1; default: return -1; } } return 0; }
From source file:org.libreplan.web.limitingresources.LimitingResourceQueueModel.java
private LimitingResourceQueueElement getFirstChild(SortedSet<LimitingResourceQueueElement> elements) { return elements.isEmpty() ? null : elements.iterator().next(); }
From source file:org.marketcetera.marketdata.core.manager.impl.MarketDataManagerImpl.java
@Override public Event requestMarketDataSnapshot(Instrument inInstrument, Content inContent, String inProvider) { if (inProvider == null) { SortedSet<Pair<FeedType, Event>> snapshotCandidates = Sets.newTreeSet(SnapshotComparator.INSTANCE); for (MarketDataProvider provider : getActiveMarketDataProviders()) { Event snapshotCandidate = provider.getSnapshot(inInstrument, inContent); if (snapshotCandidate != null) { snapshotCandidates.add(Pair.create(provider.getFeedType(), snapshotCandidate)); }/*w w w.j av a 2s . c om*/ } if (snapshotCandidates.isEmpty()) { return null; } return snapshotCandidates.first().getSecondMember(); } else { MarketDataProvider provider = getMarketDataProviderForName(inProvider); if (provider == null) { throw new MarketDataProviderNotAvailable(); } return provider.getSnapshot(inInstrument, inContent); } }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportJobsQuartzScheduler.java
protected String enumerateCronVals(SortedSet vals, int totalCount) { if (vals == null || vals.isEmpty()) { throw new JSException("jsexception.no.values.to.enumerate"); }/*from www.ja va 2 s . co m*/ if (vals.size() == totalCount) { return "*"; } StringBuffer enumStr = new StringBuffer(); for (Iterator it = vals.iterator(); it.hasNext();) { Byte val = (Byte) it.next(); enumStr.append(val.byteValue()); enumStr.append(','); } return enumStr.substring(0, enumStr.length() - 1); }
From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java
@Override public SortedSet<UniqueName> getSchemaNames(final UniqueName namespace) { final SortedSet<UniqueName> allSubschemaNames = getAllSubschemaNames(namespace); if (allSubschemaNames == null || allSubschemaNames.isEmpty()) { return allSubschemaNames; }// w w w. j ava2 s . c om final String namespaceString = (namespace != null) ? namespace.toString() : ""; final SortedSet<UniqueName> schemaNames = new TreeSet<>(); for (final UniqueName subschemaName : allSubschemaNames) { final String subschemaNameString = subschemaName.toString(); final String remainderNameString = StringUtils.removeStart(subschemaNameString, namespaceString + UniqueName.NAME_SEPARATOR); if (!remainderNameString.contains(UniqueName.NAME_SEPARATOR)) { schemaNames.add(subschemaName); } } return schemaNames; }
From source file:com.okta.swagger.codegen.AbstractOktaJavaClientCodegen.java
private void handleOktaLinkedOperations(Swagger swagger) { // we want to move any operations defined by the 'x-okta-operations' or 'x-okta-crud' vendor extension to the model Map<String, Model> modelMap = swagger.getDefinitions().entrySet().stream() .filter(e -> e.getValue().getVendorExtensions().containsKey("x-okta-operations") || e.getValue().getVendorExtensions().containsKey("x-okta-crud")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); modelMap.forEach((k, model) -> {/*from w w w. ja v a 2s. com*/ List<ObjectNode> linkNodes = new ArrayList<>(); addAllIfNotNull(linkNodes, (List<ObjectNode>) model.getVendorExtensions().get("x-okta-operations")); addAllIfNotNull(linkNodes, (List<ObjectNode>) model.getVendorExtensions().get("x-okta-crud")); Map<String, CodegenOperation> operationMap = new HashMap<>(); linkNodes.forEach(n -> { String operationId = n.get("operationId").textValue(); // find the swagger path operation swagger.getPaths().forEach((pathName, path) -> { Optional<Map.Entry<HttpMethod, Operation>> operationEntry = path.getOperationMap().entrySet() .stream().filter(e -> e.getValue().getOperationId().equals(operationId)).findFirst(); if (operationEntry.isPresent()) { Operation operation = operationEntry.get().getValue(); CodegenOperation cgOperation = fromOperation(pathName, operationEntry.get().getKey().name().toLowerCase(), operation, swagger.getDefinitions(), swagger); boolean canLinkMethod = true; JsonNode aliasNode = n.get("alias"); if (aliasNode != null) { String alias = aliasNode.textValue(); cgOperation.vendorExtensions.put("alias", alias); if ("update".equals(alias)) { model.getVendorExtensions().put("saveable", true); } else if ("delete".equals(alias)) { model.getVendorExtensions().put("deletable", true); cgOperation.vendorExtensions.put("selfDelete", true); } else if ("read".equals(alias) || "create".equals(alias)) { canLinkMethod = false; } } // we do NOT link read or create methods, those need to be on the parent object if (canLinkMethod) { // now any params that match the models we need to use the model value directly // for example if the path contained {id} we would call getId() instead Map<String, String> argMap = createArgMap(n); List<CodegenParameter> cgOtherPathParamList = new ArrayList<>(); List<CodegenParameter> cgParamAllList = new ArrayList<>(); List<CodegenParameter> cgParamModelList = new ArrayList<>(); cgOperation.pathParams.forEach(param -> { if (argMap.containsKey(param.paramName)) { String paramName = argMap.get(param.paramName); cgParamModelList.add(param); if (model.getProperties() != null) { CodegenProperty cgProperty = fromProperty(paramName, model.getProperties().get(paramName)); param.vendorExtensions.put("fromModel", cgProperty); } else { System.err.println("Model '" + model.getTitle() + "' has no properties"); } } else { cgOtherPathParamList.add(param); } }); // remove the body param if the body is the object itself for (Iterator<CodegenParameter> iter = cgOperation.bodyParams.iterator(); iter .hasNext();) { CodegenParameter bodyParam = iter.next(); if (argMap.containsKey(bodyParam.paramName)) { cgOperation.vendorExtensions.put("bodyIsSelf", true); iter.remove(); } } // do not add the parrent path params to the list (they will be parsed from the href) SortedSet<String> pathParents = parentPathParams(n); cgOtherPathParamList.forEach(param -> { if (!pathParents.contains(param.paramName)) { cgParamAllList.add(param); } }); if (!pathParents.isEmpty()) { cgOperation.vendorExtensions.put("hasPathParents", true); cgOperation.vendorExtensions.put("pathParents", pathParents); } cgParamAllList.addAll(cgOperation.queryParams); cgParamAllList.addAll(cgOperation.bodyParams); // set all params to have more cgParamAllList.forEach(param -> param.hasMore = true); // then grab the last one and mark it as the last if (!cgParamAllList.isEmpty()) { CodegenParameter param = cgParamAllList.get(cgParamAllList.size() - 1); param.hasMore = false; } cgOperation.vendorExtensions.put("allParams", cgParamAllList); cgOperation.vendorExtensions.put("fromModelPathParams", cgParamModelList); addOptionalExtension(cgOperation, cgParamAllList); operationMap.put(cgOperation.operationId, cgOperation); // mark the operation as moved so we do NOT add it to the client operation.getVendorExtensions().put("moved", true); } } }); }); model.getVendorExtensions().put("operations", operationMap.values()); }); }
From source file:org.wrml.runtime.schema.DefaultSchemaLoader.java
@Override public SortedSet<UniqueName> getSchemaSubnamespaces(final UniqueName namespace) { final SortedSet<UniqueName> allSubschemaNames = getAllSubschemaNames(namespace); if (allSubschemaNames == null || allSubschemaNames.isEmpty()) { return allSubschemaNames; }//from w w w. java 2 s . co m String namespaceString = (namespace != null) ? namespace.toString() : ""; if (!namespaceString.endsWith(UniqueName.NAME_SEPARATOR)) { namespaceString = namespaceString + UniqueName.NAME_SEPARATOR; } final SortedSet<UniqueName> subnamespaces = new TreeSet<>(); for (final UniqueName subschemaName : allSubschemaNames) { final String subschemaNameString = subschemaName.toString(); final String remainderNameString = StringUtils.removeStart(subschemaNameString, namespaceString); final int endIndex = remainderNameString.indexOf(UniqueName.NAME_SEPARATOR); if (endIndex > 0) { final String localName = remainderNameString.substring(0, endIndex); subnamespaces.add(new UniqueName(namespace, localName)); } } return subnamespaces; }
From source file:org.apache.hadoop.hbase.regionserver.MemStore.java
/** * The passed snapshot was successfully persisted; it can be let go. * @param ss The snapshot to clean out./*ww w. j av a2s . co m*/ * @throws UnexpectedException * @see {@link #snapshot()} */ void clearSnapshot(final SortedSet<KeyValue> ss) throws UnexpectedException { this.lock.writeLock().lock(); try { if (this.snapshot != ss) { throw new UnexpectedException("Current snapshot is " + this.snapshot + ", was passed " + ss); } // OK. Passed in snapshot is same as current snapshot. If not-empty, // create a new snapshot and let the old one go. if (!ss.isEmpty()) { this.snapshot = new KeyValueSkipListSet(this.comparator); this.snapshotTimeRangeTracker = new TimeRangeTracker(); } } finally { this.lock.writeLock().unlock(); } }
From source file:org.libreplan.web.limitingresources.LimitingResourceQueueModel.java
/** * Returns queue which last element is at a earliest date. * * @param potentiallyValidQueues// ww w . ja va 2 s . co m * @return {@link LimitingResourceQueue} */ private LimitingResourceQueue earliestQueue(List<LimitingResourceQueue> potentiallyValidQueues) { LimitingResourceQueue result = null; LocalDate latestDate = null; for (LimitingResourceQueue each : potentiallyValidQueues) { SortedSet<LimitingResourceQueueElement> elements = each.getLimitingResourceQueueElements(); if (!elements.isEmpty()) { LocalDate date = elements.last().getEndDate(); if (latestDate == null || date.isAfter(latestDate)) { latestDate = date; result = each; } } } if (result == null && !potentiallyValidQueues.isEmpty()) { result = potentiallyValidQueues.get(0); } return result; }