Created
February 12, 2009 15:07
-
-
Save shin1ogawa/62662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 指定したModelが、指定したModelの配下にあるのかどうかを返す。 | |
* <p>Modelの構造の外で解決した方が良い気がするので、ここに置いてみた。</p> | |
* <p>FIXME こんな適当な実装だとメソッドの中がエライ事になりそうだし、この実装はない。なんかうまい実装は無いものか。</p> | |
* | |
* @param parent | |
* @param child | |
* @return Model同士が親子関係にある時は{@code true} | |
*/ | |
public static boolean isChild(JiemamyElement parent, JiemamyElement child) { | |
if (parent instanceof RootModel) { | |
return isRootChild((RootModel) parent, child); | |
} else if (parent instanceof TableModel) { | |
return isTableChild((TableModel) parent, child); | |
} else if (parent instanceof PrimaryKeyModel) { | |
return isPrimaryKeyChild((PrimaryKeyModel) parent, child); | |
} | |
return false; | |
} | |
private static boolean isPrimaryKeyChild(PrimaryKeyModel parent, JiemamyElement child) { | |
List<ColumnRef> columnRefs = parent.getKeyColumns(); | |
for (ColumnRef ref : columnRefs) { | |
if (ref.getReferenceId().equals(child.getId())) { | |
return true; | |
} | |
} | |
return false; | |
} | |
private static boolean isRootChild(RootModel root, JiemamyElement child) { | |
for (EntityModel table : root.getEntities()) { | |
if (table == child) { | |
return true; | |
} | |
if (isChild(table, child)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
private static boolean isTableChild(TableModel table, JiemamyElement child) { | |
for (AttributeModel attribute : table.getAttributes()) { | |
if (attribute == child) { | |
return true; | |
} | |
if (isChild(attribute, child)) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment