repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalChar.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> char orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalChar.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> char orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> char orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalChar.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> char orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalChar.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> char orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(CharConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalChar.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> char orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(CharConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalChar.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> char orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(CharConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(CharConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalLong.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalLong}
* @throws IllegalStateException if there is no value present
*/
public long get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public long or(long other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalLong.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalLong}
* @throws IllegalStateException if there is no value present
*/
public long get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public long or(long other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public long or(LongSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalLong.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> long orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalLong.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> long orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> long orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalLong.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> long orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalLong.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> long orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(LongConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalLong.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> long orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(LongConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalLong.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> long orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(LongConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(LongConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalFloatTest.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | /*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalFloatTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalFloat.of(42f).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalFloat.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalFloat.of(42f).isPresent());
Assert.assertFalse(OptionalFloat.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42f, OptionalFloat.of(42f).get(), 0);
try {
OptionalFloat.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(42f), 0);
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalFloatTest.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
/*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalFloatTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalFloat.of(42f).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalFloat.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalFloat.of(42f).isPresent());
Assert.assertFalse(OptionalFloat.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42f, OptionalFloat.of(42f).get(), 0);
try {
OptionalFloat.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(42f), 0);
}
@Test
public void orWithSupplier() throws Exception { | Assert.assertEquals(42f, OptionalFloat.absent().or(new FloatSupplier() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalFloatTest.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | }
@Test
public void or() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(42f), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(new FloatSupplier() {
@Override
public float get() {
return 42f;
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalFloat.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalFloatTest.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
}
@Test
public void or() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(42f), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42f, OptionalFloat.absent().or(new FloatSupplier() {
@Override
public float get() {
return 42f;
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalFloat.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalFloatTest.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void orThrow() throws Exception {
try {
OptionalFloat.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalFloat.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalFloatTest.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void orThrow() throws Exception {
try {
OptionalFloat.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalFloat.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | OptionalFloat.of(42f).ifPresent(new FloatConsumer() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalFloatTest.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalFloat.of(42f).ifPresent(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.assertEquals(42f, value, 0);
}
});
OptionalFloat.absent().ifPresent(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalFloat.of(42f).ifPresentOrElse(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.assertEquals(42f, value, 0);
} | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalFloatTest.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalFloat.of(42f).ifPresent(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.assertEquals(42f, value, 0);
}
});
OptionalFloat.absent().ifPresent(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalFloat.of(42f).ifPresentOrElse(new FloatConsumer() {
@Override
public void consume(float value) {
Assert.assertEquals(42f, value, 0);
} | }, new Function() { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalByte.java | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalByte}
* @throws IllegalStateException if there is no value present
*/
public byte get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public byte or(byte other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalByte.java
import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalByte}
* @throws IllegalStateException if there is no value present
*/
public byte get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public byte or(byte other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public byte or(ByteSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalByte.java | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> byte orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalByte.java
import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> byte orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> byte orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalByte.java | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> byte orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalByte.java
import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> byte orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(ByteConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalByte.java | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> byte orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(ByteConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/ByteConsumer.java
// public interface ByteConsumer {
//
// void consume(byte value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ByteSupplier.java
// public interface ByteSupplier {
//
// byte get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalByte.java
import com.hadisatrio.optional.function.ByteConsumer;
import com.hadisatrio.optional.function.ByteSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> byte orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(ByteConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(ByteConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalLongTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | /*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalLongTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalLong.of(42l).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalLong.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalLong.of(42l).isPresent());
Assert.assertFalse(OptionalLong.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42l, OptionalLong.of(42l).get());
try {
OptionalLong.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(42l));
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalLongTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
/*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalLongTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalLong.of(42l).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalLong.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalLong.of(42l).isPresent());
Assert.assertFalse(OptionalLong.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42l, OptionalLong.of(42l).get());
try {
OptionalLong.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(42l));
}
@Test
public void orWithSupplier() throws Exception { | Assert.assertEquals(42l, OptionalLong.absent().or(new LongSupplier() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalLongTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | }
@Test
public void or() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(42l));
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(new LongSupplier() {
@Override
public long get() {
return 42l;
}
}));
}
@Test
public void orThrow() throws Exception {
try {
OptionalLong.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalLongTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
}
@Test
public void or() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(42l));
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42l, OptionalLong.absent().or(new LongSupplier() {
@Override
public long get() {
return 42l;
}
}));
}
@Test
public void orThrow() throws Exception {
try {
OptionalLong.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalLongTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void orThrow() throws Exception {
try {
OptionalLong.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalLong.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalLongTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void orThrow() throws Exception {
try {
OptionalLong.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalLong.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | OptionalLong.of(42l).ifPresent(new LongConsumer() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalLongTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalLong.of(42l).ifPresent(new LongConsumer() {
@Override
public void consume(long value) {
Assert.assertEquals(42l, value);
}
});
OptionalLong.absent().ifPresent(new LongConsumer() {
@Override
public void consume(long value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalLong.of(42l).ifPresentOrElse(new LongConsumer() {
@Override
public void consume(long value) {
Assert.assertEquals(42l, value);
} | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongConsumer.java
// public interface LongConsumer {
//
// void consume(long value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/LongSupplier.java
// public interface LongSupplier {
//
// long get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalLongTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.LongConsumer;
import com.hadisatrio.optional.function.LongSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalLong.of(42l).ifPresent(new LongConsumer() {
@Override
public void consume(long value) {
Assert.assertEquals(42l, value);
}
});
OptionalLong.absent().ifPresent(new LongConsumer() {
@Override
public void consume(long value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalLong.of(42l).ifPresentOrElse(new LongConsumer() {
@Override
public void consume(long value) {
Assert.assertEquals(42l, value);
} | }, new Function() { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalFloat.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalFloat}
* @throws IllegalStateException if there is no value present
*/
public float get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public float or(float other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalFloat.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalFloat}
* @throws IllegalStateException if there is no value present
*/
public float get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public float or(float other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public float or(FloatSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalFloat.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> float orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalFloat.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> float orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> float orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalFloat.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> float orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalFloat.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> float orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(FloatConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalFloat.java | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> float orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(FloatConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/FloatConsumer.java
// public interface FloatConsumer {
//
// void consume(float value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/FloatSupplier.java
// public interface FloatSupplier {
//
// float get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalFloat.java
import com.hadisatrio.optional.function.FloatConsumer;
import com.hadisatrio.optional.function.FloatSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> float orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(FloatConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(FloatConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | /*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalDoubleTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalDouble.of(42d).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalDouble.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalDouble.of(42d).isPresent());
Assert.assertFalse(OptionalDouble.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42d, OptionalDouble.of(42d).get(), 0);
try {
OptionalDouble.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(42d), 0);
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
/*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalDoubleTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalDouble.of(42d).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalDouble.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalDouble.of(42d).isPresent());
Assert.assertFalse(OptionalDouble.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42d, OptionalDouble.of(42d).get(), 0);
try {
OptionalDouble.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(42d), 0);
}
@Test
public void orWithSupplier() throws Exception { | Assert.assertEquals(42d, OptionalDouble.absent().or(new DoubleSupplier() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | }
@Test
public void or() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(42d), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(new DoubleSupplier() {
@Override
public double get() {
return 42d;
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalDouble.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
}
@Test
public void or() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(42d), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42d, OptionalDouble.absent().or(new DoubleSupplier() {
@Override
public double get() {
return 42d;
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalDouble.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void orThrow() throws Exception {
try {
OptionalDouble.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalDouble.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void orThrow() throws Exception {
try {
OptionalDouble.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalDouble.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | OptionalDouble.of(42d).ifPresent(new DoubleConsumer() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalDouble.of(42d).ifPresent(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.assertEquals(42d, value, 0);
}
});
OptionalDouble.absent().ifPresent(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalDouble.of(42d).ifPresentOrElse(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.assertEquals(42d, value, 0);
} | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalDoubleTest.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalDouble.of(42d).ifPresent(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.assertEquals(42d, value, 0);
}
});
OptionalDouble.absent().ifPresent(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalDouble.of(42d).ifPresentOrElse(new DoubleConsumer() {
@Override
public void consume(double value) {
Assert.assertEquals(42d, value, 0);
} | }, new Function() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalIntTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | /*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalIntTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalInt.of(42).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalInt.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalInt.of(42).isPresent());
Assert.assertFalse(OptionalInt.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42, OptionalInt.of(42).get());
try {
OptionalInt.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(42));
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalIntTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
/*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalIntTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalInt.of(42).isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalInt.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalInt.of(42).isPresent());
Assert.assertFalse(OptionalInt.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals(42, OptionalInt.of(42).get());
try {
OptionalInt.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(42));
}
@Test
public void orWithSupplier() throws Exception { | Assert.assertEquals(42, OptionalInt.absent().or(new IntSupplier() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalIntTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | }
@Test
public void or() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(42));
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(new IntSupplier() {
@Override
public int get() {
return 42;
}
}));
}
@Test
public void orThrow() throws Exception {
try {
OptionalInt.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalIntTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
}
@Test
public void or() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(42));
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals(42, OptionalInt.absent().or(new IntSupplier() {
@Override
public int get() {
return 42;
}
}));
}
@Test
public void orThrow() throws Exception {
try {
OptionalInt.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalIntTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void orThrow() throws Exception {
try {
OptionalInt.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalInt.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalIntTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void orThrow() throws Exception {
try {
OptionalInt.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalInt.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | OptionalInt.of(42).ifPresent(new IntConsumer() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalIntTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalInt.of(42).ifPresent(new IntConsumer() {
@Override
public void consume(int value) {
Assert.assertEquals(42, value);
}
});
OptionalInt.absent().ifPresent(new IntConsumer() {
@Override
public void consume(int value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalInt.of(42).ifPresentOrElse(new IntConsumer() {
@Override
public void consume(int value) {
Assert.assertEquals(42, value);
} | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalIntTest.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalInt.of(42).ifPresent(new IntConsumer() {
@Override
public void consume(int value) {
Assert.assertEquals(42, value);
}
});
OptionalInt.absent().ifPresent(new IntConsumer() {
@Override
public void consume(int value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalInt.of(42).ifPresentOrElse(new IntConsumer() {
@Override
public void consume(int value) {
Assert.assertEquals(42, value);
} | }, new Function() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; |
Assert.assertFalse(Optional.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals("42", Optional.of("42").get());
Assert.assertEquals("42", Optional.ofNullable("42").get());
try {
Optional.ofNullable(null).get();
Optional.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals("42", Optional.ofNullable(null).or("42"));
Assert.assertEquals("42", Optional.absent().or("42"));
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalTest.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.assertFalse(Optional.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals("42", Optional.of("42").get());
Assert.assertEquals("42", Optional.ofNullable("42").get());
try {
Optional.ofNullable(null).get();
Optional.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals("42", Optional.ofNullable(null).or("42"));
Assert.assertEquals("42", Optional.absent().or("42"));
}
@Test
public void orWithSupplier() throws Exception { | final Supplier<String> aStringSupplier = new Supplier<String>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; |
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
Optional.ofNullable(null).orThrow(anExceptionSupplier);
Optional.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orNull() throws Exception {
Assert.assertNull(Optional.ofNullable(null).orNull());
Assert.assertNull(Optional.absent().orNull());
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalTest.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
Optional.ofNullable(null).orThrow(anExceptionSupplier);
Optional.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orNull() throws Exception {
Assert.assertNull(Optional.ofNullable(null).orNull());
Assert.assertNull(Optional.absent().orNull());
}
@Test
public void ifPresent() throws Exception { | Optional.ofNullable("42").ifPresent(new Consumer<String>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalTest.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void ifPresent() throws Exception {
Optional.ofNullable("42").ifPresent(new Consumer<String>() {
@Override
public void consume(String value) {
Assert.assertEquals("42", value);
}
});
Optional.ofNullable(null).ifPresent(new Consumer<Object>() {
@Override
public void consume(Object value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
Optional.absent().ifPresent(new Consumer<Object>() {
@Override
public void consume(Object value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
Optional.ofNullable("42").ifPresentOrElse(new Consumer<String>() {
@Override
public void consume(String value) {
Assert.assertEquals("42", value);
} | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalTest.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void ifPresent() throws Exception {
Optional.ofNullable("42").ifPresent(new Consumer<String>() {
@Override
public void consume(String value) {
Assert.assertEquals("42", value);
}
});
Optional.ofNullable(null).ifPresent(new Consumer<Object>() {
@Override
public void consume(Object value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
Optional.absent().ifPresent(new Consumer<Object>() {
@Override
public void consume(Object value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
Optional.ofNullable("42").ifPresentOrElse(new Consumer<String>() {
@Override
public void consume(String value) {
Assert.assertEquals("42", value);
} | }, new Function() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalCharTest.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | /*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalCharTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalChar.of('H').isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalChar.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalChar.of('H').isPresent());
Assert.assertFalse(OptionalChar.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals('H', OptionalChar.of('H').get(), 0);
try {
OptionalChar.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or('H'), 0);
}
@Test
public void orWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalCharTest.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
/*
* Copyright (C) 2016 Hadi Satrio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.hadisatrio.optional;
public class OptionalCharTest {
@Test
public void of() throws Exception {
Assert.assertTrue(OptionalChar.of('H').isPresent());
}
@Test
public void absent() throws Exception {
Assert.assertFalse(OptionalChar.absent().isPresent());
}
@Test
public void isPresent() throws Exception {
Assert.assertTrue(OptionalChar.of('H').isPresent());
Assert.assertFalse(OptionalChar.absent().isPresent());
}
@Test
public void get() throws Exception {
Assert.assertEquals('H', OptionalChar.of('H').get(), 0);
try {
OptionalChar.absent().get();
Assert.fail("Invoking get() on an absent optional should raise an exception.");
} catch (IllegalStateException expected) {
// No-op. This is the expected behaviour.
}
}
@Test
public void or() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or('H'), 0);
}
@Test
public void orWithSupplier() throws Exception { | Assert.assertEquals('H', OptionalChar.absent().or(new CharSupplier() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalCharTest.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | }
@Test
public void or() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or('H'), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or(new CharSupplier() {
@Override
public char get() {
return 'H';
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalChar.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalCharTest.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
}
@Test
public void or() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or('H'), 0);
}
@Test
public void orWithSupplier() throws Exception {
Assert.assertEquals('H', OptionalChar.absent().or(new CharSupplier() {
@Override
public char get() {
return 'H';
}
}), 0);
}
@Test
public void orThrow() throws Exception {
try {
OptionalChar.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception { | final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalCharTest.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | public void orThrow() throws Exception {
try {
OptionalChar.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalChar.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalCharTest.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
public void orThrow() throws Exception {
try {
OptionalChar.absent().orThrow(new Exception("An exception occurred."));
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void orThrowWithSupplier() throws Exception {
final Supplier<Exception> anExceptionSupplier = new Supplier<Exception>() {
@Override
public Exception get() {
return new Exception("An exception occurred.");
}
};
try {
OptionalChar.absent().orThrow(anExceptionSupplier);
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception { | OptionalChar.of('H').ifPresent(new CharConsumer() { |
MrHadiSatrio/Optional | src/test/java/com/hadisatrio/optional/OptionalCharTest.java | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test; | Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalChar.of('H').ifPresent(new CharConsumer() {
@Override
public void consume(char value) {
Assert.assertEquals('H', value, 0);
}
});
OptionalChar.absent().ifPresent(new CharConsumer() {
@Override
public void consume(char value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalChar.of('H').ifPresentOrElse(new CharConsumer() {
@Override
public void consume(char value) {
Assert.assertEquals('H', value, 0);
} | // Path: src/main/java/com/hadisatrio/optional/function/CharConsumer.java
// public interface CharConsumer {
//
// void consume(char value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/CharSupplier.java
// public interface CharSupplier {
//
// char get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/test/java/com/hadisatrio/optional/OptionalCharTest.java
import com.hadisatrio.optional.function.CharConsumer;
import com.hadisatrio.optional.function.CharSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
Assert.fail("Invoking orThrow() on an absent optional should throw an exception.");
} catch (Exception anException) {
// No-op. This is the expected behaviour.
}
}
@Test
public void ifPresent() throws Exception {
OptionalChar.of('H').ifPresent(new CharConsumer() {
@Override
public void consume(char value) {
Assert.assertEquals('H', value, 0);
}
});
OptionalChar.absent().ifPresent(new CharConsumer() {
@Override
public void consume(char value) {
Assert.fail("ifPresent() on an absent optional should never call its consumer");
}
});
}
@Test
public void ifPresentOrElse() throws Exception {
OptionalChar.of('H').ifPresentOrElse(new CharConsumer() {
@Override
public void consume(char value) {
Assert.assertEquals('H', value, 0);
} | }, new Function() { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalDouble.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalDouble}
* @throws IllegalStateException if there is no value present
*/
public double get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public double or(double other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalDouble.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalDouble}
* @throws IllegalStateException if there is no value present
*/
public double get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public double or(double other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public double or(DoubleSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalDouble.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> double orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalDouble.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> double orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> double orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalDouble.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> double orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalDouble.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> double orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(DoubleConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalDouble.java | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> double orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(DoubleConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/DoubleConsumer.java
// public interface DoubleConsumer {
//
// void consume(double value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/DoubleSupplier.java
// public interface DoubleSupplier {
//
// double get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalDouble.java
import com.hadisatrio.optional.function.DoubleConsumer;
import com.hadisatrio.optional.function.DoubleSupplier;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> double orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(DoubleConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(DoubleConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/Optional.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present, may not
* be null
* @return the value, if present, otherwise {@code other}
* @throws IllegalArgumentException if {@code other} is null
*/
public T or(T other) {
if (other == null) {
throw new IllegalArgumentException("null may not be passed as an argument; use orNull() instead.");
}
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/Optional.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present, may not
* be null
* @return the value, if present, otherwise {@code other}
* @throws IllegalArgumentException if {@code other} is null
*/
public T or(T other) {
if (other == null) {
throw new IllegalArgumentException("null may not be passed as an argument; use orNull() instead.");
}
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public T or(Supplier<T> otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/Optional.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> T orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument; use orNull() instead.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* Return the contained value, if present, otherwise null.
*
* @return the present value, if present, otherwise null
*/
public T orNull() {
return isPresent() ? value : null;
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/Optional.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> T orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument; use orNull() instead.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* Return the contained value, if present, otherwise null.
*
* @return the present value, if present, otherwise null
*/
public T orNull() {
return isPresent() ? value : null;
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(Consumer<T> consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/Optional.java | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise null.
*
* @return the present value, if present, otherwise null
*/
public T orNull() {
return isPresent() ? value : null;
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(Consumer<T> consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Consumer.java
// public interface Consumer<T> {
//
// void consume(T value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/Optional.java
import com.hadisatrio.optional.function.Consumer;
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise null.
*
* @return the present value, if present, otherwise null
*/
public T orNull() {
return isPresent() ? value : null;
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(Consumer<T> consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(Consumer<T> consumer, Function function) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalShort.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalShort}
* @throws IllegalStateException if there is no value present
*/
public short get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public short or(short other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalShort.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalShort}
* @throws IllegalStateException if there is no value present
*/
public short get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public short or(short other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public short or(ShortSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalShort.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> short orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalShort.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> short orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> short orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalShort.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | }
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> short orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalShort.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/
public <X extends Throwable> short orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(ShortConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalShort.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | public <X extends Throwable> short orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(ShortConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortConsumer.java
// public interface ShortConsumer {
//
// void consume(short value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/ShortSupplier.java
// public interface ShortSupplier {
//
// short get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalShort.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.ShortConsumer;
import com.hadisatrio.optional.function.ShortSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
public <X extends Throwable> short orThrow(Supplier<? extends X> throwableSupplier) throws X {
if (throwableSupplier == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwableSupplier.get();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(ShortConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(ShortConsumer consumer, Function function) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalInt.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | *
* @return the value held by this {@code OptionalInt}
* @throws IllegalStateException if there is no value present
*/
public int get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public int or(int other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalInt.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
*
* @return the value held by this {@code OptionalInt}
* @throws IllegalStateException if there is no value present
*/
public int get() {
if (isPresent()) {
return value;
}
throw new IllegalStateException("Value is absent.");
}
/**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present
* @return the value, if present, otherwise {@code other}
*/
public int or(int other) {
return isPresent() ? value : other;
}
/**
* Return the value if present, otherwise invoke {@code otherSupplier} and return
* the result of that invocation.
*
* @param otherSupplier a {@code Supplier} whose result is returned if no value
* is present
* @return the value if present otherwise the result of {@code otherSupplier.get()}
* @throws IllegalArgumentException if {@code otherSupplier} is null
*/ | public int or(IntSupplier otherSupplier) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalInt.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> int orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalInt.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* instance provided as the parameter.
*
* @param <X> Type of the exception to be thrown
* @param throwable The throwable instance to be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwable} is null
*/
public <X extends Throwable> int orThrow(X throwable) throws X {
if (throwable == null) {
throw new IllegalArgumentException("null may not be passed as an argument.");
}
if (isPresent()) {
return value;
}
throw throwable;
}
/**
* Return the contained value, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* @param <X> Type of the exception to be thrown
* @param throwableSupplier a {@code Supplier} which will return the exception to
* be thrown
* @return the present value
* @throws X if there is no value present
* @throws IllegalArgumentException if {@code throwableSupplier} is null
*/ | public <X extends Throwable> int orThrow(Supplier<? extends X> throwableSupplier) throws X { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalInt.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; | * <li>the present values are "equal to" each other via the "{@code ==}"
* operator.
* </ul>
*
* @param object an object to be tested for equality
* @return {code true} if the other object is "equal to" this object
* otherwise {@code false}
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof OptionalInt)) {
return false;
}
final OptionalInt other = (OptionalInt) object;
return (isPresent() && other.isPresent())
? get() == other.get()
: isPresent() == other.isPresent();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalInt.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
* <li>the present values are "equal to" each other via the "{@code ==}"
* operator.
* </ul>
*
* @param object an object to be tested for equality
* @return {code true} if the other object is "equal to" this object
* otherwise {@code false}
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof OptionalInt)) {
return false;
}
final OptionalInt other = (OptionalInt) object;
return (isPresent() && other.isPresent())
? get() == other.get()
: isPresent() == other.isPresent();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/ | public void ifPresent(IntConsumer consumer) { |
MrHadiSatrio/Optional | src/main/java/com/hadisatrio/optional/OptionalInt.java | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
| import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable; |
if (!(object instanceof OptionalInt)) {
return false;
}
final OptionalInt other = (OptionalInt) object;
return (isPresent() && other.isPresent())
? get() == other.get()
: isPresent() == other.isPresent();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(IntConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | // Path: src/main/java/com/hadisatrio/optional/function/Function.java
// public interface Function {
//
// void call();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntConsumer.java
// public interface IntConsumer {
//
// void consume(int value);
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/IntSupplier.java
// public interface IntSupplier {
//
// int get();
// }
//
// Path: src/main/java/com/hadisatrio/optional/function/Supplier.java
// public interface Supplier<T> {
//
// T get();
// }
// Path: src/main/java/com/hadisatrio/optional/OptionalInt.java
import com.hadisatrio.optional.function.Function;
import com.hadisatrio.optional.function.IntConsumer;
import com.hadisatrio.optional.function.IntSupplier;
import com.hadisatrio.optional.function.Supplier;
import java.io.Serializable;
if (!(object instanceof OptionalInt)) {
return false;
}
final OptionalInt other = (OptionalInt) object;
return (isPresent() && other.isPresent())
? get() == other.get()
: isPresent() == other.isPresent();
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise do nothing.
*
* @param consumer block to be executed if a value is present
*/
public void ifPresent(IntConsumer consumer) {
if (isPresent()) {
consumer.consume(value);
}
}
/**
* If a value is present, invoke the specified consumer with the value,
* otherwise invoke the function passed as the second parameter.
*
* @param consumer block to be executed if a value is present
* @param function block to be executed if a value is absent
*/ | public void ifPresentOrElse(IntConsumer consumer, Function function) { |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/client/gui/element/GuiButton2State.java | // Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
| import p455w0rdslib.api.gui.IModularGui; | package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public class GuiButton2State extends GuiButton {
String text1 = "", text2 = "";
boolean state = true;
| // Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
// Path: src/main/java/p455w0rdslib/client/gui/element/GuiButton2State.java
import p455w0rdslib.api.gui.IModularGui;
package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public class GuiButton2State extends GuiButton {
String text1 = "", text2 = "";
boolean state = true;
| public GuiButton2State(IModularGui gui, GuiPos posIn, int height, String label, String label2) { |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/entity/EntitySittableBlock.java | // Path: src/main/java/p455w0rdslib/util/EasyMappings.java
// public class EasyMappings {
//
// @SideOnly(Side.CLIENT)
// public static Minecraft mc() {
// return Minecraft.getMinecraft();
// }
//
// @SideOnly(Side.CLIENT)
// public static EntityPlayerSP player() {
// return mc().player;
// }
//
// @SideOnly(Side.CLIENT)
// public static World world() {
// return mc().world;
// }
//
// public static World world(Entity entity) {
// return entity.world;
// }
//
// public static int slotPosX(Slot slot) {
// return slot.xPos;
// }
//
// public static int slotPosY(Slot slot) {
// return slot.yPos;
// }
//
// public static boolean spawn(World world, Entity entity) {
// return world.spawnEntity(entity);
// }
//
// public static NBTTagCompound readNBT(PacketBuffer buf) {
// try {
// return buf.readCompoundTag();
// }
// catch (IOException e) {
// }
// return null;
// }
//
// public static PacketBuffer writeNBT(@Nullable NBTTagCompound nbt, PacketBuffer buf) {
// return buf.writeCompoundTag(nbt);
// }
//
// public static String[] getNames(MinecraftServer server) {
// return server.getOnlinePlayerNames();
// }
//
// public static void message(Entity entity, ITextComponent message) {
// entity.sendMessage(message);
// }
//
// }
| import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import p455w0rdslib.util.EasyMappings; | public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
switch (rotation) {
case 2:
z += rotationOffset;
break;
case 0:
z -= rotationOffset;
break;
case 3:
x -= rotationOffset;
break;
case 1:
x += rotationOffset;
break;
}
setPosition(x, y, z);
}
@Override
public double getMountedYOffset() {
return height * 0.0D;
}
@Override
protected boolean shouldSetPosAfterLoading() {
return false;
}
@Override
public void onEntityUpdate() { | // Path: src/main/java/p455w0rdslib/util/EasyMappings.java
// public class EasyMappings {
//
// @SideOnly(Side.CLIENT)
// public static Minecraft mc() {
// return Minecraft.getMinecraft();
// }
//
// @SideOnly(Side.CLIENT)
// public static EntityPlayerSP player() {
// return mc().player;
// }
//
// @SideOnly(Side.CLIENT)
// public static World world() {
// return mc().world;
// }
//
// public static World world(Entity entity) {
// return entity.world;
// }
//
// public static int slotPosX(Slot slot) {
// return slot.xPos;
// }
//
// public static int slotPosY(Slot slot) {
// return slot.yPos;
// }
//
// public static boolean spawn(World world, Entity entity) {
// return world.spawnEntity(entity);
// }
//
// public static NBTTagCompound readNBT(PacketBuffer buf) {
// try {
// return buf.readCompoundTag();
// }
// catch (IOException e) {
// }
// return null;
// }
//
// public static PacketBuffer writeNBT(@Nullable NBTTagCompound nbt, PacketBuffer buf) {
// return buf.writeCompoundTag(nbt);
// }
//
// public static String[] getNames(MinecraftServer server) {
// return server.getOnlinePlayerNames();
// }
//
// public static void message(Entity entity, ITextComponent message) {
// entity.sendMessage(message);
// }
//
// }
// Path: src/main/java/p455w0rdslib/entity/EntitySittableBlock.java
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import p455w0rdslib.util.EasyMappings;
public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
switch (rotation) {
case 2:
z += rotationOffset;
break;
case 0:
z -= rotationOffset;
break;
case 3:
x -= rotationOffset;
break;
case 1:
x += rotationOffset;
break;
}
setPosition(x, y, z);
}
@Override
public double getMountedYOffset() {
return height * 0.0D;
}
@Override
protected boolean shouldSetPosAfterLoading() {
return false;
}
@Override
public void onEntityUpdate() { | if (!EasyMappings.world(this).isRemote) { |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/capabilities/CapabilityChunkLoader.java | // Path: src/main/java/p455w0rdslib/util/ChunkUtils.java
// public static class TicketHandler {
//
// private static final TicketHandler INSTANCE = new TicketHandler();
//
// private TicketHandler() {
// }
//
// public static TicketHandler getInstance() {
// return INSTANCE;
// }
//
// public Ticket getTicket(Object modInstnace, World world) {
// return ForgeChunkManager.requestTicket(modInstnace, world, ForgeChunkManager.Type.NORMAL);
// }
//
// public void load(World world, BlockPos pos, Ticket ticket) {
// if (world != null && !world.isRemote && pos != null) {
// if (!ForgeChunkManager.getPersistentChunksFor(world).containsKey(ChunkUtils.getChunkPos(world, pos))) {
// ticket.getModData().setInteger("xCoord", pos.getX());
// ticket.getModData().setInteger("yCoord", pos.getY());
// ticket.getModData().setInteger("zCoord", pos.getZ());
// ForgeChunkManager.forceChunk(ticket, ChunkUtils.getChunkPos(world, pos));
// }
// }
// }
//
// public void unload(World world, BlockPos pos, Ticket ticket) {
// if (world != null && !world.isRemote && pos != null) {
// if (ForgeChunkManager.getPersistentChunksFor(world).containsKey(ChunkUtils.getChunkPos(world, pos))) {
// ForgeChunkManager.unforceChunk(ticket, ChunkUtils.getChunkPos(world, pos));
// ForgeChunkManager.releaseTicket(ticket);
// }
// }
// }
// }
| import java.util.ArrayList;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.FMLCommonHandler;
import p455w0rdslib.util.ChunkUtils.TicketHandler; | void remove(BlockPos pos);
/**
* sets a full list to a player-mainly used for persisting data after
* death
*
* @param list
*/
void set(ArrayList<BlockPos> list);
/**
*
* @return total number of chunkloaders placed in world by the player
*/
int total();
}
public static class DefaultCLTEHandler implements ICLTEHandler {
TileEntity tile;
@Override
public void setTileEntity(TileEntity te) {
tile = te;
}
@Override
public void attachChunkLoader(Object modInstance) {
if (tile != null) { | // Path: src/main/java/p455w0rdslib/util/ChunkUtils.java
// public static class TicketHandler {
//
// private static final TicketHandler INSTANCE = new TicketHandler();
//
// private TicketHandler() {
// }
//
// public static TicketHandler getInstance() {
// return INSTANCE;
// }
//
// public Ticket getTicket(Object modInstnace, World world) {
// return ForgeChunkManager.requestTicket(modInstnace, world, ForgeChunkManager.Type.NORMAL);
// }
//
// public void load(World world, BlockPos pos, Ticket ticket) {
// if (world != null && !world.isRemote && pos != null) {
// if (!ForgeChunkManager.getPersistentChunksFor(world).containsKey(ChunkUtils.getChunkPos(world, pos))) {
// ticket.getModData().setInteger("xCoord", pos.getX());
// ticket.getModData().setInteger("yCoord", pos.getY());
// ticket.getModData().setInteger("zCoord", pos.getZ());
// ForgeChunkManager.forceChunk(ticket, ChunkUtils.getChunkPos(world, pos));
// }
// }
// }
//
// public void unload(World world, BlockPos pos, Ticket ticket) {
// if (world != null && !world.isRemote && pos != null) {
// if (ForgeChunkManager.getPersistentChunksFor(world).containsKey(ChunkUtils.getChunkPos(world, pos))) {
// ForgeChunkManager.unforceChunk(ticket, ChunkUtils.getChunkPos(world, pos));
// ForgeChunkManager.releaseTicket(ticket);
// }
// }
// }
// }
// Path: src/main/java/p455w0rdslib/capabilities/CapabilityChunkLoader.java
import java.util.ArrayList;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.FMLCommonHandler;
import p455w0rdslib.util.ChunkUtils.TicketHandler;
void remove(BlockPos pos);
/**
* sets a full list to a player-mainly used for persisting data after
* death
*
* @param list
*/
void set(ArrayList<BlockPos> list);
/**
*
* @return total number of chunkloaders placed in world by the player
*/
int total();
}
public static class DefaultCLTEHandler implements ICLTEHandler {
TileEntity tile;
@Override
public void setTileEntity(TileEntity te) {
tile = te;
}
@Override
public void attachChunkLoader(Object modInstance) {
if (tile != null) { | TicketHandler handler = TicketHandler.getInstance(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/PlayerUUIDUtils.java | // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public class LibGlobals {
// public static final String MODID = "p455w0rdslib";
// public static final String VERSION = "1.0.35";
// public static final String NAME = "p455w0rd's Library";
// public static final String SERVER_PROXY = "p455w0rdslib.proxy.CommonProxy";
// public static final String CLIENT_PROXY = "p455w0rdslib.proxy.ClientProxy";
// public static final String DEPENDENCIES = "after:mantle;after:tconstruct;after:enderio;after:ProjectE;after:tesla";
// public static final String CONFIG_FILE = "config/p455w0rdsLib.cfg";
// public static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
// public static int ELAPSED_TICKS = 0;
// public static boolean IS_CONTRIBUTOR = false;
// public static boolean CONTRIBUTOR_FILE_DOWNLOADED = false;
//
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
// }
//
// Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.io.Resources;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import p455w0rdslib.LibGlobals;
import p455w0rdslib.LibRegistry; | package p455w0rdslib.util;
/**
* Utility for fetching online player names and UUIDs<br>
* Calls performed on separate thread
*
* @author p455w0rd
*
*/
public class PlayerUUIDUtils {
public static String getPlayerName(final UUID uuid) {
String retVal = "";
try { | // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public class LibGlobals {
// public static final String MODID = "p455w0rdslib";
// public static final String VERSION = "1.0.35";
// public static final String NAME = "p455w0rd's Library";
// public static final String SERVER_PROXY = "p455w0rdslib.proxy.CommonProxy";
// public static final String CLIENT_PROXY = "p455w0rdslib.proxy.ClientProxy";
// public static final String DEPENDENCIES = "after:mantle;after:tconstruct;after:enderio;after:ProjectE;after:tesla";
// public static final String CONFIG_FILE = "config/p455w0rdsLib.cfg";
// public static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
// public static int ELAPSED_TICKS = 0;
// public static boolean IS_CONTRIBUTOR = false;
// public static boolean CONTRIBUTOR_FILE_DOWNLOADED = false;
//
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
// }
//
// Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
// Path: src/main/java/p455w0rdslib/util/PlayerUUIDUtils.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.io.Resources;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import p455w0rdslib.LibGlobals;
import p455w0rdslib.LibRegistry;
package p455w0rdslib.util;
/**
* Utility for fetching online player names and UUIDs<br>
* Calls performed on separate thread
*
* @author p455w0rd
*
*/
public class PlayerUUIDUtils {
public static String getPlayerName(final UUID uuid) {
String retVal = "";
try { | retVal = LibGlobals.THREAD_POOL.submit(() -> fetchPlayerName(uuid)).get(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/PlayerUUIDUtils.java | // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public class LibGlobals {
// public static final String MODID = "p455w0rdslib";
// public static final String VERSION = "1.0.35";
// public static final String NAME = "p455w0rd's Library";
// public static final String SERVER_PROXY = "p455w0rdslib.proxy.CommonProxy";
// public static final String CLIENT_PROXY = "p455w0rdslib.proxy.ClientProxy";
// public static final String DEPENDENCIES = "after:mantle;after:tconstruct;after:enderio;after:ProjectE;after:tesla";
// public static final String CONFIG_FILE = "config/p455w0rdsLib.cfg";
// public static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
// public static int ELAPSED_TICKS = 0;
// public static boolean IS_CONTRIBUTOR = false;
// public static boolean CONTRIBUTOR_FILE_DOWNLOADED = false;
//
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
// }
//
// Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
| import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.io.Resources;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import p455w0rdslib.LibGlobals;
import p455w0rdslib.LibRegistry; | package p455w0rdslib.util;
/**
* Utility for fetching online player names and UUIDs<br>
* Calls performed on separate thread
*
* @author p455w0rd
*
*/
public class PlayerUUIDUtils {
public static String getPlayerName(final UUID uuid) {
String retVal = "";
try {
retVal = LibGlobals.THREAD_POOL.submit(() -> fetchPlayerName(uuid)).get();
}
catch (InterruptedException | ExecutionException e) {
}
return retVal;
};
public static UUID getPlayerUUID(final String name) {
try {
return LibGlobals.THREAD_POOL.submit(() -> fetchPlayerUUID(name)).get();
}
catch (InterruptedException | ExecutionException e) {
}
return null;
};
public static EntityPlayer getPlayerFromWorld(World world, UUID player) {
if (player == null || world == null) {
return null;
}
return world.getPlayerEntityByUUID(player);
}
private static String fetchPlayerName(final UUID uuid) throws IOException { | // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public class LibGlobals {
// public static final String MODID = "p455w0rdslib";
// public static final String VERSION = "1.0.35";
// public static final String NAME = "p455w0rd's Library";
// public static final String SERVER_PROXY = "p455w0rdslib.proxy.CommonProxy";
// public static final String CLIENT_PROXY = "p455w0rdslib.proxy.ClientProxy";
// public static final String DEPENDENCIES = "after:mantle;after:tconstruct;after:enderio;after:ProjectE;after:tesla";
// public static final String CONFIG_FILE = "config/p455w0rdsLib.cfg";
// public static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
// public static int ELAPSED_TICKS = 0;
// public static boolean IS_CONTRIBUTOR = false;
// public static boolean CONTRIBUTOR_FILE_DOWNLOADED = false;
//
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
// }
//
// Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
// Path: src/main/java/p455w0rdslib/util/PlayerUUIDUtils.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.io.Resources;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import p455w0rdslib.LibGlobals;
import p455w0rdslib.LibRegistry;
package p455w0rdslib.util;
/**
* Utility for fetching online player names and UUIDs<br>
* Calls performed on separate thread
*
* @author p455w0rd
*
*/
public class PlayerUUIDUtils {
public static String getPlayerName(final UUID uuid) {
String retVal = "";
try {
retVal = LibGlobals.THREAD_POOL.submit(() -> fetchPlayerName(uuid)).get();
}
catch (InterruptedException | ExecutionException e) {
}
return retVal;
};
public static UUID getPlayerUUID(final String name) {
try {
return LibGlobals.THREAD_POOL.submit(() -> fetchPlayerUUID(name)).get();
}
catch (InterruptedException | ExecutionException e) {
}
return null;
};
public static EntityPlayer getPlayerFromWorld(World world, UUID player) {
if (player == null || world == null) {
return null;
}
return world.getPlayerEntityByUUID(player);
}
private static String fetchPlayerName(final UUID uuid) throws IOException { | if (LibRegistry.getNameRegistry().containsKey(uuid)) { |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/client/gui/element/GuiElement.java | // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
| import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.util.ResourceLocation;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IModularGui; | package p455w0rdslib.client.gui.element;
/**
* Base class for all GUI elements
*
* @author p455w0rd
*
*/
public abstract class GuiElement implements IGuiElement {
protected static final ResourceLocation VANILLA_BUTTON_TEXTURES = new ResourceLocation("textures/gui/widgets.png");
| // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
// Path: src/main/java/p455w0rdslib/client/gui/element/GuiElement.java
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.util.ResourceLocation;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IModularGui;
package p455w0rdslib.client.gui.element;
/**
* Base class for all GUI elements
*
* @author p455w0rd
*
*/
public abstract class GuiElement implements IGuiElement {
protected static final ResourceLocation VANILLA_BUTTON_TEXTURES = new ResourceLocation("textures/gui/widgets.png");
| private IModularGui gui; |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/SittableUtil.java | // Path: src/main/java/p455w0rdslib/entity/EntitySittableBlock.java
// public class EntitySittableBlock extends Entity {
//
// public int blockPosX;
// public int blockPosY;
// public int blockPosZ;
//
// public EntitySittableBlock(World world) {
// super(world);
// noClip = true;
// height = 0.01F;
// width = 0.01F;
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPosition(x + 0.5D, y + y0ffset, z + 0.5D);
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset, int rotation, double rotationOffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPostionConsideringRotation(x + 0.5D, y + y0ffset, z + 0.5D, rotation, rotationOffset);
// }
//
// public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
// switch (rotation) {
// case 2:
// z += rotationOffset;
// break;
// case 0:
// z -= rotationOffset;
// break;
// case 3:
// x -= rotationOffset;
// break;
// case 1:
// x += rotationOffset;
// break;
// }
// setPosition(x, y, z);
// }
//
// @Override
// public double getMountedYOffset() {
// return height * 0.0D;
// }
//
// @Override
// protected boolean shouldSetPosAfterLoading() {
// return false;
// }
//
// @Override
// public void onEntityUpdate() {
// if (!EasyMappings.world(this).isRemote) {
// if (!isBeingRidden() || EasyMappings.world(this).isAirBlock(new BlockPos(blockPosX, blockPosY, blockPosZ))) {
// setDead();
// EasyMappings.world(this).updateComparatorOutputLevel(getPosition(), EasyMappings.world(this).getBlockState(getPosition()).getBlock());
// }
// }
// }
//
// @Override
// protected void entityInit() {
// }
//
// @Override
// public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
// }
//
// @Override
// public void writeEntityToNBT(NBTTagCompound nbttagcompound) {
// }
//
// }
| import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import p455w0rdslib.entity.EntitySittableBlock; | package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class SittableUtil {
public static boolean sitOnBlock(World par1World, double x, double y, double z, EntityPlayer par5EntityPlayer, double par6) {
if (!checkForExistingEntity(par1World, x, y, z, par5EntityPlayer)) { | // Path: src/main/java/p455w0rdslib/entity/EntitySittableBlock.java
// public class EntitySittableBlock extends Entity {
//
// public int blockPosX;
// public int blockPosY;
// public int blockPosZ;
//
// public EntitySittableBlock(World world) {
// super(world);
// noClip = true;
// height = 0.01F;
// width = 0.01F;
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPosition(x + 0.5D, y + y0ffset, z + 0.5D);
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset, int rotation, double rotationOffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPostionConsideringRotation(x + 0.5D, y + y0ffset, z + 0.5D, rotation, rotationOffset);
// }
//
// public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
// switch (rotation) {
// case 2:
// z += rotationOffset;
// break;
// case 0:
// z -= rotationOffset;
// break;
// case 3:
// x -= rotationOffset;
// break;
// case 1:
// x += rotationOffset;
// break;
// }
// setPosition(x, y, z);
// }
//
// @Override
// public double getMountedYOffset() {
// return height * 0.0D;
// }
//
// @Override
// protected boolean shouldSetPosAfterLoading() {
// return false;
// }
//
// @Override
// public void onEntityUpdate() {
// if (!EasyMappings.world(this).isRemote) {
// if (!isBeingRidden() || EasyMappings.world(this).isAirBlock(new BlockPos(blockPosX, blockPosY, blockPosZ))) {
// setDead();
// EasyMappings.world(this).updateComparatorOutputLevel(getPosition(), EasyMappings.world(this).getBlockState(getPosition()).getBlock());
// }
// }
// }
//
// @Override
// protected void entityInit() {
// }
//
// @Override
// public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
// }
//
// @Override
// public void writeEntityToNBT(NBTTagCompound nbttagcompound) {
// }
//
// }
// Path: src/main/java/p455w0rdslib/util/SittableUtil.java
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import p455w0rdslib.entity.EntitySittableBlock;
package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class SittableUtil {
public static boolean sitOnBlock(World par1World, double x, double y, double z, EntityPlayer par5EntityPlayer, double par6) {
if (!checkForExistingEntity(par1World, x, y, z, par5EntityPlayer)) { | EntitySittableBlock nemb = new EntitySittableBlock(par1World, x, y, z, par6); |
p455w0rd/p455w0rds-Library | src/main/java/moze_intel/projecte/api/proxy/ITransmutationProxy.java | // Path: src/main/java/moze_intel/projecte/api/capabilities/IKnowledgeProvider.java
// public interface IKnowledgeProvider extends INBTSerializable<NBTTagCompound> {
//
// /**
// * @return Whether the player has the "tome" flag set, meaning all knowledge
// * checks automatically return true
// */
// boolean hasFullKnowledge();
//
// /**
// * @param fullKnowledge
// * Whether the player has the "tome" flag set, meaning all
// * knowledge checks automatically return true
// */
// void setFullKnowledge(boolean fullKnowledge);
//
// /**
// * Clears all knowledge. Additionally, clears the "tome" flag.
// */
// void clearKnowledge();
//
// /**
// * @param stack
// * The stack to query
// * @return Whether the player has transmutation knowledge for this stack
// */
// boolean hasKnowledge(@Nullable ItemStack stack);
//
// /**
// * @param stack
// * The stack to add to knowledge
// * @return Whether the operation was successful
// */
// boolean addKnowledge(@Nonnull ItemStack stack);
//
// /**
// * @param stack
// * The stack to remove from knowledge
// * @return Whether the operation was successful
// */
// boolean removeKnowledge(@Nonnull ItemStack stack);
//
// /**
// * @return An unmodifiable but live view of the knowledge list.
// */
// @Nonnull
// List<ItemStack> getKnowledge();
//
// /**
// * @return The player's input and lock slots
// */
// @Nonnull
// IItemHandler getInputAndLocks();
//
// /**
// * @return The emc in this player's transmutation tablet network
// */
// double getEmc();
//
// /**
// * @param emc
// * The emc to set in this player's transmutation tablet network
// */
// void setEmc(double emc);
//
// /**
// * @param player
// * The player to sync to.
// */
// void sync(@Nonnull EntityPlayerMP player);
//
// }
| import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
import net.minecraft.block.state.IBlockState;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID; | package moze_intel.projecte.api.proxy;
public interface ITransmutationProxy {
/**
* Register a world transmutation with the Philosopher's Stone Calls this
* during the postinit phase
*
* @param origin
* Original blockstate when targeting world transmutation
* @param result1
* First result blockstate
* @param result2
* Alternate result blockstate (when sneaking). You may pass
* null, in which there will be no alternate transmutation
* @return Whether the registration succeeded. It may fail if transmutations
* already exist for block origin
*/
boolean registerWorldTransmutation(@Nonnull IBlockState origin, @Nonnull IBlockState result1, @Nullable IBlockState result2);
/**
* Gets an {@link IKnowledgeProvider} representing the UUID provided.
*
* If the provided UUID is offline, note that the returned
* {@link IKnowledgeProvider} is immutable! If called clientside,
* {@param playerUUID} is ignored and the client player is used instead. If
* called serverside, this must be called after the server has reached state
* SERVER_STARTED.
*
* If the provided UUID could not be found both on or offline, an
* {@link IKnowledgeProvider} with no knowledge is returned.
*
* @param playerUUID
* The UUID to query
* @return an {@link IKnowledgeProvider} representing the UUID provided, or
* an {@link IKnowledgeProvider} representing no knowledge if the
* requested UUID could not be found
*/
@Nonnull | // Path: src/main/java/moze_intel/projecte/api/capabilities/IKnowledgeProvider.java
// public interface IKnowledgeProvider extends INBTSerializable<NBTTagCompound> {
//
// /**
// * @return Whether the player has the "tome" flag set, meaning all knowledge
// * checks automatically return true
// */
// boolean hasFullKnowledge();
//
// /**
// * @param fullKnowledge
// * Whether the player has the "tome" flag set, meaning all
// * knowledge checks automatically return true
// */
// void setFullKnowledge(boolean fullKnowledge);
//
// /**
// * Clears all knowledge. Additionally, clears the "tome" flag.
// */
// void clearKnowledge();
//
// /**
// * @param stack
// * The stack to query
// * @return Whether the player has transmutation knowledge for this stack
// */
// boolean hasKnowledge(@Nullable ItemStack stack);
//
// /**
// * @param stack
// * The stack to add to knowledge
// * @return Whether the operation was successful
// */
// boolean addKnowledge(@Nonnull ItemStack stack);
//
// /**
// * @param stack
// * The stack to remove from knowledge
// * @return Whether the operation was successful
// */
// boolean removeKnowledge(@Nonnull ItemStack stack);
//
// /**
// * @return An unmodifiable but live view of the knowledge list.
// */
// @Nonnull
// List<ItemStack> getKnowledge();
//
// /**
// * @return The player's input and lock slots
// */
// @Nonnull
// IItemHandler getInputAndLocks();
//
// /**
// * @return The emc in this player's transmutation tablet network
// */
// double getEmc();
//
// /**
// * @param emc
// * The emc to set in this player's transmutation tablet network
// */
// void setEmc(double emc);
//
// /**
// * @param player
// * The player to sync to.
// */
// void sync(@Nonnull EntityPlayerMP player);
//
// }
// Path: src/main/java/moze_intel/projecte/api/proxy/ITransmutationProxy.java
import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
import net.minecraft.block.state.IBlockState;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID;
package moze_intel.projecte.api.proxy;
public interface ITransmutationProxy {
/**
* Register a world transmutation with the Philosopher's Stone Calls this
* during the postinit phase
*
* @param origin
* Original blockstate when targeting world transmutation
* @param result1
* First result blockstate
* @param result2
* Alternate result blockstate (when sneaking). You may pass
* null, in which there will be no alternate transmutation
* @return Whether the registration succeeded. It may fail if transmutations
* already exist for block origin
*/
boolean registerWorldTransmutation(@Nonnull IBlockState origin, @Nonnull IBlockState result1, @Nullable IBlockState result2);
/**
* Gets an {@link IKnowledgeProvider} representing the UUID provided.
*
* If the provided UUID is offline, note that the returned
* {@link IKnowledgeProvider} is immutable! If called clientside,
* {@param playerUUID} is ignored and the client player is used instead. If
* called serverside, this must be called after the server has reached state
* SERVER_STARTED.
*
* If the provided UUID could not be found both on or offline, an
* {@link IKnowledgeProvider} with no knowledge is returned.
*
* @param playerUUID
* The UUID to query
* @return an {@link IKnowledgeProvider} representing the UUID provided, or
* an {@link IKnowledgeProvider} representing no knowledge if the
* requested UUID could not be found
*/
@Nonnull | IKnowledgeProvider getKnowledgeProviderFor(@Nonnull UUID playerUUID); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/LibConfig.java | // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
| import java.io.File;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import p455w0rdslib.LibGlobals.ConfigOptions; | package p455w0rdslib;
/**
* @author p455w0rd
*
*/
public class LibConfig {
public static Configuration CONFIG;
private static String DEF_CAT = "Options";
@SubscribeEvent
public void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent e) {
if (e.getModID().equals(LibGlobals.MODID)) {
init();
}
}
public static void init() {
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
if (CONFIG == null) {
CONFIG = new Configuration(new File(LibGlobals.CONFIG_FILE));
MinecraftForge.EVENT_BUS.register(new LibConfig());
}
| // Path: src/main/java/p455w0rdslib/LibGlobals.java
// public static class ConfigOptions {
// public static boolean ENABLE_CONTRIB_CAPE = true;
// }
// Path: src/main/java/p455w0rdslib/LibConfig.java
import java.io.File;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import p455w0rdslib.LibGlobals.ConfigOptions;
package p455w0rdslib;
/**
* @author p455w0rd
*
*/
public class LibConfig {
public static Configuration CONFIG;
private static String DEF_CAT = "Options";
@SubscribeEvent
public void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent e) {
if (e.getModID().equals(LibGlobals.MODID)) {
init();
}
}
public static void init() {
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
if (CONFIG == null) {
CONFIG = new Configuration(new File(LibGlobals.CONFIG_FILE));
MinecraftForge.EVENT_BUS.register(new LibConfig());
}
| ConfigOptions.ENABLE_CONTRIB_CAPE = CONFIG.getBoolean("EnableContributorCosmetics", DEF_CAT, true, "Enable the contributor cosmetics (Only useful if u are a contributor, but don't want the cosmetics to override other cosmetics)"); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/ProxiedUtils.java | // Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
| import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import p455w0rdslib.P455w0rdsLib; | /*
* This file is part of p455w0rd's Library.
* Copyright (c) 2016, p455w0rd (aka TheRealp455w0rd), All rights reserved
* unless
* otherwise stated.
*
* p455w0rd's Library is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* p455w0rd's Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT License for more details.
*
* You should have received a copy of the MIT License
* along with p455w0rd's Library. If not, see
* <https://opensource.org/licenses/MIT>.
*/
package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class ProxiedUtils {
public static boolean isSMP() { | // Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
// Path: src/main/java/p455w0rdslib/util/ProxiedUtils.java
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import p455w0rdslib.P455w0rdsLib;
/*
* This file is part of p455w0rd's Library.
* Copyright (c) 2016, p455w0rd (aka TheRealp455w0rd), All rights reserved
* unless
* otherwise stated.
*
* p455w0rd's Library is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* p455w0rd's Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT License for more details.
*
* You should have received a copy of the MIT License
* along with p455w0rd's Library. If not, see
* <https://opensource.org/licenses/MIT>.
*/
package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class ProxiedUtils {
public static boolean isSMP() { | return P455w0rdsLib.PROXY.isSMP(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/client/gui/element/GuiButtonMultiState.java | // Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
| import java.util.List;
import com.google.common.collect.Lists;
import p455w0rdslib.api.gui.IModularGui; | package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public class GuiButtonMultiState extends GuiButton {
List<String> labels = Lists.newArrayList();
int index = 0;
| // Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
// Path: src/main/java/p455w0rdslib/client/gui/element/GuiButtonMultiState.java
import java.util.List;
import com.google.common.collect.Lists;
import p455w0rdslib.api.gui.IModularGui;
package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public class GuiButtonMultiState extends GuiButton {
List<String> labels = Lists.newArrayList();
int index = 0;
| public GuiButtonMultiState(IModularGui gui, GuiPos posIn, int height, List<String> labelsIn) { |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/PlayerUtils.java | // Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
//
// Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
| import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import p455w0rdslib.LibRegistry;
import p455w0rdslib.P455w0rdsLib; | package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class PlayerUtils {
public static EntityPlayer getPlayer() {
return EasyMappings.player();
}
public static EntityPlayer getPlayerByContext(MessageContext ctx) { | // Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
//
// Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
// Path: src/main/java/p455w0rdslib/util/PlayerUtils.java
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import p455w0rdslib.LibRegistry;
import p455w0rdslib.P455w0rdsLib;
package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class PlayerUtils {
public static EntityPlayer getPlayer() {
return EasyMappings.player();
}
public static EntityPlayer getPlayerByContext(MessageContext ctx) { | return P455w0rdsLib.PROXY.getPlayer(ctx); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/PlayerUtils.java | // Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
//
// Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
| import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import p455w0rdslib.LibRegistry;
import p455w0rdslib.P455w0rdsLib; | return false;
}
@SideOnly(Side.SERVER)
private static boolean isOPServer(EntityPlayer sender) {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) sender.getEntityWorld().getPlayerEntityByName(sender.getName());
if (player != null && player.getGameProfile() != null) {
UserListOpsEntry userentry = player.mcServer.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
return userentry != null && userentry.getPermissionLevel() >= 4;
}
}
return false;
}
public static List<UUID> getFullPlayerList() {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
List<UUID> uuidList = Lists.newArrayList();
if (server != null) {
PlayerProfileCache playerCache = server.getPlayerProfileCache();
String[] usernames = EasyMappings.getNames(server);
for (String username : usernames) {
uuidList.add(playerCache.getGameProfileForUsername(username).getId());
}
}
return uuidList;
}
public static ItemStack getPlayerSkull(String playerName) {
ItemStack head = null; | // Path: src/main/java/p455w0rdslib/LibRegistry.java
// public class LibRegistry {
//
// private static Map<UUID, String> NAME_REGISTRY = Maps.newHashMap();
// private static Map<String, UUID> UUID_REGISTRY = Maps.newHashMap();
// private static Map<String, ItemStack> SKULL_REGISTRY = Maps.newHashMap();
//
// public static Map<String, ItemStack> getSkullRegistry() {
// return SKULL_REGISTRY;
// }
//
// public static Map<UUID, String> getNameRegistry() {
// return NAME_REGISTRY;
// }
//
// public static Map<String, UUID> getUUIDRegistry() {
// return UUID_REGISTRY;
// }
//
// public static String getPlayerName(UUID uuid) {
// return NAME_REGISTRY.get(uuid);
// }
//
// public static boolean registerName(UUID uuid, String name) {
// boolean hasChanged = false;
// if (!NAME_REGISTRY.containsKey(uuid)) {
// NAME_REGISTRY.put(uuid, name);
// hasChanged = true;
// }
// if (!UUID_REGISTRY.containsKey(name)) {
// UUID_REGISTRY.put(name, uuid);
// }
// return hasChanged;
// }
//
// public static void registerUUID(String name, UUID uuid) {
// registerName(uuid, name);
// }
//
// public static void clearNameRegistry() {
// NAME_REGISTRY = new HashMap<UUID, String>();
// UUID_REGISTRY = new HashMap<String, UUID>();
// }
// }
//
// Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
// Path: src/main/java/p455w0rdslib/util/PlayerUtils.java
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import p455w0rdslib.LibRegistry;
import p455w0rdslib.P455w0rdsLib;
return false;
}
@SideOnly(Side.SERVER)
private static boolean isOPServer(EntityPlayer sender) {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) sender.getEntityWorld().getPlayerEntityByName(sender.getName());
if (player != null && player.getGameProfile() != null) {
UserListOpsEntry userentry = player.mcServer.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
return userentry != null && userentry.getPermissionLevel() >= 4;
}
}
return false;
}
public static List<UUID> getFullPlayerList() {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
List<UUID> uuidList = Lists.newArrayList();
if (server != null) {
PlayerProfileCache playerCache = server.getPlayerProfileCache();
String[] usernames = EasyMappings.getNames(server);
for (String username : usernames) {
uuidList.add(playerCache.getGameProfileForUsername(username).getId());
}
}
return uuidList;
}
public static ItemStack getPlayerSkull(String playerName) {
ItemStack head = null; | Map<String, ItemStack> skullCache = LibRegistry.getSkullRegistry(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/LibEntities.java | // Path: src/main/java/p455w0rdslib/entity/EntitySittableBlock.java
// public class EntitySittableBlock extends Entity {
//
// public int blockPosX;
// public int blockPosY;
// public int blockPosZ;
//
// public EntitySittableBlock(World world) {
// super(world);
// noClip = true;
// height = 0.01F;
// width = 0.01F;
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPosition(x + 0.5D, y + y0ffset, z + 0.5D);
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset, int rotation, double rotationOffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPostionConsideringRotation(x + 0.5D, y + y0ffset, z + 0.5D, rotation, rotationOffset);
// }
//
// public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
// switch (rotation) {
// case 2:
// z += rotationOffset;
// break;
// case 0:
// z -= rotationOffset;
// break;
// case 3:
// x -= rotationOffset;
// break;
// case 1:
// x += rotationOffset;
// break;
// }
// setPosition(x, y, z);
// }
//
// @Override
// public double getMountedYOffset() {
// return height * 0.0D;
// }
//
// @Override
// protected boolean shouldSetPosAfterLoading() {
// return false;
// }
//
// @Override
// public void onEntityUpdate() {
// if (!EasyMappings.world(this).isRemote) {
// if (!isBeingRidden() || EasyMappings.world(this).isAirBlock(new BlockPos(blockPosX, blockPosY, blockPosZ))) {
// setDead();
// EasyMappings.world(this).updateComparatorOutputLevel(getPosition(), EasyMappings.world(this).getBlockState(getPosition()).getBlock());
// }
// }
// }
//
// @Override
// protected void entityInit() {
// }
//
// @Override
// public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
// }
//
// @Override
// public void writeEntityToNBT(NBTTagCompound nbttagcompound) {
// }
//
// }
| import net.minecraftforge.fml.common.registry.EntityRegistry;
import p455w0rdslib.entity.EntitySittableBlock; | package p455w0rdslib;
/**
* @author p455w0rd
*
*/
public class LibEntities {
private static int entityId = 0;
private static int nextID() {
return entityId++;
}
public static void init() { | // Path: src/main/java/p455w0rdslib/entity/EntitySittableBlock.java
// public class EntitySittableBlock extends Entity {
//
// public int blockPosX;
// public int blockPosY;
// public int blockPosZ;
//
// public EntitySittableBlock(World world) {
// super(world);
// noClip = true;
// height = 0.01F;
// width = 0.01F;
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPosition(x + 0.5D, y + y0ffset, z + 0.5D);
// }
//
// public EntitySittableBlock(World world, double x, double y, double z, double y0ffset, int rotation, double rotationOffset) {
// this(world);
// blockPosX = (int) x;
// blockPosY = (int) y;
// blockPosZ = (int) z;
// setPostionConsideringRotation(x + 0.5D, y + y0ffset, z + 0.5D, rotation, rotationOffset);
// }
//
// public void setPostionConsideringRotation(double x, double y, double z, int rotation, double rotationOffset) {
// switch (rotation) {
// case 2:
// z += rotationOffset;
// break;
// case 0:
// z -= rotationOffset;
// break;
// case 3:
// x -= rotationOffset;
// break;
// case 1:
// x += rotationOffset;
// break;
// }
// setPosition(x, y, z);
// }
//
// @Override
// public double getMountedYOffset() {
// return height * 0.0D;
// }
//
// @Override
// protected boolean shouldSetPosAfterLoading() {
// return false;
// }
//
// @Override
// public void onEntityUpdate() {
// if (!EasyMappings.world(this).isRemote) {
// if (!isBeingRidden() || EasyMappings.world(this).isAirBlock(new BlockPos(blockPosX, blockPosY, blockPosZ))) {
// setDead();
// EasyMappings.world(this).updateComparatorOutputLevel(getPosition(), EasyMappings.world(this).getBlockState(getPosition()).getBlock());
// }
// }
// }
//
// @Override
// protected void entityInit() {
// }
//
// @Override
// public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
// }
//
// @Override
// public void writeEntityToNBT(NBTTagCompound nbttagcompound) {
// }
//
// }
// Path: src/main/java/p455w0rdslib/LibEntities.java
import net.minecraftforge.fml.common.registry.EntityRegistry;
import p455w0rdslib.entity.EntitySittableBlock;
package p455w0rdslib;
/**
* @author p455w0rd
*
*/
public class LibEntities {
private static int entityId = 0;
private static int nextID() {
return entityId++;
}
public static void init() { | EntityRegistry.registerModEntity(EntitySittableBlock.class, "ArmorStand", nextID(), P455w0rdsLib.INSTANCE, 80, 3, false); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/util/InventoryUtils.java | // Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
| import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import p455w0rdslib.P455w0rdsLib; | package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class InventoryUtils {
@SideOnly(Side.CLIENT)
public static ItemStack getArmorPiece(EntityEquipmentSlot slot) {
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { | // Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
// @Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
// public class P455w0rdsLib {
//
// @SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY)
// public static CommonProxy PROXY;
//
// @Instance(LibGlobals.MODID)
// public static P455w0rdsLib INSTANCE;
//
// @EventHandler
// public void preInit(FMLPreInitializationEvent e) {
// INSTANCE = this;
// PROXY.preInit(e);
// }
//
// @EventHandler
// public void init(FMLInitializationEvent e) {
// PROXY.init(e);
// }
//
// }
// Path: src/main/java/p455w0rdslib/util/InventoryUtils.java
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import p455w0rdslib.P455w0rdsLib;
package p455w0rdslib.util;
/**
* @author p455w0rd
*
*/
public class InventoryUtils {
@SideOnly(Side.CLIENT)
public static ItemStack getArmorPiece(EntityEquipmentSlot slot) {
if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { | EntityPlayer player = P455w0rdsLib.PROXY.getPlayer(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/P455w0rdsLib.java | // Path: src/main/java/p455w0rdslib/proxy/CommonProxy.java
// public class CommonProxy {
//
// public void preInit(FMLPreInitializationEvent e) {
// LibConfig.init();
// //ForgeChunkManager.setForcedChunkLoadingCallback(P455w0rdsLib.INSTANCE, Callback.getInstance());
// CapabilityChunkLoader.init();
// if (FMLCommonHandler.instance().getSide().isServer()) {
// ProcessHandler.init();
// }
// }
//
// public void init(FMLInitializationEvent e) {
// LibEntities.init();
// MinecraftForge.EVENT_BUS.register(new LibEvents());
// }
//
// public boolean isSMP() {
// return FMLCommonHandler.instance().getMinecraftServerInstance() != null && FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
// }
//
// public World getWorld() {
// return null;
// }
//
// public EntityPlayer getPlayer() {
// return null;
// }
//
// public EntityPlayer getPlayer(MessageContext context) {
// return null;
// }
//
// public boolean isClientSide() {
// return FMLCommonHandler.instance().getSide() == Side.CLIENT;
// }
//
// public Object getServer() {
// return FMLCommonHandler.instance().getMinecraftServerInstance();
// }
//
// }
| import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import p455w0rdslib.proxy.CommonProxy; | package p455w0rdslib;
/**
* @author p455w0rd
*
*/
@Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
public class P455w0rdsLib {
@SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY) | // Path: src/main/java/p455w0rdslib/proxy/CommonProxy.java
// public class CommonProxy {
//
// public void preInit(FMLPreInitializationEvent e) {
// LibConfig.init();
// //ForgeChunkManager.setForcedChunkLoadingCallback(P455w0rdsLib.INSTANCE, Callback.getInstance());
// CapabilityChunkLoader.init();
// if (FMLCommonHandler.instance().getSide().isServer()) {
// ProcessHandler.init();
// }
// }
//
// public void init(FMLInitializationEvent e) {
// LibEntities.init();
// MinecraftForge.EVENT_BUS.register(new LibEvents());
// }
//
// public boolean isSMP() {
// return FMLCommonHandler.instance().getMinecraftServerInstance() != null && FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
// }
//
// public World getWorld() {
// return null;
// }
//
// public EntityPlayer getPlayer() {
// return null;
// }
//
// public EntityPlayer getPlayer(MessageContext context) {
// return null;
// }
//
// public boolean isClientSide() {
// return FMLCommonHandler.instance().getSide() == Side.CLIENT;
// }
//
// public Object getServer() {
// return FMLCommonHandler.instance().getMinecraftServerInstance();
// }
//
// }
// Path: src/main/java/p455w0rdslib/P455w0rdsLib.java
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import p455w0rdslib.proxy.CommonProxy;
package p455w0rdslib;
/**
* @author p455w0rd
*
*/
@Mod(modid = LibGlobals.MODID, name = LibGlobals.NAME, version = LibGlobals.VERSION, dependencies = LibGlobals.DEPENDENCIES, acceptableRemoteVersions = "*", acceptedMinecraftVersions = "[1.9.4,1.10.2]")
public class P455w0rdsLib {
@SidedProxy(clientSide = LibGlobals.CLIENT_PROXY, serverSide = LibGlobals.SERVER_PROXY) | public static CommonProxy PROXY; |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/api/gui/IGuiElement.java | // Path: src/main/java/p455w0rdslib/client/gui/element/GuiPos.java
// public class GuiPos {
//
// int x, y;
//
// public GuiPos(int posX, int posY) {
// x = posX;
// y = posY;
// }
//
// public int getX() {
// return x;
// }
//
// public int getY() {
// return y;
// }
//
// }
| import java.util.List;
import p455w0rdslib.client.gui.element.GuiPos; | package p455w0rdslib.api.gui;
/**
* @author p455w0rd
*
*/
public interface IGuiElement {
int getX();
IGuiElement setX(int posX);
int getY();
IGuiElement setY(int posY);
int getWidth();
IGuiElement setWidth(int width);
int getHeight();
IGuiElement setHeight(int height);
IGuiElement setSize(int width, int height);
void drawBackground(int mouseX, int mouseY, float gameTicks);
void drawForeground(int mouseX, int mouseY);
boolean onClick(int mouseX, int mouseY);
boolean onRightClick(int mouseX, int mouseY);
boolean onMiddleClick(int mouseX, int mouseY);
boolean onMousePressed(int mouseX, int mouseY, int button);
void onMouseReleased(int mouseX, int mouseY, int button);
boolean onMouseWheel(int mouseX, int mouseY, int movement);
IModularGui getGui();
IGuiElement setGui(IModularGui guiIn);
boolean isVisible();
IGuiElement setVisible(boolean visibility);
boolean isEnabled();
IGuiElement setEnabled(boolean doEnable);
IGuiElement enable();
IGuiElement disable();
| // Path: src/main/java/p455w0rdslib/client/gui/element/GuiPos.java
// public class GuiPos {
//
// int x, y;
//
// public GuiPos(int posX, int posY) {
// x = posX;
// y = posY;
// }
//
// public int getX() {
// return x;
// }
//
// public int getY() {
// return y;
// }
//
// }
// Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
import java.util.List;
import p455w0rdslib.client.gui.element.GuiPos;
package p455w0rdslib.api.gui;
/**
* @author p455w0rd
*
*/
public interface IGuiElement {
int getX();
IGuiElement setX(int posX);
int getY();
IGuiElement setY(int posY);
int getWidth();
IGuiElement setWidth(int width);
int getHeight();
IGuiElement setHeight(int height);
IGuiElement setSize(int width, int height);
void drawBackground(int mouseX, int mouseY, float gameTicks);
void drawForeground(int mouseX, int mouseY);
boolean onClick(int mouseX, int mouseY);
boolean onRightClick(int mouseX, int mouseY);
boolean onMiddleClick(int mouseX, int mouseY);
boolean onMousePressed(int mouseX, int mouseY, int button);
void onMouseReleased(int mouseX, int mouseY, int button);
boolean onMouseWheel(int mouseX, int mouseY, int movement);
IModularGui getGui();
IGuiElement setGui(IModularGui guiIn);
boolean isVisible();
IGuiElement setVisible(boolean visibility);
boolean isEnabled();
IGuiElement setEnabled(boolean doEnable);
IGuiElement enable();
IGuiElement disable();
| GuiPos getPos(); |
p455w0rd/p455w0rds-Library | src/main/java/moze_intel/projecte/api/state/PEStateProps.java | // Path: src/main/java/moze_intel/projecte/api/state/enums/EnumFuelType.java
// public enum EnumFuelType implements IStringSerializable {
// ALCHEMICAL_COAL("alchemical_coal"), MOBIUS_FUEL("mobius_fuel"), AETERNALIS_FUEL("aeternalis_fuel");
//
// private final String name;
//
// EnumFuelType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/moze_intel/projecte/api/state/enums/EnumMatterType.java
// public enum EnumMatterType implements IStringSerializable {
// DARK_MATTER("dark_matter"), RED_MATTER("red_matter");
//
// private final String name;
//
// EnumMatterType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
| import moze_intel.projecte.api.state.enums.EnumFuelType;
import moze_intel.projecte.api.state.enums.EnumMatterType;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.util.EnumFacing; | package moze_intel.projecte.api.state;
public final class PEStateProps {
public static final IProperty<EnumFacing> FACING = BlockHorizontal.FACING; | // Path: src/main/java/moze_intel/projecte/api/state/enums/EnumFuelType.java
// public enum EnumFuelType implements IStringSerializable {
// ALCHEMICAL_COAL("alchemical_coal"), MOBIUS_FUEL("mobius_fuel"), AETERNALIS_FUEL("aeternalis_fuel");
//
// private final String name;
//
// EnumFuelType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/moze_intel/projecte/api/state/enums/EnumMatterType.java
// public enum EnumMatterType implements IStringSerializable {
// DARK_MATTER("dark_matter"), RED_MATTER("red_matter");
//
// private final String name;
//
// EnumMatterType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
// Path: src/main/java/moze_intel/projecte/api/state/PEStateProps.java
import moze_intel.projecte.api.state.enums.EnumFuelType;
import moze_intel.projecte.api.state.enums.EnumMatterType;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.util.EnumFacing;
package moze_intel.projecte.api.state;
public final class PEStateProps {
public static final IProperty<EnumFacing> FACING = BlockHorizontal.FACING; | public static final IProperty<EnumFuelType> FUEL_PROP = PropertyEnum.create("fueltype", EnumFuelType.class); |
p455w0rd/p455w0rds-Library | src/main/java/moze_intel/projecte/api/state/PEStateProps.java | // Path: src/main/java/moze_intel/projecte/api/state/enums/EnumFuelType.java
// public enum EnumFuelType implements IStringSerializable {
// ALCHEMICAL_COAL("alchemical_coal"), MOBIUS_FUEL("mobius_fuel"), AETERNALIS_FUEL("aeternalis_fuel");
//
// private final String name;
//
// EnumFuelType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/moze_intel/projecte/api/state/enums/EnumMatterType.java
// public enum EnumMatterType implements IStringSerializable {
// DARK_MATTER("dark_matter"), RED_MATTER("red_matter");
//
// private final String name;
//
// EnumMatterType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
| import moze_intel.projecte.api.state.enums.EnumFuelType;
import moze_intel.projecte.api.state.enums.EnumMatterType;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.util.EnumFacing; | package moze_intel.projecte.api.state;
public final class PEStateProps {
public static final IProperty<EnumFacing> FACING = BlockHorizontal.FACING;
public static final IProperty<EnumFuelType> FUEL_PROP = PropertyEnum.create("fueltype", EnumFuelType.class); | // Path: src/main/java/moze_intel/projecte/api/state/enums/EnumFuelType.java
// public enum EnumFuelType implements IStringSerializable {
// ALCHEMICAL_COAL("alchemical_coal"), MOBIUS_FUEL("mobius_fuel"), AETERNALIS_FUEL("aeternalis_fuel");
//
// private final String name;
//
// EnumFuelType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/moze_intel/projecte/api/state/enums/EnumMatterType.java
// public enum EnumMatterType implements IStringSerializable {
// DARK_MATTER("dark_matter"), RED_MATTER("red_matter");
//
// private final String name;
//
// EnumMatterType(String name) {
// this.name = name;
// }
//
// @Nonnull
// @Override
// public String getName() {
// return name;
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
// Path: src/main/java/moze_intel/projecte/api/state/PEStateProps.java
import moze_intel.projecte.api.state.enums.EnumFuelType;
import moze_intel.projecte.api.state.enums.EnumMatterType;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.util.EnumFacing;
package moze_intel.projecte.api.state;
public final class PEStateProps {
public static final IProperty<EnumFacing> FACING = BlockHorizontal.FACING;
public static final IProperty<EnumFuelType> FUEL_PROP = PropertyEnum.create("fueltype", EnumFuelType.class); | public static final IProperty<EnumMatterType> TIER_PROP = PropertyEnum.create("tier", EnumMatterType.class); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/proxy/ClientProxy.java | // Path: src/main/java/p455w0rdslib/handlers/ProcessHandlerClient.java
// public class ProcessHandlerClient {
//
// private static List<IProcess> processes = new ArrayList<IProcess>();
// private static List<IProcess> newProcesses = new ArrayList<IProcess>();
//
// public static void init() {
// MinecraftForge.EVENT_BUS.register(new ProcessHandlerClient());
// }
//
// @SubscribeEvent
// public void onClientTick(TickEvent.ClientTickEvent event) {
// if (event.phase == TickEvent.Phase.START) {
//
// Iterator<IProcess> i = processes.iterator();
// List<IProcess> toBeRemoved = Lists.newArrayList();
//
// while (i.hasNext()) {
// IProcess process = i.next();
// if (process.isDead()) {
// toBeRemoved.add(process);
// }
// else {
// process.updateProcess();
// }
// }
//
// if (!toBeRemoved.isEmpty()) {
// for (IProcess p : toBeRemoved) {
// if (processes.contains(p)) {
// processes.remove(p);
// }
// }
// }
//
// if (!newProcesses.isEmpty()) {
// processes.addAll(newProcesses);
// newProcesses.clear();
// }
// }
// }
//
// @SubscribeEvent
// public void onWorldClose(WorldEvent.Unload event) {
// processes.clear();
// newProcesses.clear();
// }
//
// public static void addProcess(IProcess process) {
// newProcesses.add(process);
// }
//
// }
| import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import p455w0rdslib.handlers.ProcessHandlerClient; | /*
* This file is part of p455w0rd's Library.
* Copyright (c) 2016, p455w0rd (aka TheRealp455w0rd), All rights reserved
* unless
* otherwise stated.
*
* p455w0rd's Library is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* p455w0rd's Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT License for more details.
*
* You should have received a copy of the MIT License
* along with p455w0rd's Library. If not, see
* <https://opensource.org/licenses/MIT>.
*/
package p455w0rdslib.proxy;
/**
* @author p455w0rd
*
*/
public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e); | // Path: src/main/java/p455w0rdslib/handlers/ProcessHandlerClient.java
// public class ProcessHandlerClient {
//
// private static List<IProcess> processes = new ArrayList<IProcess>();
// private static List<IProcess> newProcesses = new ArrayList<IProcess>();
//
// public static void init() {
// MinecraftForge.EVENT_BUS.register(new ProcessHandlerClient());
// }
//
// @SubscribeEvent
// public void onClientTick(TickEvent.ClientTickEvent event) {
// if (event.phase == TickEvent.Phase.START) {
//
// Iterator<IProcess> i = processes.iterator();
// List<IProcess> toBeRemoved = Lists.newArrayList();
//
// while (i.hasNext()) {
// IProcess process = i.next();
// if (process.isDead()) {
// toBeRemoved.add(process);
// }
// else {
// process.updateProcess();
// }
// }
//
// if (!toBeRemoved.isEmpty()) {
// for (IProcess p : toBeRemoved) {
// if (processes.contains(p)) {
// processes.remove(p);
// }
// }
// }
//
// if (!newProcesses.isEmpty()) {
// processes.addAll(newProcesses);
// newProcesses.clear();
// }
// }
// }
//
// @SubscribeEvent
// public void onWorldClose(WorldEvent.Unload event) {
// processes.clear();
// newProcesses.clear();
// }
//
// public static void addProcess(IProcess process) {
// newProcesses.add(process);
// }
//
// }
// Path: src/main/java/p455w0rdslib/proxy/ClientProxy.java
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import p455w0rdslib.handlers.ProcessHandlerClient;
/*
* This file is part of p455w0rd's Library.
* Copyright (c) 2016, p455w0rd (aka TheRealp455w0rd), All rights reserved
* unless
* otherwise stated.
*
* p455w0rd's Library is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* p455w0rd's Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT License for more details.
*
* You should have received a copy of the MIT License
* along with p455w0rd's Library. If not, see
* <https://opensource.org/licenses/MIT>.
*/
package p455w0rdslib.proxy;
/**
* @author p455w0rd
*
*/
public class ClientProxy extends CommonProxy {
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e); | ProcessHandlerClient.init(); |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/client/gui/element/GuiScrollbar.java | // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IGuiScrollbar.java
// public interface IGuiScrollbar extends IGuiElement {
//
// void doDrag(int x, int y);
//
// int getSliderXPos();
//
// int getSliderYPos();
//
// IGuiElement getParentElement();
//
// IGuiScrollbar setParentElement(IGuiElement element);
//
// int getScrollPos();
//
// IGuiScrollbar setScrollPos(int pos);
//
// void onStopDragging();
//
// int getMinPos();
//
// IGuiScrollbar setMinPos(int pos);
//
// int getMaxPos();
//
// IGuiScrollbar setMaxPos(int pos);
//
// IGuiScrollbar setBounds(int min, int max);
//
// int getSliderWidth();
//
// IGuiScrollbar setSliderWidth(int width);
//
// int getSliderHeight();
//
// IGuiScrollbar setSliderHeight(int height);
//
// int getBorderColor();
//
// IGuiScrollbar setBorderColor(int color);
//
// int getFaceColor();
//
// IGuiScrollbar setFaceColor(int color);
//
// IGuiScrollbar setColors(int border, int face);
//
// boolean isDragging();
//
// void setDragging(boolean isDragging);
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
| import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IGuiScrollbar;
import p455w0rdslib.api.gui.IModularGui; | package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public abstract class GuiScrollbar extends GuiElement implements IGuiScrollbar {
protected int scrollPos, minPos, maxPos, sliderWidth, sliderHeight, borderColor = 0xFF000000,
faceColor = 0xFF333333;
protected boolean dragging; | // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IGuiScrollbar.java
// public interface IGuiScrollbar extends IGuiElement {
//
// void doDrag(int x, int y);
//
// int getSliderXPos();
//
// int getSliderYPos();
//
// IGuiElement getParentElement();
//
// IGuiScrollbar setParentElement(IGuiElement element);
//
// int getScrollPos();
//
// IGuiScrollbar setScrollPos(int pos);
//
// void onStopDragging();
//
// int getMinPos();
//
// IGuiScrollbar setMinPos(int pos);
//
// int getMaxPos();
//
// IGuiScrollbar setMaxPos(int pos);
//
// IGuiScrollbar setBounds(int min, int max);
//
// int getSliderWidth();
//
// IGuiScrollbar setSliderWidth(int width);
//
// int getSliderHeight();
//
// IGuiScrollbar setSliderHeight(int height);
//
// int getBorderColor();
//
// IGuiScrollbar setBorderColor(int color);
//
// int getFaceColor();
//
// IGuiScrollbar setFaceColor(int color);
//
// IGuiScrollbar setColors(int border, int face);
//
// boolean isDragging();
//
// void setDragging(boolean isDragging);
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
// Path: src/main/java/p455w0rdslib/client/gui/element/GuiScrollbar.java
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IGuiScrollbar;
import p455w0rdslib.api.gui.IModularGui;
package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public abstract class GuiScrollbar extends GuiElement implements IGuiScrollbar {
protected int scrollPos, minPos, maxPos, sliderWidth, sliderHeight, borderColor = 0xFF000000,
faceColor = 0xFF333333;
protected boolean dragging; | IGuiElement parentElement; |
p455w0rd/p455w0rds-Library | src/main/java/p455w0rdslib/client/gui/element/GuiScrollbar.java | // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IGuiScrollbar.java
// public interface IGuiScrollbar extends IGuiElement {
//
// void doDrag(int x, int y);
//
// int getSliderXPos();
//
// int getSliderYPos();
//
// IGuiElement getParentElement();
//
// IGuiScrollbar setParentElement(IGuiElement element);
//
// int getScrollPos();
//
// IGuiScrollbar setScrollPos(int pos);
//
// void onStopDragging();
//
// int getMinPos();
//
// IGuiScrollbar setMinPos(int pos);
//
// int getMaxPos();
//
// IGuiScrollbar setMaxPos(int pos);
//
// IGuiScrollbar setBounds(int min, int max);
//
// int getSliderWidth();
//
// IGuiScrollbar setSliderWidth(int width);
//
// int getSliderHeight();
//
// IGuiScrollbar setSliderHeight(int height);
//
// int getBorderColor();
//
// IGuiScrollbar setBorderColor(int color);
//
// int getFaceColor();
//
// IGuiScrollbar setFaceColor(int color);
//
// IGuiScrollbar setColors(int border, int face);
//
// boolean isDragging();
//
// void setDragging(boolean isDragging);
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
| import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IGuiScrollbar;
import p455w0rdslib.api.gui.IModularGui; | package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public abstract class GuiScrollbar extends GuiElement implements IGuiScrollbar {
protected int scrollPos, minPos, maxPos, sliderWidth, sliderHeight, borderColor = 0xFF000000,
faceColor = 0xFF333333;
protected boolean dragging;
IGuiElement parentElement;
| // Path: src/main/java/p455w0rdslib/api/gui/IGuiElement.java
// public interface IGuiElement {
//
// int getX();
//
// IGuiElement setX(int posX);
//
// int getY();
//
// IGuiElement setY(int posY);
//
// int getWidth();
//
// IGuiElement setWidth(int width);
//
// int getHeight();
//
// IGuiElement setHeight(int height);
//
// IGuiElement setSize(int width, int height);
//
// void drawBackground(int mouseX, int mouseY, float gameTicks);
//
// void drawForeground(int mouseX, int mouseY);
//
// boolean onClick(int mouseX, int mouseY);
//
// boolean onRightClick(int mouseX, int mouseY);
//
// boolean onMiddleClick(int mouseX, int mouseY);
//
// boolean onMousePressed(int mouseX, int mouseY, int button);
//
// void onMouseReleased(int mouseX, int mouseY, int button);
//
// boolean onMouseWheel(int mouseX, int mouseY, int movement);
//
// IModularGui getGui();
//
// IGuiElement setGui(IModularGui guiIn);
//
// boolean isVisible();
//
// IGuiElement setVisible(boolean visibility);
//
// boolean isEnabled();
//
// IGuiElement setEnabled(boolean doEnable);
//
// IGuiElement enable();
//
// IGuiElement disable();
//
// GuiPos getPos();
//
// IGuiElement setPos(int xPos, int yPos);
//
// void update(int mouseX, int mouseY);
//
// boolean isMouseOver(int mouseX, int mouseY);
//
// List<String> getTooltip();
//
// IGuiElement setTooltip(List<String> tooltipLines);
//
// boolean hasTooltip();
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IGuiScrollbar.java
// public interface IGuiScrollbar extends IGuiElement {
//
// void doDrag(int x, int y);
//
// int getSliderXPos();
//
// int getSliderYPos();
//
// IGuiElement getParentElement();
//
// IGuiScrollbar setParentElement(IGuiElement element);
//
// int getScrollPos();
//
// IGuiScrollbar setScrollPos(int pos);
//
// void onStopDragging();
//
// int getMinPos();
//
// IGuiScrollbar setMinPos(int pos);
//
// int getMaxPos();
//
// IGuiScrollbar setMaxPos(int pos);
//
// IGuiScrollbar setBounds(int min, int max);
//
// int getSliderWidth();
//
// IGuiScrollbar setSliderWidth(int width);
//
// int getSliderHeight();
//
// IGuiScrollbar setSliderHeight(int height);
//
// int getBorderColor();
//
// IGuiScrollbar setBorderColor(int color);
//
// int getFaceColor();
//
// IGuiScrollbar setFaceColor(int color);
//
// IGuiScrollbar setColors(int border, int face);
//
// boolean isDragging();
//
// void setDragging(boolean isDragging);
//
// }
//
// Path: src/main/java/p455w0rdslib/api/gui/IModularGui.java
// public interface IModularGui {
//
// IModularGui addElement(IGuiElement element);
//
// boolean isMouseOverElement(IGuiElement element, int mouseX, int mouseY);
//
// void drawElements(float partialTick, int mouseX, int mouseY, boolean foreground);
//
// List<IGuiElement> getElements();
//
// void updateElements(int mouseX, int mouseY);
//
// String getTitle();
//
// IModularGui setTitle(String titleText);
//
// IModularGui setTitleScale(float scale);
//
// IModularGui setTitleOffsetX(int offset);
//
// IModularGui setTitleOffsetY(int offset);
//
// IModularGui setTitlePos(int x, int y);
//
// int getTitleColor();
//
// IModularGui setTitleColor(int color);
//
// ResourceLocation getBackgroundTexture();
//
// IModularGui setBackgroundTexture(ResourceLocation location);
//
// boolean isMouseOver(int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY);
//
// int getX();
//
// int getY();
//
// int getWidth();
//
// IModularGui setWidth(int w);
//
// int getHeight();
//
// IModularGui setHeight(int h);
//
// IModularGui setSize(int w, int h);
//
// IModularGui setTooltipColor(int color, boolean top);
//
// int[] getTooltipColors();
//
// boolean onMouseWheel(int mouseX, int mouseY, int wheelMovement);
//
// }
// Path: src/main/java/p455w0rdslib/client/gui/element/GuiScrollbar.java
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import p455w0rdslib.api.gui.IGuiElement;
import p455w0rdslib.api.gui.IGuiScrollbar;
import p455w0rdslib.api.gui.IModularGui;
package p455w0rdslib.client.gui.element;
/**
* @author p455w0rd
*
*/
public abstract class GuiScrollbar extends GuiElement implements IGuiScrollbar {
protected int scrollPos, minPos, maxPos, sliderWidth, sliderHeight, borderColor = 0xFF000000,
faceColor = 0xFF333333;
protected boolean dragging;
IGuiElement parentElement;
| public GuiScrollbar(IModularGui gui, GuiPos posIn, int width, int height, int max) { |
leonarduk/unison | src/test/java/uk/co/sleonard/unison/utils/TreeNodeTest.java | // Path: src/main/java/uk/co/sleonard/unison/utils/TreeNode.java
// public class TreeNode extends DefaultMutableTreeNode {
//
// /** The Constant serialVersionUID. */
// private static final long serialVersionUID = -8471464838090837440L;
//
// /** The node name. */
// private String nodeName;
//
// /**
// * Instantiates a new tree node.
// *
// * @param childObject
// * the child object
// * @param name
// * the name
// */
// public TreeNode(final Object childObject, final String name) {
// super(childObject);
// this.nodeName = name;
// }
//
// /**
// * Sets the name.
// *
// * @param name
// * the new name
// */
// public void setName(final String name) {
// this.nodeName = name;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see javax.swing.tree.DefaultMutableTreeNode#toString()
// */
// @Override
// public String toString() {
// return this.nodeName;
// }
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import uk.co.sleonard.unison.utils.TreeNode; | package uk.co.sleonard.unison.utils;
/**
* The Class TreeNodeTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.3.0
*
*/
public class TreeNodeTest {
/**
* Test Constructor and toString
*/
@Test
public void testTreeNode() {
String expected = "mytreenode"; | // Path: src/main/java/uk/co/sleonard/unison/utils/TreeNode.java
// public class TreeNode extends DefaultMutableTreeNode {
//
// /** The Constant serialVersionUID. */
// private static final long serialVersionUID = -8471464838090837440L;
//
// /** The node name. */
// private String nodeName;
//
// /**
// * Instantiates a new tree node.
// *
// * @param childObject
// * the child object
// * @param name
// * the name
// */
// public TreeNode(final Object childObject, final String name) {
// super(childObject);
// this.nodeName = name;
// }
//
// /**
// * Sets the name.
// *
// * @param name
// * the new name
// */
// public void setName(final String name) {
// this.nodeName = name;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see javax.swing.tree.DefaultMutableTreeNode#toString()
// */
// @Override
// public String toString() {
// return this.nodeName;
// }
// }
// Path: src/test/java/uk/co/sleonard/unison/utils/TreeNodeTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import uk.co.sleonard.unison.utils.TreeNode;
package uk.co.sleonard.unison.utils;
/**
* The Class TreeNodeTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.3.0
*
*/
public class TreeNodeTest {
/**
* Test Constructor and toString
*/
@Test
public void testTreeNode() {
String expected = "mytreenode"; | TreeNode actual = new TreeNode(new Object(), "mytreenode"); |
leonarduk/unison | src/test/java/uk/co/sleonard/unison/datahandling/DAO/NewsGroupTest.java | // Path: src/test/java/org/apache/commons/net/nntp/NewsgroupInfoFactory.java
// public class NewsgroupInfoFactory {
//
// /**
// * Newsgroup info.
// *
// * @param count
// * the count
// * @param first
// * the first
// * @param last
// * the last
// * @param newsgroup
// * the newsgroup
// * @return the newsgroup info
// */
// public static NewsgroupInfo newsgroupInfo(final long count, final long first, final long last,
// final String newsgroup) {
// return NewsgroupInfoFactory.newsgroupInfo(count, first, last, newsgroup, 0);
// }
//
// /**
// * Newsgroup info.
// *
// * @param count
// * the count
// * @param first
// * the first
// * @param last
// * the last
// * @param newsgroup
// * the newsgroup
// * @param permission
// * the permission
// * @return the newsgroup info
// */
// public static NewsgroupInfo newsgroupInfo(final long count, final long first, final long last,
// final String newsgroup, final int permission) {
// final NewsgroupInfo newsgroupInfo = new NewsgroupInfo();
// newsgroupInfo._setArticleCount(count);
// newsgroupInfo._setFirstArticle(first);
// newsgroupInfo._setLastArticle(last);
// newsgroupInfo._setNewsgroup(newsgroup);
// newsgroupInfo._setPostingPermission(permission);
// return newsgroupInfo;
// }
// }
| import java.util.HashSet;
import java.util.Set;
import org.apache.commons.net.nntp.NewsgroupInfo;
import org.apache.commons.net.nntp.NewsgroupInfoFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; | /**
* NewsGroupTest
*
* @author ${author}
* @since 17-Jun-2016
*/
package uk.co.sleonard.unison.datahandling.DAO;
/**
* The Class MessageTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.2.0
*
*/
public class NewsGroupTest {
/** The expected article count. */
private static final int expectedArticleCount = 10;
/** The expected first article. */
private static final int expectedFirstMessage = 2;
/** The expected last article. */
private static final int expectedLastMessage = 79;
/** The expected posting perm. */
private static final int expectedPostingPerm = 1;
/** The nntp ng. */
private NewsGroup nntpNG;
/**
* Create a mock of NewsgroupInfo.
*
* @return Mock object of NewsgroupInfo
*/
private NewsgroupInfo generateNewsgroupInfoMock() { | // Path: src/test/java/org/apache/commons/net/nntp/NewsgroupInfoFactory.java
// public class NewsgroupInfoFactory {
//
// /**
// * Newsgroup info.
// *
// * @param count
// * the count
// * @param first
// * the first
// * @param last
// * the last
// * @param newsgroup
// * the newsgroup
// * @return the newsgroup info
// */
// public static NewsgroupInfo newsgroupInfo(final long count, final long first, final long last,
// final String newsgroup) {
// return NewsgroupInfoFactory.newsgroupInfo(count, first, last, newsgroup, 0);
// }
//
// /**
// * Newsgroup info.
// *
// * @param count
// * the count
// * @param first
// * the first
// * @param last
// * the last
// * @param newsgroup
// * the newsgroup
// * @param permission
// * the permission
// * @return the newsgroup info
// */
// public static NewsgroupInfo newsgroupInfo(final long count, final long first, final long last,
// final String newsgroup, final int permission) {
// final NewsgroupInfo newsgroupInfo = new NewsgroupInfo();
// newsgroupInfo._setArticleCount(count);
// newsgroupInfo._setFirstArticle(first);
// newsgroupInfo._setLastArticle(last);
// newsgroupInfo._setNewsgroup(newsgroup);
// newsgroupInfo._setPostingPermission(permission);
// return newsgroupInfo;
// }
// }
// Path: src/test/java/uk/co/sleonard/unison/datahandling/DAO/NewsGroupTest.java
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.net.nntp.NewsgroupInfo;
import org.apache.commons.net.nntp.NewsgroupInfoFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* NewsGroupTest
*
* @author ${author}
* @since 17-Jun-2016
*/
package uk.co.sleonard.unison.datahandling.DAO;
/**
* The Class MessageTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.2.0
*
*/
public class NewsGroupTest {
/** The expected article count. */
private static final int expectedArticleCount = 10;
/** The expected first article. */
private static final int expectedFirstMessage = 2;
/** The expected last article. */
private static final int expectedLastMessage = 79;
/** The expected posting perm. */
private static final int expectedPostingPerm = 1;
/** The nntp ng. */
private NewsGroup nntpNG;
/**
* Create a mock of NewsgroupInfo.
*
* @return Mock object of NewsgroupInfo
*/
private NewsgroupInfo generateNewsgroupInfoMock() { | return NewsgroupInfoFactory.newsgroupInfo(NewsGroupTest.expectedArticleCount, |
leonarduk/unison | src/test/java/uk/co/sleonard/unison/datahandling/DAO/ResultRowTest.java | // Path: src/main/java/uk/co/sleonard/unison/datahandling/DAO/ResultRow.java
// public class ResultRow implements Comparable<ResultRow> {
//
// /** The key. */
// private final Object key;
//
// /** The type. */
// private final Class<?> type;
//
// /** The count. */
// private final int count;
//
// /**
// * Instantiates a new result row.
// *
// * @param key
// * the key
// * @param count
// * the count
// * @param type
// * the type
// */
// public ResultRow(final Object key, final int count, final Class<?> type) {
// this.key = key;
// this.type = type;
// this.count = count;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Comparable#compareTo(java.lang.Object)
// */
// @Override
// public int compareTo(final ResultRow that) {
// // reverse order to get top ones first
// return -(this.count - that.count);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#equals(java.lang.Object)
// */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (this.getClass() != obj.getClass()) {
// return false;
// }
// final ResultRow other = (ResultRow) obj;
// if (this.count != other.count) {
// return false;
// }
// if (this.key == null) {
// if (other.key != null) {
// return false;
// }
// }
// else if (!this.key.equals(other.key)) {
// return false;
// }
// return true;
// }
//
// /**
// * Gets the count.
// *
// * @return the count
// */
// public int getCount() {
// return this.count;
// }
//
// /**
// * Gets the key.
// *
// * @return the key
// */
// public Object getKey() {
// return this.key;
// }
//
// /**
// * Gets the type.
// *
// * @return the type
// */
// public Class<?> getType() {
// return this.type;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#hashCode()
// */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = (prime * result) + this.count;
// result = (prime * result) + (this.key == null ? 0 : this.key.hashCode());
// return result;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return this.getCount() + " " + this.getKey();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import uk.co.sleonard.unison.datahandling.DAO.ResultRow; | package uk.co.sleonard.unison.datahandling.DAO;
/**
* The Class ResultRowTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.2.0
*
*/
public class ResultRowTest {
/**
* Test toString.
*/
@Test
public void testToString() {
Object obj = new Object(); | // Path: src/main/java/uk/co/sleonard/unison/datahandling/DAO/ResultRow.java
// public class ResultRow implements Comparable<ResultRow> {
//
// /** The key. */
// private final Object key;
//
// /** The type. */
// private final Class<?> type;
//
// /** The count. */
// private final int count;
//
// /**
// * Instantiates a new result row.
// *
// * @param key
// * the key
// * @param count
// * the count
// * @param type
// * the type
// */
// public ResultRow(final Object key, final int count, final Class<?> type) {
// this.key = key;
// this.type = type;
// this.count = count;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Comparable#compareTo(java.lang.Object)
// */
// @Override
// public int compareTo(final ResultRow that) {
// // reverse order to get top ones first
// return -(this.count - that.count);
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#equals(java.lang.Object)
// */
// @Override
// public boolean equals(final Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (this.getClass() != obj.getClass()) {
// return false;
// }
// final ResultRow other = (ResultRow) obj;
// if (this.count != other.count) {
// return false;
// }
// if (this.key == null) {
// if (other.key != null) {
// return false;
// }
// }
// else if (!this.key.equals(other.key)) {
// return false;
// }
// return true;
// }
//
// /**
// * Gets the count.
// *
// * @return the count
// */
// public int getCount() {
// return this.count;
// }
//
// /**
// * Gets the key.
// *
// * @return the key
// */
// public Object getKey() {
// return this.key;
// }
//
// /**
// * Gets the type.
// *
// * @return the type
// */
// public Class<?> getType() {
// return this.type;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#hashCode()
// */
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = (prime * result) + this.count;
// result = (prime * result) + (this.key == null ? 0 : this.key.hashCode());
// return result;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return this.getCount() + " " + this.getKey();
// }
//
// }
// Path: src/test/java/uk/co/sleonard/unison/datahandling/DAO/ResultRowTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import uk.co.sleonard.unison.datahandling.DAO.ResultRow;
package uk.co.sleonard.unison.datahandling.DAO;
/**
* The Class ResultRowTest.
*
* @author Elton <elton_12_nunes@hotmail.com>
* @since v1.2.0
*
*/
public class ResultRowTest {
/**
* Test toString.
*/
@Test
public void testToString() {
Object obj = new Object(); | ResultRow actual = new ResultRow(obj, 3, null); |
leonarduk/unison | src/main/java/uk/co/sleonard/unison/utils/Downloader.java | // Path: src/main/java/uk/co/sleonard/unison/UNISoNLogger.java
// public interface UNISoNLogger {
//
// /**
// * Alert.
// *
// * @param message
// * the message
// */
// public void alert(String message);
//
// /**
// * Log.
// *
// * @param message
// * the message
// */
// public void log(String message);
// }
//
// Path: src/main/java/uk/co/sleonard/unison/datahandling/DAO/DownloadRequest.java
// public enum DownloadMode {
//
// /** The basic. */
// BASIC,
// /** The headers. */
// HEADERS,
// /** The all. */
// ALL
// }
| import uk.co.sleonard.unison.UNISoNException;
import uk.co.sleonard.unison.UNISoNLogger;
import uk.co.sleonard.unison.datahandling.DAO.DownloadRequest.DownloadMode; | /**
* Downloader
*
* @author ${author}
* @since 16-Jun-2016
*/
package uk.co.sleonard.unison.utils;
public interface Downloader {
public void addDownloadRequest(final String usenetID, final DownloadMode mode, | // Path: src/main/java/uk/co/sleonard/unison/UNISoNLogger.java
// public interface UNISoNLogger {
//
// /**
// * Alert.
// *
// * @param message
// * the message
// */
// public void alert(String message);
//
// /**
// * Log.
// *
// * @param message
// * the message
// */
// public void log(String message);
// }
//
// Path: src/main/java/uk/co/sleonard/unison/datahandling/DAO/DownloadRequest.java
// public enum DownloadMode {
//
// /** The basic. */
// BASIC,
// /** The headers. */
// HEADERS,
// /** The all. */
// ALL
// }
// Path: src/main/java/uk/co/sleonard/unison/utils/Downloader.java
import uk.co.sleonard.unison.UNISoNException;
import uk.co.sleonard.unison.UNISoNLogger;
import uk.co.sleonard.unison.datahandling.DAO.DownloadRequest.DownloadMode;
/**
* Downloader
*
* @author ${author}
* @since 16-Jun-2016
*/
package uk.co.sleonard.unison.utils;
public interface Downloader {
public void addDownloadRequest(final String usenetID, final DownloadMode mode, | final UNISoNLogger log1) throws UNISoNException; |
vbauer/jconditions | src/test/java/com/github/vbauer/jconditions/annotation/RuleAnnotationsTest.java | // Path: src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java
// public class ConditionRule implements MethodRule {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public Statement apply(
// final Statement base, final FrameworkMethod method, final Object target
// ) {
// final ConditionChecker<?> checker =
// ConditionCheckerEngine.detectFailedChecker(target, method);
//
// if (checker != null) {
// return new IgnoreStatement(checker);
// }
// return base;
// }
//
// }
| import com.github.vbauer.jconditions.core.junit.ConditionRule;
import org.junit.Rule; | package com.github.vbauer.jconditions.annotation;
/**
* @author Vladislav Bauer
*/
public class RuleAnnotationsTest extends AbstractAnnotationsTest {
@Rule | // Path: src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java
// public class ConditionRule implements MethodRule {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public Statement apply(
// final Statement base, final FrameworkMethod method, final Object target
// ) {
// final ConditionChecker<?> checker =
// ConditionCheckerEngine.detectFailedChecker(target, method);
//
// if (checker != null) {
// return new IgnoreStatement(checker);
// }
// return base;
// }
//
// }
// Path: src/test/java/com/github/vbauer/jconditions/annotation/RuleAnnotationsTest.java
import com.github.vbauer.jconditions.core.junit.ConditionRule;
import org.junit.Rule;
package com.github.vbauer.jconditions.annotation;
/**
* @author Vladislav Bauer
*/
public class RuleAnnotationsTest extends AbstractAnnotationsTest {
@Rule | public final ConditionRule rule = new ConditionRule(); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/AppIsInstalledChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.AppIsInstalled;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class AppIsInstalledChecker implements ConditionChecker<AppIsInstalled> {
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/AppIsInstalledChecker.java
import com.github.vbauer.jconditions.annotation.AppIsInstalled;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class AppIsInstalledChecker implements ConditionChecker<AppIsInstalled> {
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<AppIsInstalled> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/AppIsInstalledChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.AppIsInstalled;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class AppIsInstalledChecker implements ConditionChecker<AppIsInstalled> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<AppIsInstalled> context) {
final AppIsInstalled annotation = context.getAnnotation();
final String[] applications = annotation.value();
return appsInstalled(applications);
}
private boolean appsInstalled(final String... applications) {
for (final String application : applications) { | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/AppIsInstalledChecker.java
import com.github.vbauer.jconditions.annotation.AppIsInstalled;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class AppIsInstalledChecker implements ConditionChecker<AppIsInstalled> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<AppIsInstalled> context) {
final AppIsInstalled annotation = context.getAnnotation();
final String[] applications = annotation.value();
return appsInstalled(applications);
}
private boolean appsInstalled(final String... applications) {
for (final String application : applications) { | final String app = PropUtils.injectProperties(application); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java
import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
final SocketIsOpened annotation = context.getAnnotation(); | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java
import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
final SocketIsOpened annotation = context.getAnnotation(); | final String host = PropUtils.injectProperties(annotation.host()); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
final SocketIsOpened annotation = context.getAnnotation();
final String host = PropUtils.injectProperties(annotation.host());
final int port = annotation.port();
final int timeout = annotation.timeout();
return isSocketOpened(host, port, timeout);
}
private boolean isSocketOpened(final String host, final int port, final int timeout) throws Exception {
Socket socket = null;
try {
socket = new Socket();
socket.bind(null);
socket.connect(new InetSocketAddress(host, port), timeout);
return true;
} finally { | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/InOutUtils.java
// public final class InOutUtils {
//
// private static final int BUFFER_SIZE = 1024;
// private static final int EOF = -1;
//
//
// private InOutUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean closeQuietly(final Closeable closeable) {
// try {
// closeable.close();
// return true;
// } catch (final Exception ex) {
// return false;
// }
// }
//
// public static void copy(final InputStream input, final OutputStream output) throws IOException {
// final byte[] bytes = new byte[BUFFER_SIZE];
// int read;
//
// while ((read = input.read(bytes)) != EOF) {
// output.write(bytes, 0, read);
// }
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/SocketIsOpenedChecker.java
import com.github.vbauer.jconditions.annotation.SocketIsOpened;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.InOutUtils;
import com.github.vbauer.jconditions.util.PropUtils;
import java.net.InetSocketAddress;
import java.net.Socket;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class SocketIsOpenedChecker implements ConditionChecker<SocketIsOpened> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<SocketIsOpened> context) throws Exception {
final SocketIsOpened annotation = context.getAnnotation();
final String host = PropUtils.injectProperties(annotation.host());
final int port = annotation.port();
final int timeout = annotation.timeout();
return isSocketOpened(host, port, timeout);
}
private boolean isSocketOpened(final String host, final int port, final int timeout) throws Exception {
Socket socket = null;
try {
socket = new Socket();
socket.bind(null);
socket.connect(new InetSocketAddress(host, port), timeout);
return true;
} finally { | InOutUtils.closeQuietly(socket); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/annotation/IgnoreIf.java | // Path: src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java
// public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean isSatisfied(final CheckerContext<IgnoreIf> context) {
// final IgnoreIf annotation = context.getAnnotation();
//
// @SuppressWarnings("rawtypes")
// final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//
// //noinspection unchecked
// return !ConditionCheckerExecutor.isSatisfied(context, checkerClasses);
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
| import com.github.vbauer.jconditions.checker.IgnoreIfChecker;
import com.github.vbauer.jconditions.core.Condition;
import com.github.vbauer.jconditions.core.ConditionChecker;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; | package com.github.vbauer.jconditions.annotation;
/**
* Allows to skip some test method using specific {@link ConditionChecker} class.
* It will skip test, if checker return true and execute method otherwise.
* "ConditionChecker" could be separate class, or nested static class, or even inner class.
* It also works fine with private classes.
*
* @author Vladislav Bauer
*/
@Documented
@Condition(IgnoreIfChecker.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD})
public @interface IgnoreIf {
/**
* Condition checkers that should be checked.
*
* @return condition checkers
*/
@SuppressWarnings("rawtypes") | // Path: src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java
// public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean isSatisfied(final CheckerContext<IgnoreIf> context) {
// final IgnoreIf annotation = context.getAnnotation();
//
// @SuppressWarnings("rawtypes")
// final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//
// //noinspection unchecked
// return !ConditionCheckerExecutor.isSatisfied(context, checkerClasses);
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/annotation/IgnoreIf.java
import com.github.vbauer.jconditions.checker.IgnoreIfChecker;
import com.github.vbauer.jconditions.core.Condition;
import com.github.vbauer.jconditions.core.ConditionChecker;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
package com.github.vbauer.jconditions.annotation;
/**
* Allows to skip some test method using specific {@link ConditionChecker} class.
* It will skip test, if checker return true and execute method otherwise.
* "ConditionChecker" could be separate class, or nested static class, or even inner class.
* It also works fine with private classes.
*
* @author Vladislav Bauer
*/
@Documented
@Condition(IgnoreIfChecker.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD})
public @interface IgnoreIf {
/**
* Condition checkers that should be checked.
*
* @return condition checkers
*/
@SuppressWarnings("rawtypes") | Class<? extends ConditionChecker>[] value(); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java
import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<UrlIsReachable> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<UrlIsReachable> context) {
final UrlIsReachable annotation = context.getAnnotation();
final String[] urlAddresses = annotation.value();
final int timeout = annotation.timeout();
return isReachable(urlAddresses, timeout);
}
private boolean isReachable(final String[] urlAddresses, final int timeout) {
for (final String urlAddress : urlAddresses) { | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java
import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<UrlIsReachable> context) {
final UrlIsReachable annotation = context.getAnnotation();
final String[] urlAddresses = annotation.value();
final int timeout = annotation.timeout();
return isReachable(urlAddresses, timeout);
}
private boolean isReachable(final String[] urlAddresses, final int timeout) {
for (final String urlAddress : urlAddresses) { | final String url = PropUtils.injectProperties(urlAddress); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<UrlIsReachable> context) {
final UrlIsReachable annotation = context.getAnnotation();
final String[] urlAddresses = annotation.value();
final int timeout = annotation.timeout();
return isReachable(urlAddresses, timeout);
}
private boolean isReachable(final String[] urlAddresses, final int timeout) {
for (final String urlAddress : urlAddresses) {
final String url = PropUtils.injectProperties(urlAddress);
if (!isReachable(url, timeout)) {
return false;
}
}
return urlAddresses.length > 0;
}
private boolean isReachable(final String url, final int timeout) {
try { | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/NetUtils.java
// public final class NetUtils {
//
// private static final String HTTP_PREFIX = "http://";
//
//
// private NetUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String fixScheme(final String address) {
// if (address != null) {
// final URI uri = URI.create(address);
// final String scheme = uri.getScheme();
//
// if (scheme == null) {
// return HTTP_PREFIX + address;
// }
// }
// return address;
// }
//
// public static File copyURLContentToFile(final URLConnection connection, final String target) throws Exception {
// InputStream input = null;
// OutputStream output = null;
//
// try {
// final File file = new File(target);
// output = new FileOutputStream(file);
// input = connection.getInputStream();
// InOutUtils.copy(input, output);
// return file;
// } finally {
// InOutUtils.closeQuietly(input);
// InOutUtils.closeQuietly(output);
// }
// }
//
// public static URLConnection connectURL(final String uri, final int timeout) throws IOException {
// final URL url = new URL(uri);
// final URLConnection connection = url.openConnection();
// connection.setConnectTimeout(timeout);
// connection.connect();
// return connection;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/UrlIsReachableChecker.java
import com.github.vbauer.jconditions.annotation.UrlIsReachable;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.NetUtils;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class UrlIsReachableChecker implements ConditionChecker<UrlIsReachable> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<UrlIsReachable> context) {
final UrlIsReachable annotation = context.getAnnotation();
final String[] urlAddresses = annotation.value();
final int timeout = annotation.timeout();
return isReachable(urlAddresses, timeout);
}
private boolean isReachable(final String[] urlAddresses, final int timeout) {
for (final String urlAddress : urlAddresses) {
final String url = PropUtils.injectProperties(urlAddress);
if (!isReachable(url, timeout)) {
return false;
}
}
return urlAddresses.length > 0;
}
private boolean isReachable(final String url, final int timeout) {
try { | return NetUtils.connectURL(url, timeout) != null; |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
| import com.github.vbauer.jconditions.annotation.IgnoreIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java
import com.github.vbauer.jconditions.annotation.IgnoreIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<IgnoreIf> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
| import com.github.vbauer.jconditions.annotation.IgnoreIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<IgnoreIf> context) {
final IgnoreIf annotation = context.getAnnotation();
@SuppressWarnings("rawtypes")
final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//noinspection unchecked | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/IgnoreIfChecker.java
import com.github.vbauer.jconditions.annotation.IgnoreIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IgnoreIfChecker implements ConditionChecker<IgnoreIf> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<IgnoreIf> context) {
final IgnoreIf annotation = context.getAnnotation();
@SuppressWarnings("rawtypes")
final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//noinspection unchecked | return !ConditionCheckerExecutor.isSatisfied(context, checkerClasses); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/annotation/RunIf.java | // Path: src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java
// public class RunIfChecker implements ConditionChecker<RunIf> {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean isSatisfied(final CheckerContext<RunIf> context) {
// final RunIf annotation = context.getAnnotation();
//
// @SuppressWarnings("rawtypes")
// final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//
// //noinspection unchecked
// return ConditionCheckerExecutor.isSatisfied(context, checkerClasses);
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
| import com.github.vbauer.jconditions.checker.RunIfChecker;
import com.github.vbauer.jconditions.core.Condition;
import com.github.vbauer.jconditions.core.ConditionChecker;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; | package com.github.vbauer.jconditions.annotation;
/**
* It is an opposite annotation to {@link IgnoreIf}.
* It will run test method if {@link ConditionChecker} returns `true`.
*
* @author Vladislav Bauer
*/
@Documented
@Condition(RunIfChecker.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD})
public @interface RunIf {
/**
* Condition checkers that should be checked.
*
* @return condition checkers
*/
@SuppressWarnings("rawtypes") | // Path: src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java
// public class RunIfChecker implements ConditionChecker<RunIf> {
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean isSatisfied(final CheckerContext<RunIf> context) {
// final RunIf annotation = context.getAnnotation();
//
// @SuppressWarnings("rawtypes")
// final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//
// //noinspection unchecked
// return ConditionCheckerExecutor.isSatisfied(context, checkerClasses);
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/annotation/RunIf.java
import com.github.vbauer.jconditions.checker.RunIfChecker;
import com.github.vbauer.jconditions.core.Condition;
import com.github.vbauer.jconditions.core.ConditionChecker;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
package com.github.vbauer.jconditions.annotation;
/**
* It is an opposite annotation to {@link IgnoreIf}.
* It will run test method if {@link ConditionChecker} returns `true`.
*
* @author Vladislav Bauer
*/
@Documented
@Condition(RunIfChecker.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD})
public @interface RunIf {
/**
* Condition checkers that should be checked.
*
* @return condition checkers
*/
@SuppressWarnings("rawtypes") | Class<? extends ConditionChecker>[] value(); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/IfJavaVersionChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.IfJavaVersion;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IfJavaVersionChecker implements ConditionChecker<IfJavaVersion> {
private static final String PROPERTY_JAVA_VERSION = "java.version";
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/IfJavaVersionChecker.java
import com.github.vbauer.jconditions.annotation.IfJavaVersion;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IfJavaVersionChecker implements ConditionChecker<IfJavaVersion> {
private static final String PROPERTY_JAVA_VERSION = "java.version";
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<IfJavaVersion> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/IfJavaVersionChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.github.vbauer.jconditions.annotation.IfJavaVersion;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IfJavaVersionChecker implements ConditionChecker<IfJavaVersion> {
private static final String PROPERTY_JAVA_VERSION = "java.version";
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<IfJavaVersion> context) {
final IfJavaVersion annotation = context.getAnnotation();
final String[] versions = annotation.value(); | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/util/PropUtils.java
// public final class PropUtils {
//
// private static final String VAR_PREFIX = "${";
// private static final String VAR_POSTFIX = "}";
//
//
// private PropUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static String getSystemProperty(final String key) {
// final Map<String, String> properties = getSystemProperties();
// return properties.get(key);
// }
//
// public static Map<String, String> getSystemProperties() {
// final Map<String, String> result = new HashMap<>();
// result.putAll(System.getenv());
// result.putAll(convertPropertiesToMap(System.getProperties()));
// return result;
// }
//
// public static Map<String, String> convertPropertiesToMap(final Properties properties) {
// final Map<String, String> result = new HashMap<>();
// for (final String name : properties.stringPropertyNames()) {
// result.put(name, properties.getProperty(name));
// }
// return result;
// }
//
// public static String injectProperties(final String text) {
// if (text != null && text.contains(VAR_PREFIX)) {
// String result = text;
// final Map<String, String> systemProperties = getSystemProperties();
// for (final Map.Entry<String, String> entry : systemProperties.entrySet()) {
// final String key = entry.getKey();
// final String value = entry.getValue();
// result = result.replace(VAR_PREFIX + key + VAR_POSTFIX, value);
// }
// return result;
// }
// return text;
// }
//
// public static boolean hasAnyWithProperties(final String value, final String... variants) {
// for (final String operationSystem : variants) {
// final String injected = injectProperties(operationSystem);
// if (TextUtils.containsIgnoreCase(value, injected)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/IfJavaVersionChecker.java
import com.github.vbauer.jconditions.annotation.IfJavaVersion;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.util.PropUtils;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class IfJavaVersionChecker implements ConditionChecker<IfJavaVersion> {
private static final String PROPERTY_JAVA_VERSION = "java.version";
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<IfJavaVersion> context) {
final IfJavaVersion annotation = context.getAnnotation();
final String[] versions = annotation.value(); | return PropUtils.hasAnyWithProperties(javaVersion(), versions); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java | // Path: src/main/java/com/github/vbauer/jconditions/util/ReflexUtils.java
// public final class ReflexUtils {
//
// private static final String PACKAGE_JAVA_LANG_ANNOTATION = "java.lang.annotation";
//
//
// private ReflexUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean isInJavaLangAnnotationPackage(final Annotation annotation) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
// final String annotationTypeName = annotationType.getName();
// return annotationTypeName.startsWith(PACKAGE_JAVA_LANG_ANNOTATION);
// }
//
// @SuppressWarnings("unchecked")
// public static <T> T getFieldValue(final Object object, final String fieldName) {
// try {
// final Class<?> objectClass = object.getClass();
// final Field field = objectClass.getDeclaredField(fieldName);
// field.setAccessible(true);
// return (T) field.get(object);
// } catch (final Exception ex) {
// return null;
// }
// }
//
// public static <T extends AccessibleObject> T makeAccessible(final T object) {
// if (!object.isAccessible()) {
// object.setAccessible(true);
// }
// return object;
// }
//
// public static Collection<Annotation> findAllAnnotations(final Class<?> clazz) {
// final List<Annotation> result = new ArrayList<>();
// Class<?> current = clazz;
//
// while (current != Object.class && current != null) {
// final Class<?>[] interfaces = current.getInterfaces();
// for (final Class<?> i : interfaces) {
// result.addAll(findAllAnnotations(i));
// }
//
// result.addAll(Arrays.asList(current.getAnnotations()));
// current = current.getSuperclass();
// }
// return result;
// }
//
// public static <T> T instantiate(final Object instance, final Class<T> checkerClass) {
// try {
// return instantiateImpl(instance, checkerClass);
// } catch (final RuntimeException ex) {
// throw ex;
// } catch (final Exception ex) {
// throw new RuntimeException(ex);
// }
// }
//
//
// private static <T> T instantiateImpl(final Object instance, final Class<T> clazz) throws Exception {
// if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
// return instantiateInnerClass(instance, clazz);
// }
// return instantiateClass(clazz);
// }
//
// private static <T> T instantiateClass(final Class<T> clazz) throws Exception {
// final Constructor<T> constructor = clazz.getDeclaredConstructor();
// return ReflexUtils.makeAccessible(constructor).newInstance();
// }
//
// private static <T> T instantiateInnerClass(
// final Object instance, final Class<T> clazz
// ) throws Exception {
// final Class<?> outerClass = clazz.getDeclaringClass();
// final Constructor<T> constructor = clazz.getDeclaredConstructor(outerClass);
// return ReflexUtils.makeAccessible(constructor).newInstance(instance);
// }
//
// }
| import com.github.vbauer.jconditions.util.ReflexUtils; | package com.github.vbauer.jconditions.core;
/**
* @author Vladislav Bauer
*/
public final class ConditionCheckerExecutor {
private ConditionCheckerExecutor() {
throw new UnsupportedOperationException();
}
@SafeVarargs
@SuppressWarnings("rawtypes")
public static boolean isSatisfied(
final CheckerContext<?> context,
final Class<? extends ConditionChecker>... checkerClasses
) {
for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
if (!isSatisfied(context, checkerClass)) {
return false;
}
}
return true;
}
@SuppressWarnings("rawtypes")
public static boolean isSatisfied(
final CheckerContext context,
final Class<? extends ConditionChecker> checkerClass
) {
final Object instance = context.getInstance(); | // Path: src/main/java/com/github/vbauer/jconditions/util/ReflexUtils.java
// public final class ReflexUtils {
//
// private static final String PACKAGE_JAVA_LANG_ANNOTATION = "java.lang.annotation";
//
//
// private ReflexUtils() {
// throw new UnsupportedOperationException();
// }
//
//
// public static boolean isInJavaLangAnnotationPackage(final Annotation annotation) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
// final String annotationTypeName = annotationType.getName();
// return annotationTypeName.startsWith(PACKAGE_JAVA_LANG_ANNOTATION);
// }
//
// @SuppressWarnings("unchecked")
// public static <T> T getFieldValue(final Object object, final String fieldName) {
// try {
// final Class<?> objectClass = object.getClass();
// final Field field = objectClass.getDeclaredField(fieldName);
// field.setAccessible(true);
// return (T) field.get(object);
// } catch (final Exception ex) {
// return null;
// }
// }
//
// public static <T extends AccessibleObject> T makeAccessible(final T object) {
// if (!object.isAccessible()) {
// object.setAccessible(true);
// }
// return object;
// }
//
// public static Collection<Annotation> findAllAnnotations(final Class<?> clazz) {
// final List<Annotation> result = new ArrayList<>();
// Class<?> current = clazz;
//
// while (current != Object.class && current != null) {
// final Class<?>[] interfaces = current.getInterfaces();
// for (final Class<?> i : interfaces) {
// result.addAll(findAllAnnotations(i));
// }
//
// result.addAll(Arrays.asList(current.getAnnotations()));
// current = current.getSuperclass();
// }
// return result;
// }
//
// public static <T> T instantiate(final Object instance, final Class<T> checkerClass) {
// try {
// return instantiateImpl(instance, checkerClass);
// } catch (final RuntimeException ex) {
// throw ex;
// } catch (final Exception ex) {
// throw new RuntimeException(ex);
// }
// }
//
//
// private static <T> T instantiateImpl(final Object instance, final Class<T> clazz) throws Exception {
// if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
// return instantiateInnerClass(instance, clazz);
// }
// return instantiateClass(clazz);
// }
//
// private static <T> T instantiateClass(final Class<T> clazz) throws Exception {
// final Constructor<T> constructor = clazz.getDeclaredConstructor();
// return ReflexUtils.makeAccessible(constructor).newInstance();
// }
//
// private static <T> T instantiateInnerClass(
// final Object instance, final Class<T> clazz
// ) throws Exception {
// final Class<?> outerClass = clazz.getDeclaringClass();
// final Constructor<T> constructor = clazz.getDeclaredConstructor(outerClass);
// return ReflexUtils.makeAccessible(constructor).newInstance(instance);
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
import com.github.vbauer.jconditions.util.ReflexUtils;
package com.github.vbauer.jconditions.core;
/**
* @author Vladislav Bauer
*/
public final class ConditionCheckerExecutor {
private ConditionCheckerExecutor() {
throw new UnsupportedOperationException();
}
@SafeVarargs
@SuppressWarnings("rawtypes")
public static boolean isSatisfied(
final CheckerContext<?> context,
final Class<? extends ConditionChecker>... checkerClasses
) {
for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
if (!isSatisfied(context, checkerClass)) {
return false;
}
}
return true;
}
@SuppressWarnings("rawtypes")
public static boolean isSatisfied(
final CheckerContext context,
final Class<? extends ConditionChecker> checkerClass
) {
final Object instance = context.getInstance(); | final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass); |
vbauer/jconditions | src/test/java/com/github/vbauer/jconditions/misc/Never.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
| import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker; | package com.github.vbauer.jconditions.misc;
/**
* @author Vladislav Bauer
*/
public class Never<T> implements ConditionChecker<T> {
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
// Path: src/test/java/com/github/vbauer/jconditions/misc/Never.java
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
package com.github.vbauer.jconditions.misc;
/**
* @author Vladislav Bauer
*/
public class Never<T> implements ConditionChecker<T> {
@Override | public boolean isSatisfied(final CheckerContext<T> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
| import com.github.vbauer.jconditions.annotation.RunIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class RunIfChecker implements ConditionChecker<RunIf> {
/**
* {@inheritDoc}
*/
@Override | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java
import com.github.vbauer.jconditions.annotation.RunIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class RunIfChecker implements ConditionChecker<RunIf> {
/**
* {@inheritDoc}
*/
@Override | public boolean isSatisfied(final CheckerContext<RunIf> context) { |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
| import com.github.vbauer.jconditions.annotation.RunIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor; | package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class RunIfChecker implements ConditionChecker<RunIf> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<RunIf> context) {
final RunIf annotation = context.getAnnotation();
@SuppressWarnings("rawtypes")
final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//noinspection unchecked | // Path: src/main/java/com/github/vbauer/jconditions/core/CheckerContext.java
// public class CheckerContext<T> {
//
// private final Object instance;
// private final T annotation;
//
//
// public CheckerContext(final Object instance, final T annotation) {
// this.instance = instance;
// this.annotation = annotation;
// }
//
//
// public Object getInstance() {
// return instance;
// }
//
// public T getAnnotation() {
// return annotation;
// }
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerExecutor.java
// public final class ConditionCheckerExecutor {
//
// private ConditionCheckerExecutor() {
// throw new UnsupportedOperationException();
// }
//
//
// @SafeVarargs
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext<?> context,
// final Class<? extends ConditionChecker>... checkerClasses
// ) {
// for (final Class<? extends ConditionChecker> checkerClass : checkerClasses) {
// if (!isSatisfied(context, checkerClass)) {
// return false;
// }
// }
// return true;
// }
//
// @SuppressWarnings("rawtypes")
// public static boolean isSatisfied(
// final CheckerContext context,
// final Class<? extends ConditionChecker> checkerClass
// ) {
// final Object instance = context.getInstance();
// final ConditionChecker checker = ReflexUtils.instantiate(instance, checkerClass);
// return isSatisfied(context, checker);
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// public static boolean isSatisfied(
// final CheckerContext context, final ConditionChecker checker
// ) {
// try {
// return checker.isSatisfied(context);
// } catch (final Throwable ex) {
// return false;
// }
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/checker/RunIfChecker.java
import com.github.vbauer.jconditions.annotation.RunIf;
import com.github.vbauer.jconditions.core.CheckerContext;
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerExecutor;
package com.github.vbauer.jconditions.checker;
/**
* @author Vladislav Bauer
*/
public class RunIfChecker implements ConditionChecker<RunIf> {
/**
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(final CheckerContext<RunIf> context) {
final RunIf annotation = context.getAnnotation();
@SuppressWarnings("rawtypes")
final Class<? extends ConditionChecker>[] checkerClasses = annotation.value();
//noinspection unchecked | return ConditionCheckerExecutor.isSatisfied(context, checkerClasses); |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java | // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java
// public final class ConditionCheckerEngine {
//
// private ConditionCheckerEngine() {
// throw new UnsupportedOperationException();
// }
//
//
// public static ConditionChecker<?> detectFailedChecker(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> annotations = findAllAnnotations(instance, method);
// return findCheckerByAnnotations(instance, null, annotations);
// }
//
//
// private static ConditionChecker<?> findCheckerByAnnotations(
// final Object instance, final Annotation parent, final Collection<Annotation> annotations
// ) {
// for (final Annotation annotation : annotations) {
// final ConditionChecker<?> checker =
// getConditionChecker(instance, parent, annotation);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// private static ConditionChecker<?> getConditionChecker(
// final Object instance, final Annotation parent, final Annotation annotation
// ) {
// if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
//
// if (annotationType == Condition.class) {
// final Condition condition = (Condition) annotation;
// final ConditionChecker<?> checker =
// findCheckerByCondition(instance, parent, condition);
//
// if (checker != null) {
// return checker;
// }
// }
//
// final Collection<Annotation> extra =
// Arrays.asList(annotationType.getAnnotations());
//
// final ConditionChecker<?> checker =
// findCheckerByAnnotations(instance, annotation, extra);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// private static <T> ConditionChecker<T> findCheckerByCondition(
// final T instance, final Annotation parent, final Condition condition
// ) {
// final Class<? extends ConditionChecker> checkerClass = condition.value();
// final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass);
// final CheckerContext<T> context = new CheckerContext(instance, parent);
//
// if (!ConditionCheckerExecutor.isSatisfied(context, checker)) {
// return checker;
// }
// return null;
// }
//
// private static Collection<Annotation> findAllAnnotations(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass());
// result.addAll(Arrays.asList(method.getAnnotations()));
// return result;
// }
//
// }
| import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerEngine;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement; | package com.github.vbauer.jconditions.core.junit;
/**
* @see MethodRule
* @author Vladislav Bauer
*/
public class ConditionRule implements MethodRule {
/**
* {@inheritDoc}
*/
@Override
public Statement apply(
final Statement base, final FrameworkMethod method, final Object target
) { | // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java
// public final class ConditionCheckerEngine {
//
// private ConditionCheckerEngine() {
// throw new UnsupportedOperationException();
// }
//
//
// public static ConditionChecker<?> detectFailedChecker(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> annotations = findAllAnnotations(instance, method);
// return findCheckerByAnnotations(instance, null, annotations);
// }
//
//
// private static ConditionChecker<?> findCheckerByAnnotations(
// final Object instance, final Annotation parent, final Collection<Annotation> annotations
// ) {
// for (final Annotation annotation : annotations) {
// final ConditionChecker<?> checker =
// getConditionChecker(instance, parent, annotation);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// private static ConditionChecker<?> getConditionChecker(
// final Object instance, final Annotation parent, final Annotation annotation
// ) {
// if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
//
// if (annotationType == Condition.class) {
// final Condition condition = (Condition) annotation;
// final ConditionChecker<?> checker =
// findCheckerByCondition(instance, parent, condition);
//
// if (checker != null) {
// return checker;
// }
// }
//
// final Collection<Annotation> extra =
// Arrays.asList(annotationType.getAnnotations());
//
// final ConditionChecker<?> checker =
// findCheckerByAnnotations(instance, annotation, extra);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// private static <T> ConditionChecker<T> findCheckerByCondition(
// final T instance, final Annotation parent, final Condition condition
// ) {
// final Class<? extends ConditionChecker> checkerClass = condition.value();
// final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass);
// final CheckerContext<T> context = new CheckerContext(instance, parent);
//
// if (!ConditionCheckerExecutor.isSatisfied(context, checker)) {
// return checker;
// }
// return null;
// }
//
// private static Collection<Annotation> findAllAnnotations(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass());
// result.addAll(Arrays.asList(method.getAnnotations()));
// return result;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerEngine;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
package com.github.vbauer.jconditions.core.junit;
/**
* @see MethodRule
* @author Vladislav Bauer
*/
public class ConditionRule implements MethodRule {
/**
* {@inheritDoc}
*/
@Override
public Statement apply(
final Statement base, final FrameworkMethod method, final Object target
) { | final ConditionChecker<?> checker = |
vbauer/jconditions | src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java | // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java
// public final class ConditionCheckerEngine {
//
// private ConditionCheckerEngine() {
// throw new UnsupportedOperationException();
// }
//
//
// public static ConditionChecker<?> detectFailedChecker(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> annotations = findAllAnnotations(instance, method);
// return findCheckerByAnnotations(instance, null, annotations);
// }
//
//
// private static ConditionChecker<?> findCheckerByAnnotations(
// final Object instance, final Annotation parent, final Collection<Annotation> annotations
// ) {
// for (final Annotation annotation : annotations) {
// final ConditionChecker<?> checker =
// getConditionChecker(instance, parent, annotation);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// private static ConditionChecker<?> getConditionChecker(
// final Object instance, final Annotation parent, final Annotation annotation
// ) {
// if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
//
// if (annotationType == Condition.class) {
// final Condition condition = (Condition) annotation;
// final ConditionChecker<?> checker =
// findCheckerByCondition(instance, parent, condition);
//
// if (checker != null) {
// return checker;
// }
// }
//
// final Collection<Annotation> extra =
// Arrays.asList(annotationType.getAnnotations());
//
// final ConditionChecker<?> checker =
// findCheckerByAnnotations(instance, annotation, extra);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// private static <T> ConditionChecker<T> findCheckerByCondition(
// final T instance, final Annotation parent, final Condition condition
// ) {
// final Class<? extends ConditionChecker> checkerClass = condition.value();
// final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass);
// final CheckerContext<T> context = new CheckerContext(instance, parent);
//
// if (!ConditionCheckerExecutor.isSatisfied(context, checker)) {
// return checker;
// }
// return null;
// }
//
// private static Collection<Annotation> findAllAnnotations(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass());
// result.addAll(Arrays.asList(method.getAnnotations()));
// return result;
// }
//
// }
| import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerEngine;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement; | package com.github.vbauer.jconditions.core.junit;
/**
* @see MethodRule
* @author Vladislav Bauer
*/
public class ConditionRule implements MethodRule {
/**
* {@inheritDoc}
*/
@Override
public Statement apply(
final Statement base, final FrameworkMethod method, final Object target
) {
final ConditionChecker<?> checker = | // Path: src/main/java/com/github/vbauer/jconditions/core/ConditionChecker.java
// public interface ConditionChecker<T> {
//
// /**
// * Checks if execution of test method should be continued or not.
// *
// * @param context input data for checker
// * @return true if execution should be continued and false - otherwise
// * @throws Exception on any error (it is the same as false in return value)
// */
// boolean isSatisfied(CheckerContext<T> context) throws Exception;
//
// }
//
// Path: src/main/java/com/github/vbauer/jconditions/core/ConditionCheckerEngine.java
// public final class ConditionCheckerEngine {
//
// private ConditionCheckerEngine() {
// throw new UnsupportedOperationException();
// }
//
//
// public static ConditionChecker<?> detectFailedChecker(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> annotations = findAllAnnotations(instance, method);
// return findCheckerByAnnotations(instance, null, annotations);
// }
//
//
// private static ConditionChecker<?> findCheckerByAnnotations(
// final Object instance, final Annotation parent, final Collection<Annotation> annotations
// ) {
// for (final Annotation annotation : annotations) {
// final ConditionChecker<?> checker =
// getConditionChecker(instance, parent, annotation);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// private static ConditionChecker<?> getConditionChecker(
// final Object instance, final Annotation parent, final Annotation annotation
// ) {
// if (!ReflexUtils.isInJavaLangAnnotationPackage(annotation)) {
// final Class<? extends Annotation> annotationType = annotation.annotationType();
//
// if (annotationType == Condition.class) {
// final Condition condition = (Condition) annotation;
// final ConditionChecker<?> checker =
// findCheckerByCondition(instance, parent, condition);
//
// if (checker != null) {
// return checker;
// }
// }
//
// final Collection<Annotation> extra =
// Arrays.asList(annotationType.getAnnotations());
//
// final ConditionChecker<?> checker =
// findCheckerByAnnotations(instance, annotation, extra);
//
// if (checker != null) {
// return checker;
// }
// }
// return null;
// }
//
// @SuppressWarnings({"unchecked", "rawtypes"})
// private static <T> ConditionChecker<T> findCheckerByCondition(
// final T instance, final Annotation parent, final Condition condition
// ) {
// final Class<? extends ConditionChecker> checkerClass = condition.value();
// final ConditionChecker<T> checker = ReflexUtils.instantiate(instance, checkerClass);
// final CheckerContext<T> context = new CheckerContext(instance, parent);
//
// if (!ConditionCheckerExecutor.isSatisfied(context, checker)) {
// return checker;
// }
// return null;
// }
//
// private static Collection<Annotation> findAllAnnotations(
// final Object instance, final FrameworkMethod method
// ) {
// final Collection<Annotation> result = ReflexUtils.findAllAnnotations(instance.getClass());
// result.addAll(Arrays.asList(method.getAnnotations()));
// return result;
// }
//
// }
// Path: src/main/java/com/github/vbauer/jconditions/core/junit/ConditionRule.java
import com.github.vbauer.jconditions.core.ConditionChecker;
import com.github.vbauer.jconditions.core.ConditionCheckerEngine;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
package com.github.vbauer.jconditions.core.junit;
/**
* @see MethodRule
* @author Vladislav Bauer
*/
public class ConditionRule implements MethodRule {
/**
* {@inheritDoc}
*/
@Override
public Statement apply(
final Statement base, final FrameworkMethod method, final Object target
) {
final ConditionChecker<?> checker = | ConditionCheckerEngine.detectFailedChecker(target, method); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.