Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated the utils into few new Maven modules (Cls, Dates, Pool, Var…
…, Arr).
- Loading branch information
1 parent
5a1c648
commit 689e497
Showing
110 changed files
with
799 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid</artifactId> | ||
<version>3.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rapidoid-anyobj</artifactId> | ||
<packaging>jar</packaging> | ||
<description>Rapidoid AnyObj</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-u</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-arr</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-dates</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-test-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
79 changes: 79 additions & 0 deletions
79
rapidoid-anyobj/src/main/java/org/rapidoid/anyobj/AnyObj.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.rapidoid.anyobj; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-anyobj | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
import java.util.Collection; | ||
|
||
import org.rapidoid.arr.Arr; | ||
import org.rapidoid.util.U; | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 3.1.0 | ||
*/ | ||
public class AnyObj { | ||
|
||
public static boolean contains(Object arrOrColl, Object value) { | ||
if (arrOrColl instanceof Object[]) { | ||
Object[] arr = (Object[]) arrOrColl; | ||
return Arr.indexOf(arr, value) >= 0; | ||
} else if (arrOrColl instanceof Collection<?>) { | ||
Collection<?> coll = (Collection<?>) arrOrColl; | ||
return coll.contains(value); | ||
} else { | ||
throw U.illegalArg("Expected array or collection, but found: " + U.readable(arrOrColl)); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Object include(Object arrOrColl, Object item) { | ||
if (arrOrColl instanceof Object[]) { | ||
Object[] arr = (Object[]) arrOrColl; | ||
return Arr.indexOf(arr, item) < 0 ? Arr.expand(arr, item) : arr; | ||
} else if (arrOrColl instanceof Collection<?>) { | ||
Collection<Object> coll = (Collection<Object>) arrOrColl; | ||
if (!coll.contains(item)) { | ||
coll.add(item); | ||
} | ||
return coll; | ||
} else { | ||
throw U.illegalArg("Expected array or collection!"); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Object exclude(Object arrOrColl, Object item) { | ||
if (arrOrColl instanceof Object[]) { | ||
Object[] arr = (Object[]) arrOrColl; | ||
int ind = Arr.indexOf(arr, item); | ||
return ind >= 0 ? Arr.deleteAt(arr, ind) : arr; | ||
} else if (arrOrColl instanceof Collection<?>) { | ||
Collection<Object> coll = (Collection<Object>) arrOrColl; | ||
if (coll.contains(item)) { | ||
coll.remove(item); | ||
} | ||
return coll; | ||
} else { | ||
throw U.illegalArg("Expected array or collection!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid</artifactId> | ||
<version>3.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rapidoid-arr</artifactId> | ||
<packaging>jar</packaging> | ||
<description>Rapidoid Arr</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-u</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-test-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.