/* (non-Javadoc)
@see mtas.solr.handler.util.MtasSolrBaseList#createListOutput(boolean, int)
16416
@Override
  public SimpleOrderedMap<Object> createListOutput(boolean shardRequests, int number) {
    SimpleOrderedMap<Object> output = super.createListOutput(shardRequests, number);
    output.add(NAME_SOFTLIMIT, softLimit);
    output.add(NAME_HARDLIMIT, hardLimit);
    return output;
  }
1130746
private List onRead(EntityMetadata m, List<Map<String, Object>> columnsToOutput, Table hTable,
            List<HBaseDataWrapper> results) throws IOException
    {
        Class clazz = m.getEntityClazz();
        List outputResults = new ArrayList();
        try
        {
            if (results != null)
            {
                return columnsToOutput != null && !columnsToOutput.isEmpty() ? returnSpecificFieldList(m,
                        columnsToOutput, results, outputResults) : returnEntityObjectList(m, results, outputResults);
            }
        }
        catch (Exception e)
        {
            logger.error("Error while creating an instance of {}, Caused by: .", clazz, e);
            throw new PersistenceException(e);
        }
        finally
        {
            if (hTable != null)
            {
                closeHTable(hTable);
            }
        }
        return outputResults;
    }
1312039
protected final void listUpdate(List list, int index, Object value) {
        Object converted = value;

        if(list.size() > index) {
            Object o = list.get(index);
            // can only convert types when there is an item in the currently requested place
            if(o != null) {
                Class itemType = o.getClass();
                converted = ParseUtils.convertType(value, itemType);
            }

            list.set(index, value);
        } else {
            // @note: not sure that this is the right thing.  Question is whether or not to insert nulls here to fill list up to "index"
            // @update: List doesn't guarantee that implementations will accept nulls.  So, we can't rely on that as a solution.
            // @update: this is an unfortunate but necessary solution...unless the List has enough elements to 
            // accomodate the new item at a particular index, this must be an error case.  The reasons are this:
            // 1) can't fill the list with nulls, List implementations are allowed to disallow them
            // 2) can't just do an "add" to the list -- in processing [0] and [1] on an empty list, [1] may get processed first. 
            //    this will go into list slot [0].  then, [0] gets processed and simply overwrites the previous because it's 
            //    already in the list
            // 3) can't go to a mixed approach because there's no metadata about what has been done and no time to build
            //    something that is apt to be complicated and exposed to the user
            // so...
            // the ultimate 8.1sp2 functionality is to simply disallow updating a value in a list that doesn't exist.  that 
            // being said, it is still possible to simply add to the list.  if {actionForm.list[42]} inserts into the 42'nd 
            // item, {actionForm.list} will just do an append on POST since there is no index specified.  this fix does 
            // not break backwards compatability because it will work on full lists and is completely broken now on empty 
            // lists, so changing this just gives a better exception message that "ArrayIndexOutOfBounds".  :)
            // 
            // September 2, 2003
            // ekoneil@apache.com
            // 
            String msg = "An error occurred setting a value at index \"" +
                index +
                "\" because the list is " +
                (list != null ? (" of size " + list.size()) : "null") + ".  " +
                "Be sure to allocate enough items in the List to accomodate any updates which may occur against the list.";

            LOGGER.error(msg);
            throw new RuntimeException(msg);
        }
    }
310377
public static void writeToList(CodedOutputStream out, int order, FieldType type, List list) throws IOException {
        if (list == null) {
            return;
        }
        for (Object object : list) {
            writeObject(out, order, type, object, true);
        }

    }
156205
@Override
    public Result createOutput(String namespaceUri, String defaultFileName)
        throws IOException {
        if (null == fileName) {
            fileName = defaultFileName;
        }
        return new StreamResult(new File(baseDir, fileName));
    }
1346338
private SimpleOrderedMap<Object> createOutput(boolean detailed) {
    // checkResponseOnException();
    SimpleOrderedMap<Object> output = new SimpleOrderedMap<>();
    updateShardInfo();
    output.add(NAME_KEY, key);
    output.add(NAME_REQUEST, request);
    if (errorStatus) {
      output.add(NAME_ERROR, errorMessage);
    }
    if (abortStatus) {
      output.add(NAME_ABORT, abortMessage);
    }
    output.add(NAME_FINISHED, finished);
    if (totalTime != null) {
      output.add(NAME_TIME_TOTAL, totalTime);
    }
    output.add(NAME_TIME_START, (new Date(startTime)).toString());
    output.add(NAME_SHARDREQUEST, shardRequest);
    if (shardNumberTotal > 0) {
      if (detailed) {
        output.add(NAME_STATUS_DISTRIBUTED, createShardsOutput());
      } else {
        output.add(NAME_STATUS_DISTRIBUTED, true);
      }
    } else if (detailed) {
      output.add(NAME_STATUS_DISTRIBUTED, false);
    }
    if (status.numberSegmentsTotal != null) {
      output.add(NAME_STATUS_SEGMENT_NUMBER_TOTAL, status.numberSegmentsTotal);
      output.add(NAME_STATUS_SEGMENT_NUMBER_FINISHED, status.numberSegmentsFinished);
      if (!status.subNumberSegmentsFinished.isEmpty()) {
        output.add(NAME_STATUS_SEGMENT_SUB_NUMBER_FINISHED, status.subNumberSegmentsFinished);
        output.add(NAME_STATUS_SEGMENT_SUB_NUMBER_TOTAL, status.subNumberSegmentsTotal);
        output.add(NAME_STATUS_SEGMENT_SUB_NUMBER_FINISHED_TOTAL, status.subNumberSegmentsFinishedTotal);
      }
    }
    if (status.numberDocumentsTotal != null) {
      output.add(NAME_STATUS_DOCUMENT_NUMBER_TOTAL, status.numberDocumentsTotal);
      output.add(NAME_STATUS_DOCUMENT_NUMBER_FOUND, status.numberDocumentsFound);
      output.add(NAME_STATUS_DOCUMENT_NUMBER_FINISHED, status.numberDocumentsFinished);
      if (!status.subNumberDocumentsFinished.isEmpty()) {
        output.add(NAME_STATUS_DOCUMENT_SUB_NUMBER_FINISHED, status.subNumberDocumentsFinished);
        output.add(NAME_STATUS_DOCUMENT_SUB_NUMBER_TOTAL, status.subNumberDocumentsTotal);
        output.add(NAME_STATUS_DOCUMENT_SUB_NUMBER_FINISHED_TOTAL, status.subNumberDocumentsFinishedTotal);
      }
    }
    return output;
  }
739076
public static <T> void writeListTo(LinkedBuffer buffer,
            List<T> messages, Schema<T> schema, boolean numeric)
    {
        if (buffer.start != buffer.offset)
        {
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");
        }

        if (messages.isEmpty())
        {
            return;
        }

        MsgpackXOutput output = new MsgpackXOutput(buffer, numeric, schema);

        try
        {

            for (T m : messages)
            {

                LinkedBuffer objectStarter = output.writeStartObject();
                schema.writeTo(output, m);

                if (output.isLastRepeated())
                {
                    output.writeEndArray();
                }

                output.writeEndObject(objectStarter);

            }

        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
    }
89571
public static <T> void writeListTo(LinkedBuffer buffer,
            List<T> messages, Schema<T> schema, boolean numeric)
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        if (messages.isEmpty())
        {
            System.arraycopy(EMPTY_ARRAY, 0, buffer.buffer, buffer.offset, EMPTY_ARRAY.length);
            buffer.offset += EMPTY_ARRAY.length;
            return;
        }

        final JsonXOutput output = new JsonXOutput(buffer, numeric, schema);

        try
        {
            output.writeStartArray();

            boolean first = true;
            for (T m : messages)
            {
                if (first)
                {
                    first = false;
                    output.writeStartObject();
                }
                else
                    output.writeCommaAndStartObject();

                schema.writeTo(output, m);
                if (output.isLastRepeated())
                    output.writeEndArray();

                output.writeEndObject().reset();
            }

            output.writeEndArray();
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }
    }
768353
public void setOutputDetails(java.util.Collection<OutputDetail> outputDetails) {
        if (outputDetails == null) {
            this.outputDetails = null;
            return;
        }

        this.outputDetails = new java.util.ArrayList<OutputDetail>(outputDetails);
    }
190703
public SimpleOrderedMap<Object> create(ComponentList list, Boolean encode) {
    SimpleOrderedMap<Object> mtasListResponse = new SimpleOrderedMap<>();
    mtasListResponse.add("key", list.key);
    if (list.number == 0) {
      mtasListResponse.add("total", list.total);
    }
    if (list.output != null) {
      ArrayList<NamedList<Object>> mtasListItemResponses = new ArrayList<>();
      if (list.output.equals(ComponentList.LIST_OUTPUT_HIT)) {
        mtasListResponse.add("number", list.hits.size());
        for (ListHit hit : list.hits) {
          NamedList<Object> mtasListItemResponse = new SimpleOrderedMap<>();
          mtasListItemResponse.add("documentKey",
              list.uniqueKey.get(hit.docId));
          mtasListItemResponse.add("documentHitPosition", hit.docPosition);
          mtasListItemResponse.add("documentHitTotal",
              list.subTotal.get(hit.docId));
          mtasListItemResponse.add("documentMinPosition",
              list.minPosition.get(hit.docId));
          mtasListItemResponse.add("documentMaxPosition",
              list.maxPosition.get(hit.docId));
          mtasListItemResponse.add("startPosition", hit.startPosition);
          mtasListItemResponse.add("endPosition", hit.endPosition);

          SortedMap<Integer, List<List<String>>> hitData = new TreeMap<>();
          SortedMap<Integer, List<List<String>>> leftData = null;
          SortedMap<Integer, List<List<String>>> rightData = null;
          if (list.left > 0) {
            leftData = new TreeMap<>();
          }
          if (list.right > 0) {
            rightData = new TreeMap<>();
          }
          for (int position = Math.max(0,
              hit.startPosition - list.left); position <= (hit.endPosition
                  + list.right); position++) {
            List<List<String>> hitDataItem = new ArrayList<>();
            if (hit.hits.containsKey(position)) {
              for (String term : hit.hits.get(position)) {
                List<String> hitDataSubItem = new ArrayList<>();
                hitDataSubItem.add(CodecUtil.termPrefix(term));
                hitDataSubItem.add(CodecUtil.termValue(term));
                hitDataItem.add(hitDataSubItem);
              }
            }
            if (position < hit.startPosition) {
              if (leftData != null) {
                leftData.put(position, hitDataItem);
              }
            } else if (position > hit.endPosition) {
              if (rightData != null) {
                rightData.put(position, hitDataItem);
              }
            } else {
              hitData.put(position, hitDataItem);
            }
          }
          if (list.left > 0) {
            mtasListItemResponse.add("left", leftData);
          }
          mtasListItemResponse.add("hit", hitData);
          if (list.right > 0) {
            mtasListItemResponse.add("right", rightData);
          }
          mtasListItemResponses.add(mtasListItemResponse);
        }
      } else if (list.output.equals(ComponentList.LIST_OUTPUT_TOKEN)) {
        mtasListResponse.add("number", list.tokens.size());
        for (ListToken tokenHit : list.tokens) {
          NamedList<Object> mtasListItemResponse = new SimpleOrderedMap<>();
          mtasListItemResponse.add("documentKey",
              list.uniqueKey.get(tokenHit.docId));
          mtasListItemResponse.add("documentHitPosition", tokenHit.docPosition);
          mtasListItemResponse.add("documentHitTotal",
              list.subTotal.get(tokenHit.docId));
          mtasListItemResponse.add("documentMinPosition",
              list.minPosition.get(tokenHit.docId));
          mtasListItemResponse.add("documentMaxPosition",
              list.maxPosition.get(tokenHit.docId));
          mtasListItemResponse.add("startPosition", tokenHit.startPosition);
          mtasListItemResponse.add("endPosition", tokenHit.endPosition);

          ArrayList<NamedList<Object>> mtasListItemResponseItemTokens = new ArrayList<>();
          for (MtasToken token : tokenHit.tokens) {
            NamedList<Object> mtasListItemResponseItemToken = new SimpleOrderedMap<>();
            if (token.getId() != null) {
              mtasListItemResponseItemToken.add("mtasId", token.getId());
            }
            mtasListItemResponseItemToken.add("prefix", token.getPrefix());
            mtasListItemResponseItemToken.add("value", token.getPostfix());
            if (token.getPositionStart() != null) {
              mtasListItemResponseItemToken.add("positionStart",
                  token.getPositionStart());
              mtasListItemResponseItemToken.add("positionEnd",
                  token.getPositionEnd());
            }
            if (token.getPositions() != null) {
              mtasListItemResponseItemToken.add("positions",
                  Arrays.toString(token.getPositions()));
            }
            if (token.getParentId() != null) {
              mtasListItemResponseItemToken.add("parentMtasId",
                  token.getParentId());
            }
            if (token.getPayload() != null) {
              mtasListItemResponseItemToken.add("payload", token.getPayload());
            }
            if (token.getOffsetStart() != null) {
              mtasListItemResponseItemToken.add("offsetStart",
                  token.getOffsetStart());
              mtasListItemResponseItemToken.add("offsetEnd",
                  token.getOffsetEnd());
            }
            if (token.getRealOffsetStart() != null) {
              mtasListItemResponseItemToken.add("realOffsetStart",
                  token.getRealOffsetStart());
              mtasListItemResponseItemToken.add("realOffsetEnd",
                  token.getRealOffsetEnd());
            }
            mtasListItemResponseItemTokens.add(mtasListItemResponseItemToken);
          }
          mtasListItemResponse.add("tokens", mtasListItemResponseItemTokens);
          mtasListItemResponses.add(mtasListItemResponse);
        }
      }
      mtasListResponse.add(NAME, mtasListItemResponses);
    }
    return mtasListResponse;
  }
960949
@Override
    public List<KeyedMessageWithType> invokeOutput(final T instance) throws DempsyException {
        if (outputMethods == null)
            return emptyKeyedMessageList;

        final List<KeyedMessageWithType> ret = new ArrayList<>();
        for (final Method om : outputMethods) {
            final Object or = wrap(() -> om.invoke(instance));
            if (or != null) {
                ret.addAll(convertToKeyedMessage(or));
            }
        }

        return ret.size() == 0 ? null : ret;
    }
1354521
private void createOutputFile() throws IOException {
        this.fileChannel = Files.newByteChannel(Paths.get(filePath), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
    }
1233852
protected Map<String, Map<Integer, Set<String>>> createUpdateList() {
    Map<String, Map<Integer, Set<String>>> updateList = new HashMap<>();
    updateList.put(UPDATE_TYPE_OFFSET, new HashMap<>());
    updateList.put(UPDATE_TYPE_POSITION, new HashMap<>());
    updateList.put(UPDATE_TYPE_LOCAL_REF_POSITION_START, new HashMap<>());
    updateList.put(UPDATE_TYPE_LOCAL_REF_POSITION_END, new HashMap<>());
    updateList.put(UPDATE_TYPE_LOCAL_REF_OFFSET_START, new HashMap<>());
    updateList.put(UPDATE_TYPE_LOCAL_REF_OFFSET_END, new HashMap<>());
    updateList.put(UPDATE_TYPE_VARIABLE, new HashMap<>());
    return updateList;
  }
524285
public static <L> ListenerList<L> addListener (ListenerList<L> list, L listener)
    {
        if (list == null) {
            list = new ListenerList<L>();
        }
        list.add(listener);
        return list;
    }
358634
@Override
    public <T extends EventListener> T  createListener(Class<T> classToCreate) throws ServletException {        
        boolean valid = false;
        
        T listener = super.createListener(classToCreate);
        
        for (Class c : validListenerClasses) {
            if (c != null && c.isAssignableFrom(classToCreate)) {
                valid = true;
            }
        }
        
        if (!valid) {
            throw new IllegalArgumentException(nls.getString("exception.occurred.while.creating.listener.instance"));
        }
        
        return listener;
    }
65661
int createList() {
		int node = newList_();
		if (m_b_allow_navigation_between_lists) {
			m_lists.setField(node, 3, m_list_of_lists);
			if (m_list_of_lists != nullNode())
				m_lists.setField(m_list_of_lists, 2, node);
			m_list_of_lists = node;
		}

		return node;
	}
630658
public static <T> void writeListTo(OutputStream out, List<T> messages, 
            Schema<T> schema, boolean numeric) throws IOException
    {
        final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), 
                out, false);
        
        final SmileGenerator generator = newSmileGenerator(out, 
                context.allocWriteEncodingBuffer(), 0, true, context);
        
        //final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out);
        try
        {
            JsonIOUtil.writeListTo(generator, messages, schema, numeric);
        }
        finally
        {
            generator.close();
        }
    }