001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved.
004: $Id: ReificationStatementMask.java,v 1.3 2008/01/02 12:08:23 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.db.impl;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.vocabulary.RDF;
011:
012: /**
013: Mutable statement-component masks for SpecializedGraphReifier.
014: (Extracted from same).
015: */
016: class ReificationStatementMask {
017:
018: protected int mask;
019:
020: public static final int HasSubj = 1;
021: public static final int HasPred = 2;
022: public static final int HasObj = 4;
023: public static final int HasType = 8;
024: public static final int HasSPOT = 15;
025: public static final int IsStmt = 16;
026: public static final int HasNada = 0;
027:
028: public boolean hasSubj() {
029: return (mask & HasSubj) == HasSubj;
030: }
031:
032: public boolean hasPred() {
033: return (mask & HasPred) == HasPred;
034: }
035:
036: public boolean hasObj() {
037: return (mask & HasObj) == HasObj;
038: }
039:
040: public boolean hasType() {
041: return (mask & HasType) == HasType;
042: }
043:
044: public boolean hasSPOT() {
045: return (mask & HasSPOT) == HasSPOT;
046: }
047:
048: public boolean isStmt() {
049: return (mask & IsStmt) == IsStmt;
050: }
051:
052: public boolean hasNada() {
053: return mask == HasNada;
054: }
055:
056: public boolean hasOneBit() {
057: return ((mask == HasSubj) || (mask == HasPred)
058: || (mask == HasObj) || (mask == HasType));
059: }
060:
061: // note: have SPOT does not imply a reification since
062: // 1) there may be multiple fragments for prop, obj
063: // 2) the fragments may be in multiple tuples
064:
065: ReificationStatementMask(Triple t) {
066: mask = HasNada;
067: Node p = t.getPredicate();
068: if (p != null) {
069: if (p.equals(RDF.Nodes.subject))
070: mask = HasSubj;
071: else if (p.equals(RDF.Nodes.predicate))
072: mask = HasPred;
073: else if (p.equals(RDF.Nodes.object))
074: mask = HasObj;
075: else if (p.equals(RDF.Nodes.type)) {
076: Node o = t.getObject();
077: if (o.equals(RDF.Nodes.Statement))
078: mask = HasType;
079: }
080: }
081: }
082:
083: ReificationStatementMask() {
084: mask = HasNada;
085: }
086:
087: public void setMerge(ReificationStatementMask m) {
088: mask |= m.mask;
089: }
090:
091: public void setHasType() {
092: mask |= HasType;
093: }
094:
095: public void setMask(boolean hasSubj, boolean hasProp,
096: boolean hasObj, boolean hasType) {
097: if (hasSubj)
098: mask |= HasSubj;
099: if (hasProp)
100: mask |= HasPred;
101: if (hasObj)
102: mask |= HasObj;
103: if (hasType)
104: mask |= HasType;
105: }
106:
107: public void setHasSubj() {
108: mask |= HasSubj;
109: }
110:
111: public void setHasPred() {
112: mask |= HasPred;
113: }
114:
115: public void setHasObj() {
116: mask |= HasObj;
117: }
118:
119: public void setIsStmt() {
120: mask |= IsStmt;
121: }
122:
123: public boolean hasIntersect(ReificationStatementMask m) {
124: return (mask & m.mask) != 0;
125: }
126:
127: public boolean equals(ReificationStatementMask m) {
128: return mask == m.mask;
129: }
130:
131: }
132:
133: /*
134: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
135: * All rights reserved.
136: *
137: * Redistribution and use in source and binary forms, with or without
138: * modification, are permitted provided that the following conditions
139: * are met:
140: * 1. Redistributions of source code must retain the above copyright
141: * notice, this list of conditions and the following disclaimer.
142: * 2. Redistributions in binary form must reproduce the above copyright
143: * notice, this list of conditions and the following disclaimer in the
144: * documentation and/or other materials provided with the distribution.
145: * 3. The name of the author may not be used to endorse or promote products
146: * derived from this software without specific prior written permission.
147:
148: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
149: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
150: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
151: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
152: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
153: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
154: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
155: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
157: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158: */
|