Example usage for java.util List equals

List of usage examples for java.util List equals

Introduction

In this page you can find the example usage for java.util List equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this list for equality.

Usage

From source file:com.bluexml.xforms.generator.FormGeneratorsManager.java

/**
 * Tests for the presence of the given list amongst the registered lists. We just test whether a
 * registered list 'equals' this one./*from   w w w. j  a  va  2s  .  c om*/
 * 
 * @param opList
 *            the list to check
 * @return the registration key, or null if the list is not registered.
 * @see {@link #getSearchOperatorsListId(SearchField)} for details about the key (or id).
 */
private String testOperatorList(List<SearchOperator> opList) {
    for (String key : operatorsEnumsMap.keySet()) {
        if (opList.equals(operatorsEnumsMap.get(key))) {
            return key;
        }
    }
    return null;
}

From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java

@Test
public void testMutateChromosome() {
    liberalMutationAlgorithm.setMaxMutationsPerChromosome(MAX_MUTATIONS);

    MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome();
    mockKeylessChromosome.setTargetSize(6);
    List<Gene> originalGenes = new ArrayList<Gene>();

    MockGene mockGene1 = new MockGene();
    mockGene1.addSequence(new MockSequence("a"));
    mockGene1.addSequence(new MockSequence("b"));
    mockGene1.addSequence(new MockSequence("c"));
    mockKeylessChromosome.addGene(mockGene1);
    originalGenes.add(mockGene1);/* w  ww.  jav  a2 s  .com*/

    MockGene mockGene2 = new MockGene();
    mockGene2.addSequence(new MockSequence("1"));
    mockGene2.addSequence(new MockSequence("2"));
    mockGene2.addSequence(new MockSequence("3"));
    mockKeylessChromosome.addGene(mockGene2);
    originalGenes.add(mockGene2);

    MockGene mockGeneToReturn = new MockGene();
    mockGeneToReturn.addSequence(new MockSequence("x"));
    mockGeneToReturn.addSequence(new MockSequence("y"));
    mockGeneToReturn.addSequence(new MockSequence("z"));
    when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenReturn(mockGeneToReturn.clone(),
            mockGeneToReturn.clone());

    liberalMutationAlgorithm.mutateChromosome(mockKeylessChromosome);

    assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes()));
    verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome));
    verify(geneDaoMock, atMost(2)).findRandomGene(same(mockKeylessChromosome));
    verify(chromosomeHelperSpy, atLeastOnce()).resizeChromosome(same(mockKeylessChromosome));
    verify(chromosomeHelperSpy, atMost(2)).resizeChromosome(same(mockKeylessChromosome));
    verifyZeroInteractions(logMock);
}

From source file:org.jahia.test.services.render.filter.cache.base.CacheFilterHttpTest.java

