-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
183 additions
and
60 deletions.
There are no files selected for viewing
55 changes: 31 additions & 24 deletions
55
src/main/java/net/karneim/pojobuilder/model/ImportTypesM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,58 @@ | ||
package net.karneim.pojobuilder.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
public class ImportTypesM { | ||
private final Set<TypeM> types = new HashSet<>(); | ||
private final SortedSet<String> classnames = new TreeSet<>(); | ||
private final Set<String> simpleNames = new HashSet<>(); | ||
|
||
public void add(Class<?> aClass) { | ||
add(new TypeM(aClass)); | ||
} | ||
|
||
public boolean add(TypeM e) { | ||
if (simpleNames.contains(e.getSimpleName())) { | ||
public boolean add(TypeM type) { | ||
if (!simpleNames.contains(type.getSimpleName())) { | ||
types.add(type); | ||
if (!type.isTypeVariable() && !type.isPrimitive()) { | ||
classnames.add(type.getName()); | ||
} | ||
simpleNames.add(type.getSimpleName()); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
simpleNames.add(e.getSimpleName()); | ||
return types.add(e); | ||
} | ||
|
||
public boolean canAdd(TypeM typeM) { | ||
return !types.contains(typeM) && !simpleNames.contains(typeM.getSimpleName()); | ||
public void remove(TypeM type) { | ||
types.remove(type); | ||
classnames.remove(type.getName()); | ||
simpleNames.remove(type.getSimpleName()); | ||
} | ||
|
||
public List<String> getSortedDistinctClassnames() { | ||
Set<String> resultSet = new HashSet<String>(); | ||
for (TypeM t : this.types) { | ||
if (!t.isTypeVariable() && !t.isPrimitive()) { | ||
resultSet.add(t.getName()); | ||
} | ||
} | ||
List<String> result = new ArrayList<String>(resultSet); | ||
Collections.sort(result); | ||
return result; | ||
public SortedSet<String> getSortedDistinctClassnames() { | ||
return classnames; | ||
} | ||
|
||
public void removePackage(String packageName) { | ||
Iterator<TypeM> it = this.types.iterator(); | ||
while (it.hasNext()) { | ||
TypeM t = it.next(); | ||
if (t.isInPackage(packageName)) { | ||
it.remove(); | ||
for (TypeM type : new ArrayList<>(types)) { | ||
if (type.isInPackage(packageName)) { | ||
remove(type); | ||
} | ||
} | ||
} | ||
|
||
public String getCompressedTypeName(TypeM type) { | ||
add(type); | ||
if (classnames.contains(type.getName())) { | ||
return type.getSimpleName(); | ||
} else { | ||
return type.getName(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ojobuilder/processor/with/ambiguousimports/optional/PojoWithAmbiguousOptionalImports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.karneim.pojobuilder.processor.with.ambiguousimports.optional; | ||
|
||
import net.karneim.pojobuilder.GeneratePojoBuilder; | ||
|
||
@GeneratePojoBuilder(withOptionalProperties=java.util.Optional.class) | ||
public class PojoWithAmbiguousOptionalImports { | ||
public com.google.common.base.Optional<String> field; | ||
} |
Oops, something went wrong.