1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2019, Arm Limited. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have
  22  * questions.
  23  */
  24 
  25 import java.util.function.IntFunction;
  26 
  27 public class AbstractVectorTest {
  28 
  29     interface ToBoolF {
  30         boolean apply(int i);
  31     }
  32 
  33     static boolean[] fill_boolean(int s , ToBoolF f) {
  34         return fill_boolean(new boolean[s], f);
  35     }
  36 
  37     static boolean[] fill_boolean(boolean[] a, ToBoolF f) {
  38         for (int i = 0; i < a.length; i++) {
  39             a[i] = f.apply(i);
  40         }
  41         return a;
  42     }
  43 
  44     static <R> IntFunction<R> withToString(String s, IntFunction<R> f) {
  45         return new IntFunction<R>() {
  46             @Override
  47             public R apply(int v) {
  48                 return f.apply(v);
  49             }
  50 
  51             @Override
  52             public String toString() {
  53                 return s;
  54             }
  55         };
  56     }
  57 
  58     interface IntOp {
  59         int apply(int i);
  60     }
  61 
  62     static int[] fillInts(int s , IntOp f) {
  63         return fillInts(new int[s], f);
  64     }
  65 
  66     static int[] fillInts(int[] a, IntOp f) {
  67         for (int i = 0; i < a.length; i++) {
  68             a[i] = f.apply(i);
  69         }
  70         return a;
  71     }
  72 }