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

org.apache.geode.management.internal.web.domain.LinkIndex Maven / Gradle / Ivy

Go to download

Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing

There is a newer version: 1.15.1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package org.apache.geode.management.internal.web.domain;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.geode.internal.lang.StringUtils;

/**
 * The LinkIndex class is abstraction for modeling an index of Links.
 * 

* * @see javax.xml.bind.annotation.XmlRootElement * @see org.apache.geode.management.internal.web.domain.Link * @since GemFire 8.0 */ @SuppressWarnings("unused") @XmlRootElement(name = "link-index") public class LinkIndex implements Iterable { @XmlElement(name = "link") private final Set links = new TreeSet(); public LinkIndex add(final Link link) { assert link != null : "The Link to add to the index cannot be null!"; links.add(link); return this; } public LinkIndex addAll(final Link... links) { assert links != null : "The array of Links to add to this index cannot be null!"; return addAll(Arrays.asList(links)); } public LinkIndex addAll(final Iterable links) { assert links != null : "The Iterable collection of Links to add to this index cannot be null!"; for (final Link link : links) { add(link); } return this; } public Link find(final String relation) { Link linkFound = null; for (Link link : this) { if (link.getRelation().equalsIgnoreCase(relation)) { linkFound = link; break; } } return linkFound; } public Link[] findAll(final String relation) { final List links = new ArrayList(); for (final Link link : this) { if (link.getRelation().equalsIgnoreCase(relation)) { links.add(link); } } return links.toArray(new Link[links.size()]); } public boolean isEmpty() { return links.isEmpty(); } @Override public Iterator iterator() { return Collections.unmodifiableSet(links).iterator(); } public int size() { return links.size(); } public List toList() { return new ArrayList(links); } public Map> toMap() { final Map> links = new TreeMap>(); for (final Link link : this) { List linksByRelation = links.get(link.getRelation()); if (linksByRelation == null) { linksByRelation = new ArrayList(size()); links.put(link.getRelation(), linksByRelation); } linksByRelation.add(link); } return links; } @Override public String toString() { final StringBuilder buffer = new StringBuilder("["); int count = 0; for (final Link link : this) { buffer.append(count++ > 0 ? ", " : StringUtils.EMPTY_STRING).append(link); } buffer.append("]"); return buffer.toString(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy