我正在处理一个名为Types and Tags的两个对象的应用程序。
Type.java
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#define MAX_LEN 10
#define SPECIAL '#'
bool f[MAX_LEN+1][MAX_LEN+1][MAX_LEN+1];
bool isSpecialName(char *pa, char *pb, char *pc) {
int la = strlen(pa);
int lb = strlen(pb);
int lc = strlen(pc);
if (la > lb + lc) return false;
memset(f, false, sizeof(f));
memset(f[0], true, sizeof(f[0]));
for (int i=1; i<=la; ++i) for (int j=0; j<=lb; ++j) for (int k=0; k<=lc; ++k) {
char a = tolower(pa[i-1]);
char b = j > 0 ? tolower(pb[j-1]) : SPECIAL;
char c = k > 0 ? tolower(pc[k-1]) : SPECIAL;
if (j > 0) f[i][j][k] = f[i][j-1][k] || f[i][j][k];
if (k > 0) f[i][j][k] = f[i][j][k-1] || f[i][j][k];
if (a == b) f[i][j][k] = f[i-1][j-1][k] || f[i][j][k];
if (a == c) f[i][j][k] = f[i-1][j][k-1] || f[i][j][k];
}
return f[la][lb][lc];
}
void check(char *a, char *b, char *c) {
if (isSpecialName(a, b, c)) fprintf(stdout, "'%s' *IS* special name of '%s' and '%s'\n", a, b, c);
else fprintf(stderr, "'%s' is *NOT* special of '%s' and '%s'\n", a, b, c);
}
int main() {
check("ab", "a", "b");
check("Dan", "Jane", "Adam");
check("Henry", "Hunter", "Wendy");
check("abcd", "ac", "bd");
check("abcd", "ac", "bb");
return 0;
}
Tag.java
public class Type {
private String name;
private final UUID uuid;
private final List<Tag> tags;
}
Tables.sql
public class Tag {
private String name;
private final UUID uuid;
}
我遵循DAO设计模式,但我在这里应用它时遇到了麻烦。每个Type都有一个Tags列表,那么加载Type的最佳方法是什么?