List of usage examples for java.util LinkedList addFirst
public void addFirst(E e)
From source file:com.norconex.commons.lang.file.FileUtil.java
/** * Returns the specified number of lines starting from the end * of a text file.//from w ww . j ava2 s. co m * @param file the file to read lines from * @param encoding the file encoding * @param numberOfLinesToRead the number of lines to read * @param stripBlankLines whether to return blank lines or not * @param filter InputStream filter * @return array of file lines * @throws IOException i/o problem */ public static String[] tail(File file, String encoding, final int numberOfLinesToRead, boolean stripBlankLines, IInputStreamFilter filter) throws IOException { assertFile(file); assertNumOfLinesToRead(numberOfLinesToRead); LinkedList<String> lines = new LinkedList<String>(); BufferedReader reader = new BufferedReader( new InputStreamReader(new ReverseFileInputStream(file), encoding)); int remainingLinesToRead = numberOfLinesToRead; String line; while ((line = reader.readLine()) != null) { if (remainingLinesToRead-- <= 0) { break; } String newLine = StringUtils.reverse(line); if (!stripBlankLines || StringUtils.isNotBlank(line)) { if (filter != null && filter.accept(newLine)) { lines.addFirst(newLine); } else { remainingLinesToRead++; } } else { remainingLinesToRead++; } } reader.close(); return lines.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
From source file:net.spfbl.data.Generic.java
public static boolean containsGenericDomain(String address) { if (address == null) { return false; } else {// ww w. ja va 2s .com try { int index = address.indexOf('@') + 1; address = address.substring(index); String hostname = Domain.normalizeHostname(address, true); if (hostname == null) { return false; } else { LinkedList<String> regexList = new LinkedList<String>(); do { index = hostname.indexOf('.') + 1; hostname = hostname.substring(index); if (MAP.containsGeneric('.' + hostname)) { return true; } else { regexList.addFirst('.' + hostname); } } while (hostname.contains(".")); return REGEX.get(regexList) != null; } } catch (ProcessException ex) { Server.logError(ex); return false; } } }
From source file:org.dcm4chee.storage.conf.DeepEquals.java
/** * Deeply compare two SortedMap instances. This method walks the Maps in order, * taking advantage of the fact that they Maps are SortedMaps. * @param map1 SortedMap one// w w w . ja v a 2 s. co m * @param map2 SortedMap two * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set containing items that have already been compared, to prevent cycles. * @return false if the Maps are for certain not equals. 'true' indicates that 'on the surface' the maps * are equal, however, it will place the contents of the Maps on the stack for further comparisons. */ private static boolean compareSortedMap(Map map1, Map map2, LinkedList stack, Set visited) { // Same instance check already performed... if (map1.size() != map2.size()) { return false; } Iterator i1 = map1.entrySet().iterator(); Iterator i2 = map2.entrySet().iterator(); while (i1.hasNext()) { Map.Entry entry1 = (Map.Entry) i1.next(); Map.Entry entry2 = (Map.Entry) i2.next(); // Must split the Key and Value so that Map.Entry's equals() method is not used. DualKey dk = new DualKey(entry1.getKey(), entry2.getKey()); if (!visited.contains(dk)) { // Push Keys for further comparison stack.addFirst(dk); } dk = new DualKey(entry1.getValue(), entry2.getValue()); if (!visited.contains(dk)) { // Push values for further comparison stack.addFirst(dk); } } return true; }
From source file:org.dcm4che3.conf.core.misc.DeepEquals.java
/** * Deeply compare the two sets referenced by dualKey. This method attempts * to quickly determine inequality by length, then if lengths match, it * places one collection into a temporary Map by deepHashCode(), so that it * can walk the other collection and look for each item in the map, which * runs in O(N) time, rather than an O(N^2) lookup that would occur if each * item from collection one was scanned for in collection two. * @param col1 First collection of items to compare * @param col2 Second collection of items to compare * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set containing items that have already been compared, * so as to prevent cycles.//w ww. j av a 2 s . c om * @return boolean false if the Collections are for certain not equals. A * value of 'true' indicates that the Collections may be equal, and the sets * items will be added to the Stack for further comparison. */ private static boolean compareUnorderedCollection(Collection col1, Collection col2, LinkedList stack, Set visited) { // Same instance check already performed... if (col1.size() != col2.size()) { return false; } Map fastLookup = new HashMap(); for (Object o : col2) { fastLookup.put(deepHashCode(o), o); } for (Object o : col1) { Object other = fastLookup.get(deepHashCode(o)); if (other == null) { // Item not even found in other Collection, no need to continue. return false; } DualKey dk = new DualKey(o, other); if (!visited.contains(dk)) { // Place items on 'stack' for further comparison. stack.addFirst(dk); } } return true; }
From source file:org.codehaus.groovy.grails.validation.metaclass.ConstraintsEvaluatingDynamicProperty.java
public Object get(Object object) { // Suppress recursion problems if a GroovyObject if (object instanceof GroovyObject) { GroovyObject go = (GroovyObject) object; if (go.getMetaClass() instanceof ProxyMetaClass) { go.setMetaClass(((ProxyMetaClass) go.getMetaClass()).getAdaptee()); }/* w ww . java 2 s. c o m*/ } // Compile list of ancestors to query for constraints LinkedList classChain = new LinkedList(); Class clazz = object.getClass(); while (clazz != Object.class) { classChain.addFirst(clazz); clazz = clazz.getSuperclass(); } ConstrainedPropertyBuilder delegate = new ConstrainedPropertyBuilder(object); // Evaluate all the constraints closures in the inheritance chain for (Iterator it = classChain.iterator(); it.hasNext();) { clazz = (Class) it.next(); Closure c = (Closure) GrailsClassUtils.getStaticPropertyValue(clazz, PROPERTY_NAME); if (c == null) { c = getConstraintsFromScript(object); } if (c != null) { c.setDelegate(delegate); c.call(); } else { LOG.debug("User-defined constraints not found on class [" + clazz + "], applying default constraints"); } } Map constrainedProperties = delegate.getConstrainedProperties(); if (this.properties != null) { for (int i = 0; i < this.properties.length; i++) { GrailsDomainClassProperty p = this.properties[i]; ConstrainedProperty cp = (ConstrainedProperty) constrainedProperties.get(p.getName()); if (cp == null) { cp = new ConstrainedProperty(p.getDomainClass().getClazz(), p.getName(), p.getType()); cp.setOrder(constrainedProperties.size() + 1); constrainedProperties.put(p.getName(), cp); } // Make sure all fields are required by default, unless specified otherwise by the constraints if (!cp.hasAppliedConstraint(ConstrainedProperty.NULLABLE_CONSTRAINT) && !p.getName().equals(GrailsDomainClassProperty.DATE_CREATED) && !p.getName().equals(GrailsDomainClassProperty.LAST_UPDATED) && !((p.isOneToOne() || p.isManyToOne()) && p.isCircular())) { // TODO remove "p.isOptional()" in 0.6 // cp.applyConstraint(ConstrainedProperty.NULLABLE_CONSTRAINT, Boolean.valueOf(p.isAssociation() || p.isOptional())); cp.applyConstraint(ConstrainedProperty.NULLABLE_CONSTRAINT, Boolean.valueOf(p.isOptional() || Collection.class.isAssignableFrom(p.getType()) || Map.class.isAssignableFrom(p.getType()))); } } } return constrainedProperties; }
From source file:com.redhat.rhn.frontend.filter.TreeFilter.java
/** * Adds all the elements in the path from current to its * topmost parent to the "filtered" list.. At the same time * it also ensures that duplicate elements are NOT added to the * filtered list./* www . j a v a 2s .c o m*/ * @param current the Node info of the matched object * @param result the main data result passed in the input. */ private void addMatchedPath(NodeInfo current, DataResult result) { LinkedList path = new LinkedList(); if (!positions.contains(current.position)) { positions.add(current.position); path.addFirst(result.get(current.position.intValue())); } while (current.parent != null) { current = current.parent; if (!positions.contains(current.position)) { positions.add(current.position); path.addFirst(result.get(current.position.intValue())); } } filtered.addAll(path); }
From source file:org.osaf.cosmo.dao.mock.MockDaoStorage.java
/** */ public String getItemPath(Item item) { StringBuffer path = new StringBuffer(); LinkedList<String> hierarchy = new LinkedList<String>(); hierarchy.addFirst(item.getName()); Item currentItem = item;/*from w w w.j a v a 2 s .co m*/ while (currentItem.getParent() != null) { currentItem = itemsByUid.get(currentItem.getParent().getUid()); hierarchy.addFirst(currentItem.getName()); } // hierarchy for (String part : hierarchy) path.append("/" + part); return path.toString(); }
From source file:org.dcm4che3.conf.core.misc.DeepEquals.java
/** * Deeply compare two Map instances. After quick short-circuit tests, this method * uses a temporary Map so that this method can run in O(N) time. * @param map1 Map one//from w w w.ja v a 2s. c o m * @param map2 Map two * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set containing items that have already been compared, to prevent cycles. * @return false if the Maps are for certain not equals. 'true' indicates that 'on the surface' the maps * are equal, however, it will place the contents of the Maps on the stack for further comparisons. */ private static boolean compareUnorderedMap(Map map1, Map map2, LinkedList stack, Set visited) { // Same instance check already performed... if (map1.size() != map2.size()) { return false; } Map fastLookup = new HashMap(); for (Map.Entry entry : (Set<Map.Entry>) map2.entrySet()) { fastLookup.put(entry.getKey(), entry); } for (Map.Entry entry : (Set<Map.Entry>) map1.entrySet()) { Map.Entry other = (Map.Entry) fastLookup.get(entry.getKey()); if (other == null) { return false; } DualKey dk = new DualKey(entry.getKey(), other.getKey()); if (!visited.contains(dk)) { // Push keys for further comparison stack.addFirst(dk); } dk = new DualKey(entry.getValue(), other.getValue()); if (!visited.contains(dk)) { // Push values for further comparison stack.addFirst(dk); } } return true; }
From source file:com.moss.simpledeb.core.action.LaunchScriptAction.java
@Override public void run(DebState state) throws Exception { {//w w w. ja v a 2 s. c o m File target = new File(targetFile).getParentFile(); LinkedList<File> pathsNeeded = new LinkedList<File>(); File f = target; while (f != null) { pathsNeeded.addFirst(f); f = f.getParentFile(); } for (int i = 0; i < pathLevel; i++) { pathsNeeded.removeFirst(); } for (File e : pathsNeeded) { String p = "./" + e.getPath(); if (!p.endsWith("/")) { p = p + "/"; } TarArchiveEntry tarEntry = new TarArchiveEntry(p); tarEntry.setGroupId(0); tarEntry.setGroupName("root"); tarEntry.setIds(0, 0); tarEntry.setModTime(System.currentTimeMillis()); tarEntry.setSize(0); tarEntry.setUserId(0); tarEntry.setUserName("root"); tarEntry.setMode(Integer.parseInt("755", 8)); ArchivePath path = new DirArchivePath(tarEntry); state.addPath(DebComponent.CONTENT, path); } } String cp; { StringBuffer sb = new StringBuffer(); for (String path : state.classpath) { if (sb.length() == 0) { sb.append(path); } else { sb.append(":"); sb.append(path); } } cp = sb.toString(); } StringBuilder sb = new StringBuilder(); sb.append("#!/bin/bash\n"); sb.append("CP=\""); sb.append(cp); sb.append("\"\n"); sb.append("/usr/bin/java -cp $CP "); sb.append(className); sb.append(" $@\n"); byte[] data = sb.toString().getBytes(); String entryName = "./" + targetFile; TarArchiveEntry tarEntry = new TarArchiveEntry(entryName); tarEntry.setGroupId(0); tarEntry.setGroupName("root"); tarEntry.setIds(0, 0); tarEntry.setModTime(System.currentTimeMillis()); tarEntry.setSize(data.length); tarEntry.setUserId(0); tarEntry.setUserName("root"); tarEntry.setMode(Integer.parseInt("755", 8)); ArchivePath path = new BytesArchivePath(tarEntry, data); state.addPath(DebComponent.CONTENT, path); }
From source file:org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.java
private List<HibernatePropertiesCustomizer> determineHibernatePropertiesCustomizers( PhysicalNamingStrategy physicalNamingStrategy, ImplicitNamingStrategy implicitNamingStrategy, List<HibernatePropertiesCustomizer> hibernatePropertiesCustomizers) { if (physicalNamingStrategy != null || implicitNamingStrategy != null) { LinkedList<HibernatePropertiesCustomizer> customizers = new LinkedList<>( hibernatePropertiesCustomizers); customizers.addFirst(new NamingStrategiesHibernatePropertiesCustomizer(physicalNamingStrategy, implicitNamingStrategy)); return customizers; }/*from w w w .j a va2 s. c o m*/ return hibernatePropertiesCustomizers; }