com.ibm.icu.impl.Assert Java Examples

The following examples show how to use com.ibm.icu.impl.Assert. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RBBINode.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
RBBINode(int t) {
    Assert.assrt(t < nodeTypeLimit);
    fSerialNum = ++gLastSerial;
    fType = t;

    fFirstPosSet = new HashSet<RBBINode>();
    fLastPosSet = new HashSet<RBBINode>();
    fFollowPos = new HashSet<RBBINode>();
    if (t == opCat) {
        fPrecedence = precOpCat;
    } else if (t == opOr) {
        fPrecedence = precOpOr;
    } else if (t == opStart) {
        fPrecedence = precStart;
    } else if (t == opLParen) {
        fPrecedence = precLParen;
    } else {
        fPrecedence = precZero;
    }
}
 
Example #2
Source File: RuleBasedBreakIterator.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private void makeRuleStatusValid() {
    if (fLastStatusIndexValid == false) {
        //  No cached status is available.
        int curr = current();
        if (curr == BreakIterator.DONE || curr == fText.getBeginIndex()) {
            //  At start of text, or there is no text.  Status is always zero.
            fLastRuleStatusIndex = 0;
            fLastStatusIndexValid = true;
        } else {
            //  Not at start of text.  Find status the tedious way.
            int pa = fText.getIndex();
            first();
            int pb = current();
            while (fText.getIndex() < pa) {
                pb = next();
            }
            Assert.assrt(pa == pb);
        }
        Assert.assrt(fLastStatusIndexValid == true);
        Assert.assrt(fLastRuleStatusIndex >= 0  &&  fLastRuleStatusIndex < fRData.fStatusTable.length);
    }
}
 
Example #3
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
void bofFixup() {
    //
    //   The parse tree looks like this ...
    //         fTree root  --.       <cat>
    //                               /     \
    //                            <cat>   <#end node>
    //                           /     \
    //                     <bofNode>   rest
    //                               of tree
    //
    //    We will be adding things to the followPos set of the <bofNode>
    //
    RBBINode  bofNode = fRB.fTreeRoots[fRootIx].fLeftChild.fLeftChild;
    Assert.assrt(bofNode.fType == RBBINode.leafChar);
    Assert.assrt(bofNode.fVal == 2);

    // Get all nodes that can be the start a match of the user-written rules
    //  (excluding the fake bofNode)
    //  We want the nodes that can start a match in the
    //     part labeled "rest of tree"
    //
    Set<RBBINode> matchStartNodes = fRB.fTreeRoots[fRootIx].fLeftChild.fRightChild.fFirstPosSet;
    for (RBBINode startNode : matchStartNodes) {
        if (startNode.fType != RBBINode.leafChar) {
            continue;
        }

        if (startNode.fVal == bofNode.fVal) {
            //  We found a leaf node corresponding to a {bof} that was
            //    explicitly written into a rule.
            //  Add everything from the followPos set of this node to the
            //    followPos set of the fake bofNode at the start of the tree.
            //
            bofNode.fFollowPos.addAll(startNode.fFollowPos);
        }
    }
}
 
Example #4
Source File: RBBISetBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
void split(int where) {
    Assert.assrt(where>fStartChar && where<=fEndChar);
    RangeDescriptor nr = new RangeDescriptor(this);
 
    //  RangeDescriptor copy constructor copies all fields.
    //  Only need to update those that are different after the split.
    nr.fStartChar = where;
    this.fEndChar = where-1;
    nr.fNext      = this.fNext;
    this.fNext    = nr;
    
    // TODO:  fIncludesSets is not updated.  Check it out.
    //         Probably because they haven't been populated yet, 
    //         but still sloppy.
}
 
Example #5
Source File: RBBISetBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
int getTrieSize()  {
    int size = 0;
    try {
        // The trie serialize function returns the size of the data written.
        //    null output stream says give size only, don't actually write anything.
        size = fTrie.serialize(null, true, dm );
    } catch (IOException e) {
        Assert.assrt (false);
    }
    return size;
}
 
Example #6
Source File: BytesDictionaryMatcher.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public BytesDictionaryMatcher(byte[] chars, int transform) {
    characters = chars;
    Assert.assrt((transform & DictionaryData.TRANSFORM_TYPE_MASK) == DictionaryData.TRANSFORM_TYPE_OFFSET);
    // while there is only one transform type so far, save the entire transform constant so that
    // if we add any others, we need only change code in transform() and the assert above rather
    // than adding a "transform type" variable
    this.transform = transform;
}
 
