本文整理了Java中com.atlassian.jira.util.json.JSONArray.length()
方法的一些代码示例,展示了JSONArray.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.length()
方法的具体详情如下:
包路径:com.atlassian.jira.util.json.JSONArray
类名称:JSONArray
方法名:length
[英]Get the number of elements in the JSONArray, included nulls.
[中]获取JSONArray中的元素数,包括null。
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Get the optional object value associated with an index.
*
* @param index The index must be between 0 and length() - 1.
* @return An object value, or null if there is no
* object at that index.
*/
public Object opt(final int index)
{
return ((index < 0) || (index >= length())) ? null : list.get(index);
}
代码示例来源:origin: com.atlassian.jira/jira-api
private static Collection<Long> getRoleIds(final JSONArray jsonArray) throws JSONException
{
Set<Long> roleIds = Sets.newHashSetWithExpectedSize(jsonArray.length());
for (int i = 0 ; i<jsonArray.length(); i++)
{
roleIds.add(jsonArray.getLong(i));
}
return roleIds;
}
代码示例来源:origin: com.atlassian.jira/jira-api
private static Collection<String> getGroups(final JSONArray jsonArray) throws JSONException
{
Set<String> groups = Sets.newHashSetWithExpectedSize(jsonArray.length());
for (int i = 0 ; i<jsonArray.length(); i++)
{
groups.add(jsonArray.getString(i));
}
return groups;
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Make a string from the contents of this JSONArray. The
* <code>separator</code> string is inserted between each element.
* Warning: This method assumes that the data structure is acyclical.
*
* @param separator A string that will be inserted between the elements.
* @return a string.
* @throws JSONException If the array contains an invalid number.
*/
public String join(final String separator) throws JSONException
{
final int len = length();
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i += 1)
{
if (i > 0)
{
sb.append(separator);
}
sb.append(JSONObject.valueToString(list.get(i)));
}
return sb.toString();
}
代码示例来源: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 static List<String> parseShortcut(String shortcut) throws JSONException
{
if (JSON_VALUE_ARRAY.matcher(shortcut).matches())
{
final JSONArray array = new JSONArray(shortcut);
final List<String> result = Lists.newArrayListWithCapacity(array.length());
for (int i = 0; i < array.length(); i++) {
result.add(array.getString(i));
}
return result;
}
else if (JSON_VALUE_STRING.matcher(shortcut).matches())
{
final String key = "shortcut";
JSONObject json = new JSONObject(String.format("{ \"%s\": %s }", key, shortcut));
return Arrays.asList(json.getString(key));
}
else
{
final List<String> result = new ArrayList<String>();
for (char c : shortcut.toCharArray())
{
result.add(String.valueOf(c));
}
return result;
}
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Produce a JSONObject by combining a JSONArray of names with the values
* of this JSONArray.
*
* @param names A JSONArray containing a list of key strings. These will be
* paired with the values.
* @return A JSONObject, or null if there are no names or if this JSONArray
* has no values.
* @throws JSONException If any of the names are null.
*/
public JSONObject toJSONObject(final JSONArray names) throws JSONException
{
if ((names == null) || (names.length() == 0) || (length() == 0))
{
return null;
}
final JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1)
{
jo.put(names.getString(i), opt(i));
}
return jo;
}
代码示例来源:origin: com.atlassian.jira/jira-api
/**
* Convert the passed array into SharePermissions.
*
* @param array the JSON array to convert.
* @return the converted SharePermission.
* @throws JSONException if an error occurs during convertion.
*/
public static SharePermissions fromJsonArray(final JSONArray array) throws JSONException
{
notNull("array", array);
final Set<SharePermission> permissions = new HashSet<SharePermission>(array.length());
for (int i = 0; i < array.length(); i++)
{
permissions.add(SharePermissionUtils.fromJsonObject(array.getJSONObject(i)));
}
return new SharePermissions(permissions);
}
代码示例来源: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-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.jira/jira-core
private List<SearchRequest> toSearchRequests(final ApplicationUser user, final JSONObject json) throws JSONException
{
final JSONArray jsonArray = json.getJSONArray(IDS);
final List<SearchRequest> filters = Lists.newArrayList();
for (int i = 0; i < jsonArray.length(); i++)
{
final long filterId = jsonArray.getLong(i);
final SearchRequest filter = searchRequestService.getFilter(new JiraServiceContextImpl(user), filterId);
if (filter != null)
{
filters.add(filter);
}
}
return ImmutableList.copyOf(filters);
}
代码示例来源: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;
}
代码示例来源:origin: com.atlassian.jira/jira-api
if (index < length())
while (index != length())
代码示例来源: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.plugin.deflection/deflection-cse
public static boolean resultMatches(JSONObject result, Iterable<String> patternToMatch) throws JSONException
{
final JSONArray labels = result.optJSONArray("perResultLabels");
if (labels != null)
{
for (int idx = 0; idx < labels.length(); idx++)
{
String label = labels.getJSONObject(idx).getString("label");
for (String pattern : patternToMatch)
{
if (label.equals(pattern))
{
return true;
}
}
}
}
return false;
}
}
代码示例来源:origin: com.marvelution.jira.plugins/jira-jenkins-plugin
@Override
public List<Job> getJobs() {
List<Job> jobs = Lists.newArrayList();
try {
RestResponse response = executeGetRequest("/api/json", CALL_TIMEOUT);
if (response.getJson() != null && response.getJson().has("jobs")) {
JSONArray json = response.getJson().getJSONArray("jobs");
LOGGER.info("Found {} jobs", new Object[] { json.length() });
for (int index = 0; index < json.length(); index++) {
final JSONObject jsonJob = json.getJSONObject(index);
jobs.add(new Job(site.getId(), jsonJob.getString("name")));
}
} else {
handleNoJsonResponse(response);
}
} catch (CredentialsRequiredException e) {
LOGGER.error("Authentication failure on {} [{}]: {}", new Object[] { applicationLink.getName(),
applicationLink.getDisplayUrl(), e.getMessage() });
} catch (JSONException e) {
LOGGER.error("Failed to get the Job list from {}: {}", applicationLink.getName(), e.getMessage());
}
return jobs;
}
代码示例来源:origin: com.atlassian.plugin.deflection/deflection-hot-issues
protected List<SearchResult> searchJQL(int filterID, String filterName) throws IOException, JSONException
{
List<SearchResult> results = Lists.newArrayList();
JSONArray issueList = new JSONObject(searchResults(filterID)).getJSONArray("issues");
for (int i = 0; i < issueList.length(); i++)
{
JSONObject issue = issueList.getJSONObject(i);
String title = issue.getString("key");
String content = issue.getJSONObject("fields").getString("summary");
String url = JAC_BASE_URL + "/browse/" + issue.getString("key");
String source = "HotIssues" + filterName;
results.add(new DefaultSearchResult(content, url, title, source, ""));
}
return results;
}
代码示例来源:origin: com.atlassian.plugin.deflection/deflection-cse
@Override
public final boolean shouldAddResult(JSONObject result) throws JSONException
{
final JSONArray labels = result.optJSONArray("perResultLabels");
if (labels != null)
{
for (int idx = 0; idx < labels.length(); idx++)
{
String label = labels.getJSONObject(idx).getString("label");
if (CAC.equals(label))
{
return ConfluenceResultMatcher.resultMatches(result, getCacPattern());
}
else if (JAC.equals(label))
{
return JIRAResultMatcher.resultMatches(result, getJacPattern());
}
else if (AAC.equals(label))
{
return AnswersResultMatcher.resultMatches(result, getAacPattern());
}
}
}
// No matching response parser, so we don't know whether to add. Return false for now
return false;
}
代码示例来源:origin: com.atlassian.cpji/cpji-jira-plugin
private static ErrorCollection convertJsonToErrorCollection(final JSONObject json)
{
final ErrorCollection errors = new SimpleErrorCollection();
try
{
final JSONArray errorMessages = json.getJSONArray("errorMessages");
for (int i = 0; i < errorMessages.length(); i++)
{
errors.addErrorMessage(errorMessages.getString(i));
}
final JSONObject errorsMap = json.getJSONObject("errors");
final Iterator<String> keys = errorsMap.keys();
while (keys.hasNext())
{
final String key = keys.next();
errors.addError(key, errorsMap.getString(key));
}
}
catch (final JSONException e)
{
return null;
}
return errors;
}
代码示例来源:origin: com.atlassian.jirawallboard/atlassian-wallboard-plugin
static public WallboardPluginSettings loadSettings(PluginSettingsFactory pluginSettingsFactory, ApplicationUser user)
{
WallboardPluginSettings settings = new WallboardPluginSettings(pluginSettingsFactory, user);
Object val = pluginSettingsFactory.createGlobalSettings().get(WALLBOARD_KEY + mapNullToBlank(settings.userKey));
if (val == null)
{
settings.isConfigured = false;
return settings;
}
JSONObject jsonRepresentation;
try
{
jsonRepresentation = new JSONObject((String) val);
JSONArray rawDashboardIds = jsonRepresentation.getJSONArray("dashboardIds");
settings.dashboardIds = new ArrayList<>(rawDashboardIds.length());
for (int i = 0; i < rawDashboardIds.length(); i++)
{
settings.dashboardIds.add(i, (String) rawDashboardIds.get(i));
}
settings.setCyclePeriod(jsonRepresentation.getInt(WallboardServlet.CYCLE_PERIOD.getKey()));
settings.setTransitionFx(jsonRepresentation.getString(WallboardServlet.TRANSITION_FX.getKey()));
settings.setRandom(jsonRepresentation.getBoolean(WallboardServlet.RANDOM.getKey()));
}
catch (JSONException e)
{
settings.isConfigured = false;
}
return settings;
}
内容来源于网络,如有侵权,请联系作者删除!