Java Code Examples for java.util.ArrayList#clone()

The following examples show how to use java.util.ArrayList#clone() . 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: AddAliasView.java    From Atomic with GNU General Public License v3.0 6 votes vote down vote up
public AddAliasView(Context context, ArrayList<String> aliases) {
  super(context);
  this.aliases = (ArrayList<String>)(aliases.clone());

  LayoutInflater.from(context).inflate(R.layout.aliasadd, this, true);

  aliasInput = (EditText)findViewById(R.id.alias);
  aliasInput.addTextChangedListener(this);

  adapter = new ArrayAdapter<String>(this.getContext(), R.layout.aliasitem, this.aliases);

  ListView list = (ListView)findViewById(R.id.aliases);
  list.setAdapter(adapter);
  list.setOnItemClickListener(this);

  addButton = (Button)findViewById(R.id.add);
  addButton.setOnClickListener(this);
}
 
Example 2
Source File: ClientPooledConnection.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public synchronized void addConnectionEventListener(
                                        ConnectionEventListener listener) {
    if (logWriter_ != null) {
        logWriter_.traceEntry(this, "addConnectionEventListener", listener);
    }

    if (listener == null) {
        // Ignore the listener if it is null. Otherwise, an exception is
        // thrown when a connection event occurs (DERBY-3307).
        return;
    }

    if (eventIterators > 0) {
        // DERBY-3401: Someone is iterating over the ArrayList, and since
        // we were able to synchronize on this, that someone is us. Clone
        // the list of listeners in order to prevent invalidation of the
        // iterator.
        listeners_ = (ArrayList) listeners_.clone();
    }
    listeners_.add(listener);
}
 
Example 3
Source File: TieredCompactionJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testAlterMaxInputFileSize() throws Exception {
  HdfsSortedOplogOrganizer organizer = new HdfsSortedOplogOrganizer(regionManager, 0);
  HoplogCompactor compactor = (HoplogCompactor) organizer.getCompactor();

  assertTrue(TEN_MB * 2 < hdfsStore.getHDFSCompactionConfig().getMaxInputFileSizeMB() * ONE_MB);
  
  ArrayList<TrackedReference<TestHoplog>> targets = new ArrayList<TrackedReference<TestHoplog>>();
  for (int i = 0; i < 5; i++) {
    TrackedReference<TestHoplog> hop = new TrackedReference<TestHoplog>(new TestHoplog(hdfsStore, TEN_MB + i));
    hop.increment();
    targets.add(hop);
  }
  
  List<TrackedReference<Hoplog>> list = (List<TrackedReference<Hoplog>>) targets.clone();
  compactor.getMinorCompactionTargets(list, -1);
  assertEquals(targets.size(), list.size());
  
  HDFSStoreMutator mutator = hdfsStore.createHdfsStoreMutator();
  mutator.getCompactionConfigMutator().setMaxInputFileSizeMB(1);
  hdfsStore.alter(mutator);
  
  compactor.getMinorCompactionTargets(list, -1);
  assertEquals(0, list.size());
}
 
Example 4
Source File: ConditionalPermissionUpdateImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
ConditionalPermissionUpdateImpl(ConditionalPermissionInfoStorage cpis,
                                ArrayList<ConditionalPermissionInfoImpl> org,
                                int generation)
{
  storage = cpis;
  @SuppressWarnings({ "unchecked", "rawtypes" })
  final ArrayList<ConditionalPermissionInfo> clone = (ArrayList) org.clone();
  cpiTable = clone;
  parent = generation;
}
 
Example 5
Source File: RenderNodeAnimator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private ArrayList<AnimatorListener> cloneListeners() {
    ArrayList<AnimatorListener> listeners = getListeners();
    if (listeners != null) {
        listeners = (ArrayList<AnimatorListener>) listeners.clone();
    }
    return listeners;
}
 
