       return arg.fetch()
     return []
 
+  # @param {Array.<Meteor.Collection>} collections
+  # @returns {Object.<String, Meteor.Collection>} A map of collection name to object for the given
+  #      collections.
+  getMap: (collections) ->
+    collectionMap = {}
+    _.each collections, (collection) =>
+      name = @getName(collection)
+      collectionMap[name] = collection
+    collectionMap
+
+  # @param {Object.<String, String>} map - A map of IDs to names of the items.
+  # @returns A temporary collection with items created from the given map.
+  fromNameMap: (map, args) ->
+    args = _.extend({
+    }, args)
+    collection = Collections.createTemporary()
+    callback = args.callback
+    _.each map, (item, id) ->
+      if callback
+        name = callback(item, id)
+      else
+        name = item
+      collection.insert(_id: id, name: name)
+    collection
+
   createTemporary: (docs) ->
     collection = new Meteor.Collection(null)
     @insertAll(docs, collection)

    tmpCollection.update(insertedId, modifier)
    tmpCollection.findOne(insertedId)

  # @param {Meteor.Collection} collection
  # @param {Function} validate - A validation method which returns a string on failure or throws
  # an exception, which causes validation to fail and prevents insert() or update() on the collection
  # from completing.
  addValidation: (collection, validate) ->
    collection.before.insert (userId, doc, options) =>
      return if options?.validate == false

    else
      handle(result)

####################################################################################################
# SANITIZATION
####################################################################################################

  # @param {Meteor.Collection} collection
  # @param {Function} sanitize - A sanitization method which is passed a document before insertions
  #      or updates occur for the given collection. If a MongoDB modifier is returned, it is applied
  #      to the document before the operation takes place, allowing for any final changes.
  addSanitization: (collection, sanitize) ->
    collection.before.insert (userId, doc) =>
      context = {userId: userId}
      modifier = sanitize.call(context, doc)
      if modifier
        # TODO(aramk) Apply the change directly on the doc for better performance.
        updatedDoc = @simulateModifierUpdate(doc, modifier)
        Setter.merge(doc, updatedDoc)

    collection.before.update (userId, doc, fieldNames, modifier) ->
      updatedDoc = Collections.simulateModifierUpdate(doc, modifier)
      context = {userId: userId}
      # sanitizedDoc = Setter.clone(updatedDoc)
      sanitizeModifier = sanitize.call(context, updatedDoc)
      return unless sanitizeModifier
      # docDiff = Objects.diff(updatedDoc, sanitizedDoc)
      Setter.merge(modifier, sanitizeModifier)
      # Ensure no fields exist in $unset from $set.
      $unset = modifier.$unset
      if $unset
        _.each $set, (value, key) ->
          delete $unset[key]