@Test
@SuppressWarnings("unchecked")
public void testRandomFlush() throws Exception {
    JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession("live", new Locale("en"));
    Query q = session.getWorkspace().getQueryManager().createQuery(
            "select * from [jnt:page] as p where isdescendantnode(p,'" + SITECONTENT_ROOT_NODE + "/home')",
            Query.JCR_SQL2);// ww  w. ja v  a2  s. com
    List<String> paths = new ArrayList<String>();
    NodeIterator nodes = q.execute().getNodes();
    Set<String> skipped = new HashSet<>(Arrays.asList("long", "error", "user-per-content-test", "simple-page-A",
            "simple-page-B", "simple-page-C", "simple-page-AC", "simple-page-BC", "simple-page-AB",
            "simple-page-root", "simple-page-users"));
    while (nodes.hasNext()) {
        JCRNodeWrapper next = (JCRNodeWrapper) nodes.next();
        if (!skipped.contains(next.getName())) {
            paths.add(next.getPath());
        }
    }
    List<String> users = Arrays.asList("userAB", "userAC", "userBC");
    Map<String, String> m = new HashMap<String, String>();
    for (String user : users) {
        for (String path : paths) {
            m.put(user + path, getContent(getUrl(path), user, "password", null));
        }
    }

    final Cache cache = ModuleCacheProvider.getInstance().getCache();
    List<String> keysBefore = cache.getKeys();

    Map<String, Object> cacheCopy = new HashMap<String, Object>();
    for (String s : keysBefore) {
        final Element element = cache.get(s);
        if (element != null) {
            cacheCopy.put(s, element.getObjectValue());
        }
    }

    for (int j = 0; j < 10; j++) {
        System.out.println("flush " + j);
        List<String> toFlush = randomizeFlush(keysBefore, 10);
        for (String user : users) {
            for (String path : paths) {
                System.out.println(user + " - " + path);
                assertEquals("Different content for " + user + " , " + path + " when flushing : " + toFlush,
                        m.get(user + path), getContent(getUrl(path), user, "password", null));

                checkCacheContent(cache, cacheCopy, toFlush);
            }
        }
        List<String> keysAfter = cache.getKeys();
        Collections.sort(keysBefore);
        Collections.sort(keysAfter);
        if (!keysBefore.equals(keysAfter)) {
            List<String> onlyInBefore = new ArrayList<String>(keysBefore);
            onlyInBefore.removeAll(keysAfter);
            List<String> onlyInAfter = new ArrayList<String>(keysAfter);
            onlyInAfter.removeAll(keysBefore);
            fail("Key sets are not the same before and after flushing : " + toFlush + "\n Before flushs :"
                    + onlyInBefore + " ,\n After flush : " + onlyInAfter);
        }
        checkCacheContent(cache, cacheCopy, toFlush);
    }
}

From source file:com.leanplum.Leanplum.java

/**
 * Applies the variables, messages, or update rules in a start or getVars response.
 *
 * @param response The response containing content.
 * @param alwaysApply Always apply the content regardless of whether the content changed.
 *//*from  w  w  w. j  ava2  s  .  co  m*/
private static void applyContentInResponse(JSONObject response, boolean alwaysApply) {
    Map<String, Object> values = JsonConverter
            .mapFromJsonOrDefault(response.optJSONObject(Constants.Keys.VARS));
    Map<String, Object> messages = JsonConverter
            .mapFromJsonOrDefault(response.optJSONObject(Constants.Keys.MESSAGES));
    List<Map<String, Object>> updateRules = JsonConverter
            .listFromJsonOrDefault(response.optJSONArray(Constants.Keys.UPDATE_RULES));
    List<Map<String, Object>> eventRules = JsonConverter
            .listFromJsonOrDefault(response.optJSONArray(Constants.Keys.EVENT_RULES));
    Map<String, Object> regions = JsonConverter
            .mapFromJsonOrDefault(response.optJSONObject(Constants.Keys.REGIONS));
    List<Map<String, Object>> variants = JsonConverter
            .listFromJsonOrDefault(response.optJSONArray(Constants.Keys.VARIANTS));

    if (alwaysApply || !values.equals(VarCache.getDiffs()) || !messages.equals(VarCache.getMessageDiffs())
            || !updateRules.equals(VarCache.getUpdateRuleDiffs())
            || !eventRules.equals(VarCache.getEventRuleDiffs()) || !regions.equals(VarCache.regions())) {
        VarCache.applyVariableDiffs(values, messages, updateRules, eventRules, regions, variants);
    }
}

From source file:com.haibison.android.lockpattern.LockPatternFragment.java

/**
 * Compares {@code pattern} to the given pattern (
 * {@link #ACTION_COMPARE_PATTERN}) or to the generated "CAPTCHA" pattern (
 * {@link #ACTION_VERIFY_CAPTCHA}). Then finishes the activity if they
 * match./*  ww w.j  av  a  2s . c o m*/
 *
 * @param pattern
 *            the pattern to be compared.
 */
