Java Code Examples for java.util.Collections#copy()

The following examples show how to use java.util.Collections#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouteTableModel.java    From railways with MIT License 6 votes vote down vote up
void filterChanged() {
    // Here we should update model.
    filteredRoutes.clear();

    if (!filter.isFilterActive()) {
        filteredRoutes.setSize(myRouteList.size());
        Collections.copy(filteredRoutes, myRouteList);
    } else {
        // Filter all elements
        for (Route route : myRouteList)
            if (filter.match(route))
                filteredRoutes.add(route);
    }

    this.fireTableDataChanged();
}
 
Example 2
Source File: CollectionsTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void test_copy_check_index() {
    ArrayList a1 = new ArrayList();
    a1.add("one");
    a1.add("two");

    ArrayList a2 = new ArrayList();
    a2.add("aa");

    try {
        Collections.copy(a2, a1);
        fail("Expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
        //Expected
    }

    assertEquals("aa", a2.get(0));
}
 
Example 3
Source File: Select.java    From QuantumFlux with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the query as a cursor, and then retrieves the row count from the cursor, the cursor is then closed and the count returned.
 *
 * @return The count indicating the amount of results for this select
 */
public int queryAsCount() {
    QuantumFluxCursor<T> cursor = queryAsCursor();

    List<String> includedColumnsTemp = new ArrayList<>();
    List<String> excludedColumnsTemp = new ArrayList<>();
    Collections.copy(includedColumnsTemp, mIncludedColumns);
    Collections.copy(excludedColumnsTemp, mExcludedColumns);

    mIncludedColumns.clear();
    mExcludedColumns.clear();

    String columnName = QuantumFlux.findTableDetails(mDataObjectClass).findPrimaryKeyColumn().getColumnName();
    mIncludedColumns.add(columnName);
    try {
        return cursor.getCount();
    } finally {
        if (cursor != null) cursor.close();
        mIncludedColumns.clear();

        //Restore the previous includes and excludes
        Collections.copy(mIncludedColumns, mIncludedColumns);
        Collections.copy(excludedColumnsTemp, mExcludedColumns);
    }

}
 
Example 4
Source File: TestUtil.java    From firebase-jobdispatcher-android with Apache License 2.0 6 votes vote down vote up
static List<List<Integer>> getAllConstraintCombinations() {
  List<List<Integer>> combos = new ArrayList<>();

  combos.add(Collections.<Integer>emptyList());
  for (Integer cur : Constraint.ALL_CONSTRAINTS) {
    for (int l = combos.size() - 1; l >= 0; l--) {
      List<Integer> oldCombo = combos.get(l);
      List<Integer> newCombo = Arrays.asList(new Integer[oldCombo.size() + 1]);

      Collections.copy(newCombo, oldCombo);
      newCombo.set(oldCombo.size(), cur);
      combos.add(newCombo);
    }
    combos.add(Collections.singletonList(cur));
  }

  return combos;
}
 
Example 5
Source File: WordComposer.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord) {
    mEvents.clear();
    Collections.copy(mEvents, lastComposedWord.mEvents);
    mInputPointers.set(lastComposedWord.mInputPointers);
    mCombinerChain.reset();
    refreshTypedWordCache();
    mCapitalizedMode = lastComposedWord.mCapitalizedMode;
    mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
    mCursorPositionWithinWord = mCodePointSize;
    mRejectedBatchModeSuggestion = null;
    mIsResumed = true;
}
 
Example 6
Source File: CompositeSeekingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) {
    CompositeSeekingIterator to = new CompositeSeekingIterator();
    to.setSource(getSource().deepCopy(env));
    
    Collections.copy(to.fieldNames, fieldNames);
    to.fieldToDiscreteIndexType = new HashMap<>(fieldToDiscreteIndexType);
    to.separator = separator;
    to.seekThreshold = seekThreshold;
    to.compositeSeeker = new ShardIndexCompositeSeeker(to.fieldNames, to.separator, to.fieldToDiscreteIndexType);
    
    return to;
}
 
Example 7
Source File: NUTableModel.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
public static List<Uploader> getUnsyncCopy_uploadList(){
    synchronized (uploadList){
        ArrayList<Uploader> uploadList2 = new ArrayList<Uploader>();
        Collections.copy(uploadList, uploadList2);
        return uploadList2;
    }
}
 
Example 8
Source File: CollectionsUtils.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private static void javaUtilCollections_copy(){
    System.out.println("\njavaUtilCollections_copy():");

    List<String> list1 = Arrays.asList("s1","s2");
    List<String> list2 = Arrays.asList("s3", "s4", "s5");
    Collections.copy(list2, list1);
    System.out.println(list2);    //prints: [s1, s2, s5]
}
 
