01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.fixtures;
04:
05: import java.util.ArrayList;
06: import fit.RowFixture;
07:
08: public class PrimeFactorsFixture extends RowFixture {
09: public static class Factor {
10: public Factor(int factor) {
11: this .factor = factor;
12: }
13:
14: public int factor;
15: }
16:
17: public Object[] query() {
18: int n = Integer.parseInt(args[0]);
19: ArrayList factors = new ArrayList();
20: for (int f = 2; n > 1; f++)
21: for (; n % f == 0; n /= f)
22: factors.add(new Factor(f));
23: return (Factor[]) factors.toArray(new Factor[0]);
24: }
25:
26: public Class getTargetClass() // get expected type of row
27: {
28: return Factor.class;
29: }
30: }
|