com.atlassian.jira.util.json.JSONArray.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(127)

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

JSONArray.<init>介绍

[英]Construct an empty JSONArray.
[中]构造一个空的JSONArray。

代码示例

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

/**
 * Put a value in the JSONArray, where the value will be a
 * JSONArray which is produced from a Collection.
 *
 * @param value A Collection value.
 * @return this.
 */
public JSONArray put(final Collection<Object> value)
{
  put(new JSONArray(value));
  return this;
}

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

@Override
public String failureReason()
{
  if (failureReasons.isEmpty())
  {
    return null;
  }
  if (failureReasons.size() == 1)
  {
    return failureReasons.get(0);
  }
  return new JSONArray(failureReasons).toString();
}

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

/**
 * Put a key/value pair in the JSONObject, where the value will be a
 * JSONArray which is produced from a Collection.
 *
 * @param key   A key string.
 * @param values A Collection value.
 * @return this.
 * @throws JSONException If the value is non-finite number or if the key is null.
 */
public JSONObject put(final String key, final Collection<Object> values) throws JSONException
{
  put(key, new JSONArray(values));
  return this;
}

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

/**
 * Put a value in the JSONArray, where the value will be a
 * JSONArray which is produced from a Collection.
 *
 * @param index The subscript.
 * @param value A Collection value.
 * @return this.
 * @throws JSONException If the index is negative or if the value is
 *                       not finite.
 */
public JSONArray put(final int index, final Collection<? extends Object> value) throws JSONException
{
  put(index, new JSONArray(value));
  return this;
}

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

public String getEffectiveApplicationsJson()
{
  return new JSONArray(effectiveApplications.stream().map(EffectiveApplication::getKey).collect(CollectorsUtil.toImmutableSet())).toString();
}

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

public static SharePermissions fromJsonArrayString(final String jsonString) throws JSONException
{
  notNull("jsonString", jsonString);
  if (StringUtils.isBlank(jsonString))
  {
    return SharePermissions.PRIVATE;
  }
  else
  {
    return SharePermissionUtils.fromJsonArray(new JSONArray(jsonString));
  }
}

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

public static AttachmentArchive fromJSONArrayQuiet(final String jsonArrayString, final int maxSize)
{
  try
  {
    final JSONArray jsonArray = new JSONArray(jsonArrayString);
    final ImmutableList.Builder<AttachmentArchiveEntry> builder = ImmutableList.builder();
    final int maxIndex = Math.min(jsonArray.length(), maxSize);
    for (int i = 0; i < maxIndex; i++)
    {
      builder.add(FROM_JSON.apply(jsonArray.getJSONObject(i)));
    }
    final List<AttachmentArchiveEntry> entries = builder.build();
    return new AttachmentArchiveImpl(entries, jsonArray.length());
  }
  catch (final JSONException ignore)
  {
    log.error(String.format("Invalid jsonArray supplied: %s", jsonArrayString));
    return null;
  }
}

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

private Collection<RemoteProject> parseProjects(final String response, final ApplicationLink applicationLink)
      throws ResponseException, CredentialsRequiredException
  {
    try
    {
      JSONArray json = new JSONArray(response);
      int length = json.length();
      final Collection<RemoteProject> projects = new ArrayList<RemoteProject>(length);
      for (int i = 0; i < length; i++)
      {
        projects.add(RemoteProject.from(applicationLink, json.getJSONObject(i)));
      }
      return projects;
    }
    catch (JSONException ex)
    {
      throw new RuntimeException("Unable to parse the JSON response for get projects : " + response, ex);
    }
  }
}

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

public JiraEntityLogEntry(DateTime timestamp, String entry, String existingEntry)
{
  this.timestamp = timestamp;
  this.entry = entry;
  this.last = createJSONEntry(timestamp, entry);
  final JSONArray jsonArray = new JSONArray();
  jsonArray.put(this.last);
  this.all = StringUtils.isBlank(existingEntry) ? jsonArray : parseExistingArray(existingEntry);
}

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

public static ImmutableMap<String, JSONObject> getCommentPropertiesFromParameters(final Map<String, Object> commentParams)
      throws JSONException
  {
    if (commentParams.containsKey(PARAM_COMMENT_PROPERTY))
    {
      final String[] array = (String[]) commentParams.get(PARAM_COMMENT_PROPERTY);
      if (array != null && array.length == 1)
      {
        final JSONArray jsonArray = new JSONArray(array[0]);
        final ImmutableMap.Builder<String, JSONObject> builder = ImmutableMap.builder();
        for (int i = 0; i < jsonArray.length(); i++)
        {
          JSONObject object = jsonArray.getJSONObject(i);
          builder.put(object.getString("key"), object.getJSONObject("value"));
        }
        return builder.build();
      }
    }
    return ImmutableMap.of();
  }
}

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

public JSONArray getAnnouncementsData()
  {
    final Option<ApplicationUser> applicationUser = Option.option(authContext.getUser());

    final List<String> activitiesIds = Lists.transform(postSetupAnnouncements.getReadyAnnouncements(applicationUser), new Function<PostSetupAnnouncementStatus, String>()
    {
      @Override
      public String apply(final PostSetupAnnouncementStatus input)
      {
        return input.getActivityId();
      }
    });

    return new JSONArray(activitiesIds);
  }
}

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

