1/*
2	Copyright (c) 2012 Kier Davis
3
4	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5	associated documentation files (the "Software"), to deal in the Software without restriction,
6	including without limitation the rights to use, copy, modify, merge, publish, distribute,
7	sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8	furnished to do so, subject to the following conditions:
9
10	The above copyright notice and this permission notice shall be included in all copies or substantial
11	portions of the Software.
12
13	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14	NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
16	OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17	CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18*/
19
20package gojsonld
21
22import (
23	"fmt"
24)
25
26// A Triple contains a subject, a predicate and an object term.
27type Triple struct {
28	Subject   Term
29	Predicate Term
30	Object    Term
31}
32
33// Function NewTriple returns a new triple with the given subject, predicate and object.
34func NewTriple(subject Term, predicate Term, object Term) (triple *Triple) {
35	return &Triple{
36		Subject:   subject,
37		Predicate: predicate,
38		Object:    object,
39	}
40}
41
42// Method String returns the NTriples representation of this triple.
43func (triple Triple) String() (str string) {
44	subj_str := "nil"
45	if triple.Subject != nil {
46		subj_str = triple.Subject.String()
47	}
48
49	pred_str := "nil"
50	if triple.Predicate != nil {
51		pred_str = triple.Predicate.String()
52	}
53
54	obj_str := "nil"
55	if triple.Object != nil {
56		obj_str = triple.Object.String()
57	}
58
59	return fmt.Sprintf("%s %s %s .", subj_str, pred_str, obj_str)
60}
61
62// Method Equal returns this triple is equivalent to the argument.
63func (triple Triple) Equal(other *Triple) bool {
64	return triple.Subject.Equal(other.Subject) &&
65		triple.Predicate.Equal(other.Predicate) &&
66		triple.Object.Equal(other.Object)
67}
68