gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under
the git version control system
1 import java
.math
.BigInteger
;
2 import java
.util
.Random
;
3 import java
.util
.concurrent
.atomic
.AtomicInteger
;
5 import org
.svetovid
.io
.SvetovidReader
;
6 import org
.svetovid
.io
.SvetovidWriter
;
9 * Ova klasa sluzi za generisanje random stabala. Nije potrebno znati je,
10 * i bice data, prilikom izrade prakticnih zadataka.
12 public class StabloIORandom
implements StabloIO
{
18 public StabloIORandom() {
19 this(System
.currentTimeMillis());
22 public StabloIORandom(long seed
) {
26 public StabloIORandom(long seed
, int length
, int depth
) {
32 public long getSeed() {
36 public void setSeed(long seed
) {
40 public int getLength() {
44 public void setLength(int length
) {
48 public int getDepth() {
52 public void setDepth(int depth
) {
57 public Stablo
readStablo(SvetovidReader in
) {
58 Random random
= new Random(seed
);
59 AtomicInteger sequence
= new AtomicInteger();
60 Stablo stablo
= readStablo(random
, sequence
, length
, depth
);
64 private Stablo
readStablo(Random random
, AtomicInteger sequence
, int length
, int depth
) {
68 int id
= sequence
.addAndGet(1 + random
.nextInt(9));
69 String vrednost
= new BigInteger(length
, random
).toString(36);
70 Stablo desni
= readStablo(random
, sequence
, length
+ random
.nextInt(5), depth
- random
.nextInt(5));
71 Stablo levi
= readStablo(random
, sequence
, length
+ random
.nextInt(5), depth
- random
.nextInt(5));
72 return new Stablo(id
, vrednost
, levi
, desni
);
76 public void printStablo(SvetovidWriter out
, Stablo stablo
) {
77 throw new UnsupportedOperationException();
Svarog.pmf.uns.ac.rs/gitweb
maintanance
Doni Pracner