Skip to content

Commit

Permalink
- Add Enumeration for LINQ.create();
Browse files Browse the repository at this point in the history
  • Loading branch information
duykhang53 committed Apr 23, 2019
1 parent 38fca2c commit c96fd69
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"javascript.implicitProjectConfig.checkJs": true,
"java.completion.guessMethodArguments": true,
"java.classPath": ["/src/main/java"]
"java.classPath": [
"/src/main/java"
],
"java.configuration.updateBuildConfiguration": "interactive"
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'java-library'
apply plugin: 'maven-publish'

group = "kayseven"
version = "1.0.0"
version = "1.0.1"

sourceCompatibility = 1.6
targetCompatibility = 1.6
Expand Down
34 changes: 27 additions & 7 deletions src/main/java/kayseven/linq/LINQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -49,32 +50,51 @@ public static <E> List<E> asList(final Iterator<E> iterator) {

public static <T> LINQ<T> create(Iterable<T> iterable) {
return new LINQ<T>(iterable != null ? iterable : new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}
});
}

public static <T> LINQ<T> create(T[] ary) {
return new LINQ<T>(ary != null ? Arrays.asList(ary) : new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}
});
}

public static <T> LINQ<T> create(final Enumeration<T> enumeration) {
return new LINQ<T>(enumeration != null ? new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
@Override
public boolean hasNext() {
return false;
return enumeration.hasMoreElements();
}

@Override
public T next() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return enumeration.nextElement();
}

@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
} : new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}
});
}

public static <T> LINQ<T> create(T[] ary) {
return new LINQ<T>(Arrays.asList(ary));
}

private static <T> LINQ<T> concat(final Iterator<T> ite1, final Iterator<T> ite2) {
return new ConcatenateOperation<T>(ite1, ite2).getLINQ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kayseven/linq/LINQOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean hasNext() {

@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}

}

0 comments on commit c96fd69

Please sign in to comment.