}
return Optional.absent();
}
- }
- private static Optional<Double> getDoubleValue(Optional<Measure> measureOptional) {
- if (!measureOptional.isPresent()) {
- return Optional.absent();
- }
- Measure measure = measureOptional.get();
- switch (measure.getValueType()) {
- case DOUBLE:
- return Optional.of(measure.getDoubleValue());
- case LONG:
- return Optional.of((double) measure.getLongValue());
- case INT:
- return Optional.of((double) measure.getIntValue());
- case NO_VALUE:
+ private Optional<Double> getDoubleValue(Optional<Measure> measureOptional) {
+ if (!measureOptional.isPresent()) {
return Optional.absent();
- default:
- throw new IllegalArgumentException(String.format("Measure of type '%s' are not supported", measure.getValueType().name()));
+ }
+ Measure measure = measureOptional.get();
+ switch (measure.getValueType()) {
+ case DOUBLE:
+ return Optional.of(measure.getDoubleValue());
+ case LONG:
+ return Optional.of((double) measure.getLongValue());
+ case INT:
+ return Optional.of((double) measure.getIntValue());
+ case NO_VALUE:
+ return Optional.absent();
+ default:
+ throw new IllegalArgumentException(String.format("Measure of type '%s' are not supported", measure.getValueType().name()));
+ }
}
}
-
}
}
return target.build();
}
- }
- private static DbCommons.TextRange.Builder convertTextRange(BatchReport.TextRange sourceRange) {
- DbCommons.TextRange.Builder targetRange = DbCommons.TextRange.newBuilder();
- if (sourceRange.hasStartLine()) {
- targetRange.setStartLine(sourceRange.getStartLine());
- }
- if (sourceRange.hasStartOffset()) {
- targetRange.setStartOffset(sourceRange.getStartOffset());
- }
- if (sourceRange.hasEndLine()) {
- targetRange.setEndLine(sourceRange.getEndLine());
- }
- if (sourceRange.hasEndOffset()) {
- targetRange.setEndOffset(sourceRange.getEndOffset());
+ private DbCommons.TextRange.Builder convertTextRange(BatchReport.TextRange sourceRange) {
+ DbCommons.TextRange.Builder targetRange = DbCommons.TextRange.newBuilder();
+ if (sourceRange.hasStartLine()) {
+ targetRange.setStartLine(sourceRange.getStartLine());
+ }
+ if (sourceRange.hasStartOffset()) {
+ targetRange.setStartOffset(sourceRange.getStartOffset());
+ }
+ if (sourceRange.hasEndLine()) {
+ targetRange.setEndLine(sourceRange.getEndLine());
+ }
+ if (sourceRange.hasEndOffset()) {
+ targetRange.setEndOffset(sourceRange.getEndOffset());
+ }
+ return targetRange;
}
- return targetRange;
}
}
checkNotNull(outputMetrics);
return outputMetrics;
}
- }
- private static void checkNotNull(String[] metrics) {
- for (String metric : metrics) {
- requireNonNull(metric, "Null metric is not allowed");
+ private static void checkNotNull(String[] metrics) {
+ for (String metric : metrics) {
+ requireNonNull(metric, "Null metric is not allowed");
+ }
}
}
}
}
}
}
- }
- private static double computeVariation(Measure measure, Double pastValue) {
- switch (measure.getValueType()) {
- case INT:
- return measure.getIntValue() - pastValue;
- case LONG:
- return measure.getLongValue() - pastValue;
- case DOUBLE:
- return measure.getDoubleValue() - pastValue;
- case BOOLEAN:
- return (measure.getBooleanValue() ? 1d : 0d) - pastValue;
- default:
- throw new IllegalArgumentException("Unsupported Measure.ValueType " + measure.getValueType());
+ private double computeVariation(Measure measure, Double pastValue) {
+ switch (measure.getValueType()) {
+ case INT:
+ return measure.getIntValue() - pastValue;
+ case LONG:
+ return measure.getLongValue() - pastValue;
+ case DOUBLE:
+ return measure.getDoubleValue() - pastValue;
+ case BOOLEAN:
+ return (measure.getBooleanValue() ? 1d : 0d) - pastValue;
+ default:
+ throw new IllegalArgumentException("Unsupported Measure.ValueType " + measure.getValueType());
+ }
}
}
return existingComponent;
}
}
+
+ private void addToCache(Component component, ComponentDto componentDto) {
+ dbIdsRepository.setComponentId(component, componentDto.getId());
+ }
}
public ComponentDto createForProject(Component project) {
componentDto.setModuleUuidPath(parentModule.moduleUuidPath());
}
- private void addToCache(Component component, ComponentDto componentDto) {
- dbIdsRepository.setComponentId(component, componentDto.getId());
- }
-
private static boolean updateExisting(ComponentDto existingComponent, ComponentDto newComponent) {
boolean modified = false;
if (!StringUtils.equals(existingComponent.name(), newComponent.name())) {
}
}
}
- }
- @CheckForNull
- private static String computeRevision(FileSourceDto previousDto, @Nullable Changeset latestChange) {
- if (latestChange == null) {
- return previousDto.getRevision();
+ @CheckForNull
+ private String computeRevision(FileSourceDto previousDto, @Nullable Changeset latestChange) {
+ if (latestChange == null) {
+ return previousDto.getRevision();
+ }
+ return latestChange.getRevision();
}
- return latestChange.getRevision();
- }
- @CheckForNull
- private static String computeRevision(@Nullable Changeset latestChange) {
- if (latestChange == null) {
- return null;
+ @CheckForNull
+ private String computeRevision(@Nullable Changeset latestChange) {
+ if (latestChange == null) {
+ return null;
+ }
+ return latestChange.getRevision();
}
- return latestChange.getRevision();
}
private static class LineReaders {
}
}
}
- }
- private static String convertType(Constants.ComponentLinkType reportType) {
- String type = typesConverter.get(reportType);
- if (type != null) {
- return type;
- } else {
- throw new IllegalArgumentException(String.format("Unsupported type %s", reportType.name()));
+ private String convertType(Constants.ComponentLinkType reportType) {
+ String type = typesConverter.get(reportType);
+ if (type != null) {
+ return type;
+ } else {
+ throw new IllegalArgumentException(String.format("Unsupported type %s", reportType.name()));
+ }
}
}
commonForAnyVisit(projectView, path, snapshot);
}
+ private void updateSnapshotPeriods(SnapshotDto snapshotDto) {
+ for (Period period : periodsHolder.getPeriods()) {
+ int index = period.getIndex();
+ snapshotDto.setPeriodMode(index, period.getMode());
+ snapshotDto.setPeriodParam(index, period.getModeParameter());
+ snapshotDto.setPeriodDate(index, period.getSnapshotDate());
+ }
+ }
+
private void commonForAnyVisit(Component project, Path<SnapshotDtoHolder> path, SnapshotDto snapshot) {
persist(snapshot, dbSession);
addToCache(project, snapshot);
dbIdsRepository.setSnapshotId(component, snapshotDto.getId());
}
- private void updateSnapshotPeriods(SnapshotDto snapshotDto) {
- for (Period period : periodsHolder.getPeriods()) {
- int index = period.getIndex();
- snapshotDto.setPeriodMode(index, period.getMode());
- snapshotDto.setPeriodParam(index, period.getModeParameter());
- snapshotDto.setPeriodDate(index, period.getSnapshotDate());
- }
- }
-
private static String getFileQualifier(Component component) {
return component.getFileAttributes().isUnitTest() ? Qualifiers.UNIT_TEST_FILE : Qualifiers.FILE;
}
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
+import static java.util.Collections.singletonList;
@ServerSide
public class MeasureFilterFactory {
return null;
}
- private List<String> toList(@Nullable Object obj) {
+ private static List<String> toList(@Nullable Object obj) {
List<String> result = null;
if (obj != null) {
if (obj instanceof String) {
- result = Arrays.asList((String) obj);
+ result = singletonList((String) obj);
} else {
result = (List<String>) obj;
}
}
@CheckForNull
- private Date toDate(@Nullable String date) {
+ private static Date toDate(@Nullable String date) {
if (date != null) {
return DateUtils.parseDate(date);
}
* As the anyone group does not exists in db, it's not returned when it has not the permission.
* We have to manually add it at the begin of the list, if it matched the search text
*/
- private void addAnyoneGroup(List<GroupWithPermissionDto> groups, PermissionQuery query) {
+ private static void addAnyoneGroup(List<GroupWithPermissionDto> groups, PermissionQuery query) {
boolean hasAnyoneGroup = Iterables.any(groups, IsAnyoneGroup.INSTANCE);
if (!hasAnyoneGroup
&& !GlobalPermissions.SYSTEM_ADMIN.equals(query.permission())
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.sonar.api.server.ServerSide;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.DbClient;
import static com.google.common.collect.Lists.newArrayList;
}
}
- private List<QProfile> toQProfiles(List<QualityProfileDto> dtos) {
+ private static List<QProfile> toQProfiles(List<QualityProfileDto> dtos) {
return newArrayList(Iterables.transform(dtos, ToQProfile.INSTANCE));
}
checkNotNull(outputMetrics);
return outputMetrics;
}
- }
- private static void checkNotNull(String[] metrics) {
- for (String metric : metrics) {
- requireNonNull(metric, "Null metric is not allowed");
+ private static void checkNotNull(String[] metrics) {
+ for (String metric : metrics) {
+ requireNonNull(metric, "Null metric is not allowed");
+ }
}
}