Create class which components can take only values from the set {0, 1 , 2}
<p>How to create a collection, array which values are only 0 , 1 , 2 numbers.
I have a task to create an mathematical vector, which components are only from the set {0 ,1 ,2}. So I need some data structure which can contain only 0 ,1 ,2 values and nothing else. How to implement such a set or impose restrictions on class field? Helpe me please.`</p>

<pre><code>public class MyClass
{
// This type supposed to contains only values from the set {0 ,1 , 2}.
    Type components;
}
</code></pre>