_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14500 | BusItinerary.removeBusHalt | train | public boolean removeBusHalt(BusItineraryHalt bushalt) {
try {
int index = ListUtil.indexOf(this.validHalts, VALID_HALT_COMPARATOR, bushalt);
if (index >= 0) {
return removeBusHalt(index);
}
index = ListUtil.indexOf(this.invalidHalts, INVALID_HALT_COMPARATOR, bushalt);
if (index >= 0) {
index += this.validHalts.size();
return removeBusHalt(index);
}
} catch (Throwable exception) {
//
}
return false;
} | java | {
"resource": ""
} |
q14501 | BusItinerary.removeBusHalt | train | public boolean removeBusHalt(String name) {
Iterator<BusItineraryHalt> iterator = this.validHalts.iterator();
BusItineraryHalt bushalt;
int i = 0;
while (iterator.hasNext()) {
bushalt = iterator.next();
if (name.equals(bushalt.getName())) {
return removeBusHalt(i);
}
++i;
}
iterator = this.invalidHalts.iterator();
i = 0;
while (iterator.hasNext()) {
bushalt = iterator.next();
if (name.equals(bushalt.getName())) {
return removeBusHalt(i);
}
++i;
}
return false;
} | java | {
"resource": ""
} |
q14502 | BusItinerary.removeBusHalt | train | public boolean removeBusHalt(int index) {
try {
final BusItineraryHalt removedBushalt;
if (index < this.validHalts.size()) {
removedBushalt = this.validHalts.remove(index);
} else {
final int idx = index - this.validHalts.size();
removedBushalt = this.invalidHalts.remove(idx);
}
removedBushalt.setContainer(null);
removedBushalt.setRoadSegmentIndex(-1);
removedBushalt.setPositionOnSegment(Float.NaN);
removedBushalt.setEventFirable(true);
removedBushalt.checkPrimitiveValidity();
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ITINERARY_HALT_REMOVED,
removedBushalt,
removedBushalt.indexInParent(),
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
return true;
} catch (Throwable exception) {
//
}
return false;
} | java | {
"resource": ""
} |
q14503 | BusItinerary.indexOf | train | @Pure
public int indexOf(BusItineraryHalt bushalt) {
if (bushalt == null) {
return -1;
}
if (bushalt.isValidPrimitive()) {
return ListUtil.indexOf(this.validHalts, VALID_HALT_COMPARATOR, bushalt);
}
int idx = ListUtil.indexOf(this.invalidHalts, INVALID_HALT_COMPARATOR, bushalt);
if (idx >= 0) {
idx += this.validHalts.size();
}
return idx;
} | java | {
"resource": ""
} |
q14504 | BusItinerary.contains | train | @Pure
public boolean contains(BusItineraryHalt bushalt) {
if (bushalt == null) {
return false;
}
if (bushalt.isValidPrimitive()) {
return ListUtil.contains(this.validHalts, VALID_HALT_COMPARATOR, bushalt);
}
return ListUtil.contains(this.invalidHalts, INVALID_HALT_COMPARATOR, bushalt);
} | java | {
"resource": ""
} |
q14505 | BusItinerary.getBusHaltAt | train | @Pure
public BusItineraryHalt getBusHaltAt(int index) {
if (index < this.validHalts.size()) {
return this.validHalts.get(index);
}
return this.invalidHalts.get(index - this.validHalts.size());
} | java | {
"resource": ""
} |
q14506 | BusItinerary.getBusHalt | train | @Pure
public BusItineraryHalt getBusHalt(UUID uuid) {
if (uuid == null) {
return null;
}
for (final BusItineraryHalt busHalt : this.validHalts) {
if (uuid.equals(busHalt.getUUID())) {
return busHalt;
}
}
for (final BusItineraryHalt busHalt : this.invalidHalts) {
if (uuid.equals(busHalt.getUUID())) {
return busHalt;
}
}
return null;
} | java | {
"resource": ""
} |
q14507 | BusItinerary.getBusHalt | train | @Pure
public BusItineraryHalt getBusHalt(String name, Comparator<String> nameComparator) {
if (name == null) {
return null;
}
final Comparator<String> cmp = nameComparator == null ? BusNetworkUtilities.NAME_COMPARATOR : nameComparator;
for (final BusItineraryHalt bushalt : this.validHalts) {
if (cmp.compare(name, bushalt.getName()) == 0) {
return bushalt;
}
}
for (final BusItineraryHalt bushalt : this.invalidHalts) {
if (cmp.compare(name, bushalt.getName()) == 0) {
return bushalt;
}
}
return null;
} | java | {
"resource": ""
} |
q14508 | BusItinerary.toBusHaltArray | train | @Pure
public BusItineraryHalt[] toBusHaltArray() {
final BusItineraryHalt[] tab = new BusItineraryHalt[this.validHalts.size() + this.invalidHalts.size()];
int i = 0;
for (final BusItineraryHalt h : this.validHalts) {
tab[i] = h;
++i;
}
for (final BusItineraryHalt h : this.invalidHalts) {
tab[i] = h;
++i;
}
return tab;
} | java | {
"resource": ""
} |
q14509 | BusItinerary.toInvalidBusHaltArray | train | @Pure
public BusItineraryHalt[] toInvalidBusHaltArray() {
final BusItineraryHalt[] tab = new BusItineraryHalt[this.invalidHalts.size()];
return this.invalidHalts.toArray(tab);
} | java | {
"resource": ""
} |
q14510 | BusItinerary.toValidBusHaltArray | train | @Pure
public BusItineraryHalt[] toValidBusHaltArray() {
final BusItineraryHalt[] tab = new BusItineraryHalt[this.validHalts.size()];
return this.validHalts.toArray(tab);
} | java | {
"resource": ""
} |
q14511 | BusItinerary.getNearestRoadSegment | train | @Pure
public RoadSegment getNearestRoadSegment(Point2D<?, ?> point) {
assert point != null;
double distance = Double.MAX_VALUE;
RoadSegment nearestSegment = null;
final Iterator<RoadSegment> iterator = this.roadSegments.roadSegments();
RoadSegment segment;
while (iterator.hasNext()) {
segment = iterator.next();
final double d = segment.distance(point);
if (d < distance) {
distance = d;
nearestSegment = segment;
}
}
return nearestSegment;
} | java | {
"resource": ""
} |
q14512 | BusItinerary.addRoadSegments | train | public boolean addRoadSegments(RoadPath segments, boolean autoConnectHalts, boolean enableLoopAutoBuild) {
if (segments == null || segments.isEmpty()) {
return false;
}
BusItineraryHalt halt;
RoadSegment sgmt;
final Map<BusItineraryHalt, RoadSegment> haltMapping = new TreeMap<>(
(obj1, obj2) -> Integer.compare(System.identityHashCode(obj1), System.identityHashCode(obj2)));
final Iterator<BusItineraryHalt> haltIterator = this.validHalts.iterator();
while (haltIterator.hasNext()) {
halt = haltIterator.next();
sgmt = this.roadSegments.getRoadSegmentAt(halt.getRoadSegmentIndex());
haltMapping.put(halt, sgmt);
}
final boolean isValidBefore = isValidPrimitive();
final RoadPath changedPath = this.roadSegments.addAndGetPath(segments);
if (changedPath != null) {
if (enableLoopAutoBuild) {
autoLoop(isValidBefore, changedPath, segments);
}
int nIdx;
for (final Entry<BusItineraryHalt, RoadSegment> entry : haltMapping.entrySet()) {
halt = entry.getKey();
sgmt = entry.getValue();
nIdx = this.roadSegments.indexOf(sgmt);
halt.setRoadSegmentIndex(nIdx);
halt.checkPrimitiveValidity();
}
final BusItineraryHalt[] tabV = new BusItineraryHalt[this.validHalts.size()];
this.validHalts.toArray(tabV);
this.validHalts.clear();
for (final BusItineraryHalt busHalt : tabV) {
assert busHalt != null && busHalt.isValidPrimitive();
ListUtil.addIfAbsent(this.validHalts, VALID_HALT_COMPARATOR, busHalt);
}
if (this.roadNetwork == null) {
final RoadNetwork network = segments.getFirstSegment().getRoadNetwork();
this.roadNetwork = new WeakReference<>(network);
network.addRoadNetworkListener(this);
}
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.SEGMENT_ADDED,
segments.getLastSegment(),
this.roadSegments.indexOf(segments.getLastSegment()),
"shape", //$NON-NLS-1$
null,
null));
// Try to connect the itinerary halts to
// the road segments
if (autoConnectHalts) {
putInvalidHaltsOnRoads();
} else {
checkPrimitiveValidity();
}
return true;
}
return false;
} | java | {
"resource": ""
} |
q14513 | BusItinerary.putHaltOnRoad | train | @SuppressWarnings("checkstyle:nestedifdepth")
public boolean putHaltOnRoad(BusItineraryHalt halt, RoadSegment road) {
if (contains(halt)) {
final BusStop stop = halt.getBusStop();
if (stop != null) {
final Point2d stopPosition = stop.getPosition2D();
if (stopPosition != null) {
final int idx = indexOf(road);
if (idx >= 0) {
final Point1d pos = road.getNearestPosition(stopPosition);
if (pos != null) {
halt.setRoadSegmentIndex(idx);
halt.setPositionOnSegment(pos.getCurvilineCoordinate());
halt.checkPrimitiveValidity();
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ITINERARY_CHANGED,
null,
-1,
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
return true;
}
}
return false;
}
}
}
return true;
} | java | {
"resource": ""
} |
q14514 | BusItinerary.removeAllRoadSegments | train | public void removeAllRoadSegments() {
for (final BusItineraryHalt halt : this.invalidHalts) {
halt.setRoadSegmentIndex(-1);
halt.setPositionOnSegment(Float.NaN);
halt.checkPrimitiveValidity();
}
final BusItineraryHalt[] halts = new BusItineraryHalt[this.validHalts.size()];
this.validHalts.toArray(halts);
for (final BusItineraryHalt halt : halts) {
halt.setRoadSegmentIndex(-1);
halt.setPositionOnSegment(Float.NaN);
halt.checkPrimitiveValidity();
}
if (this.roadNetwork != null) {
final RoadNetwork network = this.roadNetwork.get();
if (network != null) {
network.removeRoadNetworkListener(this);
}
this.roadNetwork = null;
}
this.roadSegments.clear();
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.ALL_SEGMENTS_REMOVED,
null,
-1,
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
} | java | {
"resource": ""
} |
q14515 | BusItinerary.removeRoadSegment | train | public boolean removeRoadSegment(int segmentIndex) {
if (segmentIndex >= 0 && segmentIndex < this.roadSegments.getRoadSegmentCount()) {
final RoadSegment segment = this.roadSegments.getRoadSegmentAt(segmentIndex);
if (segment != null) {
//
// Invalidate the bus halts on the segment
//
final Map<BusItineraryHalt, RoadSegment> segmentMap = new TreeMap<>(
(obj1, obj2) -> Integer.compare(System.identityHashCode(obj1), System.identityHashCode(obj2)));
final Iterator<BusItineraryHalt> haltIterator = this.validHalts.iterator();
while (haltIterator.hasNext()) {
final BusItineraryHalt halt = haltIterator.next();
final int sgmtIndex = halt.getRoadSegmentIndex();
if (sgmtIndex == segmentIndex) {
segmentMap.put(halt, null);
} else {
final RoadSegment sgmt = this.roadSegments.getRoadSegmentAt(sgmtIndex);
segmentMap.put(halt, sgmt);
}
}
//
// Remove the road segment itself on the segment
//
this.roadSegments.removeRoadSegmentAt(segmentIndex);
//
// Force the road segment indexes
//
for (final Entry<BusItineraryHalt, RoadSegment> entry : segmentMap.entrySet()) {
final BusItineraryHalt halt = entry.getKey();
final RoadSegment sgmt = entry.getValue();
if (sgmt == null) {
halt.setRoadSegmentIndex(-1);
halt.setPositionOnSegment(Float.NaN);
halt.checkPrimitiveValidity();
} else {
final int sgmtIndex = halt.getRoadSegmentIndex();
final int idx = this.roadSegments.indexOf(sgmt);
if (idx != sgmtIndex) {
halt.setRoadSegmentIndex(idx);
halt.checkPrimitiveValidity();
}
}
}
//
// Change the road network reference
//
if (this.roadSegments.isEmpty() && this.roadNetwork != null) {
final RoadNetwork network = this.roadNetwork.get();
if (network != null) {
network.removeRoadNetworkListener(this);
}
this.roadNetwork = null;
}
fireShapeChanged(new BusChangeEvent(this,
BusChangeEventType.SEGMENT_REMOVED,
segment,
segmentIndex,
"shape", //$NON-NLS-1$
null,
null));
checkPrimitiveValidity();
return true;
}
}
return false;
} | java | {
"resource": ""
} |
q14516 | BusItinerary.roadSegments | train | @Pure
public Iterable<RoadSegment> roadSegments() {
return new Iterable<RoadSegment>() {
@Override
public Iterator<RoadSegment> iterator() {
return roadSegmentsIterator();
}
};
} | java | {
"resource": ""
} |
q14517 | EquivalenceBasedProvenancedAligner.forEquivalenceFunction | train | @SuppressWarnings("unchecked")
/**
* Creates an aligner given a single function from items to equivalence classes (requires left
* and right items to both be of types compatible with this function).
*/
public static <InT, EqClass> EquivalenceBasedProvenancedAligner<InT, InT, EqClass> forEquivalenceFunction(
Function<? super InT, ? extends EqClass> equivalenceFunction) {
return new EquivalenceBasedProvenancedAligner<InT, InT, EqClass>(
(Function<InT, EqClass>) equivalenceFunction,
(Function<InT, EqClass>) equivalenceFunction);
} | java | {
"resource": ""
} |
q14518 | VMCommandLine.getExecutableFilename | train | @Pure
public static String getExecutableFilename(String name) {
if (OperatingSystem.WIN.isCurrentOS()) {
return name + ".exe"; //$NON-NLS-1$
}
return name;
} | java | {
"resource": ""
} |
q14519 | VMCommandLine.getVMBinary | train | @Pure
public static String getVMBinary() {
final String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
final File binDir = new File(new File(javaHome), "bin"); //$NON-NLS-1$
if (binDir.isDirectory()) {
File exec = new File(binDir, getExecutableFilename("javaw")); //$NON-NLS-1$
if (exec.isFile()) {
return exec.getAbsolutePath();
}
exec = new File(binDir, getExecutableFilename("java")); //$NON-NLS-1$
if (exec.isFile()) {
return exec.getAbsolutePath();
}
}
return null;
} | java | {
"resource": ""
} |
q14520 | VMCommandLine.launchVMWithJar | train | @SuppressWarnings("checkstyle:magicnumber")
public static Process launchVMWithJar(File jarFile, String... additionalParams) throws IOException {
final String javaBin = getVMBinary();
if (javaBin == null) {
throw new FileNotFoundException("java"); //$NON-NLS-1$
}
final long totalMemory = Runtime.getRuntime().maxMemory() / 1024;
final String userDir = FileSystem.getUserHomeDirectoryName();
final int nParams = 4;
final String[] params = new String[additionalParams.length + nParams];
params[0] = javaBin;
params[1] = "-Xmx" + totalMemory + "k"; //$NON-NLS-1$ //$NON-NLS-2$
params[2] = "-jar"; //$NON-NLS-1$
params[3] = jarFile.getAbsolutePath();
System.arraycopy(additionalParams, 0, params, nParams, additionalParams.length);
return Runtime.getRuntime().exec(params, null, new File(userDir));
} | java | {
"resource": ""
} |
q14521 | VMCommandLine.getAllCommandLineParameters | train | @Pure
@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
public static String[] getAllCommandLineParameters() {
final int osize = commandLineOptions == null ? 0 : commandLineOptions.size();
final int psize = commandLineParameters == null ? 0 : commandLineParameters.length;
final int tsize = (osize > 0 && psize > 0) ? 1 : 0;
final List<String> params = new ArrayList<>(osize + tsize);
if (osize > 0) {
List<Object> values;
String name;
String prefix;
String v;
for (final Entry<String, List<Object>> entry : commandLineOptions.entrySet()) {
name = entry.getKey();
prefix = (name.length() > 1) ? "--" : "-"; //$NON-NLS-1$ //$NON-NLS-2$
values = entry.getValue();
if (values == null || values.isEmpty()) {
params.add(prefix + name);
} else {
for (final Object value : values) {
if (value != null) {
v = value.toString();
if (v != null && v.length() > 0) {
params.add(prefix + name + "=" + v); //$NON-NLS-1$
} else {
params.add(prefix + name);
}
}
}
}
}
}
if (tsize > 0) {
params.add("--"); //$NON-NLS-1$
}
final String[] tab = new String[params.size() + psize];
params.toArray(tab);
params.clear();
if (psize > 0) {
System.arraycopy(commandLineParameters, 0, tab, osize + tsize, psize);
}
return tab;
} | java | {
"resource": ""
} |
q14522 | VMCommandLine.shiftCommandLineParameters | train | public static String shiftCommandLineParameters() {
String removed = null;
if (commandLineParameters != null) {
if (commandLineParameters.length == 0) {
commandLineParameters = null;
} else if (commandLineParameters.length == 1) {
removed = commandLineParameters[0];
commandLineParameters = null;
} else {
removed = commandLineParameters[0];
final String[] newTab = new String[commandLineParameters.length - 1];
System.arraycopy(commandLineParameters, 1, newTab, 0, commandLineParameters.length - 1);
commandLineParameters = newTab;
}
}
return removed;
} | java | {
"resource": ""
} |
q14523 | VMCommandLine.getCommandLineOptions | train | @Pure
public static Map<String, List<Object>> getCommandLineOptions() {
if (commandLineOptions != null) {
return Collections.unmodifiableSortedMap(commandLineOptions);
}
return Collections.emptyMap();
} | java | {
"resource": ""
} |
q14524 | VMCommandLine.getCommandLineOption | train | @Pure
public static List<Object> getCommandLineOption(String name) {
if (commandLineOptions != null && commandLineOptions.containsKey(name)) {
final List<Object> value = commandLineOptions.get(name);
return value == null ? Collections.emptyList() : value;
}
return Collections.emptyList();
} | java | {
"resource": ""
} |
q14525 | VMCommandLine.getFirstOptionValue | train | @Pure
@SuppressWarnings("static-method")
public Object getFirstOptionValue(String optionLabel) {
final List<Object> options = getCommandLineOption(optionLabel);
if (options == null || options.isEmpty()) {
return null;
}
return options.get(0);
} | java | {
"resource": ""
} |
q14526 | VMCommandLine.getOptionValues | train | @Pure
@SuppressWarnings("static-method")
public List<Object> getOptionValues(String optionLabel) {
final List<Object> options = getCommandLineOption(optionLabel);
if (options == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(options);
} | java | {
"resource": ""
} |
q14527 | VMCommandLine.isParameterExists | train | @Pure
@SuppressWarnings("static-method")
public boolean isParameterExists(int index) {
final String[] params = getCommandLineParameters();
return index >= 0 && index < params.length && params[index] != null;
} | java | {
"resource": ""
} |
q14528 | MapComposedElement.firstInGroup | train | private int firstInGroup(int groupIndex) {
if (this.pointCoordinates == null) {
throw new IndexOutOfBoundsException();
}
final int count = getGroupCount();
if (groupIndex < 0) {
throw new IndexOutOfBoundsException(groupIndex + "<0"); //$NON-NLS-1$
}
if (groupIndex >= count) {
throw new IndexOutOfBoundsException(groupIndex + ">=" + count); //$NON-NLS-1$
}
final int g = groupIndex - 1;
if (g >= 0 && this.partIndexes != null && g < this.partIndexes.length) {
return this.partIndexes[g];
}
return 0;
} | java | {
"resource": ""
} |
q14529 | MapComposedElement.lastInGroup | train | private int lastInGroup(int groupIndex) {
if (this.pointCoordinates == null) {
throw new IndexOutOfBoundsException();
}
final int count = getGroupCount();
if (groupIndex < 0) {
throw new IndexOutOfBoundsException(groupIndex + "<0"); //$NON-NLS-1$
}
if (groupIndex >= count) {
throw new IndexOutOfBoundsException(groupIndex + ">=" + count); //$NON-NLS-1$
}
if (this.partIndexes != null && groupIndex < this.partIndexes.length) {
return this.partIndexes[groupIndex] - 2;
}
return this.pointCoordinates.length - 2;
} | java | {
"resource": ""
} |
q14530 | MapComposedElement.groupIndexForPoint | train | private int groupIndexForPoint(int pointIndex) {
if (this.pointCoordinates == null || pointIndex < 0 || pointIndex >= this.pointCoordinates.length) {
throw new IndexOutOfBoundsException();
}
if (this.partIndexes == null) {
return 0;
}
for (int i = 0; i < this.partIndexes.length; ++i) {
if (pointIndex < this.partIndexes[i]) {
return i;
}
}
return this.partIndexes.length;
} | java | {
"resource": ""
} |
q14531 | MapComposedElement.getPointCountInGroup | train | @Pure
public int getPointCountInGroup(int groupIndex) {
if (groupIndex == 0 && this.pointCoordinates == null) {
return 0;
}
final int firstInGroup = firstInGroup(groupIndex);
final int lastInGroup = lastInGroup(groupIndex);
return (lastInGroup - firstInGroup) / 2 + 1;
} | java | {
"resource": ""
} |
q14532 | MapComposedElement.getPointIndex | train | @Pure
public int getPointIndex(int groupIndex, int position) {
final int groupMemberCount = getPointCountInGroup(groupIndex);
final int pos;
if (position < 0) {
pos = 0;
} else if (position >= groupMemberCount) {
pos = groupMemberCount - 1;
} else {
pos = position;
}
// Move the start/end indexes to corresponds to the bounds of the new points
return (firstInGroup(groupIndex) + pos * 2) / 2;
} | java | {
"resource": ""
} |
q14533 | MapComposedElement.getPointIndex | train | @Pure
public int getPointIndex(int groupIndex, Point2D<?, ?> point2d) {
if (!this.containsPoint(point2d, groupIndex)) {
return -1;
}
Point2d cur = null;
int pos = -1;
for (int i = 0; i < getPointCountInGroup(groupIndex); ++i) {
cur = getPointAt(groupIndex, i);
if (cur.epsilonEquals(point2d, MapElementConstants.POINT_FUSION_DISTANCE)) {
pos = i;
break;
}
}
return (firstInGroup(groupIndex) + pos * 2) / 2;
} | java | {
"resource": ""
} |
q14534 | MapComposedElement.getGroupAt | train | @Pure
public PointGroup getGroupAt(int index) {
final int count = getGroupCount();
if (index < 0) {
throw new IndexOutOfBoundsException(index + "<0"); //$NON-NLS-1$
}
if (index >= count) {
throw new IndexOutOfBoundsException(index + ">=" + count); //$NON-NLS-1$
}
return new PointGroup(index);
} | java | {
"resource": ""
} |
q14535 | MapComposedElement.groups | train | @Pure
public Iterable<PointGroup> groups() {
return new Iterable<PointGroup>() {
@Override
public Iterator<PointGroup> iterator() {
return MapComposedElement.this.groupIterator();
}
};
} | java | {
"resource": ""
} |
q14536 | MapComposedElement.points | train | @Pure
public Iterable<Point2d> points() {
return new Iterable<Point2d>() {
@Override
public Iterator<Point2d> iterator() {
return MapComposedElement.this.pointIterator();
}
};
} | java | {
"resource": ""
} |
q14537 | MapComposedElement.addPoint | train | public int addPoint(double x, double y) {
int pointIndex;
if (this.pointCoordinates == null) {
this.pointCoordinates = new double[] {x, y};
this.partIndexes = null;
pointIndex = 0;
} else {
double[] pts = new double[this.pointCoordinates.length + 2];
System.arraycopy(this.pointCoordinates, 0, pts, 0, this.pointCoordinates.length);
pointIndex = pts.length - 2;
pts[pointIndex] = x;
pts[pointIndex + 1] = y;
this.pointCoordinates = pts;
pts = null;
pointIndex /= 2;
}
fireShapeChanged();
fireElementChanged();
return pointIndex;
} | java | {
"resource": ""
} |
q14538 | MapComposedElement.addGroup | train | public int addGroup(double x, double y) {
int pointIndex;
if (this.pointCoordinates == null) {
this.pointCoordinates = new double[] {x, y};
this.partIndexes = null;
pointIndex = 0;
} else {
double[] pts = new double[this.pointCoordinates.length + 2];
System.arraycopy(this.pointCoordinates, 0, pts, 0, this.pointCoordinates.length);
pointIndex = pts.length - 2;
pts[pointIndex] = x;
pts[pointIndex + 1] = y;
final int groupCount = getGroupCount();
int[] grps = new int[groupCount];
if (this.partIndexes != null) {
System.arraycopy(this.partIndexes, 0, grps, 0, groupCount - 1);
}
grps[groupCount - 1] = pointIndex;
this.pointCoordinates = pts;
pts = null;
this.partIndexes = grps;
grps = null;
pointIndex /= 2;
}
fireShapeChanged();
fireElementChanged();
return pointIndex;
} | java | {
"resource": ""
} |
q14539 | MapComposedElement.invertPointsIn | train | public MapComposedElement invertPointsIn(int groupIndex) {
if (this.pointCoordinates == null) {
throw new IndexOutOfBoundsException();
}
final int grpCount = getGroupCount();
if (groupIndex < 0) {
throw new IndexOutOfBoundsException(groupIndex + "<0"); //$NON-NLS-1$
}
if (groupIndex > grpCount) {
throw new IndexOutOfBoundsException(groupIndex + ">" + grpCount); //$NON-NLS-1$
}
final int count = this.getPointCountInGroup(groupIndex);
final int first = firstInGroup(groupIndex);
double[] tmp = new double[count * 2];
for (int i = 0; i < count * 2; i += 2) {
tmp[i] = this.pointCoordinates[first + 2 * count - 1 - (i + 1)];
tmp[i + 1] = this.pointCoordinates[first + 2 * count - 1 - i];
}
System.arraycopy(tmp, 0, this.pointCoordinates, first, tmp.length);
tmp = null;
return this;
} | java | {
"resource": ""
} |
q14540 | MapComposedElement.invert | train | public MapComposedElement invert() {
if (this.pointCoordinates == null) {
throw new IndexOutOfBoundsException();
}
double[] tmp = new double[this.pointCoordinates.length];
for (int i = 0; i < this.pointCoordinates.length; i += 2) {
tmp[i] = this.pointCoordinates[this.pointCoordinates.length - 1 - (i + 1)];
tmp[i + 1] = this.pointCoordinates[this.pointCoordinates.length - 1 - i];
}
System.arraycopy(tmp, 0, this.pointCoordinates, 0, this.pointCoordinates.length);
if (this.partIndexes != null) {
int[] tmpint = new int[this.partIndexes.length];
//part 0 not inside the index array
for (int i = 0; i < this.partIndexes.length; ++i) {
tmpint[this.partIndexes.length - 1 - i] = this.pointCoordinates.length - this.partIndexes[i];
}
System.arraycopy(tmpint, 0, this.partIndexes, 0, this.partIndexes.length);
tmpint = null;
}
tmp = null;
return this;
} | java | {
"resource": ""
} |
q14541 | MapComposedElement.getPointAt | train | @Pure
public Point2d getPointAt(int index) {
final int count = getPointCount();
int idx = index;
if (idx < 0) {
idx = count + idx;
}
if (idx < 0) {
throw new IndexOutOfBoundsException(idx + "<0"); //$NON-NLS-1$
}
if (idx >= count) {
throw new IndexOutOfBoundsException(idx + ">=" + count); //$NON-NLS-1$
}
return new Point2d(
this.pointCoordinates[idx * 2],
this.pointCoordinates[idx * 2 + 1]);
} | java | {
"resource": ""
} |
q14542 | MapComposedElement.getPointAt | train | @Pure
public Point2d getPointAt(int groupIndex, int indexInGroup) {
final int startIndex = firstInGroup(groupIndex);
// Besure that the member's index is in the group index's range
final int groupMemberCount = getPointCountInGroup(groupIndex);
if (indexInGroup < 0) {
throw new IndexOutOfBoundsException(indexInGroup + "<0"); //$NON-NLS-1$
}
if (indexInGroup >= groupMemberCount) {
throw new IndexOutOfBoundsException(indexInGroup + ">=" + groupMemberCount); //$NON-NLS-1$
}
return new Point2d(
this.pointCoordinates[startIndex + indexInGroup * 2],
this.pointCoordinates[startIndex + indexInGroup * 2 + 1]);
} | java | {
"resource": ""
} |
q14543 | MapComposedElement.removeGroupAt | train | public boolean removeGroupAt(int groupIndex) {
try {
final int startIndex = firstInGroup(groupIndex);
final int lastIndex = lastInGroup(groupIndex);
final int ptsToRemoveCount = (lastIndex - startIndex + 2) / 2;
int rest = this.pointCoordinates.length / 2 - ptsToRemoveCount;
if (rest > 0) {
// Remove the points
rest *= 2;
final double[] newPts = new double[rest];
System.arraycopy(this.pointCoordinates, 0, newPts, 0, startIndex);
System.arraycopy(
this.pointCoordinates, lastIndex + 2,
newPts, startIndex,
rest - startIndex);
this.pointCoordinates = newPts;
// Remove the group
if (this.partIndexes != null) {
// Shift the group's indexes
for (int i = groupIndex; i < this.partIndexes.length; ++i) {
this.partIndexes[i] -= ptsToRemoveCount * 2;
}
// Removing the group
int[] newGroups = null;
if (this.partIndexes.length > 1) {
newGroups = new int[this.partIndexes.length - 1];
if (groupIndex == 0) {
System.arraycopy(this.partIndexes, 1, newGroups, 0, this.partIndexes.length - 1);
} else {
System.arraycopy(this.partIndexes, 0, newGroups, 0, groupIndex - 1);
System.arraycopy(
this.partIndexes, groupIndex,
newGroups, groupIndex - 1,
this.partIndexes.length - groupIndex);
}
}
this.partIndexes = newGroups;
}
} else {
// Remove all the points
this.pointCoordinates = null;
this.partIndexes = null;
}
fireShapeChanged();
fireElementChanged();
return true;
} catch (IndexOutOfBoundsException exception) {
//
}
return false;
} | java | {
"resource": ""
} |
q14544 | MapComposedElement.removePointAt | train | public Point2d removePointAt(int groupIndex, int indexInGroup) {
final int startIndex = firstInGroup(groupIndex);
final int lastIndex = lastInGroup(groupIndex);
// Translate local point's coordinate into global point's coordinate
final int g = indexInGroup * 2 + startIndex;
// Be sure that the member's index is in the group index's range
if (g < startIndex) {
throw new IndexOutOfBoundsException(g + "<" + startIndex); //$NON-NLS-1$
}
if (g > lastIndex) {
throw new IndexOutOfBoundsException(g + ">" + lastIndex); //$NON-NLS-1$
}
final Point2d p = new Point2d(
this.pointCoordinates[g],
this.pointCoordinates[g + 1]);
// Deleting the point
final double[] newPtsArray;
if (this.pointCoordinates.length <= 2) {
newPtsArray = null;
} else {
newPtsArray = new double[this.pointCoordinates.length - 2];
System.arraycopy(this.pointCoordinates, 0, newPtsArray, 0, g);
System.arraycopy(
this.pointCoordinates, g + 2,
newPtsArray, g, this.pointCoordinates.length - g - 2);
}
this.pointCoordinates = newPtsArray;
if (this.partIndexes != null) {
// Shift the group's indexes
for (int i = groupIndex; i < this.partIndexes.length; ++i) {
this.partIndexes[i] -= 2;
}
// Removing the group
final int ptsCount = (lastIndex - startIndex) / 2;
if (ptsCount <= 0) {
int[] newGroups = null;
if (this.partIndexes.length > 1) {
newGroups = new int[this.partIndexes.length - 1];
if (groupIndex == 0) {
System.arraycopy(this.partIndexes, 1, newGroups, 0, this.partIndexes.length - 1);
} else {
System.arraycopy(this.partIndexes, 0, newGroups, 0, groupIndex - 1);
System.arraycopy(
this.partIndexes, groupIndex,
newGroups, groupIndex - 1,
this.partIndexes.length - groupIndex);
}
}
this.partIndexes = newGroups;
}
}
fireShapeChanged();
fireElementChanged();
return p;
} | java | {
"resource": ""
} |
q14545 | MapComposedElement.canonize | train | private boolean canonize(int index) {
final int count = getPointCount();
int ix = index;
if (ix < 0) {
ix = count + ix;
}
if (ix < 0) {
throw new IndexOutOfBoundsException(ix + "<0"); //$NON-NLS-1$
}
if (ix >= count) {
throw new IndexOutOfBoundsException(ix + ">=" + count); //$NON-NLS-1$
}
final int partIndex = groupIndexForPoint(ix);
final int firstPts = firstInGroup(partIndex);
final int endPts = lastInGroup(partIndex);
final int myIndex = ix * 2;
int firstToRemove = myIndex;
int lastToRemove = myIndex;
boolean removeOne = false;
final double xbase = this.pointCoordinates[ix * 2];
final double ybase = this.pointCoordinates[ix * 2 + 1];
final PointFusionValidator validator = getPointFusionValidator();
// Search for the first point to remove
for (int idx = myIndex - 2; idx >= firstPts; idx -= 2) {
final double x = this.pointCoordinates[idx];
final double y = this.pointCoordinates[idx + 1];
if (validator.isSame(xbase, ybase, x, y)) {
firstToRemove = idx;
removeOne = true;
} else {
// Stop search
break;
}
}
// Search for the last point to remove
for (int idx = myIndex + 2; idx <= endPts; idx += 2) {
final double x = this.pointCoordinates[idx];
final double y = this.pointCoordinates[idx + 1];
if (validator.isSame(xbase, ybase, x, y)) {
lastToRemove = idx;
removeOne = true;
} else {
// Stop search
break;
}
}
if (removeOne) {
// A set of points are detected as too near.
// They should be removed and replaced by the reference point
final int removalCount = (lastToRemove / 2 - firstToRemove / 2) * 2;
// Deleting the point
final double[] newPtsArray = new double[this.pointCoordinates.length - removalCount];
assert newPtsArray.length >= 2;
System.arraycopy(this.pointCoordinates, 0, newPtsArray, 0, firstToRemove);
System.arraycopy(this.pointCoordinates, lastToRemove + 2, newPtsArray,
firstToRemove + 2, this.pointCoordinates.length - lastToRemove - 2);
newPtsArray[firstToRemove] = xbase;
newPtsArray[firstToRemove + 1] = ybase;
this.pointCoordinates = newPtsArray;
if (this.partIndexes != null) {
// Shift the group's indexes
for (int i = partIndex; i < this.partIndexes.length; ++i) {
this.partIndexes[i] -= removalCount;
}
}
return true;
}
return false;
} | java | {
"resource": ""
} |
q14546 | IncludeAllPaginator.addOutputInformation | train | private Optional<IncludeAllPageWithOutput> addOutputInformation(IncludeAllPage pages, FileResource baseResource, Path includeAllBasePath, Locale locale) {
// depth = 0 is the file that has the include-all directive
if (pages.depth == 0) {
return of(new IncludeAllPageWithOutput(pages, pages.files.get(0), pages.files.get(0).getPath(), locale));
}
Path baseResourceParentPath = baseResource.getPath().getParent();
Optional<FileResource> virtualResource = pages.files.stream().findFirst()
.map(fr -> new VirtualPathFileResource(baseResourceParentPath.resolve(includeAllBasePath.relativize(fr.getPath()).toString()), fr));
return virtualResource.map(vr -> {
Path finalOutputPath = outputPathExtractor.apply(vr).normalize();
return new IncludeAllPageWithOutput(pages, vr, finalOutputPath, locale);
});
} | java | {
"resource": ""
} |
q14547 | SelectorManager.getReactorByIndex | train | public Reactor getReactorByIndex(int index) {
if (index < 0 || index > reactorSet.length - 1) {
throw new ArrayIndexOutOfBoundsException();
}
return reactorSet[index];
} | java | {
"resource": ""
} |
q14548 | PainterExtensions.getCompoundPainter | train | @SuppressWarnings("rawtypes")
public static CompoundPainter getCompoundPainter(final Color matte, final Color gloss,
final GlossPainter.GlossPosition position, final double angle, final Color pinstripe)
{
final MattePainter mp = new MattePainter(matte);
final GlossPainter gp = new GlossPainter(gloss, position);
final PinstripePainter pp = new PinstripePainter(pinstripe, angle);
final CompoundPainter compoundPainter = new CompoundPainter(mp, pp, gp);
return compoundPainter;
} | java | {
"resource": ""
} |
q14549 | PainterExtensions.getCompoundPainter | train | @SuppressWarnings("rawtypes")
public static CompoundPainter getCompoundPainter(final Color color,
final GlossPainter.GlossPosition position, final double angle)
{
final MattePainter mp = new MattePainter(color);
final GlossPainter gp = new GlossPainter(color, position);
final PinstripePainter pp = new PinstripePainter(color, angle);
final CompoundPainter compoundPainter = new CompoundPainter(mp, pp, gp);
return compoundPainter;
} | java | {
"resource": ""
} |
q14550 | PainterExtensions.getMattePainter | train | public static MattePainter getMattePainter(final int width, final int height,
final float[] fractions, final Color... colors)
{
final LinearGradientPaint gradientPaint = new LinearGradientPaint(0.0f, 0.0f, width, height,
fractions, colors);
final MattePainter mattePainter = new MattePainter(gradientPaint);
return mattePainter;
} | java | {
"resource": ""
} |
q14551 | Sphere3f.set | train | @Override
public void set(Point3D center, double radius1) {
this.cx = center.getX();
this.cy = center.getY();
this.cz = center.getZ();
this.radius = Math.abs(radius1);
} | java | {
"resource": ""
} |
q14552 | MultiShape3dfx.elementsProperty | train | public ListProperty<T> elementsProperty() {
if (this.elements == null) {
this.elements = new SimpleListProperty<>(this,
MathFXAttributeNames.ELEMENTS, new InternalObservableList<>());
}
return this.elements;
} | java | {
"resource": ""
} |
q14553 | InformedArrayList.extractClassFrom | train | @SuppressWarnings("unchecked")
protected static <E> Class<? extends E> extractClassFrom(Collection<? extends E> collection) {
Class<? extends E> clazz = null;
for (final E elt : collection) {
clazz = (Class<? extends E>) ReflectionUtil.getCommonType(clazz, elt.getClass());
}
return clazz == null ? (Class<E>) Object.class : clazz;
} | java | {
"resource": ""
} |
q14554 | BaseDesktopMenu.getHelpSet | train | public HelpSet getHelpSet()
{
HelpSet hs = null;
final String filename = "simple-hs.xml";
final String path = "help/" + filename;
URL hsURL;
hsURL = ClassExtensions.getResource(path);
try
{
if(hsURL != null) {
hs = new HelpSet(ClassExtensions.getClassLoader(), hsURL);
} else {
hs = new HelpSet();
}
}
catch (final HelpSetException e)
{
String title = e.getLocalizedMessage();
String htmlMessage = "<html><body width='650'>" + "<h2>" + title + "</h2>" + "<p>"
+ e.getMessage() + "\n" + path ;
JOptionPane.showMessageDialog(this.getParent(), htmlMessage, title,
JOptionPane.ERROR_MESSAGE);
log.log(Level.SEVERE, e.getMessage(), e);
}
return hs;
} | java | {
"resource": ""
} |
q14555 | BaseDesktopMenu.newHelpMenu | train | protected JMenu newHelpMenu(final ActionListener listener)
{
// Help menu
final JMenu menuHelp = new JMenu(newLabelTextHelp());
menuHelp.setMnemonic('H');
// Help JMenuItems
// Help content
final JMenuItem mihHelpContent = JComponentFactory.newJMenuItem(newLabelTextContent(), 'c',
'H');
menuHelp.add(mihHelpContent);
// 2. assign help to components
CSH.setHelpIDString(mihHelpContent, newLabelTextOverview());
// 3. handle events
final CSH.DisplayHelpFromSource displayHelpFromSource = new CSH.DisplayHelpFromSource(
helpBroker);
mihHelpContent.addActionListener(displayHelpFromSource);
// Donate
final JMenuItem mihDonate = new JMenuItem(newLabelTextDonate());
mihDonate.addActionListener(
newOpenBrowserToDonateAction(newLabelTextDonate(), applicationFrame));
menuHelp.add(mihDonate);
// Licence
final JMenuItem mihLicence = new JMenuItem(newLabelTextLicence());
mihLicence.addActionListener(
newShowLicenseFrameAction(newLabelTextLicence() + "Action", newLabelTextLicence()));
menuHelp.add(mihLicence);
// Info
final JMenuItem mihInfo = new JMenuItem(newLabelTextInfo(), 'i'); // $NON-NLS-1$
MenuExtensions.setCtrlAccelerator(mihInfo, 'I');
mihInfo.addActionListener(newShowInfoDialogAction(newLabelTextInfo(),
(Frame)applicationFrame, newLabelTextInfo()));
menuHelp.add(mihInfo);
return menuHelp;
} | java | {
"resource": ""
} |
q14556 | BaseDesktopMenu.newLookAndFeelMenu | train | protected JMenu newLookAndFeelMenu(final ActionListener listener)
{
final JMenu menuLookAndFeel = new JMenu("Look and Feel");
menuLookAndFeel.setMnemonic('L');
// Look and Feel JMenuItems
// GTK
JMenuItem jmiPlafGTK;
jmiPlafGTK = new JMenuItem("GTK", 'g'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafGTK, 'G');
jmiPlafGTK.addActionListener(new LookAndFeelGTKAction("GTK", this.applicationFrame));
menuLookAndFeel.add(jmiPlafGTK);
// Metal default Metal theme
JMenuItem jmiPlafMetal;
jmiPlafMetal = new JMenuItem("Metal", 'm'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafMetal, 'M');
jmiPlafMetal.addActionListener(new LookAndFeelMetalAction("Metal", this.applicationFrame));
menuLookAndFeel.add(jmiPlafMetal);
// Metal Ocean theme
JMenuItem jmiPlafOcean;
jmiPlafOcean = new JMenuItem("Ocean", 'o'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafOcean, 'O');
jmiPlafOcean.addActionListener(new LookAndFeelMetalAction("Ocean", this.applicationFrame));
menuLookAndFeel.add(jmiPlafOcean);
// Motif
JMenuItem jmiPlafMotiv;
jmiPlafMotiv = new JMenuItem("Motif", 't'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafMotiv, 'T');
jmiPlafMotiv.addActionListener(new LookAndFeelMotifAction("Motif", this.applicationFrame));
menuLookAndFeel.add(jmiPlafMotiv);
// Nimbus
JMenuItem jmiPlafNimbus;
jmiPlafNimbus = new JMenuItem("Nimbus", 'n'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafNimbus, 'N');
jmiPlafNimbus
.addActionListener(new LookAndFeelNimbusAction("Nimbus", this.applicationFrame));
menuLookAndFeel.add(jmiPlafNimbus);
// Windows
JMenuItem jmiPlafSystem;
jmiPlafSystem = new JMenuItem("System", 'd'); //$NON-NLS-1$
MenuExtensions.setCtrlAccelerator(jmiPlafSystem, 'W');
jmiPlafSystem
.addActionListener(new LookAndFeelSystemAction("System", this.applicationFrame));
menuLookAndFeel.add(jmiPlafSystem);
return menuLookAndFeel;
} | java | {
"resource": ""
} |
q14557 | NYTCorpusDocumentParser.parseNYTCorpusDocumentFromFile | train | public NYTCorpusDocument parseNYTCorpusDocumentFromFile(File file,
boolean validating) {
Document document = null;
if (validating) {
document = loadValidating(file);
} else {
document = loadNonValidating(file);
}
return parseNYTCorpusDocumentFromDOMDocument(file, document);
} | java | {
"resource": ""
} |
q14558 | NYTCorpusDocumentParser.loadNonValidating | train | private Document loadNonValidating(InputStream is) {
Document document;
StringBuffer sb = new StringBuffer();
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(is, "UTF8"));
String line = null;
while ((line = in.readLine()) != null) {
sb.append(line + "\n");
}
String xmlData = sb.toString();
xmlData = xmlData.replace("<!DOCTYPE nitf " + "SYSTEM \"http://www.nitf.org/" + "IPTC/NITF/3.3/specification/dtd/nitf-3-3.dtd\">", "");
document = parseStringToDOM(xmlData, "UTF-8");
return document;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("Error loading inputstream.");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Error loading file inputstream.");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Error loading file inputstream.");
} finally {
if (in != null)
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
} | java | {
"resource": ""
} |
q14559 | NYTCorpusDocumentParser.parseStringToDOM | train | private Document parseStringToDOM(String s, String encoding) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
InputStream is = new ByteArrayInputStream(s.getBytes(encoding));
Document doc = factory.newDocumentBuilder().parse(is);
return doc;
} catch (SAXException e) {
e.printStackTrace();
System.out.println("Exception processing string.");
} catch (ParserConfigurationException e) {
e.printStackTrace();
System.out.println("Exception processing string.");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Exception processing string.");
}
return null;
} | java | {
"resource": ""
} |
q14560 | NYTCorpusDocumentParser.getDOMObject | train | private Document getDOMObject(String filename, boolean validating)
throws SAXException, IOException, ParserConfigurationException {
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
if (!validating) {
factory.setValidating(validating);
factory.setSchema(null);
factory.setNamespaceAware(false);
}
DocumentBuilder builder = factory.newDocumentBuilder();
// Create the builder and parse the file
Document doc = builder.parse(new File(filename));
return doc;
} | java | {
"resource": ""
} |
q14561 | MultiValue.getValueType | train | @Pure
@SuppressWarnings("unchecked")
public Class<? extends T> getValueType() {
if (this.object == null) {
return null;
}
return (Class<? extends T>) this.object.getClass();
} | java | {
"resource": ""
} |
q14562 | MultiValue.add | train | public void add(T newValue) {
if (this.isSet) {
if (!this.isMultiple
&& newValue != this.object && (newValue == null || !newValue.equals(this.object))) {
this.isMultiple = true;
this.object = null;
}
} else {
this.object = newValue;
this.isSet = true;
this.isMultiple = false;
}
} | java | {
"resource": ""
} |
q14563 | PlotBundle.commandsWritingDataTo | train | public String commandsWritingDataTo(File dataDirectory) throws IOException {
final Map<DatafileReference, File> refsToFiles = Maps.newHashMap();
for (final DatafileReference datafileReference : datafileReferences) {
final File randomFile = File.createTempFile("plotBundle", ".dat", dataDirectory);
randomFile.deleteOnExit();
refsToFiles.put(datafileReference, randomFile);
Files.asCharSink(randomFile, Charsets.UTF_8).write(datafileReference.data);
}
final StringBuilder ret = new StringBuilder();
for (final Object commandComponent : commandComponents) {
if (commandComponent instanceof String) {
ret.append(commandComponent);
} else if (commandComponent instanceof DatafileReference) {
final File file = refsToFiles.get(commandComponent);
if (file != null) {
ret.append(file.getAbsolutePath());
} else {
throw new RuntimeException("PlotBundle references an unknown data source");
}
} else {
throw new RuntimeException("Unknown command component " + commandComponent);
}
}
return ret.toString();
} | java | {
"resource": ""
} |
q14564 | DBaseFileWriter.setCodePage | train | public void setCodePage(DBaseCodePage code) {
if (this.columns != null) {
throw new IllegalStateException();
}
if (code != null) {
this.language = code;
}
} | java | {
"resource": ""
} |
q14565 | DBaseFileWriter.writeDBFDate | train | @SuppressWarnings("checkstyle:magicnumber")
private void writeDBFDate(Date date) throws IOException {
final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); //$NON-NLS-1$
writeDBFString(format.format(date), 8, (byte) ' ');
} | java | {
"resource": ""
} |
q14566 | DBaseFileWriter.computeFieldSize | train | private static int computeFieldSize(AttributeValue value) throws DBaseFileException, AttributeException {
final DBaseFieldType dbftype = DBaseFieldType.fromAttributeType(value.getType());
return dbftype.getFieldSize(value.getString());
} | java | {
"resource": ""
} |
q14567 | DBaseFileWriter.computeDecimalSize | train | private static int computeDecimalSize(AttributeValue value) throws DBaseFileException, AttributeException {
final DBaseFieldType dbftype = DBaseFieldType.fromAttributeType(value.getType());
return dbftype.getDecimalPointPosition(value.getString());
} | java | {
"resource": ""
} |
q14568 | DBaseFileWriter.isSupportedType | train | @Pure
public static boolean isSupportedType(DBaseFieldType type) {
return (type != DBaseFieldType.BINARY)
&& (type != DBaseFieldType.GENERAL)
&& (type != DBaseFieldType.MEMORY)
&& (type != DBaseFieldType.PICTURE)
&& (type != DBaseFieldType.VARIABLE);
} | java | {
"resource": ""
} |
q14569 | DBaseFileWriter.extractColumns | train | @SuppressWarnings("checkstyle:magicnumber")
private List<DBaseFileField> extractColumns(List<? extends AttributeProvider> providers)
throws DBaseFileException, AttributeException {
final Map<String, DBaseFileField> attributeColumns = new TreeMap<>();
DBaseFileField oldField;
String name;
String kname;
int fieldSize;
int decimalSize;
final Set<String> skippedColumns = new TreeSet<>();
for (final AttributeProvider provider : providers) {
for (final Attribute attr : provider.attributes()) {
final DBaseFieldType dbftype = DBaseFieldType.fromAttributeType(attr.getType());
// The following types are not yet supported
if (isSupportedType(dbftype)) {
name = attr.getName();
kname = name.toLowerCase();
oldField = attributeColumns.get(kname);
// compute the sizes
fieldSize = computeFieldSize(attr);
decimalSize = computeDecimalSize(attr);
if (oldField == null) {
oldField = new DBaseFileField(
name,
dbftype,
fieldSize,
decimalSize);
attributeColumns.put(kname, oldField);
} else {
oldField.updateSizes(fieldSize, decimalSize);
}
} else {
skippedColumns.add(attr.getName().toUpperCase());
}
}
// Be sure that the memory was not fully filled by the saving process
provider.freeMemory();
}
//Max of field allowed : 128
if (attributeColumns.size() > 128) {
throw new TooManyDBaseColumnException(attributeColumns.size(), 128);
}
final List<DBaseFileField> dbColumns = new ArrayList<>();
dbColumns.addAll(attributeColumns.values());
attributeColumns.clear();
for (int idx = 0; idx < dbColumns.size(); ++idx) {
dbColumns.get(idx).setColumnIndex(idx);
}
if (!skippedColumns.isEmpty()) {
columnsSkipped(skippedColumns);
}
return dbColumns;
} | java | {
"resource": ""
} |
q14570 | DBaseFileWriter.writeHeader | train | public void writeHeader(List<? extends AttributeProvider> providers) throws IOException, AttributeException {
if (this.columns == null) {
this.columns = extractColumns(providers);
writeDescriptionHeader(providers.size());
writeColumns();
}
} | java | {
"resource": ""
} |
q14571 | DBaseFileWriter.writeRecord | train | @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:magicnumber"})
public void writeRecord(AttributeProvider element) throws IOException, AttributeException {
if (this.columns == null) {
throw new MustCallWriteHeaderFunctionException();
}
//Field deleted flag (value : 2Ah (*) => Record is deleted, 20h (blank) => Record is valid)
this.stream.writeByte(0x20);
for (final DBaseFileField field : this.columns) {
// Get attribute
final DBaseFieldType dbftype = field.getType();
final String fieldName = field.getName();
AttributeValue attr = element != null ? element.getAttribute(fieldName) : null;
if (attr == null) {
attr = new AttributeValueImpl(dbftype.toAttributeType());
attr.setToDefault();
} else {
if (attr.isAssigned()) {
attr = new AttributeValueImpl(attr);
attr.cast(dbftype.toAttributeType());
} else {
attr = new AttributeValueImpl(attr);
attr.setToDefaultIfUninitialized();
}
}
// Write value
switch (dbftype) {
case BOOLEAN:
writeDBFBoolean(attr.getBoolean());
break;
case DATE:
writeDBFDate(attr.getDate());
break;
case STRING:
writeDBFString(attr.getString(), field.getLength(), (byte) ' ');
break;
case INTEGER_2BYTES:
writeDBFInteger((short) attr.getInteger());
break;
case INTEGER_4BYTES:
writeDBFLong((int) attr.getInteger());
break;
case DOUBLE:
writeDBFDouble(attr.getReal());
break;
case FLOATING_NUMBER:
case NUMBER:
if (attr.getType() == AttributeType.REAL) {
writeDBFNumber(attr.getReal(), field.getLength(), field.getDecimalPointPosition());
} else {
writeDBFNumber(attr.getInteger(), field.getLength(), field.getDecimalPointPosition());
}
break;
case BINARY:
case GENERAL:
case MEMORY:
case PICTURE:
case VARIABLE:
// not yet supported
writeDBFString((String) null, 10, (byte) 0);
break;
default:
throw new IllegalStateException();
}
}
// Be sure that the memory was not fully filled by the saving process
if (element != null) {
element.freeMemory();
}
} | java | {
"resource": ""
} |
q14572 | DBaseFileWriter.write | train | public void write(AttributeProvider... providers) throws IOException, AttributeException {
writeHeader(providers);
for (final AttributeProvider provider : providers) {
writeRecord(provider);
}
close();
} | java | {
"resource": ""
} |
q14573 | DBaseFileWriter.close | train | @Override
@SuppressWarnings("checkstyle:magicnumber")
public void close() throws IOException {
if (this.stream != null) {
//End of file (1Ah)
this.stream.write(0x1A);
this.stream.close();
this.stream = null;
}
if (this.columns != null) {
this.columns.clear();
this.columns = null;
}
} | java | {
"resource": ""
} |
q14574 | BinaryTreeNode.getChildAt | train | @Pure
public final N getChildAt(BinaryTreeZone index) {
switch (index) {
case LEFT:
return this.left;
case RIGHT:
return this.right;
default:
throw new IndexOutOfBoundsException();
}
} | java | {
"resource": ""
} |
q14575 | BinaryTreeNode.setRightChild | train | public boolean setRightChild(N newChild) {
final N oldChild = this.right;
if (oldChild == newChild) {
return false;
}
if (oldChild != null) {
oldChild.setParentNodeReference(null, true);
--this.notNullChildCount;
firePropertyChildRemoved(1, oldChild);
}
if (newChild != null) {
final N oldParent = newChild.getParentNode();
if (oldParent != this) {
newChild.removeFromParent();
}
}
this.right = newChild;
if (newChild != null) {
newChild.setParentNodeReference(toN(), true);
++this.notNullChildCount;
firePropertyChildAdded(1, newChild);
}
return true;
} | java | {
"resource": ""
} |
q14576 | BinaryTreeNode.setChildAt | train | public final boolean setChildAt(BinaryTreeZone zone, N newChild) {
switch (zone) {
case LEFT:
return setLeftChild(newChild);
case RIGHT:
return setRightChild(newChild);
default:
throw new IndexOutOfBoundsException();
}
} | java | {
"resource": ""
} |
q14577 | PropertiesTableModel.add | train | public void add(final String key, final String value)
{
data.setProperty(key, value);
fireTableDataChanged();
} | java | {
"resource": ""
} |
q14578 | DssatWeatherInput.readFile | train | @Override
protected HashMap readFile(HashMap brMap) throws IOException {
HashMap ret = new HashMap();
ArrayList<HashMap> files = readDailyData(brMap, new HashMap());
// compressData(files);
ret.put("weathers", files);
return ret;
} | java | {
"resource": ""
} |
q14579 | Transform2D.getTranslationVector | train | @Pure
public void getTranslationVector(Tuple2D<?> translation) {
assert translation != null : AssertMessages.notNullParameter();
translation.set(this.m02, this.m12);
} | java | {
"resource": ""
} |
q14580 | Transform2D.getScaleRotate2x2 | train | @SuppressWarnings("checkstyle:magicnumber")
protected void getScaleRotate2x2(double[] scales, double[] rots) {
final double[] tmp = new double[9];
tmp[0] = this.m00;
tmp[1] = this.m01;
tmp[2] = 0;
tmp[3] = this.m10;
tmp[4] = this.m11;
tmp[5] = 0;
tmp[6] = 0;
tmp[7] = 0;
tmp[8] = 0;
computeSVD(tmp, scales, rots);
} | java | {
"resource": ""
} |
q14581 | Transform2D.getRotation | train | @Pure
@SuppressWarnings("checkstyle:magicnumber")
public double getRotation() {
final double[] tmpScale = new double[3];
final double[] tmpRot = new double[9];
getScaleRotate2x2(tmpScale, tmpRot);
if (Math.signum(tmpRot[0]) != Math.signum(tmpRot[4])) {
// Sinuses are on the top-left to bottom-right diagonal
// -s c 0
// c s 0
// 0 0 1
return Math.atan2(tmpRot[4], tmpRot[3]);
}
// Sinuses are on the top-right to bottom-left diagonal
// c -s 0
// s c 0
// 0 0 1
return Math.atan2(tmpRot[3], tmpRot[0]);
} | java | {
"resource": ""
} |
q14582 | Transform2D.setRotation | train | @SuppressWarnings("checkstyle:magicnumber")
public void setRotation(double angle) {
final double[] tmpScale = new double[3];
final double[] tmpRot = new double[9];
getScaleRotate2x2(tmpScale, tmpRot);
final double cos = Math.cos(angle);
final double sin = Math.sin(angle);
// R * S
this.m00 = tmpScale[0] * cos;
this.m01 = tmpScale[1] * -sin;
this.m10 = tmpScale[0] * sin;
this.m11 = tmpScale[1] * cos;
// S * R
// this.m00 = tmp_scale[0] * cos;
// this.m01 = tmp_scale[0] * -sin;
// this.m10 = tmp_scale[1] * sin;
// this.m11 = tmp_scale[1] * cos;
} | java | {
"resource": ""
} |
q14583 | Transform2D.getScale | train | @Pure
@SuppressWarnings("checkstyle:magicnumber")
public double getScale() {
final double[] tmpScale = new double[3];
final double[] tmpRot = new double[9];
getScaleRotate2x2(tmpScale, tmpRot);
return MathUtil.max(tmpScale);
} | java | {
"resource": ""
} |
q14584 | Transform2D.getScaleVector | train | @Pure
@SuppressWarnings("checkstyle:magicnumber")
public void getScaleVector(Tuple2D<?> scale) {
assert scale != null : AssertMessages.notNullParameter();
final double[] tmpScale = new double[3];
final double[] tmpRot = new double[9];
getScaleRotate2x2(tmpScale, tmpRot);
scale.set(tmpScale[0], tmpScale[1]);
} | java | {
"resource": ""
} |
q14585 | Transform2D.setScale | train | @SuppressWarnings("checkstyle:magicnumber")
public void setScale(double scaleX, double scaleY) {
final double[] tmpScale = new double[3];
final double[] tmpRot = new double[9];
getScaleRotate2x2(tmpScale, tmpRot);
this.m00 = tmpRot[0] * scaleX;
this.m01 = tmpRot[1] * scaleY;
this.m10 = tmpRot[3] * scaleX;
this.m11 = tmpRot[4] * scaleY;
} | java | {
"resource": ""
} |
q14586 | Transform2D.setScale | train | public void setScale(Tuple2D<?> tuple) {
assert tuple != null : AssertMessages.notNullParameter();
setScale(tuple.getX(), tuple.getY());
} | java | {
"resource": ""
} |
q14587 | Transform2D.makeRotationMatrix | train | public void makeRotationMatrix(double angle) {
final double sinAngle = Math.sin(angle);
final double cosAngle = Math.cos(angle);
this.m00 = cosAngle;
this.m01 = -sinAngle;
this.m02 = 0.;
this.m11 = cosAngle;
this.m10 = sinAngle;
this.m12 = 0.;
this.m20 = 0.;
this.m21 = 0.;
this.m22 = 1.;
} | java | {
"resource": ""
} |
q14588 | Transform2D.makeTranslationMatrix | train | public void makeTranslationMatrix(double dx, double dy) {
this.m00 = 1.;
this.m01 = 0.;
this.m02 = dx;
this.m10 = 0.;
this.m11 = 1.;
this.m12 = dy;
this.m20 = 0.;
this.m21 = 0.;
this.m22 = 1.;
} | java | {
"resource": ""
} |
q14589 | Transform2D.makeScaleMatrix | train | public void makeScaleMatrix(double scaleX, double scaleY) {
this.m00 = scaleX;
this.m01 = 0.;
this.m02 = 0.;
this.m10 = 0.;
this.m11 = scaleY;
this.m12 = 0.;
this.m20 = 0.;
this.m21 = 0.;
this.m22 = 1.;
} | java | {
"resource": ""
} |
q14590 | Transform2D.transform | train | public void transform(Tuple2D<?> tuple, Tuple2D<?> result) {
assert tuple != null : AssertMessages.notNullParameter(0);
assert result != null : AssertMessages.notNullParameter(1);
result.set(
this.m00 * tuple.getX() + this.m01 * tuple.getY() + this.m02,
this.m10 * tuple.getX() + this.m11 * tuple.getY() + this.m12);
} | java | {
"resource": ""
} |
q14591 | KeyPadPanel.initializeButton | train | protected void initializeButton(final Button button, final Color foreground,
final Color background)
{
button.setForeground(foreground);
button.setBackground(background);
} | java | {
"resource": ""
} |
q14592 | KeyPadPanel.initializeButtons | train | private void initializeButtons()
{
initializeButton(button1 = new Button("1"), Color.black, Color.lightGray);
initializeButton(button2 = new Button("2"), Color.black, Color.lightGray);
initializeButton(button3 = new Button("3"), Color.black, Color.lightGray);
initializeButton(button4 = new Button("4"), Color.black, Color.lightGray);
initializeButton(button5 = new Button("5"), Color.black, Color.lightGray);
initializeButton(button6 = new Button("6"), Color.black, Color.lightGray);
initializeButton(button7 = new Button("7"), Color.black, Color.lightGray);
initializeButton(button8 = new Button("8"), Color.black, Color.lightGray);
initializeButton(button9 = new Button("9"), Color.black, Color.lightGray);
initializeButton(button0 = new Button("0"), Color.black, Color.lightGray);
initializeButton(buttonCancel = new Button("A"), Color.black, Color.lightGray);
initializeButton(buttonTable = new Button("T"), Color.black, Color.lightGray);
initializeButton(buttonEnter = new Button("E"), Color.black, Color.lightGray);
initializeButton(buttonMinus = new Button("-"), Color.black, Color.lightGray);
initializeButton(buttonPlus = new Button("+"), Color.black, Color.lightGray);
initializeButton(buttonStorno = new Button("ST"), Color.black, Color.lightGray);
} | java | {
"resource": ""
} |
q14593 | SGraphSegment.connectBeginToBegin | train | public void connectBeginToBegin(SGraphSegment segment) {
if (segment.getGraph() != getGraph()) {
throw new IllegalArgumentException();
}
final SGraphPoint point = new SGraphPoint(getGraph());
setBegin(point);
segment.setBegin(point);
final SGraph g = getGraph();
assert g != null;
g.updatePointCount(-1);
} | java | {
"resource": ""
} |
q14594 | SGraphSegment.connectBeginToEnd | train | public void connectBeginToEnd(SGraphSegment segment) {
if (segment.getGraph() != getGraph()) {
throw new IllegalArgumentException();
}
final SGraphPoint point = new SGraphPoint(getGraph());
setBegin(point);
segment.setEnd(point);
final SGraph g = getGraph();
assert g != null;
g.updatePointCount(-1);
} | java | {
"resource": ""
} |
q14595 | SGraphSegment.connectEndToEnd | train | public void connectEndToEnd(SGraphSegment segment) {
if (segment.getGraph() != getGraph()) {
throw new IllegalArgumentException();
}
final SGraphPoint point = new SGraphPoint(getGraph());
setEnd(point);
segment.setEnd(point);
final SGraph g = getGraph();
assert g != null;
g.updatePointCount(-1);
} | java | {
"resource": ""
} |
q14596 | SGraphSegment.disconnectBegin | train | public void disconnectBegin() {
if (this.startPoint != null) {
this.startPoint.remove(this);
}
this.startPoint = new SGraphPoint(getGraph());
this.startPoint.add(this);
} | java | {
"resource": ""
} |
q14597 | SGraphSegment.disconnectEnd | train | public void disconnectEnd() {
if (this.endPoint != null) {
this.endPoint.remove(this);
}
this.endPoint = new SGraphPoint(getGraph());
this.endPoint.add(this);
} | java | {
"resource": ""
} |
q14598 | SGraphSegment.addUserData | train | public boolean addUserData(Object userData) {
if (this.userData == null) {
this.userData = new ArrayList<>();
}
return this.userData.add(userData);
} | java | {
"resource": ""
} |
q14599 | SGraphSegment.getUserDataAt | train | @Pure
public Object getUserDataAt(int index) {
if (this.userData == null) {
throw new IndexOutOfBoundsException();
}
return this.userData.get(index);
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.