01 /*
02 * Java Genetic Algorithm Library (jenetics-1.5.0).
03 * Copyright (c) 2007-2013 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
19 */
20 package org.jenetics.internal.util;
21
22 //import static java.lang.Math.max;
23 //import static java.lang.Math.min;
24 //
25 //import org.jenetics.util.Concurrent;
26 import org.jenetics.util.Factory;
27 import org.jenetics.util.StaticObject;
28
29 /**
30 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
31 * @since 1.5
32 * @version 1.5 — <em>$Date: 2013-11-18 $</em>
33 */
34 public final class arrays extends StaticObject {
35 private arrays() {}
36
37 // static int MIN_BULK_SIZE = 11;
38 // public static Object[] fill(final Object[] array, final Factory<?> factory) {
39 // if (array.length > 0) {
40 // try (Concurrent c = new Concurrent()) {
41 // final int threads = c.getParallelism();
42 // final int[] parts = org.jenetics.util.arrays.partition(
43 // array.length, min(threads, max(array.length/MIN_BULK_SIZE, 1))
44 // );
45 //
46 // for (int i = 0; i < parts.length - 1; ++i) {
47 // final int part = i;
48 //
49 // c.execute(new Runnable() { @Override public void run() {
50 // for (int j = parts[part]; j < parts[part + 1]; ++j) {
51 // array[j] = factory.newInstance();
52 // }
53 // }});
54 // }
55 // }
56 // }
57 //
58 // return array;
59 // }
60
61 public static Object[] fill(final Object[] array, final Factory<?> factory) {
62 for (int i = 0; i < array.length; ++i) {
63 array[i] = factory.newInstance();
64 }
65 return array;
66 }
67
68 }
69
|