use of javax.annotation.CheckForNull in project JMRI by JMRI.
the class StoreXmlConfigAction method getFileCustom.
/**
* Do the filename handling:
* <OL>
* <LI>rescan directory to see any new files
* <LI>Prompt user to select a file
* <LI>adds .xml extension if needed
* <LI>if that file exists, check with user
* </OL>
*
* @param fileChooser the file chooser to use
* @return the file to store or null if the user declined to store a file
*/
@CheckForNull
public static File getFileCustom(JFileChooser fileChooser) {
fileChooser.rescanCurrentDirectory();
int retVal = fileChooser.showDialog(null, null);
if (retVal != JFileChooser.APPROVE_OPTION) {
// give up if no file selected
return null;
}
File file = fileChooser.getSelectedFile();
if (fileChooser.getFileFilter() != fileChooser.getAcceptAllFileFilter()) {
// append .xml to file name if needed
String fileName = file.getAbsolutePath();
String fileNameLC = fileName.toLowerCase();
if (!fileNameLC.endsWith(".xml")) {
fileName = fileName + ".xml";
file = new File(fileName);
}
}
if (log.isDebugEnabled()) {
log.debug("Save file: " + file.getPath());
}
// check for possible overwrite
if (file.exists()) {
int selectedValue = JOptionPane.showConfirmDialog(null, Bundle.getMessage("FileOverwriteWarning", file.getName()), Bundle.getMessage("OverwriteFile"), JOptionPane.OK_CANCEL_OPTION);
if (selectedValue != JOptionPane.OK_OPTION) {
return null;
}
}
return file;
}
use of javax.annotation.CheckForNull in project JMRI by JMRI.
the class LayoutBlock method getNextBlock.
/**
* Used if we already know the block prior to our block, and the destination
* block. direction, is optional and is used where the previousBlock is
* equal to our block.
*/
@CheckForNull
public Block getNextBlock(Block previousBlock, Block destBlock) {
int bestMetric = 965000;
Block bestBlock = null;
for (Routes r : routes) {
if (r.getDestBlock() == destBlock) {
//Check that the route through from the previous block, to the next hop is valid
if (validThroughPath(previousBlock, r.getNextBlock())) {
if (r.getMetric() < bestMetric) {
bestMetric = r.getMetric();
//bestBlock=r.getDestBlock();
bestBlock = r.getNextBlock();
}
}
}
}
return bestBlock;
}
use of javax.annotation.CheckForNull in project sling by apache.
the class SimpleDistributionQueue method remove.
@CheckForNull
public DistributionQueueEntry remove(@Nonnull String id) {
DistributionQueueEntry toRemove = getItem(id);
boolean removed = false;
if (toRemove != null) {
removed = queue.remove(toRemove.getItem());
}
log.debug("item with id {} removed from the queue: {}", id, removed);
if (removed) {
return toRemove;
} else {
return null;
}
}
use of javax.annotation.CheckForNull in project sling by apache.
the class AbstractDistributionPackageBuilder method getPackage.
@CheckForNull
public DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String id) {
DistributionPackage distributionPackage = SimpleDistributionPackage.fromIdString(id, type);
// not a simple package
if (distributionPackage == null) {
if (id.startsWith("reference")) {
String localId = id.substring("reference-".length());
distributionPackage = new ReferencePackage(getPackageInternal(resourceResolver, localId));
} else {
distributionPackage = getPackageInternal(resourceResolver, id);
}
}
return distributionPackage;
}
use of javax.annotation.CheckForNull in project sling by apache.
the class OsgiInstallerImpl method getInstallationState.
/**
* @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
*/
@Override
public InstallationState getInstallationState() {
synchronized (this.resourcesLock) {
final InstallationState state = new InstallationState() {
private final List<ResourceGroup> activeResources = new ArrayList<>();
private final List<ResourceGroup> installedResources = new ArrayList<>();
private final List<RegisteredResource> untransformedResources = new ArrayList<>();
@Override
public List<ResourceGroup> getActiveResources() {
return activeResources;
}
@Override
public List<ResourceGroup> getInstalledResources() {
return installedResources;
}
@Override
public List<RegisteredResource> getUntransformedResources() {
return untransformedResources;
}
@Override
public String toString() {
return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
}
};
for (final String entityId : this.persistentList.getEntityIds()) {
if (!this.persistentList.isSpecialEntityId(entityId)) {
final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
final String alias = group.getAlias();
final List<Resource> resources = new ArrayList<>();
boolean first = true;
boolean isActive = false;
for (final TaskResource tr : group.getResources()) {
final ResourceState resourceState = tr.getState();
if (first) {
if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
isActive = true;
}
first = false;
}
resources.add(new Resource() {
@Override
public String getScheme() {
return tr.getScheme();
}
@Override
public String getURL() {
return tr.getURL();
}
@Override
public String getType() {
return tr.getType();
}
@Override
public InputStream getInputStream() throws IOException {
return tr.getInputStream();
}
@Override
public Dictionary<String, Object> getDictionary() {
return tr.getDictionary();
}
@Override
public String getDigest() {
return tr.getDigest();
}
@Override
public int getPriority() {
return tr.getPriority();
}
@Override
public String getEntityId() {
return tr.getEntityId();
}
@Override
public ResourceState getState() {
return resourceState;
}
@Override
public Version getVersion() {
return tr.getVersion();
}
@Override
public long getLastChange() {
return ((RegisteredResourceImpl) tr).getLastChange();
}
@Override
public Object getAttribute(final String key) {
return tr.getAttribute(key);
}
@Override
@CheckForNull
public String getError() {
return tr.getError();
}
@Override
public String toString() {
return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
}
});
}
final ResourceGroup rg = new ResourceGroup() {
@Override
public List<Resource> getResources() {
return resources;
}
@Override
public String getAlias() {
return alias;
}
@Override
public String toString() {
return "group[" + resources + "]";
}
};
if (isActive) {
state.getActiveResources().add(rg);
} else {
state.getInstalledResources().add(rg);
}
}
}
Collections.sort(state.getActiveResources(), COMPARATOR);
Collections.sort(state.getInstalledResources(), COMPARATOR);
state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
return state;
}
}
Aggregations