code
stringlengths
67
466k
docstring
stringlengths
1
13.2k
public void set(String key, String value) { if(key == null) throw new IllegalArgumentException("Null keys not allowed."); if(value == null) throw new IllegalArgumentException("Null values not allowed."); ArrayList<String> vals = new ArrayList<String>(); vals.add(value); map.put(key,vals); }
Set a value for the supplied key. This will overwrite any values that are currently stored for this key. @param key The key @param value The value to store
public void add(String key, String value) { if(key == null) throw new IllegalArgumentException("Null keys not allowed."); if(value == null) throw new IllegalArgumentException("Null values not allowed."); List<String> vals = map.get(key); if(vals == null) { vals = new ArrayList<String>(); map.put(key,vals); } vals.add(value); }
Add a value for the supplied key. This will add the value to any existing values stored for this key. @param key the key @param value The value
public MultiMap merge(MultiMap multiMap) { MultiMap result = new MultiMap(); result.map.putAll(this.map); result.map.putAll(multiMap.map); return result; }
Merge the values in the specified map with the values in this map and return the results in a new map. @param multiMap The map to merge @return A new map containing the merged values
@Override protected int compare(Double o1, Double o2) { /* * Convert to IEEE and compare as unsigned */ long x = Double.doubleToLongBits(o1) ^ Long.MIN_VALUE; long y = Double.doubleToLongBits(o2) ^ Long.MIN_VALUE; return (x < y) ? -1 : ((x == y) ? 0 : 1); }
{@inheritDoc}
@Override protected int msd(Double a, Double b) { /* * For this to work, arithmetic must be unsigned */ long ux = Double.doubleToLongBits(a); long uy = Double.doubleToLongBits(b); if (ux == uy) { return -1; } double d = UnsignedUtils.unsignedLongToDouble(ux ^ uy); return Math.getExponent(d); }
{@inheritDoc}
@Override public void release() { super.release(); setBase64Expr(null); setActionExpr(null); setModuleExpr(null); setAlignExpr(null); setAltExpr(null); setAltKeyExpr(null); setBorderExpr(null); setBundleExpr(null); setDirExpr(null); setHeightExpr(null); setHspaceExpr(null); setImageNameExpr(null); setIsmapExpr(null); setLangExpr(null); setLocaleExpr(null); setNameExpr(null); setOnclickExpr(null); setOndblclickExpr(null); setOnkeydownExpr(null); setOnkeypressExpr(null); setOnkeyupExpr(null); setOnmousedownExpr(null); setOnmousemoveExpr(null); setOnmouseoutExpr(null); setOnmouseoverExpr(null); setOnmouseupExpr(null); setPageExpr(null); setPageKeyExpr(null); setParamIdExpr(null); setParamNameExpr(null); setParamPropertyExpr(null); setParamScopeExpr(null); setPropertyExpr(null); setScopeExpr(null); setSrcExpr(null); setSrcKeyExpr(null); setStyleExpr(null); setStyleClassExpr(null); setStyleIdExpr(null); setTitleExpr(null); setTitleKeyExpr(null); setUseLocalEncodingExpr(null); setUsemapExpr(null); setVspaceExpr(null); setWidthExpr(null); }
Resets attribute values for tag reuse.
private void evaluateExpressions() throws JspException { String string = null; Boolean bool = null; if (getBase64Expr() != null && (bool = EvalHelper.evalBoolean("base64", getBase64Expr(), this, pageContext)) != null) { setBase64(bool); } if (getAlignExpr() != null && (string = EvalHelper.evalString("align", getAlignExpr(), this, pageContext)) != null) { setAlign(string); } if (getAltExpr() != null && (string = EvalHelper.evalString("alt", getAltExpr(), this, pageContext)) != null) { setAlt(string); } if (getBorderExpr() != null && (string = EvalHelper.evalString("border", getBorderExpr(), this, pageContext)) != null) { setBorder(string); } if (getDirExpr() != null && (string = EvalHelper.evalString("dir", getDirExpr(), this, pageContext)) != null) { setDir(string); } if (getHeightExpr() != null && (string = EvalHelper.evalString("height", getHeightExpr(), this, pageContext)) != null) { setHeight(string); } if (getHspaceExpr() != null && (string = EvalHelper.evalString("hspace", getHspaceExpr(), this, pageContext)) != null) { setHspace(string); } if (getNameExpr() != null && (string = EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) { setName(string); } if (getIsmapExpr() != null && (string = EvalHelper.evalString("ismap", getIsmapExpr(), this, pageContext)) != null) { setIsmap(string); } if (getLangExpr() != null && (string = EvalHelper.evalString("lang", getLangExpr(), this, pageContext)) != null) { setLang(string); } if (getNameExpr() != null && (string = EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) { setName(string); } if (getOnclickExpr() != null && (string = EvalHelper.evalString("onclick", getOnclickExpr(), this, pageContext)) != null) { setOnclick(string); } if (getOndblclickExpr() != null && (string = EvalHelper.evalString("ondblclick", getOndblclickExpr(), this, pageContext)) != null) { setOndblclick(string); } if (getOnkeydownExpr() != null && (string = EvalHelper.evalString("onkeydown", getOnkeydownExpr(), this, pageContext)) != null) { setOnkeydown(string); } if (getOnkeypressExpr() != null && (string = EvalHelper.evalString("onkeypress", getOnkeypressExpr(), this, pageContext)) != null) { setOnkeypress(string); } if (getOnkeyupExpr() != null && (string = EvalHelper.evalString("onkeyup", getOnkeyupExpr(), this, pageContext)) != null) { setOnkeyup(string); } if (getOnmousedownExpr() != null && (string = EvalHelper.evalString("onmousedown", getOnmousedownExpr(), this, pageContext)) != null) { setOnmousedown(string); } if (getOnmousemoveExpr() != null && (string = EvalHelper.evalString("onmousemove", getOnmousemoveExpr(), this, pageContext)) != null) { setOnmousemove(string); } if (getOnmouseoutExpr() != null && (string = EvalHelper.evalString("onmouseout", getOnmouseoutExpr(), this, pageContext)) != null) { setOnmouseout(string); } if (getOnmouseoverExpr() != null && (string = EvalHelper.evalString("onmouseover", getOnmouseoverExpr(), this, pageContext)) != null) { setOnmouseover(string); } if (getOnmouseupExpr() != null && (string = EvalHelper.evalString("onmouseup", getOnmouseupExpr(), this, pageContext)) != null) { setOnmouseup(string); } if (getSrcExpr() != null && (string = EvalHelper.evalString("src", getSrcExpr(), this, pageContext)) != null) { setSrc(string); } if (getStyleExpr() != null && (string = EvalHelper.evalString("style", getStyleExpr(), this, pageContext)) != null) { setStyle(string); } if (getStyleClassExpr() != null && (string = EvalHelper.evalString("styleClass", getStyleClassExpr(), this, pageContext)) != null) { setStyleClass(string); } if (getStyleIdExpr() != null && (string = EvalHelper.evalString("styleId", getStyleIdExpr(), this, pageContext)) != null) { setStyleId(string); } if (getTitleExpr() != null && (string = EvalHelper.evalString("title", getTitleExpr(), this, pageContext)) != null) { setTitle(string); } if (getUsemapExpr() != null && (string = EvalHelper.evalString("usemap", getUsemapExpr(), this, pageContext)) != null) { setUsemap(string); } if (getVspaceExpr() != null && (string = EvalHelper.evalString("vspace", getVspaceExpr(), this, pageContext)) != null) { setVspace(string); } if (getWidthExpr() != null && (string = EvalHelper.evalString("width", getWidthExpr(), this, pageContext)) != null) { setWidth(string); } }
Processes all attribute values which use the JSTL expression evaluation engine to determine their values. @throws JspException if a JSP exception has occurred
@Override protected int compare(Double o1, Double o2) { /* * Convert to IEEE and compare as unsigned */ long x = Double.doubleToLongBits(o1) ^ Long.MIN_VALUE; long y = Double.doubleToLongBits(o2) ^ Long.MIN_VALUE; // assert if (o1.doubleValue() < o2.doubleValue()) { assert x < y; } else if (o1.doubleValue() == o2.doubleValue()) { assert x == y; } else { assert x > y; } return (x < y) ? -1 : ((x == y) ? 0 : 1); }
{@inheritDoc}
public RequestBuilder<T,ID> addParameter(String name,String value) { parameters.add(name, value); return this; }
Add a parameter to the request. Adds this value to any existing values for this name. @param name The name of the parameter @param value The value @return The request builder
public RequestBuilder<T,ID> setParameter(String name,String value) { parameters.set(name, value); return this; }
Set a parameter on the request. Replaces any existing values for the name. @param name The name of the parameter @param value The value @return The request builder
public RequestBuilder<T,ID> addHeader(String name,String value) { headers.add(name, value); return this; }
Add a header to the request. Adds this value to any existing values for this name. @param name The name of the header @param value The value @return The request builder
public Request<T> build() { MultiMap headers = resolveHeaders(); MultiMap parameters = resolveParameters(); parameters.add("version",Integer.toString(version)); Request<T> request = new Request<T>(); request.setEntityName(entityName); request.setEntityType(objectType); request.setHeaders(headers); request.setParameters(parameters); return request; }
Build the request @return The request
protected MultiMap resolveHeaders() { MultiMap resolved = null; if(headerFactory != null) resolved = headerFactory.getHeaders(); if(resolved != null) resolved = resolved.merge(headers); else resolved = headers; return resolved; }
Combine any locally defined headers with any headers from the header factory @return The headers to use for this request
protected MultiMap resolveParameters() { MultiMap resolved = null; if(parameterFactory != null) resolved = parameterFactory.getParameters(); if(resolved != null) resolved = resolved.merge(parameters); else resolved = parameters; return resolved; }
Combine any locally defined parameters with any parameters from the parameter factory @return The parameters to use for this request
protected String join(Object[] values) { StringBuilder sb = new StringBuilder(100); if(values.length == 0) return sb.toString(); sb.append(values[0]); if(values.length == 1) return sb.toString(); for (int i = 1; i < values.length; i++) { sb.append(",").append(values[i]); } return sb.toString(); }
Joing the values together in a comma separated list @param values The values to join @return The combined values
protected String join(List<String> values) { StringBuilder sb = new StringBuilder(100); if(values.size() == 0) return sb.toString(); sb.append(values.get(0)); if(values.size() == 1) return sb.toString(); for (int i = 1; i < values.size(); i++) { sb.append(",").append(values.get(i)); } return sb.toString(); }
Joing the values together in a comma separated list @param values The values to join @return The combined values
@Override public Set<String> getResourceNames(String path) { return ((WebJarsLocatorPathResolver)resolver).getResourceNames(path); }
/* (non-Javadoc) @see net.jawr.web.resource.bundle.generator.classpath.ClasspathJSGenerator#getResourceNames(java.lang.String)
@Override @ConstantTime(amortized = true) public AddressableHeap.Handle<K, V> insert(K key, V value) { if (other != this) { throw new IllegalStateException("A heap cannot be used after a meld"); } if (key == null) { throw new NullPointerException("Null keys not permitted"); } Node<K, V> n = new Node<K, V>(this, key, value); addToRootList(n); size++; return n; }
{@inheritDoc} @throws IllegalStateException if the heap has already been used in the right hand side of a meld
@Override @LogarithmicTime(amortized = true) public AddressableHeap.Handle<K, V> deleteMin() { if (size == 0) { throw new NoSuchElementException(); } Node<K, V> z = minRoot; // move z children into root list Node<K, V> x = z.child; while (x != null) { Node<K, V> nextX = (x.next == x) ? null : x.next; // clear parent x.parent = null; // remove from child list x.prev.next = x.next; x.next.prev = x.prev; // add to root list x.next = minRoot.next; x.prev = minRoot; minRoot.next = x; x.next.prev = x; roots++; // advance x = nextX; } z.degree = 0; z.child = null; // remove z from root list z.prev.next = z.next; z.next.prev = z.prev; roots--; // decrease size size--; // update minimum root if (z == z.next) { minRoot = null; } else { minRoot = z.next; consolidate(); } // clear other fields z.next = null; z.prev = null; return z; }
{@inheritDoc}
@Override @ConstantTime(amortized = true) @SuppressWarnings("unchecked") public void meld(MergeableAddressableHeap<K, V> other) { FibonacciHeap<K, V> h = (FibonacciHeap<K, V>) other; // check same comparator if (comparator != null) { if (h.comparator == null || !h.comparator.equals(comparator)) { throw new IllegalArgumentException("Cannot meld heaps using different comparators!"); } } else if (h.comparator != null) { throw new IllegalArgumentException("Cannot meld heaps using different comparators!"); } if (h.other != h) { throw new IllegalStateException("A heap cannot be used after a meld."); } if (size == 0) { // copy the other minRoot = h.minRoot; } else if (h.size != 0) { // concatenate root lists Node<K, V> h11 = minRoot; Node<K, V> h12 = h11.next; Node<K, V> h21 = h.minRoot; Node<K, V> h22 = h21.next; h11.next = h22; h22.prev = h11; h21.next = h12; h12.prev = h21; // find new minimum if ((comparator == null && ((Comparable<? super K>) h.minRoot.key).compareTo(minRoot.key) < 0) || (comparator != null && comparator.compare(h.minRoot.key, minRoot.key) < 0)) { minRoot = h.minRoot; } } roots += h.roots; size += h.size; // clear other h.size = 0; h.minRoot = null; h.roots = 0; // take ownership h.other = this; }
{@inheritDoc}
@SuppressWarnings("unchecked") private void decreaseKey(Node<K, V> n, K newKey) { int c = ((Comparable<? super K>) newKey).compareTo(n.key); if (c > 0) { throw new IllegalArgumentException("Keys can only be decreased!"); } n.key = newKey; if (c == 0) { return; } if (n.next == null) { throw new IllegalArgumentException("Invalid handle!"); } // if not root and heap order violation Node<K, V> y = n.parent; if (y != null && ((Comparable<? super K>) n.key).compareTo(y.key) < 0) { cut(n, y); cascadingCut(y); } // update minimum root if (((Comparable<? super K>) n.key).compareTo(minRoot.key) < 0) { minRoot = n; } }
/* Decrease the key of a node.
private void decreaseKeyWithComparator(Node<K, V> n, K newKey) { int c = comparator.compare(newKey, n.key); if (c > 0) { throw new IllegalArgumentException("Keys can only be decreased!"); } n.key = newKey; if (c == 0) { return; } if (n.next == null) { throw new IllegalArgumentException("Invalid handle!"); } // if not root and heap order violation Node<K, V> y = n.parent; if (y != null && comparator.compare(n.key, y.key) < 0) { cut(n, y); cascadingCut(y); } // update minimum root if (comparator.compare(n.key, minRoot.key) < 0) { minRoot = n; } }
/* Decrease the key of a node.
private void forceDecreaseKeyToMinimum(Node<K, V> n) { // if not root Node<K, V> y = n.parent; if (y != null) { cut(n, y); cascadingCut(y); } minRoot = n; }
/* Decrease the key of a node to the minimum. Helper function for performing a delete operation. Does not change the node's actual key, but behaves as the key is the minimum key in the heap.
@SuppressWarnings("unchecked") private void consolidate() { int maxDegree = -1; // for each node in root list int numRoots = roots; Node<K, V> x = minRoot; while (numRoots > 0) { Node<K, V> nextX = x.next; int d = x.degree; while (true) { Node<K, V> y = aux[d]; if (y == null) { break; } // make sure x's key is smaller int c; if (comparator == null) { c = ((Comparable<? super K>) y.key).compareTo(x.key); } else { c = comparator.compare(y.key, x.key); } if (c < 0) { Node<K, V> tmp = x; x = y; y = tmp; } // make y a child of x link(y, x); aux[d] = null; d++; } // store result aux[d] = x; // keep track of max degree if (d > maxDegree) { maxDegree = d; } // advance x = nextX; numRoots--; } // recreate root list and find minimum root minRoot = null; roots = 0; for (int i = 0; i <= maxDegree; i++) { if (aux[i] != null) { addToRootList(aux[i]); aux[i] = null; } } }
/* Consolidate: Make sure each root tree has a distinct degree.
private void link(Node<K, V> y, Node<K, V> x) { // remove from root list y.prev.next = y.next; y.next.prev = y.prev; // one less root roots--; // clear if marked y.mark = false; // hang as x's child x.degree++; y.parent = x; Node<K, V> child = x.child; if (child == null) { x.child = y; y.next = y; y.prev = y; } else { y.prev = child; y.next = child.next; child.next = y; y.next.prev = y; } }
/* Remove node y from the root list and make it a child of x. Degree of x increases by 1 and y is unmarked if marked.
private void cut(Node<K, V> x, Node<K, V> y) { // remove x from child list of y x.prev.next = x.next; x.next.prev = x.prev; y.degree--; if (y.degree == 0) { y.child = null; } else if (y.child == x) { y.child = x.next; } // add x to the root list x.parent = null; addToRootList(x); // clear if marked x.mark = false; }
/* Cut the link between x and its parent y making x a root.
private void cascadingCut(Node<K, V> y) { Node<K, V> z; while ((z = y.parent) != null) { if (!y.mark) { y.mark = true; break; } cut(y, z); y = z; } }
/* Cascading cut until a root or an unmarked node is found.
@SuppressWarnings("unchecked") private void addToRootList(Node<K, V> n) { if (minRoot == null) { n.next = n; n.prev = n; minRoot = n; roots = 1; } else { n.next = minRoot.next; n.prev = minRoot; minRoot.next.prev = n; minRoot.next = n; int c; if (comparator == null) { c = ((Comparable<? super K>) n.key).compareTo(minRoot.key); } else { c = comparator.compare(n.key, minRoot.key); } if (c < 0) { minRoot = n; } roots++; } }
/* Add a node to the root list and update the minimum.
@Override public InputStream createResourceAsStream(GeneratorContext context) { String path = context.getPath(); return rd.getResourceAsStream(path); }
/* (non-Javadoc) @see net.jawr.web.resource.bundle.generator.StreamResourceGenerator# createResourceAsStream (net.jawr.web.resource.bundle.generator.GeneratorContext)
private OWLClass getOWLClass(Object id) { // Special cases top and bottom if(NamedConcept.TOP.equals(id)) { return owlFactory.getOWLThing(); } else if(NamedConcept.BOTTOM.equals(id)) { return owlFactory.getOWLNothing(); } else { String iri = (String)id; return owlFactory.getOWLClass(IRI.create(iri)); } }
Returns the {@link OWLClass} for the corresponding internal object representation. @param c @return
private Object getId(OWLClass oc) { if(oc.isAnonymous()) return null; String id = oc.toStringID(); if(id.equals("<"+OWLImporter.THING_IRI+">") || id.equals(OWLImporter.THING_IRI)) { return NamedConcept.TOP; } else if(id.equals("<"+OWLImporter.NOTHING_IRI+">") || id.equals(OWLImporter.NOTHING_IRI)) { return NamedConcept.BOTTOM; } else { return id; } }
Returns the identifier for an {@link OWLClass}. If the owl class is anonymous then it returns null. @param oc @return
private au.csiro.ontology.Node getNode(OWLClass oc) { final Object id = getId(oc); final au.csiro.ontology.Node n; if(id instanceof String) { n = getTaxonomy().getNode((String)id); } else if(NamedConcept.TOP.equals(id)) { n = getTaxonomy().getTopNode(); } else if(NamedConcept.BOTTOM.equals(id)) { n = getTaxonomy().getBottomNode(); } else { throw new RuntimeException("Unexpected id "+id); } return n; }
Returns the {@link au.csiro.ontology.Node} for an {@link OWLClass}. If the owl class is anonymous then it throws a {@link RuntimeException}. @param oc @return
private Node<OWLClass> nodeToOwlClassNode(au.csiro.ontology.Node n) { if(n == null) return new OWLClassNode(); final Set<OWLClass> classes = new HashSet<>(); for (Object eq : n.getEquivalentConcepts()) { classes.add(getOWLClass(eq)); } return new OWLClassNode(classes); }
Transforms a {@link ClassNode} into a {@link Node} of {@link OWLClass}es. @param n may be null, in which case an empty Node is returned @return
private NodeSet<OWLClass> nodesToOwlClassNodeSet(Set<au.csiro.ontology.Node> nodes) { Set<Node<OWLClass>> temp = new HashSet<Node<OWLClass>>(); for (au.csiro.ontology.Node n : nodes) { temp.add(nodeToOwlClassNode(n)); } return new OWLClassNodeSet(temp); }
Transforms a set of {@link ClassNode}s into a {@link NodeSet}. @param nodes @return
private void classify() { // Classify monitor.taskStarted("Classifying"); monitor.taskBusy(); reasoner = reasoner.classify(); monitor.taskEnded(); monitor.taskStarted("Building taxonomy"); monitor.taskBusy(); taxonomy = reasoner.getClassifiedOntology(); monitor.taskEnded(); }
Performs a full classification on the current ontology.
@Override public void flush() { if (rawChanges.isEmpty() || !buffering) { return; } // Get the changed axioms boolean hasRemoveAxiom = false; List<OWLAxiom> newAxioms = new ArrayList<OWLAxiom>(); for (OWLOntologyChange change : rawChanges) { OWLAxiom axiom = change.getAxiom(); if(axiom instanceof RemoveAxiom) { hasRemoveAxiom = true; break; } newAxioms.add(axiom); } if(hasRemoveAxiom) { rawChanges.clear(); classify(); return; } // Transform the axioms into the canonical model Set<Axiom> canAxioms = getAxioms(newAxioms); // Classify monitor.taskStarted("Classifying incrementally"); monitor.taskBusy(); reasoner.loadAxioms(canAxioms); reasoner = reasoner.classify(); monitor.taskEnded(); monitor.taskStarted("Calculating taxonomy incrementally"); monitor.taskBusy(); taxonomy = reasoner.getClassifiedOntology(); monitor.taskEnded(); rawChanges.clear(); }
Classifies the ontology incrementally if no import changes have occurred. Flushes any changes stored in the buffer, which causes the reasoner to take into consideration the changes the current root ontology specified by the changes. If the reasoner buffering mode is {@link org.semanticweb.owlapi.reasoner.BufferingMode#NON_BUFFERING} then this method will have no effect.
@Override public Set<OWLAxiom> getPendingAxiomAdditions() { Set<OWLAxiom> added = new HashSet<OWLAxiom>(); for (OWLOntologyChange change : rawChanges) { if (change instanceof AddAxiom) { added.add(change.getAxiom()); } } return added; }
Gets the axioms that as a result of ontology changes need to be added to the reasoner to synchronise it with the root ontology imports closure. If the buffering mode is {@link org.semanticweb.owlapi.reasoner.BufferingMode#NON_BUFFERING} then there will be no pending axiom additions. @return The set of axioms that need to added to the reasoner to the reasoner to synchronise it with the root ontology imports closure.
@Override public Set<OWLAxiom> getPendingAxiomRemovals() { Set<OWLAxiom> removed = new HashSet<OWLAxiom>(); for (OWLOntologyChange change : rawChanges) { if (change instanceof RemoveAxiom) { removed.add(change.getAxiom()); } } return removed; }
Gets the axioms that as a result of ontology changes need to removed to the reasoner to synchronise it with the root ontology imports closure. If the buffering mode is {@link org.semanticweb.owlapi.reasoner.BufferingMode#NON_BUFFERING} then there will be no pending axiom additions. @return The set of axioms that need to added to the reasoner to the reasoner to synchronise it with the root ontology imports closure.
@Override public void precomputeInferences(InferenceType... inferenceTypes) throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException { for (InferenceType inferenceType : inferenceTypes) { if (inferenceType.equals(InferenceType.CLASS_HIERARCHY)) { classify(); } } }
Asks the reasoner to precompute certain types of inferences. Note that it is NOT necessary to call this method before asking any other queries - the reasoner will answer all queries correctly regardless of whether inferences are precomputed or not. For example, if the imports closure of the root ontology entails <code>SubClassOf(A B)</code> then the result of <code>getSubClasses(B)</code> will contain <code>A</code>, regardless of whether <code>precomputeInferences({@link InferenceType#CLASS_HIERARCHY})</code> has been called. <p> If the reasoner does not support the precomputation of a particular type of inference then it will silently ignore the request. @param inferenceTypes Suggests a list of the types of inferences that should be precomputed. If the list is empty then the reasoner will determine which types of inferences are precomputed. Note that the order of the list is unimportant - the reasoner will determine the order in which inferences are computed. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public boolean isPrecomputed(InferenceType inferenceType) { if (inferenceType.equals(InferenceType.CLASS_HIERARCHY)) { return reasoner.isClassified(); } else { return false; } }
Determines if a specific set of inferences have been precomputed. @param inferenceType The type of inference to check for. @return <code>true</code> if the specified type of inferences have been precomputed, otherwise <code>false</code>.
@Override public boolean isConsistent() throws ReasonerInterruptedException, TimeOutException { au.csiro.ontology.Node bottom = getTaxonomy().getBottomNode(); return bottom.getEquivalentConcepts().isEmpty(); }
Inconsistent Ontology - this occurs when the axioms in an ontology contain a contradiction which prevents the ontology from having a model, e.g., when the ontology asserts that an individual belongs to an unsatisfiable concept. Determines if the set of reasoner axioms is consistent. Note that this method will NOT throw an {@link org.semanticweb.owlapi.reasoner.InconsistentOntologyException} even if the root ontology imports closure is inconsistent. @return <code>true</code> if the imports closure of the root ontology is consistent, or <code>false</code> if the imports closure of the root ontology is inconsistent. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process). @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public boolean isSatisfiable(OWLClassExpression classExpression) throws ReasonerInterruptedException, TimeOutException, ClassExpressionNotInProfileException, FreshEntitiesException, InconsistentOntologyException { if (classExpression.isAnonymous()) { return false; } else { // If the node that contains OWLNothing contains this OWLClass then // it is not satisfiable Object id = getId(classExpression.asOWLClass()); au.csiro.ontology.Node bottom = getTaxonomy().getBottomNode(); return !bottom.getEquivalentConcepts().contains(id); } }
A convenience method that determines if the specified class expression is satisfiable with respect to the reasoner axioms. @param classExpression The class expression @return <code>true</code> if classExpression is satisfiable with respect to the set of axioms, or <code>false</code> if classExpression is unsatisfiable with respect to the axioms. @throws InconsistentOntologyException if the set of reasoner axioms is inconsistent @throws ClassExpressionNotInProfileException if <code>classExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of the classExpression is not contained within the signature of the set of reasoner axioms. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public Node<OWLClass> getUnsatisfiableClasses() throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException { return nodeToOwlClassNode(getTaxonomy().getBottomNode()); }
A convenience method that obtains the classes in the signature of the root ontology that are unsatisfiable. @return A <code>Node</code> that is the bottom node in the class hierarchy. This node represents <code>owl:Nothing</code> and contains <code>owl:Nothing</code> itself plus classes that are equivalent to <code>owl:Nothing</code>. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}. @throws InconsistentOntologyException if the set of reasoner axioms is inconsistent
@Override public boolean isEntailed(Set<? extends OWLAxiom> axioms) throws ReasonerInterruptedException, UnsupportedEntailmentTypeException, TimeOutException, AxiomNotInProfileException, FreshEntitiesException, InconsistentOntologyException { throw new UnsupportedEntailmentTypeException(axioms.iterator().next()); }
Determines if the specified set of axioms is entailed by the reasoner axioms. @param axioms The set of axioms to be tested @return <code>true</code> if the set of axioms is entailed by the axioms in the imports closure of the root ontology, otherwise <code>false</code>. If the set of reasoner axioms is inconsistent then <code>true</code>. @throws FreshEntitiesException if the signature of the set of axioms is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}. @throws UnsupportedEntailmentTypeException if the reasoner cannot perform a check to see if the specified axiom is entailed @throws AxiomNotInProfileException if <code>axiom</code> is not in the profile that is supported by this reasoner. @throws InconsistentOntologyException if the set of reasoner axioms is inconsistent @see #isEntailmentCheckingSupported(org.semanticweb.owlapi.model.AxiomType)
@Override public Node<OWLClass> getTopClassNode() { au.csiro.ontology.Node top = getTaxonomy().getTopNode(); return nodeToOwlClassNode(top); }
Gets the <code>Node</code> corresponding to the top node (containing <code>owl:Thing</code>) in the class hierarchy. @return A <code>Node</code> containing <code>owl:Thing</code> that is the top node in the class hierarchy. This <code>Node</code> is essentially equal to the <code>Node</code> returned by calling {@link #getEquivalentClasses(org.semanticweb.owlapi.model.OWLClassExpression)} with a parameter of <code>owl:Thing</code>.
@Override public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { checkOntologyConsistent(); checkNamedClass(ce); au.csiro.ontology.Node n = getNode(ce.asOWLClass()); if(n == null) { // TODO: add logging and warn! return new OWLClassNodeSet(); } Set<au.csiro.ontology.Node> children = n.getChildren(); if (direct) { // Transform the response back into owlapi objects return nodesToOwlClassNodeSet(children); } else { Set<au.csiro.ontology.Node> res = new HashSet<au.csiro.ontology.Node>(); Queue<Set<au.csiro.ontology.Node>> todo = new LinkedList<Set<au.csiro.ontology.Node>>(); todo.add(children); while (!todo.isEmpty()) { Set<au.csiro.ontology.Node> items = todo.remove(); res.addAll(items); for (au.csiro.ontology.Node item : items) { Set<au.csiro.ontology.Node> cn = item.getChildren(); if (!cn.isEmpty()) todo.add(cn); } } return nodesToOwlClassNodeSet(res); } }
Gets the set of named classes that are the strict (potentially direct) subclasses of the specified class expression with respect to the reasoner axioms. Note that the classes are returned as a {@link NodeSet}. @param ce The class expression whose strict (direct) subclasses are to be retrieved. @param direct Specifies if the direct subclasses should be retrived ( <code>true</code>) or if the all subclasses (descendant) classes should be retrieved (<code>false</code>). @return If direct is <code>true</code>, a <code>NodeSet</code> such that for each class <code>C</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>DirectSubClassOf(C, ce)</code>. </p> If direct is <code>false</code>, a <code>NodeSet</code> such that for each class <code>C</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>StrictSubClassOf(C, ce)</code>. </p> If <code>ce</code> is equivalent to <code>owl:Nothing</code> then the empty <code>NodeSet</code> will be returned. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if <code>classExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of the classExpression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public Node<OWLClass> getEquivalentClasses(OWLClassExpression ce) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { checkOntologyConsistent(); checkNamedClass(ce); au.csiro.ontology.Node n = getNode(ce.asOWLClass()); return nodeToOwlClassNode(n); }
Gets the set of named classes that are equivalent to the specified class expression with respect to the set of reasoner axioms. The classes are returned as a {@link Node}. @param ce The class expression whose equivalent classes are to be retrieved. @return A node containing the named classes such that for each named class <code>C</code> in the node the root ontology imports closure entails <code>EquivalentClasses(ce C)</code>. If <code>ce</code> is not a class name (i.e. it is an anonymous class expression) and there are no such classes <code>C</code> then the node will be empty. </p> If <code>ce</code> is a named class then <code>ce</code> will be contained in the node. </p> If <code>ce</code> is unsatisfiable with respect to the set of reasoner axioms then the node representing and containing <code>owl:Nothing</code>, i.e. the bottom node, will be returned. </p> If <code>ce</code> is equivalent to <code>owl:Thing</code> with respect to the set of reasoner axioms then the node representing and containing <code>owl:Thing</code>, i.e. the top node, will be returned </p>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if <code>classExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of the classExpression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException { throw new ReasonerInternalException( "getDisjointClasses not implemented"); }
Gets the classes that are disjoint with the specified class expression <code>ce</code>. The classes are returned as a {@link NodeSet}. @param ce The class expression whose disjoint classes are to be retrieved. @return The return value is a <code>NodeSet</code> such that for each class <code>D</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>EquivalentClasses(D, ObjectComplementOf(ce))</code> or <code>StrictSubClassOf(D, ObjectComplementOf(ce))</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if <code>classExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of the classExpression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLObjectPropertyExpression> getSubObjectProperties( OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getSubObjectProperties not implemented"); }
Gets the set of <a href="#spe">simplified object property expressions</a> that are the strict (potentially direct) subproperties of the specified object property expression with respect to the imports closure of the root ontology. Note that the properties are returned as a {@link NodeSet}. @param pe The object property expression whose strict (direct) subproperties are to be retrieved. @param direct Specifies if the direct subproperties should be retrived ( <code>true</code>) or if the all subproperties (descendants) should be retrieved (<code>false</code>). @return If direct is <code>true</code>, a <code>NodeSet</code> of <a href="#spe">simplified object property expressions</a>, such that for each <a href="#spe">simplified object property expression</a>, <code>P</code>, in the <code>NodeSet</code> the set of reasoner axioms entails <code>DirectSubObjectPropertyOf(P, pe)</code>. </p> If direct is <code>false</code>, a <code>NodeSet</code> of <a href="#spe">simplified object property expressions</a>, such that for each <a href="#spe">simplified object property expression</a>, <code>P</code>, in the <code>NodeSet</code> the set of reasoner axioms entails <code>StrictSubObjectPropertyOf(P, pe)</code>. </p> If <code>pe</code> is equivalent to <code>owl:bottomObjectProperty</code> then the empty <code>NodeSet</code> will be returned. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the object property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public Node<OWLObjectPropertyExpression> getEquivalentObjectProperties( OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { return new OWLObjectPropertyNode(); }
Gets the set of <a href="#spe">simplified object property expressions</a> that are equivalent to the specified object property expression with respect to the set of reasoner axioms. The properties are returned as a {@link Node}. @param pe The object property expression whose equivalent properties are to be retrieved. @return A node containing the <a href="#spe">simplified object property expressions</a> such that for each <a href="#spe">simplified object property expression</a>, <code>P</code>, in the node, the set of reasoner axioms entails <code>EquivalentObjectProperties(pe P)</code>. </p> If <code>pe</code> is a <a href="#spe">simplified object property expression</a> then <code>pe</code> will be contained in the node. </p> If <code>pe</code> is unsatisfiable with respect to the set of reasoner axioms then the node representing and containing <code>owl:bottomObjectProperty</code>, i.e. the bottom node, will be returned. </p> If <code>pe</code> is equivalent to <code>owl:topObjectProperty</code> with respect to the set of reasoner axioms then the node representing and containing <code>owl:topObjectProperty</code>, i.e. the top node, will be returned </p>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the object property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties( OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getDisjointObjectProperties not implemented"); }
Gets the <a href="#spe">simplified object property expressions</a> that are disjoint with the specified object property expression <code>pe</code>. The object properties are returned as a {@link NodeSet}. @param pe The object property expression whose disjoint object properties are to be retrieved. @return The return value is a <code>NodeSet</code> of <a href="#spe">simplified object property expressions</a>, such that for each <a href="#spe">simplified object property expression</a>, <code>P</code>, in the <code>NodeSet</code> the set of reasoner axioms entails <code>EquivalentObjectProperties(P, ObjectPropertyComplementOf(pe))</code> or <code>StrictSubObjectPropertyOf(P, ObjectPropertyComplementOf(pe))</code> . @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if <code>object propertyExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of <code>pe</code> is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}.and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW} @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public Node<OWLObjectPropertyExpression> getInverseObjectProperties( OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getInverseObjectProperties not implemented"); }
Gets the set of <a href="#spe">simplified object property expressions</a> that are the inverses of the specified object property expression with respect to the imports closure of the root ontology. The properties are returned as a {@link NodeSet} @param pe The property expression whose inverse properties are to be retrieved. @return A <code>NodeSet</code> of <a href="#spe">simplified object property expressions</a>, such that for each simplified object property expression <code>P</code> in the nodes set, the set of reasoner axioms entails <code>InverseObjectProperties(pe, P)</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the object property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLClass> getObjectPropertyDomains( OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getObjectPropertyDomains not implemented"); }
Gets the named classes that are the direct or indirect domains of this property with respect to the imports closure of the root ontology. The classes are returned as a {@link NodeSet} . @param pe The property expression whose domains are to be retrieved. @param direct Specifies if the direct domains should be retrieved ( <code>true</code>), or if all domains should be retrieved ( <code>false</code>). @return Let <code>N = getEquivalentClasses(ObjectSomeValuesFrom(pe owl:Thing))</code> . <p> If <code>direct</code> is <code>true</code>: then if <code>N</code> is not empty then the return value is <code>N</code>, else the return value is the result of <code>getSuperClasses(ObjectSomeValuesFrom(pe owl:Thing), true)</code>. <p> If <code>direct</code> is <code>false</code>: then the result of <code>getSuperClasses(ObjectSomeValuesFrom(pe owl:Thing), false)</code> together with <code>N</code> if <code>N</code> is non-empty. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the object property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLDataProperty> getSubDataProperties(OWLDataProperty pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getSubDataProperties not implemented"); }
Gets the set of named data properties that are the strict (potentially direct) subproperties of the specified data property expression with respect to the imports closure of the root ontology. Note that the properties are returned as a {@link NodeSet}. @param pe The data property whose strict (direct) subproperties are to be retrieved. @param direct Specifies if the direct subproperties should be retrived ( <code>true</code>) or if the all subproperties (descendants) should be retrieved (<code>false</code>). @return If direct is <code>true</code>, a <code>NodeSet</code> such that for each property <code>P</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>DirectSubDataPropertyOf(P, pe)</code>. </p> If direct is <code>false</code>, a <code>NodeSet</code> such that for each property <code>P</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>StrictSubDataPropertyOf(P, pe)</code>. </p> If <code>pe</code> is equivalent to <code>owl:bottomDataProperty</code> then the empty <code>NodeSet</code> will be returned. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the data property is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public Node<OWLDataProperty> getEquivalentDataProperties(OWLDataProperty pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getEquivalentDataProperties not implemented"); }
Gets the set of named data properties that are equivalent to the specified data property expression with respect to the imports closure of the root ontology. The properties are returned as a {@link Node}. @param pe The data property expression whose equivalent properties are to be retrieved. @return A node containing the named data properties such that for each named data property <code>P</code> in the node, the set of reasoner axioms entails <code>EquivalentDataProperties(pe P)</code>. </p> If <code>pe</code> is a named data property then <code>pe</code> will be contained in the node. </p> If <code>pe</code> is unsatisfiable with respect to the set of reasoner axioms then the node representing and containing <code>owl:bottomDataProperty</code>, i.e. the bottom node, will be returned. </p> If <code>ce</code> is equivalent to <code>owl:topDataProperty</code> with respect to the set of reasoner axioms then the node representing and containing <code>owl:topDataProperty</code>, i.e. the top node, will be returned </p>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the data property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLDataProperty> getDisjointDataProperties( OWLDataPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getDisjointDataProperties not implemented"); }
Gets the data properties that are disjoint with the specified data property expression <code>pe</code>. The data properties are returned as a {@link NodeSet}. @param pe The data property expression whose disjoint data properties are to be retrieved. @return The return value is a <code>NodeSet</code> such that for each data property <code>P</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>EquivalentDataProperties(P, DataPropertyComplementOf(pe))</code> or <code>StrictSubDataPropertyOf(P, DataPropertyComplementOf(pe))</code> . @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if <code>data propertyExpression</code> is not within the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of <code>pe</code> is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getDataPropertyDomains not implemented"); }
Gets the named classes that are the direct or indirect domains of this property with respect to the imports closure of the root ontology. The classes are returned as a {@link NodeSet} . @param pe The property expression whose domains are to be retrieved. @param direct Specifies if the direct domains should be retrieved ( <code>true</code>), or if all domains should be retrieved ( <code>false</code>). @return Let <code>N = getEquivalentClasses(DataSomeValuesFrom(pe rdfs:Literal))</code> . <p> If <code>direct</code> is <code>true</code>: then if <code>N</code> is not empty then the return value is <code>N</code>, else the return value is the result of <code>getSuperClasses(DataSomeValuesFrom(pe rdfs:Literal), true)</code>. <p> If <code>direct</code> is <code>false</code>: then the result of <code>getSuperClasses(DataSomeValuesFrom(pe rdfs:Literal), false)</code> together with <code>N</code> if <code>N</code> is non-empty. <p> (Note, <code>rdfs:Literal</code> is the top datatype). @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the object property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLClass> getTypes(OWLNamedIndividual ind, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException("getTypes not implemented"); }
Gets the named classes which are (potentially direct) types of the specified named individual. The classes are returned as a {@link NodeSet}. @param ind The individual whose types are to be retrieved. @param direct Specifies if the direct types should be retrieved ( <code>true</code>), or if all types should be retrieved ( <code>false</code>). @return If <code>direct</code> is <code>true</code>, a <code>NodeSet</code> containing named classes such that for each named class <code>C</code> in the node set, the set of reasoner axioms entails <code>DirectClassAssertion(C, ind)</code>. </p> If <code>direct</code> is <code>false</code>, a <code>NodeSet</code> containing named classes such that for each named class <code>C</code> in the node set, the set of reasoner axioms entails <code>ClassAssertion(C, ind)</code>. </p> @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the individual is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce, boolean direct) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { return new OWLNamedIndividualNodeSet(); }
Gets the individuals which are instances of the specified class expression. The individuals are returned a a {@link NodeSet}. @param ce The class expression whose instances are to be retrieved. @param direct Specifies if the direct instances should be retrieved ( <code>true</code>), or if all instances should be retrieved ( <code>false</code>). @return If <code>direct</code> is <code>true</code>, a <code>NodeSet</code> containing named individuals such that for each named individual <code>j</code> in the node set, the set of reasoner axioms entails <code>DirectClassAssertion(ce, j)</code>. </p> If <code>direct</code> is <code>false</code>, a <code>NodeSet</code> containing named individuals such that for each named individual <code>j</code> in the node set, the set of reasoner axioms entails <code>ClassAssertion(ce, j)</code>. </p> </p> If ce is unsatisfiable with respect to the set of reasoner axioms then the empty <code>NodeSet</code> is returned. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws ClassExpressionNotInProfileException if the class expression <code>ce</code> is not in the profile that is supported by this reasoner. @throws FreshEntitiesException if the signature of the class expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}. @see {@link org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy}
@Override public NodeSet<OWLNamedIndividual> getObjectPropertyValues( OWLNamedIndividual ind, OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getObjectPropertyValues not implemented"); }
Gets the object property values for the specified individual and object property expression. The individuals are returned as a {@link NodeSet}. @param ind The individual that is the subject of the object property values @param pe The object property expression whose values are to be retrieved for the specified individual @return A <code>NodeSet</code> containing named individuals such that for each individual <code>j</code> in the node set, the set of reasoner axioms entails <code>ObjectPropertyAssertion(pe ind j)</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the individual and property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}. @see {@link org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy}
@Override public Set<OWLLiteral> getDataPropertyValues(OWLNamedIndividual ind, OWLDataProperty pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { return Collections.emptySet(); }
Gets the data property values for the specified individual and data property expression. The values are a set of literals. Note that the results are not guaranteed to be complete for this method. The reasoner may also return canonical literals or they may be in a form that bears a resemblance to the syntax of the literals in the root ontology imports closure. @param ind The individual that is the subject of the data property values @param pe The data property expression whose values are to be retrieved for the specified individual @return A set of <code>OWLLiteral</code>s containing literals such that for each literal <code>l</code> in the set, the set of reasoner axioms entails <code>DataPropertyAssertion(pe ind l)</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the individual and property expression is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}. @see {@link org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy}
@Override public Node<OWLNamedIndividual> getSameIndividuals(OWLNamedIndividual ind) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getSameIndividuals not implemented"); }
Gets the individuals that are the same as the specified individual. @param ind The individual whose same individuals are to be retrieved. @return A node containing individuals such that for each individual <code>j</code> in the node, the root ontology imports closure entails <code>SameIndividual(j, ind)</code>. Note that the node will contain <code>j</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the individual is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public NodeSet<OWLNamedIndividual> getDifferentIndividuals( OWLNamedIndividual ind) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { throw new ReasonerInternalException( "getDifferentIndividuals not implemented"); }
Gets the individuals which are entailed to be different from the specified individual. The individuals are returned as a {@link NodeSet}. @param ind The individual whose different individuals are to be returned. @return A <code>NodeSet</code> containing <code>OWLNamedIndividual</code> s such that for each individual <code>i</code> in the <code>NodeSet</code> the set of reasoner axioms entails <code>DifferentIndividuals(ind, i)</code>. @throws InconsistentOntologyException if the imports closure of the root ontology is inconsistent @throws FreshEntitiesException if the signature of the individual is not contained within the signature of the imports closure of the root ontology and the undeclared entity policy of this reasoner is set to {@link FreshEntityPolicy#DISALLOW}. @throws ReasonerInterruptedException if the reasoning process was interrupted for any particular reason (for example if reasoning was cancelled by a client process) @throws TimeOutException if the reasoner timed out during a basic reasoning operation. See {@link #getTimeOut()}.
@Override public void dispose() { owlOntology.getOWLOntologyManager().removeOntologyChangeListener( ontologyChangeListener); rawChanges.clear(); reasoner = new SnorocketReasoner(); }
Disposes of this reasoner. This frees up any resources used by the reasoner and detaches the reasoner as an {@link org.semanticweb.owlapi.model.OWLOntologyChangeListener} from the {@link org.semanticweb.owlapi.model.OWLOntologyManager} that manages the ontologies contained within the reasoner.
@Override public String resolveVariant(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); String skin = defaultSkin; if (cookies != null) { int nbCookies = cookies.length; for (int i = 0; i < nbCookies; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(skinCookieName)) { skin = cookie.getValue(); } } } LOGGER.debug("Resolved skin " + skin); return skin; }
/* (non-Javadoc) @see net.jawr.web.resource.bundle.variant.VariantResolver#resolveVariant(javax .servlet.http.HttpServletRequest)
@Override protected BundleRenderer createRenderer(FacesContext context) { ResourceBundlesHandler rsHandler = getResourceBundlesHandler(context); String media = (String) getAttributes().get(JawrConstant.MEDIA_ATTR); boolean alternate = Boolean.parseBoolean((String) getAttributes().get(JawrConstant.ALTERNATE_ATTR)); boolean displayAlternate = Boolean .parseBoolean((String) getAttributes().get(JawrConstant.DISPLAY_ALTERNATE_ATTR)); String title = (String) getAttributes().get(JawrConstant.TITLE_ATTR); return RendererFactory.getCssBundleRenderer(rsHandler, getUseRandomParamFlag(rsHandler.getConfig()), media, alternate, displayAlternate, title); }
/* (non-Javadoc) @see net.jawr.web.taglib.jsf.AbstractResourceBundleTag#createRenderer(javax. faces.context.FacesContext)
public static boolean methodBelongsTo(Method m, Method[] methods){ boolean result = false; for (int i = 0; i < methods.length && !result; i++) { if(methodEquals (methods [i], m)){ result = true; } } return result; }
Returns true if the method is in the method array. @param m the method @param methods the method array @return true if the method is in the method array.
public static boolean methodEquals( Method method, Method other){ if ((method.getDeclaringClass().equals( other.getDeclaringClass())) && (method.getName().equals( other.getName()))) { if (!method.getReturnType().equals(other.getReturnType())) return false; Class<?>[] params1 = method.getParameterTypes(); Class<?>[] params2 = other.getParameterTypes(); if (params1.length == params2.length) { for (int i = 0; i < params1.length; i++) { if (params1[i] != params2[i]) return false; } return true; } } return false; }
Checks if the 2 methods are equals. @param method the first method @param other the second method @return true if the 2 methods are equals
public List<T> execute(HyperionClient client) { EntityList<T> response = client.create(build()); return response.getEntries(); }
Execute the request using the supplied client @param client the client @return The request
@Override protected int compare(Integer o1, Integer o2) { if (o1 < o2) { return -1; } else if (o1 > o2) { return 1; } else { return 0; } }
{@inheritDoc}
@Override protected int msd(Integer a, Integer b) { /* * Value equal */ if (a.intValue() == b.intValue()) { return -1; } /* * This is a fast way to compute floor(log_2(a xor b)). */ float axorb = a ^ b; return Math.getExponent(axorb); }
{@inheritDoc}
@LinearTime public static <K> MinMaxBinaryArrayDoubleEndedHeap<K> heapify(K[] array) { if (array == null) { throw new IllegalArgumentException("Array cannot be null"); } if (array.length == 0) { return new MinMaxBinaryArrayDoubleEndedHeap<K>(); } MinMaxBinaryArrayDoubleEndedHeap<K> h = new MinMaxBinaryArrayDoubleEndedHeap<K>(array.length); System.arraycopy(array, 0, h.array, 1, array.length); h.size = array.length; for (int i = array.length / 2; i > 0; i--) { h.fixdown(i); } return h; }
Create a heap from an array of elements. The elements of the array are not destroyed. The method has linear time complexity. @param <K> the type of keys maintained by the heap @param array an array of elements @return a heap @throws IllegalArgumentException in case the array is null
@LinearTime public static <K> MinMaxBinaryArrayDoubleEndedHeap<K> heapify(K[] array, Comparator<? super K> comparator) { if (array == null) { throw new IllegalArgumentException("Array cannot be null"); } if (array.length == 0) { return new MinMaxBinaryArrayDoubleEndedHeap<K>(comparator); } MinMaxBinaryArrayDoubleEndedHeap<K> h = new MinMaxBinaryArrayDoubleEndedHeap<K>(comparator, array.length); System.arraycopy(array, 0, h.array, 1, array.length); h.size = array.length; for (int i = array.length / 2; i > 0; i--) { h.fixdownWithComparator(i); } return h; }
Create a heap from an array of elements. The elements of the array are not destroyed. The method has linear time complexity. @param <K> the type of keys maintained by the heap @param array an array of elements @param comparator the comparator to use @return a heap @throws IllegalArgumentException in case the array is null
@Override @SuppressWarnings("unchecked") public K findMax() { switch (size) { case 0: throw new NoSuchElementException(); case 1: return array[1]; case 2: return array[2]; default: if (comparator == null) { if (((Comparable<? super K>) array[3]).compareTo(array[2]) > 0) { return array[3]; } else { return array[2]; } } else { if (comparator.compare(array[3], array[2]) > 0) { return array[3]; } else { return array[2]; } } } }
{@inheritDoc}
@Override @SuppressWarnings("unchecked") public K deleteMax() { K result; switch (size) { case 0: throw new NoSuchElementException(); case 1: result = array[1]; array[1] = null; size--; break; case 2: result = array[2]; array[2] = null; size--; break; default: if (comparator == null) { if (((Comparable<? super K>) array[3]).compareTo(array[2]) > 0) { result = array[3]; array[3] = array[size]; array[size] = null; size--; if (size >= 3) { fixdownMax(3); } } else { result = array[2]; array[2] = array[size]; array[size] = null; size--; fixdownMax(2); } } else { if (comparator.compare(array[3], array[2]) > 0) { result = array[3]; array[3] = array[size]; array[size] = null; size--; if (size >= 3) { fixdownMaxWithComparator(3); } } else { result = array[2]; array[2] = array[size]; array[size] = null; size--; fixdownMaxWithComparator(2); } } break; } if (Constants.NOT_BENCHMARK) { if (2 * minCapacity < array.length - 1 && 4 * size < array.length - 1) { ensureCapacity((array.length - 1) / 2); } } return result; }
{@inheritDoc}
@Override @SuppressWarnings("unchecked") protected void fixup(int k) { if (onMinLevel(k)) { int p = k / 2; K kValue = array[k]; if (p > 0 && ((Comparable<? super K>) array[p]).compareTo(kValue) < 0) { array[k] = array[p]; array[p] = kValue; fixupMax(p); } else { fixupMin(k); } } else { int p = k / 2; K kValue = array[k]; if (p > 0 && ((Comparable<? super K>) kValue).compareTo(array[p]) < 0) { array[k] = array[p]; array[p] = kValue; fixupMin(p); } else { fixupMax(k); } } }
Upwards fix starting from a particular element @param k the index of the starting element
protected void fixupWithComparator(int k) { if (onMinLevel(k)) { int p = k / 2; K kValue = array[k]; if (p > 0 && comparator.compare(array[p], kValue) < 0) { array[k] = array[p]; array[p] = kValue; fixupMaxWithComparator(p); } else { fixupMinWithComparator(k); } } else { int p = k / 2; K kValue = array[k]; if (p > 0 && comparator.compare(kValue, array[p]) < 0) { array[k] = array[p]; array[p] = kValue; fixupMinWithComparator(p); } else { fixupMaxWithComparator(k); } } }
Upwards fix starting from a particular element @param k the index of the starting element
@SuppressWarnings("unchecked") private void fixupMin(int k) { K key = array[k]; int gp = k / 4; while (gp > 0 && ((Comparable<? super K>) array[gp]).compareTo(key) > 0) { array[k] = array[gp]; k = gp; gp = k / 4; } array[k] = key; }
Upwards fix starting from a particular element at a minimum level @param k the index of the starting element
private void fixupMinWithComparator(int k) { K key = array[k]; int gp = k / 4; while (gp > 0 && comparator.compare(array[gp], key) > 0) { array[k] = array[gp]; k = gp; gp = k / 4; } array[k] = key; }
Upwards fix starting from a particular element at a minimum level. Performs comparisons using the comparator. @param k the index of the starting element
private void fixupMaxWithComparator(int k) { K key = array[k]; int gp = k / 4; while (gp > 0 && comparator.compare(array[gp], key) < 0) { array[k] = array[gp]; k = gp; gp = k / 4; } array[k] = key; }
Upwards fix starting from a particular element at a maximum level. Performs comparisons using the comparator. @param k the index of the starting element
@SuppressWarnings("unchecked") private void fixdownMin(int k) { int c = 2 * k; while (c <= size) { int m = minChildOrGrandchild(k); if (m > c + 1) { // grandchild if (((Comparable<? super K>) array[m]).compareTo(array[k]) >= 0) { break; } K tmp = array[k]; array[k] = array[m]; array[m] = tmp; if (((Comparable<? super K>) array[m]).compareTo(array[m / 2]) > 0) { tmp = array[m]; array[m] = array[m / 2]; array[m / 2] = tmp; } // go down k = m; c = 2 * k; } else { // child if (((Comparable<? super K>) array[m]).compareTo(array[k]) < 0) { K tmp = array[k]; array[k] = array[m]; array[m] = tmp; } break; } } }
Downwards fix starting from a particular element at a minimum level. @param k the index of the starting element
private void fixdownMinWithComparator(int k) { int c = 2 * k; while (c <= size) { int m = minChildOrGrandchildWithComparator(k); if (m > c + 1) { // grandchild if (comparator.compare(array[m], array[k]) >= 0) { break; } K tmp = array[k]; array[k] = array[m]; array[m] = tmp; if (comparator.compare(array[m], array[m / 2]) > 0) { tmp = array[m]; array[m] = array[m / 2]; array[m / 2] = tmp; } // go down k = m; c = 2 * k; } else { // child if (comparator.compare(array[m], array[k]) < 0) { K tmp = array[k]; array[k] = array[m]; array[m] = tmp; } break; } } }
Downwards fix starting from a particular element at a minimum level. Performs comparisons using the comparator. @param k the index of the starting element
@SuppressWarnings("unchecked") private void fixdownMax(int k) { int c = 2 * k; while (c <= size) { int m = maxChildOrGrandchild(k); if (m > c + 1) { // grandchild if (((Comparable<? super K>) array[m]).compareTo(array[k]) <= 0) { break; } K tmp = array[k]; array[k] = array[m]; array[m] = tmp; if (((Comparable<? super K>) array[m]).compareTo(array[m / 2]) < 0) { tmp = array[m]; array[m] = array[m / 2]; array[m / 2] = tmp; } // go down k = m; c = 2 * k; } else { // child if (((Comparable<? super K>) array[m]).compareTo(array[k]) > 0) { K tmp = array[k]; array[k] = array[m]; array[m] = tmp; } break; } } }
Downwards fix starting from a particular element at a maximum level. @param k the index of the starting element
private void fixdownMaxWithComparator(int k) { int c = 2 * k; while (c <= size) { int m = maxChildOrGrandchildWithComparator(k); if (m > c + 1) { // grandchild if (comparator.compare(array[m], array[k]) <= 0) { break; } K tmp = array[k]; array[k] = array[m]; array[m] = tmp; if (comparator.compare(array[m], array[m / 2]) < 0) { tmp = array[m]; array[m] = array[m / 2]; array[m / 2] = tmp; } // go down k = m; c = 2 * k; } else { // child if (comparator.compare(array[m], array[k]) > 0) { K tmp = array[k]; array[k] = array[m]; array[m] = tmp; } break; } } }
Downwards fix starting from a particular element at a maximum level. Performs comparisons using the comparator. @param k the index of the starting element
@VisibleForTesting boolean onMinLevel(int k) { float kAsFloat = k; int exponent = Math.getExponent(kAsFloat); return exponent % 2 == 0; }
Return true if on a minimum level, false otherwise. @param k the element @return true if on a minimum level, false otherwise
@SuppressWarnings("unchecked") private int maxChildOrGrandchild(int k) { int gc = 4 * k; int maxgc; K gcValue; // 4 grandchilden if (gc + 3 <= size) { gcValue = array[gc]; maxgc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { maxgc = gc; } return maxgc; } // less or equal to 3 switch (size - gc) { case 2: // 3 grandchildren, two children gcValue = array[gc]; maxgc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { maxgc = gc; } return maxgc; case 1: // 2 grandchildren, maybe two children gcValue = array[gc]; maxgc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; case 0: // 1 grandchild, maybe two children gcValue = array[gc]; maxgc = gc; if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; } // 0 grandchildren maxgc = 2 * k; gcValue = array[maxgc]; if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; }
Given a node at a maximum level, find its child or grandchild with the maximum key. This method should not be called for a node which has no children. @param k a node at a maximum level @return the child or grandchild with a maximum key, or undefined if there are no children
private int maxChildOrGrandchildWithComparator(int k) { int gc = 4 * k; int maxgc; K gcValue; // 4 grandchilden if (gc + 3 <= size) { gcValue = array[gc]; maxgc = gc; if (comparator.compare(array[++gc], gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (comparator.compare(array[++gc], gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (comparator.compare(array[++gc], gcValue) > 0) { maxgc = gc; } return maxgc; } // less or equal to 3 switch (size - gc) { case 2: // 3 grandchildren, two children gcValue = array[gc]; maxgc = gc; if (comparator.compare(array[++gc], gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (comparator.compare(array[++gc], gcValue) > 0) { maxgc = gc; } return maxgc; case 1: // 2 grandchildren, maybe two children gcValue = array[gc]; maxgc = gc; if (comparator.compare(array[++gc], gcValue) > 0) { gcValue = array[gc]; maxgc = gc; } if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; case 0: // 1 grandchild, maybe two children gcValue = array[gc]; maxgc = gc; if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; } // 0 grandchildren maxgc = 2 * k; gcValue = array[maxgc]; if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) > 0) { maxgc = 2 * k + 1; } return maxgc; }
Given a node at a maximum level, find its child or grandchild with the maximum key. This method should not be called for a node which has no children. @param k a node at a maximum level @return the child or grandchild with a maximum key, or undefined if there are no children
@SuppressWarnings("unchecked") private int minChildOrGrandchild(int k) { int gc = 4 * k; int mingc; K gcValue; // 4 grandchilden if (gc + 3 <= size) { gcValue = array[gc]; mingc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { mingc = gc; } return mingc; } // less or equal to 3 switch (size - gc) { case 2: // 3 grandchildren, two children gcValue = array[gc]; mingc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { mingc = gc; } return mingc; case 1: // 2 grandchildren, maybe two children gcValue = array[gc]; mingc = gc; if (((Comparable<? super K>) array[++gc]).compareTo(gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) < 0) { mingc = 2 * k + 1; } return mingc; case 0: // 1 grandchild, maybe two children gcValue = array[gc]; mingc = gc; if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) < 0) { mingc = 2 * k + 1; } return mingc; } // 0 grandchildren mingc = 2 * k; gcValue = array[mingc]; if (2 * k + 1 <= size && ((Comparable<? super K>) array[2 * k + 1]).compareTo(gcValue) < 0) { mingc = 2 * k + 1; } return mingc; }
Given a node at a minimum level, find its child or grandchild with the minimum key. This method should not be called for a node which has no children. @param k a node at a minimum level @return the child or grandchild with a minimum key, or undefined if there are no children
private int minChildOrGrandchildWithComparator(int k) { int gc = 4 * k; int mingc; K gcValue; // 4 grandchilden if (gc + 3 <= size) { gcValue = array[gc]; mingc = gc; if (comparator.compare(array[++gc], gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (comparator.compare(array[++gc], gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (comparator.compare(array[++gc], gcValue) < 0) { mingc = gc; } return mingc; } // less or equal to 3 switch (size - gc) { case 2: // 3 grandchildren, two children gcValue = array[gc]; mingc = gc; if (comparator.compare(array[++gc], gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (comparator.compare(array[++gc], gcValue) < 0) { mingc = gc; } return mingc; case 1: // 2 grandchildren, maybe two children gcValue = array[gc]; mingc = gc; if (comparator.compare(array[++gc], gcValue) < 0) { gcValue = array[gc]; mingc = gc; } if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) < 0) { mingc = 2 * k + 1; } return mingc; case 0: // 1 grandchild, maybe two children gcValue = array[gc]; mingc = gc; if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) < 0) { mingc = 2 * k + 1; } return mingc; } // 0 grandchildren mingc = 2 * k; gcValue = array[mingc]; if (2 * k + 1 <= size && comparator.compare(array[2 * k + 1], gcValue) < 0) { mingc = 2 * k + 1; } return mingc; }
Given a node at a minimum level, find its child or grandchild with the minimum key. This method should not be called for a node which has no children. @param k a node at a minimum level @return the child or grandchild with a minimum key, or undefined if there are no children
@Override @LogarithmicTime @SuppressWarnings("unchecked") public AddressableHeap.Handle<K, V> insert(K key, V value) { if (key == null) { throw new NullPointerException("Null keys not permitted"); } Node n = new Node(key, value); // easy special cases if (size == 0) { root = n; size = 1; return n; } else if (size == 1) { int c; if (comparator == null) { c = ((Comparable<? super K>) key).compareTo(root.key); } else { c = comparator.compare(key, root.key); } if (c < 0) { n.o_c = root; root.y_s = n; root = n; } else { root.o_c = n; n.y_s = root; } size = 2; return n; } // find parent of last node and hang Node p = findParentNode(size + 1); if (p.o_c == null) { p.o_c = n; } else { p.o_c.y_s = n; } n.y_s = p; // increase size size++; // fix priorities fixup(n); return n; }
{@inheritDoc}
@Override @LogarithmicTime public AddressableHeap.Handle<K, V> deleteMin() { if (size == 0) { throw new NoSuchElementException(); } Node oldRoot = root; // easy special cases if (size == 1) { root = null; size = 0; return oldRoot; } else if (size == 2) { root = root.o_c; root.o_c = null; root.y_s = null; size = 1; oldRoot.o_c = null; return oldRoot; } // remove last node Node lastNodeParent = findParentNode(size); Node lastNode = lastNodeParent.o_c; if (lastNode.y_s != lastNodeParent) { Node tmp = lastNode; lastNode = tmp.y_s; tmp.y_s = lastNodeParent; } else { lastNodeParent.o_c = null; } lastNode.y_s = null; // decrease size size--; // place it as root // (assumes root.o_c exists) if (root.o_c.y_s == root) { root.o_c.y_s = lastNode; } else { root.o_c.y_s.y_s = lastNode; } lastNode.o_c = root.o_c; root = lastNode; // fix priorities fixdown(root); oldRoot.o_c = null; return oldRoot; }
{@inheritDoc}
private Node getParent(Node n) { if (n.y_s == null) { return null; } Node c = n.y_s; if (c.o_c == n) { return c; } Node p1 = c.y_s; if (p1 != null && p1.o_c == n) { return p1; } return c; }
/* Get the parent node of a given node.
private Node findParentNode(long node) { // assert node > 0; // find bit representation of node long[] s = { node }; BitSet bits = BitSet.valueOf(s); // traverse path to last node Node cur = root; for (int i = bits.length() - 2; i > 0; i--) { if (bits.get(i)) { cur = cur.o_c.y_s; } else { cur = cur.o_c; } } return cur; }
/* Start at the root and traverse the tree in order to find the parent node of a particular node. Uses the bit representation to keep the cost log(n). @param node the node number assuming that the root node is number one
private void swap(Node n, Node root) { // assert this.root == root; Node nLeftChild = n.o_c; if (root.o_c == n) { if (n.y_s == root) { // n is left child and no right sibling n.o_c = root; root.y_s = n; } else { // n is left child and has right sibling root.y_s = n.y_s; root.y_s.y_s = n; n.o_c = root; } } else { // n is right child root.o_c.y_s = root; n.o_c = root.o_c; root.y_s = n; } n.y_s = null; // hang children root.o_c = nLeftChild; if (nLeftChild != null) { if (nLeftChild.y_s == n) { nLeftChild.y_s = root; } else { nLeftChild.y_s.y_s = root; } } this.root = n; }
/* Swap a node with its parent which must be the root.
private void swap(Node n, Node p, Node pp) { if (pp == null) { swap(n, p); return; } Node nLeftChild = n.o_c; if (pp.o_c == p) { // p left child of pp if (p.o_c == n) { if (n.y_s == p) { // n left child of p and no sibling pp.o_c = n; n.y_s = p.y_s; n.o_c = p; p.y_s = n; } else { // n left child or p and sibling n.y_s.y_s = n; Node tmp = n.y_s; n.y_s = p.y_s; p.y_s = tmp; pp.o_c = n; n.o_c = p; } } else { // n right child of p Node tmp = p.o_c; n.y_s = p.y_s; pp.o_c = n; n.o_c = tmp; tmp.y_s = p; p.y_s = n; } } else { // p right child of pp if (p.o_c == n) { if (n.y_s == p) { // n left child of p and no sibling n.y_s = pp; pp.o_c.y_s = n; n.o_c = p; p.y_s = n; } else { // n left child of p and sibling pp.o_c.y_s = n; p.y_s = n.y_s; n.y_s = pp; n.o_c = p; p.y_s.y_s = n; } } else { // n right child of p pp.o_c.y_s = n; n.y_s = pp; n.o_c = p.o_c; n.o_c.y_s = p; p.y_s = n; } } // hang children p.o_c = nLeftChild; if (nLeftChild != null) { if (nLeftChild.y_s == n) { nLeftChild.y_s = p; } else { nLeftChild.y_s.y_s = p; } } }
/* Swap a node with its parent @param n the node @param p the parent node @param pp the parent of the parent node, maybe null
public void startMonitoringNetworkChanges() { if (networkReceiver != null) { IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); context.registerReceiver(networkReceiver, filter); } else { logger.warn("Cannot monitor device network changes. Make sure that a NetworkConnectionListener was passed to the NetworkMonitor constructor."); } }
Begin monitoring changes in the device's network connection. Before using this method, be sure to pass a {@link NetworkConnectionListener} to {@link #NetworkMonitor(Context, NetworkConnectionListener)}.
@TargetApi(24) public String getMobileNetworkType() { String resultUnknown = "unknown"; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { return resultUnknown; } if (getTelephonyManager() == null) { return resultUnknown; } switch (getTelephonyManager().getDataNetworkType()) { case TelephonyManager.NETWORK_TYPE_LTE: return "4G"; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_HSPAP: return "3G"; case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_IDEN: return "2G"; default: return resultUnknown; } }
Get the type of mobile data network connection. It is recommended to call {@link #getCurrentConnectionType()} before this method to make sure that the device does have a mobile data connection. <p><b>Note:</b> This method is only available for Android API 24 and up. When used on a lower API version, this method will return "unknown".</p> @return "4G", "3G", "2G", or "unknown"
public NetworkConnectionType getCurrentConnectionType() { NetworkInfo activeNetworkInfo = getActiveNetworkInfo(); if (activeNetworkInfo == null || !isInternetAccessAvailable()) { return NetworkConnectionType.NO_CONNECTION; } switch (activeNetworkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return NetworkConnectionType.WIFI; case ConnectivityManager.TYPE_MOBILE: return NetworkConnectionType.MOBILE; case ConnectivityManager.TYPE_WIMAX: return NetworkConnectionType.WIMAX; case ConnectivityManager.TYPE_ETHERNET: return NetworkConnectionType.ETHERNET; default: return NetworkConnectionType.NO_CONNECTION; } }
Get the type of network connection that the device is currently using to connect to the internet. @return The type of network connection that the device is currently using.
protected NetworkInfo getActiveNetworkInfo() { ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); return connectivityManager.getActiveNetworkInfo(); }
Retrieves information on the current type of network connection that the device is using
@Override @ConstantTime public Handle<K, V> insert(K key, V value) { if (key == null) { throw new IllegalArgumentException("Null keys not permitted"); } if (compare(key, maxKey) > 0) { throw new IllegalArgumentException("Key is more than the maximum allowed key"); } if (compare(key, lastDeletedKey) < 0) { throw new IllegalArgumentException("Invalid key. Monotone heap."); } // add to bucket Node p = new Node(key, value); int b = computeBucket(key, lastDeletedKey); p.bucket = b; if (buckets[b] == null) { buckets[b] = p; } else { buckets[b].prev = p; p.next = buckets[b]; buckets[b] = p; } // update current minimum cache if (currentMin == null || compare(key, currentMin.key) < 0) { currentMin = p; } size++; return p; }
{@inheritDoc} @throws IllegalArgumentException if the key is null @throws IllegalArgumentException if the key is less than the minimum allowed key @throws IllegalArgumentException if the key is more than the maximum allowed key @throws IllegalArgumentException if the key is less than the last deleted key (or the minimum key allowed if no key has been deleted)