Example usage for java.util HashSet remove

List of usage examples for java.util HashSet remove

Introduction

In this page you can find the example usage for java.util HashSet remove.

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the specified element from this set if it is present.

Usage

From source file:fr.msch.wissl.server.TestIndexer.java

public void test() throws Exception {
    HttpClient client = new HttpClient();

    // /indexer/status as user: 401
    GetMethod get = new GetMethod(URL + "indexer/status");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);//from w w  w. java  2s . co m
    Assert.assertEquals(401, get.getStatusCode());

    // /indexer/status as admin: 200
    get = new GetMethod(URL + "indexer/status");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    JSONObject obj = new JSONObject(get.getResponseBodyAsString());
    // won't try to check the actual content of this object,
    // since I can't predict easily and accurately if 
    // the Indexer will be in Running or Sleeping state at a given time.
    assertTrue(obj.has("running"));
    assertTrue(obj.has("percentDone"));
    assertTrue(obj.has("secondsLeft"));
    assertTrue(obj.has("songsDone"));
    assertTrue(obj.has("songsTodo"));

    // /indexer/rescan as user: 401
    PostMethod post = new PostMethod(URL + "indexer/rescan");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /indexer/rescan as amdin
    post = new PostMethod(URL + "indexer/rescan");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(204, post.getStatusCode());

    // /folders as user: 401
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(401, get.getStatusCode());

    // /folders: should be empty
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(0, obj.getJSONArray("folders").length());

    // /folders/listing as user: 401
    get = new GetMethod(URL + "folders/listing");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(401, get.getStatusCode());

    // /folders/listing on some file that does not exist: 404
    get = new GetMethod(URL + "folders/listing?directory=/does/not/exist");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(404, get.getStatusCode());

    File exp_home = new File(System.getProperty("user.home"));

    // /folders/listing with no arg: homedir
    get = new GetMethod(URL + "folders/listing");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    File dir = new File(obj.getString("directory"));
    assertEquals(exp_home.getAbsolutePath(), dir.getAbsolutePath());
    assertEquals(exp_home.getParentFile().getAbsolutePath(), dir.getParentFile().getAbsolutePath());
    assertTrue(obj.getJSONArray("listing").length() > 0);

    // /folders/listing with arg '$ROOT'
    get = new GetMethod(URL + "folders/listing?directory=$ROOT");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    File[] dirs = File.listRoots();
    assertEquals("", obj.getString("directory"));
    assertEquals("$ROOT", obj.getString("parent"));
    JSONArray arr = obj.getJSONArray("listing");
    HashSet<String> hs = new HashSet<String>(arr.length());
    for (int i = 0; i < arr.length(); i++) {
        hs.add(new File(arr.getString(i)).getAbsolutePath());
    }
    for (File d : dirs) {
        // on windows, listRoots returns a bunch of drive names that don't exist
        if (d.exists()) {
            assertTrue(hs.remove(d.getAbsolutePath()));
        }
    }
    assertTrue(hs.isEmpty());

    // lists test resources folder
    File f = new File("src/test/resources/data2");
    get = new GetMethod(URL + "folders/listing?directory=" + URIUtil.encodeQuery(f.getAbsolutePath()));
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    dir = new File(obj.getString("directory"));
    assertEquals(f.getAbsolutePath(), dir.getAbsolutePath());
    assertEquals(f.getParentFile().getAbsolutePath(), dir.getParentFile().getAbsolutePath());
    dirs = dir.listFiles();
    arr = obj.getJSONArray("listing");
    assertEquals(2, arr.length());
    assertEquals(new File("src/test/resources/data2/sub1").getAbsolutePath(), arr.get(0));
    assertEquals(new File("src/test/resources/data2/sub2").getAbsolutePath(), arr.get(1));

    // /folders/add as user: 401
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", "/");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /folders/add : directory does not exist: 404
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", "/does/not/exist");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(404, post.getStatusCode());

    // /folders/add : not a directory: 400
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", new File("src/test/resources/data/1.mp3").getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // /folders/add "/src/test/resources/data"
    f = new File("src/test/resources/data");
    RuntimeStats rt = new RuntimeStats();
    rt.songCount.set(15);
    rt.albumCount.set(5);
    rt.artistCount.set(2);
    rt.playlistCount.set(0);
    rt.userCount.set(2);
    rt.playtime.set(15);
    rt.downloaded.set(0);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // check /folders
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(f.getAbsolutePath(), obj.getJSONArray("folders").getString(0));

    // /folders/add "/src/test/resources/data2/sub1"
    f = new File("src/test/resources/data2/sub1");
    rt.songCount.addAndGet(3);
    rt.albumCount.addAndGet(1);
    rt.artistCount.addAndGet(1);
    rt.playtime.addAndGet(3);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // /folders/add "/src/test/resources/data2/"
    f = new File("src/test/resources/data2/");
    rt.songCount.addAndGet(6);
    rt.playtime.addAndGet(6);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // check /folders
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    arr = obj.getJSONArray("folders");
    assertEquals(3, arr.length());
    for (int i = 0; i < 3; i++) {
        String s = new File(arr.getString(i)).getAbsolutePath();
        String s1 = new File("src/test/resources/data").getAbsolutePath();
        String s2 = new File("src/test/resources/data2/sub1").getAbsolutePath();
        String s3 = new File("src/test/resources/data2").getAbsolutePath();
        assertTrue(s.equals(s1) || s.equals(s2) || s.equals(s3));
    }

    // /folders/remove as user: 401
    post = new PostMethod(URL + "folders/remove");
    post.addParameter("directory[]", "/");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /folders/remove unknown dir: 400
    post = new PostMethod(URL + "folders/remove");
    post.addParameter("directory[]", "/does/not/exist");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // /folders/remove "/src/test/resources/data","src/test/resources/data2"
    post = new PostMethod(URL + "folders/remove");
    f = new File("src/test/resources/data");
    post.addParameter("directory[]", f.getAbsolutePath());
    f = new File("src/test/resources/data2");
    post.addParameter("directory[]", f.getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    assertEquals(204, post.getStatusCode());

    rt.songCount.set(3);
    rt.albumCount.set(1);
    rt.artistCount.set(1);
    rt.userCount.set(2);
    rt.playtime.set(3);
    rt.downloaded.set(0);
    this.checkStats(rt);

    // /folders/remove "/src/test/resources/data/sub1"
    post = new PostMethod(URL + "folders/remove");
    f = new File("src/test/resources/data2/sub1");
    post.addParameter("directory[]", f.getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    assertEquals(204, post.getStatusCode());

    rt.songCount.set(0);
    rt.albumCount.set(0);
    rt.artistCount.set(0);
    rt.userCount.set(2);
    rt.playtime.set(0);
    rt.downloaded.set(0);
    this.checkStats(rt);

    // /folders: should be empty
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(0, obj.getJSONArray("folders").length());

}

From source file:org.jlinda.core.coregistration.estimation.utils.MathUtils.java

/**
 * Runs the reverse Cuthill-McKee algorithm on the adjacency lists
 * to provide an efficient ordering of the vertices
 *
 * @param adjacencyLists a list of the adjacency lists of the graph
 * @param startingVertex the vertex to start in the ordering
 * @return a permutation of the vertices that is efficient for a sparse matrix
 *//* w  w w .ja v a  2s  . co m*/
private static int[] reverseCuthillMcKee(int[][] adjacencyLists, int startingVertex) {

    // error check args
    if (startingVertex < 0 || startingVertex >= adjacencyLists.length) {
        throw new IllegalArgumentException("startingVertex must be in [0," + adjacencyLists.length + ").");
    }

    int numVertices = adjacencyLists.length;
    HashSet<Integer> unvisitedVertices = new HashSet<Integer>();

    // determine the branching factors of each vertex
    int[] branchingFactors = new int[numVertices];
    for (int v = 0; v < numVertices; v++) {
        branchingFactors[v] = adjacencyLists[v].length;
        unvisitedVertices.add(v);
    }

    ArrayList<Integer> ordering = new ArrayList<Integer>();

    // start at the given vertex
    ordering.add(startingVertex);
    unvisitedVertices.remove(startingVertex);

    int i = 0;
    // keep looping until all vertices have been explored
    while (ordering.size() < numVertices) {

        // if we've reached the end of one component of the graph, start another
        if (i == ordering.size()) {
            // determine the lowest branching factor of the unvisitedVertices
            int minBranchingFactor = Integer.MAX_VALUE;
            int minBranchingFactorVertex = -1;
            for (int v : unvisitedVertices) {
                if (branchingFactors[v] < minBranchingFactor) {
                    minBranchingFactor = branchingFactors[v];
                    minBranchingFactorVertex = v;
                }
            }
            // start again with that vertex
            ordering.add(minBranchingFactorVertex);
            unvisitedVertices.remove(minBranchingFactorVertex);
        }

        int currVertex = ordering.get(i++);

        // sort the neighbors in increasing order
        int[] neighborDegrees = new int[adjacencyLists[currVertex].length];
        for (int nIdx = 0; nIdx < adjacencyLists[currVertex].length; nIdx++) {
            int neighbor = adjacencyLists[currVertex][nIdx];
            neighborDegrees[nIdx] = branchingFactors[neighbor];
        }
        int[] neighborOrder = MathUtils.sortOrder(neighborDegrees);

        // append unvisited neighbors to the ordering
        for (int nIdx : neighborOrder) {
            int neighbor = adjacencyLists[currVertex][nIdx];
            if (unvisitedVertices.contains(neighbor)) {
                ordering.add(neighbor);
                unvisitedVertices.remove(neighbor);
            }
        }
    }

    // return the reverse ordering
    int[] permutation = new int[ordering.size()];
    i = ordering.size() - 1;
    for (int v : ordering) {
        permutation[i--] = v;
    }
    return permutation;
}

From source file:org.apache.accumulo.examples.wikisearch.parser.QueryEvaluator.java

/**
 * Evaluates the query against an event.
 * //from w w  w. j a v a  2s  .  c o m
 * @param eventFields
 */
public boolean evaluate(EventFields eventFields) {

    this.modifiedQuery = null;
    boolean rewritten = false;

    // Copy the query
    StringBuilder q = new StringBuilder(query);
    // Copy the literals, we are going to remove elements from this set
    // when they are added to the JEXL context. This will allow us to
    // determine which items in the query where *NOT* in the data.
    HashSet<String> literalsCopy = new HashSet<String>(literals);

    // Loop through the event fields and add them to the JexlContext.
    for (Entry<String, Collection<FieldValue>> field : eventFields.asMap().entrySet()) {
        String fName = field.getKey();
        if (caseInsensitive) {
            fName = fName.toLowerCase();
        }
        // If this field is not part of the expression, then skip it.
        if (!literals.contains(fName)) {
            continue;
        } else {
            literalsCopy.remove(fName);
        }

        // This field may have multiple values.
        if (field.getValue().size() == 0) {
            continue;
        } else if (field.getValue().size() == 1) {
            // We are explicitly converting these bytes to a String.
            if (caseInsensitive) {
                ctx.set(field.getKey().toLowerCase(),
                        (new String(field.getValue().iterator().next().getValue())).toLowerCase());
            } else {
                ctx.set(field.getKey(), new String(field.getValue().iterator().next().getValue()));
            }

        } else {
            // q = queryRewrite(q, field.getKey(), field.getValue());
            q = rewriteQuery(q, field.getKey(), field.getValue());
            rewritten = true;
        } // End of if

    } // End of loop

    // For any literals in the query that were not found in the data, add them to the context
    // with a null value.
    for (String lit : literalsCopy) {
        ctx.set(lit, null);
    }

    if (log.isDebugEnabled()) {
        log.debug("Evaluating query: " + q.toString());
    }

    this.modifiedQuery = q.toString();

    Boolean result = null;
    if (rewritten) {
        Script script = engine.createScript(this.modifiedQuery);
        try {
            result = (Boolean) script.execute(ctx);
        } catch (Exception e) {
            log.error("Error evaluating script: " + this.modifiedQuery + " against event"
                    + eventFields.toString(), e);
        }
    } else {
        Expression expr = engine.createExpression(this.modifiedQuery);
        try {
            result = (Boolean) expr.evaluate(ctx);
        } catch (Exception e) {
            log.error("Error evaluating expression: " + this.modifiedQuery + " against event"
                    + eventFields.toString(), e);
        }
    }
    if (null != result && result) {
        return true;
    } else {
        return false;
    }
}

From source file:android.support.design.widget.DirectedAcyclicGraph.java

private void dfs(final T node, final ArrayList<T> result, final HashSet<T> tmpMarked) {
    if (result.contains(node)) {
        // We've already seen and added the node to the result list, skip...
        return;//from w  w  w.  jav  a 2s  . c  o m
    }
    if (tmpMarked.contains(node)) {
        throw new RuntimeException("This graph contains cyclic dependencies");
    }
    // Temporarily mark the node
    tmpMarked.add(node);
    // Recursively dfs all of the node's edges
    final ArrayList<T> edges = mGraph.get(node);
    if (edges != null) {
        for (int i = 0, size = edges.size(); i < size; i++) {
            dfs(edges.get(i), result, tmpMarked);
        }
    }
    // Unmark the node from the temporary list
    tmpMarked.remove(node);
    // Finally add it to the result list
    result.add(node);
}

From source file:org.pentaho.platform.scheduler.QuartzSubscriptionScheduler.java

/**
 * Returns a list of exception messages/*  w  w w .  ja  v  a  2  s . c om*/
 */
public List syncSchedule(final List newSchedules) throws Exception {
    List exceptionList = new ArrayList();
    if (newSchedules == null) {
        return (exceptionList);
    }

    Scheduler scheduler = QuartzSystemListener.getSchedulerInstance();
    HashSet jobSet = new HashSet(Arrays.asList(scheduler.getJobNames(QuartzSubscriptionScheduler.GROUP_NAME)));

    // Add/modify the good schedules
    for (int i = 0; i < newSchedules.size(); ++i) {
        ISchedule sched = (ISchedule) newSchedules.get(i);
        try {
            syncSchedule(sched.getScheduleReference(), sched);
        } catch (Throwable t) {
            exceptionList.add(Messages.getString("QuartzSubscriptionScheduler.ERROR_SCHEDULING", //$NON-NLS-1$
                    sched.getScheduleReference(), t.getLocalizedMessage()));
        }
        jobSet.remove(sched.getScheduleReference());
    }

    // Now delete the left overs
    for (Iterator it = jobSet.iterator(); it.hasNext();) {
        scheduler.deleteJob((String) it.next(), QuartzSubscriptionScheduler.GROUP_NAME);
    }

    return (exceptionList);
}

From source file:com.android.talkback.formatter.TouchExplorationFormatter.java

/**
 * Resets cached scrollable state when touch exploration after window state
 * changes.//from  ww  w. j  a v a 2s.c o  m
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Reset cached scrollable state.
        mLastNodeWasScrollable = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Store window title in the map.
            List<CharSequence> titles = event.getText();
            if (titles.size() > 0) {
                AccessibilityNodeInfo node = event.getSource();
                if (node != null) {
                    int windowType = getWindowType(node);
                    if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION
                            || windowType == AccessibilityWindowInfo.TYPE_SYSTEM) {
                        mWindowTitlesMap.put(node.getWindowId(), titles.get(0));
                    }
                    node.recycle();
                }
            }
        }
        break;
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Copy key set not to modify original map.
            HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>();
            windowIdsToBeRemoved.addAll(mWindowTitlesMap.keySet());

            // Enumerate window ids to be removed.
            List<AccessibilityWindowInfo> windows = mService.getWindows();
            for (AccessibilityWindowInfo window : windows) {
                windowIdsToBeRemoved.remove(window.getId());
            }

            // Delete titles of non-existing window ids.
            for (Integer windowId : windowIdsToBeRemoved) {
                mWindowTitlesMap.remove(windowId);
            }
        }
        break;
    }
}

From source file:opennlp.tools.textsimilarity.TextProcessor.java

private static HashSet<String> extractCommonSegments(Pair<List<String>, Map<String, HashSet<Integer>>> objA,
        Pair<List<String>, Map<String, HashSet<Integer>>> objB, Integer segSize) {

    HashSet<String> commonSegments = new HashSet<String>();

    List<String> tokensA = objA.getFirst();

    Map<String, HashSet<Integer>> tokenPosB = objB.getSecond();

    HashSet<Integer> lastPositions = null;
    int segLength = 1;
    StringBuffer segmentStr = new StringBuffer();

    for (int i = 0; i < tokensA.size(); i++) {
        String token = tokensA.get(i);
        HashSet<Integer> positions = null;
        // if ((positions = tokenPosB.get(token)) != null &&
        // !token.equals("<punc>") &&
        // !StopList.getInstance().isStopWord(token) && token.length()>1) {
        if ((positions = tokenPosB.get(token)) != null) {
            // we have a list of positions
            if (lastPositions != null) {
                // see if there is overlap in positions
                if (hasNextPosition(lastPositions, positions)) {
                    segLength++;/*w ww .j  a  va  2  s.  c om*/

                    commonSegments.remove(segmentStr.toString().trim());
                    segmentStr.append(" ");
                    segmentStr.append(token);
                    if (StringUtils.countMatches(segmentStr.toString(), " ") >= segSize) {
                        commonSegments.add(segmentStr.toString().trim());
                    }
                    lastPositions = positions;

                } else {
                    // did not find segment, reset
                    segLength = 1;
                    segmentStr.setLength(0);
                    lastPositions = null;
                }
            } else {
                lastPositions = positions;
                segmentStr.append(" ");
                segmentStr.append(token);
            }
        } else {
            // did not find segment, reset
            segLength = 1;
            segmentStr.setLength(0);
            lastPositions = null;
        }
    }

    return commonSegments;
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Displays a multiple choice question to the user.
 * @param question the question to be displayed
 * @param linearLayoutInsideAScrollView the view to add the question to
 * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5
 *///from   ww w.java  2 s .c om