public String getJqlReservedWordsJson() throws JSONException
{
  final Set<String> reservedWords = jqlStringSupport.getJqlReservedWords();
  JSONArray results = new JSONArray();
  for (String reservedWord : reservedWords)
  {
    results.put(reservedWord);
  }
  return results.toString();
}

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

/**
   * Returns the content of the DarkFeatures &lt;meta&gt; tag. This will be a JSON array literal,
   * e.g. <code>[ "feat1", "feat2" ]</code>.
   *
   * @return a String containing a Javscript array literal with the enabled dark feature names
   */
  String getContent()
  {
    Set<String> keys = featureManager.getDarkFeatures().getAllEnabledFeatures();

    return new JSONArray(keys).toString();
  }
}

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

private Option<String> generateArchiveFileIndex(final @Nonnull File file, final @Nonnull Attachment attachment)
{
  final Iterable<AttachmentProcessorModuleDescriptor> filteredProcessors = filterProcessors(attachment);
  if (Iterables.isEmpty(filteredProcessors))
  {
    return Option.none();
  }
  final AttachmentProcessorModuleDescriptor firstDescriptor = filteredProcessors.iterator().next();
  final List<AttachmentArchiveEntry> entries = firstDescriptor.getModule().processAttachment(file);
  final Iterable<JSONObject> jsons = AttachmentArchiveImpl.serialize(entries);
  final JSONArray array = new JSONArray(Lists.newArrayList(
      Iterables.filter(jsons, new TotalLengthPredicate(EntityConstants.EXTREMELY_LONG_MAXIMUM_LENGTH))));
  return Option.some(array.toString());
}

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

/**
 * Produce a JSONArray containing the names of the elements of this
 * JSONObject.
 *
 * @return A JSONArray containing the key strings, or null if the JSONObject
 *         is empty.
 */
public JSONArray names()
{
  final JSONArray ja = new JSONArray();
  for (final String key : keySet())
  {
    ja.put(key);
  }
  return ja.length() == 0 ? null : ja;
}

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

/**
 * Converts the passed SharePermissions into a JSON array.
 * 
 * @param permissions the permissions to convert.
 * @return the JSON array.
 * @throws JSONException if an error occurs while creating the JSONArray.
 */
public static JSONArray toJsonArray(final Collection<SharePermission> permissions) throws JSONException
{
  notNull("permission", permissions);
  final JSONArray array = new JSONArray();
  for (final SharePermission sharePermission : permissions)
  {
    array.put(SharePermissionUtils.toJson(sharePermission));
  }
  return array;
}

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

private JSONArray parseExistingArray(final String existingJson)
{
  JSONArray jsonArray = new JSONArray();
  try
  {
    jsonArray = new JSONObject(existingJson).optJSONArray(ALL_KEY);
  }
  catch (JSONException e)
  {
    // swallow the exception
  }
  jsonArray.put(createJSONEntry(timestamp, entry));
  return jsonArray;
}

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

/**
 * Convert the {@code userFilter} to {@code JSONObject}
 * @param userFilter the user filter to be converted
 * @param projectRoleManager optional, if provided, will be used to filter invalid project roles
 * @throws JSONException
 */
public static JSONObject toJson(final UserFilter userFilter, final ProjectRoleManager projectRoleManager) throws JSONException
{
  checkNotNull(userFilter, "userFilter");
  final JSONObject object = new JSONObject();
  object.put(KEY_ENABLED, userFilter.isEnabled());
  if (userFilter.isEnabled())
  {
    object.put(KEY_GROUPS, new JSONArray(sortGroups(userFilter.getGroups())));
    object.put(KEY_ROLEIDS, new JSONArray(
        projectRoleManager != null ?
          filterRemovedRoleIds(userFilter.getRoleIds(), projectRoleManager) :
          userFilter.getRoleIds()));
  }
  return object;
}

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

/**
 * Returns a json string of [ {name: groupName}, ... ]
 */
private String getGroupsAsJsonString(final Collection<Group> groups)
{
  JSONArray root = new JSONArray();
  for (Group group : groups)
  {
    JSONObject groupJson = new JSONObject();
    try
    {
      groupJson.put("name", group.getName());
    }
    catch (JSONException e)
    {
      log.warn("skipping project role object that could not converted to json: " + group.getName() + " - " + e.getMessage());
    }
    root.put(groupJson);
  }
  return root.toString();
}

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

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.
 *
 * @param names A JSONArray containing a list of key strings. This
 *              determines the sequence of the values in the result.
 * @return A JSONArray of values.
 * @throws JSONException If any of the values are non-finite numbers.
 */
public JSONArray toJSONArray(final JSONArray names) throws JSONException
{
  if ((names == null) || (names.length() == 0))
  {
    return null;
  }
  final JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1)
  {
    ja.put(opt(names.getString(i)));
  }
  return ja;
}

相关文章