BrightSide Workbench Full Report + Source Code
MetaList.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.context;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24 import org.turro.util.CompareUtil;
25 
30 public class MetaList extends ArrayList<String> {
31 
32  public MetaList(Collection<? extends String> c) {
33  super(c);
34  }
35 
36  @Override
37  public boolean addAll(Collection<? extends String> c) {
38  if(c == null) return false;
39  for(String s : c) {
40  add(s);
41  }
42  return true;
43  }
44 
45  @Override
46  public boolean add(String e) {
47  Iterator<String> it = iterator();
48  while(it.hasNext()) {
49  String meta = it.next();
50  if(isSameProperty(meta, e)) {
51  it.remove();
52  }
53  }
54  return super.add(e);
55  }
56 
57  private boolean isSameProperty(String meta1, String meta2) {
58  return CompareUtil.compare(metaProperty(meta1), metaProperty(meta2)) == 0;
59  }
60 
61  private String metaProperty(String meta) {
62  int p = meta.indexOf("content=");
63  if(p > -1) {
64  return meta.substring(0, p).toLowerCase().trim();
65  } else {
66  return meta.toLowerCase().trim();
67  }
68  }
69 
70 }
MetaList(Collection<? extends String > c)
Definition: MetaList.java:32
boolean addAll(Collection<? extends String > c)
Definition: MetaList.java:37