List of usage examples for java.util List equals
boolean equals(Object o);
From source file:org.apache.fop.complexscripts.bidi.BidiResolver.java
private static List splitRuns(List runs) { List runsNew = new Vector(); for (Iterator it = runs.iterator(); it.hasNext();) { InlineRun ir = (InlineRun) it.next(); if (ir.isHomogenous()) { runsNew.add(ir);/* w w w. j a va 2 s . c o m*/ } else { runsNew.addAll(ir.split()); } } if (!runsNew.equals(runs)) { runs = runsNew; } return runs; }
From source file:org.apache.hadoop.tools.util.DistCpUtils.java
/** * Preserve attribute on file matching that of the file status being sent * as argument. Barring the block size, all the other attributes are preserved * by this function//from w w w . ja v a 2 s.c o m * * @param targetFS - File system * @param path - Path that needs to preserve original file status * @param srcFileStatus - Original file status * @param attributes - Attribute set that needs to be preserved * @param preserveRawXattrs if true, raw.* xattrs should be preserved * @throws IOException - Exception if any (particularly relating to group/owner * change or any transient error) */ public static void preserve(FileSystem targetFS, Path path, CopyListingFileStatus srcFileStatus, EnumSet<FileAttribute> attributes, boolean preserveRawXattrs) throws IOException { // If not preserving anything from FileStatus, don't bother fetching it. FileStatus targetFileStatus = attributes.isEmpty() ? null : targetFS.getFileStatus(path); String group = targetFileStatus == null ? null : targetFileStatus.getGroup(); String user = targetFileStatus == null ? null : targetFileStatus.getOwner(); boolean chown = false; if (attributes.contains(FileAttribute.ACL)) { List<AclEntry> srcAcl = srcFileStatus.getAclEntries(); List<AclEntry> targetAcl = getAcl(targetFS, targetFileStatus); if (!srcAcl.equals(targetAcl)) { targetFS.setAcl(path, srcAcl); } // setAcl doesn't preserve sticky bit, so also call setPermission if needed. if (srcFileStatus.getPermission().getStickyBit() != targetFileStatus.getPermission().getStickyBit()) { targetFS.setPermission(path, srcFileStatus.getPermission()); } } else if (attributes.contains(FileAttribute.PERMISSION) && !srcFileStatus.getPermission().equals(targetFileStatus.getPermission())) { targetFS.setPermission(path, srcFileStatus.getPermission()); } final boolean preserveXAttrs = attributes.contains(FileAttribute.XATTR); if (preserveXAttrs || preserveRawXattrs) { Map<String, byte[]> srcXAttrs = srcFileStatus.getXAttrs(); Map<String, byte[]> targetXAttrs = getXAttrs(targetFS, path); if (srcXAttrs != null && !srcXAttrs.equals(targetXAttrs)) { for (Entry<String, byte[]> entry : srcXAttrs.entrySet()) { String xattrName = entry.getKey(); if (preserveXAttrs) { targetFS.setXAttr(path, xattrName, entry.getValue()); } } } } if (attributes.contains(FileAttribute.REPLICATION) && !targetFileStatus.isDirectory() && (srcFileStatus.getReplication() != targetFileStatus.getReplication())) { targetFS.setReplication(path, srcFileStatus.getReplication()); } if (attributes.contains(FileAttribute.GROUP) && !group.equals(srcFileStatus.getGroup())) { group = srcFileStatus.getGroup(); chown = true; } if (attributes.contains(FileAttribute.USER) && !user.equals(srcFileStatus.getOwner())) { user = srcFileStatus.getOwner(); chown = true; } if (chown) { targetFS.setOwner(path, user, group); } if (attributes.contains(FileAttribute.TIMES)) { targetFS.setTimes(path, srcFileStatus.getModificationTime(), srcFileStatus.getAccessTime()); } }
From source file:picard.util.LiftoverUtils.java
protected static GenotypesContext fixGenotypes(final GenotypesContext originals, final List<Allele> originalAlleles, final List<Allele> newAlleles) { // optimization: if nothing needs to be fixed then don't bother if (originalAlleles.equals(newAlleles)) { return originals; }/* ww w . j a v a 2s . co m*/ if (originalAlleles.size() != newAlleles.size()) { throw new IllegalStateException( "Error in allele lists: the original and new allele lists are not the same length: " + originalAlleles.toString() + " / " + newAlleles.toString()); } final Map<Allele, Allele> alleleMap = new HashMap<>(); for (int idx = 0; idx < originalAlleles.size(); idx++) { alleleMap.put(originalAlleles.get(idx), newAlleles.get(idx)); } final GenotypesContext fixedGenotypes = GenotypesContext.create(originals.size()); for (final Genotype genotype : originals) { final List<Allele> fixedAlleles = new ArrayList<>(); for (final Allele allele : genotype.getAlleles()) { if (allele.isNoCall()) { fixedAlleles.add(allele); } else { Allele newAllele = alleleMap.get(allele); if (newAllele == null) { throw new IllegalStateException("Allele not found: " + allele.toString() + ", " + originalAlleles + "/ " + newAlleles); } fixedAlleles.add(newAllele); } } fixedGenotypes.add(new GenotypeBuilder(genotype).alleles(fixedAlleles).make()); } return fixedGenotypes; }
From source file:com.googlecode.fightinglayoutbugs.helpers.TestHelper.java
/** * Handles {@code null}, numbers, collections, and arrays. *//*from w w w.ja v a 2s .c o m*/ public static Matcher<Object> is(final Object expected, final Object... moreExpectedValues) { return new BaseMatcher<Object>() { @Override public boolean matches(Object o) { boolean matches; if (o == null) { matches = (moreExpectedValues.length == 0 && expected == null); } else if (o instanceof Number) { if (moreExpectedValues.length > 0) { matches = false; } else { if (expected instanceof Number) { if (expected instanceof Long && o instanceof Integer) { matches = (((Long) expected) == ((Integer) o).longValue()); } else if (expected instanceof Integer && o instanceof Long) { matches = (((Integer) expected).longValue() == ((Long) o)); } else { matches = o.equals(expected); } } else { matches = false; } } } else if (o instanceof Collection) { if (moreExpectedValues.length > 0) { if (o instanceof Set) { Set<?> expectedSet = Sets.union(TestHelper.asSet(expected), TestHelper.asSet(moreExpectedValues)); matches = expectedSet.equals(o); } else if (o instanceof List) { List<?> expectedList = Lists.asList(expected, moreExpectedValues); matches = expectedList.equals(o); } else { throw new RuntimeException( "Don't know how to match a " + o.getClass().getName() + " instance."); } } else if (expected == null) { throw new RuntimeException( "Ambigious matcher: Use either isNull() or isEqualTo(Collections.singleton(null))"); } else if (expected instanceof Collection) { matches = expected.equals(o); } else { matches = (((Collection) o).size() == 1 && expected.equals(((Collection) o).iterator().next())); } } else if (o.getClass().isArray()) { final Object expectedArray; if (moreExpectedValues.length > 0) { final Object[] a = new Object[moreExpectedValues.length + 1]; a[0] = expected; System.arraycopy(moreExpectedValues, 0, a, 1, moreExpectedValues.length); expectedArray = a; } else if (expected != null && !expected.getClass().isArray()) { expectedArray = new Object[] { expected }; } else { expectedArray = expected; } matches = new IsEqual<Object>(expectedArray).matches(o); } else { matches = (moreExpectedValues.length == 0 && o.equals(expected)); } return matches; } @Override public void describeTo(Description description) { if (moreExpectedValues.length == 0) { if (expected instanceof SelfDescribing) { ((SelfDescribing) expected).describeTo(description); } else { description.appendText(StringHelper.asString(expected)); } } else { final List<Object> temp = new ArrayList<Object>(moreExpectedValues.length + 1); temp.add(expected); temp.addAll(Arrays.asList(moreExpectedValues)); description.appendText(Joiner.on(", ").join(temp)); } } }; }
From source file:org.kuali.rice.krad.uif.layout.collections.DataTablesPagingHelper.java
/** * Sort the given modelCollection (in place) according to the specified columnSorts. * * <p>Not all columns will necessarily be directly mapped to the modelCollection, so the collectionGroup and view * are available as well for use in calculating those other column values. However, if all the columns are in fact * mapped to the elements of the modelCollection, subclasses should be able to easily override this method to * provide custom sorting logic.</p> * * <p>//ww w.j a v a 2s . co m * Create an index array and sort that. The array slots represents the slots in the modelCollection, and * the values are indices to the elements in the modelCollection. At the end, we'll re-order the * modelCollection so that the elements are in the collection slots that correspond to the array locations. * * A small example may be in order. Here's the incoming modelCollection: * * modelCollection = { "Washington, George", "Adams, John", "Jefferson, Thomas", "Madison, James" } * * Initialize the array with its element references all matching initial positions in the modelCollection: * * reSortIndices = { 0, 1, 2, 3 } * * After doing our sort in the array (where we sort indices based on the values in the modelCollection): * * reSortIndices = { 1, 2, 3, 0 } * * Then, we go back and apply that ordering to the modelCollection: * * modelCollection = { "Adams, John", "Jefferson, Thomas", "Madison, James", "Washington, George" } * * Why do it this way instead of just sorting the modelCollection directly? Because we may need to know * the original index of the element e.g. for the auto sequence column. * </p> * * @param modelCollection the collection to sort * @param oldColumnSorts the sorting that reflects the current state of the collection * @param newColumnSorts the sorting to apply to the collection * @param collectionGroup the CollectionGroup that is being rendered * @param form object containing the view's data * @param view the view */ protected static void applyTableJsonSort(final List<Object> modelCollection, List<ColumnSort> oldColumnSorts, final List<ColumnSort> newColumnSorts, final CollectionGroup collectionGroup, ViewModel form, final View view) { boolean isCollectionEmpty = CollectionUtils.isEmpty(modelCollection); boolean isSortingSpecified = !CollectionUtils.isEmpty(newColumnSorts); boolean isSortOrderChanged = newColumnSorts != oldColumnSorts && !newColumnSorts.equals(oldColumnSorts); if (!isCollectionEmpty && isSortingSpecified && isSortOrderChanged) { Integer[] sortIndices = new Integer[modelCollection.size()]; for (int i = 0; i < sortIndices.length; i++) { sortIndices[i] = i; } MultiColumnComparator comparator = new MultiColumnComparator(modelCollection, collectionGroup, newColumnSorts, form, view); Arrays.sort(sortIndices, comparator); // apply the sort to the modelCollection Object[] sorted = new Object[sortIndices.length]; for (int i = 0; i < sortIndices.length; i++) { sorted[i] = modelCollection.get(sortIndices[i]); } for (int i = 0; i < sorted.length; i++) { modelCollection.set(i, sorted[i]); } } }
From source file:org.diorite.inventory.recipe.craft.MultiCraftingRecipeItem.java
@SuppressWarnings("unchecked") protected static boolean fuzzyEquals(final List<NbtTag> pattern, final List<NbtTag> check) { if (pattern == null) { return true; }/*from w w w.j a v a 2 s.c o m*/ if (check == null) { return false; } try { final List<NbtTag> patternList = new ArrayList<>(pattern); final List<NbtTag> list = new ArrayList<>(check); final Class<?> type = patternList.isEmpty() ? (list.isEmpty() ? null : list.get(0).getClass()) : patternList.get(0).getClass(); if (type == null) { return true; } if (String.class.isAssignableFrom(type)) { return patternList.equals(list); } if (Map.class.isAssignableFrom(type)) { for (final Iterator<NbtTag> it = patternList.iterator(); it.hasNext();) { final Map<String, NbtTag> patternMap = (Map<String, NbtTag>) it.next(); boolean matches = false; for (final Iterator<NbtTag> it2 = list.iterator(); it2.hasNext();) { final Map<String, NbtTag> nbtTagMap = (Map<String, NbtTag>) it2.next(); if (fuzzyEquals(patternMap, nbtTagMap)) { it2.remove(); matches = true; break; } } if (!matches) { return false; } it.remove(); } } else if (List.class.isAssignableFrom(type)) { for (final Iterator<NbtTag> it = patternList.iterator(); it.hasNext();) { final List<NbtTag> patternList2 = (List<NbtTag>) it.next(); boolean matches = false; for (final Iterator<NbtTag> it2 = list.iterator(); it2.hasNext();) { final List<NbtTag> nbtTagList = (List<NbtTag>) it2.next(); if (fuzzyEquals(patternList2, nbtTagList)) { it2.remove(); matches = true; break; } } if (!matches) { return false; } it.remove(); } } else { for (final Iterator<NbtTag> it = patternList.iterator(); it.hasNext();) { final NbtTag patternTag2 = it.next(); if (!list.remove(patternTag2)) { return false; } it.remove(); } } return patternList.isEmpty(); } catch (final Exception e) { if (Diorite.getCore().isDebug()) { e.printStackTrace(); } return false; } }
From source file:com.healthmarketscience.jackcess.ExportUtil.java
/** * Copy a table in this database into a new delimited text file. * /* w w w. j av a2 s.c o m*/ * @param cursor * Cursor to export * @param out * Writer to export to * @param header * If <code>true</code> the first line contains the column names * @param delim * The column delimiter, <code>null</code> for default (comma) * @param quote * The quote character * @param filter * valid export filter * * @see Builder */ public static void exportWriter(Cursor cursor, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException { String delimiter = (delim == null) ? DEFAULT_DELIMITER : delim; // create pattern which will indicate whether or not a value needs to be // quoted or not (contains delimiter, separator, or newline) Pattern needsQuotePattern = Pattern.compile("(?:" + "x" + ")|(?:" + "x" + ")|(?:[\n\r])"); //Pattern needsQuotePattern = Pattern.compile( //"(?:" + Pattern.quote(delimiter) + ")|(?:" + //Pattern.quote("" + quote) + ")|(?:[\n\r])"); List<Column> origCols = cursor.getTable().getColumns(); List<Column> columns = new ArrayList<Column>(origCols); columns = filter.filterColumns(columns); Collection<String> columnNames = null; if (!origCols.equals(columns)) { // columns have been filtered columnNames = new HashSet<String>(); for (Column c : columns) { columnNames.add(c.getName()); } } // print the header row (if desired) if (header) { for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { writeValue(out, iter.next().getName(), quote, needsQuotePattern); if (iter.hasNext()) { out.write(delimiter); } } out.newLine(); } // print the data rows Map<String, Object> row; Object[] unfilteredRowData = new Object[columns.size()]; while ((row = cursor.getNextRow(columnNames)) != null) { // fill raw row data in array for (int i = 0; i < columns.size(); i++) { unfilteredRowData[i] = columns.get(i).getRowValue(row); } // apply filter Object[] rowData = filter.filterRow(unfilteredRowData); if (rowData == null) { continue; } // print row for (int i = 0; i < columns.size(); i++) { Object obj = rowData[i]; if (obj != null) { String value = null; if (obj instanceof byte[]) { value = ByteUtil.toHexString((byte[]) obj); } else { value = String.valueOf(rowData[i]); } writeValue(out, value, quote, needsQuotePattern); } if (i < columns.size() - 1) { out.write(delimiter); } } out.newLine(); } out.flush(); }
From source file:com.healthmarketscience.jackcess.util.ExportUtil.java
/** * Copy a table in this database into a new delimited text file. * //ww w . j a va2 s . co m * @param cursor * Cursor to export * @param out * Writer to export to * @param header * If <code>true</code> the first line contains the column names * @param delim * The column delimiter, <code>null</code> for default (comma) * @param quote * The quote character * @param filter * valid export filter * * @see Builder */ public static void exportWriter(Cursor cursor, BufferedWriter out, boolean header, String delim, char quote, ExportFilter filter) throws IOException { String delimiter = (delim == null) ? DEFAULT_DELIMITER : delim; // create pattern which will indicate whether or not a value needs to be // quoted or not (contains delimiter, separator, or newline) Pattern needsQuotePattern = Pattern .compile("(?:" + Pattern.quote(delimiter) + ")|(?:" + Pattern.quote("" + quote) + ")|(?:[\n\r])"); List<? extends Column> origCols = cursor.getTable().getColumns(); List<Column> columns = new ArrayList<Column>(origCols); columns = filter.filterColumns(columns); Collection<String> columnNames = null; if (!origCols.equals(columns)) { // columns have been filtered columnNames = new HashSet<String>(); for (Column c : columns) { columnNames.add(c.getName()); } } // print the header row (if desired) if (header) { for (Iterator<Column> iter = columns.iterator(); iter.hasNext();) { writeValue(out, iter.next().getName(), quote, needsQuotePattern); if (iter.hasNext()) { out.write(delimiter); } } out.newLine(); } // print the data rows Object[] unfilteredRowData = new Object[columns.size()]; Row row; while ((row = cursor.getNextRow(columnNames)) != null) { // fill raw row data in array for (int i = 0; i < columns.size(); i++) { unfilteredRowData[i] = columns.get(i).getRowValue(row); } // apply filter Object[] rowData = filter.filterRow(unfilteredRowData); if (rowData == null) { continue; } // print row for (int i = 0; i < columns.size(); i++) { Object obj = rowData[i]; if (obj != null) { String value = null; if (obj instanceof byte[]) { value = ByteUtil.toHexString((byte[]) obj); } else { value = String.valueOf(rowData[i]); } writeValue(out, value, quote, needsQuotePattern); } if (i < columns.size() - 1) { out.write(delimiter); } } out.newLine(); } out.flush(); }
From source file:com.ruoogle.base.imgload.ImageWorker.java
/** * Returns true if the current work has been canceled or if there was no work in * progress on this image view.//from w ww.j a v a 2 s . com * Returns false if the work in progress deals with the same data. The work is not * stopped in that case. */ public static boolean cancelPotentialWork(List<String> sURLList, ImageView imageView) { final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); if (bitmapWorkerTask != null) { final Object bitmapData = bitmapWorkerTask.sURLList; if (bitmapData == null || !sURLList.equals(bitmapData)) { bitmapWorkerTask.cancel(true); if (BuildConfig.DEBUG) { Log.d(TAG, "cancelPotentialWork - cancelled work for " + sURLList); } } else { // The same work is already in progress. return false; } } return true; }
From source file:de.adesso.referencer.search.helper.MyHelpMethods.java
public static boolean match(List<String> one, List<String> two) { if (one == null && two == null) { return true; }//from w w w.j ava 2s . co m if ((one == null && two != null) || one != null && two == null || one.size() != two.size()) { return false; } //to avoid messing the order of the lists we will use a copy //as noted in comments by A. R. S. List<String> list1 = stripNullValues(one); List<String> list2 = stripNullValues(two); if (list1.size() != list2.size()) { return false; } Collections.sort(list1); Collections.sort(list2); return list1.equals(list2); }