Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graphstream JSON #90

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!---freshmark shields
output = [
link(shield('Bintray', 'bintray', 'tersesystems:terse-logback', 'blue'), 'https://bintray.com/tersesystems/maven/terse-logback/view'),
link(shield('Latest version', 'latest', '{{version}}', 'blue'), 'https://github.com/tersesystems/terse-logback/releases/latest'),
link(shield('Latest version', 'latest', '{{previousVersion}}', 'blue'), 'https://github.com/tersesystems/terse-logback/releases/latest'),
link(shield('License CC0', 'license', 'CC0', 'blue'), 'https://tldrlegal.com/license/creative-commons-cc0-1.0-universal'),
'',
link(shield('Release Notes', 'release-notes', '{{version}}', 'brightgreen'), 'docs/release-notes.md'),
link(shield('Release Notes', 'release-notes', '{{previousVersion}}', 'brightgreen'), 'docs/release-notes.md'),
link(image('Travis CI', 'https://travis-ci.org/tersesystems/terse-logback.svg?branch=master'), 'https://travis-ci.org/tersesystems/terse-logback')
].join('\n')
-->
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ junitJupiterVersion = 5.0.1
junitVintageVersion = 4.12.1
junitPlatformVersion = 1.0.1
slf4jVersion = 1.7.25
logstashVersion = 6.1
logstashVersion = 6.2
logbackVersion = 1.2.3
configVersion = 1.3.3
zstdVersion = 1.4.0-1
1 change: 1 addition & 0 deletions logback-graphstream/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project_description = Logback Graphstream
23 changes: 23 additions & 0 deletions logback-graphstream/logback-graphstream.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: CC0-1.0
*
* Copyright 2018-2019 Will Sargent.
*
* Licensed under the CC0 Public Domain Dedication;
* You may obtain a copy of the License at
*
* http://creativecommons.org/publicdomain/zero/1.0/
*/
plugins {
id 'java-library'
}

