Skip to content

Commit

Permalink
more rename of visit in accept to follow the standard design pattern …
Browse files Browse the repository at this point in the history
…naming
  • Loading branch information
MarcGuiot committed Jun 21, 2024
1 parent 9f33d33 commit 1a2a9b4
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The main drawback of GlobsFramework is its limited compatibility with beans. How
The inspiration for GlobsFramework stems from the telecom industry's reliance on GDMO (https://en.wikipedia.org/wiki/Guidelines_for_the_Definition_of_Managed_Objects) models, which were initially used to generate code for various purposes like databases, UI, and ASN1 encoding. Over time, this generic model evolved into direct use within codebases, with XML serving as the description format for Managed Objects (MO). The framework's genesis occurred during a rewrite for a private financial company in 2006 by Regis Medina and Marc Guiot, and it continues to be actively used today. Subsequently, an open-source version was developed for the BudgetView project (https://web.archive.org/web/20181229134134/http://www.mybudgetview.com/, https://github.com/MarcGuiot/budgetview).
It is used in other company for aggregation of data and in an e-Commerce back-end.

## exemple of a db query
## exemple of a db query in a lib that use Globs

```
sqlConnection.getQueryBuilder(DummyObject.TYPE,
Expand Down Expand Up @@ -64,7 +64,7 @@ A Field interface
public interface Field {
GlobType getGlobType()
String getName();
<T extends FieldVisitor> T visit(T visitor) throws Exception;
<T extends FieldVisitor> T accept(T visitor) throws Exception;
Glob getAnnotation(Key key);
...
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/globsframework/model/ChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public interface ChangeSet {

FieldValues getPreviousValues(Key key);

void visit(ChangeSetVisitor visitor) throws Exception;
void accept(ChangeSetVisitor visitor) throws Exception;

void safeVisit(ChangeSetVisitor visitor);
void safeAccept(ChangeSetVisitor visitor);

void visit(GlobType type, ChangeSetVisitor visitor) throws Exception;
void accept(GlobType type, ChangeSetVisitor visitor) throws Exception;

void safeVisit(GlobType type, ChangeSetVisitor visitor);
void safeAccept(GlobType type, ChangeSetVisitor visitor);

void visit(Key key, ChangeSetVisitor visitor) throws Exception;
void accept(Key key, ChangeSetVisitor visitor) throws Exception;

void safeVisit(Key key, ChangeSetVisitor visitor);
void safeAccept(Key key, ChangeSetVisitor visitor);

ChangeSet reverse();
}
36 changes: 18 additions & 18 deletions src/main/java/org/globsframework/model/delta/DefaultChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,41 @@ protected DefaultDeltaGlob createDeltaGlob(Key key) {
return new DefaultDeltaGlob(key);
}

public void visit(ChangeSetVisitor visitor) throws Exception {
public void accept(ChangeSetVisitor visitor) throws Exception {
Collection<DefaultDeltaGlob> values = deltaGlobsByKey.values();
visit(visitor, values, DeltaState.DELETED);
visit(visitor, values, DeltaState.UPDATED);
visit(visitor, values, DeltaState.CREATED);
accept(visitor, values, DeltaState.DELETED);
accept(visitor, values, DeltaState.UPDATED);
accept(visitor, values, DeltaState.CREATED);
}

public void safeVisit(ChangeSetVisitor visitor) {
public void safeAccept(ChangeSetVisitor visitor) {
try {
visit(visitor);
accept(visitor);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public void visit(GlobType type, ChangeSetVisitor visitor) throws Exception {
public void accept(GlobType type, ChangeSetVisitor visitor) throws Exception {
Collection<DefaultDeltaGlob> values = deltaGlobsByKey.get(type).values();
visit(visitor, values, DeltaState.DELETED);
visit(visitor, values, DeltaState.UPDATED);
visit(visitor, values, DeltaState.CREATED);
accept(visitor, values, DeltaState.DELETED);
accept(visitor, values, DeltaState.UPDATED);
accept(visitor, values, DeltaState.CREATED);
}

private void visit(ChangeSetVisitor visitor, Collection<DefaultDeltaGlob> globs, DeltaState state) throws Exception {
private void accept(ChangeSetVisitor visitor, Collection<DefaultDeltaGlob> globs, DeltaState state) throws Exception {
for (DefaultDeltaGlob deltaGlob : globs) {
if (deltaGlob.getState() == state) {
deltaGlob.visit(visitor);
}
}
}

public void safeVisit(GlobType type, ChangeSetVisitor visitor) {
public void safeAccept(GlobType type, ChangeSetVisitor visitor) {
try {
visit(type, visitor);
accept(type, visitor);
} catch (BreakException e) {
} catch (RuntimeException e) {
throw e;
Expand All @@ -124,16 +124,16 @@ public void safeVisit(GlobType type, ChangeSetVisitor visitor) {
}
}

public void visit(Key key, ChangeSetVisitor visitor) throws Exception {
public void accept(Key key, ChangeSetVisitor visitor) throws Exception {
DefaultDeltaGlob deltaGlob = deltaGlobsByKey.get(key.getGlobType(), key);
if (deltaGlob != null) {
deltaGlob.visit(visitor);
}
}

public void safeVisit(Key key, ChangeSetVisitor visitor) {
public void safeAccept(Key key, ChangeSetVisitor visitor) {
try {
visit(key, visitor);
accept(key, visitor);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ public int size() {
}

public void merge(ChangeSet other) throws InvalidState {
other.safeVisit(new ChangeSetVisitor() {
other.safeAccept(new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) throws Exception {
processCreation(key, values);
}
Expand All @@ -371,7 +371,7 @@ public void visitDeletion(Key key, FieldsValueScanner values) throws Exception {
public String toString() {
try {
StringWriter writer = new StringWriter();
visit(new PrintChangeVisitor(writer));
accept(new PrintChangeVisitor(writer));
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public void deleteAll(GlobType... types) throws OperationDenied {
}

public void apply(ChangeSet changeSet) throws InvalidParameter {
changeSet.safeVisit(new ChangeSetVisitor() {
changeSet.safeAccept(new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) {
if (contains(key)) {
throw new InvalidParameter("Object " + key + " already exists\n" +
Expand All @@ -623,7 +623,7 @@ public void visitDeletion(Key key, FieldsValueScanner values) {

try {
startChangeSet();
changeSet.safeVisit(new ChangeSetExecutor());
changeSet.safeAccept(new ChangeSetExecutor());
} finally {
completeChangeSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void deleteAll(GlobType... types) throws OperationDenied {
public void apply(ChangeSet changeSet) throws InvalidParameter {
final DefaultChangeSet localChangeSet = new DefaultChangeSet();
final DefaultChangeSet remoteChangeSet = new DefaultChangeSet();
changeSet.safeVisit(new ChangeVisitor() {
changeSet.safeAccept(new ChangeVisitor() {
public void complete() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static void dispatchChanges(ChangeSet changeSet,
final MultiMap<GlobType, ChangeWithPrevious> updates,
final MultiMap<GlobType, Change> deletions,
final GlobTypeDependencies dependencies) {
changeSet.safeVisit(new ChangeSetVisitor() {
changeSet.safeAccept(new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) throws Exception {
if (!dependencies.needsPostUpdate(key.getGlobType())) {
creations.put(key.getGlobType(), new Change(key, values));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void writeKnowGlob(Glob glob) {

public void writeChangeSet(ChangeSet changeSet) {
writeInteger(changeSet.getChangeCount());
changeSet.safeVisit(this);
changeSet.safeAccept(this);
}

public void write(int[] values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void testChangeAnalysisForUpdate() throws Exception {
@Test
public void testUpdatedFieldsDoNoContainKeys() throws Exception {
changeSet.processUpdate(key1, DummyObject.VALUE, 1.1, null);
changeSet.visit(DummyObject.TYPE, new DefaultChangeSetVisitor() {
changeSet.accept(DummyObject.TYPE, new DefaultChangeSetVisitor() {
public void visitUpdate(Key key, FieldsValueWithPreviousScanner values) throws Exception {
assertFalse(TestUtils.contains(values, DummyObject.ID));
}
Expand Down Expand Up @@ -273,7 +273,7 @@ public void testApplyingReverseChangesClearsTheChangeSet() throws Exception {

final ChangeSet reverse = changeSet.reverse();

reverse.visit(new ChangeSetVisitor() {
reverse.accept(new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) throws Exception {
changeSet.processCreation(key, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void testCreationAndUpdateHaveNoKeyFieldsInTheFieldValuesParameter() thro

repository.addChangeListener(new DefaultChangeSetListener() {
public void globsChanged(ChangeSet changeSet, GlobRepository repository) {
changeSet.safeVisit(new DefaultChangeSetVisitor() {
changeSet.safeAccept(new DefaultChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) throws Exception {
values.apply(new NoKeyFieldChecker().withoutKeyField());
}
Expand Down Expand Up @@ -754,7 +754,7 @@ public void testTriggersAreCalledBeforeListeners() throws Exception {
initRepository();
repository.addTrigger(new DefaultChangeSetListener() {
public void globsChanged(ChangeSet changeSet, final GlobRepository repository) {
changeSet.safeVisit(DummyObject.TYPE, new ChangeSetVisitor() {
changeSet.safeAccept(DummyObject.TYPE, new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner values) throws Exception {
String newValue = (TestUtils.contains(values, DummyObject.NAME) ? TestUtils.get(values, DummyObject.NAME) : "null") + "-created";
repository.update(key, DummyObject.NAME, newValue);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/globsframework/xml/XmlChangeSetWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private XmlChangeSetWriter() {
public static void write(ChangeSet changeSet, Writer writer) {
doWrite(changeSet, writer, new ContentDumper() {
public void process(ChangeSet changeSet, ChangeSetVisitor visitor) {
changeSet.safeVisit(visitor);
changeSet.safeAccept(visitor);
}
});
}
Expand All @@ -25,7 +25,7 @@ public static void write(ChangeSet changeSet, final List<Key> keys, Writer write
doWrite(changeSet, writer, new ContentDumper() {
public void process(ChangeSet changeSet, ChangeSetVisitor visitor) {
for (Key key : keys) {
changeSet.safeVisit(key, visitor);
changeSet.safeAccept(key, visitor);
}
}
});
Expand All @@ -34,14 +34,14 @@ public void process(ChangeSet changeSet, ChangeSetVisitor visitor) {
public static void write(ChangeSet changeSet, final GlobType type, Writer writer) {
doWrite(changeSet, writer, new ContentDumper() {
public void process(ChangeSet changeSet, ChangeSetVisitor visitor) {
changeSet.safeVisit(type, visitor);
changeSet.safeAccept(type, visitor);
}
});
}

public static void prettyWrite(ChangeSet changeSet, Writer writer) {
XmlChangeSetVisitor visitor = new XmlChangeSetVisitor(writer, 2);
changeSet.safeVisit(visitor);
changeSet.safeAccept(visitor);
visitor.complete();
try {
writer.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void testStandardCase() throws Exception {
));

assertEquals(3, changeSet.getChangeCount(DummyObject.TYPE));
changeSet.visit(new ChangeSetVisitor() {
changeSet.accept(new ChangeSetVisitor() {
public void visitCreation(Key key, FieldsValueScanner valueScanner) throws Exception {
DefaultFieldValues values = new DefaultFieldValues(valueScanner);
assertEquals(1, key.get(DummyObject.ID).intValue());
Expand Down

0 comments on commit 1a2a9b4

Please sign in to comment.