001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.management;
020
021import java.util.*;
022
023/**
024 * Selects nodes based on their uuids.
025 * @author Laurent Cohen
026 */
027public class UuidSelector implements NodeSelector, DriverSelector {
028  /**
029   * Explicit serialVersionUID.
030   */
031  private static final long serialVersionUID = 1L;
032  /**
033   * The list of uuids of the nodes to select. This list is immutable.
034   */
035  private final Collection<String> uuids;
036
037  /**
038   * Initialize this selector with the specified list of node UUIDs.
039   * @param uuids the uuids of the nodes to select.
040   */
041  public UuidSelector(final Collection<String> uuids) {
042    this.uuids = (uuids == null) ? Collections.<String>emptyList() : new ArrayList<>(uuids);
043  }
044
045  /**
046   * Initialize this selector with the specified array of node UUIDs.
047   * @param uuids the uuids of the nodes to select.
048   */
049  public UuidSelector(final String...uuids) {
050    this.uuids = (uuids == null) ? Collections.<String>emptyList() : Arrays.asList(uuids);
051  }
052
053  /**
054   * Get the list of uuids of the nodes to select. This list is immutable.
055   * @return a collection of uuids as strings.
056   */
057  public Collection<String> getUuids() {
058    return uuids;
059  }
060
061  @Override
062  public boolean accepts(final JPPFManagementInfo nodeInfo) {
063    return (nodeInfo != null) && uuids.contains(nodeInfo.getUuid());
064  }
065}