Example 6
Source File: TypeHierarchy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private synchronized ArrayList getClonedChangeListeners() {
	ArrayList listeners = this.changeListeners;
	if (listeners == null) {
		return null;
	}
	return (ArrayList) listeners.clone();
}
 
Example 7
Source File: SuggestionAdapter.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
public SuggestionAdapter(@NonNull Context context,
                         @LayoutRes int resource, @NonNull ArrayList<SuggestionItem> objects) {
    super(context, resource, objects);
    inflater = LayoutInflater.from(context);
    clone = (ArrayList<SuggestionItem>) objects.clone();
    suggestion = new ArrayList<>();
    resourceID = resource;
}
 
Example 8
Source File: VoxelVDWListChecker.java    From OSPREY3 with GNU General Public License v2.0 5 votes vote down vote up
ArrayList<LinearConstraint> calcFeasiblePolytope3(){
    
    //first get lc polygon, to prune bad uc
    ArrayList<LinearConstraint> lcPolygon = voxelPolygon();
            
    int numVDWPairs = interactingAtoms.size();
    for(int p=0; p<numVDWPairs; p++){            
        LinearConstraint lc = tooCloseConstr(interactingAtoms.get(p));
        boolean validLC = ! (lc.getCoefficients().getNorm()<1e-10);
        
        if(validLC){
            if(!canAddConstr(lc,lcPolygon)){
                return null;
            }
            lcPolygon.add(lc);
        }
    }
        
    
    //ok now get the real polygon
    ArrayList<LinearConstraint> curPolygon = (ArrayList<LinearConstraint>)lcPolygon.clone();
    for(int p=0; p<numVDWPairs; p++){            
        LinearConstraint uc = tooFarConstr(interactingAtoms.get(p));
        
        boolean validUC = ! (uc.getCoefficients().getNorm()<1e-10);
        
        if(validUC){
            if(canAddConstr(uc,lcPolygon)){
                if(!canAddConstr(uc,curPolygon)){
                    return null;
                }
            }
            curPolygon.add(uc);
        }
    }
    
    //if we got here we have a feasible pt and its containing polygon!!!
    return curPolygon;
}
 
Example 9
Source File: ClientPooledConnection.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public synchronized void removeConnectionEventListener(
                                        ConnectionEventListener listener) {
    if (logWriter_ != null) {
        logWriter_.traceEntry(this, "removeConnectionEventListener", listener);
    }
    if (eventIterators > 0) {
        // DERBY-3401: Someone is iterating over the ArrayList, and since
        // we were able to synchronize on this, that someone is us. Clone
        // the list of listeners in order to prevent invalidation of the
        // iterator.
        listeners_ = (ArrayList) listeners_.clone();
    }
    listeners_.remove(listener);
}
 
Example 10
Source File: MediaLibrary.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
public ArrayList<SongBean> shuffleList(ArrayList<SongBean> originalList){
    ArrayList<SongBean> ret = new ArrayList<>();
    originalList = (ArrayList<SongBean>) originalList.clone();
    while(originalList.size() >0 ){
        ret.add(originalList.remove(new Random().nextInt(originalList.size())));
    }
    return ret;
}
 
Example 11
Source File: JobLauncherForm.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <p>
 * This operation sets the input files that may be selected in the Form for
 * the input type with the specified name. Passing null for the name or file
 * list will not make any changes to the Form.
 * </p>
 * 
 * @param name
 *            Name of the input file type.
 * @param desc
 *            Description of the file type.
 * @param files
 *            List of files available for the job.
 */
