/** * Randomize the {@code array} using the {@link Random} object currently * registered in the {@link RandomRegistry} class. The used shuffling * algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition, * page 142, Algorithm S (Selection sampling technique). * * @return this shuffled sequence */ public default MSeq<T> shuffle() { return shuffle(RandomRegistry.getRandom()); }
/** * Create a new {@code Seq} from the given values. * * @param <T> the element type * @param values the array values. * @return a new {@code Seq} with the given values. * @throws NullPointerException if the {@code values} array is {@code null}. */ public static <T> Seq<T> of(final Iterable<? extends T> values) { return ISeq.of(values); }
/** * Returns a sequential {@code Stream} of chromosomes with this genotype as * its source. * * @since 3.4 * * @return a sequential {@code Stream} of chromosomes */ public Stream<Chromosome<G>> stream() { return _chromosomes.stream(); }
/** * Randomize the {@code list} using the given {@link Random} object. The used * shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, * Third edition, page 142, Algorithm S (Selection sampling technique). * * @param list the {@code array} to randomize. * @param <T> the component type of the array to randomize. * @throws NullPointerException if the give list is {@code null}. */ public static <T> void shuffle(final List<T> list) { shuffle(list, RandomRegistry.getRandom()); }
protected MSeq<T> newEqualObjects(final int length) { return Stream .generate(() -> with(new Random(589), r -> factory().newInstance())) .limit(length) .collect(toMSeq()); }
@Test public void objectSerialize() throws Exception { final Object object = factory().newInstance(); if (object instanceof Serializable) { for (int i = 0; i < 10; ++i) { final Serializable serializable = (Serializable)factory().newInstance(); Serialize.object.test(serializable); } } }
/** * Returns the index of the last occurrence of the specified element * in this sequence, or -1 if this sequence does not contain the element. * * @param element element to search for, can be {@code null} * @return the index of the last occurrence of the specified element in * this sequence, or -1 if this sequence does not contain the element */ public default int lastIndexOf(final Object element) { return lastIndexOf(element, 0, length()); }
/** * Reads an object from the given file. * * @param file the file to read from. * @return the de-serialized object. * @throws NullPointerException if the input stream {@code in} is {@code null}. * @throws IOException if the object could not be read. */ public Object read(final File file) throws IOException { return read(Object.class, file); }
/** * Returns a fixed-size list backed by the specified sequence. (Changes to * the returned list "write through" to the array.) The returned list is * fixed size, serializable and implements {@link RandomAccess}. * * @return a list view of this sequence */ public default List<T> asList() { return new SeqList<>(this); }
@Override public Iterator<String[]> iterator() { return new DataIterator(getResourcePath()); }
@Override public boolean equals(final Object object) { if (object == this) { return true; } if (!(object instanceof Seq)) { return false; } final Seq<?> seq = (Seq)object; return Seq.equals(this, seq); }
/** * Return an integer factory which creates an integer sequence starting with * zero an with the given {@code step}. * * @param step the gap between the generated integers. * @return an integer factory. */ public static Supplier<Integer> Int(final int step) { return Int(0, step); }
@Override public int nextInt() { return (int)nextLong(); } }
@Override public void close() { _reader.close(); } }