Example 9
Source File: WordComposer.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord) {
    mEvents.clear();
    Collections.copy(mEvents, lastComposedWord.mEvents);
    mInputPointers.set(lastComposedWord.mInputPointers);
    mCombinerChain.reset();
    refreshTypedWordCache();
    mCapitalizedMode = lastComposedWord.mCapitalizedMode;
    mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
    mCursorPositionWithinWord = mCodePointSize;
    mRejectedBatchModeSuggestion = null;
    mIsResumed = true;
}
 
Example 10
Source File: DemoTableController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 查询数据
 */
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(UserTableModel userModel)
{
    TableDataInfo rspData = new TableDataInfo();
    List<UserTableModel> userList = new ArrayList<UserTableModel>(Arrays.asList(new UserTableModel[users.size()]));
    Collections.copy(userList, users);
    // 查询条件过滤
    if (StringUtils.isNotEmpty(userModel.getUserName()))
    {
        userList.clear();
        for (UserTableModel user : users)
        {
            if (user.getUserName().equals(userModel.getUserName()))
            {
                userList.add(user);
            }
        }
    }
    PageDomain pageDomain = TableSupport.buildPageRequest();
    if (null == pageDomain.getPageNum() || null == pageDomain.getPageSize())
    {
        rspData.setRows(userList);
        rspData.setTotal(userList.size());
        return rspData;
    }
    Integer pageNum = (pageDomain.getPageNum() - 1) * 10;
    Integer pageSize = pageDomain.getPageNum() * 10;
    if (pageSize > userList.size())
    {
        pageSize = userList.size();
    }
    rspData.setRows(userList.subList(pageNum, pageSize));
    rspData.setTotal(userList.size());
    return rspData;
}
 
Example 11
Source File: ListTest.java    From werewolf_server with Apache License 2.0 5 votes vote down vote up
@Test
public void test(){

    List<String> src = new ArrayList<>();
    src.add("asd");
    List<String> dest = new ArrayList<>(Arrays.asList(new String[src.size()]));
    Collections.copy(dest,src);
    System.out.println(dest);

}
 
Example 12
Source File: CopyElementsOfVectorToVectorExample.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {

        //create first Vector object
        Vector v1 = new Vector();

        //Add elements to Vector
        v1.add("1");
        v1.add("2");
        v1.add("3");

        //create another Vector object
        Vector v2 = new Vector();

        //Add elements to Vector
        v2.add("One");
        v2.add("Two");
        v2.add("Three");
        v2.add("Four");
        v2.add("Five");

    /*
      To copy elements of one Java Vector to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

        System.out.println("Before copy, Second Vector Contains : " + v2);

        //copy all elements of Vector to another Vector using copy
        //method of Collections class
        Collections.copy(v2, v1);

    /*
      Please note that, If destination Vector object is not long enough
      to hold all elements of source Vector,
      it throws IndexOutOfBoundsException.
    */

        System.out.println("After copy, Second Vector Contains : " + v2);
    }
 
Example 13
Source File: CopyElementsOfArrayListToArrayListExample.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {

        //create first ArrayList object
        ArrayList arrayList1 = new ArrayList();

        //Add elements to ArrayList
        arrayList1.add("1");
        arrayList1.add("2");
        arrayList1.add("3");

        //create another ArrayList object
        ArrayList arrayList2 = new ArrayList();

        //Add elements to Arraylist
        arrayList2.add("One");
        arrayList2.add("Two");
        arrayList2.add("Three");
        arrayList2.add("Four");
        arrayList2.add("Five");

    /*
      To copy elements of one Java ArrayList to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

        System.out.println("Before copy, Second ArrayList Contains : " + arrayList2);

        //copy all elements of ArrayList to another ArrayList using copy
        //method of Collections class
        Collections.copy(arrayList2, arrayList1);

    /*
      Please note that, If destination ArrayList object is not long
      enough to hold all elements of source ArrayList,
      it throws IndexOutOfBoundsException.
    */

        System.out.println("After copy, Second ArrayList Contains : " + arrayList2);
    }
 
Example 14
Source File: CopyElementsOfArrayListToVectorExample.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {
    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("1");
    arrayList.add("4");
    arrayList.add("2");
    arrayList.add("5");
    arrayList.add("3");

    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("A");
    v.add("B");
    v.add("D");
    v.add("E");
    v.add("F");
    v.add("G");
    v.add("H");

/*
  To copy elements of Java ArrayList to Java Vector use,
  static void copy(List dstList, List sourceList) method of Collections class.

  This method copies all elements of source list to destination list. After copy
  index of the elements in both source and destination lists would be identical.

  The destination list must be long enough to hold all copied elements. If it is
  longer than that, the rest of the destination list's elments would remain
  unaffected.
*/

    System.out.println("Before copy, Vector Contains : " + v);

    //copy all elements of ArrayList to Vector using copy method of Collections class
    Collections.copy(v, arrayList);

/*
   Please note that, If Vector is not long enough to hold all elements of
   ArrayList, it throws IndexOutOfBoundsException.
*/

    System.out.println("After Copy, Vector Contains : " + v);
}
 
