com.atlassian.fugue.Option.flatMap()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.atlassian.fugue.Option.flatMap()方法的一些代码示例,展示了Option.flatMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.flatMap()方法的具体详情如下:
包路径:com.atlassian.fugue.Option
类名称:Option
方法名:flatMap

Option.flatMap介绍

暂无

代码示例

代码示例来源:origin: com.atlassian.jira/jira-core

private Option<TemporaryWebAttachmentsMonitor> getMonitorFromSession(final Option<HttpSession> sessionOption)
{
  return sessionOption.flatMap(session ->
      Option.option((TemporaryWebAttachmentsMonitor) session.getAttribute(SessionKeys.TEMP_WEB_ATTACHMENTS)));
}

代码示例来源:origin: com.atlassian.plugins/base-hipchat-integration-plugin-api

@Override
public Option<HipChatLinkId> getHipChatLinkId() {
  return hipChatLinkProvider.getDefaultLink().flatMap(new Function<HipChatLink, Option<HipChatLinkId>>() {
    @Override
    public Option<HipChatLinkId> apply(HipChatLink link) {
      return Option.some(link.getId());
    }
  });
}

代码示例来源:origin: com.atlassian.jira/jira-core

private Option<ApplicationRole> toApplicationRole(final String applicationId)
{
  return toApplicationKey(applicationId).flatMap(applicationRoleManager::getRole);
}

代码示例来源:origin: com.atlassian.plugins/base-hipchat-integration-plugin

@Override
  public Option<SessionData> apply(HipChatUserId hipChatUserId) {
    return hipChatAOUserManager.getByUserKey(user).flatMap(new Function<AOHipChatUser, Option<SessionData>>() {
      @Override
      public Option<SessionData> apply(AOHipChatUser aoHipChatUser) {
        return Option.some(
            new SessionData(
                aoHipChatUser.getHipChatLink().getGroupName(),
                aoHipChatUser.getHipChatUserName(),
                aoHipChatUser.getHipChatLink().getApiUrl()));
      }
    });
  }
});

代码示例来源:origin: com.atlassian.labs.hipchat/hipchat-for-jira-plugin

@Override
  public Option<User> load(final String idOrEmailAddress) {
    return hipChatLinkProvider.getDefaultLink()
                 .flatMap(new Function<HipChatLink, Option<User>>() {
                   @Override
                   public Option<User> apply(HipChatLink link) {
                     return link.getAddonApi()
                           .users()
                           .getUser(idOrEmailAddress)
                           .claim()
                           .option();
                   }
                 });
  }
},

代码示例来源:origin: com.atlassian.jira/jira-core

private Option<ErrorCollection> validateAvatar(final ApplicationUser user, final IssueTypeUpdateInput issueTypeCreateInput)
{
  return issueTypeCreateInput.getAvatarId().flatMap(new Function<Long, Option<ErrorCollection>>()
  {
    @Override
    public Option<ErrorCollection> apply(final Long avatarId)
    {
      final Avatar avatar = avatarService.getAvatar(user, avatarId);
      if (avatar == null)
      {
        return errorCollection("avatarId", i18n.getText("admin.errors.project.no.avatar.with.id"), VALIDATION_FAILED);
      }
      return none();
    }
  });
}

代码示例来源:origin: com.atlassian.jira/jira-core

private boolean hasSingleAnnotation(final Method method)
{
  return option(method.getAnnotation(ActionViewData.class)).flatMap(new Function<ActionViewData, Option<String>>()
  {
    @Override
    public Option<String> apply(final ActionViewData input)
    {
      return option(input.value());
    }
  }).flatMap(new Function<String, Option<Boolean>>()
  {
    @Override
    public Option<Boolean> apply(@Nullable final String value)
    {
      return option(actionResult.equals(value) || "*".equals(value));
    }
  }).getOrElse(false);
}

代码示例来源:origin: com.atlassian.labs.hipchat/hipchat-for-jira-plugin

@Override
public Option<DedicatedRoom> getDedicatedRoom(final Issue issue) {
  return hipChatService.getApiUrl().flatMap(new Function<String, Option<DedicatedRoom>>() {
    @Override
    public Option<DedicatedRoom> apply(final String apiUrl) {
      return dedicatedRoomDAO.getDedicatedRoom(issue.getId())
                  .map(new Function<DedicatedRoom, DedicatedRoom>() {
                    @Override
                    public DedicatedRoom apply(DedicatedRoom room) {
                      return DedicatedRoomDTO.builder(room)
                                 .setApiUrl(domainManager.getDefaultDomain())
                                 .build();
                    }
                  });
    }
  });
}

