List of usage examples for java.util LinkedList addLast
public void addLast(E e)
From source file:org.guzz.builder.GuzzConfigFileBuilder.java
/** * //from w w w . ja v a2 s. c o m * @throws Exception * @return List (@link POJOBasedObjectMapping) */ public List listBusinessObjectMappings() throws Exception { /* <business name="user" class="org.guzz.test.User" interpret="" file="classpath:com/guzz/test/User.hbm.xml" /> */ LinkedList mappings = new LinkedList(); List bus = this.rootDoc.selectNodes("business"); for (int i = 0; i < bus.size(); i++) { Element e = (Element) bus.get(i); String m_name = e.attributeValue("name"); String m_class = e.attributeValue("class"); String m_interpret = e.attributeValue("interpret"); String m_file = e.attributeValue("file"); String m_dbgroup = e.attributeValue("dbgroup"); if (StringUtil.isEmpty(m_name)) { throw new GuzzException("bussiness name not found. xml:[" + e.asXML() + "]"); } if (StringUtil.isEmpty(m_file)) { throw new GuzzException("file not found. xml:[" + e.asXML() + "]"); } Class i_cls = StringUtil.notEmpty(m_interpret) ? Class.forName(m_interpret) : null; Class d_cls = StringUtil.notEmpty(m_class) ? Class.forName(m_class) : null; Resource r = new FileResource(m_file); try { POJOBasedObjectMapping map = HbmXMLBuilder.parseHbmStream(gf, m_dbgroup, null, m_name, d_cls, i_cls, r.getInputStream()); mappings.addLast(map); } finally { CloseUtil.close(r); } } return mappings; }
From source file:org.guzz.builder.GuzzConfigFileBuilder.java
protected List parseForPhysicsDBGroup(List segElements, String defaultDialect) { if (segElements == null) return null; if (segElements.isEmpty()) return null; LinkedList dbGroups = new LinkedList(); for (int i = 0; i < segElements.size(); i++) { Element e = (Element) segElements.get(i); PhysicsDBGroup db = new PhysicsDBGroup(); String groupName = e.attributeValue("name"); String masterName = e.attributeValue("masterDBConfigName"); String slaveName = e.attributeValue("slaveDBConfigName"); String dialectName = e.attributeValue("dialectName"); if (StringUtil.isEmpty(groupName)) { db.setGroupName("default"); } else {/* w w w . ja v a 2 s . c o m*/ db.setGroupName(groupName); } if (StringUtil.notEmpty(masterName)) { db.setMasterDB(this.gf.getOrCreateDataService(masterName)); } if (StringUtil.notEmpty(slaveName)) { db.setSlaveDB(this.gf.getOrCreateDataService(slaveName)); } if (StringUtil.isEmpty(dialectName)) { dialectName = defaultDialect; } Dialect dt = this.gf.getDialect(dialectName); if (dt == null) { throw new GuzzException("dialect:[" + dialectName + "] not found for dbgroup:[" + e.asXML() + "]"); } db.setDialect(dt); dbGroups.addLast(db); } return dbGroups; }
From source file:org.apache.airavata.sharing.registry.server.SharingRegistryServerHandler.java
private boolean shareEntity(String domainId, String entityId, List<String> groupOrUserList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException { try {//from w w w .ja va 2s . com if (permissionTypeId .equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { throw new SharingRegistryException( OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); } List<Sharing> sharings = new ArrayList<>(); //Adding permission for the specified users/groups for the specified entity LinkedList<Entity> temp = new LinkedList<>(); for (String userId : groupOrUserList) { Sharing sharing = new Sharing(); sharing.setPermissionTypeId(permissionTypeId); sharing.setEntityId(entityId); sharing.setGroupId(userId); sharing.setInheritedParentId(entityId); sharing.setDomainId(domainId); if (cascadePermission) { sharing.setSharingType(SharingType.DIRECT_CASCADING); } else { sharing.setSharingType(SharingType.DIRECT_NON_CASCADING); } sharing.setCreatedTime(System.currentTimeMillis()); sharing.setUpdatedTime(System.currentTimeMillis()); sharings.add(sharing); } if (cascadePermission) { //Adding permission for the specified users/groups for all child entities (new EntityRepository()).getChildEntities(domainId, entityId).stream() .forEach(e -> temp.addLast(e)); while (temp.size() > 0) { Entity entity = temp.pop(); String childEntityId = entity.entityId; for (String userId : groupOrUserList) { Sharing sharing = new Sharing(); sharing.setPermissionTypeId(permissionTypeId); sharing.setEntityId(childEntityId); sharing.setGroupId(userId); sharing.setInheritedParentId(entityId); sharing.setSharingType(SharingType.INDIRECT_CASCADING); sharing.setInheritedParentId(entityId); sharing.setDomainId(domainId); sharing.setCreatedTime(System.currentTimeMillis()); sharing.setUpdatedTime(System.currentTimeMillis()); sharings.add(sharing); (new EntityRepository()).getChildEntities(domainId, childEntityId).stream() .forEach(e -> temp.addLast(e)); } } } (new SharingRepository()).create(sharings); EntityPK entityPK = new EntityPK(); entityPK.setDomainId(domainId); entityPK.setEntityId(entityId); Entity entity = (new EntityRepository()).get(entityPK); entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); (new EntityRepository()).update(entity); return true; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException() .setMessage(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); } }
From source file:jext2.DataBlockAccess.java
/** Get up to maxBlocks BlockNrs for the logical fileBlockNr. I dont really like to change behavior * by specifing a flag variable but this is more or less like the linux implementation. Use getBlocks * or getBlocksAllocate./*from www.j a v a2 s.c om*/ * @param inode Inode of the data block * @param fileBlockNr the logical block address * @param maxBlocks maximum blocks returned * @param create true: create blocks if nesseccary; false: just read * @return list of block nrs; if create=false null is returned if block does not exist * @throws NoSpaceLeftOnDevice * @throws FileTooLarge * @throws IOException */ @MustReturnLock private LinkedList<Long> getBlocks(long fileBlockNr, long maxBlocks, boolean create) throws JExt2Exception, NoSpaceLeftOnDevice, FileTooLarge { if (fileBlockNr < 0 || maxBlocks < 1) throw new IllegalArgumentException(); LinkedList<Long> result = new LinkedList<Long>(); int[] offsets; long[] blockNrs; int depth; int existDepth; hierarchyLock.readLock().lock(); offsets = blockToPath(fileBlockNr); depth = offsets.length; blockNrs = getBranch(offsets); existDepth = blockNrs.length; /* Simplest case - block found, no allocation needed */ if (depth == existDepth) { long firstBlockNr = blockNrs[depth - 1]; result.addFirst(firstBlockNr); long blocksToBoundary = 0; if (depth >= 2) /* indirect blocks */ blocksToBoundary = superblock.getAddressesPerBlock() - offsets[depth - 1] - 1; else /* direct blocks */ blocksToBoundary = Constants.EXT2_NDIR_BLOCKS - offsets[0] - 1; int count = 1; while (count < maxBlocks && count <= blocksToBoundary) { long nextByNumber = firstBlockNr + count; long nextOnDisk = -1; if (depth >= 2) /* indirect blocks */ nextOnDisk = blocks.readBlockNumberFromBlock(blockNrs[depth - 2], offsets[depth - 1] + count); else /* direct blocks */ nextOnDisk = inode.getBlock()[offsets[0] + count]; /* check if next neighbor block belongs to inode */ if (nextByNumber == nextOnDisk) { result.addLast(nextByNumber); count++; } else { break; } } assert hierarchyLock.getReadHoldCount() == 1 : "Returning without holding lock"; return result; } assert hierarchyLock.getReadHoldCount() == 1 : "Should have a read lock around"; /* Next simple case - plain lookup mode */ if (!create) { assert hierarchyLock.getReadHoldCount() == 1 : "Returning without holding lock"; return null; } hierarchyLock.readLock().unlock(); /* Okay, we need to do block allocation. */ hierarchyLock.writeLock().lock(); long goal = findGoal(fileBlockNr, blockNrs, offsets); int count = depth - existDepth; LinkedList<Long> newBlockNrs = allocBranch(count, goal, offsets, blockNrs); spliceBranch(fileBlockNr, offsets, blockNrs, newBlockNrs); result.add(newBlockNrs.getLast()); hierarchyLock.readLock().lock(); hierarchyLock.writeLock().unlock(); /* Again return with an open read lock */ assert hierarchyLock.getReadHoldCount() == 1 : "Returning without holding lock"; return result; }
From source file:com.redhat.persistence.oql.QFrame.java
private void render(LinkedList joins, List where, QFrame oroot, QFrame root, Set emitted) { // If the first non empty frame is outer we treat it as inner. if (m_outer && !joins.isEmpty()) { oroot = this; }/*from w ww .j a va2 s . com*/ Code table = null; if (m_table != null && m_duplicate == null) { table = new Code(m_table).add(" ").add(alias()); } else if (m_tableExpr != null && m_duplicate == null) { table = m_tableExpr.emit(m_generator).add(" ").add(alias()); } if (table != null) { joins.addFirst(JFrame.leaf(table, this, oroot)); } List children = getChildren(); for (int i = 0; i < children.size(); i++) { QFrame child = (QFrame) children.get(i); child.render(joins, where, oroot, root, emitted); } if (m_condition != null) { Code c = m_condition.emit(m_generator); if (!c.isTrue() && !emitted.contains(c)) { m_used.clear(); frames(m_condition, m_used); boolean join = false; for (Iterator it = joins.iterator(); it.hasNext();) { JFrame frame = (JFrame) it.next(); boolean modified = m_used.removeAll(frame.defined); if (m_used.isEmpty()) { // We default to putting things in the where // clause here because oracle won't resolve // external variable references correctly when // they appear in join conditions. if (oroot.equals(root)) { where.add(c); } else if (frame.froot != null && oroot.equals(frame.froot)) { frame.join = frame.join.add(" and ").add(c); } else { throw new IllegalStateException( "unable to place condition: " + m_condition + " " + c + trace(joins)); } } else if (modified) { join = true; break; } } if (join) { JFrame right = (JFrame) joins.removeFirst(); if (joins.isEmpty()) { throw new IllegalStateException( "unresolved variable in condition: " + m_condition + " " + c + trace(joins)); } LinkedList skipped = null; JFrame left = (JFrame) joins.removeFirst(); while (true) { m_used.clear(); frames(m_condition, m_used); m_used.removeAll(right.defined); boolean cross = m_used.removeAll(left.defined); if (m_used.isEmpty()) { joins.addFirst(JFrame.join(left, right, c)); break; } else if (joins.isEmpty()) { throw new IllegalStateException( "unresolved variable in condition: " + m_condition + " " + c + trace(joins)); } else if (cross) { JFrame lefter = (JFrame) joins.removeFirst(); left = JFrame.cross(lefter, left); } else { if (skipped == null) { skipped = new LinkedList(); } skipped.addLast(left); left = (JFrame) joins.removeFirst(); } } if (skipped != null) { while (!skipped.isEmpty()) { joins.addFirst(skipped.removeLast()); } } } emitted.add(c); } } }
From source file:org.myrian.persistence.oql.QFrame.java
private void render(LinkedList joins, List where, QFrame oroot, QFrame root, Set emitted) { // If the first non empty frame is outer we treat it as inner. if (m_outer && !joins.isEmpty()) { oroot = this; }/*w ww . j a v a 2s . co m*/ Code table = null; if (m_table != null && m_duplicate == null) { table = new Code(m_table).add(" ").add(alias()); } else if (m_tableExpr != null && m_duplicate == null) { table = m_tableExpr.emit(m_generator).add(" ").add(alias()); } if (table != null) { joins.addFirst(JFrame.leaf(table, this, oroot)); } List children = getChildren(); for (int i = 0; i < children.size(); i++) { QFrame child = (QFrame) children.get(i); child.render(joins, where, oroot, root, emitted); } if (m_condition != null) { Code c = m_condition.emit(m_generator); if (!c.isTrue() && !emitted.contains(c)) { m_used.clear(); frames(m_condition, m_used); boolean join = false; for (Iterator it = joins.iterator(); it.hasNext();) { JFrame frame = (JFrame) it.next(); boolean modified = m_used.removeAll(frame.defined); if (m_used.isEmpty()) { // We default to putting things in the where // clause here because oracle won't resolve // external variable references correctly when // they appear in join conditions. if (oroot.equals(root)) { where.add(c); } else if (frame.froot != null && oroot.equals(frame.froot)) { frame.join = frame.join.add(" and ").add(c); } else { /* * XXX rhs needs to make sure this is * the right thing to do */ where.add(c); } } else if (modified) { join = true; break; } } if (join) { JFrame right = (JFrame) joins.removeFirst(); if (joins.isEmpty()) { throw new IllegalStateException( "unresolved variable in condition: " + m_condition + " " + c + trace(joins)); } LinkedList skipped = null; JFrame left = (JFrame) joins.removeFirst(); while (true) { m_used.clear(); frames(m_condition, m_used); m_used.removeAll(right.defined); boolean cross = m_used.removeAll(left.defined); if (m_used.isEmpty()) { joins.addFirst(JFrame.join(left, right, c)); break; } else if (joins.isEmpty()) { throw new IllegalStateException( "unresolved variable in condition: " + m_condition + " " + c + trace(joins)); } else if (cross) { JFrame lefter = (JFrame) joins.removeFirst(); left = JFrame.cross(lefter, left); } else { if (skipped == null) { skipped = new LinkedList(); } skipped.addLast(left); left = (JFrame) joins.removeFirst(); } } if (skipped != null) { while (!skipped.isEmpty()) { joins.addFirst(skipped.removeLast()); } } } emitted.add(c); } } }
From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtil.java
/** * Find the differences between two texts. Simplifies the problem by * stripping any common prefix or suffix off the texts before diffing. * * @param list1 Old string to be diffed. * @param list2 New string to be diffed. * @param checklines Speedup flag. If false, then don't run a * line-level diff first to identify the changed areas. * If true, then run a faster slightly less optimal diff. * @param deadline Time when the diff should be complete by. Used * internally for recursive calls. Users should set DiffTimeout instead. * @return Linked List of Diff objects./* www .ja va 2 s . c o m*/ */ private LinkedList<Diff<T>> diff_main(List<T> list1, List<T> list2, boolean checklines, long deadline) { // Check for null inputs. if (list1 == null || list2 == null) { throw new IllegalArgumentException("Null inputs. (diff_main)"); } // Check for equality (speedup). LinkedList<Diff<T>> diffs; if (list1.equals(list2)) { diffs = new LinkedList<Diff<T>>(); if (list1.size() != 0) { diffs.add(new Diff<T>(Operation.EQUAL, list1)); } return diffs; } // Trim off common prefix (speedup). int commonlength = diff_commonPrefix(list1, list2); List<T> commonprefix = list1.subList(0, commonlength); list1 = list1.subList(commonlength, list1.size()); list2 = list2.subList(commonlength, list2.size()); // Trim off common suffix (speedup). commonlength = diff_commonSuffix(list1, list2); List<T> commonsuffix = list1.subList(list1.size() - commonlength, list1.size()); list1 = list1.subList(0, list1.size() - commonlength); list2 = list2.subList(0, list2.size() - commonlength); // Compute the diff on the middle block. diffs = diff_compute(list1, list2, checklines, deadline); // Restore the prefix and suffix. if (commonprefix.size() != 0) { diffs.addFirst(new Diff<T>(Operation.EQUAL, commonprefix)); } if (commonsuffix.size() != 0) { diffs.addLast(new Diff<T>(Operation.EQUAL, commonsuffix)); } diff_cleanupMerge(diffs); return diffs; }
From source file:mitm.djigzo.web.services.security.HMACFilterImpl.java
private void calculateHMACs(MarkupWriter writer, List<String> hmacs) { Document document = writer.getDocument(); if (document != null) { Element root = document.getRootElement(); if (root != null) { LinkedList<Element> queue = new LinkedList<Element>(); queue.add(root);/*from ww w . j ava 2s . c o m*/ while (!queue.isEmpty()) { Element element = queue.removeFirst(); if (element == null) { continue; } String elementName = element.getAttribute("name"); if (elementName != null) { elementName = elementName.trim().toLowerCase(); } if (protectedElements.contains(elementName)) { /* * It's a protected item so we should calculate the HMAC of the value */ String value = element.getAttribute("value"); String hmac; try { hmac = calculateHMAC(value, true /* create ASO if not exist */); } catch (InvalidKeyException e) { throw new DjigzoRuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new DjigzoRuntimeException(e); } if (hmac == null) { throw new DjigzoRuntimeException("hmac is null."); } if (hmacs != null) { hmacs.add(hmac); } else { /* * Add the HMAC checksum as a hidden element */ element.element("input", "type", "hidden", "name", HMAC_PARAMETER, "value", hmac); } } for (Node n : element.getChildren()) { Element child = null; if (n instanceof Element) { child = (Element) n; } if (child != null) queue.addLast(child); } } } } }
From source file:org.drools.semantics.builder.model.inference.DelegateInferenceStrategy.java
private void applyPropertyRestrictions(OWLOntology ontoDescr, OntoModel hierarchicalModel, OWLDataFactory factory) {//w ww. j a v a 2 s . c o m for (PropertyRelation prop : hierarchicalModel.getProperties()) { if (prop.getTarget() == null) { logger.warn("Property without target concept " + prop.getName()); } } Map<String, Set<OWLClassExpression>> supers = new HashMap<String, Set<OWLClassExpression>>(); for (OWLClass klass : ontoDescr.getClassesInSignature(true)) { supers.put(klass.getIRI().toQuotedString(), new HashSet<OWLClassExpression>()); } for (OWLClass klass : ontoDescr.getClassesInSignature(true)) { if (isDelegating(klass)) { OWLClassExpression delegate = aliases.get(klass); supers.get(delegate.asOWLClass().getIRI().toQuotedString()) .addAll(klass.getSuperClasses(ontoDescr)); } else { Set<OWLClassExpression> sup = supers.get(klass.asOWLClass().getIRI().toQuotedString()); Set<OWLClassExpression> ancestors = klass.getSuperClasses(ontoDescr); sup.addAll(ancestors); for (OWLClassExpression anc : ancestors) { if (reverseAliases.containsKey(anc)) { sup.addAll(reverseAliases.get(anc)); } } } } for (Concept con : hierarchicalModel.getConcepts()) { //use concepts as they're sorted! if (isDelegating(con.getIri())) { continue; } if (con == null) { logger.warn("Looking for superclasses of an undefined concept"); continue; } LinkedList<OWLClassExpression> orderedSupers = new LinkedList<OWLClassExpression>(); // cardinalities should be fixed last for (OWLClassExpression sup : supers.get(con.getIri())) { if (sup instanceof OWLCardinalityRestriction) { orderedSupers.addLast(sup); } else { orderedSupers.addFirst(sup); } } for (OWLClassExpression sup : orderedSupers) { if (sup.isClassExpressionLiteral()) { continue; } processSuperClass(sup, con, hierarchicalModel, factory); } // for ( PropertyRelation prop : con.getProperties().values() ) { // if ( prop.isRestricted() && ( prop.getMaxCard() == null || prop.getMaxCard() > 1 ) ) { // prop.setName( prop.getName() + "s" ); // } // } } }
From source file:org.gldapdaemon.core.ldap.ContactLoader.java
public ContactLoader(ThreadGroup mainGroup, Configurator configurator) throws Exception { super(mainGroup, "Contact loader"); this.configurator = configurator; this.vcardDirectory = new File(configurator.getWorkDirectory(), "vcard"); if (!vcardDirectory.isDirectory()) { vcardDirectory.mkdirs();/*from w w w. j a v a2 s.c om*/ } // Acceptable hostnames FilterMask[] hosts = configurator.getFilterProperty(Configurator.LDAP_ALLOWED_HOSTNAMES); // Acceptable TCP/IP addresses FilterMask[] addresses = configurator.getFilterProperty(Configurator.LDAP_ALLOWED_ADDRESSES); // Get contact list cache timeout long timeout = configurator.getConfigProperty(Configurator.LDAP_CACHE_TIMEOUT, 3600000L); if (timeout < 180000L) { log.warn("The fastest contact list polling period is '3 min'!"); timeout = 180000L; } pollingTimeout = timeout; // Get username/password pairs LinkedList usernameList = new LinkedList(); LinkedList passwordList = new LinkedList(); String parameterPostfix; int gapCounter = 0; for (int i = 1;; i++) { // Create parameter postfix [..n] if (i == 1) { parameterPostfix = ""; } else { parameterPostfix = Integer.toString(i); } if (configurator.getConfigProperty(Configurator.LDAP_GOOGLE_USERNAME + parameterPostfix, null) == null) { if (gapCounter < MAX_INDEX_GAP) { gapCounter++; continue; } break; } gapCounter = 0; // Get username String username = configurator.getConfigProperty(Configurator.LDAP_GOOGLE_USERNAME + parameterPostfix, null); // Get password String password = null; if (configurator.getConfigProperty(Configurator.LDAP_GOOGLE_PASSWORD + parameterPostfix, null) != null) { password = configurator.getPasswordProperty(Configurator.LDAP_GOOGLE_PASSWORD + parameterPostfix); } // Verify parameters if (username == null) { throw new NullPointerException( "Missing username (" + Configurator.LDAP_GOOGLE_USERNAME + parameterPostfix + ")!"); } if (password == null) { throw new NullPointerException( "Missing password (" + Configurator.LDAP_GOOGLE_PASSWORD + parameterPostfix + ")!"); } // Add parameters to lists usernameList.addLast(username); passwordList.addLast(password); } // Create object arrays usernames = new String[usernameList.size()]; passwords = new String[passwordList.size()]; usernameList.toArray(usernames); passwordList.toArray(passwords); if (hosts == null && addresses == null) { // Security warning log.warn("Set the '" + Configurator.LDAP_ALLOWED_HOSTNAMES + "' parameter to limit remote access."); } else { // Debug filters if (log.isDebugEnabled()) { log.debug("Allowed LDAP hosts: " + configurator.getConfigProperty(Configurator.LDAP_ALLOWED_HOSTNAMES, "*")); log.debug("Allowed LDAP addresses: " + configurator.getConfigProperty(Configurator.LDAP_ALLOWED_ADDRESSES, "*")); } } // Get vCard properties String value = configurator.getConfigProperty(Configurator.LDAP_VCARD_ENCODING, "quoted"); if (value.equals("quoted")) { vcardEncoding = VCARD_QUOTED_ENCODING; } else { if (value.equals("native")) { vcardEncoding = VCARD_NATIVE_ENCODING; } else { vcardEncoding = VCARD_UTF8_ENCODING; } } value = configurator.getConfigProperty(Configurator.LDAP_VCARD_VERSION, "3.0"); try { double num = Double.parseDouble(value); vcardVersion = Double.toString(num); } catch (Exception formatError) { log.fatal("Invalid vCard version: " + value); throw formatError; } // Create and start LDAP listener int port = (int) configurator.getConfigProperty(Configurator.LDAP_PORT, 9080); ldapListener = new LDAPListener(this, hosts, addresses, port); // Start listener start(); }