Codota Logo
JSONArray.length
Code IndexAdd Codota to your IDE (free)

How to use
length
method
in
org.opencms.json.JSONArray

Best Java code snippets using org.opencms.json.JSONArray.length (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
origin: org.opencms/opencms-core

/**
 * Get the optional object value associated with an index.<p>
 *
 * @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(int index) {
  return ((index < 0) || (index >= length())) ? null : m_myArrayList.get(index);
}
origin: org.opencms/opencms-solr

/**
 * Get the optional object value associated with an index.<p>
 * 
 * @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(int index) {
  return (index < 0 || index >= length()) ? null : this.m_myArrayList.get(index);
}
origin: org.opencms/opencms-solr

/**
 * Make a string from the contents of this JSONArray.<p>
 * 
 * The <code>separator</code> string is inserted between each element.<p>
 * 
 * Warning: This method assumes that the data structure is acyclical.<p>
 * 
 * @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(String separator) throws JSONException {
  int len = length();
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < len; i += 1) {
    if (i > 0) {
      sb.append(separator);
    }
    sb.append(JSONObject.valueToString(this.m_myArrayList.get(i)));
  }
  return sb.toString();
}
origin: org.opencms/opencms-core

/**
 * Make a string from the contents of this JSONArray.<p>
 *
 * The <code>separator</code> string is inserted between each element.<p>
 *
 * Warning: This method assumes that the data structure is acyclical.<p>
 *
 * @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(String separator) throws JSONException {
  int len = length();
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < len; i += 1) {
    if (i > 0) {
      sb.append(separator);
    }
    sb.append(JSONObject.valueToString(m_myArrayList.get(i)));
  }
  return sb.toString();
}
origin: org.opencms/opencms-core

/** Parses the list of query items for the query facet.
 * @param queryFacetObject JSON object representing the node with the query facet.
 * @return list of query options
 * @throws JSONException if the list cannot be parsed.
 */
private List<I_CmsFacetQueryItem> parseFacetQueryItems(final JSONObject queryFacetObject) throws JSONException {
  final JSONArray items = queryFacetObject.getJSONArray(JSON_KEY_QUERY_FACET_QUERY);
  List<I_CmsFacetQueryItem> result = new ArrayList<I_CmsFacetQueryItem>(items.length());
  for (int i = 0; i < items.length(); i++) {
    I_CmsFacetQueryItem item = parseFacetQueryItem(items.getJSONObject(i));
    if (item != null) {
      result.add(item);
    }
  }
  return result;
}
origin: org.opencms/opencms-core

/**
 * Produce a JSONObject by combining a JSONArray of names with the values
 * of this JSONArray.<p>
 *
 * @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(JSONArray names) throws JSONException {
  if ((names == null) || (names.length() == 0) || (length() == 0)) {
    return null;
  }
  JSONObject jo = new JSONObject();
  for (int i = 0; i < names.length(); i += 1) {
    jo.put(names.getString(i), opt(i));
  }
  return jo;
}
origin: org.opencms/opencms-core

/**
 * Converts the given JSON object into a valid parameter map.<p>
 *
 * @param params the JSON object to convert
 *
 * @return the parameter map from the given JSON object
 */
public static Map<String, String[]> getParameterMapFromJSON(JSONObject params) {
  Map<String, String[]> result = new HashMap<String, String[]>();
  Iterator<String> itKeys = params.keys();
  while (itKeys.hasNext()) {
    String key = itKeys.next();
    JSONArray paramValue = params.optJSONArray(key);
    result.put(key, new String[paramValue.length()]);
    for (int i = 0, l = paramValue.length(); i < l; i++) {
      result.get(key)[i] = paramValue.optString(i);
    }
  }
  return result;
}
origin: org.opencms/opencms-solr

/**
 * Produce a JSONObject by combining a JSONArray of names with the values
 * of this JSONArray.<p>
 * 
 * @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(JSONArray names) throws JSONException {
  if (names == null || names.length() == 0 || length() == 0) {
    return null;
  }
  JSONObject jo = new JSONObject();
  for (int i = 0; i < names.length(); i += 1) {
    jo.put(names.getString(i), this.opt(i));
  }
  return jo;
}
origin: org.opencms/opencms-core

/**
 * Produce a comma delimited text from a JSONArray of JSONObjects using
 * a provided list of names. The list of names is not included in the
 * output.<p>
 *
 * @param names A JSONArray of strings
 * @param ja A JSONArray of JSONObjects
 * @return A comma delimited text
 * @throws JSONException if something goes wrong
 */
public static String toString(JSONArray names, JSONArray ja) throws JSONException {
  if ((names == null) || (names.length() == 0)) {
    return null;
  }
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < ja.length(); i += 1) {
    JSONObject jo = ja.optJSONObject(i);
    if (jo != null) {
      sb.append(rowToString(jo.toJSONArray(names)));
    }
  }
  return sb.toString();
}
origin: org.opencms/opencms-solr

