Search in sources :

Example 16 with Objects

use of java.util.Objects in project robo4j by Robo4J.

the class RaspistillUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    Map<String, String> parameters = new HashMap<>();
    parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
    parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
    parameters.put(KEY_EXPOSURE, configuration.getString(KEY_EXPOSURE, "sport"));
    parameters.put(KEY_BRIGHTNESS, configuration.getString(KEY_BRIGHTNESS, null));
    parameters.put(KEY_SHARPNESS, configuration.getString(KEY_SHARPNESS, null));
    parameters.put(KEY_CONTRAST, configuration.getString(KEY_CONTRAST, null));
    parameters.put(KEY_TIMEOUT, configuration.getString(KEY_TIMEOUT, "1"));
    parameters.put(KEY_TIMELAPSE, configuration.getString(KEY_TIMELAPSE, "100"));
    parameters.put(KEY_ROTATION, configuration.getString(KEY_ROTATION, null));
    //@formatter:off
    cameraCommand = new StringBuilder().append(RaspistillUtils.RASPISTILL_COMMAND).append(Constants.UTF8_SPACE).append(parameters.entrySet().stream().filter(p -> Objects.nonNull(p.getValue())).map(e -> {
        StringBuilder c = new StringBuilder();
        if (RaspistillUtils.isOption(e.getKey())) {
            return c.append(RaspistillUtils.getOption(e.getKey())).append(Constants.UTF8_SPACE).append(e.getValue()).toString();
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.joining(Constants.UTF8_SPACE))).append(Constants.UTF8_SPACE).append(DEFAULT_IMAGE_SETUP).toString();
    SimpleLoggingUtil.print(getClass(), "cameraCommand:" + cameraCommand);
    //@formatter:on
    targetOut = configuration.getString("targetOut", null);
    String tmpClient = configuration.getString("client", null);
    if (tmpClient == null || targetOut == null) {
        throw ConfigurationException.createMissingConfigNameException("targetOut, client");
    }
    storeTarget = configuration.getString("storeTarget", null);
    try {
        InetAddress inetAddress = InetAddress.getByName(tmpClient);
        String clientPort = configuration.getString("clientPort", null);
        client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
        clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
    } catch (UnknownHostException e) {
        SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
        throw ConfigurationException.createMissingConfigNameException("unknown ip address");
    }
}
Also used : KEY_SHARPNESS(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_SHARPNESS) CameraMessageCodec(com.robo4j.core.httpunit.codec.CameraMessageCodec) FORMAT_IMAGE(com.robo4j.units.rpi.camera.RaspistillUtils.FORMAT_IMAGE) KEY_TIMEOUT(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_TIMEOUT) KEY_TIMELAPSE(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_TIMELAPSE) HashMap(java.util.HashMap) RoboUnit(com.robo4j.core.RoboUnit) InetAddress(java.net.InetAddress) KEY_CONTRAST(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_CONTRAST) CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) KEY_HEIGHT(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_HEIGHT) SimpleLoggingUtil(com.robo4j.core.logging.SimpleLoggingUtil) Map(java.util.Map) RoboContext(com.robo4j.core.RoboContext) KEY_WIDTH(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_WIDTH) Configuration(com.robo4j.core.configuration.Configuration) DEFAULT(com.robo4j.units.rpi.camera.RaspistillUtils.DEFAULT) Constants(com.robo4j.core.httpunit.Constants) LifecycleState(com.robo4j.core.LifecycleState) CameraClientException(com.robo4j.hw.rpi.camera.CameraClientException) KEY_ROTATION(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_ROTATION) KEY_EXPOSURE(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_EXPOSURE) ConfigurationException(com.robo4j.core.ConfigurationException) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Base64(java.util.Base64) RaspistilDevice(com.robo4j.hw.rpi.camera.RaspistilDevice) KEY_BRIGHTNESS(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_BRIGHTNESS) RoboHttpUtils(com.robo4j.core.client.util.RoboHttpUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Objects(java.util.Objects) InetAddress(java.net.InetAddress)

Example 17 with Objects

use of java.util.Objects in project intellij-plugins by StepicOrg.

the class AbstractMoveHandlerDelegate method doMove.

@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
    StringBuilder message = new StringBuilder();
    if (sources.size() > 1) {
        message.append("You can not move the following elements:");
    } else {
        PsiFileSystemItem source = sources.get(0);
        message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
    }
    for (PsiFileSystemItem file : sources) {
        message.append("\n").append(file.getVirtualFile().getPath());
    }
    MessagesEx.error(project, message.toString(), "Move").showNow();
}
Also used : MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) Arrays(java.util.Arrays) ProjectPsiFilesUtils.isNotMovableOrRenameElement(org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement) MoveCallback(com.intellij.refactoring.move.MoveCallback) MessagesEx(com.intellij.openapi.ui.ex.MessagesEx) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils.isCanNotBeTarget(org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils)

Example 18 with Objects

use of java.util.Objects in project intellij-community by JetBrains.

the class PropertiesInheritorsSearcher method processQuery.