private void makeMultipleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView,
        int ordinal) {
    LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView);
    String questionText = question.getTitle();
    List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers();
    Collections.sort(possibleAnswers);

    TextView questionView = new TextView(getActivity());
    questionView.setText(ordinal + ". " + questionText);
    if (question.isMandatory())
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory);
    else
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle);
    questionContainer.addView(questionView);
    mQuestionTitleMappings.put(question, questionView);

    Log.i(LOG_TAG, "questionView = " + questionView.getText());

    final HashSet<String> madeAnswers = new HashSet<String>();
    madeAnswers.addAll(Arrays.asList(question.getAnswer().split(",")));
    madeAnswers.remove(""); // paranoia

    final CheckBox[] checkBoxs = new CheckBox[possibleAnswers.size()];
    for (int i = 0; i < checkBoxs.length; i++) {
        final PossibleAnswer possibleAnswer = possibleAnswers.get(i);
        final String possibleAnswerId = String.valueOf(possibleAnswer.getId());
        checkBoxs[i] = new CheckBox(getActivity());
        if (i % 2 == 0)
            checkBoxs[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray));
        checkBoxs[i].setText(possibleAnswer.getTitle());
        checkBoxs[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle);
        if (madeAnswers.contains(possibleAnswerId))
            checkBoxs[i].setChecked(true);

        // click handling
        checkBoxs[i].setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    madeAnswers.add(possibleAnswerId);
                else
                    madeAnswers.remove(possibleAnswerId);
                String newAnswer = "";
                for (String madeAnswer1 : madeAnswers)
                    newAnswer = newAnswer + "," + madeAnswer1;
                if (!newAnswer.isEmpty())
                    newAnswer = newAnswer.substring(1); // remove the leading ","
                question.setAnswer(newAnswer);
            }
        });

        checkBoxs[i].setVisibility(View.VISIBLE);
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            checkBoxs[i].setEnabled(false);
        questionContainer.addView(checkBoxs[i]);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.ha.TestRetryCacheWithHA.java

