Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilation warnings fixes #2606

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author michael
*/
@SuppressWarnings("serial")
public class BitSet implements Serializable {

private long store = 0l;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static BitSet from(EnumSet<?> es) {
return emptySet();
}
BitSet retVal = new BitSet();
for (Enum e : es) {
for (Enum<?> e : es) {
retVal.set(e.ordinal());
}
return retVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public static Locale getCurrentLocale() {

// -------------------- PRIVATE --------------------

private static String getStringFromPropertyFile(String bundleKey, String bundleName) throws MissingResourceException {
return getStringFromPropertyFile(bundleKey, bundleName, getCurrentLocale());
}

/**
* Gets display name for specified bundle key. If it is external bundle,
* method tries to access external directory (jvm property - dataverse.lang.directory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package edu.harvard.iq.dataverse.persistence.dataset;

import edu.harvard.iq.dataverse.common.BundleUtil;
import edu.harvard.iq.dataverse.persistence.dataverse.Dataverse;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
Expand All @@ -18,6 +15,13 @@
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import static edu.harvard.iq.dataverse.common.BundleUtil.getStringFromNonDefaultBundle;
import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REMOVE;
import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
Expand All @@ -37,7 +41,7 @@ public class MetadataBlock implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(nullable = false)
Expand Down Expand Up @@ -72,7 +76,7 @@ public void setNamespaceUri(String namespaceUri) {
this.namespaceUri = namespaceUri;
}

@OneToMany(mappedBy = "metadataBlock", cascade = {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.PERSIST})
@OneToMany(mappedBy = "metadataBlock", cascade = {REMOVE, MERGE, PERSIST})
@OrderBy("displayOrder")
private List<DatasetFieldType> datasetFieldTypes;

Expand All @@ -85,12 +89,8 @@ public void setDatasetFieldTypes(List<DatasetFieldType> datasetFieldTypes) {
}

public boolean isDisplayOnCreate() {
for (DatasetFieldType dsfType : datasetFieldTypes) {
if (dsfType.isDisplayOnCreate()) {
return true;
}
}
return false;
return this.datasetFieldTypes.stream()
.anyMatch(DatasetFieldType::isDisplayOnCreate);
}

public String getDisplayName() {
Expand All @@ -107,7 +107,8 @@ public boolean isCitationMetaBlock() {
}

@OneToOne
@JoinColumn(name = "owner_id", unique = false, nullable = true, insertable = true, updatable = true)
@JoinColumn(name = "owner_id", unique = false, nullable = true,
insertable = true, updatable = true)
private Dataverse owner;

public Dataverse getOwner() {
Expand Down Expand Up @@ -188,7 +189,7 @@ public String toString() {
}

public String getLocaleDisplayName() {
String localeDisplayName = BundleUtil.getStringFromNonDefaultBundle("metadatablock.displayName", getName());
String localeDisplayName = getStringFromNonDefaultBundle("metadatablock.displayName", getName());
return localeDisplayName.isEmpty() ? displayName : localeDisplayName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.harvard.iq.dataverse.persistence.dataset;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

public class MetadataBlockTest {

@Test
void isDisplayOnCreate_works() {
MetadataBlock block = new MetadataBlock();
block.setDatasetFieldTypes(new ArrayList<>());

assertThat(block.isDisplayOnCreate()).isFalse();

block.getDatasetFieldTypes().add(new DatasetFieldType());

assertThat(block.isDisplayOnCreate()).isFalse();

block.getDatasetFieldTypes().add(new DatasetFieldType());

assertThat(block.isDisplayOnCreate()).isFalse();

block.getDatasetFieldTypes().get(1).setDisplayOnCreate(true);

assertThat(block.isDisplayOnCreate()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public Response replaceFileInDataset(
// -------------------------------------
if ((jsonObj.has("forceReplace")) && (!jsonObj.get("forceReplace").isJsonNull())) {
forceReplace = jsonObj.get("forceReplace").getAsBoolean();
if (forceReplace == null) {
forceReplace = false;
}
}
try {
// (2b) Load up optional params via JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ public String getAffiliation(String shibIdp, DevShibAccountType devShibAccountTy
logger.info(ex.toString());
return null;
}
if (url == null) {
logger.info("url object was null after parsing " + discoFeedUrl);
return null;
}
HttpURLConnection discoFeedRequest = null;
try {
discoFeedRequest = (HttpURLConnection) url.openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void afterJob() throws Exception {
doReport();

// report any unused checksums
HashMap checksumHashMap = (HashMap<String, String>) jobContext.getTransientUserData();
HashMap<String, String> checksumHashMap = (HashMap<String, String>) jobContext.getTransientUserData();
for (Object key : checksumHashMap.keySet()) {
getJobLogger().log(Level.SEVERE, "File listed in checksum manifest not found: " + key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ private void rescaleImage(BufferedImage fullSizeImage, int width, int height, in
thumbImage = makeColorTransparent(bufferedImageForTransparency, new Color(color));
*/
ImageWriter writer = null;
Iterator iter = ImageIO.getImageWritersByFormatName("png");
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("png");
if (iter.hasNext()) {
writer = (ImageWriter) iter.next();
writer = iter.next();
} else {
throw new IOException("Failed to locatie ImageWriter plugin for image type PNG");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ public <T> Iterator<T> getServiceProviders(Class<T> category,
if (reg == null) {
throw new IllegalArgumentException("category unknown!");
}
Iterator iter = getServiceProviders(category, useOrdering);
return new FilterIterator(iter, filter);
Iterator<T> iter = getServiceProviders(category, useOrdering);
return new FilterIterator<T>(iter, filter);
}

/**
Expand All @@ -531,7 +531,7 @@ public <T> T getServiceProviderByClass(Class<T> providerClass) {
if (providerClass == null) {
throw new IllegalArgumentException("providerClass == null!");
}
for (Class c : categoryMap.keySet()) {
for (Class<?> c : categoryMap.keySet()) {
if (c.isAssignableFrom(providerClass)) {
SubRegistry reg = categoryMap.get(c);
T provider = reg.getServiceProviderByClass(providerClass);
Expand Down Expand Up @@ -652,11 +652,7 @@ public void deregisterAll(Class<?> category) {
* categories.
*/
public void deregisterAll() {
Iterator iter = categoryMap.values().iterator();
while (iter.hasNext()) {
SubRegistry reg = (SubRegistry) iter.next();
reg.clear();
}
this.categoryMap.values().forEach(SubRegistry::clear);
}

/**
Expand Down Expand Up @@ -762,7 +758,7 @@ public <T> T getServiceProviderByClass(Class<T> providerClass) {
}

public void clear() {
Iterator iter = map.values().iterator();
Iterator<Object> iter = map.values().iterator();
while (iter.hasNext()) {
Object provider = iter.next();
iter.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,9 @@ public void removeAllTimers() {

int i = 0;

for (Iterator it = timerService.getTimers().iterator(); it.hasNext(); ) {

Timer timer = (Timer) it.next();

for(final Timer timer : timerService.getTimers()) {
logger.info("Removing timer " + i + ";");
timer.cancel();

i++;
}
logger.info("Done!");
Expand All @@ -269,9 +265,7 @@ public void removeHarvestTimers() {
logger.log(Level.INFO, "Removing existing harvest timers..");

int i = 1;
for (Iterator it = timerService.getTimers().iterator(); it.hasNext(); ) {

Timer timer = (Timer) it.next();
for(final Timer timer : timerService.getTimers()) {
logger.log(Level.INFO, "HarvesterService: checking timer " + i);

if (timer.getInfo() instanceof HarvestTimerInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ public void setUp() {
gbResp.setGuestbook(gbA);
gbResp.setDataset(movedResponses);

List<Guestbook> includeA = new ArrayList();
List<Guestbook> includeA = new ArrayList<>();
includeA.add(gbA);
includeA.add(gbB);

grandchildAA.setGuestbooks(includeA);

List<Guestbook> notIncludeA = new ArrayList();
List<Guestbook> notIncludeA = new ArrayList<>();
notIncludeA.add(gbC);
notIncludeA.add(gbB);

childB.setGuestbooks(notIncludeA);

List<Guestbook> none = new ArrayList();
List<Guestbook> none = new ArrayList<>();
root.setGuestbooks(none);
grandchildBB.setGuestbooks(none);
grandchildBB.setGuestbookRoot(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void setUp() {
datasetC.setGuestbook(gbA);
datasetCC.setGuestbook(gbA);

List<Guestbook> noneGb = new ArrayList();
List<Guestbook> noneGb = new ArrayList<>();
root.setGuestbooks(noneGb);
childA.setGuestbooks(noneGb);
grandchildAA.setGuestbooks(noneGb);
Expand Down
Loading