/**
 * Produce a comma delimited text from a JSONArray of JSONObjects using
 * a provided list of names. The list of names is not included in the
 * output.<p>
 * 
 * @param names A JSONArray of strings
 * @param ja A JSONArray of JSONObjects
 * @return A comma delimited text
 * @throws JSONException if something goes wrong
 */
public static String toString(JSONArray names, JSONArray ja) throws JSONException {
  if (names == null || names.length() == 0) {
    return null;
  }
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < ja.length(); i += 1) {
    JSONObject jo = ja.optJSONObject(i);
    if (jo != null) {
      sb.append(rowToString(jo.toJSONArray(names)));
    }
  }
  return sb.toString();
}
origin: org.opencms/opencms-core

/**
 * Produce a JSONArray containing the names of the elements of this JSONObject.<p>
 *
 * @return a JSONArray containing the key strings, or null if the JSONObject is empty.
 */
public JSONArray names() {
  JSONArray ja = new JSONArray();
  Iterator<String> keys = keys();
  while (keys.hasNext()) {
    ja.put(keys.next());
  }
  return ja.length() == 0 ? null : ja;
}
origin: org.opencms/opencms-solr

/**
 * Produce a JSONArray containing the names of the elements of this JSONObject.<p>
 * 
 * @return a JSONArray containing the key strings, or null if the JSONObject is empty.
 */
public JSONArray names() {
  JSONArray ja = new JSONArray();
  Iterator keys = keys();
  while (keys.hasNext()) {
    ja.put(keys.next());
  }
  return ja.length() == 0 ? null : ja;
}
origin: org.opencms/opencms-core

/**
 * Decodes a parameter which has been encoded from a string list using encodeStringsAsBase64Parameter.<p>
 *
 * @param data the data to decode
 * @return the list of strings
 */
public static List<String> decodeStringsFromBase64Parameter(String data) {
  data = StringUtils.replaceChars(data, BASE64_EXTRA_REPLACEMENTS, BASE64_EXTRA);
  byte[] bytes = deobfuscateBytes(Base64.decodeBase64(data));
  try {
    JSONArray json = new JSONArray(new String(bytes, "UTF-8"));
    List<String> result = Lists.newArrayList();
    for (int i = 0; i < json.length(); i++) {
      result.add(json.getString(i));
    }
    return result;
  } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (JSONException e) {
    throw new IllegalArgumentException("Decoding failed: " + data, e);
  }
  return null;
}
origin: org.opencms/opencms-core

/** Helper for reading a mandatory String value list - throwing an Exception if parsing fails.
 * @param json The JSON object where the list should be read from.
 * @param key The key of the value to read.
 * @return The value from the JSON.
 * @throws JSONException thrown when parsing fails.
 */
protected List<String> parseMandatoryStringValues(final JSONObject json, final String key) throws JSONException {
  List<String> list = null;
  JSONArray array = json.getJSONArray(key);
  list = new ArrayList<String>(array.length());
  for (int i = 0; i < array.length(); i++) {
    try {
      String entry = array.getString(i);
      list.add(entry);
    } catch (JSONException e) {
      LOG.info(Messages.get().getBundle().key(Messages.LOG_OPTIONAL_STRING_ENTRY_UNPARSABLE_1, key), e);
    }
  }
  return list;
}
origin: org.opencms/opencms-core

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.<p>
 *
 * @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(JSONArray names) throws JSONException {
  if ((names == null) || (names.length() == 0)) {
    return null;
  }
  JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1) {
    ja.put(opt(names.getString(i)));
  }
  return ja;
}
origin: org.opencms/opencms-solr

/**
 * Produce a JSONArray containing the values of the members of this
 * JSONObject.<p>
 * 
 * @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(JSONArray names) throws JSONException {
  if (names == null || names.length() == 0) {
    return null;
  }
  JSONArray ja = new JSONArray();
  for (int i = 0; i < names.length(); i += 1) {
    ja.put(this.opt(names.getString(i)));
  }
  return ja;
}
origin: org.opencms/opencms-core

/** Returns the list of the configured sort options, or the empty list if no sort options are configured.
 * @return The list of the configured sort options, or the empty list if no sort options are configured.
 */
