building new collections
960313
function toArray(coll, xform) {
  if(!xform) {
    return reduce(coll, arrayReducer, []);
  }
  return transduce(coll, xform, arrayReducer, []);
}
321700
function Collection(nodes) {
  this.length = 0;
  if (nodes) {
    nodes = unique(nodes);
    this.length = nodes.length;
    // add each node to an index-based property on collection, in order to
    // appear "array"-like
    for (var i = 0, len = nodes.length; i < len; i++) {
      this[i] = nodes[i];
    }
  }
}
1356279
def create_collection(self, name, type=2):
        

        return Collection.create(name=name, database=self.name, type=type)
248782
function someCollections(db, collections, next) {

  var last = ~~collections.length, counter = 0;
  if (last === 0) { // empty set
    return next(null);
  }

  collections.forEach(function(collection) {

    db.collection(collection, function(err, collection) {

      logger('select collection ' + collection.collectionName);
      if (err) {
        return last === ++counter ? next(err) : error(err);
      }
      collection.drop(function(err) {

        if (err) {
          error(err); // log if missing
        }
        return last === ++counter ? next(null) : null;
      });
    });
  });
}
955278
def _unpickle_collection(self, collection):
        """"""
        for mkey in collection:
            if isinstance(collection[mkey], list):
                for item in collection[mkey]:
                    item.unpickle(self)
            else:
                collection[mkey].unpickle(self)
617217
public void addCollection(Collection<? extends E> collection) {
		if (collection != null && !collection.isEmpty()) {
			this.collections.add(collection);
		}
	}
1371811
public static <T, R> List<R> buildNewList(Collection<T> collection,
            Function<T, R> transformFunction) {
        return collection.stream().map(transformFunction)
                .collect(Collectors.toList());
    }
854397
protected function prepareCollection()
    {
        $need_conversion = false;
        $first_row = $this->data->first();

        if (!$first_row) {
            return;
        }

        foreach ($first_row as $item) {
            if (!is_string($item)) {
                $need_conversion = true;
            }
        }
        if ($need_conversion) {
            $this->transform();
        }
    }
236361
def buildCatalogs(self, exclusions=None, **kwargs):
        
        self.generateXY(**kwargs)
        self.generateRaDec()
        if exclusions:
            self.apply_exclusions(exclusions)

        # apply selection limits as specified by the user:
        self.apply_flux_limits()
1346802
function(collection){
	Array.apply(this);
	if(arguments.length >= 1){
		for(var i=0,len = collection.length;i<len;i++){
			var item = collection[i];
			if(this.indexOf(item) < 0){
				this.push(item);
			}
		}
	}
 }
1358835
def rebuild_collection_tree(old_collection_ident, new_document_id_map, plpy):
    
    get_tree = plpy.prepare('''
    WITH RECURSIVE t(node, parent, document, title, childorder, latest, path)
        AS (SELECT tr.nodeid, tr.parent_id, tr.documentid, tr.title,
                   tr.childorder, tr.latest, ARRAY[tr.nodeid]
            FROM trees tr
            WHERE tr.documentid = $1 AND tr.is_collated = 'False'
    UNION ALL
        SELECT c.nodeid, c.parent_id, c.documentid, c.title,
               c.childorder, c.latest, path || ARRAY[c.nodeid]
        FROM trees c JOIN t ON (c.parent_id = t.node)
        WHERE not c.nodeid = ANY(t.path)
    )
    SELECT * FROM t
    ''', ('integer',))

    def get_old_tree():
        return plpy.execute(get_tree, (old_collection_ident,))

    tree = {}  # { old_nodeid: {'data': ...}, ...}
    children = {}  # { nodeid: [child_nodeid, ...], child_nodeid: [...]}
    for i in get_old_tree():
        tree[i['node']] = {'data': i, 'new_nodeid': None}
        children.setdefault(i['parent'], [])
        children[i['parent']].append(i['node'])

    insert_tree = plpy.prepare('''
    INSERT INTO trees (nodeid, parent_id, documentid,
        title, childorder, latest)
    VALUES (DEFAULT, $1, $2, $3, $4, $5)
    RETURNING nodeid
    ''', ('integer', 'integer', 'text', 'integer', 'boolean'))

    def execute(fields):
        results = plpy.execute(insert_tree, fields, 1)
        return results[0]['nodeid']

    root_node = children[None][0]

    def build_tree(node, parent):
        data = tree[node]['data']
        new_node = execute([parent, new_document_id_map.get(data['document'],
                            data['document']), data['title'],
                            data['childorder'], data['latest']])
        for i in children.get(node, []):
            build_tree(i, new_node)
    build_tree(root_node, None)
