00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package sensix.sensing;
00036
00037 import sensix.*;
00038
00039
00040 public class Aggregate extends Sensory
00041 {
00042 protected String name = "";
00043 protected Collection[] series;
00044
00045
00046 public Aggregate(String n, byte l, Collection[] c) {
00047 super(l, Sensix.INVALID, (Functor[])c);
00048 name = n;
00049 series = c;
00050 if (series == null)
00051 series = new Collection[0];
00052 }
00053
00054 public Aggregate(String n, Collection[] c) {
00055 super((Functor[])c);
00056 name = n;
00057 series = c;
00058 if (series == null)
00059 series = new Collection[0];
00060 }
00061
00062 public Aggregate(String n, byte l, Collection[] c, int seq) {
00063 super(l, Sensix.INVALID, (Functor[])c, seq);
00064 name = n;
00065 series = c;
00066 if (series == null)
00067 series = new Collection[0];
00068 }
00069
00070
00071 public Sensory[] senses() {
00072 int num = series.length;
00073 Sensory[] array = new Sensory[num];
00074 for (int i = 0; i < num; i++)
00075 array[i] = series[i].sense();
00076 return array;
00077 }
00078
00079
00080 public Collection[] collectors() {
00081 return series;
00082 }
00083
00084 public void collectors(Collection[] c) {
00085 series = c;
00086 }
00087
00088
00089 public byte sensor() {
00090 return Sensix.INVALID;
00091 }
00092
00093 public Sensory sense() {
00094 return series[0].sense();
00095 }
00096
00097 public void sense(Sensory s) {}
00098
00099 public long timeused() {
00100 long max = 0;
00101 for (int i = 0; i < series.length; i++) {
00102 if (series[i].timeused() > max)
00103 max = series[i].timeused();
00104 }
00105 return max;
00106 }
00107
00108 public void timeused(long t) {}
00109
00110 public double energyused() {
00111 double sum = 0.0;
00112 for (int i = 0; i < series.length; i++)
00113 sum += series[i].energyused();
00114 return sum;
00115 }
00116
00117 public void energyused(double e) {}
00118
00119 public byte priority() {
00120 byte max = 0;
00121 for (int i = 0; i < series.length; i++) {
00122 if (series[i].priority() > max)
00123 max = series[i].priority();
00124 }
00125 return max;
00126 }
00127
00128 public void priority(byte p) {
00129 for (int i = 0; i < series.length; i++)
00130 series[i].priority(p);
00131 }
00132
00133 public FunctorError[] errors() {
00134 int num = 0, pos = 0;
00135 for (int i = 0; i < series.length; i++) {
00136 if (series[i].errors() != null)
00137 num += series[i].errors().length;
00138 }
00139 FunctorError[] e = new FunctorError[num];
00140 for (int i = 0; i < series.length; i++) {
00141 if (series[i].errors() != null && series[i].errors().length > 0) {
00142 System.arraycopy(series[i].errors(), 0, e, pos,
00143 series[i].errors().length);
00144 pos += series[i].errors().length;
00145 }
00146 }
00147 return e;
00148 }
00149
00150 public void errors(FunctorError[] fe) {}
00151
00152 public String asString() {
00153 String string_rep = name + "(";
00154 if (level() != Sensix.INVALID)
00155 string_rep += "level=" + (int)level() + ",";
00156 for (int i = 0; i < series.length; i ++) {
00157 string_rep += series[i].asString();
00158 if (i < series.length - 1)
00159 string_rep += "&&";
00160 }
00161 string_rep += ")";
00162 return string_rep;
00163 }
00164 }