All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.owasp.fileio.codecs.Trie Maven / Gradle / Ivy

Go to download

The OWASP Java File I/O Security Project provides an easy to use library for validating and sanitizing filenames, directory paths, and uploaded files.

The newest version!
/**
 * This file is part of the Open Web Application Security Project (OWASP) Java File IO Security project. For details, please see
 * https://www.owasp.org/index.php/OWASP_Java_File_I_O_Security_Project.
 *
 * Copyright (c) 2014 - The OWASP Foundation
 *
 * This API is published by OWASP under the Apache 2.0 license. You should read and accept the LICENSE before you use, modify, and/or redistribute this software.
 *
 * @author August Detlefsen CodeMagi - Java File IO Security Project lead
 * @created 2014
 */
package org.owasp.fileio.codecs;

import java.io.IOException;
import java.io.PushbackReader;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

public interface Trie extends Map {

    public Map.Entry getLongestMatch(CharSequence key);

    public Map.Entry getLongestMatch(PushbackReader keyIn) throws IOException;

    public int getMaxKeyLength();

    static class TrieProxy implements Trie {

	private Trie wrapped;

	TrieProxy(Trie toWrap) {
	    wrapped = toWrap;
	}

	protected Trie getWrapped() {
	    return wrapped;
	}

	public Map.Entry getLongestMatch(CharSequence key) {
	    return wrapped.getLongestMatch(key);
	}

	public Map.Entry getLongestMatch(PushbackReader keyIn) throws IOException {
	    return wrapped.getLongestMatch(keyIn);
	}

	public int getMaxKeyLength() {
	    return wrapped.getMaxKeyLength();
	}

	/* java.util.Map: */
	public int size() {
	    return wrapped.size();
	}

	public boolean isEmpty() {
	    return wrapped.isEmpty();
	}

	public boolean containsKey(Object key) {
	    return wrapped.containsKey(key);
	}

	public boolean containsValue(Object val) {
	    return wrapped.containsValue(val);
	}

	public T get(Object key) {
	    return wrapped.get(key);
	}

	public T put(CharSequence key, T value) {
	    return wrapped.put(key, value);
	}

	public T remove(Object key) {
	    return wrapped.remove(key);
	}

	public void putAll(Map t) {
	    wrapped.putAll(t);
	}

	public void clear() {
	    wrapped.clear();
	}

	public Set keySet() {
	    return wrapped.keySet();
	}

	public Collection values() {
	    return wrapped.values();
	}

	public Set> entrySet() {
	    return wrapped.entrySet();
	}

	public boolean equals(Object other) {
	    return wrapped.equals(other);
	}

	public int hashCode() {
	    return wrapped.hashCode();
	}
    }

    static class Unmodifiable extends TrieProxy {

	Unmodifiable(Trie toWrap) {
	    super(toWrap);
	}

	public T put(CharSequence key, T value) {
	    throw new UnsupportedOperationException("Unmodifiable Trie");
	}

	public T remove(CharSequence key) {
	    throw new UnsupportedOperationException("Unmodifiable Trie");
	}

	public void putAll(Map t) {
	    throw new UnsupportedOperationException("Unmodifiable Trie");
	}

	public void clear() {
	    throw new UnsupportedOperationException("Unmodifiable Trie");
	}

	public Set keySet() {
	    return Collections.unmodifiableSet(super.keySet());
	}

	public Collection values() {
	    return Collections.unmodifiableCollection(super.values());
	}

	public Set> entrySet() {
	    return Collections.unmodifiableSet(super.entrySet());
	}
    }

    public static class Util {

	private Util() {
	}

	static  Trie unmodifiable(Trie toWrap) {
	    return new Unmodifiable(toWrap);
	}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy