01 /*
02 * Java Genetic Algorithm Library (jenetics-1.6.0).
03 * Copyright (c) 2007-2014 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.util;
21
22 import static java.util.Objects.requireNonNull;
23
24 /**
25 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
26 * @since 1.0
27 * @version 1.0 — <em>$Date: 2014-02-15 $</em>
28 */
29 class ArrayISeq<T> extends ArraySeq<T> implements ISeq<T> {
30 private static final long serialVersionUID = 1L;
31
32
33 ArrayISeq(final ArrayRef array, final int start, final int end) {
34 super(array, start, end);
35 }
36
37 @Override
38 public ISeq<T> subSeq(final int start, final int end) {
39 checkIndex(start, end);
40 return new ArrayISeq<>(_array, start + _start, end + _start);
41 }
42
43 @Override
44 public ISeq<T> subSeq(final int start) {
45 return subSeq(start, length());
46 }
47
48 @Override
49 public <B> ISeq<B> map(final Function<? super T, ? extends B> converter) {
50 requireNonNull(converter, "Converter");
51
52 final int length = length();
53 final ArrayISeq<B> result = new ArrayISeq<>(new ArrayRef(length), 0, length);
54 assert (result._array.data.length == length);
55
56 for (int i = length; --i >= 0;) {
57 @SuppressWarnings("unchecked")
58 final T value = (T)_array.data[i + _start];
59 result._array.data[i] = converter.apply(value);
60 }
61 return result;
62 }
63
64 @Override
65 public MSeq<T> copy() {
66 return new Array<>(new ArrayRef(toArray()), 0, length());
67 }
68
69 @Deprecated
70 @Override
71 @SuppressWarnings("unchecked")
72 public <A> ISeq<A> upcast(final ISeq<? extends A> seq) {
73 return (ISeq<A>)seq;
74 }
75
76 }
|