List of usage examples for java.util SortedSet tailSet
SortedSet<E> tailSet(E fromElement);
From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java
private Integer[] mixExistingWithIntersectionPoint(final IProfile profil, final Integer intersectionIndex) { final Integer[] markerPoints = existingMarkersAsIndices(profil); final SortedSet<Integer> markerIndices = new TreeSet<>(Arrays.asList(markerPoints)); // depends on the side of the profile! final IProfileRecord lowestPoint = ProfileVisitors.findLowestPoint(profil); if (Objects.isNull(lowestPoint)) return new Integer[] { intersectionIndex }; final Collection<Integer> result = new ArrayList<>(2); result.add(intersectionIndex);//w ww.j a v a 2 s . c o m if (intersectionIndex > lowestPoint.getIndex()) { // use leftmost of all left markers final SortedSet<Integer> leftSet = markerIndices.headSet(lowestPoint.getIndex()); if (!leftSet.isEmpty()) { result.add(leftSet.first()); } } else { // use leftmost of all left markers final SortedSet<Integer> rightSet = markerIndices.tailSet(lowestPoint.getIndex()); if (!rightSet.isEmpty()) { result.add(rightSet.last()); } } return result.toArray(new Integer[result.size()]); }
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"); }// ww w . j a v a 2 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.zanata.client.commands.push.RawPushCommand.java
@Override public void run() throws IOException { PushCommand.logOptions(log, getOpts()); consoleInteractor.printfln(DisplayMode.Warning, "Using EXPERIMENTAL project type 'file'."); List<FileTypeInfo> serverAcceptedTypes = fileTypeInfoList(client); if (getOpts().getListFileTypes()) { printFileTypes(serverAcceptedTypes); return;/* w ww. ja v a 2 s . com*/ } if (!pushSource() && !pushTrans()) { throw new RuntimeException("Invalid option for push type"); } // only supporting single module for now File sourceDir = getOpts().getSrcDir(); if (!sourceDir.exists()) { boolean enableModules = getOpts().getEnableModules(); // TODO(files) remove warning when modules supported if (enableModules) { consoleInteractor.printfln(DisplayMode.Warning, "enableModules=true but multi-modules not yet supported for this command. Using single module push."); } throw new RuntimeException("directory '" + sourceDir + "' does not exist - check " + getOpts().getSrcDirParameterName() + " option"); } RawPushStrategy strat = new RawPushStrategy(); strat.setPushOptions(getOpts()); ImmutableList<FileTypeInfo> actualFileTypes = getActualFileTypes(serverAcceptedTypes, getOpts().getFileTypes()); if (actualFileTypes.isEmpty()) { log.info("no valid types specified; nothing to do"); return; } ImmutableList.Builder<String> sourceFileExtensionsBuilder = ImmutableList.builder(); actualFileTypes .forEach(fileTypeInfo -> sourceFileExtensionsBuilder.addAll(fileTypeInfo.getSourceExtensions())); ImmutableList<String> sourceFileExtensions = sourceFileExtensionsBuilder.build(); String[] srcFiles = strat.getSrcFiles(sourceDir, getOpts().getIncludes(), getOpts().getExcludes(), sourceFileExtensions, true, getOpts().getCaseSensitive()); SortedSet<String> localDocNames = new TreeSet<String>(Arrays.asList(srcFiles)); // TODO(files) handle obsolete document deletion consoleInteractor.printfln(DisplayMode.Warning, "Obsolete document removal is not yet implemented, no documents will be removed from the server."); SortedSet<String> docsToPush = localDocNames; if (getOpts().getFromDoc() != null) { if (!localDocNames.contains(getOpts().getFromDoc())) { log.error("Document with id {} not found, unable to start push from unknown document. Aborting.", getOpts().getFromDoc()); // FIXME should this be throwing an exception to properly abort? // need to see behaviour with modules return; } docsToPush = localDocNames.tailSet(getOpts().getFromDoc()); int numSkippedDocs = localDocNames.size() - docsToPush.size(); log.info("Skipping {} document(s) before {}.", numSkippedDocs, getOpts().getFromDoc()); } if (docsToPush.isEmpty()) { log.info("no documents in module: {}; nothing to do", getOpts().getCurrentModule()); return; } else { consoleInteractor.printfln("Found source documents:"); for (String docName : localDocNames) { if (docsToPush.contains(docName)) { FileTypeName fileType = getFileTypeNameBySourceExtension(actualFileTypes, FilenameUtils.getExtension(docName)); consoleInteractor.printfln(" " + Messages.format("push.info.documentToPush", docName, fileType.getName())); } else { consoleInteractor.printfln(Messages.format("push.info.skipDocument", docName)); } } } if (pushTrans()) { if (getOpts().getLocaleMapList() == null) throw new ConfigException( "pushType set to '" + getOpts().getPushType() + "', but project has no locales configured"); consoleInteractor.printfln(DisplayMode.Warning, Messages.format("push.warn.overrideTranslations", getOpts().getPushType())); if (getOpts().getPushType() == PushPullType.Both) { confirmWithUser("This will overwrite existing documents AND TRANSLATIONS on the server.\n"); // , and delete obsolete documents.\n"); } else if (getOpts().getPushType() == PushPullType.Trans) { confirmWithUser("This will overwrite existing TRANSLATIONS on the server.\n"); } } else { // confirmWithUser("This will overwrite existing documents on the server, and delete obsolete documents.\n"); confirmWithUser("This will overwrite existing documents on the server.\n"); } boolean hasErrors = false; for (final String localDocName : docsToPush) { try { final String srcExtension = FilenameUtils.getExtension(localDocName); final FileTypeInfo fileType = getFileType(actualFileTypes, srcExtension); final String qualifiedDocName = qualifiedDocName(localDocName); if (pushSource()) { if (!getOpts().isDryRun()) { boolean sourcePushed = pushSourceDocumentToServer(sourceDir, localDocName, qualifiedDocName, fileType.getType().getName()); // ClientUtility.checkResult(putResponse, uri); if (!sourcePushed) { hasErrors = true; } } else { log.info("pushing source doc [qualifiedname={}] to server (skipped due to dry run)", qualifiedDocName); } } if (pushTrans()) { Optional<String> translationFileExtension = getTranslationFileExtension(fileType, srcExtension); strat.visitTranslationFiles(localDocName, new TranslationFilesVisitor() { @Override public void visit(LocaleMapping locale, File translatedDoc) { log.info("pushing {} translation of {}", locale.getLocale(), qualifiedDocName); pushDocumentToServer(qualifiedDocName, fileType.getType().getName(), locale.getLocale(), translatedDoc); } }, translationFileExtension); } } 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(localDocName)); throw new RuntimeException(e.getMessage(), e); } } if (hasErrors) { throw new RuntimeException("Push completed with errors, see log for details."); } }
From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java
private static void addTypeTo(final Set<Class<?>> target, final SortedSet<String> sortedSet) { addTypeTo(target, (Collection<?>) sortedSet); addTypeTo(target, (Set<String>) sortedSet.headSet("foo")); addTypeTo(target, (Set<String>) sortedSet.tailSet("foo")); addTypeTo(target, (Set<String>) sortedSet.subSet("foo", "foo")); }
From source file:uk.ac.ebi.fg.jobs.OntologySimilarityJob.java
public void doExecute(JobExecutionContext jobExecutionContext) throws JobExecutionException, InterruptedException { JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap(); Map<ExperimentId, SortedSet<EfoTerm>> smallMap = (Map<ExperimentId, SortedSet<EfoTerm>>) dataMap .get("smallMap"); OntologyDistanceCalculator distanceCalculator = (OntologyDistanceCalculator) dataMap .get("distanceCalculator"); Map<String, SortedSet<ExperimentId>> uriToExpMap = (ConcurrentHashMap<String, SortedSet<ExperimentId>>) dataMap .get("uriToExpMap"); Map<ExperimentId, SortedSet<EfoTerm>> expToURIMap = (ConcurrentHashMap<ExperimentId, SortedSet<EfoTerm>>) dataMap .get("expToURIMap"); Map<ExperimentId, SortedSet<ExperimentId>> ontologyResults = (ConcurrentHashMap<ExperimentId, SortedSet<ExperimentId>>) dataMap .get("ontologyResults"); lowPriorityURIs = (SortedSet<String>) dataMap.get("lowPriorityOntologyURIs"); int counter = (Integer) dataMap.get("counter"); Configuration properties = (Configuration) dataMap.get("properties"); final int maxOWLSimilarityCount = properties.getInt("max_displayed_OWL_similarities"); final int smallExpAssayCountLimit = properties.getInt("small_experiment_assay_count_limit"); final float minCalculatedOntologyDistance = properties.getFloat("minimal_calculated_ontology_distance"); logger.info("Started " + (counter - smallMap.size()) + " - " + counter + " ontology similarity jobs"); for (Map.Entry<ExperimentId, SortedSet<EfoTerm>> entry : smallMap.entrySet()) { ExperimentId experiment = entry.getKey(); SortedSet<ExperimentId> resultExpSimilaritySet = new TreeSet<ExperimentId>(); for (EfoTerm efoTerm : entry.getValue()) { Set<OntologySimilarityResult> similars = distanceCalculator.getSimilarNodes(efoTerm.getUri()); if (null != similars) { for (OntologySimilarityResult ontologySimilarityResult : similars) { int distance = ontologySimilarityResult.getDistance(); SortedSet<ExperimentId> similarExperiments = uriToExpMap .get(ontologySimilarityResult.getURI()); if (similarExperiments != null) { for (ExperimentId exp : similarExperiments) { if (experiment.getSpecies().equals(exp.getSpecies()) && !experiment.equals(exp)) { if (resultExpSimilaritySet.contains(exp)) { ExperimentId expClone = resultExpSimilaritySet.tailSet(exp).first().clone(); resultExpSimilaritySet.remove(exp); resultExpSimilaritySet.add( setDistance(expClone, ontologySimilarityResult.getURI(), distance)); } else { ExperimentId expClone = exp.clone(); resultExpSimilaritySet.add( setDistance(expClone, ontologySimilarityResult.getURI(), distance)); }/*from ww w . ja v a 2s. c o m*/ } } } } } } // store information for maximal score calculation ExperimentId experimentClone = experiment.clone(); for (EfoTerm efoTerm : expToURIMap.get(experimentClone)) { if (lowPriorityURIs.contains(efoTerm.getUri())) experimentClone.setLowPriorityMatchCount(experimentClone.getLowPriorityMatchCount() + 1); else experimentClone.setDist0Count(experimentClone.getDist0Count() + 1); experimentClone.setNumbOfMatches(experimentClone.getNumbOfMatches() + 1); } ontologyResults.put(experimentClone, cleanResults(experimentClone, resultExpSimilaritySet, smallExpAssayCountLimit, maxOWLSimilarityCount, minCalculatedOntologyDistance, expToURIMap)); Thread.currentThread().wait(1); } logger.info("Finished " + (counter - smallMap.size()) + " - " + counter + " ontology similarity jobs"); smallMap.clear(); }
From source file:visolate.Visolate.java
public void mouseClicked(double x, double y, int modifiers) { SortedSet<Net> clickedNets = new TreeSet<Net>(); model.getNetsAtPoint(x, y, 1.0 / display.getDPI(), clickedNets); if (manualTopology.isSelected()) { clearSelection();//from w w w.j av a 2 s .c om TopologyProcessor.mergeNets(clickedNets); return; } if ((selectedNet != null) && clickedNets.contains(selectedNet)) { Iterator<Net> it = (clickedNets.tailSet(selectedNet)).iterator(); it.next(); if (it.hasNext()) { selectedNet = it.next(); } else { selectedNet = clickedNets.iterator().next(); } } else { selectedNet = null; if (!clickedNets.isEmpty()) { selectedNet = clickedNets.iterator().next(); } } Net selectedNetSave = selectedNet; if (!((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0)) clearSelection(); selectedNet = selectedNetSave; if (selectedNet != null) { selectedNets.add(selectedNet); selectedNet.setHighlighted(true); } }