下面列出了java.util.ArrayList#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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);
}
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());
}
@SuppressWarnings("unchecked")
private ArrayList<AnimatorListener> cloneListeners() {
ArrayList<AnimatorListener> listeners = getListeners();
if (listeners != null) {
listeners = (ArrayList<AnimatorListener>) listeners.clone();
}
return listeners;
}
private synchronized ArrayList getClonedChangeListeners() {
ArrayList listeners = this.changeListeners;
if (listeners == null) {
return null;
}
return (ArrayList) listeners.clone();
}
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;
}
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;
}
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);
}
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;
}
/**
*
*/
ConditionalPermissionUpdateImpl(ConditionalPermissionInfoStorage cpis,
ArrayList<ConditionalPermissionInfoImpl> org,
int generation)
{
storage = cpis;
@SuppressWarnings({ "unchecked", "rawtypes" })
final ArrayList<ConditionalPermissionInfo> clone = (ArrayList) org.clone();
cpiTable = clone;
parent = generation;
}
/**
* @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;
}
@SuppressWarnings("unchecked")
public ViewCluster(ArrayList<View> views, ItemConfiguration config) {
this.views = (ArrayList<View>) views.clone();
this.config = config;
resetEdges();
}
public Object[] getElements( Object inputElement )
{
ArrayList list = ( (ArrayList) inputElement );
ArrayList elementsList = (ArrayList) list.clone( );
return elementsList.toArray( );
}
/**
* <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;
}
@SuppressWarnings("unchecked")
public ViewCluster(ArrayList<View> views, ItemConfiguration config) {
this.views = (ArrayList<View>) views.clone();
this.config = config;
resetEdges();
}
public void setInterBubbleIntersectionCounts(ArrayList<int[][]> ibic){
this.interBubbleIntersectionCounts = (ArrayList<int[][]>)ibic.clone();
}
public Builder setFilter(ArrayList<String> filterList) {
if ( filterList != null ) {
this.filterList = (ArrayList<String>) filterList.clone();
}
return this;
}
public Words(ArrayList<String> words, boolean[] used){
this.words = (ArrayList<String>) words.clone();
this.used = arrayCopy(used, 0, words.size());
}
/**
* 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;
}
@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));
}