java.util.ArrayList.contains()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中java.util.ArrayList.contains()方法的一些代码示例,展示了ArrayList.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayList.contains()方法的具体详情如下:
包路径:java.util.ArrayList
类名称:ArrayList
方法名:contains

ArrayList.contains介绍

[英]Searches this ArrayList for the specified object.
[中]在此ArrayList中搜索指定的对象。

代码示例

代码示例来源:origin: prestodb/presto

public void addRule(Rule rule) {
  if (!iRules.contains(rule)) {
    iRules.add(rule);
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

public void removeMissingTrans( MissingTrans trans ) {
 if ( missingTrans != null && trans != null && missingTrans.contains( trans ) ) {
  missingTrans.remove( trans );
 }
}

代码示例来源:origin: lingochamp/FileDownloader

@Override
public BaseDownloadTask addFinishListener(
    final BaseDownloadTask.FinishListener finishListener) {
  if (mFinishListenerList == null) {
    mFinishListenerList = new ArrayList<>();
  }
  if (!mFinishListenerList.contains(finishListener)) {
    mFinishListenerList.add(finishListener);
  }
  return this;
}

代码示例来源:origin: nutzam/nutz

/**
 * Context 的获取优先级,以数组的顺序来决定
 * 
 * @param contexts
 */
public ComboContext(IocContext... contexts) {
  ArrayList<IocContext> tmp = new ArrayList<IocContext>(contexts.length);
  for (IocContext iocContext : contexts) {
    if (tmp.contains(iocContext))
      continue;
    if (iocContext instanceof ComboContext){
      ComboContext comboContext = (ComboContext)iocContext;
      for (IocContext iocContext2 : comboContext.contexts) {
        if (tmp.contains(iocContext2))
          continue;
        tmp.add(iocContext2);
      }
    }
    else
      tmp.add(iocContext);
  }
  this.contexts = tmp.toArray(new IocContext[tmp.size()]);
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private void disableExcludedCiphers(SSLEngine sslEngine) {
 String[] cipherSuites = sslEngine.getEnabledCipherSuites();
 ArrayList<String> defaultEnabledCipherSuites =
   new ArrayList<String>(Arrays.asList(cipherSuites));
 Iterator iterator = excludeCiphers.iterator();
 while(iterator.hasNext()) {
  String cipherName = (String)iterator.next();
  if(defaultEnabledCipherSuites.contains(cipherName)) {
   defaultEnabledCipherSuites.remove(cipherName);
   LOG.debug("Disabling cipher suite {}.", cipherName);
  }
 }
 cipherSuites = defaultEnabledCipherSuites.toArray(
   new String[defaultEnabledCipherSuites.size()]);
 sslEngine.setEnabledCipherSuites(cipherSuites);
}

代码示例来源:origin: ben-manes/caffeine

/**
 * Values.toArray contains all values
 */
public void testValuesToArray() {
  ConcurrentMap map = map5();
  Collection v = map.values();
  Object[] ar = v.toArray();
  ArrayList s = new ArrayList(Arrays.asList(ar));
  assertEquals(5, ar.length);
  assertTrue(s.contains("A"));
  assertTrue(s.contains("B"));
  assertTrue(s.contains("C"));
  assertTrue(s.contains("D"));
  assertTrue(s.contains("E"));
}

代码示例来源:origin: org.drools/drools-compiler

ResourceType.DRL );
System.out.println( knowledgeBuilder.getErrors().toString() );
KieSession kSession = createKnowledgeSession(kBase);
java.util.ArrayList list = new ArrayList();
kSession.setGlobal( "list",
          list );
kSession.fireAllRules();
assertTrue( list.contains( 84.2 ) );

代码示例来源:origin: Sable/soot

private void graphTraverse(Unit startPoint, InterproceduralCFG<Unit, SootMethod> icfg) {
  List<Unit> currentSuccessors = icfg.getSuccsOf(startPoint);

  if (currentSuccessors.size() == 0) {
   System.out.println("Traversal complete");
   return;
  } else {
   for (Unit succ : currentSuccessors) {
    System.out.println("Succesor: " + succ.toString());
    if (!visited.contains(succ)) {
     dotIcfg.drawEdge(startPoint.toString(), succ.toString());
     visited.add(succ);
     graphTraverse(succ, icfg);

    } else {
     dotIcfg.drawEdge(startPoint.toString(), succ.toString());
    }
   }
  }
 }
}

代码示例来源:origin: deathmarine/Luyten

public static void add(String path) {
  if (paths.contains(path)) {
    paths.remove(path);
    paths.add(path);
    return;
  }
  
  if (paths.size() >= 10) paths.remove(0);
  paths.add(path);
  
  save();
}

代码示例来源:origin: commonsguy/cw-omnibus

void addDevice(BluetoothDevice device) {
 if (isCandidateDevice(device) && !devices.contains(device)) {
  devices.add(device);
  notifyItemInserted(devices.size()-1);
 }
}

代码示例来源:origin: seven332/EhViewer

@Override
  protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    if (mDoTrick) {
      ArrayList<View> sortedScenes = mSortedScenes;
      if (child == mDumpView) {
        boolean more = false;
        for (int i = 0, n = sortedScenes.size(); i < n; i++) {
          more |= super.drawChild(canvas, sortedScenes.get(i), drawingTime);
        }
        return more;
      } else if (sortedScenes.contains(child)) {
        // Skip
        return false;
      }
    }

    return super.drawChild(canvas, child, drawingTime);
  }
}

