/* (non-Javadoc)
@see org.apache.hadoop.mapred.Mapper#map(java.lang.Object, java.lang.Object, org.apache.hadoop.mapred.OutputCollector, org.apache.hadoop.mapred.Reporter)
192891
public void map(DocumentID key, LineDocTextAndOp value,
      OutputCollector<DocumentID, DocumentAndOp> output, Reporter reporter)
      throws IOException {

    DocumentAndOp.Op op = value.getOp();
    Document doc = null;
    Term term = null;

    if (op == DocumentAndOp.Op.INSERT || op == DocumentAndOp.Op.UPDATE) {
      doc = new Document();
      doc.add(new Field(docidFieldName, key.getText().toString(),
          Field.Store.YES, Field.Index.UN_TOKENIZED));
      doc.add(new Field(contentFieldName, value.getText().toString(),
          Field.Store.NO, Field.Index.TOKENIZED));
    }

    if (op == DocumentAndOp.Op.DELETE || op == DocumentAndOp.Op.UPDATE) {
      term = new Term(docidFieldName, key.getText().toString());
    }

    output.collect(key, new DocumentAndOp(op, doc, term));
  }
1304969
private <T extends ProgramElementDoc> void mapTypeParameters(Map<String,List<T>> map, Object doc,
            T holder) {
        TypeVariable[] typeVariables;
        if (doc instanceof ClassDoc) {
            typeVariables = ((ClassDoc) doc).typeParameters();
        } else if (doc instanceof WildcardType) {
            for (Type extendsBound : ((WildcardType) doc).extendsBounds()) {
                addTypeParameterToMap(map, extendsBound, holder);
            }
            for (Type superBound : ((WildcardType) doc).superBounds()) {
                addTypeParameterToMap(map, superBound, holder);
            }
            return;
        } else if (doc instanceof ParameterizedType) {
            for (Type typeArgument : ((ParameterizedType) doc).typeArguments()) {
                addTypeParameterToMap(map, typeArgument, holder);
            }
            return;
        } else if (doc instanceof ExecutableMemberDoc) {
            typeVariables = ((ExecutableMemberDoc) doc).typeParameters();
        } else if (doc instanceof FieldDoc) {
            Type fieldType = ((FieldDoc) doc).type();
            mapTypeParameters(map, fieldType, holder);
            return;
        } else {
            return;
        }
        for (TypeVariable typeVariable : typeVariables) {
            for (Type bound : typeVariable.bounds()) {
                addTypeParameterToMap(map, bound, holder);
            }
        }
    }
1214929
private void mapArrayCollectionToVertex(ITypedInstance typedInstance, AtlasVertex instanceVertex,
                                            AttributeInfo attributeInfo, Operation operation) throws AtlasException {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Mapping instance {} for array attribute {} vertex {}", typedInstance.toShortString(),
                    attributeInfo.name, string(instanceVertex));
        }

        List newElements = (List) typedInstance.get(attributeInfo.name);
        boolean newAttributeEmpty = (newElements == null || newElements.isEmpty());

        IDataType elementType = ((DataTypes.ArrayType) attributeInfo.dataType()).getElemType();
        String propertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo);

        List<Object> currentElements = GraphHelper.getArrayElementsProperty(elementType, instanceVertex, propertyName);

        List<Object> newElementsCreated = new ArrayList<>();

        if (!newAttributeEmpty) {
            int index = 0;
            for (; index < newElements.size(); index++) {
                Object currentElement = (currentElements != null && index < currentElements.size()) ?
                        currentElements.get(index) : null;
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Adding/updating element at position {}, current element {}, new element {}", index,
                            currentElement, newElements.get(index));
                }

                Object newEntry = addOrUpdateCollectionEntry(instanceVertex, attributeInfo, elementType,
                        newElements.get(index), currentElement, propertyName, operation);
                newElementsCreated.add(newEntry);
            }
        }

        if(GraphHelper.isReference(elementType)) {
            if (attributeInfo.reverseAttributeName != null && newElementsCreated.size() > 0) {
                // Set/add the new reference value(s) on the reverse reference.
                for (Object newElement : newElementsCreated) {
                    if ((newElement instanceof AtlasEdge)) {
                        AtlasEdge newEdge = (AtlasEdge) newElement;
                        addReverseReference(instanceVertex, attributeInfo.reverseAttributeName, newEdge);
                    }
                    else {
                        throw new AtlasException("Invalid array element type " + newElement.getClass().getName() + " - expected " + AtlasEdge.class.getName() +
                            " for reference " + GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo) + " on vertex " + GraphHelper.getVertexDetails(instanceVertex));
                    }
                }
            }

            List<AtlasEdge> additionalEdges = removeUnusedEntries(instanceVertex, propertyName, (List)currentElements,
                    (List)newElementsCreated, elementType, attributeInfo);
            newElementsCreated.addAll(additionalEdges);
        }

        // for dereference on way out
        GraphHelper.setArrayElementsProperty(elementType, instanceVertex, propertyName, newElementsCreated);
    }
1346435
private ObjectMapper createObjectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new JodaModule());
        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        return mapper;
    }
659928
public static void saveMapping(final Writer out,
                                   final DSLMapping mapping) throws IOException {
        for (DSLMappingEntry dslMappingEntry : mapping.getEntries()) {
            out.write(dslMappingEntry.toString());
            out.write("\n");
        }
    }
580884
public void writeResult(Map<BioPAXElement, List<Match>> matches, OutputStream out)
		throws IOException
	{
		writeResultDetailed(matches, out, 5);
	}
6837
public void serialize(Map<String, T> map, JsonGenerator jsonGenerator) throws IOException {
        jsonGenerator.writeStartObject();
        for (Map.Entry<String, T> entry : map.entrySet()) {
            jsonGenerator.writeFieldName(entry.getKey());
            if (entry.getValue() == null) {
                jsonGenerator.writeNull();
            } else {
                serialize(entry.getValue(), jsonGenerator, true);
            }
        }
        jsonGenerator.writeEndObject();
    }
919829
public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {
    // init
    if (outThread_ == null) {
      startOutputThreads(output, reporter);
    }
    if (outerrThreadsThrowable != null) {
      mapRedFinished();
      throw new IOException ("MROutput/MRErrThread failed:"
                             + StringUtils.stringifyException(
                                                              outerrThreadsThrowable));
    }
    try {
      // 1/4 Hadoop in
      numRecRead_++;
      maybeLogRecord();
      if (debugFailDuring_ && numRecRead_ == 3) {
        throw new IOException("debugFailDuring_");
      }

      // 2/4 Hadoop to Tool
      if (numExceptions_ == 0) {
        if (!this.ignoreKey) {
          write(key);
          clientOut_.write('\t');
        }
        write(value);
        if(!this.skipNewline) {
            clientOut_.write('\n');
        }
        // clientOut_.flush();
      } else {
        numRecSkipped_++;
      }
    } catch (IOException io) {
      numExceptions_++;
      if (numExceptions_ > 1 || numRecWritten_ < minRecWrittenToEnableSkip_) {
        // terminate with failure
        String msg = logFailure(io);
        appendLogToJobLog("failure");
        mapRedFinished();
        throw new IOException(msg);
      } else {
        // terminate with success:
        // swallow input records although the stream processor failed/closed
      }
    }
  }
1225799
@Override
	public final void map(INPUT_KEY key, INPUT_VALUE value, Context context)
	    throws IOException, InterruptedException {
		map(key, value, this.context, collector);
	}
198502
private void writeMap(String fieldName, Object value) throws IOException
   {
      @SuppressWarnings("unchecked")
      Map<String, Object> map = (Map<String, Object>) value;
      m_writer.writeStartObject(fieldName);
      for (Map.Entry<String, Object> entry : map.entrySet())
      {
         Object entryValue = entry.getValue();
         if (entryValue != null)
         {
            DataType type = TYPE_MAP.get(entryValue.getClass().getName());
            if (type == null)
            {
               type = DataType.STRING;
               entryValue = entryValue.toString();
            }
            writeField(entry.getKey(), type, entryValue);
         }
      }
      m_writer.writeEndObject();
   }
29141
public static <T_Result, T_Source> List<T_Result> map(Collection<T_Source> source,
            Mapper<T_Result, T_Source> mapper) {
        List<T_Result> result = new LinkedList<T_Result>();
        for (T_Source element : source) {
            result.add(mapper.map(element));
        }
        return result;
    }
503504
private <T extends ProgramElementDoc> void mapTypeParameters(Map<String,List<T>> map, Object doc,
            T holder) {
        TypeVariable[] typeVariables;
        if (doc instanceof ClassDoc) {
            typeVariables = ((ClassDoc) doc).typeParameters();
        } else if (doc instanceof WildcardType) {
            Type[] extendsBounds = ((WildcardType) doc).extendsBounds();
            for (int k = 0; k < extendsBounds.length; k++) {
                addTypeParameterToMap(map, extendsBounds[k], holder);
            }
            Type[] superBounds = ((WildcardType) doc).superBounds();
            for (int k = 0; k < superBounds.length; k++) {
                addTypeParameterToMap(map, superBounds[k], holder);
            }
            return;
        } else if (doc instanceof ParameterizedType) {
            Type[] typeArguments = ((ParameterizedType) doc).typeArguments();
            for (int k = 0; k < typeArguments.length; k++) {
                addTypeParameterToMap(map, typeArguments[k], holder);
            }
            return;
        } else if (doc instanceof ExecutableMemberDoc) {
            typeVariables = ((ExecutableMemberDoc) doc).typeParameters();
        } else if (doc instanceof FieldDoc) {
            Type fieldType = ((FieldDoc) doc).type();
            mapTypeParameters(map, fieldType, holder);
            return;
        } else {
            return;
        }
        for (int i = 0; i < typeVariables.length; i++) {
            Type[] bounds = typeVariables[i].bounds();
            for (int j = 0; j < bounds.length; j++) {
                addTypeParameterToMap(map, bounds[j], holder);
            }
        }
    }
1350456
private void writeMapComplex(SerIterator itemIterator) throws IOException {
        output.writeObjectStart();
        while (itemIterator.hasNext()) {
            itemIterator.next();
            Object key = itemIterator.key();
            if (key == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be null");
            }
            String str = settings.getConverter().convertToString(itemIterator.key());
            if (str == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be a null string");
            }
            output.writeObjectKey(str);
            writeObject(itemIterator.valueType(), itemIterator.value(), itemIterator);
        }
        output.writeObjectEnd();
    }
282386
@Deprecated
    public void close(org.apache.hadoop.mapred.Reporter reporter) throws IOException
    {
        close();
    }
123026
@Override
    protected void writeToOutput(final Map<String, Object> row)
            throws IOException {
        if (generator == null) {
            ObjectMapper mapper = new ObjectMapper();
            JsonFactory factory = new JsonFactory(mapper);
            generator = factory.createGenerator(getWriter());
            generator.writeStartArray(); // [
        }

        // Convert the row into a map
        generator.writeObject(row);
    }
412012
public static void jsonMap(JsonWriter writer, Map<String, Object> map) throws IOException {
        if (map != null) {
            writer.beginObject();
            jsonMapEntries(writer, map);
            writer.endObject();
        }
    }
1229014
public void toJson(Map<?, ?> map, Writer writer) throws IOException {
    if (map == null) {
      throw new IllegalArgumentException("map == null");
    }
    if (writer == null) {
      throw new IllegalArgumentException("writer == null");
    }

    JsonWriter jsonWriter = new JsonWriter(writer);
    jsonWriter.setLenient(isLenient);
    if (prettyPrint) {
      jsonWriter.setIndent("  ");
    }
    try {
      mapToWriter(map, jsonWriter);
    } finally {
      jsonWriter.close();
    }
  }