hudson.util.CopyOnWriteList Java Examples

The following examples show how to use hudson.util.CopyOnWriteList. 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: CopyOnWriteListMapper.java    From DotCi with MIT License 6 votes vote down vote up
@Override
public void fromDBObject(DBObject dbObject, MappedField mf, Object entity, EntityCache cache, Mapper mapper) {
    BasicDBList cowlist = (BasicDBList) dbObject.get(mf.getNameToStore());

    if (cowlist == null)
        throw new IllegalArgumentException("Improperly formatted DBObject for CopyOnWriteList");

    List core = new ArrayList();
    for (Object obj : cowlist) {
        DBObject listEntryDbObj = (DBObject) obj;

        // Hack until we can coax MappedField to understand what CopyOnWriteList is. Eliminate as soon as possible.
        // Currently mf.getSubType() is null because MappedField does not use Iterable to determine a list and thus
        // does not check for subtypes.
        Class clazz = mapper.getOptions().getObjectFactory().createInstance(mapper, mf, listEntryDbObj).getClass();

        core.add(mapper.fromDBObject(clazz, listEntryDbObj, cache));
    }
    mf.setFieldValue(entity, new CopyOnWriteList(core));
}
 
Example #2
Source File: CopyOnWriteListConverter.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo) {
    if (fromDBObject == null) return null;

    BasicDBList rawList = (BasicDBList) fromDBObject;

    List core = new ArrayList();
    for (Object obj : rawList) {
        DBObject dbObj = (DBObject) obj;
        core.add(getMapper().fromDBObject(optionalExtraInfo.getSubClass(), dbObj, getMapper().createEntityCache()));
    }

    return new CopyOnWriteList(core);
}
 
Example #3
Source File: CopyOnWriteListConverter.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public Object encode(Object value, MappedField optionalExtraInfo) {
    if (value == null) return null;

    CopyOnWriteList copyOnWriteList = (CopyOnWriteList) value;
    List core = new BasicDBList();

    for (Object obj : copyOnWriteList) {
        core.add(getMapper().toDBObject(obj));
    }

    return core;
}
 
Example #4
Source File: CopyOnWriteListMapper.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public void toDBObject(Object entity, MappedField mf, DBObject dbObject, Map<Object, DBObject> involvedObjects, Mapper mapper) {
    final String name = mf.getNameToStore();
    CopyOnWriteList copyOnWriteList = (CopyOnWriteList) mf.getFieldValue(entity);
    List core = new ArrayList();

    mf.getSubType();

    for (Object obj : copyOnWriteList) {
        core.add(mapper.toDBObject(obj, involvedObjects));
    }

    dbObject.put(name, core);
}
 
Example #5
Source File: JenkinsMapper.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public DBObject toDBObject(final Object entity, final Map<Object, DBObject> involvedObjects) {
    if (!(entity instanceof CopyOnWriteList || involvedObjects.containsKey(entity))) {
        involvedObjects.put(entity, null);
    }

    return super.toDBObject(entity, involvedObjects);
}
 
Example #6
Source File: JenkinsEmbeddedMapper.java    From DotCi with MIT License 5 votes vote down vote up
JenkinsEmbeddedMapper() {
    this.customMappers = new HashMap<>();
    this.customMappers.put(CopyOnWriteList.class, new CopyOnWriteListMapper());

    this.serializationMethodInvoker = new SerializationMethodInvoker();

    this.awkwardMapper = new MapKeyValueMapper();
}
 
Example #7
Source File: TemplateUtils.java    From ez-templates with Apache License 2.0 5 votes vote down vote up
private static void fixProperties(AbstractProject implementationProject, TemplateImplementationProperty property, boolean implementationIsTemplate) throws IOException {
    CopyOnWriteList<JobProperty<?>> properties = ReflectionUtils.getFieldValue(Job.class, implementationProject, "properties");
    properties.add(property);

    if (!implementationIsTemplate) {
        for (JobProperty<?> jobProperty : properties) {
            if (jobProperty instanceof TemplateProperty) {
                properties.remove(jobProperty);
            }
        }
    }
}
 
Example #8
Source File: CopyOnWriteListConverter.java    From DotCi with MIT License 4 votes vote down vote up
public CopyOnWriteListConverter() {
    super(CopyOnWriteList.class);
}
 
Example #9
Source File: JenkinsMappedClass.java    From DotCi with MIT License 2 votes vote down vote up
/**
 * constructor
 *
 * @param mapper
 */
public CopyOnWriteListMappedClass(final Mapper mapper) {
    super(CopyOnWriteList.class, mapper);
}