代码示例来源:origin: com.atlassian.plugins/atlassian-connect-server-integration-tests-support

public Option<String> getHttpHeaderFromLastRequest(final String name) {
  Predicate<String> equalsIgnoreCase = headerName -> headerName.equalsIgnoreCase(name);
  Option<String> maybeHeaderName = Iterables.findFirst(this.headersFromLastRequest.keySet(), equalsIgnoreCase);
  return maybeHeaderName.flatMap(headerName -> Option.option(headersFromLastRequest.get(headerName)));
}

代码示例来源:origin: com.atlassian.jira/jira-core

private boolean hasMultiAnnotation(final Method method)
  {
    return option(method.getAnnotation(ActionViewDataMappings.class)).flatMap(new Function<ActionViewDataMappings, Option<String[]>>()
    {
      @Override
      public Option<String[]> apply(final ActionViewDataMappings input)
      {
        return option(input.value());
      }
    }).flatMap(new Function<String[], Option<Boolean>>()
    {
      @Override
      public Option<Boolean> apply(final String[] input)
      {
        for (String s : input)
        {
          if (actionResult.equals(s))
          {
            return option(true);
          }
        }
        return option(false);
      }
    }).getOrElse(false);
  }
}

代码示例来源:origin: com.atlassian.labs.hipchat/hipchat-for-jira-plugin

