Java Code Examples for java.util.List.equals()

The following are Jave code examples for showing how to use equals() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: RequestOptionsGenerator.java   View Source Code Vote up 6 votes
private boolean isMethodInRequestOptions(ExecutableElement toFind) {
  // toFind is a method in a GlideExtension whose first argument is a BaseRequestOptions<?> type.
  // Since we're comparing against methods in BaseRequestOptions itself, we need to drop that
  // first type.
  List<String> toFindParameterNames = getComparableParameterNames(toFind, true /*skipFirst*/);
  String toFindSimpleName = toFind.getSimpleName().toString();
  for (Element element : requestOptionsType.getEnclosedElements()) {
    if (element.getKind() != ElementKind.METHOD) {
      continue;
    }
    ExecutableElement inBase = (ExecutableElement) element;
    if (toFindSimpleName.equals(inBase.getSimpleName().toString())) {
      List<String> parameterNamesInBase =
          getComparableParameterNames(inBase, false /*skipFirst*/);
      if (parameterNamesInBase.equals(toFindParameterNames)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 2
Project: openjdk-jdk10   File: MappingGenerationTest.java   View Source Code Vote up 6 votes
/**
 * Verifies that SystemFlavorMap is not affected by modification of
 * the Lists returned from getNativesForFlavor() and
 * getFlavorsForNative().
 */
public static void test2() {
    DataFlavor df = new DataFlavor("text/plain-test2", null);
    String nat = "native2";
    DataFlavor extraDf = new DataFlavor("text/test", null);

    List<String> natives = fm.getNativesForFlavor(df);
    natives.add("Should not be here");
    java.util.List nativesNew = fm.getNativesForFlavor(df);
    if (natives.equals(nativesNew)) {
        System.err.println("orig=" + natives);
        System.err.println("new=" + nativesNew);
        throw new RuntimeException("Test failed");
    }

    List<DataFlavor> flavors = fm.getFlavorsForNative(nat);
    flavors.add(extraDf);
    java.util.List flavorsNew = fm.getFlavorsForNative(nat);
    if (flavors.equals(flavorsNew)) {
        System.err.println("orig=" + flavors);
        System.err.println("new=" + flavorsNew);
        throw new RuntimeException("Test failed");
    }
}
 
Example 3
Project: openjdk-jdk10   File: PluginsInModulesTest.java   View Source Code Vote up 6 votes
@Test
public void testUseOnlyOneProcessor(Path base) throws Exception {
    initialization(base);
    List<String> log = new JavacTask(tb)
            .options("--processor-module-path", processorCompiledModules.toString(),
                    "-Xplugin:simpleplugin1")
            .outdir(classes)
            .sources(testClass)
            .run()
            .writeAll()
            .getOutputLines(Task.OutputKind.STDOUT);
    if (!log.equals(Arrays.asList("simpleplugin1 started for event COMPILATION",
                                  "simpleplugin1 finished for event COMPILATION"))) {
        throw new AssertionError("Unexpected output: " + log);
    }
}
 
Example 4
Project: openjdk-jdk10   File: ProfileOptionTest.java   View Source Code Vote up 6 votes
void checkDiags(String msg, List<Diagnostic<? extends JavaFileObject>> diags, List<String> expectDiagCodes) {
    System.err.print(msg);
    if (diags.isEmpty())
        System.err.println(" OK");
    else {
        System.err.println();
        System.err.println(diags);
    }

    List<String> foundDiagCodes = new ArrayList<String>();
    for (Diagnostic<? extends JavaFileObject> d: diags)
        foundDiagCodes.add(d.getCode());

    if (!foundDiagCodes.equals(expectDiagCodes)) {
        System.err.println("Found diag codes:    " + foundDiagCodes);
        System.err.println("Expected diag codes: " + expectDiagCodes);
        error("expected diagnostics not found");
    }
}
 
Example 5
Project: myfaces-trinidad   File: UIXSelectOrderTemplate.java   View Source Code Vote up 6 votes
/**
 * Compares two values, paying attention to the order of the elements.
 * @return true if the values are different
 */
// TODO improve efficiency for the array case?
@Override
@SuppressWarnings("unchecked")
protected boolean compareValues(Object previous, Object value)
{
  int prevSize = __getSize(previous);
  int newSize = __getSize(value);

  // If the sizes are different, no need to bother with further work
  if (prevSize != newSize)
    return true;

  // If the sizes are the same, and they're empty, we're also done.
  if (prevSize == 0)
    return false;

  List<Object> prevList = (previous instanceof List)
                    ? (List<Object>) previous : __toList(previous);
  List<Object> newList = (value instanceof List)
                    ? (List<Object>) value : __toList(value);

  // Since List has explicit rules about how equals() works, we
  // can just use that method.
  return !prevList.equals(newList);
}
 
Example 6
Project: cyberduck   File: FileNameMatcher.java   View Source Code Vote up 6 votes
private void extendStringToMatchByOneCharacter(final char c) {
    final List<Head> newHeads = listForLocalUseage;
    newHeads.clear();
    List<Head> lastAddedHeads = null;
    for(final Head head : heads) {
        final List<Head> headsToAdd = head.getNextHeads(c);
        // Why the next performance optimization isn't wrong:
        // Some times two heads return the very same list.
        // We save future effort if we don't add these heads again.
        // This is the case with the heads "a" and "*" of "a*b" which
        // both can return the list ["*","b"]
        if(!headsToAdd.equals(lastAddedHeads)) {
            newHeads.addAll(headsToAdd);
            lastAddedHeads = headsToAdd;
        }
    }
    listForLocalUseage = heads;
    heads = newHeads;
}
 
Example 7
Project: jdk8u-jdk   File: Arrrghs.java   View Source Code Vote up 6 votes
void doArgumentCheck(String inArgs, String... expArgs) {
    Map<String, String> env = new HashMap<>();
    env.put(JLDEBUG_KEY, "true");
    TestResult tr = doExec(env, javaCmd, inArgs);
    System.out.println(tr);
    int sindex = tr.testOutput.indexOf("Command line args:");
    if (sindex < 0) {
        System.out.println(tr);
        throw new RuntimeException("Error: no output");
    }
    sindex++; // skip over the tag
    List<String> gotList = new ArrayList<>();
    for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
        String a[] = x.split("=");
        gotList.add(a[a.length - 1].trim());
    }
    List<String> expList = Arrays.asList(expArgs);
    if (!gotList.equals(expList)) {
        System.out.println(tr);
        System.out.println("Expected args:");
        System.out.println(expList);
        System.out.println("Obtained args:");
        System.out.println(gotList);
        throw new RuntimeException("Error: args do not match");
    }
}
 
Example 8
Project: openjdk-jdk10   File: ReleaseOptionUnsupported.java   View Source Code Vote up 5 votes
@Test
public void testUnsafeUnnamed(Path base) throws IOException {
    Path src = base.resolve("src");
    tb.writeJavaFiles(src,
                      "package test; public class Test { sun.misc.Unsafe unsafe; } ");
    Path classes = base.resolve("classes");
    tb.createDirectories(classes);

    List<String> log;
    List<String> expected = Arrays.asList(
            "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe",
            "1 warning"
    );

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics")
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--release", Target.DEFAULT.multiReleaseValue())
            .outdir(classes)
            .files(tb.findJavaFiles(src))
            .run(Expect.SUCCESS)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log)) {
        throw new AssertionError("Unexpected output: " + log);
    }
}
 
Example 9
Project: incubator-netbeans   File: ImmutableTreeTranslator.java   View Source Code Vote up 5 votes
protected final ModifiersTree rewriteChildren(ModifiersTree tree) {
List<? extends AnnotationTree> annotations = translateStable(tree.getAnnotations());
if (!annotations.equals(tree.getAnnotations())) {
    ModifiersTree n = make.Modifiers(tree, annotations);
           model.setType(n, model.getType(tree));
    copyCommentTo(tree,n);
           copyPosTo(tree,n);
    tree = n;
}
return tree;
   }
 
Example 10
Project: openjdk-jdk10   File: ConvenientAccessErrorsTest.java   View Source Code Vote up 5 votes
public void testInaccessibleUnnamedModule(Path base) throws Exception {
    Path jar = prepareTestJar(base, "package api; class Api { public static class Foo {} }");

    Path moduleSrc = base.resolve("module-src");
    Path m1x = moduleSrc.resolve("m1x");

    Path classes = base.resolve("classes");

    Files.createDirectories(classes);

    tb.writeJavaFiles(m1x,
                      "module m1x { }",
                      "package test; public class Test { api.Api api; api.Api.Foo api; }");

    List<String> log = new JavacTask(tb)
            .options("-classpath", jar.toString(),
                     "-XDrawDiagnostics")
            .outdir(classes)
            .files(findJavaFiles(moduleSrc))
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    List<String> expected = Arrays.asList(
            "Test.java:1:38: compiler.err.not.def.access.package.cant.access: api.Api, api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
            "Test.java:1:51: compiler.err.not.def.access.package.cant.access: api.Api, api, (compiler.misc.not.def.access.does.not.read.unnamed: api, m1x)",
            "2 errors");

    if (!expected.equals(log))
        throw new Exception("expected output not found; actual: " + log);
}
 
Example 11
Project: appinventor-extensions   File: GameClient.java   View Source Code Vote up 5 votes
private void processInstanceLists(JSONObject instanceLists){
  try {
    joinedInstances = JsonUtil.getStringListFromJsonArray(instanceLists.
        getJSONArray(JOINED_LIST_KEY));

    publicInstances = JsonUtil.getStringListFromJsonArray(instanceLists.
        getJSONArray(PUBLIC_LIST_KEY));

    List<String> receivedInstancesInvited = JsonUtil.getStringListFromJsonArray(instanceLists.
        getJSONArray(INVITED_LIST_KEY));

    if (!receivedInstancesInvited.equals(InvitedInstances())) {
      List<String> oldList = invitedInstances;
      invitedInstances = receivedInstancesInvited;
      List<String> newInvites = new ArrayList<String>(receivedInstancesInvited);
      newInvites.removeAll(oldList);

      for (final String instanceInvited : newInvites) {
        Invited(instanceInvited);
      }
    }

  } catch (JSONException e) {
    Log.w(LOG_TAG, e);
    Info("Instance lists failed to parse.");
  }
}
 
Example 12
Project: incubator-netbeans   File: EclipseWizardIterator.java   View Source Code Vote up 5 votes
private void updateExtraWizardPanels() {
    List<WizardDescriptor.Panel<WizardDescriptor>> l = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>();
    if (getCurrent() == workspacePanel) {
        numberOfPanels = workspacePanel.isWorkspaceChosen() ? 2 : 1;
    }
    if (getCurrent() != projectPanel) {
        return;
    }
    Set<String> alreadyIncluded = new HashSet<String>();
    List<String> panelProviders = new ArrayList<String>();
    for (EclipseProject ep : getProjects()) {
        if (!ep.isImportSupported()) {
            continue;
        }
        if (alreadyIncluded.contains(ep.getProjectTypeFactory().getClass().getName())) {
            continue;
        } else {
            alreadyIncluded.add(ep.getProjectTypeFactory().getClass().getName());
        }
        l.addAll(ep.getProjectTypeFactory().getAdditionalImportWizardPanels());
        panelProviders.add(ep.getProjectTypeFactory().getClass().getName());
    }
    if (panelProviders.equals(currentPanelProviders)) {
        return;
    } else {
        currentPanelProviders = panelProviders;
    }
    extraPanels = l;
    numberOfPanels = 2 + l.size();
    int index = 2;
    for (WizardDescriptor.Panel p : l) {
        JComponent comp = (JComponent)p.getComponent();
        comp.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX,  // NOI18N
                new Integer(index));
        index++;
        comp.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, getWizardPanelName(l));
    }
    ((JComponent)projectPanel.getComponent()).putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, getWizardPanelName(l));
}
 