private List<I_CmsSearchConfigurationSortOption> getSortOptions() {
  final List<I_CmsSearchConfigurationSortOption> options = new LinkedList<I_CmsSearchConfigurationSortOption>();
  try {
    final JSONArray sortOptions = m_configObject.getJSONArray(JSON_KEY_SORTOPTIONS);
    for (int i = 0; i < sortOptions.length(); i++) {
      final I_CmsSearchConfigurationSortOption option = parseSortOption(sortOptions.getJSONObject(i));
      if (option != null) {
        options.add(option);
      }
    }
  } catch (final JSONException e) {
    LOG.info(Messages.get().getBundle().key(Messages.LOG_NO_SORT_CONFIG_0), e);
  }
  return options;
}
origin: org.opencms/opencms-core

/**
 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseFieldFacets()
 */
@Override
public Map<String, I_CmsSearchConfigurationFacetField> parseFieldFacets() {
  final Map<String, I_CmsSearchConfigurationFacetField> facetConfigs = new LinkedHashMap<String, I_CmsSearchConfigurationFacetField>();
  try {
    final JSONArray fieldFacets = m_configObject.getJSONArray(JSON_KEY_FIELD_FACETS);
    for (int i = 0; i < fieldFacets.length(); i++) {
      final I_CmsSearchConfigurationFacetField config = parseFieldFacet(fieldFacets.getJSONObject(i));
      if (config != null) {
        facetConfigs.put(config.getName(), config);
      }
    }
  } catch (final JSONException e) {
    LOG.info(Messages.get().getBundle().key(Messages.LOG_NO_FACET_CONFIG_0), e);
  }
  return facetConfigs;
}
origin: org.opencms/opencms-core

/**
 * @see org.opencms.jsp.search.config.parser.I_CmsSearchConfigurationParser#parseRangeFacets()
 */
public Map<String, I_CmsSearchConfigurationFacetRange> parseRangeFacets() {
  final Map<String, I_CmsSearchConfigurationFacetRange> facetConfigs = new LinkedHashMap<String, I_CmsSearchConfigurationFacetRange>();
  try {
    final JSONArray rangeFacets = m_configObject.getJSONArray(JSON_KEY_RANGE_FACETS);
    for (int i = 0; i < rangeFacets.length(); i++) {
      final I_CmsSearchConfigurationFacetRange config = parseRangeFacet(rangeFacets.getJSONObject(i));
      if (config != null) {
        facetConfigs.put(config.getName(), config);
      }
    }
  } catch (final JSONException e) {
    LOG.info(Messages.get().getBundle().key(Messages.LOG_NO_FACET_CONFIG_0), e);
  }
  return facetConfigs;
}
origin: org.opencms/opencms-core

/**
 * Reads the folder filters for the current site.<p>
 *
 * @return the folder filters
 */
private Set<String> readFolderFilters() {
  JSONObject storedFilters = readUserFolderFilters();
  Set<String> result = null;
  if (storedFilters.has(getCmsObject().getRequestContext().getSiteRoot())) {
    try {
      org.opencms.json.JSONArray folders = storedFilters.getJSONArray(
        getCmsObject().getRequestContext().getSiteRoot());
      result = new HashSet<String>();
      for (int i = 0; i < folders.length(); i++) {
        result.add(folders.getString(i));
      }
    } catch (JSONException e) {
      LOG.error(e.getLocalizedMessage(), e);
    }
  }
  return result;
}
org.opencms.jsonJSONArraylength

Javadoc

Get the number of elements in the JSONArray, included nulls.

Popular methods of JSONArray

  • <init>
    Construct a JSONArray from a JSONTokener.
  • toString
    Make a pretty printed JSON text of this JSONArray. Warning: This method assumes that the data struct
  • get
    Get the object value associated with an index.
  • getBoolean
    Get the boolean value associated with an index. The string values "true" and "false" are converted t
  • getDouble
    Get the double value associated with an index.
  • getInt
    Get the int value associated with an index.
  • getLong
    Get the long value associated with an index.
  • getString
    Get the string associated with an index.
  • join
    Make a string from the contents of this JSONArray. The separator string is inserted between each ele
  • opt
    Get the optional object value associated with an index.
  • optBoolean
    Get the optional boolean value associated with an index. It returns the defaultValue if there is no
  • optDouble
    Get the optional double value associated with an index. The defaultValue is returned if there is no
  • optBoolean,
  • optDouble,
  • optInt,
  • optJSONObject,
  • optLong,
  • optString,
  • put,
  • toJSONObject,
  • write

Popular in Java

  • Reactive rest calls using spring rest template
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • startActivity (Activity)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • Path (java.nio.file)
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • TimerTask (java.util)
    A task that can be scheduled for one-time or repeated execution by a Timer.
  • TreeSet (java.util)
    A NavigableSet implementation based on a TreeMap. The elements are ordered using their Comparable, o
  • JFileChooser (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now