Example 15
Source File: CopyElementsOfVectorToArrayListExample.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {

        //create a Vector object
        Vector v = new Vector();

        //Add elements to Vector
        v.add("1");
        v.add("2");
        v.add("3");

        //create an ArrayList object
        ArrayList arrayList = new ArrayList();

        //Add elements to Arraylist
        arrayList.add("One");
        arrayList.add("Two");
        arrayList.add("Three");
        arrayList.add("Four");
        arrayList.add("Five");

    /*
      To copy elements of Java Vector to Java ArrayList use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

        System.out.println("Before copy ArrayList Contains : " + arrayList);

        //copy all elements of Vector to ArrayList using copy method of Collections class
        Collections.copy(arrayList, v);

    /*
      Please note that, If ArrayList is not long enough to hold all elements of
      Vector, it throws IndexOutOfBoundsException.
    */

        System.out.println("After Copy ArrayList Contains : " + arrayList);
    }
 
Example 16
Source File: CopyElementsOfArrayListToArrayListExample.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

    //create first ArrayList object
    ArrayList arrayList1 = new ArrayList();

    //Add elements to ArrayList
    arrayList1.add("1");
    arrayList1.add("2");
    arrayList1.add("3");

    //create another ArrayList object
    ArrayList arrayList2 = new ArrayList();

    //Add elements to Arraylist
    arrayList2.add("One");
    arrayList2.add("Two");
    arrayList2.add("Three");
    arrayList2.add("Four");
    arrayList2.add("Five");

    /*
      To copy elements of one Java ArrayList to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy, Second ArrayList Contains : " + arrayList2);

    //copy all elements of ArrayList to another ArrayList using copy
    //method of Collections class
    Collections.copy(arrayList2, arrayList1);

    /*
      Please note that, If destination ArrayList object is not long
      enough to hold all elements of source ArrayList,
      it throws IndexOutOfBoundsException.
    */

    System.out.println("After copy, Second ArrayList Contains : " + arrayList2);
  }
 
Example 17
Source File: CopyListService.java    From tutorials with MIT License 4 votes vote down vote up
public List<Integer> copyListByCopyMethod(List<Integer> source, List<Integer> dest) {
    Collections.copy(dest, source);
    return dest;
}
 
Example 18
Source File: CopyElementsOfVectorToArrayListExample.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("1");
    v.add("2");
    v.add("3");

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("One");
    arrayList.add("Two");
    arrayList.add("Three");
    arrayList.add("Four");
    arrayList.add("Five");

    /*
      To copy elements of Java Vector to Java ArrayList use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy ArrayList Contains : " + arrayList);

    //copy all elements of Vector to ArrayList using copy method of Collections class
    Collections.copy(arrayList, v);

    /*
      Please note that, If ArrayList is not long enough to hold all elements of
      Vector, it throws IndexOutOfBoundsException.
    */

    System.out.println("After Copy ArrayList Contains : " + arrayList);
  }
 
Example 19
Source File: CopyElementsOfVectorToVectorExample.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

    //create first Vector object
    Vector v1 = new Vector();

    //Add elements to Vector
    v1.add("1");
    v1.add("2");
    v1.add("3");

    //create another Vector object
    Vector v2 = new Vector();

    //Add elements to Vector
    v2.add("One");
    v2.add("Two");
    v2.add("Three");
    v2.add("Four");
    v2.add("Five");

    /*
      To copy elements of one Java Vector to another use,
      static void copy(List dstList, List sourceList) method of Collections class.

      This method copies all elements of source list to destination list. After copy
      index of the elements in both source and destination lists would be identical.

      The destination list must be long enough to hold all copied elements. If it is
      longer than that, the rest of the destination list's elments would remain
      unaffected.
    */

    System.out.println("Before copy, Second Vector Contains : " + v2);

    //copy all elements of Vector to another Vector using copy
    //method of Collections class
    Collections.copy(v2, v1);

    /*
      Please note that, If destination Vector object is not long enough
      to hold all elements of source Vector,
      it throws IndexOutOfBoundsException.
    */

    System.out.println("After copy, Second Vector Contains : " + v2);
  }
 
Example 20
Source File: AbstractModelNode.java    From mql-editor with GNU Lesser General Public License v2.1 4 votes vote down vote up
public AbstractModelNode( List<T> children ) {
  Collections.copy( this.children, children );
}