代码示例来源:origin: robovm/robovm

@Override
void findResources(String name, ArrayList<URL> resources) {
  URL res = findResourceInOwn(name);
  if (res != null && !resources.contains(res)) {
    resources.add(res);
  }
  if (index != null) {
    int pos = name.lastIndexOf("/");
    // only keep the directory part of the resource
    // as index.list only keeps track of directories and root files
    String indexedName = (pos > 0) ? name.substring(0, pos) : name;
    ArrayList<URL> urls = index.get(indexedName);
    if (urls != null) {
      urls.remove(url);
      for (URL url : urls) {
        URLHandler h = getSubHandler(url);
        if (h != null) {
          h.findResources(name, resources);
        }
      }
    }
  }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListRecordSets() {
 EasyMock.expect(dnsRpcMock.listRecordSets(ZONE_INFO.getName(), EMPTY_RPC_OPTIONS))
   .andReturn(LIST_OF_PB_DNS_RECORDS);
 EasyMock.replay(dnsRpcMock);
 dns = options.getService(); // creates DnsImpl
 Page<RecordSet> dnsPage = dns.listRecordSets(ZONE_INFO.getName());
 assertEquals(2, Lists.newArrayList(dnsPage.getValues()).size());
 assertTrue(Lists.newArrayList(dnsPage.getValues()).contains(DNS_RECORD1));
 assertTrue(Lists.newArrayList(dnsPage.getValues()).contains(DNS_RECORD2));
}

代码示例来源:origin: naman14/Timber

public static void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  PermissionRequest requestResult = new PermissionRequest(requestCode);
  if (permissionRequests.contains(requestResult)) {
    PermissionRequest permissionRequest = permissionRequests.get(permissionRequests.indexOf(requestResult));
    if (verifyPermissions(grantResults)) {
      //Permission has been granted
      permissionRequest.getPermissionCallback().permissionGranted();
    } else {
      permissionRequest.getPermissionCallback().permissionRefused();
    }
    permissionRequests.remove(requestResult);
  }
  refreshMonitoredList();
}

代码示例来源:origin: aa112901/remusic