private void doComparePattern(final List<Cell> pattern) {
    if (pattern == null)
        return;

    /*
     * Use a LoadingDialog because decrypting pattern might take time...
     */

    new LoadingDialog<Void, Void, Boolean>(getActivity(), false) {

        @Override
        protected Boolean doInBackground(Void... params) {
            if (ACTION_COMPARE_PATTERN.equals(fa.getIntent().getAction())) {
                char[] currentPattern = fa.getIntent().getCharArrayExtra(EXTRA_PATTERN);
                if (currentPattern == null)
                    currentPattern = Settings.Security.getPattern(getActivity());
                if (currentPattern != null) {
                    if (mEncrypter != null)
                        return pattern.equals(mEncrypter.decrypt(getActivity(), currentPattern));
                    else
                        return Arrays.equals(currentPattern,
                                LockPatternUtils.patternToSha256(pattern).toCharArray());
                }
            } // ACTION_COMPARE_PATTERN
            else if (ACTION_VERIFY_CAPTCHA.equals(fa.getIntent().getAction())) {
                return pattern.equals(fa.getIntent().getParcelableArrayListExtra(EXTRA_PATTERN));
            } // ACTION_VERIFY_CAPTCHA

            return false;
        }// doInBackground()

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);

            if (result)
                finishWithResultOk(null);
            else {
                mRetryCount++;
                mIntentResult.putExtra(EXTRA_RETRY_COUNT, mRetryCount);

                if (mRetryCount >= mMaxRetries)
                    finishWithNegativeResult(RESULT_FAILED);
                else {
                    mLockPatternView.setDisplayMode(DisplayMode.Wrong);
                    mTextInfo.setText(R.string.alp_42447968_msg_try_again);
                    mLockPatternView.postDelayed(mLockPatternViewReloader,
                            DELAY_TIME_TO_RELOAD_LOCK_PATTERN_VIEW);
                }
            }
        }// onPostExecute()

    }.execute();
}

From source file:au.org.ala.delta.intkey.directives.invocation.UseDirectiveInvocation.java

/**
 * Cleans up the specimen after the prompt for a character value is
 * cancelled, or returns successfully but with no values specified. The
 * values for any automatically-set controlling characters are removed from
 * the specimen, unless they are higher in the dependency hierarchy than a
 * manually set controlling character.//from  www .j  a  v a 2 s  .  co m
 * 
 * @param setControllingCharacters
 *            A list of all controlling characters that were set, in the
 *            order that they were set.
 * @param manuallySetControllingCharacters
 *            A list of all manually set controlling characters, in the
 *            order that they were set
 * @param specimen
 *            the specimen.
 */
private void cleanupSpecimenAfterCancel(List<Character> setControllingCharacters,
        List<Character> manuallySetControllingCharacters, Specimen specimen) {
    List<Character> charsToRemoveFromSpecimen = new ArrayList<Character>();

    if (manuallySetControllingCharacters.isEmpty()) {
        charsToRemoveFromSpecimen.addAll(setControllingCharacters);
    } else {
        Character lastManuallySetCharacter = manuallySetControllingCharacters
                .get(manuallySetControllingCharacters.size() - 1);
        charsToRemoveFromSpecimen.addAll(
                setControllingCharacters.subList(setControllingCharacters.indexOf(lastManuallySetCharacter) + 1,
                        setControllingCharacters.size()));
    }

    for (Character ch : charsToRemoveFromSpecimen) {
        specimen.removeValueForCharacter(ch);
    }

    // If all values set for controlling characters have been removed, the
    // net change to the specimen is zero. Hence it does not need to be
    // considered updated.
    if (charsToRemoveFromSpecimen.equals(setControllingCharacters)) {
        _specimenUpdated = false;
    }
}

From source file:com.haibison.android.lockpattern.LockPatternFragment.java

/**
 * Checks and creates the pattern./*from  w w  w  . ja  v a 2  s. co  m*/
 *
 * @param pattern
 *            the current pattern of lock pattern view.
 */