Example 13
Project: incubator-netbeans   File: PatchFile.java   View Source Code Vote up 5 votes
private boolean patchCreatesNewFileThatAlreadyExists(SinglePatch patch, List<String> originalFile) throws PatchException {
    if (patch.hunks.length != 1) {
        return false;
    }
    Hunk hunk = patch.hunks[0];
    if (hunk.baseStart != 0 || hunk.baseCount != 0 || hunk.modifiedStart
            != 1 || hunk.modifiedCount != originalFile.size()) {
        return false;
    }

    List<String> target = new ArrayList<>(hunk.modifiedCount);
    applyHunk(target, hunk);
    return target.equals(originalFile);
}
 
Example 14
Project: jdk8u-jdk   File: Arrrghs.java   View Source Code Vote up 5 votes
void checkArgumentParsing(String inArgs, String... expArgs) throws IOException {
    List<String> scratchpad = new ArrayList<>();
    scratchpad.add("set " + JLDEBUG_KEY + "=true");
    // GAK, -version needs to be added so that windows can flush its stderr
    // exiting the process prematurely can terminate the stderr.
    scratchpad.add(javaCmd + " -version " + inArgs);
    File batFile = new File("atest.bat");
    createAFile(batFile, scratchpad);

    TestResult tr = doExec(batFile.getName());

    ArrayList<String> expList = new ArrayList<>();
    expList.add(javaCmd);
    expList.add("-version");
    expList.addAll(Arrays.asList(expArgs));

    List<String> gotList = new ArrayList<>();
    for (String x : tr.testOutput) {
        Matcher m = ArgPattern.matcher(x);
        if (m.matches()) {
            String a[] = x.split("=");
            gotList.add(a[a.length - 1].trim());
        }
    }
    if (!gotList.equals(expList)) {
        System.out.println(tr);
        System.out.println("Expected args:");
        System.out.println(expList);
        System.out.println("Obtained args:");
        System.out.println(gotList);
        throw new RuntimeException("Error: args do not match");
    }
    System.out.println("\'" + inArgs + "\'" + " - Test passed");
}
 