@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
    final PsiElement element = queryParameters.getElement();
    Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
    if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
        return;
    }
    ReadAction.run(() -> {
        final String key = prop.getKey();
        if (!prop.isValid() || key == null)
            return;
        final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
        LOG.assertTrue(currentFile != null);
        final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
        currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
            ProgressManager.checkCanceled();
            return !consumer.process(psiElement);
        });
    });
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Property(com.intellij.lang.properties.psi.Property) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DefinitionsScopedSearch(com.intellij.psi.search.searches.DefinitionsScopedSearch) ReadAction(com.intellij.openapi.application.ReadAction) QueryExecutorBase(com.intellij.openapi.application.QueryExecutorBase) Objects(java.util.Objects) IProperty(com.intellij.lang.properties.IProperty) PropertiesImplUtil(com.intellij.lang.properties.PropertiesImplUtil) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PropertiesUtil(com.intellij.lang.properties.PropertiesUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Objects(java.util.Objects) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty) PsiElement(com.intellij.psi.PsiElement)

Example 19 with Objects

use of java.util.Objects in project EnrichmentMapApp by BaderLab.

the class CreateDiseaseSignatureNetworkTask method createHubNode.

/**
	 * Creates a signature hub node if it doesn't already exist.
	 * Otherwise it updates the attributes of the existing node.
	 */
private void createHubNode(String hubName, CyNetwork network, CyNetworkView netView, String prefix, CyTable edgeTable, CyTable nodeTable, Set<Integer> geneUniverse, GeneSet sigGeneSet, EMSignatureDataSet sigDataSet) {
    // Test for existing node first
    CyNode hubNode = NetworkUtil.getNodeWithValue(network, nodeTable, CyNetwork.NAME, hubName);
    if (hubNode == null) {
        hubNode = network.addNode();
        taskResult.addNewNode(hubNode);
    }
    sigDataSet.addNodeSuid(hubNode.getSUID());
    network.getRow(hubNode).set(CyNetwork.NAME, hubName);
    String formattedLabel = CreateEMNetworkTask.formatLabel(hubName);
    CyRow row = nodeTable.getRow(hubNode.getSUID());
    Columns.NODE_FORMATTED_NAME.set(row, prefix, null, formattedLabel);
    List<String> geneList = sigGeneSet.getGenes().stream().map(map::getGeneFromHashKey).filter(Objects::nonNull).sorted().collect(Collectors.toList());
    List<String> enrGeneList = sigGeneSet.getGenes().stream().filter(geneUniverse::contains).map(map::getGeneFromHashKey).filter(Objects::nonNull).sorted().collect(Collectors.toList());
    Columns.NODE_GENES.set(row, prefix, null, geneList);
    Columns.NODE_ENR_GENES.set(row, prefix, null, enrGeneList);
    Columns.NODE_GS_DESCR.set(row, prefix, null, sigGeneSet.getDescription());
    Columns.NODE_GS_TYPE.set(row, prefix, null, Columns.NODE_GS_TYPE_SIGNATURE);
    Columns.NODE_NAME.set(row, prefix, null, sigGeneSet.getName());
    Columns.NODE_GS_SIZE.set(row, prefix, null, sigGeneSet.getGenes().size());
    //		// Add the geneset of the signature node to the GenesetsOfInterest,
    //		// as the Heatmap will grep it's data from there.
    //		EMDataSet dataSet = map.getDataSet(dataSetName);
    //		Set<Integer> sigGenesInDataSet = ImmutableSet.copyOf(Sets.intersection(sigGeneSet.getGenes(), dataSet.getDataSetGenes()));
    //		GeneSet geneSetInDataSet = new GeneSet(sigGeneSet.getName(), sigGeneSet.getDescription(), sigGenesInDataSet);
    //		dataSet.getGeneSetsOfInterest().getGeneSets().put(hubName, geneSetInDataSet);
    nodeCache.put(hubName, hubNode);
}
Also used : Objects(java.util.Objects) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow)

Example 20 with Objects

use of java.util.Objects in project geode by apache.

the class ClusterConfigurationService method downloadJarFromOtherLocators.

// used in the cluster config change listener when jarnames are changed in the internal region
public void downloadJarFromOtherLocators(String groupName, String jarName) throws IllegalStateException, IOException {
    logger.info("Getting Jar files from other locators");
    DM dm = this.cache.getDistributionManager();
    DistributedMember me = this.cache.getMyId();
    Set<DistributedMember> locators = new HashSet<>(dm.getAllHostedLocatorsWithSharedConfiguration().keySet());
    locators.remove(me);
    createConfigDirIfNecessary(groupName);
    byte[] jarBytes = locators.stream().map((DistributedMember locator) -> downloadJarFromLocator(locator, groupName, jarName)).filter(Objects::nonNull).findFirst().orElseThrow(() -> new IllegalStateException("No locators have a deployed jar named " + jarName + " in " + groupName));
    File jarToWrite = getPathToJarOnThisLocator(groupName, jarName).toFile();
    FileUtils.writeByteArrayToFile(jarToWrite, jarBytes);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Objects(java.util.Objects) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

Objects (java.util.Objects)55 List (java.util.List)29 Map (java.util.Map)24 Collectors (java.util.stream.Collectors)22 ArrayList (java.util.ArrayList)20 Set (java.util.Set)19 Optional (java.util.Optional)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 Collections (java.util.Collections)13 HashSet (java.util.HashSet)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 Result (ddf.catalog.data.Result)9 Stream (java.util.stream.Stream)9 Metacard (ddf.catalog.data.Metacard)8 TimeUnit (java.util.concurrent.TimeUnit)8 LoggerFactory (org.slf4j.LoggerFactory)8 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 Path (java.nio.file.Path)7 Logger (org.slf4j.Logger)7