1044004
def mode_new_collection():
    

    print globals()['mode_new_collection'].__doc__
    collection_name = raw_input("Collection name: ")
    item_attr_list = []
    collection_node_id = None
    if collection_name:
        collection_node_id = insert_node(name=collection_name, value=None)
        insert_query(name='select_link_node_from_node.sql', node_id=collection_node_id)
        item_attr = True
        while item_attr:
            item_attr = raw_input("Add a collection item attribute name: ")
            if item_attr:
                item_attr_list.append(item_attr)

    # if no collection name then exit
    selection = collection_name

    while selection:
        selection = select([
            'Add item',
            ])
        if selection == 'Add item':
            # create item
            add_item_with_attributes_to_collection(
                    collection_name=collection_name,
                    collection_node_id=collection_node_id,
                    item_attr_list=item_attr_list)

    if collection_node_id:
        print "Added collection name '{0}' with node id: {1}".format(collection_name, collection_node_id)
930041
private function createCollections()
    {
        $collections = $this->mongo->listCollections();

        $collectionsCreated = false;
        foreach ($collections as $collection) {
            /* @var $collection CollectionInfo */
            if ($collection->getName() == self::ADB_STATS_DAILY) {
                $collectionsCreated = true;
                break;
            }
        }

        if (!$collectionsCreated) {

            // create collections
            $this->mongo->createCollection(self::ADB_STATS_DAILY);
            $this->mongo->createCollection(self::ADB_STATS_MONTHLY);
            $this->mongo->createCollection(self::ADB_DIMS);

            // ensure indexes
            $this->mongo->createIndex(self::ADB_STATS_DAILY, new CompoundIndex('entityTsEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_DAILY,
                new CompoundIndex('entityTsAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_STATS_MONTHLY, new CompoundIndex('entityMonthEntry', ['entity', 'ref', 'ts'], true, true));
            $this->mongo->createIndex(self::ADB_STATS_MONTHLY,
                new CompoundIndex('entityMonthAttrEntry', ['entity', 'ts', 'attributes.name', 'attributes.value'], false, false));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension', ['name', 'value', 'entity', 'ts'], true, true));

            $this->mongo->createIndex(self::ADB_DIMS, new CompoundIndex('dimension_entity', ['entity', 'ts'], true));
        }
    }
125512
function constructCollection(Collection, options) {
  return construct({
    input: Collection,
    expected: AmpersandCollection,
    createConstructor: collection,
    options: options
  });
}
105537
private void createEmptyDataCollection()
    {
        Class<?> collectionClass = getRelation().getProperty().getType();
        if (collectionClass.isAssignableFrom(Set.class))
        {
            dataCollection = new HashSet();
        }
        else if (collectionClass.isAssignableFrom(List.class))
        {
            dataCollection = new ArrayList();
        }
    }
91060
def collect(options = {}, &block)
      collector = AnswersCollector.new(self, options)
      collector.call(&block)
    end
384557
function(connection, collection, definition, cb) {
      log.debug('define:', collection);

      // Create the collection and indexes
      connections[connection].createCollection(collection, definition, cb);
    }