This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  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,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.wake.profiler;
020
021import org.apache.reef.tang.types.ConstructorDef;
022
023import java.util.Arrays;
024
025/**
026 * A vertex in the object graph.  There is no edge type, since that would be redundant.
027 */
028public class Vertex<T> {
029  private final Object object;
030  private final String name;
031  private final ConstructorDef<T> constructorDef;
032  private final Vertex<?>[] constructorArguments;
033
034  public Vertex(final T object, final String name, final ConstructorDef<T> constructorDef,
035                final Vertex<?>[] constructorArguments) {
036    this.object = object;
037    if (object == null) {
038      throw new NullPointerException("The first argument of the Vertex constructor is null.");
039    }
040    this.name = name;
041    this.constructorDef = constructorDef;
042    this.constructorArguments = constructorArguments;
043    for (final Vertex<?> v : constructorArguments) {
044      if (v == null) {
045        throw new NullPointerException("One of the vertices in the Vertex constructorArguments is null.");
046      }
047    }
048  }
049
050  public Vertex(final T object, final ConstructorDef<T> constructorDef, final Vertex<?>[] constructorArguments) {
051    this.object = object;
052    if (object == null) {
053      throw new NullPointerException("The first argument of the Vertex constructor is null.");
054    }
055    this.name = null;
056    this.constructorDef = constructorDef;
057    this.constructorArguments = constructorArguments;
058    for (final Vertex<?> v : constructorArguments) {
059      if (v == null) {
060        throw new NullPointerException("One of the vertices in the Vertex constructorArguments is null.");
061      }
062    }
063  }
064
065  public Vertex(final Object object) {
066    this.object = object;
067    if (object == null) {
068      throw new NullPointerException("The argument of the Vertex constructor is null.");
069    }
070    this.name = null;
071    this.constructorDef = null;
072    this.constructorArguments = null;
073  }
074
075  public ConstructorDef<T> getConstructorDef() {
076    return this.constructorDef;
077  }
078
079  public Vertex<?>[] getOutEdges() {
080    if (constructorArguments == null) {
081      return new Vertex[0];
082    } else {
083      return Arrays.copyOf(constructorArguments, constructorArguments.length);
084    }
085  }
086
087  public Object getObject() {
088    return object;
089  }
090
091  public String getName() {
092    return name;
093  }
094}