@SuppressWarnings("unchecked")
private void listCachePools(HashSet<String> poolNames, int active) throws Exception {
    HashSet<String> tmpNames = (HashSet<String>) poolNames.clone();
    RemoteIterator<CachePoolEntry> pools = dfs.listCachePools();
    int poolCount = poolNames.size();
    for (int i = 0; i < poolCount; i++) {
        CachePoolEntry pool = pools.next();
        String pollName = pool.getInfo().getPoolName();
        assertTrue("The pool name should be expected", tmpNames.remove(pollName));
        if (i % 2 == 0) {
            int standby = active;
            active = (standby == 0) ? 1 : 0;
            cluster.shutdownNameNode(standby);
            cluster.waitActive(active);// w  w  w . jav  a2  s.  c o  m
            cluster.restartNameNode(standby, false);
        }
    }
    assertTrue("All pools must be found", tmpNames.isEmpty());
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanupIndexer.java

/**
 * //from w  w  w .ja  va 2  s .com
 */
public void initLuceneforReading() {
    try {
        reader = IndexReader.open(FSDirectory.open(FILE_INDEX_DIR));

    } catch (CorruptIndexException e) {
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }
    Set<?> stdStopWords = StandardAnalyzer.STOP_WORDS_SET;
    HashSet<Object> stopWords = new HashSet<Object>(stdStopWords);
    stopWords.remove("will");

    /*for (Object o : stopWords)
    {
    System.out.print(o.toString()+' ');
    }
    System.out.println();*/

    searcher = new IndexSearcher(reader);
    analyzer = new StandardAnalyzer(Version.LUCENE_47, CharArraySet.EMPTY_SET);
    parser = new QueryParser(Version.LUCENE_47, "loc", analyzer);
}