Example 15
Project: openjdk-jdk10   File: MethodHandles.java   View Source Code Vote up 4 votes
private static MethodHandle dropArgumentsToMatch(MethodHandle target, int skip, List<Class<?>> newTypes, int pos,
                                  boolean nullOnFailure) {
    newTypes = copyTypes(newTypes.toArray());
    List<Class<?>> oldTypes = target.type().parameterList();
    int match = oldTypes.size();
    if (skip != 0) {
        if (skip < 0 || skip > match) {
            throw newIllegalArgumentException("illegal skip", skip, target);
        }
        oldTypes = oldTypes.subList(skip, match);
        match -= skip;
    }
    List<Class<?>> addTypes = newTypes;
    int add = addTypes.size();
    if (pos != 0) {
        if (pos < 0 || pos > add) {
            throw newIllegalArgumentException("illegal pos", pos, newTypes);
        }
        addTypes = addTypes.subList(pos, add);
        add -= pos;
        assert(addTypes.size() == add);
    }
    // Do not add types which already match the existing arguments.
    if (match > add || !oldTypes.equals(addTypes.subList(0, match))) {
        if (nullOnFailure) {
            return null;
        }
        throw newIllegalArgumentException("argument lists do not match", oldTypes, newTypes);
    }
    addTypes = addTypes.subList(match, add);
    add -= match;
    assert(addTypes.size() == add);
    // newTypes:     (   P*[pos], M*[match], A*[add] )
    // target: ( S*[skip],        M*[match]  )
    MethodHandle adapter = target;
    if (add > 0) {
        adapter = dropArguments0(adapter, skip+ match, addTypes);
    }
    // adapter: (S*[skip],        M*[match], A*[add] )
    if (pos > 0) {
        adapter = dropArguments0(adapter, skip, newTypes.subList(0, pos));
    }
    // adapter: (S*[skip], P*[pos], M*[match], A*[add] )
    return adapter;
}
 
