List of usage examples for java.lang.ref SoftReference SoftReference
public SoftReference(T referent)
From source file:org.kuali.coeus.propdev.impl.budget.subaward.BudgetSubAwards.java
public void setSubAwardXmlFileData(String subAwardXmlFileData) { if (subAwardXmlFileData == null) { getKcAttachmentDao().removeData(xmlDataId); xmlDataId = null;/*from w w w .j ava 2 s . co m*/ } else { xmlDataId = getKcAttachmentDao().saveData(subAwardXmlFileData.getBytes(StandardCharsets.UTF_8), xmlDataId); } this.subAwardXmlFileData = new SoftReference<String>(subAwardXmlFileData); }
From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram2D.java
protected double[] getSatArray() { double[] satArray = null; if (satArrayReference == null || satArrayReference.get() == null) { satArray = (double[]) getScanAcquisitionTime().get1DJavaArray(double.class); satArrayReference = new SoftReference<>(satArray); } else {//w w w .ja va 2 s .c o m satArray = satArrayReference.get(); } return satArray; }
From source file:com.achep.acdisplay.Config.java
@NonNull public HashMap<String, Option> getHashMap() { HashMap<String, Option> hashMap = mHashMapRef.get(); if (hashMap == null) { hashMap = new HashMap<>(); hashMap.put(KEY_ENABLED, new Option("setEnabled", "isEnabled", boolean.class)); hashMap.put(KEY_KEYGUARD, new Option("setKeyguardEnabled", "isKeyguardEnabled", boolean.class)); hashMap.put(KEY_ACTIVE_MODE, new Option("setActiveModeEnabled", "isActiveModeEnabled", boolean.class)); hashMap.put(KEY_ACTIVE_MODE_WITHOUT_NOTIFICATIONS, new Option("setActiveModeWithoutNotificationsEnabled", "isActiveModeWithoutNotifiesEnabled", boolean.class)); hashMap.put(KEY_NOTIFY_LOW_PRIORITY, new Option("setLowPriorityNotificationsAllowed", "isLowPriorityNotificationsAllowed", boolean.class)); hashMap.put(KEY_NOTIFY_WAKE_UP_ON, new Option("setWakeUpOnNotifyEnabled", "isNotifyWakingUp", boolean.class)); hashMap.put(KEY_ONLY_WHILE_CHARGING, new Option("setEnabledOnlyWhileCharging", "isEnabledOnlyWhileCharging", boolean.class)); hashMap.put(KEY_UI_FULLSCREEN, new Option("setFullScreen", "isFullScreen", boolean.class)); hashMap.put(KEY_UI_WALLPAPER_SHOWN, new Option("setWallpaperShown", "isWallpaperShown", boolean.class)); hashMap.put(KEY_UI_SHADOW_TOGGLE, new Option("setShadowEnabled", "isShadowEnabled", boolean.class)); hashMap.put(KEY_UI_MIRRORED_TIMEOUT_BAR, new Option("setMirroredTimeoutProgressBarEnabled", "isMirroredTimeoutProgressBarEnabled", boolean.class)); hashMap.put(KEY_UI_NOTIFY_CIRCLED_ICON, new Option("setCircledLargeIconEnabled", "isCircledLargeIconEnabled", boolean.class)); hashMap.put(KEY_UI_STATUS_BATTERY_STICKY, new Option("setStatusBatterySticky", "isStatusBatterySticky", boolean.class)); hashMap.put(KEY_UI_UNLOCK_ANIMATION, new Option("setUnlockAnimationEnabled", "isUnlockAnimationEnabled", boolean.class)); hashMap.put(KEY_FEEL_SCREEN_OFF_AFTER_LAST_NOTIFY, new Option("setScreenOffAfterLastNotify", "isScreenOffAfterLastNotify", boolean.class)); hashMap.put(KEY_FEEL_WIDGET_PINNABLE, new Option("setWidgetPinnable", "isWidgetPinnable", boolean.class)); hashMap.put(KEY_FEEL_WIDGET_READABLE, new Option("setWidgetReadable", "isWidgetReadable", boolean.class)); hashMap.put(KEY_DEV_SENSORS_DUMP, new Option("setDevSensorsDumpEnabled", "isDevSensorsDumpEnabled", boolean.class)); mHashMapRef = new SoftReference<>(hashMap); }/* w w w .ja va2 s . c o m*/ return hashMap; }
From source file:ch.rasc.extclassgenerator.ModelGenerator.java
public static ModelBean createModel(final Class<?> clazz, final OutputConfig outputConfig) { Assert.notNull(clazz, "clazz must not be null"); Assert.notNull(outputConfig.getIncludeValidation(), "includeValidation must not be null"); ModelCacheKey key = new ModelCacheKey(clazz.getName(), outputConfig); SoftReference<ModelBean> modelReference = modelCache.get(key); if (modelReference != null && modelReference.get() != null) { return modelReference.get(); }/*from w w w . ja va 2 s .co m*/ Model modelAnnotation = clazz.getAnnotation(Model.class); final ModelBean model = new ModelBean(); if (modelAnnotation != null && StringUtils.hasText(modelAnnotation.value())) { model.setName(modelAnnotation.value()); } else { model.setName(clazz.getName()); } if (modelAnnotation != null) { model.setAutodetectTypes(modelAnnotation.autodetectTypes()); } if (modelAnnotation != null) { model.setExtend(modelAnnotation.extend()); model.setIdProperty(modelAnnotation.idProperty()); model.setVersionProperty(trimToNull(modelAnnotation.versionProperty())); model.setPaging(modelAnnotation.paging()); model.setDisablePagingParameters(modelAnnotation.disablePagingParameters()); model.setCreateMethod(trimToNull(modelAnnotation.createMethod())); model.setReadMethod(trimToNull(modelAnnotation.readMethod())); model.setUpdateMethod(trimToNull(modelAnnotation.updateMethod())); model.setDestroyMethod(trimToNull(modelAnnotation.destroyMethod())); model.setMessageProperty(trimToNull(modelAnnotation.messageProperty())); model.setWriter(trimToNull(modelAnnotation.writer())); model.setReader(trimToNull(modelAnnotation.reader())); model.setSuccessProperty(trimToNull(modelAnnotation.successProperty())); model.setTotalProperty(trimToNull(modelAnnotation.totalProperty())); model.setRootProperty(trimToNull(modelAnnotation.rootProperty())); model.setWriteAllFields(modelAnnotation.writeAllFields()); model.setIdentifier(trimToNull(modelAnnotation.identifier())); String clientIdProperty = trimToNull(modelAnnotation.clientIdProperty()); if (StringUtils.hasText(clientIdProperty)) { model.setClientIdProperty(clientIdProperty); model.setClientIdPropertyAddToWriter(true); } else { model.setClientIdProperty(null); model.setClientIdPropertyAddToWriter(false); } } final Set<String> hasReadMethod = new HashSet<String>(); BeanInfo bi; try { bi = Introspector.getBeanInfo(clazz); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor pd : bi.getPropertyDescriptors()) { if (pd.getReadMethod() != null && pd.getReadMethod().getAnnotation(JsonIgnore.class) == null) { hasReadMethod.add(pd.getName()); } } if (clazz.isInterface()) { final List<Method> methods = new ArrayList<Method>(); ReflectionUtils.doWithMethods(clazz, new MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { methods.add(method); } }); Collections.sort(methods, new Comparator<Method>() { @Override public int compare(Method o1, Method o2) { return o1.getName().compareTo(o2.getName()); } }); for (Method method : methods) { createModelBean(model, method, outputConfig); } } else { final Set<String> fields = new HashSet<String>(); Set<ModelField> modelFieldsOnType = AnnotationUtils.getRepeatableAnnotation(clazz, ModelFields.class, ModelField.class); for (ModelField modelField : modelFieldsOnType) { if (StringUtils.hasText(modelField.value())) { ModelFieldBean modelFieldBean; if (StringUtils.hasText(modelField.customType())) { modelFieldBean = new ModelFieldBean(modelField.value(), modelField.customType()); } else { modelFieldBean = new ModelFieldBean(modelField.value(), modelField.type()); } updateModelFieldBean(modelFieldBean, modelField); model.addField(modelFieldBean); } } Set<ModelAssociation> modelAssociationsOnType = AnnotationUtils.getRepeatableAnnotation(clazz, ModelAssociations.class, ModelAssociation.class); for (ModelAssociation modelAssociationAnnotation : modelAssociationsOnType) { AbstractAssociation modelAssociation = AbstractAssociation .createAssociation(modelAssociationAnnotation); if (modelAssociation != null) { model.addAssociation(modelAssociation); } } Set<ModelValidation> modelValidationsOnType = AnnotationUtils.getRepeatableAnnotation(clazz, ModelValidations.class, ModelValidation.class); for (ModelValidation modelValidationAnnotation : modelValidationsOnType) { AbstractValidation modelValidation = AbstractValidation.createValidation( modelValidationAnnotation.propertyName(), modelValidationAnnotation, outputConfig.getIncludeValidation()); if (modelValidation != null) { model.addValidation(modelValidation); } } ReflectionUtils.doWithFields(clazz, new FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { if (!fields.contains(field.getName()) && (field.getAnnotation(ModelField.class) != null || field.getAnnotation(ModelAssociation.class) != null || (Modifier.isPublic(field.getModifiers()) || hasReadMethod.contains(field.getName())) && field.getAnnotation(JsonIgnore.class) == null)) { // ignore superclass declarations of fields already // found in a subclass fields.add(field.getName()); createModelBean(model, field, outputConfig); } } }); } modelCache.put(key, new SoftReference<ModelBean>(model)); return model; }
From source file:com.li.utils.ui.mdbottom.BottomNavigation.java
public void setDefaultTypeface(final Typeface typeface) { this.typeface = new SoftReference<>(typeface); }
From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java
/** * Reads in the disciplines file (is loaded when the class is loaded). * @return Reads in the disciplines file (is loaded when the class is loaded). *//*from ww w . j a v a 2 s . c o m*/ public static DBTableIdMgr getDatabaseSchema() { DBTableIdMgr schema = null; if (databasechema != null) { schema = databasechema.get(); } if (schema == null) { schema = new DBTableIdMgr(false); //check for custom config files in appdatadir File customSchemaFile = new File( UIRegistry.getAppDataDir() + File.separator + "specify_workbench_datamodel.xml"); File customDefFile = new File( UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml"); if (customSchemaFile.exists() && !customDefFile.exists()) { log.error( "a customized specify_workbench_datamodel.xml was found but not loaded because a customized specify_workbench_upload_def.xml was not found"); } else if (!customSchemaFile.exists() && customDefFile.exists()) { log.error( "a customized specify_workbench_upload_def.xml was found but not loaded because a customized specify_workbench_datamodel.xml was not found"); } if (customSchemaFile.exists() && customDefFile.exists()) { schema.initialize(customSchemaFile); isCustomizedSchema = true; } else { schema.initialize(new File(XMLHelper.getConfigDirPath("specify_workbench_datamodel.xml"))); } databasechema = new SoftReference<DBTableIdMgr>(schema); SchemaLocalizerXMLHelper schemaLocalizer = new SchemaLocalizerXMLHelper( SpLocaleContainer.WORKBENCH_SCHEMA, schema); schemaLocalizer.load(true); schemaLocalizer.setTitlesIntoSchema(); DBTableIdMgr mgr = databasechema.get(); DBTableInfo taxonOnly = mgr.getInfoById(4000); if (taxonOnly != null) { taxonOnly.setTitle(getResourceString("WB_TAXONIMPORT_ONLY")); //taxonOnly.setTableId(4); } } return schema; }
From source file:edu.ksu.cis.santos.mdcf.dml.symbol.SymbolTable.java
/** * Retrieves all {@link FeatureInit}s declared in the {@link #models}. * //from w w w. j a v a2s. co m * @return an immutable {@link List}. */ public List<FeatureInit> featureInits() { List<FeatureInit> result = null; if ((this._featureInits == null) || ((result = this._featureInits.get()) == null)) { final ImmutableList.Builder<FeatureInit> b = ImmutableList.builder(); new AbstractVisitor() { @Override public boolean visitFeatureInit(final FeatureInit node) { b.add(node); return true; } }.visit(this.models); result = b.build(); this._featureInits = new SoftReference<List<FeatureInit>>(result); } return result; }
From source file:de.fhg.igd.mapviewer.AbstractTileOverlayPainter.java
private void cacheTile(int x, int y, int zoom, BufferedImage img) { synchronized (cache) { // cache per zoom TIntObjectHashMap<TIntObjectHashMap<SoftReference<BufferedImage>>> zoomCache = cache.get(zoom); if (zoomCache == null) { zoomCache = new TIntObjectHashMap<TIntObjectHashMap<SoftReference<BufferedImage>>>(); cache.put(zoom, zoomCache);// w w w. ja v a 2s . c o m } // cache per x TIntObjectHashMap<SoftReference<BufferedImage>> xCache = zoomCache.get(x); if (xCache == null) { xCache = new TIntObjectHashMap<SoftReference<BufferedImage>>(); zoomCache.put(x, xCache); } // image cache xCache.put(y, new SoftReference<BufferedImage>(img)); } }
From source file:org.apache.sysml.utils.PersistentLRUCache.java
ValueWrapper(DataWrapper data, boolean isInReadOnlyMode) { _lock = new Object(); _isInReadOnlyMode = isInReadOnlyMode; boolean isDummyValue = (data._key == PersistentLRUCache.dummyKey); if (!_isInReadOnlyMode && !isDummyValue) { // Aggressive write to disk when the cache is used in the write-mode. // This avoids the need to depend on finalize to perform writing. Thread t = new Thread() { public void run() { try { data.write(true);//from ww w . jav a 2s . co m } catch (IOException e) { throw new DMLRuntimeException("Error occured while aggressively writing the value to disk.", e); } } }; t.start(); } _softRef = new SoftReference<>(data); if (data._mb != null) { _rlen = data._mb.getNumRows(); _clen = data._mb.getNumColumns(); _nnz = data._mb.getNonZeros(); } }
From source file:org.apache.sysml.utils.PersistentLRUCache.java
void update(DataWrapper data) { _softRef = new SoftReference<>(data); if (data._mb != null) { _rlen = data._mb.getNumRows();//w ww. j a v a 2 s. c o m _clen = data._mb.getNumColumns(); _nnz = data._mb.getNonZeros(); } }