summaryrefslogtreecommitdiff
path: root/src/library/scalax/collection/mutable/Appendable.scala
blob: 6dbe89346ed748e2f20e18e11a258fb915246d11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2008, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id: Iterable.scala 15188 2008-05-24 15:01:02Z stepancheg $

package scalax.collection.mutable

/** This class represents collections that can be augmented using a += operator.
 *
 *  @autor   Martin Odersky
 *  @owner   Martin Odersky
 *  @version 2.8
 */
trait Appendable[A] {

  /** Append a single element to this buffer.
   *
   *  @param elem  the element to append.
   */
  def +=(elem: A): Unit

  /** Append a two or more elements to this buffer.
   *
   *  @param elem1 the first element to append.
   *  @param elem2 the second element to append.
   *  @param elems the remaining elements to append.
   */
  def +=(elem1: A, elem2: A, elems: A*) {
    this += elem1
    this += elem2
    this ++= elems.asInstanceOf[Iterable[A]] // !@!
  }

  /** Appends a number of elements provided by an iterator
   *
   *  @param iter  the iterator.
   */
  def ++=(iter: collection.Iterator[A]) { iter foreach += }

  /** Appends a number of elements provided by an iterable object
   *  via its <code>elements</code> method.
   *
   *  @param iter  the iterable object.
   */
  def ++=(iter: collection.Iterable[A]) { iter foreach += }

  /** Append a single element to this buffer and return
   *  the identity of the buffer.
   *
   *  @param elem  the element to append.
   */
  def +(elem: A): this.type = { this += elem; this }

  /** Append two or more elements to this buffer and return
   *  the identity of the buffer.
   *
   *  @param elem1 the first element to append.
   *  @param elem2 the second element to append.
   *  @param elems the remaining elements to append.
   */
  def +(elem1: A, elem2: A, elems: A*): this.type =
    this + elem1 + elem2 ++ elems.asInstanceOf[Iterable[A]] // !@!

  /** Appends a number of elements provided by an iterable object
   *  via its <code>elements</code> method. The identity of the
   *  buffer is returned.
   *
   *  @param iter     the iterable object.
   *  @return       the updated buffer.
   */
  def ++(iter: Iterable[A]): this.type = { this ++= iter; this }

  /** Appends a number of elements provided by an iterator
   *  via its <code>elements</code> method. The identity of the
   *  buffer is returned.
   *
   *  @param iter   the iterator
   *  @return       the updated buffer.
   */
  def ++(iter: Iterator[A]): this.type = { this ++= iter; this }

  /** Clears the buffer contents.
   */
  def clear()
}