Skip to content

Commit

Permalink
Create Guide.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jan 6, 2025
1 parent e44fd43 commit 33a5afb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# kala-common
# Kala Common

[![Gradle Check](https://github.com/Glavo/kala-common/actions/workflows/check.yml/badge.svg)](https://github.com/Glavo/kala-common/actions/workflows/check.yml)
[![codecov](https://codecov.io/github/Glavo/kala-common/graph/badge.svg?token=IHM4ZK7K7A)](https://codecov.io/github/Glavo/kala-common)
Expand Down
8 changes: 8 additions & 0 deletions docs/zh/Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Kala Common 用户教程 (WIP)

## 简介

Kala Common 是一个强大的 Java 基础库,提供了强大的可变以及不可变的的集合库、各类常用的结构 (`Try`, `Either`, `Tuple` 等)、
范围、字符串工具等。

(TODO)
8 changes: 4 additions & 4 deletions kala-base/src/main/java/kala/collection/base/Iterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static <E> Iterator<E> narrow(Iterator<? extends E> iterator) {
return Iterators.empty();
}

return new AbstractIterator<E>() {
return new AbstractIterator<>() {
@Override
public boolean hasNext() {
return enumeration.hasMoreElements();
Expand Down Expand Up @@ -754,7 +754,7 @@ public static <E> E min(@NotNull Iterator<? extends E> it, Comparator<? super E>
return prepended(it, newValue);
}

return new AbstractIterator<E>() {
return new AbstractIterator<>() {
private int idx = 0;

@Override
Expand Down Expand Up @@ -869,7 +869,7 @@ public E next() {
if (!it.hasNext()) { // implicit null check of it
return Iterators.empty();
}
return new AbstractIterator<U>() {
return new AbstractIterator<>() {
@Override
public boolean hasNext() {
return it.hasNext();
Expand All @@ -890,7 +890,7 @@ public U next() {
if (!it.hasNext()) { // implicit null check of it
return Iterators.empty();
}
return new AbstractIterator<U>() {
return new AbstractIterator<>() {
private int idx = 0;

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/kala/collection/base/IteratorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.IntFunction;
import java.util.function.Predicate;

import static kala.ExtendedAssertions.assertIteratorEquals;
import static org.junit.jupiter.api.Assertions.*;

public class IteratorsTest {
Expand All @@ -48,6 +50,18 @@ public void ofTest() {
assertIteratorElements(Iterators.of("A", "B", "C", "D", "E"), "A", "B", "C", "D", "E");
}

@SafeVarargs
private static <T> Iterator<T> enumerationIterator(T... values) {
return Iterators.ofEnumeration(new java.util.Vector<>(List.of(values)).elements());
}

@Test
public void ofEnumerationTest() {
assertIteratorEquals(List.of(), enumerationIterator());
assertIteratorEquals(List.of("A"), enumerationIterator("A"));
assertIteratorEquals(List.of("A", "B", "C"), enumerationIterator("A", "B", "C"));
}

@Test
public void fillTest() {
assertIteratorElements(Iterators.fill(-1, "foo"));
Expand Down

0 comments on commit 33a5afb

Please sign in to comment.