Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Snippet] Functional operators for Filter & Functional classes (negate, chain, and, or, ...)

Featured Replies

Chain, negate, combine, ...

 

Filter Example:

	public static void main(String[] args) {
		Filter<String> IS_EMPTY =  s -> s.isEmpty();
		Filter<String> CONTAINS_O = s -> s.contains("o");
		
		String a = "";
		String b = "osbot";
		
		// Check if empty
		System.out.println(IS_EMPTY.match(a)); //true
		System.out.println(IS_EMPTY.match(b)); //false
		
		//Check if NOT empty
		System.out.println(FilterOperation.negate(IS_EMPTY).match(a)); //false
		System.out.println(FilterOperation.negate(IS_EMPTY).match(b)); //true
		
		// Check if empty OR contains o
		System.out.println(FilterOperation.or(IS_EMPTY, CONTAINS_O).match(a)); //true
		System.out.println(FilterOperation.or(IS_EMPTY, CONTAINS_O).match(b)); //true
		
		// Check if empty AND contains o
		System.out.println(FilterOperation.and(IS_EMPTY, CONTAINS_O).match(a)); //false
		System.out.println(FilterOperation.and(IS_EMPTY, CONTAINS_O).match(b)); //false
	}

Filter Operations:

package org.botre.functional;

import org.osbot.rs07.api.filter.Filter;

public final class FilterOperation {
	
	private FilterOperation() {
		
	}
	
	/**
	 * Returns a filter that represents the logical negation of the supplied filter.
	 * 
	 * @return a filter that represents the logical negation of the supplied filter
	 */
	public static final <T> Filter<T> negate(Filter<? super T> filter) {
		return e -> !filter.match(e);
	}
	
	/**
	 * Returns a filter that represents a short-circuiting logical AND of the supplied filters.
	 * 
	 * @return a filter that represents a short-circuiting logical AND of the supplied filters
	 */
	@SafeVarargs
	public static final <T> Filter<T> and(Filter<? super T>... filters) {
		if(filters.length < 1) throw new IllegalArgumentException();
		return new Filter<T>() {
			@Override
			public boolean match(T e) {
				for (Filter<? super T> filter : filters) if(!filter.match(e)) return false;
				return true;
			}
		};
	}
	
	/**
	 * Returns a composed filter that represents a short-circuiting logical OR of the supplied filters.
	 * 
	 * @return a composed filter that represents a short-circuiting logical OR of the supplied filters
	 */
	@SafeVarargs
	public static final <T> Filter<T> or(Filter<? super T>... filters) {
		if(filters.length < 1) throw new IllegalArgumentException();
		return new Filter<T>() {
			@Override
			public boolean match(T e) {
				for (Filter<? super T> filter : filters) if(filter.match(e)) return true;
				return false;
			}
		};
	}
	
}

Functional Operations:

package org.botre.functional;

import java.util.function.BooleanSupplier;
import java.util.function.Predicate;

public final class FunctionalOperation {

	private FunctionalOperation() {
		
	}
	
	/**
	 * Returns a composed boolean supplier that represents a short-circuiting logical AND of the supplied boolean suppliers.
	 * 
	 * @return a composed boolean supplier that represents a short-circuiting logical AND of the supplied boolean suppliers
	 */
	public static final BooleanSupplier and(BooleanSupplier... suppliers) {
		if(suppliers.length < 1) throw new IllegalArgumentException();
		return () -> {
			for (BooleanSupplier s : suppliers) if(!s.getAsBoolean()) return false;
			return true;
		};
	}
	
	/**
	 * Returns a composed boolean supplier that represents a short-circuiting logical OR of the supplied boolean suppliers.
	 * 
	 * @return a composed boolean supplier that represents a short-circuiting logical OR of the supplied boolean suppliers
	 */
	public static final BooleanSupplier or(BooleanSupplier... suppliers) {
		if(suppliers.length < 1) throw new IllegalArgumentException();
		return () -> {
			for (BooleanSupplier s : suppliers) if(s.getAsBoolean()) return true;
			return false;
		};
	}
	
	/**
	 * Returns a composed predicate that represents a short-circuiting logical AND of the supplied predicates.
	 * 
	 * @return a composed predicate that represents a short-circuiting logical AND of the supplied predicates
	 */
	@SafeVarargs
	public static final <T> Predicate<T> and(Predicate<T>... predicates) {
		if(predicates.length < 1) throw new IllegalArgumentException();
		Predicate<T> result = predicates[0];
		for (int i = 1; i < predicates.length; i++) {
			result  = result.and(predicates[i]);
		}
		return result;
	}
	
	/**
	 * Returns a composed predicate that represents a short-circuiting logical OR of the supplied predicates.
	 * 
	 * @return a composed predicate that represents a short-circuiting logical OR of the supplied predicates
	 */
	@SafeVarargs
	public static final <T> Predicate<T> or(Predicate<T>... predicates) {
		if(predicates.length < 1) throw new IllegalArgumentException();
		Predicate<T> result = predicates[0];
		for (int i = 1; i < predicates.length; i++) {
			result  = result.or(predicates[i]);
		}
		return result;
	}
	
}

nice snippet!

 

edit: i had a question but i answered it myself

 

ps: i think the devs like it

5251ac2df2394e36012afde8aa276b0f.png

Edited by Shiny

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.