private void doCheckAndCreatePattern(final List<Cell> pattern) {
    if (pattern.size() < mMinWiredDots) {
        mLockPatternView.setDisplayMode(DisplayMode.Wrong);
        mTextInfo.setText(getResources().getQuantityString(R.plurals.alp_42447968_pmsg_connect_x_dots,
                mMinWiredDots, mMinWiredDots));
        mLockPatternView.postDelayed(mLockPatternViewReloader, DELAY_TIME_TO_RELOAD_LOCK_PATTERN_VIEW);
        return;
    }

    if (fa.getIntent().hasExtra(EXTRA_PATTERN)) {
        /*
         * Use a LoadingDialog because decrypting pattern might take time...
         */
        new LoadingDialog<Void, Void, Boolean>(getActivity(), false) {

            @Override
            protected Boolean doInBackground(Void... params) {
                if (mEncrypter != null)
                    return pattern.equals(
                            mEncrypter.decrypt(getActivity(), fa.getIntent().getCharArrayExtra(EXTRA_PATTERN)));
                else
                    return Arrays.equals(fa.getIntent().getCharArrayExtra(EXTRA_PATTERN),
                            LockPatternUtils.patternToSha256(pattern).toCharArray());
            }// doInBackground()

            @Override
            protected void onPostExecute(Boolean result) {
                super.onPostExecute(result);

                if (result) {
                    mTextInfo.setText(R.string.alp_42447968_msg_your_new_unlock_pattern);
                    mBtnConfirm.setEnabled(true);
                } else {
                    mTextInfo.setText(R.string.alp_42447968_msg_redraw_pattern_to_confirm);
                    mBtnConfirm.setEnabled(false);
                    mLockPatternView.setDisplayMode(DisplayMode.Wrong);
                    mLockPatternView.postDelayed(mLockPatternViewReloader,
                            DELAY_TIME_TO_RELOAD_LOCK_PATTERN_VIEW);
                }
            }// onPostExecute()

        }.execute();
    } else {
        /*
         * Use a LoadingDialog because encrypting pattern might take time...
         */
        new LoadingDialog<Void, Void, char[]>(getActivity(), false) {

            @Override
            protected char[] doInBackground(Void... params) {
                return mEncrypter != null ? mEncrypter.encrypt(getActivity(), pattern)
                        : LockPatternUtils.patternToSha256(pattern).toCharArray();
            }// onCancel()

            @Override
            protected void onPostExecute(char[] result) {
                super.onPostExecute(result);

                fa.getIntent().putExtra(EXTRA_PATTERN, result);
                mTextInfo.setText(R.string.alp_42447968_msg_pattern_recorded);
                mBtnConfirm.setEnabled(true);
            }// onPostExecute()

        }.execute();
    }
}

From source file:org.omnaest.utils.table.TableTest.java

@Test
public void testExecuteWithLocks() throws InterruptedException, ExecutionException {
    final Table<String> table = this.filledTableWithTitles(100, 3);

    ExecutorService executorService = Executors.newFixedThreadPool(10);
    final List<Future<Boolean>> futureList = new ArrayList<Future<Boolean>>();
    for (int ii = 0; ii < 10; ii++) {
        futureList.add(executorService.submit(new Callable<Boolean>() {
            @Override/*from  ww  w  .  j a v  a 2s. c  o m*/
            public Boolean call() throws Exception {
                final AtomicBoolean retval = new AtomicBoolean();

                table.executeWithReadLock(new TableExecution<ImmutableTable<String>, String>() {
                    @Override
                    public void execute(ImmutableTable<String> table) {
                        ImmutableRow<String> row = table.row(10);
                        final List<String> elementList = row.to().list();

                        try {
                            Thread.sleep(5);
                        } catch (InterruptedException e) {
                        }

                        retval.set(elementList.equals(table.row(10).to().list()));
                    }

                });

                return retval.get();
            }
        }));
        futureList.add(executorService.submit(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                final AtomicBoolean retval = new AtomicBoolean();

                table.executeWithWriteLock(new TableExecution<Table<String>, String>() {
                    @Override
                    public void execute(Table<String> table) {
                        Row<String> row = table.row(10);
                        row.cell(1).setElement("xxx" + Math.random());
                        final List<String> elementList = row.to().list();

                        try {
                            Thread.sleep(5);
                        } catch (InterruptedException e) {
                        }

                        retval.set(elementList.equals(table.row(10).to().list()));
                    }
                });

                return retval.get();
            }
        }));
    }

    executorService.shutdown();

    for (Future<Boolean> future : futureList) {
        assertTrue(future.get());
    }
}

