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//  private final Set<Object> referencesToThisObject = new MonotonicHashSet<>();
034
035  public Vertex(T object, String name, ConstructorDef<T> constructorDef, Vertex<?>[] constructorArguments) {
036    this.object = object;
037    if (object == null) {
038      throw new NullPointerException();
039    }
040    this.name = name;
041    this.constructorDef = constructorDef;
042    this.constructorArguments = constructorArguments;
043    for (Vertex<?> v : constructorArguments) {
044      if (v == null) {
045        throw new NullPointerException();
046      }
047    }
048  }
049
050  public Vertex(T object, ConstructorDef<T> constructorDef, Vertex<?>[] constructorArguments) {
051    this.object = object;
052    if (object == null) {
053      throw new NullPointerException();
054    }
055    this.name = null;
056    this.constructorDef = constructorDef;
057    this.constructorArguments = constructorArguments;
058    for (Vertex<?> v : constructorArguments) {
059      if (v == null) {
060        throw new NullPointerException();
061      }
062    }
063  }
064
065  public Vertex(Object object) {
066    this.object = object;
067    if (object == null) {
068      throw new NullPointerException();
069    }
070    this.name = null;
071    this.constructorDef = null;
072    this.constructorArguments = null;
073  }
074
075  //  public void addReference(Vertex<?> v) {
076//    referencesToThisObject.add(v);
077//  }
078//  public Vertex<?>[] getInEdges() {
079//    return referencesToThisObject.toArray(new Vertex[0]);
080//  }
081  public ConstructorDef<T> getConstructorDef() {
082    return this.constructorDef;
083  }
084
085  public Vertex<?>[] getOutEdges() {
086    if (constructorArguments == null) {
087      return new Vertex[0];
088    } else {
089      return Arrays.copyOf(constructorArguments, constructorArguments.length);
090    }
091  }
092
093  public Object getObject() {
094    return object;
095  }
096
097  public String getName() {
098    return name;
099  }
100}