ArrayProxyISeq.java
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.internal.util;
21 
22 import org.jenetics.util.Function;
23 import org.jenetics.util.ISeq;
24 import org.jenetics.util.MSeq;
25 
26 /**
27  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
28  @since 1.4
29  @version 1.5 &mdash; <em>$Date: 2013-12-04 $</em>
30  */
31 public class ArrayProxyISeq<T> extends ArrayProxySeq<T> implements ISeq<T> {
32 
33     public ArrayProxyISeq(final ArrayProxy<T> proxy) {
34         super(proxy);
35     }
36 
37     @Override
38     public <B> ISeq<B> map(final Function<? super T, ? extends B> mapper) {
39         final ArrayProxyImpl<B> proxy = new ArrayProxyImpl<>(_proxy._length);
40         for (int i = 0; i < proxy._length; ++i) {
41             proxy._array[i= mapper.apply(_proxy.uncheckedGet(i));
42         }
43         return new ArrayProxyISeq<>(proxy);
44     }
45 
46     @Override
47     public ISeq<T> subSeq(final int start) {
48         return new ArrayProxyISeq<>(_proxy.slice(start));
49     }
50 
51     @Override
52     public ISeq<T> subSeq(int start, int end) {
53         return new ArrayProxyISeq<>(_proxy.slice(start, end));
54     }
55 
56     @SuppressWarnings("unchecked")
57     @Override
58     @Deprecated
59     public <A> ISeq<A> upcast(ISeq<? extends A> seq) {
60         return (ISeq<A>)seq;
61     }
62 
63     @Override
64     public MSeq<T> copy() {
65         return new ArrayProxyMSeq<>(_proxy.copy());
66     }
67 
68 }