public void setInputFiles(String name, String desc,
		ArrayList<String> files) {

	// Local Declarations
	int oldId = 0;
	IEntry oldEntry = null;
	DataComponent fileComponent = ((DataComponent) getComponent(1));
	final ArrayList<String> finalFiles = (files != null)
			? (ArrayList<String>) files.clone() : new ArrayList<String>();
	String oldValue = "";

	// Determine if the Entry already exists in the component and remove it
	// if necessary
	if (fileComponent.contains(name)) {
		// Store the id and Entry
		oldEntry = fileComponent.retrieveEntry(name);
		oldId = oldEntry.getId();
		oldValue = oldEntry.getValue();
	}

	// Create an Entry with the filenames
	IEntry fileEntry = new FileEntry();
	fileEntry.setAllowedValues(finalFiles);

	// Set the name and description of the Filename entry
	fileEntry.setDescription(desc);
	fileEntry.setName(name);
	// FIXME! Bug - needs a unique id
	fileEntry.setId((oldId > 0) ? oldId
			: fileComponent.retrieveAllEntries().size());
	// Keep the original value, if possible
	if (fileEntry.getAllowedValues().contains(oldValue)) {
		fileEntry.setValue(oldValue);
		fileEntry.setDefaultValue(oldValue);
	} else if (!finalFiles.isEmpty()) {
		fileEntry.setValue(finalFiles.get(0));
		fileEntry.setDefaultValue(finalFiles.get(0));
	} else {
		fileEntry.setAllowedValues(Arrays.asList("Import a File"));
		fileEntry.setValue("Import a File");
		fileEntry.setDefaultValue("Import a File");
	}
	// Determine if the Entry already exists in the component and reuse it
	if (oldEntry != null) {
		((FileEntry) oldEntry).copy((FileEntry) fileEntry);
	} else {
		// Or just add it
		fileComponent.addEntry(fileEntry);
	}

	return;
}
 
