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

ch.lambdaj.group.LeafGroup Maven / Gradle / Ivy

// Modified or written by Ex Machina SAGL for inclusion with lambdaj.
// Copyright (c) 2009 Mario Fusco.
// Licensed under the Apache License, Version 2.0 (the "License")

package ch.lambdaj.group;

import java.util.*;

/**
 * A leaf group is a group that doesn't contain other groups.
 * @author Mario Fusco
 */
public class LeafGroup implements Group {

	private final List list;
	private Map headMap = new TreeMap();
	
	@SuppressWarnings("unchecked")
	LeafGroup(Map map, String childrenNodeName) {
		headMap = new TreeMap(map);
		list = (List)headMap.remove(childrenNodeName);
	}
	
	public List find(String key) {
		return list;
	}

	public List find(Object key) {
		return find(key.toString());
	}
	
	public List findAll() {
		return list;
	}

	public Group findGroup(String key) {
		return this;
	}
	
	public Group findGroup(Object key) {
		return findGroup(key.toString());
	}
	
	public List> subgroups() {
		return new ArrayList>();
	}

	public int getSize() {
		return list.size();
	}

	public boolean isLeaf() {
		return true;
	}

	public Set keySet() {
		return new HashSet();
	}

	public String getHeadValue(String key) {
		Object value = headMap.get(key);
		return value == null ? "" : value.toString();
	}

	public Set getHeads() {
		return headMap.keySet();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy