001 package com.croftsoft.core.ai.astar; 002 003 import com.croftsoft.core.lang.NullArgumentException; 004 005 /********************************************************************* 006 * A* algorithm node information. 007 * 008 * @version 009 * 2003-05-09 010 * @since 011 * 2002-04-21 012 * @author 013 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 014 *********************************************************************/ 015 016 public final class NodeInfo 017 implements Comparable 018 ////////////////////////////////////////////////////////////////////// 019 ////////////////////////////////////////////////////////////////////// 020 { 021 022 private final Object node; 023 024 // 025 026 private double costFromStart; 027 028 private NodeInfo parentNodeInfo; 029 030 private double totalCost; 031 032 ////////////////////////////////////////////////////////////////////// 033 ////////////////////////////////////////////////////////////////////// 034 035 public NodeInfo ( Object node ) 036 ////////////////////////////////////////////////////////////////////// 037 { 038 NullArgumentException.check ( this.node = node ); 039 } 040 041 ////////////////////////////////////////////////////////////////////// 042 ////////////////////////////////////////////////////////////////////// 043 044 public double getCostFromStart ( ) { return costFromStart; } 045 046 public Object getNode ( ) { return node; } 047 048 public NodeInfo getParentNodeInfo ( ) { return parentNodeInfo; } 049 050 public double getTotalCost ( ) { return totalCost; } 051 052 ////////////////////////////////////////////////////////////////////// 053 ////////////////////////////////////////////////////////////////////// 054 055 public void setCostFromStart ( double costFromStart ) 056 ////////////////////////////////////////////////////////////////////// 057 { 058 this.costFromStart = costFromStart; 059 } 060 061 public void setParentNodeInfo ( NodeInfo parentNodeInfo ) 062 ////////////////////////////////////////////////////////////////////// 063 { 064 NullArgumentException.check ( 065 this.parentNodeInfo = parentNodeInfo ); 066 } 067 068 public void setTotalCost ( double totalCost ) 069 ////////////////////////////////////////////////////////////////////// 070 { 071 this.totalCost = totalCost; 072 } 073 074 ////////////////////////////////////////////////////////////////////// 075 ////////////////////////////////////////////////////////////////////// 076 077 public int compareTo ( Object other ) 078 ////////////////////////////////////////////////////////////////////// 079 { 080 NodeInfo otherNodeInfo = ( NodeInfo ) other; 081 082 double otherTotalCost = otherNodeInfo.totalCost; 083 084 if ( totalCost < otherTotalCost ) 085 { 086 return -1; 087 } 088 089 if ( totalCost > otherTotalCost ) 090 { 091 return 1; 092 } 093 094 return 0; 095 } 096 097 ////////////////////////////////////////////////////////////////////// 098 ////////////////////////////////////////////////////////////////////// 099 }