@Nullable
  // when we figure out how to get a link to a room this will need to be passed the room...
  private URI getRootURI() {
    return hipChat.getApiUrl().flatMap(new Function<String, Option<URI>>() {
      @Override
      public Option<URI> apply(@Nullable String apiUrlString) {
        try {
          URI api = new URI(apiUrlString);
          return Option.some(new URI(api.getScheme(), api.getHost(), "/chat", null));
        } catch (URISyntaxException e) {
          return Option.none();
        }
      }
    }).getOrNull();
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
@Nonnull
public Option<String> getHelpSpace(@Nonnull final ApplicationKey applicationKey)
{
  return applicationManager.getApplication(applicationKey)
      .flatMap(app -> featureManager.isOnDemand() ? app.getProductHelpCloudSpaceURI() : app.getProductHelpServerSpaceURI())
      .map(uri -> uri.toString());
}

代码示例来源:origin: com.atlassian.jira/jira-rest-plugin

private Option<PermissionHolderType> getActorType(final PermissionGrantBean grantBean)
  {
    return Option.option(grantBean.getHolder()).flatMap(new Function<PermissionHolderBean, Option<PermissionHolderType>>()
    {
      @Override
      public Option<PermissionHolderType> apply(final PermissionHolderBean holder)
      {
        return option(holder.getType()).map(new Function<String, PermissionHolderType>()
        {
          @Override
          public PermissionHolderType apply(final String holderType)
          {
            return PermissionHolderTypeMapping.fromRestType(holderType).orElse(permissionHolderType(holderType, holder.getParameter()));
          }
        });
      }
    });
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

return applications.flatMap(new Function<Iterable<Application>, Option<? extends Application>>()

代码示例来源:origin: com.atlassian.labs.hipchat/hipchat-for-jira-plugin

/**
 * Stores a T against the given issue id. It won't do anything if the given value is None
 *
 * @param issueId the issueId to store against
 * @param key the key for the issue property to store value as
 * @param value the value to store
 * @throws java.lang.IllegalArgumentException if value is null or can not be serialised
 * @throws java.lang.IllegalStateException if an error is thrown during serialisation or serialisation fails
 */
public void put(final long issueId, final String key, @Nonnull final Option<T> value) {
  checkNotNull(value, "value is null. Pass an option.none() instead.");
  final Option<String> valueAsJson = value.flatMap(new Function<T, Option<String>>() {
    @Override
    public Option<String> apply(T input) {
      try {
        return Option.option(OBJECT_MAPPER.writeValueAsString(input));
      } catch (IOException e) {
        log.error("Error serialising value to JSON: " + input, e);
        return Option.none();
      }
    }
  });
  if (valueAsJson.isEmpty()) {
    log.error("Error serialising value to JSON: " + value.getOrNull());
    throw new IllegalStateException("Value could not be serialised to JSON.");
  }
  //TODO: remove call to deprecated method: https://jira.atlassian.com/browse/HC-10752
  jsonEntityPropertyManager.put(entityName, issueId, key, valueAsJson.get());
}

代码示例来源:origin: com.atlassian.jira/jira-core

/**
 * To support old temporary attachments we will use TemporaryAttachmentsMonitor
 */
private boolean allAttachmentExistsInOldMonitor(final List<String> temporaryAttachmentEntryIds)
{
  //noinspection deprecation
  return Option.option(temporaryAttachmentsMonitorLocator.get(false)).flatMap(new Function<TemporaryAttachmentsMonitor, Option<Boolean>>()
  {
    @Override
    public Option<Boolean> apply(@Nullable final TemporaryAttachmentsMonitor monitor)
    {
      return convertToLongIds(temporaryAttachmentEntryIds).map(new Function<List<Long>, Boolean>()
      {
        @Override
        public Boolean apply(@Nullable final List<Long> longIds)
        {
          return allAttachmentExistsInOldMonitor(longIds, monitor);
        }
      });
    }
  }).getOrElse(false);
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public Option<String> getUrl(final Map<String, Object> context)
{
  if (urlProvider != null)
  {
    return SafePluginPointAccess.call(new Callable<Option<String>>()
    {
      @Override
      public Option<String> call() throws Exception
      {
        return urlProvider.getUrl(ReportModuleDescriptorImpl.this, context);
      }
    }).flatMap(Functions.<Option<String>>identity());
  }
  Project project = (Project) context.get("project");
  return Option.option(MessageFormat.format(PARAMS_PATTERN, url, project.getId(), project.getName(), getCompleteKey()));
}

代码示例来源:origin: com.atlassian.jira/jira-core

public static PluginInfo addFailures(final PluginInfo pluginInfo, final Throwable cause)
{
  final List<String> copiedCauses = copyPreviousCauses(pluginInfo);
  Option<List<String>> capturedCauses = option(cause).flatMap(CAPTURE_CAUSES);
  if (capturedCauses.isDefined())
  {
    copiedCauses.addAll(capturedCauses.get());
  }
  return new PluginInfo(pluginInfo.pluginKey, pluginInfo.pluginName, pluginInfo.pluginArtifact, option(copiedCauses), pluginInfo.dependencies);
}

代码示例来源:origin: com.atlassian.jira/jira-core

public String getPostSetupRedirect(Option<String> origin) throws URISyntaxException
{
  final Option<Application> applicationWithPostInstall = getApplicationWithPostInstall();
  final Option<URI> postInstallUri = applicationWithPostInstall.flatMap(new Function<Application, Option<URI>>()
  {
    @Override
    public Option<URI> apply(final Application input)
    {
      return input.getPostInstallURI();
    }
  });
  final String rawUri = postInstallUri.getOrElse(getDefaultPostSetupURI()).toASCIIString();
  final String redirectWithOrigin = origin.fold(Suppliers.ofInstance(rawUri), new Function<String, String>()
  {
    @Override
    public String apply(final String input)
    {
      return addParameterToURI(rawUri, input);
    }
  });
  return redirectWithOrigin;
}

代码示例来源:origin: com.atlassian.jira/jira-core

private boolean isAllowedToPickAvatar(final String ownerId, Avatar.Type type)
{
  final ApplicationUser user = authenticationContext.getUser();
  if (type == Avatar.Type.USER)
  {
    return avatarManager.hasPermissionToEdit(user, userUtil.getUserByKey(ownerId));
  }
  else {
    final Option<TypeAvatarService> avatars = Option.option(universalAvatarsService.getAvatars(type));
    final Option<Boolean> canCreateAvatarOption = avatars.flatMap(new Function<TypeAvatarService, Option<Boolean>>()
    {
      @Override
      public Option<Boolean> apply(final TypeAvatarService typeAvatarService)
      {
        return Option.some(typeAvatarService.canUserCreateAvatar(user, ownerId));
      }
    });
    return canCreateAvatarOption.getOrElse(Boolean.FALSE);
  }
}

相关文章