From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java

@Test
public void testMutateChromosomeGreaterThanTargetSize() {
    liberalMutationAlgorithm.setMaxMutationsPerChromosome(MAX_MUTATIONS);

    MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome();
    mockKeylessChromosome.setTargetSize(6);
    List<Gene> originalGenes = new ArrayList<Gene>();

    MockGene mockGene1 = new MockGene();
    mockGene1.addSequence(new MockSequence("a"));
    mockGene1.addSequence(new MockSequence("b"));
    mockGene1.addSequence(new MockSequence("c"));
    mockKeylessChromosome.addGene(mockGene1);
    originalGenes.add(mockGene1);//ww w  .j  av a  2  s  .c  om

    MockGene mockGene2 = new MockGene();
    mockGene2.addSequence(new MockSequence("1"));
    mockGene2.addSequence(new MockSequence("2"));
    mockGene2.addSequence(new MockSequence("3"));
    mockKeylessChromosome.addGene(mockGene2);
    originalGenes.add(mockGene2);

    MockGene mockGeneToReturn = new MockGene();
    mockGeneToReturn.addSequence(new MockSequence("w"));
    mockGeneToReturn.addSequence(new MockSequence("x"));
    mockGeneToReturn.addSequence(new MockSequence("y"));
    mockGeneToReturn.addSequence(new MockSequence("z"));
    when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenReturn(mockGeneToReturn.clone(),
            mockGeneToReturn.clone());

    assertEquals(3, mockGene1.size());
    assertEquals(3, mockGene2.size());
    assertEquals(4, mockGeneToReturn.size());

    liberalMutationAlgorithm.mutateChromosome(mockKeylessChromosome);

    assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes()));
    assertEquals(2, mockKeylessChromosome.getGenes().size());
    assertEquals(new Integer(6), mockKeylessChromosome.actualSize());
    verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome));
    verify(geneDaoMock, atMost(2)).findRandomGene(same(mockKeylessChromosome));
    verify(chromosomeHelperSpy, atLeastOnce()).resizeChromosome(same(mockKeylessChromosome));
    verify(chromosomeHelperSpy, atMost(2)).resizeChromosome(same(mockKeylessChromosome));
    verifyZeroInteractions(logMock);
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtil.java

/**
 * Determine if the suffix of one string is the prefix of another.
 *
 * @param list1 First string./*w  w w.  j  a v  a  2 s  .  c  om*/
 * @param list2 Second string.
 * @return The number of characters common to the end of the first
 *         string and the start of the second string.
 */
protected int diff_commonOverlap(List<T> list1, List<T> list2) {
    // Cache the text lengths to prevent multiple calls.
    int text1_length = list1.size();
    int text2_length = list2.size();
    // Eliminate the null case.
    if (text1_length == 0 || text2_length == 0) {
        return 0;
    }
    // Truncate the longer string.
    if (text1_length > text2_length) {
        list1 = list1.subList(text1_length - text2_length, list1.size());
    } else if (text1_length < text2_length) {
        list2 = list2.subList(0, text1_length);
    }
    int text_length = Math.min(text1_length, text2_length);
    // Quick check for the worst case.
    if (list1.equals(list2)) {
        return text_length;
    }

    // Start by looking for a single character match
    // and increase length until no match is found.
    // Performance analysis: http://neil.fraser.name/news/2010/11/04/
    int best = 0;
    int length = 1;
    while (true) {
        List<T> pattern = list1.subList(text_length - length, list1.size());
        int found = list2.indexOf(pattern); //TODO
        if (found == -1) {
            return best;
        }
        length += found;
        if (found == 0 || list1.subList(text_length - length, list1.size()).equals(list2.subList(0, length))) {
            best = length;
            length++;
        }
    }
}