Example #7
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
void buildStateTable() {
    //
    // Add a dummy state 0 - the stop state.  Not from Aho.
    int      lastInputSymbol = fRB.fSetBuilder.getNumCharCategories() - 1;
    RBBIStateDescriptor failState = new RBBIStateDescriptor(lastInputSymbol);
    fDStates.add(failState);

    // initially, the only unmarked state in Dstates is firstpos(root),
    //       where toot is the root of the syntax tree for (r)#;
    RBBIStateDescriptor initialState = new RBBIStateDescriptor(lastInputSymbol);
    initialState.fPositions.addAll(fRB.fTreeRoots[fRootIx].fFirstPosSet);
    fDStates.add(initialState);

    // while there is an unmarked state T in Dstates do begin
    for (;;) {
        RBBIStateDescriptor T = null;
        int              tx;
        for (tx=1; tx<fDStates.size(); tx++) {
            RBBIStateDescriptor temp  = fDStates.get(tx);
            if (temp.fMarked == false) {
                T = temp;
                break;
            }
        }
        if (T == null) {
            break;
        }

        // mark T;
        T.fMarked = true;

        // for each input symbol a do begin
        int  a;
        for (a = 1; a<=lastInputSymbol; a++) {
            // let U be the set of positions that are in followpos(p)
            //    for some position p in T
            //    such that the symbol at position p is a;
            Set<RBBINode> U = null;
            for (RBBINode p : T.fPositions) {
                if ((p.fType == RBBINode.leafChar) &&  (p.fVal == a)) {
                    if (U == null) {
                        U = new HashSet<RBBINode>();
                    }
                    U.addAll(p.fFollowPos);
                }
            }

            // if U is not empty and not in DStates then
            int  ux = 0;
            boolean    UinDstates = false;
            if (U != null) {
                Assert.assrt(U.size() > 0);
                int  ix;
                for (ix=0; ix<fDStates.size(); ix++) {
                    RBBIStateDescriptor temp2;
                    temp2 = fDStates.get(ix);
                    if (U.equals(temp2.fPositions)) {
                        U  = temp2.fPositions;
                        ux = ix;
                        UinDstates = true;
                        break;
                    }
                }

                // Add U as an unmarked state to Dstates
                if (!UinDstates)
                {
                    RBBIStateDescriptor newState = new RBBIStateDescriptor(lastInputSymbol);
                    newState.fPositions = U;
                    fDStates.add(newState);
                    ux = fDStates.size()-1;
                }

                // Dtran[T, a] := U;
                T.fDtran[a] = ux;
            }
        }
    }
}
 
Example #8
Source File: RBBITableBuilder.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
short [] exportTable() {
    int                state;
    int                col;

    if (fRB.fTreeRoots[fRootIx] == null) {
        return new short[0];
    }

    Assert.assrt(fRB.fSetBuilder.getNumCharCategories() < 0x7fff &&
        fDStates.size() < 0x7fff);

    int numStates = fDStates.size();

    // Size of table size in shorts.
    //  the "4" is the size of struct RBBIStateTableRow, the row header part only.
    int rowLen = 4 + fRB.fSetBuilder.getNumCharCategories();
    int tableSize = getTableSize() / 2;


    short [] table = new short[tableSize];

    //
    // Fill in the header fields.
    //      Annoying because they really want to be ints, not shorts.
    //
    // RBBIStateTable.fNumStates
    table[RBBIDataWrapper.NUMSTATES]   = (short)(numStates >>> 16);
    table[RBBIDataWrapper.NUMSTATES+1] = (short)(numStates & 0x0000ffff);

    // RBBIStateTable.fRowLen
    table[RBBIDataWrapper.ROWLEN]   = (short)(rowLen >>> 16);
    table[RBBIDataWrapper.ROWLEN+1] = (short)(rowLen & 0x0000ffff);

    // RBBIStateTable.fFlags
    int flags = 0;
    if (fRB.fLookAheadHardBreak) {
        flags  |= RBBIDataWrapper.RBBI_LOOKAHEAD_HARD_BREAK;
    }
    if (fRB.fSetBuilder.sawBOF()) {
        flags  |= RBBIDataWrapper.RBBI_BOF_REQUIRED;
    }
    table[RBBIDataWrapper.FLAGS]   = (short)(flags >>> 16);
    table[RBBIDataWrapper.FLAGS+1] = (short)(flags & 0x0000ffff);

    int numCharCategories = fRB.fSetBuilder.getNumCharCategories();
    for (state=0; state<numStates; state++) {
        RBBIStateDescriptor sd = fDStates.get(state);
        int                row = 8 + state*rowLen;
        Assert.assrt (-32768 < sd.fAccepting && sd.fAccepting <= 32767);
        Assert.assrt (-32768 < sd.fLookAhead && sd.fLookAhead <= 32767);
        table[row + RBBIDataWrapper.ACCEPTING] = (short)sd.fAccepting;
        table[row + RBBIDataWrapper.LOOKAHEAD] = (short)sd.fLookAhead;
        table[row + RBBIDataWrapper.TAGIDX]    = (short)sd.fTagsIdx;
        for (col=0; col<numCharCategories; col++) {
            table[row + RBBIDataWrapper.NEXTSTATES + col] = (short)sd.fDtran[col];
        }
    }
    return table;
}
 
