forked from Linyuzai/concept
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tanghanzheng
committed
Dec 14, 2022
1 parent
2d56feb
commit 9934aaa
Showing
52 changed files
with
683 additions
and
337 deletions.
There are no files selected for viewing
16 changes: 12 additions & 4 deletions
16
concept-thing/concept-thing-core/src/main/java/com/github/linyuzai/thing/core/Test.java
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
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
23 changes: 21 additions & 2 deletions
23
...g/concept-thing-core/src/main/java/com/github/linyuzai/thing/core/action/ThingAction.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
package com.github.linyuzai.thing.core.action; | ||
|
||
import com.github.linyuzai.thing.core.event.ThingEvent; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface ThingAction { | ||
|
||
ThingActionPerformance perform(); | ||
String ADD = "ThingAction::ADD"; | ||
|
||
String REMOVE = "ThingAction::REMOVE"; | ||
|
||
String VALUE_UPDATE = "ThingAction::VALUE_UPDATE"; | ||
|
||
ThingActionExecution execute(); | ||
|
||
//ThingActionChain chain(); | ||
|
||
static ThingAction create(Supplier<Supplier<ThingEvent>> supplier) { | ||
return () -> { | ||
Supplier<ThingEvent> event = supplier.get(); | ||
return event::get; | ||
}; | ||
} | ||
|
||
|
||
ThingActionChain chain(); | ||
} |
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
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
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
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
19 changes: 14 additions & 5 deletions
19
...pt-thing-core/src/main/java/com/github/linyuzai/thing/core/concept/AbstractAttribute.java
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
39 changes: 38 additions & 1 deletion
39
...ept-thing-core/src/main/java/com/github/linyuzai/thing/core/concept/AbstractCategory.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
package com.github.linyuzai.thing.core.concept; | ||
|
||
public abstract class AbstractCategory implements Category { | ||
import com.github.linyuzai.thing.core.container.Categories; | ||
import com.github.linyuzai.thing.core.container.Labels; | ||
import com.github.linyuzai.thing.core.factory.CategoryFactory; | ||
import com.github.linyuzai.thing.core.factory.LabelFactory; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class AbstractCategory extends AbstractIdentify<Category> implements Category { | ||
|
||
private String name; | ||
|
||
private Category parent; | ||
|
||
private Categories categories; | ||
|
||
private Labels labels; | ||
|
||
@Override | ||
public Categories getCategories() { | ||
if (categories == null) { | ||
CategoryFactory factory = getContext().get(CategoryFactory.class); | ||
categories = factory.createContainer(); | ||
categories.setContext(getContext()); | ||
} | ||
return categories; | ||
} | ||
|
||
@Override | ||
public Labels getLabels() { | ||
if (labels == null) { | ||
LabelFactory factory = getContext().get(LabelFactory.class); | ||
labels = factory.createContainer(); | ||
labels.setContext(getContext()); | ||
labels.setCategory(this); | ||
} | ||
return labels; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ept-thing-core/src/main/java/com/github/linyuzai/thing/core/concept/AbstractIdentify.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.github.linyuzai.thing.core.concept; | ||
|
||
import com.github.linyuzai.thing.core.context.ThingContext; | ||
import com.github.linyuzai.thing.core.generate.IdentifyGenerator; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.function.Function; | ||
|
||
@Getter | ||
@Setter | ||
@SuppressWarnings("unchecked") | ||
public abstract class AbstractIdentify<T extends Identify<T>> implements Identify<T> { | ||
|
||
private String id; | ||
|
||
private Function<T, String> idProvider = t -> { | ||
IdentifyGenerator generator = getContext().get(IdentifyGenerator.class); | ||
return generator.generateId(t); | ||
}; | ||
|
||
private String key; | ||
|
||
private Function<T, String> keyProvider = t -> { | ||
IdentifyGenerator generator = getContext().get(IdentifyGenerator.class); | ||
return generator.generateKey(t); | ||
}; | ||
|
||
private ThingContext context; | ||
|
||
@Override | ||
public String getId() { | ||
if (id == null) { | ||
if (idProvider != null) { | ||
id = idProvider.apply((T) this); | ||
} | ||
} | ||
return id; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
if (key == null) { | ||
if (keyProvider != null) { | ||
key = keyProvider.apply((T) this); | ||
} | ||
} | ||
return key; | ||
} | ||
} |
10 changes: 9 additions & 1 deletion
10
...oncept-thing-core/src/main/java/com/github/linyuzai/thing/core/concept/AbstractLabel.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.github.linyuzai.thing.core.concept; | ||
|
||
public abstract class AbstractLabel implements Label { | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class AbstractLabel extends AbstractIdentify<Label> implements Label { | ||
|
||
private String name; | ||
|
||
private Category category; | ||
} |
32 changes: 31 additions & 1 deletion
32
...thing-core/src/main/java/com/github/linyuzai/thing/core/concept/AbstractRelationship.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
package com.github.linyuzai.thing.core.concept; | ||
|
||
public abstract class AbstractRelationship implements Relationship { | ||
import com.github.linyuzai.thing.core.factory.RelationshipFactory; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class AbstractRelationship extends AbstractIdentify<Relationship> implements Relationship { | ||
|
||
private String name; | ||
|
||
private Thing thing; | ||
|
||
private Thing relation; | ||
|
||
private Relationship opposite; | ||
|
||
public Relationship getOpposite() { | ||
if (opposite == null) { | ||
RelationshipFactory factory = getContext().get(RelationshipFactory.class); | ||
opposite = factory.create(); | ||
String suffix = ".OPPOSITE"; | ||
if (name.endsWith(suffix)) { | ||
opposite.setName(name.substring(0, name.length() - suffix.length())); | ||
} else { | ||
opposite.setName(name + suffix); | ||
} | ||
opposite.setThing(relation); | ||
opposite.setRelation(thing); | ||
opposite.setOpposite(this); | ||
opposite.setContext(getContext()); | ||
} | ||
return opposite; | ||
} | ||
} |
Oops, something went wrong.