public void cancel(String taskId) {
  if (currentTask != null) {
    if (taskId.equals(currentTask.getId())) {
      currentTask.cancel();
      currentTask.setDownloadStatus(DownloadStatus.DOWNLOAD_STATUS_CANCEL);
    }
  }
  if (prepareTaskList.contains(taskId)) {
    downTaskCount--;
    prepareTaskList.remove(taskId);
  }
  if (prepareTaskList.size() == 0) {
    currentTask = null;
  }
  downFileStore.deleteTask(taskId);
  upDateNotification();
  sendIntent(TASKS_CHANGED);
  L.D(d, TAG, "cancle task = " + taskId);
}

代码示例来源:origin: apache/hive

/**
 * Define the connection profile to execute the current statement
 */
String getStatementConnection() {
 if (exec.stmtConnList.contains(exec.conf.defaultConnection)) {
  return exec.conf.defaultConnection;
 }
 else if (!exec.stmtConnList.isEmpty()) {
  return exec.stmtConnList.get(0);
 }
 return exec.conf.defaultConnection;
}

代码示例来源:origin: guoguibing/librec

/**
 * Get the continent/country/city list and their corresponding sizes
 */
protected void getLayers() {
  for (String user: hierarchy.keySet()) {
    String continent = hierarchy.get(user).get(0);
    String country = hierarchy.get(user).get(1);
    String city = hierarchy.get(user).get(2);
    if (!continentList.contains(continent)) continentList.add(continent);
    if (!countryList.contains(country)) countryList.add(country);
    if (!cityList.contains(city)) cityList.add(city);
  }
  continentNum = continentList.size();
  countryNum = countryList.size();
  cityNum = cityList.size();
  total_node = continentNum + countryNum + cityNum;
  non_leaf = continentNum + countryNum + 1;
  LOG.info("continentNum: "+ continentNum+"; countryNum: "+countryNum+"; cityNum: "+cityNum);
  LOG.info("total number of nodes: "+total_node + "; the number of non_leaf nodes: "+ non_leaf);
}

代码示例来源:origin: stackoverflow.com

public boolean hasImageCaptureBug() {

  // list of known devices that have the bug
  ArrayList<String> devices = new ArrayList<String>();
  devices.add("android-devphone1/dream_devphone/dream");
  devices.add("generic/sdk/generic");
  devices.add("vodafone/vfpioneer/sapphire");
  devices.add("tmobile/kila/dream");
  devices.add("verizon/voles/sholes");
  devices.add("google_ion/google_ion/sapphire");

  return devices.contains(android.os.Build.BRAND + "/" + android.os.Build.PRODUCT + "/"
      + android.os.Build.DEVICE);

}

代码示例来源:origin: oblac/jodd

@Test
void testUseProfiles_withTwoDifferentValues() throws Exception {
  //given
  Vtor vtor = new Vtor();
  vtor.useProfiles("testProfile1", "testProfile2");
  assertEquals(2, vtor.enabledProfiles.size());
  ArrayList<String> enabledProfileList = new ArrayList<>(vtor.enabledProfiles);
  assertTrue(enabledProfileList.contains("testProfile1"), "first element must be equal to first added profile");
  assertTrue(enabledProfileList.contains("testProfile2"), "second element must be equal to second added profile");
  //when
  vtor.useProfile(null);
  //then
  assertEquals(2, vtor.enabledProfiles.size());
}

代码示例来源:origin: wangdan/AisenWeiBo

private void onPictureSelectedChange(String path) {
    if (!selectedFile.contains(path)) {
      if (selectedFile.size() >= maxSize) {
        showMessage(String.format("最多只能选%d张相片", maxSize));
        return;
      }

      selectedFile.add(path);
    }
    else
      selectedFile.remove(path);

    getAdapter().notifyDataSetChanged();
    getActivity().invalidateOptionsMenu();
//        btnCounter.setVisibility(selectedFile.size() == 0 ? View.GONE : View.VISIBLE);
//        txtCounter.setText(String.format("预览(%d/%d)", selectedFile.size(), maxSize));
  }

相关文章