Example #9
Source File: RBBIRuleScanner.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
void findSetFor(String s, RBBINode node, UnicodeSet setToAdopt) {

        RBBISetTableEl el;

        // First check whether we've already cached a set for this string.
        // If so, just use the cached set in the new node.
        //   delete any set provided by the caller, since we own it.
        el = fSetTable.get(s);
        if (el != null) {
            node.fLeftChild = el.val;
            Assert.assrt(node.fLeftChild.fType == RBBINode.uset);
            return;
        }

        // Haven't seen this set before.
        // If the caller didn't provide us with a prebuilt set,
        //   create a new UnicodeSet now.
        if (setToAdopt == null) {
            if (s.equals(kAny)) {
                setToAdopt = new UnicodeSet(0x000000, 0x10ffff);
            } else {
                int c;
                c = UTF16.charAt(s, 0);
                setToAdopt = new UnicodeSet(c, c);
            }
        }

        //
        // Make a new uset node to refer to this UnicodeSet
        // This new uset node becomes the child of the caller's setReference
        // node.
        //
        RBBINode usetNode = new RBBINode(RBBINode.uset);
        usetNode.fInputSet = setToAdopt;
        usetNode.fParent = node;
        node.fLeftChild = usetNode;
        usetNode.fText = s;

        //
        // Add the new uset node to the list of all uset nodes.
        //
        fRB.fUSetNodes.add(usetNode);

        //
        // Add the new set to the set hash table.
        //
        el = new RBBISetTableEl();
        el.key = s;
        el.val = usetNode;
        fSetTable.put(el.key, el);

        return;
    }
 
Example #10
Source File: WebDAVMethodTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void expiryLockTest()
{
    // ACE-4347 extra debug logging just for this test so we can see what's going on when it next fails
    Level repoWebdavSaveLogLevel = Logger.getLogger("org.alfresco.repo.webdav").getLevel();
    Logger.getLogger("org.alfresco.repo.webdav").setLevel(Level.ALL);
    Level webdavProtocolSaveLogLevel = Logger.getLogger("org.alfresco.webdav.protocol").getLevel();
    Logger.getLogger("org.alfresco.webdav.protocol").setLevel(Level.ALL);
    try
    {
        setUpApplicationContext();

        req = new MockHttpServletRequest();
        resp = new MockHttpServletResponse();

        String rootPath = "/app:company_home";
        StoreRef storeRef = new StoreRef("workspace://SpacesStore");
        NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
        List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
        NodeRef defaultRootNode = nodeRefs.get(0);

        NodeRef rootNodeRef = tenantService.getRootNode(nodeService, searchService, namespaceService, rootPath, defaultRootNode);

        // Create test folder.
        NodeRef folderNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_FOLDER,
                Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "WebDavMethodExpiryLockTest" + System.currentTimeMillis())).getChildRef();

        // Create test document.
        NodeRef nodeRef = nodeService.createNode(folderNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("test"), ContentModel.TYPE_CONTENT,
                Collections.<QName, Serializable> singletonMap(ContentModel.PROP_NAME, "text.txt")).getChildRef();

        lockMethod = new LockMethod();
        lockMethod.createExclusive = true;
        lockMethod.m_timeoutDuration = 1;
        lockMethod.setDetails(req, resp, webDAVHelper, nodeRef);

        transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Object>()
        {
            @Override
            public Object execute() throws Throwable
            {
                try
            {
                // LOCK document.
                lockMethod.executeImpl();
                
                //wait for the lock to expire up to 5 seconds
                int timeout = 5;
                while( timeout > 0 && !lockMethod.lockInfo.isExpired())
                {
                    Thread.sleep(1000);
                    timeout--;
                }
                
                // LOCK against an expired lock.
                lockMethod.executeImpl();
            }
            catch (WebDAVServerException e)
            {
                logger.debug(e);
                Assert.fail("Document was not locked again, when lock has expired.");
            }
            return null;
            }
        });

        // Remove test folder.
        nodeService.deleteNode(folderNodeRef);
    }
    finally
    {
        Logger.getLogger("org.alfresco.webdav.protocol").setLevel(webdavProtocolSaveLogLevel);
        Logger.getLogger("org.alfresco.repo.webdav").setLevel(repoWebdavSaveLogLevel);
    }
}
 
