List of usage examples for java.util.function Consumer Consumer
Consumer
From source file:dk.dma.epd.ship.EPDShip.java
/** * Constructor// w w w .java2 s .c om * * @param path * the home path to use */ private EPDShip(String path) throws IOException { super(); if (!StringUtils.isEmpty(path)) { homePath = Paths.get(path); try { optionalTitle = " - " + path.split("epd-ship")[1]; } catch (Exception e) { } } else { homePath = determineHomePath(Paths.get(System.getProperty("user.home"), ".epd-ship")); } new Bootstrap().run(this, new String[] { "epd-ship.properties", "enc_navicon.properties", "settings.properties", "transponder.xml" }, new String[] { "routes", "layout/static", "shape/GSHHS_shp", "identities" }); // Set up log4j logging LOG = LoggerFactory.getLogger(EPDShip.class); // Set default exception handler Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler()); // Determine version LOG.info("Starting eNavigation Prototype Display Ship - version " + VersionInfo.getVersionAndBuild()); LOG.info("Copyright (C) 2011 Danish Maritime Authority"); LOG.info("This program comes with ABSOLUTELY NO WARRANTY."); LOG.info("This is free software, and you are welcome to redistribute it under certain conditions."); LOG.info("For details see LICENSE file."); // Create the bean context (map handler) mapHandler = new MapHandler(); // Load settings or get defaults and add to bean context settings = new EPDSettings(); LOG.info("Using settings file: " + getSettings().getSettingsFile()); settings.loadFromFile(); mapHandler.add(settings); // Determine if instance already running and if that is allowed OneInstanceGuard guard = new OneInstanceGuard(getHomePath().resolve("epd.lock").toString()); if (guard.isAlreadyRunning()) { handleEpdAlreadyRunning(); } // start riskHandler startRiskHandler(); // Enable PNT timer by adding it to bean context PntTime.init(settings.getSensorSettings().isUseTimeFromPnt()); mapHandler.add(PntTime.getInstance()); // Start position handler and add to bean context pntHandler = new PntHandler(); mapHandler.add(pntHandler); // Start the multi-source PNT handler and add to bean context msPntHandler = new MultiSourcePntHandler(); msPntHandler.addPntListener(pntHandler); mapHandler.add(msPntHandler); // Start AIS target monitoring aisHandler = new AisHandler(settings.getSensorSettings(), settings.getAisSettings()); aisHandler.loadView(); EPD.startThread(aisHandler, "AisHandler"); mapHandler.add(aisHandler); // Start own-ship handler ownShipHandler = new OwnShipHandler(settings.getAisSettings()); ownShipHandler.loadView(); ownShipHandler.addListener(this); mapHandler.add(ownShipHandler); // Start dynamic predictor handler dynamicPredictorHandler = new DynamicPredictorHandler(); mapHandler.add(dynamicPredictorHandler); // Start dynamic predictor sensor sentence parser dynamicPredictorParser = new DynamicPredictorSentenceParser(); mapHandler.add(dynamicPredictorParser); // Maybe start dynamic prediction generator if (settings.getSensorSettings().isStartPredictionGenerator()) { dynamicPredictor = new DynamicPredictor(); mapHandler.add(dynamicPredictor); } // Load routeManager and register as GPS data listener routeManager = RouteManager.loadRouteManager(); mapHandler.add(routeManager); falManager = FALManager.loadFALManager(); mapHandler.add(falManager); voctManager = VOCTManager.loadVOCTManager(); mapHandler.add(voctManager); // Create shore services shoreServices = new ShoreServices(getSettings().getEnavSettings()); mapHandler.add(shoreServices); // Create mona lisa route exchange monaLisaRouteExchange = new MonaLisaRouteOptimization(); mapHandler.add(monaLisaRouteExchange); // Create NoGo handler nogoHandler = new NogoHandler(); mapHandler.add(nogoHandler); // Create Maritime Cloud service maritimeCloudService = new MaritimeCloudService(); mapHandler.add(maritimeCloudService); maritimeCloudService.start(); strategicRouteHandler = new StrategicRouteHandler(); mapHandler.add(strategicRouteHandler); // Create intended route handler intendedRouteHandler = new IntendedRouteHandler(); intendedRouteHandler.updateSettings(settings.getEnavSettings()); mapHandler.add(intendedRouteHandler); // Create the route suggestion handler // routeSuggestionHandler = new RouteSuggestionHandler(); routeSuggestionHandler = RouteSuggestionHandler.loadRouteSuggestionHandler(); mapHandler.add(routeSuggestionHandler); // Create a new MSI-NM handler msiNmHandler = new MsiNmServiceHandlerCommon(); mapHandler.add(msiNmHandler); // Create a chat service handler chatServiceHandler = new ChatServiceHandlerCommon(); mapHandler.add(chatServiceHandler); // Create voyage event dispatcher voyageEventDispatcher = new VoyageEventDispatcher(); // Create identity handler identityHandler = new IdentityHandler(); mapHandler.add(identityHandler); // Create VOCT handler voctHandler = new VoctHandler(); mapHandler.add(voctHandler); // Create FAL Handler falHandler = new FALHandler(); mapHandler.add(falHandler); // Start sensors startSensors(); // Create plugin components try { pluginLoader = new PluginLoader(getProperties(), getHomePath(), getPropertyFileName()); pluginLoader.createPluginComponents(new Consumer<Object>() { public void accept(Object comp) { mapHandler.add(comp); } }); } catch (Exception e) { LOG.error("Failed to load plugin container " + e.getMessage()); } // pluginLoader.createPluginComponents(comp -> mapHandler.add(comp)); final CountDownLatch guiCreated = new CountDownLatch(1); // Create and show GUI SwingUtilities.invokeLater(new Runnable() { @Override public void run() { createAndShowGUI(); guiCreated.countDown(); } }); // Wait for gui to be created try { guiCreated.await(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for GUI to be created", e); } // Create embedded transponder frame transponderFrame = new TransponderFrame(getHomePath().resolve("transponder.xml").toString(), true, mainFrame); mapHandler.add(transponderFrame); if (settings.getSensorSettings().isStartTransponder()) { transponderFrame.startTransponder(); } }
From source file:gedi.atac.Atac.java
public static void buildInsertionIndex(String path, boolean shortFrags, boolean longFrags, GenomicRegionStorage<? extends AlignedReadsData> storage, int condition, boolean start, boolean stop) throws IOException { DiskGenomicNumericBuilder build = new DiskGenomicNumericBuilder(path); int offset = 4; build.setReferenceSorted(true);/* ww w . j a v a 2 s.c om*/ storage.ei().progress(new ConsoleProgress(), (int) storage.size(), r -> r.toLocationStringRemovedIntrons()) .forEachRemaining(new Consumer<ImmutableReferenceGenomicRegion<? extends AlignedReadsData>>() { @Override public void accept(ImmutableReferenceGenomicRegion<? extends AlignedReadsData> mrgr) { try { int v = mrgr.getData().getTotalCountForConditionInt(condition, ReadCountMode.All); int l = mrgr.getRegion().getTotalLength(); if ((l > 180 && longFrags) || (l <= 180 && shortFrags)) { if (v != 0) { if (start) build.addValue(mrgr.getReference(), GenomicRegionPosition.Start .position(mrgr.getReference(), mrgr.getRegion(), offset), v); if (stop) build.addValue(mrgr.getReference(), GenomicRegionPosition.Stop .position(mrgr.getReference(), mrgr.getRegion(), -offset), v); } } } catch (Exception e) { throw new RuntimeException(e); } } }); build.build(); FileUtils .writeAllText( DynamicObject .from("conditions", DynamicObject.from(new Object[] { storage.getMetaData().getEntry("conditions").getEntry(condition) })) .toJson(), new File(path + ".metadata.json")); }
From source file:org.apache.pulsar.sql.presto.PulsarMetadata.java
private ConnectorTableMetadata getTableMetadata(SchemaTableName schemaTableName, boolean withInternalColumns) { if (schemaTableName.getSchemaName().equals(INFORMATION_SCHEMA)) { return null; }/*w w w . j a v a 2 s . c om*/ TopicName topicName = TopicName .get(String.format("%s/%s", schemaTableName.getSchemaName(), schemaTableName.getTableName())); List<String> topics; try { if (!PulsarConnectorUtils.isPartitionedTopic(topicName, this.pulsarAdmin)) { topics = this.pulsarAdmin.topics().getList(schemaTableName.getSchemaName()); } else { topics = this.pulsarAdmin.topics().getPartitionedTopicList((schemaTableName.getSchemaName())); } } catch (PulsarAdminException e) { if (e.getStatusCode() == 404) { throw new PrestoException(NOT_FOUND, "Schema " + schemaTableName.getSchemaName() + " does not exist"); } throw new RuntimeException("Failed to get topics in schema " + schemaTableName.getSchemaName() + ": " + ExceptionUtils.getRootCause(e).getLocalizedMessage(), e); } if (!topics.contains(topicName.toString())) { log.error("Table %s not found", String.format("%s/%s", schemaTableName.getSchemaName(), schemaTableName.getTableName())); throw new TableNotFoundException(schemaTableName); } SchemaInfo schemaInfo; try { schemaInfo = this.pulsarAdmin.schemas().getSchemaInfo( String.format("%s/%s", schemaTableName.getSchemaName(), schemaTableName.getTableName())); } catch (PulsarAdminException e) { if (e.getStatusCode() == 404) { // to indicate that we can't read from topic because there is no schema return null; } throw new RuntimeException("Failed to get schema information for topic " + String.format("%s/%s", schemaTableName.getSchemaName(), schemaTableName.getTableName()) + ": " + ExceptionUtils.getRootCause(e).getLocalizedMessage(), e); } String schemaJson = new String(schemaInfo.getSchema()); if (StringUtils.isBlank(schemaJson)) { throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema"); } Schema schema; try { schema = PulsarConnectorUtils.parseSchema(schemaJson); } catch (SchemaParseException ex) { throw new PrestoException(NOT_SUPPORTED, "Topic " + topicName.toString() + " does not have a valid schema"); } ImmutableList.Builder<ColumnMetadata> builder = ImmutableList.builder(); builder.addAll(getColumns(null, schema, new HashSet<>(), new Stack<>(), new Stack<>())); if (withInternalColumns) { PulsarInternalColumn.getInternalFields().stream().forEach(new Consumer<PulsarInternalColumn>() { @Override public void accept(PulsarInternalColumn pulsarInternalColumn) { builder.add(pulsarInternalColumn.getColumnMetadata(false)); } }); } return new ConnectorTableMetadata(schemaTableName, builder.build()); }
From source file:com.taobao.android.builder.manager.AtlasLibTaskManager.java
@Override public void runTask() { new UpdatePomTask(project).updatePom(); libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() { @Override// ww w . ja v a 2s . c om public void accept(LibraryVariant libraryVariant) { LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension); TBuildType tBuildType = libVariantContext.getBuildType(); if (null != tBuildType) { try { new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig()); } catch (Exception e) { throw new GradleException("process awo exception", e); } } AwbGenerator awbGenerator = new AwbGenerator(atlasExtension); List<LibVariantOutputData> list = libVariantContext.getVariantData().getOutputs(); if (null != list) { for (LibVariantOutputData libVariantOutputData : list) { Zip zipTask = libVariantOutputData.packageLibTask; if (atlasExtension.getBundleConfig().isJarEnabled()) { new JarExtractTask().generateJarArtifict(zipTask); } //awb extension if (atlasExtension.getBundleConfig().isAwbBundle()) { awbGenerator.generateAwbArtifict(zipTask, libVariantOutputData); } if (null != tBuildType && (StringUtils.isNotEmpty(tBuildType.getBaseApDependency()) || null != tBuildType.getBaseApFile()) && libraryVariant.getName().equals("debug")) { atlasExtension.getTBuildConfig().setUseCustomAapt(true); libVariantContext.setBundleTask(zipTask); try { libVariantContext.setAwbBundle(awbGenerator.createAwbBundle(libVariantContext)); } catch (IOException e) { throw new GradleException("set awb bundle error"); } if (atlasExtension.getBundleConfig().isAwbBundle()) { createAwoTask(libVariantContext, zipTask); } else { createDexTask(libVariantContext, zipTask); } } } } } }); }
From source file:com.taobao.android.builder.AtlasLibTaskManager.java
@Override public void runTask() { //????// w w w . j a v a 2s . com if (!atlasExtension.getBundleConfig().isMergeRes()) { new ResMerger(project).mergeRes(); } //maven?? new PublishHooker(project).hookPublish(); libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() { @Override public void accept(LibraryVariant libraryVariant) { //if ("debug".equals(libraryVariant.getBaseName())) { // new ModuleInfoWriter(project,libraryVariant).write(); //} LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension); List<Zip> zipTasks = libVariantContext.getZipTasks(); if (zipTasks.isEmpty()) { return; } for (Zip zipTask : zipTasks) { new AndroidComponetCreator(atlasExtension, project).createAndroidComponent(zipTask); //? awb jar new AwbGenerator(atlasExtension).generate(zipTask); } } }); libraryExtension.getLibraryVariants().forEach(new Consumer<LibraryVariant>() { @Override public void accept(LibraryVariant libraryVariant) { LibVariantContext libVariantContext = new LibVariantContext((LibraryVariantImpl) libraryVariant, project, atlasExtension, libraryExtension); List<Zip> zipTasks = libVariantContext.getZipTasks(); if (zipTasks.isEmpty()) { return; } for (Zip zipTask : zipTasks) { TBuildType tBuildType = libVariantContext.getBuildType(); if (null != tBuildType) { try { new AwoPropHandler().process(tBuildType, atlasExtension.getBundleConfig()); } catch (Exception e) { throw new GradleException("process awo exception", e); } } //TODO DEBUG it if (atlasExtension.getBundleConfig().isAwoBuildEnabled() && libraryVariant.getName().equals("debug")) { libVariantContext.setBundleTask(zipTask); try { libVariantContext .setAwbBundle(createAwbBundle(libVariantContext, libraryVariant.getName())); } catch (IOException e) { throw new GradleException("set awb bundle error"); } if (atlasExtension.getBundleConfig().isAwbBundle()) { createAwoTask(libVariantContext, zipTask); } else { createDexTask(libVariantContext, zipTask); } } } } }); }
From source file:gedi.atac.Atac.java
public static void buildCoverageIndex(String path, boolean shortFrags, boolean longFrags, GenomicRegionStorage<? extends AlignedReadsData> storage, int condition) throws IOException { DiskGenomicNumericBuilder build = new DiskGenomicNumericBuilder(path); int offset = 4; build.setReferenceSorted(true);/* w ww .j av a 2 s .co m*/ NumericArray buff = NumericArray.createMemory(1, NumericArrayType.Integer); storage.ei().progress(new ConsoleProgress(), (int) storage.size(), r -> r.toLocationStringRemovedIntrons()) .forEachRemaining(new Consumer<ImmutableReferenceGenomicRegion<? extends AlignedReadsData>>() { @Override public void accept(ImmutableReferenceGenomicRegion<? extends AlignedReadsData> mrgr) { try { int v = mrgr.getData().getTotalCountForConditionInt(condition, ReadCountMode.All); int l = mrgr.getRegion().getTotalLength(); if ((l > 180 && longFrags) || (l <= 180 && shortFrags)) { if (v != 0) { buff.setInt(0, v); build.addCoverageEx(mrgr.getReference(), mrgr.getRegion(), buff); } } } catch (Exception e) { throw new RuntimeException(e); } } }); build.build(true); FileUtils .writeAllText( DynamicObject .from("conditions", DynamicObject.from(new Object[] { storage.getMetaData().getEntry("conditions").getEntry(condition) })) .toJson(), new File(path + ".metadata.json")); }
From source file:com.taobao.android.builder.dependency.parser.helper.DependencyGroup.java
/** * ?bundle??//from w w w.j a va2 s .c o m * * @param bundleClasspath * @return */ private Map<String, Set<String>> getBundleProvidedMap(Configuration bundleClasspath) { Map<String, Set<String>> bundleMap = new HashMap<>(); bundleClasspath.getDependencies().forEach(new Consumer<Dependency>() { @Override public void accept(Dependency dependency) { if (dependency instanceof DefaultProjectDependency) { DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency; String key = projectDependency.getGroup() + ":" + projectDependency.getName(); Set<String> providedSets = new HashSet<>(); try { projectDependency.getDependencyProject().getConfigurations().getByName("compile") .getDependencies().forEach(new Consumer<Dependency>() { @Override public void accept(Dependency dependency) { if ("com.android.support".equals(dependency.getGroup()) || "com.android.databinding".equals(dependency.getGroup())) { providedSets.add(dependency.getGroup() + ":" + dependency.getName()); } } }); projectDependency.getDependencyProject().getConfigurations() .getByName(AtlasPlugin.PROVIDED_COMPILE).getDependencies() .forEach(new Consumer<Dependency>() { @Override public void accept(Dependency dependency) { providedSets.add(dependency.getGroup() + ":" + dependency.getName()); } }); } catch (UnknownConfigurationException e) { } bundleMap.put(key, providedSets); } } }); return bundleMap; }
From source file:gedi.atac.Atac.java
public static void buildInsertionIndex(String path, GenomicRegionStorage<? extends AlignedReadsData> storage) throws IOException { DiskGenomicNumericBuilder build = new DiskGenomicNumericBuilder(path); int offset = 4; build.setReferenceSorted(true);/*from w w w. ja v a 2 s . com*/ TreeSet<String> refs = new TreeSet<String>(); storage.getReferenceSequences().forEach(r -> refs.add(r.getName())); ConsoleProgress p = new ConsoleProgress(); Consumer<MutableReferenceGenomicRegion<? extends AlignedReadsData>> adder = new Consumer<MutableReferenceGenomicRegion<? extends AlignedReadsData>>() { @Override public void accept(MutableReferenceGenomicRegion<? extends AlignedReadsData> mrgr) { try { int v = mrgr.getData().getTotalCountOverallInt(ReadCountMode.All); if (v > 0) { build.addValue(mrgr.getReference().toPlusStrand(), GenomicRegionPosition.Start.position(mrgr.getReference(), mrgr.getRegion(), offset), v); build.addValue(mrgr.getReference().toPlusStrand(), GenomicRegionPosition.Stop.position(mrgr.getReference(), mrgr.getRegion(), -offset), v); } p.incrementProgress(); } catch (Exception e) { throw new RuntimeException(e); } } }; for (String n : refs) { p.init(); p.setDescription(n + "+"); storage.iterateMutableReferenceGenomicRegions(Chromosome.obtain(n, Strand.Plus)) .forEachRemaining(adder); p.setDescription(n + "-"); storage.iterateMutableReferenceGenomicRegions(Chromosome.obtain(n, Strand.Minus)) .forEachRemaining(adder); p.finish(); } build.build(); }
From source file:com.taobao.android.tools.TPatchTool.java
private File createTPatchFile(File outPatchDir, File patchTmpDir) throws IOException { // bundle,bundle File mainBundleFoder = new File(patchTmpDir, ((TpatchInput) input).mainBundleName); File metaFile = new File(mainBundleFoder, SO_PATCH_META); if (soFileDefs.size() > 0) { com.taobao.android.tpatch.model.PatchFile patchFile = new com.taobao.android.tpatch.model.PatchFile( metaFile);//from w ww . j av a2s. co m soFileDefs.stream().forEach(new Consumer<SoFileDef>() { @Override public void accept(SoFileDef soFileDef) { patchFile.append(soFileDef); } }); patchFile.close(); } File mainBundleFile = new File(patchTmpDir, ((TpatchInput) input).mainBundleName + ".so"); if (FileUtils.listFiles(mainBundleFoder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size() > 0) { hasMainBundle = true; CommandUtils.exec(mainBundleFoder, "zip -r " + mainBundleFile.getAbsolutePath() + " . -x */ -x .*"); } FileUtils.deleteDirectory(mainBundleFoder); // ??bundle File patchFile = null; patchFile = new File(outPatchDir, "patch-" + input.newApkBo.getVersionName() + "@" + input.baseApkBo.getVersionName() + ".tpatch"); if (patchFile.exists()) { FileUtils.deleteQuietly(patchFile); } File infoFile = new File(patchTmpDir, "patchInfo"); FileUtils.writeStringToFile(infoFile, "patch-" + input.newApkBo.getVersionName() + "@" + input.baseApkBo.getVersionName() + ".tpatch"); // zipBundle(patchTmpDir, patchFile); CommandUtils.exec(patchTmpDir, "zip -r " + patchFile.getAbsolutePath() + " . -x */ -x .*"); FileUtils.deleteDirectory(patchTmpDir); return patchFile; }
From source file:com.taobao.android.builder.tasks.library.publish.UpdatePomTask.java
private Map<String, DependencyExtraInfo> getExtraMap() { Map<String, DependencyExtraInfo> dependencyExtraInfoMap = new HashMap<>(); DependencySet dependencies = project.getConfigurations().getByName("compile").getDependencies(); dependencies.forEach(new Consumer<Dependency>() { @Override/*from w w w . j a v a 2 s . co m*/ public void accept(Dependency dependency) { String group = dependency.getGroup(); String name = dependency.getName(); String scope = "compile"; String type = ""; if (dependency instanceof DefaultProjectDependency) { DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency; if (projectDependency.getDependencyProject().getPlugins().hasPlugin(LibraryPlugin.class)) { type = "aar"; } } dependencyExtraInfoMap.put(group + ":" + name, new DependencyExtraInfo(type, scope)); } }); return dependencyExtraInfoMap; }