/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.codahale.shamir;

import static org.quicktheories.quicktheories.generators.SourceDSL.integers;
import static org.quicktheories.quicktheories.generators.SourceDSL.lists;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.quicktheories.quicktheories.core.Source;

public interface Generators {

  static Source<Byte> bytes() {
    return integers().between(0, 255).as(Integer::byteValue, Byte::intValue);
  }

  static Source<Byte> nonZeroBytes() {
    return integers().between(1, 255).as(Integer::byteValue, Byte::intValue);
  }

  static Source<byte[]> byteArrays(int minSize, int maxSize) {
    return lists().arrayListsOf(bytes()).ofSizeBetween(minSize, maxSize).as(
        l -> {
          final byte[] bytes = new byte[l.size()];
          for (int i = 0; i < l.size(); i++) {
            bytes[i] = l.get(i);
          }
          return bytes;
        },
        a -> {
          final List<Byte> bytes = new ArrayList<>(a.length);
          for (byte b : a) {
            bytes.add(b);
          }
          return bytes;
        }).describedAs(Arrays::toString);
  }
}

@@ -750,27 +750,42 @@
 ort 
-java.util.ArrayList
+com.google.common.primitives.Bytes
 ;%0Aim
@@ -811,31 +811,8 @@
 ys;%0A
-import java.util.List;%0A
 impo
@@ -956,24 +956,46 @@
 ween(0, 255)
+%0A                     
 .as(Integer:
@@ -1104,16 +1104,38 @@
 (1, 255)
+%0A                     
 .as(Inte
@@ -1275,16 +1275,35 @@
 bytes())
+%0A                  
 .ofSizeB
@@ -1326,20 +1326,16 @@
 maxSize)
-.as(
 %0A       
@@ -1339,15 +1339,9 @@
     
-l -%3E %7B%0A
+ 
     
@@ -1349,355 +1349,61 @@
     
- final byte%5B%5D bytes = new byte%5Bl.size()%5D;%0A          for (int i = 0; i %3C l.size(); i++) %7B%0A            bytes%5Bi%5D = l.get(i);%0A          %7D%0A          return bytes;%0A        %7D,%0A        a -%3E %7B%0A          final List%3CByte%3E bytes = new ArrayList%3C%3E(a.length);%0A          for (byte b : a) %7B%0A            bytes.add(b);%0A          %7D%0A          return bytes;%0A        %7D)
+.as(Bytes::toArray, Bytes::asList)%0A                  
 .des

Simplify the byte array generator.