Example 16
Project: BaseClient   File: TileEntityBrewingStand.java   View Source Code Vote up 4 votes
private boolean canBrew()
{
    if (this.brewingItemStacks[3] != null && this.brewingItemStacks[3].stackSize > 0)
    {
        ItemStack itemstack = this.brewingItemStacks[3];

        if (!itemstack.getItem().isPotionIngredient(itemstack))
        {
            return false;
        }
        else
        {
            boolean flag = false;

            for (int i = 0; i < 3; ++i)
            {
                if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potionitem)
                {
                    int j = this.brewingItemStacks[i].getMetadata();
                    int k = this.getPotionResult(j, itemstack);

                    if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
                    {
                        flag = true;
                        break;
                    }

                    List<PotionEffect> list = Items.potionitem.getEffects(j);
                    List<PotionEffect> list1 = Items.potionitem.getEffects(k);

                    if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k)
                    {
                        flag = true;
                        break;
                    }
                }
            }

            return flag;
        }
    }
    else
    {
        return false;
    }
}
 
Example 17
Project: openjdk-jdk10   File: EdgeCases.java   View Source Code Vote up 4 votes
@Test
public void testWrongPackageInExportedPackage(Path base) throws Exception {
    Path src = base.resolve("src");
    Path m = src.resolve("m");
    tb.writeJavaFiles(m,
                      "module m { exports api; }");
    Path apiFile = m.resolve("api").resolve("Api.java");
    Files.createDirectories(apiFile.getParent());
    try (BufferedWriter w = Files.newBufferedWriter(apiFile)) {
        w.write("package impl; public class Api { }");
    }
    Path classes = base.resolve("classes");
    tb.createDirectories(classes);

    List<String> log;

    List<String> expected =
            Arrays.asList("module-info.java:1:20: compiler.err.package.empty.or.not.found: api",
                          "1 error");

    System.err.println("file explicitly specified:");

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--module-source-path", src.toString())
            .outdir(classes)
            .files(findJavaFiles(src))
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log))
        throw new Exception("expected output not found: " + log);

    System.err.println("file not specified:");

    tb.cleanDirectory(classes);

    log = new JavacTask(tb)
            .options("-XDrawDiagnostics",
                     "--module-source-path", src.toString())
            .outdir(classes)
            .files(findJavaFiles(m.resolve("module-info.java")))
            .run(Task.Expect.FAIL)
            .writeAll()
            .getOutputLines(Task.OutputKind.DIRECT);

    if (!expected.equals(log))
        throw new Exception("expected output not found: " + log);
}
 