dependencies {
implementation project(':logback-classic')

//implementation "org.graphstream:gs-core:1.3"
//implementation "org.graphstream:gs-ui:1.3"

implementation "ch.qos.logback:logback-classic:$logbackVersion"
implementation "net.logstash.logback:logstash-logback-encoder:$logstashVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package com.tersesystems.logback.graphstream;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

interface BuilderAttributes<H> {
H addAttribute(String name, Object attribute);

H addAttributes(Map<String, Object> attributes);

H removeAttribute(String name);

H removeAttributes(Set<String> names);

H changeAttribute(String name, Object attribute);

H changeAttributes(Map<String, Object> attributes);
}

interface BuilderEdges<H> {
H from(String nodeId);

H to(String nodeId);

H directed(boolean isDirected);
}

// http://egalluzzo.blogspot.com/2010/06/using-inheritance-with-fluent.html
// https://stackoverflow.com/questions/17164375/subclassing-a-java-builder-class
// https://onelostlogician.wordpress.com/2016/10/10/inheritance-generics-and-builders/

public abstract class Builder<SELF extends Builder<SELF>> implements BuilderAttributes<SELF> {

Set<GraphAttributeEvent> attributes;

public abstract GraphEventMarker build();

@SuppressWarnings("unchecked")
final SELF self() {
return (SELF) this;
}

@Override
public SELF addAttribute(String name, Object attribute) {
attributes.add(new GraphAttributeEvent.Add(name, attribute));
return self();
}

@Override
public SELF addAttributes(Map<String, Object> attributesMap) {
Set<GraphAttributeEvent> newSet =
attributesMap.entrySet().stream()
.map(entry -> new GraphAttributeEvent.Add(entry.getKey(), entry.getValue()))
.collect(Collectors.toSet());
attributes.addAll(newSet);
return self();
}

@Override
public SELF removeAttribute(String name) {
attributes.add(new GraphAttributeEvent.Remove(name));
return self();
}

@Override
public SELF removeAttributes(Set<String> names) {
Set<GraphAttributeEvent.Remove> newSet =
names.stream().map(GraphAttributeEvent.Remove::new).collect(Collectors.toSet());
attributes.addAll(newSet);
return self();
}

@Override
public SELF changeAttribute(String name, Object value) {
attributes.add(new GraphAttributeEvent.Change(name, value));
return self();
}

@Override
public SELF changeAttributes(Map<String, Object> attributeMap) {
Set<GraphAttributeEvent.Change> newSet =
attributeMap.entrySet().stream()
.map(entry -> new GraphAttributeEvent.Change(entry.getKey(), entry.getValue()))
.collect(Collectors.toSet());
attributes.addAll(newSet);
return self();
}

static class AddNode extends Builder<AddNode> {
private final String nodeId;
private final String graphId;

AddNode(String graphId, String nodeId) {
this.graphId = graphId;
this.nodeId = nodeId;
this.attributes = new LinkedHashSet<>();
}

public GraphEventMarker build() {
return new GraphEventMarker.AddNodeEventMarker(graphId, nodeId, attributes);
}
}

static class ChangeNode extends Builder<ChangeNode> {
private final String nodeId;
private final String graphId;

ChangeNode(String graphId, String nodeId) {
this.graphId = graphId;
this.nodeId = nodeId;
this.attributes = new LinkedHashSet<>();
}

@Override
public GraphEventMarker build() {
return new GraphEventMarker.ChangeNodeEventMarker(graphId, nodeId, attributes);
}
}

static class AddEdge extends Builder<AddEdge> implements BuilderEdges<AddEdge> {

private final String sourceId;
private final String edgeId;
private boolean directed;
private String fromNodeId;
private String toNodeId;

AddEdge(String sourceId, String edgeId) {
this.sourceId = sourceId;
this.edgeId = edgeId;
this.attributes = new LinkedHashSet<>();
}

@Override
public AddEdge from(String fromNodeId) {
this.fromNodeId = fromNodeId;
return self();
}

@Override
public AddEdge to(String toNodeId) {
this.toNodeId = toNodeId;
return self();
}

@Override
public AddEdge directed(boolean isDirected) {
this.directed = isDirected;
return self();
}

@Override
public GraphEventMarker build() {
return new GraphEventMarker.AddEdgeEventMarker(
sourceId, edgeId, fromNodeId, toNodeId, directed, attributes);
}
}

static class ChangeEdge extends Builder<ChangeEdge> {
private final String edgeId;
private final String graphId;

ChangeEdge(String graphId, String edgeId) {
this.graphId = graphId;
this.edgeId = edgeId;
this.attributes = new LinkedHashSet<>();
}

@Override
public GraphEventMarker build() {
return new GraphEventMarker.ChangeEdgeEventMarker(graphId, edgeId, attributes);
}
}

static class ChangeGraph extends Builder<ChangeGraph> {
private final String graphId;

ChangeGraph(String graphId) {
this.graphId = graphId;
this.attributes = new LinkedHashSet<>();
}

@Override
public GraphEventMarker build() {
return new GraphEventMarker.ChangeGraphEventMarker(graphId, attributes);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.tersesystems.logback.graphstream;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "op", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = GraphAttributeEvent.Add.class),
@JsonSubTypes.Type(value = GraphAttributeEvent.Change.class),
@JsonSubTypes.Type(value = GraphAttributeEvent.Remove.class),
})
public abstract class GraphAttributeEvent {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@JsonTypeName("add")
public static class Add extends GraphAttributeEvent {
private Object value;

public Add() {}

public Add(String name, Object value) {
setName(name);
this.value = value;
}

public Object getValue() {
return value;
}

public void setValue(Object value) {
this.value = value;
}
}

@JsonTypeName("set")
public static class Change extends GraphAttributeEvent {
private Object value;

public Change() {}

public Change(String name, Object newValue) {
setName(name);
setValue(newValue);
}

public Object getValue() {
return value;
}

public void setValue(Object value) {
this.value = value;
}
}

@JsonTypeName("rm")
public static class Remove extends GraphAttributeEvent {
public Remove() {}

public Remove(String name) {
setName(name);
}
}
}
Loading