samples/preventcyclicdependencies/src-acyclic1/org/apidesign/cycles/array/MutableArray.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:48 +0200
changeset 87 618b79994cd4
child 88 97d71053c1a8
permissions -rw-r--r--
How to eliminate cyclic dependencies
jtulach@87
     1
package org.apidesign.cycles.array;
jtulach@87
     2
jtulach@87
     3
import java.io.IOException;
jtulach@87
     4
import java.io.OutputStream;
jtulach@87
     5
import org.openide.util.Lookup;
jtulach@87
     6
// BEGIN: nocycles.ma2
jtulach@87
     7
public class MutableArray {
jtulach@87
     8
    private byte[] arr;
jtulach@87
     9
jtulach@87
    10
    public MutableArray(byte[] arr) {
jtulach@87
    11
        this.arr = arr;
jtulach@87
    12
    }
jtulach@87
    13
jtulach@87
    14
    public void xor(byte b) {
jtulach@87
    15
        for (int i = 0; i < arr.length; i++) { arr[i] ^= b; }
jtulach@87
    16
    }
jtulach@87
    17
jtulach@87
    18
    public void and(byte b) {
jtulach@87
    19
        for (int i = 0; i < arr.length; i++) { arr[i] &= b; }
jtulach@87
    20
    }
jtulach@87
    21
jtulach@87
    22
    public void or(byte b) {
jtulach@87
    23
        for (int i = 0; i < arr.length; i++) { arr[i] |= b; }
jtulach@87
    24
    }
jtulach@87
    25
jtulach@87
    26
    public void encrypt(OutputStream os) throws IOException {
jtulach@87
    27
        DoEncode en = Lookup.getDefault().lookup(DoEncode.class);
jtulach@87
    28
        assert en != null : "We need org.netbeans.example.crypt to be enabled!";
jtulach@87
    29
        byte[] clone = (byte[]) arr.clone();
jtulach@87
    30
        en.encode(clone);
jtulach@87
    31
        os.write(clone);
jtulach@87
    32
    }
jtulach@87
    33
    
jtulach@87
    34
    public interface DoEncode {
jtulach@87
    35
        public void encode(byte[] arr);
jtulach@87
    36
    }
jtulach@87
    37
}
jtulach@87
    38
// END: nocycles.ma2