Example 12
Source File: GeometryAdapterFactoryTest.java    From geogson with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldHandleGeometryCollection() {

  ArrayList<Geometry<?>> geometries = new ArrayList<Geometry<?>>();
  geometries.add(Point.from(56.7, 83.6));
  geometries.add(MultiPoint.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8)));
  geometries.add(LineString.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8)));
  geometries.add(MultiLineString.of(
      LineString.of(Point.from(14.5, 47.3), Point.from(42.19, 3.8)),
      LineString.of(Point.from(11.3, 44.3), Point.from(42.9, 2.8))
  ));
  geometries.add(MultiLineString.of(
      LineString.of(Point.from(14.5, 47.3), Point.from(42.19, 3.8))
  ));
  geometries.add(LinearRing.of(Point.from(12.3, 45.3), Point.from(43.9, 5.8), Point.from(43.9, 5.8), Point.from(12.3, 45.3)));
  geometries.add(Polygon.of(
      LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)),
      LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3))
  ));
  geometries.add(MultiPolygon.of(
      Polygon.of(
              LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)),
              LinearRing.of(Point.from(150.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(150.3, 45.3))
      ),
      Polygon.of(
              LinearRing.of(Point.from(102.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(102.3, 45.3)),
              LinearRing.of(Point.from(104.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(104.3, 45.3))
      )
  ));
  geometries.add(MultiPolygon.of(
      Polygon.of(
              LinearRing.of(Point.from(120.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(120.3, 45.3)),
              LinearRing.of(Point.from(110.3, 45.3), Point.from(100, -50.8), Point.from(100, 5.8), Point.from(110.3, 45.3))
      )
  ));

  ArrayList<Geometry<?>> innerGeometries = (ArrayList<Geometry<?>>) geometries.clone();
  geometries.add(GeometryCollection.of(innerGeometries));

  GeometryCollection source = GeometryCollection.of(geometries);

  GeometryCollection parsed = this.toTest.fromJson(this.toTest.toJson(source), GeometryCollection.class);

  assertThat(parsed, equalTo(source));
}
 
Example 13
Source File: XSGrammarBucket.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * put a schema grammar and any grammars imported by it (directly or
 * inderectly) into the registry. when a grammar with the same target
 * namespace is already in the bucket, and different from the one being
 * added, it's an error, and no grammar will be added into the bucket.
 *
 * @param grammar   the grammar to put in the registry
 * @param deep      whether to add imported grammars
 * @return          whether the process succeeded
 */
public boolean putGrammar(SchemaGrammar grammar, boolean deep) {
    // whether there is one with the same tns
    SchemaGrammar sg = getGrammar(grammar.fTargetNamespace);
    if (sg != null) {
        // if the one we have is different from the one passed, it's an error
        return sg == grammar;
    }
    // not deep import, then just add this one grammar
    if (!deep) {
        putGrammar(grammar);
        return true;
    }

    // get all imported grammars, and make a copy of the Vector, so that
    // we can recursively process the grammars, and add distinct ones
    // to the same vector
    ArrayList<SchemaGrammar> currGrammars = (ArrayList<SchemaGrammar>)grammar.getImportedGrammars();
    if (currGrammars == null) {
        putGrammar(grammar);
        return true;
    }

    @SuppressWarnings("unchecked")
    List<SchemaGrammar> grammars = ((ArrayList<SchemaGrammar>)currGrammars.clone());
    SchemaGrammar sg1, sg2;
    List<SchemaGrammar> gs;
    // for all (recursively) imported grammars
    for (int i = 0; i < grammars.size(); i++) {
        // get the grammar
        sg1 = grammars.get(i);
        // check whether the bucket has one with the same tns
        sg2 = getGrammar(sg1.fTargetNamespace);
        if (sg2 == null) {
            // we need to add grammars imported by sg1 too
            gs = sg1.getImportedGrammars();
            // for all grammars imported by sg2, but not in the vector
            // we add them to the vector
            if(gs == null) continue;
            for (int j = gs.size() - 1; j >= 0; j--) {
                sg2 = gs.get(j);
                if (!grammars.contains(sg2))
                    grammars.add(sg2);
            }
        }
        // we found one with the same target namespace
        // if the two grammars are not the same object, then it's an error
        else if (sg2 != sg1) {
            return false;
        }
    }

    // now we have all imported grammars stored in the vector. add them
    putGrammar(grammar);
    for (int i = grammars.size() - 1; i >= 0; i--)
        putGrammar(grammars.get(i));

    return true;
}
 
Example 14
Source File: Words.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Words(ArrayList<String> words, boolean[] used){
    this.words = (ArrayList<String>) words.clone();
    this.used = arrayCopy(used, 0, words.size());
}
 
Example 15
Source File: FunctionConfig.java    From GalleryFinal with Apache License 2.0 4 votes vote down vote up
public Builder setFilter(ArrayList<String> filterList) {
    if ( filterList != null ) {
        this.filterList = (ArrayList<String>) filterList.clone();
    }
    return this;
}
 
Example 16
Source File: Path.java    From kourami with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setInterBubbleIntersectionCounts(ArrayList<int[][]> ibic){
this.interBubbleIntersectionCounts = (ArrayList<int[][]>)ibic.clone();
   }
 
Example 17
Source File: CellLayout.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public ViewCluster(ArrayList<View> views, ItemConfiguration config) {
    this.views = (ArrayList<View>) views.clone();
    this.config = config;
    resetEdges();
}
 
Example 18
Source File: EditableTreeTableLineItem.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param label         label of the line item
 * @param relevantitems number of items in this line-item
 */
@SuppressWarnings("unchecked")
public EditableTreeTableLineItem(String label, ArrayList<E> relevantitems) {
	this.relevantitems = (ArrayList<E>) relevantitems.clone();
	this.label = label;
}
 
Example 19
Source File: ParameterDialog.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Object[] getElements( Object inputElement )
{
	ArrayList list = ( (ArrayList) inputElement );
	ArrayList elementsList = (ArrayList) list.clone( );
	return elementsList.toArray( );
}
 
Example 20
Source File: CellLayout.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public ViewCluster(ArrayList<View> views, ItemConfiguration config) {
    this.views = (ArrayList<View>) views.clone();
    this.config = config;
    resetEdges();
}