Example #11
Source File: TestTicket1518.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
  * Quads in SPARQL update data block (INSERT clause). 
  */
 
 public void testQuadsInSPARQLInsertBlock() throws Exception {

     BigdataSailRepositoryConnection cxn = null;

     final BigdataSail sail = getSail(getTriplesNoInference());

     try {

         sail.initialize();
         
         final BigdataSailRepository repo = new BigdataSailRepository(sail);
         
         cxn = (BigdataSailRepositoryConnection) repo.getConnection();
         
         cxn.begin();
         
         final String update = "INSERT DATA  {" + // 
         		
         		"GRAPH <http://graphA> {<s:s1> <p:p1> <o:o1> .} " + //
    			
 			"} ";

         final Update  q = cxn.prepareUpdate(QueryLanguage.SPARQL, update);
         try {
	
	q.execute();
	
	Assert.fail("");
	
} catch (QuadsOperationInTriplesModeException ex) {
	
	String expectedMessage = "Quads in SPARQL update data block are not supported " + 
							"in triples mode.";
	
	assertEquals(expectedMessage, ex.getMessage());
	
}

     } finally {
     	
     	if (cxn != null)
             cxn.close();
         sail.__tearDownUnitTest();
     }
 }
 
Example #12
Source File: TestTicket1518.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
  * Quads in SPARQL update data block (DELETE clause).
  */
 
 public void testQuadsInSPARQLDeleteDataBlock() throws Exception {

     BigdataSailRepositoryConnection cxn = null;

     final BigdataSail sail = getSail(getTriplesNoInference());

     try {

         sail.initialize();
         
         final BigdataSailRepository repo = new BigdataSailRepository(sail);
         
         cxn = (BigdataSailRepositoryConnection) repo.getConnection();
         
         cxn.begin();
      
         final String update = "DELETE DATA  {" + // 
         
			"GRAPH <http://graphA> {<s:s1> <p:p1> <o:o1> .} " + //
    			
 			"} ";

         final Update  q = cxn.prepareUpdate(QueryLanguage.SPARQL, update);
         try {
	
	q.execute();
	
	Assert.fail("");
	
} catch (QuadsOperationInTriplesModeException ex) {
	
	String expectedMessage = "Quads in SPARQL update data block are not supported " + 
							"in triples mode.";
	
	assertEquals(expectedMessage, ex.getMessage());
	
}

     } finally {
     	
     	if (cxn != null)
             cxn.close();
         sail.__tearDownUnitTest();
     }
 }
 
Example #13
Source File: TestTicket1518.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
  * Test named graph referenced through WITH clause.
  */
 
 public void testNamedGraphReferencedThroughWITHClause() throws Exception {

     BigdataSailRepositoryConnection cxn = null;

     final BigdataSail sail = getSail(getTriplesNoInference());

     try {

         sail.initialize();
         
         final BigdataSailRepository repo = new BigdataSailRepository(sail);
         
         cxn = (BigdataSailRepositoryConnection) repo.getConnection();
         
         cxn.begin();
        
         final String update = "with <c:graphA> " + //
         					 "INSERT { <s:s1> <p:p1> <o:o1> . } where {}";

         final Update  q = cxn.prepareUpdate(QueryLanguage.SPARQL, update);
         try {
	
	q.execute();
	
	Assert.fail("");
	
} catch (QuadsOperationInTriplesModeException ex) {
	
	String expectedMessage = "Use of WITH and GRAPH constructs in query body is not supported " +
											"in triples mode.";
	
	assertEquals(expectedMessage, ex.getMessage());
	
}
		

     } finally {
         if (cxn != null)
             cxn.close();
         sail.__tearDownUnitTest();
     }
 }
 
Example #14
Source File: TestTicket1518.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
  * Test using of GRAPH construct in query body.
  */
 
 public void testGRAPHConstructInQueryBody() throws Exception {

     BigdataSailRepositoryConnection cxn = null;

     final BigdataSail sail = getSail(getTriplesNoInference());

     try {

         sail.initialize();
         
         final BigdataSailRepository repo = new BigdataSailRepository(sail);
         
         cxn = (BigdataSailRepositoryConnection) repo.getConnection();
         
         cxn.begin();
         
         
        
         final String query = "SELECT ?g ?s ?p ?o" + //
					"WHERE { GRAPH ?g { ?s ?p ?o }}";
					

         final TupleQuery q = cxn.prepareTupleQuery(QueryLanguage.SPARQL,
			query);

         try {
	
	final TupleQueryResult tqr = q.evaluate();
	
	Assert.fail("");
	
} catch (QuadsOperationInTriplesModeException ex) {
	
	String expectedMessage = "Use of WITH and GRAPH constructs in query body is not supported " +
                     					"in triples mode.";
	
	assertEquals(expectedMessage, ex.getMessage());
	
}
		

     } finally {
         if (cxn != null)
             cxn.close();
         sail.__tearDownUnitTest();
     }
 }