Example 18
Project: DecompiledMinecraft   File: TileEntityBrewingStand.java   View Source Code Vote up 4 votes
private boolean canBrew()
{
    if (this.brewingItemStacks[3] != null && this.brewingItemStacks[3].stackSize > 0)
    {
        ItemStack itemstack = this.brewingItemStacks[3];

        if (!itemstack.getItem().isPotionIngredient(itemstack))
        {
            return false;
        }
        else
        {
            boolean flag = false;

            for (int i = 0; i < 3; ++i)
            {
                if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potionitem)
                {
                    int j = this.brewingItemStacks[i].getMetadata();
                    int k = this.getPotionResult(j, itemstack);

                    if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
                    {
                        flag = true;
                        break;
                    }

                    List<PotionEffect> list = Items.potionitem.getEffects(j);
                    List<PotionEffect> list1 = Items.potionitem.getEffects(k);

                    if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k)
                    {
                        flag = true;
                        break;
                    }
                }
            }

            return flag;
        }
    }
    else
    {
        return false;
    }
}
 
Example 19
Project: BaseClient   File: TileEntityBrewingStand.java   View Source Code Vote up 4 votes
private void brewPotions()
{
    if (this.canBrew())
    {
        ItemStack itemstack = this.brewingItemStacks[3];

        for (int i = 0; i < 3; ++i)
        {
            if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potionitem)
            {
                int j = this.brewingItemStacks[i].getMetadata();
                int k = this.getPotionResult(j, itemstack);
                List<PotionEffect> list = Items.potionitem.getEffects(j);
                List<PotionEffect> list1 = Items.potionitem.getEffects(k);

                if (j > 0 && list == list1 || list != null && (list.equals(list1) || list1 == null))
                {
                    if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
                    {
                        this.brewingItemStacks[i].setItemDamage(k);
                    }
                }
                else if (j != k)
                {
                    this.brewingItemStacks[i].setItemDamage(k);
                }
            }
        }

        if (itemstack.getItem().hasContainerItem())
        {
            this.brewingItemStacks[3] = new ItemStack(itemstack.getItem().getContainerItem());
        }
        else
        {
            --this.brewingItemStacks[3].stackSize;

            if (this.brewingItemStacks[3].stackSize <= 0)
            {
                this.brewingItemStacks[3] = null;
            }
        }
    }
}
 
Example 20
Project: openjdk-jdk10   File: PriorityQueueSort.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    int n = 10000;
    if (args.length > 0)
        n = Integer.parseInt(args[0]);

    List<Integer> sorted = new ArrayList<>(n);
    for (int i = 0; i < n; i++)
        sorted.add(new Integer(i));
    List<Integer> shuffled = new ArrayList<>(sorted);
    Collections.shuffle(shuffled);

    Queue<Integer> pq = new PriorityQueue<>(n, new MyComparator());
    for (Iterator<Integer> i = shuffled.iterator(); i.hasNext(); )
        pq.add(i.next());

    List<Integer> recons = new ArrayList<>();
    while (!pq.isEmpty())
        recons.add(pq.remove());
    if (!recons.equals(sorted))
        throw new RuntimeException("Sort test failed");

    recons.clear();
    pq = new PriorityQueue<>(shuffled);
    while (!pq.isEmpty())
        recons.add(pq.remove());
    if (!recons.equals(sorted))
        throw new RuntimeException("Sort test failed");

    // Remove all odd elements from queue
    pq = new PriorityQueue<>(shuffled);
    for (Iterator<Integer> i = pq.iterator(); i.hasNext(); )
        if ((i.next().intValue() & 1) == 1)
            i.remove();
    recons.clear();
    while (!pq.isEmpty())
        recons.add(pq.remove());

    for (Iterator<Integer> i = sorted.iterator(); i.hasNext(); )
        if ((i.next().intValue() & 1) == 1)
            i.remove();

    if (!recons.equals(sorted))
        throw new RuntimeException("Iterator remove test failed.");
}