├── .gitignore ├── README.md ├── ch.akuhn.hapax ├── .classpath ├── .project ├── .settings │ └── org.eclipse.ltk.core.refactoring.prefs ├── LICENSE ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── lib │ ├── chunks-r8MP.jar │ ├── snowball.jar │ └── svdlib-r50M.jar ├── src │ └── ch │ │ └── akuhn │ │ └── hapax │ │ ├── CorpusBuilder.java │ │ ├── Hapax.java │ │ ├── NewHapaxExample.java │ │ ├── Query.java │ │ ├── cluster │ │ ├── ClusterEngine.java │ │ ├── Dendrogram.java │ │ ├── Distance.java │ │ └── Similarity.java │ │ ├── corpus │ │ ├── CamelCaseScanner.java │ │ ├── Corpora.java │ │ ├── Corpus.java │ │ ├── CorpusBuilderHelper.java │ │ ├── LetterScanner.java │ │ ├── PorterStemmer.java │ │ ├── ScannerClient.java │ │ ├── SimpleCorpus.java │ │ ├── Stemmer.java │ │ ├── Stopwords.java │ │ ├── TermScanner.java │ │ ├── Terms.java │ │ └── WordScanner.java │ │ ├── index │ │ ├── AssociativeList.java │ │ ├── GlobalWeighting.java │ │ ├── LatentSemanticIndex.java │ │ ├── LocalWeighting.java │ │ ├── LogLikelihood.java │ │ ├── Ranking.java │ │ └── TermDocumentMatrix.java │ │ ├── linalg │ │ ├── BufferedMatrix.java │ │ ├── DenseMatrix.java │ │ ├── DenseVector.java │ │ ├── Matrix.java │ │ ├── OfflineMatrix.java │ │ ├── SVD.java │ │ ├── SparseMatrix.java │ │ ├── SparseVector.java │ │ ├── SymetricMatrix.java │ │ └── Vector.java │ │ ├── resources │ │ ├── Resource.java │ │ ├── hapax.fm3.mse │ │ ├── stopwords_SMART.txt │ │ ├── stopwords_basicEnglish.txt │ │ └── stopwords_moreBasicEnglish.txt │ │ └── util │ │ ├── BloomFilter.java │ │ ├── CharStream.java │ │ ├── FileResource.java │ │ ├── Open.java │ │ ├── Resource.java │ │ ├── ResourceStream.java │ │ ├── RuntimeIOException.java │ │ └── Ziperator.java └── test │ ├── ch │ └── akuhn │ │ └── hapax │ │ ├── index │ │ └── AssociativeListTest.java │ │ └── linalg │ │ ├── DenseMatrixTest.java │ │ └── SVDTest.java │ ├── example │ ├── ClusterExample.java │ ├── CurrentDirJava.java │ ├── Examples.java │ ├── LogLikelihoodExample.java │ └── Sandbox.java │ └── hapax │ └── test │ ├── CamelCaseScannerTest.java │ ├── DeerExample.java │ ├── InputStreamScannerTest.java │ ├── SmallDocumentsTest.java │ ├── SparseVectorTest.java │ ├── StopwordsTest.java │ └── SymetricMatrixTest.java ├── ch.akuhn.matrix ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── data │ ├── arpack-examples-simple-dssimp.f │ ├── data.txt │ ├── edu-stanford-waldron-isomap.m │ ├── ggvis_ggobi-2.1.8_mds.c │ └── swiss_roll_data.matlab5 ├── ggobi.zip ├── lib │ ├── arpack-combo-0.1.jar │ ├── dat1.txt │ ├── dat2.txt │ ├── dat3.txt │ ├── matrix.txt │ ├── mtj-0.9.12.jar │ ├── netlib-java-0.9.1.jar │ └── svdlibc.zip ├── src │ └── ch │ │ └── akuhn │ │ ├── com │ │ └── mathworks │ │ │ └── matlab │ │ │ └── OpenMatlab5.java │ │ ├── edu │ │ └── mit │ │ │ └── tedlab │ │ │ ├── DMat.java │ │ │ ├── SMat.java │ │ │ ├── SVDRec.java │ │ │ └── Svdlib.java │ │ ├── foreach │ │ ├── Collect.java │ │ ├── CollectAs.java │ │ ├── Each.java │ │ ├── EachAs.java │ │ ├── EachB.java │ │ ├── EachXY.java │ │ ├── For.java │ │ ├── Interval.java │ │ ├── Select.java │ │ ├── State.java │ │ └── Times.java │ │ ├── graph │ │ ├── DijkstraAlgorithm2.java │ │ ├── DijkstrasAlgorithm.java │ │ ├── FloydWarshallAlgorithm.java │ │ ├── Graph.java │ │ └── Node.java │ │ ├── graph2 │ │ ├── DijkstrasAlgorithm.java │ │ ├── Edge.java │ │ ├── FloydWarshallAlgorithm.java │ │ ├── Graph.java │ │ ├── KruskalsAlgorithm.java │ │ ├── MergeFind.java │ │ └── Node.java │ │ ├── isomap │ │ └── Isomap.java │ │ ├── linalg │ │ └── SVD.java │ │ ├── matrix │ │ ├── DenseMatrix.java │ │ ├── DenseVector.java │ │ ├── Function.java │ │ ├── Matrix.java │ │ ├── SparseMatrix.java │ │ ├── SparseVector.java │ │ ├── SymmetricMatrix.java │ │ ├── Util.java │ │ ├── Vector.java │ │ └── eigenvalues │ │ │ ├── AllEigenvalues.java │ │ │ ├── Eigenvalues.java │ │ │ ├── FewEigenvalues.java │ │ │ └── SingularValues.java │ │ ├── mds │ │ └── MultidimensionalScaling.java │ │ ├── org │ │ └── ggobi │ │ │ └── plugins │ │ │ └── ggvis │ │ │ ├── Main.java │ │ │ ├── Mds.java │ │ │ ├── Points.java │ │ │ ├── PointsDatavis.java │ │ │ ├── Viz.java │ │ │ └── WriteGGobiXML.java │ │ └── util │ │ ├── All.java │ │ ├── Arrays.java │ │ ├── As.java │ │ ├── Assert.java │ │ ├── Bag.java │ │ ├── CacheMap.java │ │ ├── Concat.java │ │ ├── Cycle.java │ │ ├── CycleDetector.java │ │ ├── Defaults.java │ │ ├── Extensions.java │ │ ├── Factory.java │ │ ├── Files.java │ │ ├── Generator.java │ │ ├── Get.java │ │ ├── IntArray.java │ │ ├── Is.java │ │ ├── IterableIterator.java │ │ ├── IterableIteratorFactory.java │ │ ├── IteratorAsList.java │ │ ├── Jason.java │ │ ├── List.java │ │ ├── ListBuffer.java │ │ ├── Maybe.java │ │ ├── Out.java │ │ ├── Pair.java │ │ ├── PrintOn.java │ │ ├── ProgressMonitor.java │ │ ├── Providable.java │ │ ├── Separator.java │ │ ├── Size.java │ │ ├── SizeOf.java │ │ ├── Stopwatch.java │ │ ├── Strings.java │ │ ├── Tab.java │ │ ├── TeeInputStream.java │ │ ├── TeeOutputStream.java │ │ └── Throw.java └── test │ └── ch │ └── akuhn │ ├── edu │ └── mit │ │ └── tedlab │ │ ├── Dat3.java │ │ ├── DeerwesterTest.java │ │ ├── Main.java │ │ ├── RegressionTest.java │ │ ├── Revision39.java │ │ └── SmallMatricesTest.java │ ├── foreach │ ├── CollectAsTest.java │ ├── CollectTest.java │ └── SelectTest.java │ ├── isomap │ ├── IsomapSwissRollTest.java │ ├── IsomapTest.java │ └── SwissRoll.java │ ├── matrix │ ├── MatrixTest.java │ ├── PerformanceTest.java │ ├── SymetricMatrixTest.java │ ├── eigenvalues │ │ ├── AllEigenvaluesTest.java │ │ └── FewEigenvaluesTest.java │ ├── printoptoassembly-1d-mult-v1.txt │ ├── printoptoassembly-onedimensional.txt │ └── printoptoassembly-twodimensional.txt │ ├── org │ └── ggobi │ │ └── plugins │ │ └── ggvis │ │ └── GGvisTest.java │ └── util │ ├── AssertionsEnabledTest.java │ ├── BagTest.java │ ├── CacheMapTest.java │ ├── CycleDetectorTest.java │ ├── CycleTest.java │ ├── DefaultsTest.java │ ├── FilesTest.java │ ├── GeneratorExamples.java │ ├── IteratorAsListTest.java │ ├── ListTest.java │ ├── Lorem.java │ ├── MaybeTest.java │ ├── ProvidableTest.java │ ├── SeparatorTest.java │ ├── StringsTest.java │ ├── TabTest.java │ └── ThrowTest.java ├── ch.akuhn.util ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.jdt.ui.prefs ├── LICENSE ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── src │ └── ch │ │ └── akuhn │ │ ├── foreach │ │ ├── Collect.java │ │ ├── CollectAs.java │ │ ├── Each.java │ │ ├── EachAs.java │ │ ├── EachB.java │ │ ├── EachXY.java │ │ ├── For.java │ │ ├── Interval.java │ │ ├── Select.java │ │ ├── State.java │ │ └── Times.java │ │ ├── util │ │ ├── All.java │ │ ├── Arrays.java │ │ ├── As.java │ │ ├── Assert.java │ │ ├── Bag.java │ │ ├── CacheMap.java │ │ ├── Concat.java │ │ ├── Cycle.java │ │ ├── CycleDetector.java │ │ ├── Defaults.java │ │ ├── Extensions.java │ │ ├── Factory.java │ │ ├── Files.java │ │ ├── Generator.java │ │ ├── Get.java │ │ ├── IntArray.java │ │ ├── Is.java │ │ ├── IterableIterator.java │ │ ├── IterableIteratorFactory.java │ │ ├── IteratorAsList.java │ │ ├── Jason.java │ │ ├── List.java │ │ ├── ListBuffer.java │ │ ├── Maybe.java │ │ ├── Out.java │ │ ├── Pair.java │ │ ├── PrintOn.java │ │ ├── ProgressMonitor.java │ │ ├── Providable.java │ │ ├── Separator.java │ │ ├── Size.java │ │ ├── SizeOf.java │ │ ├── Stopwatch.java │ │ ├── Strings.java │ │ ├── Tab.java │ │ ├── TeeInputStream.java │ │ ├── TeeOutputStream.java │ │ └── Throw.java │ │ └── values │ │ ├── AbstractValue.java │ │ ├── ActionValue.java │ │ ├── Arguments.java │ │ ├── BooleanValue.java │ │ ├── CollectionValue.java │ │ ├── ComputedValue.java │ │ ├── ImmutableValue.java │ │ ├── IntegerValue.java │ │ ├── MapValue.java │ │ ├── ReferenceValue.java │ │ ├── TaskFactory.java │ │ ├── TaskValue.java │ │ ├── Value.java │ │ ├── ValueChangedListener.java │ │ └── Values.java └── test │ └── ch │ └── akuhn │ ├── foreach │ ├── CollectAsTest.java │ ├── CollectTest.java │ └── SelectTest.java │ └── util │ ├── AssertionsEnabledTest.java │ ├── BagTest.java │ ├── CacheMapTest.java │ ├── CycleDetectorTest.java │ ├── CycleTest.java │ ├── DefaultsTest.java │ ├── FilesTest.java │ ├── GeneratorExamples.java │ ├── IteratorAsListTest.java │ ├── ListTest.java │ ├── Lorem.java │ ├── MaybeTest.java │ ├── ProvidableTest.java │ ├── SeparatorTest.java │ ├── StringsTest.java │ ├── TabTest.java │ └── ThrowTest.java ├── com.example.lawofdemeter ├── .classpath ├── .project ├── .settings │ ├── org.codemap.points.prefs │ ├── org.codemap.ui.mapview.prefs │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── plugin.xml └── src │ └── com │ └── example │ └── lawofdemeter │ ├── IJavaElementVisitor.java │ ├── LawOfDemeter.java │ ├── ModelBuilder.java │ ├── MyCompilationParticipant.java │ ├── MyElementChangedListener.java │ ├── model │ ├── Field.java │ ├── Method.java │ ├── Model.java │ └── Type.java │ └── views │ └── SampleView.java ├── org.codemap.feature ├── .project ├── build.properties ├── feature.properties └── feature.xml ├── org.codemap.test ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── lib │ └── jexample-r285.jar └── src │ └── ch │ └── unibe │ └── softwaremap │ ├── BaseTest.java │ └── ui │ ├── MapViewTest.java │ └── MeanderWindow.java ├── org.codemap.update ├── .project ├── ant-clean.xml ├── ant-upload.xml └── site_qualifier.txt └── org.codemap ├── .classpath ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs ├── org.eclipse.ltk.core.refactoring.prefs └── org.eclipse.wst.html.core.prefs ├── META-INF └── MANIFEST.MF ├── build.properties ├── icons ├── eclipse │ ├── call_hierarchy.gif │ ├── coverage.gif │ ├── error_obj.gif │ ├── file.gif │ ├── flow.gif │ ├── force_selection.gif │ ├── green_circle.gif │ ├── info_obj.gif │ ├── labels.gif │ ├── layers.gif │ ├── linked.gif │ ├── markers.gif │ ├── meeple.gif │ ├── packages.gif │ ├── palette.gif │ ├── search.gif │ ├── selection.gif │ ├── trace.gif │ ├── warning_obj.gif │ └── youarehere.gif └── sample.gif ├── icons_dev ├── codemap_noshadow.png ├── codemap_noshadow.svg ├── codemap_shadow.png └── codemap_shadow.svg ├── intro ├── codemapintro.html ├── codemapintro.md ├── css │ └── overview.css ├── images │ ├── codemap_noshadow.png │ ├── codemap_shadow.png │ ├── codemap_view.png │ └── open_codemap.png └── overviewExtensionContent.xml ├── lib └── jexample-4.4-r281.jar ├── plugin.xml ├── src ├── edu │ └── stanford │ │ └── hci │ │ └── flowmap │ │ ├── cluster │ │ ├── Cluster.java │ │ ├── ClusterLayout.java │ │ ├── DistancePair.java │ │ ├── FlowLayout.java │ │ ├── HierarchicalCluster.java │ │ └── Vector2D.java │ │ ├── prefuse │ │ └── render │ │ │ ├── BezierSpline.java │ │ │ └── FlowScale.java │ │ ├── structure │ │ ├── Edge.java │ │ ├── Graph.java │ │ └── Node.java │ │ └── utils │ │ ├── AttributeMap.java │ │ ├── GoodColorChooser.java │ │ ├── GraphicsGems.java │ │ └── Pair.java └── org │ └── codemap │ ├── ByPackageColorScheme.java │ ├── CodemapCore.java │ ├── Configuration.java │ ├── DefaultLabelScheme.java │ ├── DigitalElevationModel.java │ ├── HillShading.java │ ├── Labeling.java │ ├── Location.java │ ├── MapAlgorithm.java │ ├── MapInstance.java │ ├── MapPerProject.java │ ├── MapPerProjectCache.java │ ├── MapSelection.java │ ├── MapSetting.java │ ├── Point.java │ ├── callhierarchy │ ├── CallHierarchyTracker.java │ ├── CallModel.java │ ├── CallOverlay.java │ ├── GraphConversionVisitor.java │ └── vizualization │ │ ├── EdgeRenderer.java │ │ ├── Globals.java │ │ └── Options.java │ ├── commands │ ├── CallHierarchyCommand.java │ ├── CheckedCommand.java │ ├── ColoringCommand.java │ ├── Command.java │ ├── CompositeCommand.java │ ├── DropDownCommand.java │ ├── IConfigureMapValues.java │ ├── IConfigureMapView.java │ ├── LabelingCommand.java │ ├── MapCommands.java │ ├── MarkerCommand.java │ ├── OpenFilesCommand.java │ ├── SearchResultCommand.java │ ├── SelectionCommand.java │ └── YouAreHereCommand.java │ ├── communication │ ├── CodemapECFStart.java │ ├── ECFContribution.java │ ├── SelectionShare.java │ ├── messages │ │ ├── Message.java │ │ ├── SelectionMessage.java │ │ ├── StartMessage.java │ │ └── StopMessage.java │ ├── util │ │ ├── CommunicationOverlay.java │ │ ├── EditorPartListener.java │ │ └── StringShareDebugOptions.java │ └── views │ │ ├── CodemapRosterMenuHandler.java │ │ └── CodemapRosterMenuItem.java │ ├── eclemma │ ├── CoverageListener.java │ ├── ICodemapCoverage.java │ └── NullCoverageListener.java │ ├── editors │ └── CodemapEditor.java │ ├── internal │ ├── DEMAlgorithm.java │ ├── Grayscales.java │ ├── HausdorffDistance.java │ ├── LayoutAlgorithm.java │ ├── MapCaches.java │ └── ShadeAlgorithm.java │ ├── kdtree │ ├── Checker.java │ ├── DistanceMetric.java │ ├── Editor.java │ ├── EuclideanDistance.java │ ├── HPoint.java │ ├── HRect.java │ ├── HammingDistance.java │ ├── KDException.java │ ├── KDNode.java │ ├── KDTree.java │ ├── KdTreeLookup.java │ ├── KeyDuplicateException.java │ ├── KeyMissingException.java │ ├── KeySizeException.java │ └── NearestNeighborList.java │ ├── layers │ ├── Background.java │ ├── CodemapVisualization.java │ ├── CompositeLayer.java │ ├── CurrentSelectionOverlay.java │ ├── DefaultLabelScheme.java │ ├── Label.java │ ├── LabelFocus.java │ ├── LabelOverlay.java │ ├── Layer.java │ ├── OpenFileIconsLayer.java │ ├── OpenFilesOverlay.java │ ├── SearchResultsOverlay.java │ ├── SelectionOverlay.java │ └── YouAreHereOverlay.java │ ├── mapview │ ├── AllTextUpdater.java │ ├── CanvasListener.java │ ├── ControllerUtils.java │ ├── EditorPartListener.java │ ├── HeatMapColors.java │ ├── HoverShell.java │ ├── ITextUpdater.java │ ├── MapController.java │ ├── MapSelectionProvider.java │ ├── MapView.java │ ├── NullTextUpdater.java │ ├── ResizeListener.java │ ├── SearchBar.java │ ├── SelectionInfoAction.java │ ├── SelectionTracker.java │ ├── TextFilter.java │ ├── VisitedFilesHistory.java │ └── action │ │ ├── ActionStore.java │ │ ├── CheckBoxAction.java │ │ ├── ColorDropDownAction.java │ │ ├── CommandAction.java │ │ ├── DebugLocationsAction.java │ │ ├── DropDownAction.java │ │ ├── ForceSelectionAction.java │ │ ├── LabelDrowDownAction.java │ │ ├── LayerDropDownAction.java │ │ ├── LinkWithCallHierarchyAction.java │ │ ├── LinkWithSelectionAction.java │ │ ├── RadioButtonAction.java │ │ ├── ReloadMapAction.java │ │ ├── SaveAsPNGAction.java │ │ ├── SaveHapaxDataAction.java │ │ ├── ShowClassNameLabelAction.java │ │ ├── ShowCoverageAction.java │ │ ├── ShowDefaultColorsAction.java │ │ ├── ShowHeatMapColorsAction.java │ │ ├── ShowMarkersAction.java │ │ ├── ShowNoLabelAction.java │ │ ├── ShowOpenFilesAction.java │ │ ├── ShowPackageColorsAction.java │ │ ├── ShowSearchResultsAction.java │ │ ├── ShowSelectionAction.java │ │ └── ShowYouAreHereAction.java │ ├── marker │ ├── MarkerController.java │ ├── MarkerSelection.java │ └── MarkersOverlay.java │ ├── resources │ ├── MapBuilder.java │ ├── MapValueBuilder.java │ └── MapValues.java │ ├── sandbox │ └── main │ │ ├── DebugLog.java │ │ ├── Log.java │ │ ├── NullLog.java │ │ ├── QuickNDirtyMap.java │ │ └── SwtMain.java │ ├── search │ ├── QueryListener.java │ ├── SearchResultController.java │ └── SearchResultListener.java │ ├── tasks │ ├── ComputeBackgroundTask.java │ ├── ComputeConfigurationTask.java │ ├── ComputeEclipseIndexTask.java │ ├── ComputeElementsTask.java │ ├── ComputeElevationModelTask.java │ ├── ComputeFilteredElevationTask.java │ ├── ComputeHillShadingTask.java │ ├── ComputeIndexTask.java │ ├── ComputeLabelingTask.java │ ├── ComputeMapInstanceTask.java │ └── MapSelectionsValue.java │ ├── util │ ├── Adaptables.java │ ├── ArrayUtil.java │ ├── ChangeTriggerValue.java │ ├── CodemapColors.java │ ├── CodemapIcons.java │ ├── CodemapLabels.java │ ├── ColorBrewer.java │ ├── ColorScheme.java │ ├── CompositeActionGroup.java │ ├── Delimiter.java │ ├── EclipseTaskFactory.java │ ├── EclipseUtil.java │ ├── GoodColorGenerator.java │ ├── ID.java │ ├── IFileNameCallback.java │ ├── IconFactory.java │ ├── Log.java │ ├── MColor.java │ ├── MapScheme.java │ ├── MeanderError.java │ ├── MersenneTwister.java │ ├── Resources.java │ ├── RunLengthEncodedList.java │ ├── SafeSaveDialog.java │ ├── SelectionView.java │ ├── SparseTrueBooleanList.java │ ├── StopWatch.java │ ├── Tag.java │ └── geom │ │ ├── AffineTransform.java │ │ ├── Arc2D.java │ │ ├── ArcIterator.java │ │ ├── Area.java │ │ ├── AreaOp.java │ │ ├── ChainEnd.java │ │ ├── Crossings.java │ │ ├── CubicCurve2D.java │ │ ├── CubicIterator.java │ │ ├── Curve.java │ │ ├── CurveLink.java │ │ ├── Dimension.java │ │ ├── Dimension2D.java │ │ ├── Edge.java │ │ ├── Ellipse2D.java │ │ ├── EllipseIterator.java │ │ ├── FlatteningPathIterator.java │ │ ├── GeneralPath.java │ │ ├── IllegalPathStateException.java │ │ ├── Line2D.java │ │ ├── LineIterator.java │ │ ├── NoninvertibleTransformException.java │ │ ├── Order0.java │ │ ├── Order1.java │ │ ├── Order2.java │ │ ├── Order3.java │ │ ├── Path2D.java │ │ ├── PathIterator.java │ │ ├── Point.java │ │ ├── Point2D.java │ │ ├── QuadCurve2D.java │ │ ├── QuadIterator.java │ │ ├── RectIterator.java │ │ ├── Rectangle.java │ │ ├── Rectangle2D.java │ │ ├── RectangularShape.java │ │ ├── RoundRectIterator.java │ │ ├── RoundRectangle2D.java │ │ ├── Shape.java │ │ └── package.html │ └── wizards │ ├── NewCodemapCreationWizard.java │ └── NewCodemapCreationWizardPage.java └── test ├── ch ├── akuhn │ └── org │ │ └── ggobi │ │ └── plugins │ │ └── ggvis │ │ └── GGvisTest.java └── deif │ └── meander │ ├── AssertionsEnabledTest.java │ ├── DEMAlgorithmTest.java │ ├── RegressionTestNN.java │ └── util │ ├── ColorsTest.java │ ├── RunLengthEncodedListTest.java │ └── SparseTrueBooleanListTest.java └── example └── ExampleMap.java /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | *Codemap is your roadmap to software!* 2 | 3 | Codemap is a data-driven product (built using Java, Eclipse, and libraries trans-compiled from C/Fortran) that uses cartographic spatial visualizations to fosters awareness in collaborative software development. 4 | 5 | - 6 | - -- talk at the MIT 7 | 8 | Here's an outline of the code 9 | 10 | - `ch.akuhn.hapax` -- information retrieval, latent semantic indexing 11 | - `ch.akuhn.matrix` -- singular value decomposition, multi-dimesional scaling, isomap algorithm 12 | - `ch.akuhn.util` 13 | - `org.codemap` -- the Eclipse plug-in 14 | - `org.codemap.feature` 15 | - `org.codemap.test` 16 | - `org.codemap.update` 17 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ch.akuhn.hapax 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | #Thu Aug 06 18:33:47 CEST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 4 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Adrian Kuhn 2 | 3 | http://github.com/akuhn/ch.akuhn.util 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Hapax (software vocabulary search) 4 | Bundle-SymbolicName: ch.akuhn.hapax 5 | Bundle-Vendor: Adrian Kuhn 6 | Bundle-Version: 0.7.264.qualifier 7 | Export-Package: ch.akuhn.hapax, 8 | ch.akuhn.hapax.cluster, 9 | ch.akuhn.hapax.corpus, 10 | ch.akuhn.hapax.index, 11 | ch.akuhn.hapax.linalg, 12 | ch.akuhn.hapax.resources 13 | Bundle-ClassPath: ., 14 | lib/snowball.jar, 15 | lib/svdlib-r50M.jar 16 | Require-Bundle: ch.akuhn.util;bundle-version="2.1.0" 17 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 18 | 19 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | lib/snowball.jar,\ 6 | lib/svdlib-r50M.jar 7 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/lib/chunks-r8MP.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.hapax/lib/chunks-r8MP.jar -------------------------------------------------------------------------------- /ch.akuhn.hapax/lib/snowball.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.hapax/lib/snowball.jar -------------------------------------------------------------------------------- /ch.akuhn.hapax/lib/svdlib-r50M.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.hapax/lib/svdlib-r50M.jar -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/Query.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax; 2 | 3 | import ch.akuhn.hapax.index.LatentSemanticIndex; 4 | 5 | public class Query { 6 | 7 | public Query(double[] pseudoDocument, LatentSemanticIndex latentIndex) { 8 | // TODO Auto-generated constructor stub 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/cluster/Dendrogram.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.cluster; 2 | 3 | public abstract class Dendrogram { 4 | 5 | public static class Leaf extends Dendrogram { 6 | 7 | public final E element; 8 | 9 | public Leaf(E element) { 10 | this.element = element; 11 | } 12 | 13 | @Override 14 | public String toString() { 15 | return element.toString(); 16 | } 17 | 18 | } 19 | 20 | public static class Node extends Dendrogram { 21 | 22 | public final Dendrogram left, right; 23 | public final double threshold; 24 | 25 | public Node(Dendrogram left, Dendrogram right, double threshold) { 26 | this.left = left; 27 | this.right = right; 28 | this.threshold = threshold; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return String.format("(%s %s)", left, right); 34 | } 35 | 36 | } 37 | 38 | public Dendrogram parent; 39 | 40 | public Dendrogram merge(Dendrogram dendro, double threshold) { 41 | return new Node(this, dendro, threshold); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/cluster/Distance.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.cluster; 2 | 3 | public interface Distance { 4 | 5 | public static final double INFINITY = Double.POSITIVE_INFINITY; 6 | 7 | /** 8 | * Returns the distance between two objects. 9 | * 10 | * @return a non-negative value between 0.0 and {@link INFINITY}; 11 | */ 12 | public double dist(T a, T b); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/cluster/Similarity.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.cluster; 2 | 3 | public abstract class Similarity implements Distance { 4 | 5 | //@Override 6 | public double dist(T a, T b) { 7 | return 1 - similarity(a, b); 8 | } 9 | 10 | /** 11 | * Returns the similarity between two objects. 12 | * 13 | * @return a value between -1.0 and +1.0. 14 | */ 15 | public abstract double similarity(T a, T b); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/CamelCaseScanner.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import static java.lang.Character.isLetter; 4 | import static java.lang.Character.isLowerCase; 5 | import static java.lang.Character.isUpperCase; 6 | 7 | public class CamelCaseScanner extends TermScanner { 8 | 9 | @Override 10 | protected void scan() { 11 | while (true) { 12 | while (!isLetter(ch)) 13 | next(); 14 | this.mark(); 15 | if (isLowerCase(ch)) { 16 | next(); 17 | while (isLowerCase(ch)) 18 | next(); 19 | } else { 20 | next(); 21 | if (isLowerCase(ch)) { 22 | while (isLowerCase(ch)) 23 | next(); 24 | } else { 25 | while (isUpperCase(ch)) 26 | next(); 27 | if (isLowerCase(ch)) backtrack(); 28 | } 29 | } 30 | this.yank(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/Corpora.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import java.util.Iterator; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | public class Corpora implements Iterable{ 8 | 9 | private List corpora = new LinkedList(); 10 | 11 | public Corpora() { 12 | // do nothing 13 | } 14 | 15 | public void add(Corpus corpus) { 16 | corpora.add(corpus); 17 | } 18 | 19 | public Iterator iterator() { 20 | return corpora.iterator(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/Corpus.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | /** Text corpus, with term frequencies for each document. 4 | * Both terms and documents are identified by strings. 5 | * 6 | * @author Adrian Kuhn 7 | * 8 | */ 9 | public abstract class Corpus { 10 | 11 | public abstract void putDocument(String name, Terms content); 12 | 13 | public Terms terms() { 14 | Terms terms = new Terms(); 15 | for (String doc: documents()) terms.addAll(getDocument(doc)); 16 | return terms; 17 | } 18 | 19 | public abstract Iterable documents(); 20 | 21 | public abstract int documentCount(); 22 | 23 | public abstract boolean containsDocument(String doc); 24 | 25 | public boolean containsTerm(String term) { 26 | for (String doc: documents()) if (getDocument(doc).contains(term)) return true; 27 | return false; 28 | } 29 | 30 | public abstract Terms getDocument(String doc); 31 | 32 | public int termCount() { 33 | return terms().uniqueSize(); 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return String.format("%s (%d documents, %d terms)", 39 | this.getClass().getName(), 40 | documentCount(), 41 | termCount()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/LetterScanner.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import static java.lang.Character.isLetter; 4 | 5 | public class LetterScanner extends TermScanner { 6 | 7 | @Override 8 | protected void scan() { 9 | while (true) { 10 | while (!isLetter(ch)) 11 | next(); 12 | this.mark(); 13 | while (isLetter(ch)) 14 | next(); 15 | this.yank(); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/PorterStemmer.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import org.tartarus.snowball.SnowballStemmer; 4 | import org.tartarus.snowball.ext.porterStemmer; 5 | 6 | public class PorterStemmer implements Stemmer { 7 | 8 | private SnowballStemmer stemmer = new porterStemmer(); 9 | 10 | public String stem(CharSequence string) { 11 | stemmer.setCurrent(string.toString()); 12 | stemmer.stem(); 13 | return stemmer.getCurrent(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/ScannerClient.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | public interface ScannerClient { 4 | 5 | public static final ScannerClient DEBUG = new ScannerClient() { 6 | //@Override 7 | public void yield(CharSequence term) { 8 | System.out.println("\"" + term + "\""); 9 | } 10 | }; 11 | 12 | public static final ScannerClient NULL = new ScannerClient() { 13 | //@Override 14 | public void yield(CharSequence term) { 15 | // do nothing 16 | } 17 | }; 18 | 19 | public void yield(CharSequence term); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/SimpleCorpus.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | import java.util.TreeMap; 6 | 7 | 8 | public class SimpleCorpus extends Corpus { 9 | 10 | private Map documents; 11 | 12 | public SimpleCorpus() { 13 | this.documents = new TreeMap(); 14 | } 15 | 16 | @Override 17 | public boolean containsDocument(String doc) { 18 | return documents.containsKey(doc); 19 | } 20 | 21 | @Override 22 | public int documentCount() { 23 | return documents.size(); 24 | } 25 | 26 | @Override 27 | public Iterable documents() { 28 | return Collections.unmodifiableCollection(documents.keySet()); 29 | } 30 | 31 | @Override 32 | public Terms getDocument(String doc) { 33 | return documents.get(doc); 34 | } 35 | 36 | @Override 37 | public void putDocument(String name, Terms contents) { 38 | documents.put(name, contents); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/Stemmer.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | public interface Stemmer { 4 | 5 | public static final Stemmer NULL = new Stemmer() { 6 | //@Override 7 | public String stem(CharSequence string) { 8 | return string.toString(); 9 | } 10 | }; 11 | 12 | public String stem(CharSequence string); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/Stopwords.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import java.util.HashSet; 4 | 5 | import ch.akuhn.hapax.resources.Resource; 6 | import ch.akuhn.util.Strings; 7 | 8 | @SuppressWarnings("serial") 9 | public class Stopwords extends HashSet { 10 | 11 | public static final Stopwords BASIC_ENGLISH = new Stopwords() 12 | .readFromResource("stopwords_SMART.txt"); 13 | 14 | public Stopwords readFromResource(String name) { 15 | CharSequence str = Strings.fromInputStream(Resource.get(name)); 16 | for (String line: Strings.lines(str)) { 17 | if (line.startsWith("#")) continue; 18 | for (String word: Strings.letters(line)) { 19 | this.add(word); 20 | } 21 | } 22 | return this; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/corpus/WordScanner.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.corpus; 2 | 3 | import static java.lang.Character.isWhitespace; 4 | 5 | public class WordScanner extends TermScanner { 6 | 7 | @Override 8 | protected void scan() { 9 | while (true) { 10 | while (isWhitespace(ch)) 11 | next(); 12 | this.mark(); 13 | while (!isWhitespace(ch)) 14 | next(); 15 | this.yank(); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/index/LocalWeighting.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.index; 2 | 3 | public enum LocalWeighting { 4 | 5 | BINARY { 6 | @Override 7 | public double weight(double value) { 8 | return Math.signum(value); 9 | } 10 | }, 11 | LOG { 12 | @Override 13 | public double weight(double value) { 14 | return Math.log(value); 15 | } 16 | }, 17 | NULL, TERM; 18 | 19 | public double weight(double value) { 20 | return value; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/index/Ranking.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.index; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | 6 | class Rank implements Comparable> { 7 | 8 | public final T element; 9 | public final double rank; 10 | 11 | public Rank(T element, double rank) { 12 | this.element = element; 13 | this.rank = rank; 14 | } 15 | 16 | //@Override 17 | public int compareTo(Rank other) { 18 | return (int) Math.signum(other.rank - this.rank); 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return String.format("%s %.0f%%", element, rank * 100); 24 | } 25 | 26 | } 27 | 28 | @SuppressWarnings("serial") 29 | public class Ranking extends ArrayList> { 30 | 31 | public void add(T element, double rank) { 32 | this.add(new Rank(element, rank)); 33 | } 34 | 35 | public Ranking sort() { 36 | Collections.sort(this); 37 | return this; 38 | } 39 | 40 | public Ranking top(int ten) { 41 | Ranking result = new Ranking(); 42 | int end = Math.min(this.size(), ten); 43 | for (Rank each: this.subList(0, end)) result.add(each); 44 | return result; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/linalg/DenseMatrix.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.linalg; 2 | 3 | public class DenseMatrix extends Matrix { 4 | 5 | private double[][] values; 6 | 7 | public DenseMatrix(double[][] values) { 8 | this.values = values; 9 | } 10 | 11 | public DenseMatrix(int rows, int columns) { 12 | values = new double[rows][columns]; 13 | } 14 | 15 | @Override 16 | public double add(int row, int column, double value) { 17 | return values[row][column] += value; 18 | } 19 | 20 | @Override 21 | public int columnCount() { 22 | return values[0].length; 23 | } 24 | 25 | @Override 26 | public double get(int row, int column) { 27 | return values[row][column]; 28 | } 29 | 30 | @Override 31 | public double put(int row, int column, double value) { 32 | return values[row][column] = value; 33 | } 34 | 35 | @Override 36 | public int rowCount() { 37 | return values.length; 38 | } 39 | 40 | @Override 41 | public int used() { 42 | // TODO Auto-generated method stub 43 | throw null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/linalg/SymetricMatrix.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.linalg; 2 | 3 | import static ch.akuhn.foreach.For.range; 4 | 5 | import java.util.Arrays; 6 | 7 | public class SymetricMatrix extends Matrix { 8 | 9 | public double[][] values; 10 | 11 | public SymetricMatrix(int size) { 12 | values = new double[size][]; 13 | for (int n: range(values.length)) 14 | values[n] = new double[n + 1]; 15 | } 16 | 17 | @Override 18 | public int columnCount() { 19 | return rowCount(); 20 | } 21 | 22 | @Override 23 | public double get(int row, int column) { 24 | return row > column ? values[row][column] : values[column][row]; 25 | } 26 | 27 | @Override 28 | public double put(int row, int column, double value) { 29 | return row > column ? (values[row][column] = value) : (values[column][row] = value); 30 | } 31 | 32 | @Override 33 | public int rowCount() { 34 | return values.length; 35 | } 36 | 37 | @Override 38 | public int used() { 39 | throw new UnsupportedOperationException(); 40 | } 41 | 42 | public void fill(double constant) { 43 | for (double[] row: values) Arrays.fill(row, constant); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/resources/Resource.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.resources; 2 | 3 | import java.io.InputStream; 4 | 5 | public class Resource { 6 | 7 | public static InputStream get(String name) { 8 | return Resource.class.getResourceAsStream(name); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/resources/hapax.fm3.mse: -------------------------------------------------------------------------------- 1 | ( 2 | (FM3.Package (id: 1) 3 | (name 'Hapax') 4 | (classes 5 | (FM3.Class (id: 5) 6 | (name 'Doc') 7 | (superclass (ref: Object)) 8 | (attributes 9 | (FM3.Property (id: 8) 10 | (name 'contents') 11 | (type (ref: String))) 12 | (FM3.Property (id: 6) 13 | (name 'name') 14 | (type (ref: String))) 15 | (FM3.Property (id: 4) 16 | (name 'terms') 17 | (@fame.util.bag String) 18 | (multivalued true) 19 | (type (ref: Object))) 20 | (FM3.Property (id: 2) 21 | (name 'version') 22 | (type (ref: String)))))))) -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/resources/stopwords_moreBasicEnglish.txt: -------------------------------------------------------------------------------- 1 | Hello, worlds! 2 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/util/Open.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.util; 2 | 3 | import java.io.File; 4 | 5 | public class Open { 6 | 7 | public static final Resource file(File file) { 8 | return new FileResource(file); 9 | } 10 | 11 | public static final Resource file(String name) { 12 | return new FileResource(new File(name)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/util/Resource.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.util; 2 | 3 | public interface Resource { 4 | 5 | public abstract ResourceStream open(); 6 | 7 | public abstract ResourceStream writeStream(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/util/ResourceStream.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.util; 2 | 3 | public interface ResourceStream { 4 | 5 | public int nextInt(); 6 | 7 | public void close(); 8 | 9 | public double nextDouble(); 10 | 11 | public ResourceStream put(double value); 12 | 13 | public ResourceStream put(int value); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/src/ch/akuhn/hapax/util/RuntimeIOException.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.util; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | 6 | @SuppressWarnings("serial") 7 | public class RuntimeIOException extends RuntimeException { 8 | 9 | public RuntimeIOException(IOException ex) { 10 | super(ex); 11 | } 12 | 13 | @Override 14 | public synchronized Throwable fillInStackTrace() { 15 | return this; 16 | } 17 | 18 | public boolean isEOF() { 19 | return getCause() instanceof EOFException; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/ch/akuhn/hapax/linalg/DenseMatrixTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.hapax.linalg; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | 8 | public class DenseMatrixTest { 9 | 10 | private static final double EPSILON = 1e-9; 11 | 12 | @Test 13 | public void testRowColumnVector() { 14 | DenseMatrix m = new DenseMatrix(30, 40); 15 | assertEquals(30, m.rowCount()); 16 | assertEquals(40, m.columnCount()); 17 | Vector row = m.row(7); 18 | assertEquals(40, row.size()); 19 | Vector column = m.column(23); 20 | assertEquals(30, column.size()); 21 | row.put(23, 2009); 22 | assertEquals(2009, row.get(23), EPSILON); 23 | assertEquals(2009, column.get(7), EPSILON); 24 | assertEquals(2009, m.get(7,23), EPSILON); 25 | } 26 | 27 | @Test 28 | public void testRowColumnVectorIterable() { 29 | DenseMatrix m = new DenseMatrix(30, 40); 30 | assertEquals(30, m.rowCount()); 31 | assertEquals(40, m.columnCount()); 32 | m.rows().iterator().next().put(23, 2323); 33 | m.columns().iterator().next().put(7, 77); 34 | assertEquals(2323, m.get(0,23), EPSILON); 35 | assertEquals(77, m.get(7,0), EPSILON); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/example/ClusterExample.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import java.awt.Point; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import ch.akuhn.hapax.cluster.ClusterEngine; 8 | import ch.akuhn.hapax.cluster.Distance; 9 | 10 | public class ClusterExample { 11 | 12 | public static void main(String[] args) { 13 | 14 | Distance sim = new Distance() { 15 | //@Override 16 | public double dist(Point a, Point b) { 17 | return a.distance(b); 18 | } 19 | }; 20 | 21 | List points = new ArrayList(); 22 | points.add(new Point(2, 3)); 23 | points.add(new Point(2, 5)); 24 | points.add(new Point(2, 6)); 25 | points.add(new Point(7, 8)); 26 | 27 | ClusterEngine clusty = new ClusterEngine(points, sim); 28 | System.out.println(clusty.dendrogram()); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/example/LogLikelihoodExample.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import java.io.File; 4 | import java.util.SortedSet; 5 | import java.util.TreeSet; 6 | 7 | import ch.akuhn.hapax.corpus.Corpus; 8 | import ch.akuhn.hapax.corpus.CorpusBuilderHelper; 9 | import ch.akuhn.hapax.corpus.SimpleCorpus; 10 | import ch.akuhn.hapax.corpus.Terms; 11 | import ch.akuhn.hapax.index.LogLikelihood; 12 | import ch.akuhn.util.Out; 13 | 14 | public class LogLikelihoodExample { 15 | 16 | public static void main(String... args) { 17 | 18 | Corpus c1 = new CorpusBuilderHelper(new SimpleCorpus()).importAllFiles(new File("../Fame"), ".java"); 19 | Corpus c2 = new CorpusBuilderHelper(new SimpleCorpus()).importAllFiles(new File("../CELLS"), ".java"); 20 | 21 | System.out.println(c1); 22 | System.out.println(c2); 23 | 24 | SortedSet list = new TreeSet(); 25 | for (String each: (union(c1.terms(), c2.terms())).elements()) { 26 | list.add(new LogLikelihood(c1.terms(), c2.terms(), each)); 27 | } 28 | 29 | Out.puts(list); 30 | 31 | } 32 | 33 | private static Terms union(Terms t1, Terms t2) { 34 | Terms terms = new Terms(); 35 | terms.addAll(t1); 36 | terms.addAll(t2); 37 | return terms; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/example/Sandbox.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import ch.akuhn.hapax.util.CharStream; 4 | 5 | public class Sandbox { 6 | 7 | public static void main(String[] args) { 8 | CharStream in = CharStream.fromString("abc"); 9 | System.out.println(in.next()); 10 | System.out.println(in.next()); 11 | System.out.println(in.next()); 12 | System.out.println(in.next()); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/hapax/test/InputStreamScannerTest.java: -------------------------------------------------------------------------------- 1 | package hapax.test; 2 | 3 | import java.io.ByteArrayInputStream; 4 | 5 | import ch.akuhn.hapax.corpus.TermScanner; 6 | 7 | public class InputStreamScannerTest extends CamelCaseScannerTest { 8 | 9 | @Override 10 | protected TermScanner scannerOn(String string) { 11 | return scanner.onStream(new ByteArrayInputStream(string.getBytes())); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/hapax/test/StopwordsTest.java: -------------------------------------------------------------------------------- 1 | package hapax.test; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | 8 | import ch.akuhn.hapax.corpus.Stopwords; 9 | import ch.unibe.jexample.JExample; 10 | 11 | 12 | @RunWith(JExample.class) 13 | public class StopwordsTest { 14 | 15 | @Test 16 | public void stopWords() { 17 | Stopwords basicEnglish = Stopwords.BASIC_ENGLISH; 18 | assertTrue(basicEnglish.contains("a")); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch.akuhn.hapax/test/hapax/test/SymetricMatrixTest.java: -------------------------------------------------------------------------------- 1 | package hapax.test; 2 | 3 | import static java.lang.Math.PI; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import org.junit.Test; 7 | 8 | import ch.akuhn.hapax.linalg.Matrix; 9 | import ch.akuhn.hapax.linalg.SymetricMatrix; 10 | 11 | public class SymetricMatrixTest { 12 | 13 | @Test 14 | public void testPutGetIsSymetric() { 15 | Matrix m = new SymetricMatrix(5); 16 | m.put(4, 2, PI); 17 | assertEquals(PI, m.get(4, 2), Double.MIN_VALUE); 18 | assertEquals(PI, m.get(2, 4), Double.MIN_VALUE); 19 | m.put(3, 3, PI); 20 | assertEquals(PI, m.get(3, 3), Double.MIN_VALUE); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ch.akuhn.matrix 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.codemap.HapaxBuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | 22 | 23 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sun Jul 19 21:25:54 CEST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: ch.akuhn.mds 4 | Bundle-SymbolicName: ch.akuhn.matrix 5 | Bundle-Version: 0.7.894.qualifier 6 | Require-Bundle: org.eclipse.swt;bundle-version="3.5.0", 7 | ch.akuhn.util;bundle-version="2.1.277", 8 | ch.akuhn.hapax;bundle-version="0.7.264" 9 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 10 | Export-Package: ch.akuhn.isomap, 11 | ch.akuhn.mds, 12 | ch.akuhn.org.ggobi.plugins.ggvis 13 | Bundle-Vendor: Adrian Kuhn 14 | Bundle-ClassPath: lib/arpack-combo-0.1.jar, 15 | lib/mtj-0.9.12.jar, 16 | lib/netlib-java-0.9.1.jar, 17 | . 18 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | lib/arpack-combo-0.1.jar,\ 5 | lib/mtj-0.9.12.jar,\ 6 | lib/netlib-java-0.9.1.jar 7 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/data/swiss_roll_data.matlab5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/data/swiss_roll_data.matlab5 -------------------------------------------------------------------------------- /ch.akuhn.matrix/ggobi.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/ggobi.zip -------------------------------------------------------------------------------- /ch.akuhn.matrix/lib/arpack-combo-0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/lib/arpack-combo-0.1.jar -------------------------------------------------------------------------------- /ch.akuhn.matrix/lib/matrix.txt: -------------------------------------------------------------------------------- 1 | 12 9 2 | 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 3 | 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 4 | 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 5 | 0.0 1.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0 6 | 0.0 1.0 1.0 2.0 0.0 0.0 0.0 0.0 0.0 7 | 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 8 | 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 9 | 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 10 | 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 11 | 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0 0.0 12 | 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0 13 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 14 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/lib/mtj-0.9.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/lib/mtj-0.9.12.jar -------------------------------------------------------------------------------- /ch.akuhn.matrix/lib/netlib-java-0.9.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/lib/netlib-java-0.9.1.jar -------------------------------------------------------------------------------- /ch.akuhn.matrix/lib/svdlibc.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/ch.akuhn.matrix/lib/svdlibc.zip -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/edu/mit/tedlab/DMat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ch.akuhn.edu.mit.tedlab; 5 | 6 | public class DMat { 7 | public int rows; 8 | public int cols; 9 | public double[][] value; /* 10 | * Accessed by [row][col]. Free value[0] and value to 11 | * free. 12 | */ 13 | 14 | public DMat(int rows, int cols) { 15 | this.rows = rows; 16 | this.cols = cols; 17 | this.value = new double[rows][cols]; 18 | } 19 | } -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/edu/mit/tedlab/SMat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ch.akuhn.edu.mit.tedlab; 5 | 6 | public class SMat { 7 | 8 | public int rows; 9 | public int cols; 10 | public int vals; /* Total non-zero entries. */ 11 | public int[] pointr; /* For each col (plus 1), index of first non-zero entry. */ 12 | public int[] rowind; /* For each nz entry, the row index. */ 13 | public double[] value; /* For each nz entry, the value. */ 14 | 15 | public SMat(int rows, int cols, int vals) { 16 | this.rows = rows; 17 | this.cols = cols; 18 | this.vals = vals; 19 | this.pointr = new int[cols + 1]; 20 | this.rowind = new int[vals]; 21 | this.value = new double[vals]; 22 | } 23 | } -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/edu/mit/tedlab/SVDRec.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package ch.akuhn.edu.mit.tedlab; 5 | 6 | public class SVDRec { 7 | public int d; /* Dimensionality (rank) */ 8 | public DMat Ut; /* 9 | * Transpose of left singular vectors. (d by m) The vectors are 10 | * the rows of Ut. 11 | */ 12 | public double[] S; /* Array of singular values. (length d) */ 13 | public DMat Vt; /* 14 | * Transpose of right singular vectors. (d by n) The vectors are 15 | * the rows of Vt. 16 | */ 17 | 18 | public SVDRec() { 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/Each.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | 4 | public class Each { 5 | 6 | public int index; 7 | public E value; 8 | public E yield; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/EachAs.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachAs { 4 | 5 | public int index; 6 | public E value; 7 | public R yield; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/EachB.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachB { 4 | 5 | public E value; 6 | public boolean yield; 7 | public int index; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/EachXY.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachXY { 4 | 5 | public final int width; 6 | public final int height; 7 | public int x = 0; 8 | public int y = 0; 9 | 10 | public EachXY(int width, int height) { 11 | this.width = width; 12 | this.height = height; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/State.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | /*default*/ enum State { 4 | 5 | NULL, FIRST, EACH, DONE, BROKEN, VOID, YIELD; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/foreach/Times.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class Times { 4 | 5 | public static Iterable repeat(int times) { 6 | return For.range(times); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph/DijkstrasAlgorithm.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph; 2 | 3 | import java.util.Arrays; 4 | 5 | public class DijkstrasAlgorithm { 6 | 7 | public static int[] apply(Graph g, int source) { 8 | int[] dist = new int[g.nodes.length]; 9 | boolean[] done = new boolean[g.nodes.length]; 10 | Node[] todo = new Node[g.nodes.length]; 11 | Arrays.fill(dist, Integer.MAX_VALUE); 12 | int index = 0; 13 | todo[index++] = g.nodes[source]; 14 | done[source] = true; 15 | dist[source] = 0; 16 | for (int n = 0; n < todo.length; n++) { 17 | Node node = todo[n]; 18 | if (node == null) break; 19 | int d = dist[node.index] + 1; 20 | for (Node each: node.edges) { 21 | if (done[each.index]) continue; 22 | todo[index++] = each; 23 | dist[each.index] = d; 24 | done[each.index] = true; 25 | } 26 | } 27 | return dist; 28 | } 29 | 30 | public static int[][] apply(Graph g) { 31 | int[][] dist = new int[g.nodes.length][]; 32 | for (int i = 0; i < dist.length; i++) dist[i] = apply(g, i); 33 | return dist; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph/FloydWarshallAlgorithm.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph; 2 | 3 | import ch.akuhn.matrix.DenseMatrix; 4 | import ch.akuhn.matrix.Matrix; 5 | 6 | /** Computes shortest path between all pairs in O(n3) time. 7 | * Used for integration test of Dijasktra's algorithm. 8 | *

9 | * @author Adrian Kuhn 10 | * 11 | */ 12 | public class FloydWarshallAlgorithm { 13 | 14 | public static void apply(int[][] path) { 15 | for (int k = 0; k < path.length; k++) { 16 | for (int i = 0; i < path.length; i++) { 17 | int path_i_k = path[i][k]; 18 | for (int j = 0; j < path.length; j++) { 19 | path[i][j] = Math.min(path[i][j], path_i_k + path[k][j]); 20 | } 21 | } 22 | } 23 | } 24 | 25 | public static Matrix apply(double[][] path) { 26 | for (int k = 0; k < path.length; k++) { 27 | for (int i = 0; i < path.length; i++) { 28 | double path_i_k = path[i][k]; 29 | for (int j = 0; j < path.length; j++) { 30 | path[i][j] = Math.min(path[i][j], path_i_k + path[k][j]); 31 | } 32 | } 33 | } 34 | return new DenseMatrix(path); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph/Node.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph; 2 | 3 | /** Node in an unweighted, undirected graph. 4 | * 5 | */ 6 | public class Node { 7 | 8 | 9 | final int index; 10 | public Node[] edges; 11 | 12 | public Node(int index) { 13 | this.index = index; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "#"+index; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph2/Edge.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Scanner; 6 | 7 | import org.junit.Test; 8 | 9 | public class Edge implements Comparable { 10 | 11 | public static Edge[] parse(String s) { 12 | Scanner in = new Scanner(s); 13 | in.nextInt(); // unused 14 | int M = in.nextInt(); 15 | Edge[] edges = new Edge[M]; 16 | for (int m = 0; m < M; m++) { 17 | int a = in.nextInt() - 1; 18 | int b = in.nextInt() - 1; 19 | int c = in.nextInt(); 20 | edges[m] = new Edge(a, b, c); 21 | } 22 | return edges; 23 | } 24 | int a, b; 25 | 26 | int cost; 27 | 28 | public Edge(int a, int b, int cost) { 29 | super(); 30 | this.a = a; 31 | this.b = b; 32 | this.cost = cost; 33 | } 34 | 35 | @Override 36 | public int compareTo(Edge that) { 37 | return this.cost - that.cost; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return String.format("cost(%d,%d) = %d", a, b, cost); 43 | } 44 | 45 | public static class Examples { 46 | 47 | @Test 48 | public void shouldParseFromString() { 49 | String s = "6 7\n1 2 20\n1 3 5\n1 4 10\n2 3 8\n2 4 15\n3 4 2\n5 6 9"; 50 | Edge[] edges = Edge.parse(s); 51 | assertEquals(7, edges.length); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph2/FloydWarshallAlgorithm.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class FloydWarshallAlgorithm { 8 | 9 | public int[][] apply(Graph g) { 10 | int N = g.size(); 11 | int[][] dist = g.clone().cost; 12 | for (int k = 0; k < N; k++) { 13 | for (int i = 0; i < N; i++) { 14 | if (dist[i][k] == Graph.NIL) continue; 15 | for (int j = 0; j < N; j++) { 16 | if (dist[k][j] == Graph.NIL) continue; 17 | dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]); 18 | } 19 | } 20 | } 21 | return dist; 22 | } 23 | 24 | public static class Examples { 25 | 26 | @Test 27 | public void shouldFindAllShortestPaths() { 28 | String s = "6 7\n1 2 20\n1 3 5\n1 4 10\n2 3 8\n2 4 15\n3 4 2\n5 6 9"; 29 | Graph g = Graph.parse(s); 30 | int[][] dist = new FloydWarshallAlgorithm().apply(g); 31 | assertEquals(6, dist.length); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph2/Graph.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Arrays; 6 | import java.util.Scanner; 7 | 8 | import org.junit.Test; 9 | 10 | public class Graph { 11 | 12 | public static final int NIL = Integer.MAX_VALUE; 13 | 14 | public static Graph parse(String s) { 15 | Scanner in = new Scanner(s); 16 | int N = in.nextInt(); 17 | int M = in.nextInt(); 18 | Graph g = new Graph(N); 19 | for (int m = 0; m < M; m++) { 20 | int a = in.nextInt() - 1; 21 | int b = in.nextInt() - 1; 22 | int c = in.nextInt(); 23 | g.cost[a][b] = c; 24 | g.cost[b][a] = c; 25 | } 26 | return g; 27 | } 28 | 29 | final int[][] cost; 30 | 31 | public Graph(int size) { 32 | cost = new int[size][size]; 33 | for (int[] each: cost) { 34 | Arrays.fill(each, NIL); 35 | } 36 | } 37 | 38 | public Graph clone() { 39 | Graph g = new Graph(this.size()); 40 | for (int n = 0; n < cost.length; n++) { 41 | g.cost[n] = Arrays.copyOf(cost[n], cost[n].length); 42 | } 43 | return g; 44 | } 45 | 46 | public int size() { 47 | return cost.length; 48 | } 49 | 50 | public static class Examples { 51 | 52 | @Test 53 | public void shouldParseString() { 54 | String s = "6 7\n1 2 20\n1 3 5\n1 4 10\n2 3 8\n2 4 15\n3 4 2\n5 6 9"; 55 | Graph g = Graph.parse(s); 56 | assertEquals(6, g.size()); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph2/KruskalsAlgorithm.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import org.junit.Test; 11 | 12 | public class KruskalsAlgorithm { 13 | 14 | public Edge[] apply(Edge[] edges) { 15 | Arrays.sort(edges); 16 | List mst = new ArrayList(); 17 | MergeFind forest = new MergeFind(edges.length); 18 | for (Edge each: edges) { 19 | int a = forest.find(each.a); 20 | int b = forest.find(each.b); 21 | if (a != b) { 22 | forest.merge(a, b); 23 | mst.add(each); 24 | } 25 | } 26 | return mst.toArray(new Edge[mst.size()]); 27 | } 28 | 29 | public static class Examples { 30 | 31 | @Test 32 | public void shouldFindMinimalSpanningTree() { 33 | String s = "6 7\n1 2 20\n1 3 5\n1 4 10\n2 3 8\n2 4 15\n3 4 2\n5 6 9"; 34 | Edge[] edges = Edge.parse(s); 35 | Edge[] mst = new KruskalsAlgorithm().apply(edges); 36 | String out = Arrays.asList(mst).toString(); 37 | assertEquals(4, mst.length); 38 | assertTrue(out.contains("(2,3)")); 39 | assertTrue(out.contains("(0,2)")); 40 | assertTrue(out.contains("(1,2)")); 41 | assertTrue(out.contains("(4,5)")); 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/graph2/Node.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.graph2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Arrays; 6 | import java.util.Scanner; 7 | 8 | import org.junit.Test; 9 | 10 | public class Node { 11 | 12 | public static int NIL = Integer.MAX_VALUE; 13 | 14 | public static Node[] parse(String s) { 15 | Scanner in = new Scanner(s); 16 | int N = in.nextInt(); 17 | int M = in.nextInt(); 18 | Node[] nodes = new Node[N]; 19 | for (int n = 0; n < N; n++) { 20 | nodes[n] = new Node(n, N); 21 | } 22 | for (int m = 0; m < M; m++) { 23 | int a = in.nextInt() - 1; 24 | int b = in.nextInt() - 1; 25 | int c = in.nextInt(); 26 | nodes[a].cost[b] = c; 27 | nodes[b].cost[a] = c; 28 | } 29 | return nodes; 30 | } 31 | int n; 32 | 33 | int[] cost; 34 | 35 | public Node(int n, int size) { 36 | this.n = n; 37 | this.cost = new int[size]; 38 | Arrays.fill(cost, NIL); 39 | } 40 | 41 | public static class Examples { 42 | 43 | @Test 44 | public void shouldParseFromString() { 45 | String s = "6 7\n1 2 20\n1 3 5\n1 4 10\n2 3 8\n2 4 15\n3 4 2\n5 6 9"; 46 | Node[] nodes = Node.parse(s); 47 | assertEquals(6, nodes.length); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/matrix/eigenvalues/Eigenvalues.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.matrix.eigenvalues; 2 | 3 | import ch.akuhn.matrix.Matrix; 4 | import ch.akuhn.matrix.Vector; 5 | 6 | public class Eigenvalues { 7 | 8 | public double[] value; 9 | public Vector[] vector; 10 | 11 | protected int n; 12 | protected int nev; 13 | 14 | public Eigenvalues(int n) { 15 | this.n = n; 16 | this.nev = n; 17 | } 18 | 19 | public static Eigenvalues of(Matrix A) { 20 | if (A.columnCount() == 0) { 21 | Eigenvalues eigen = new Eigenvalues(0); 22 | eigen.value = new double[0]; 23 | eigen.vector = new Vector[0]; 24 | return eigen; 25 | } 26 | if (A.columnCount() == 1) { 27 | Eigenvalues eigen = new Eigenvalues(0); 28 | eigen.value = new double[] { A.get(0, 0) }; 29 | eigen.vector = new Vector[] { Vector.from(1.0) }; 30 | return eigen; 31 | } 32 | if (A.columnCount() < 10) return new AllEigenvalues(A); 33 | return FewEigenvalues.of(A); 34 | } 35 | 36 | public Eigenvalues largest(int nev) { 37 | this.nev = nev; 38 | return this; 39 | } 40 | 41 | public Eigenvalues run() { 42 | return this; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/org/ggobi/plugins/ggvis/Main.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.org.ggobi.plugins.ggvis; 2 | 3 | import java.io.IOException; 4 | 5 | import ch.akuhn.hapax.Hapax; 6 | import ch.akuhn.mds.MultidimensionalScaling; 7 | 8 | public class Main { 9 | 10 | private transient static boolean VIZ = true; 11 | 12 | public static void main(String[] args) throws IOException { 13 | 14 | Hapax hapax = Hapax.newCorpus() 15 | .useTFIDF() 16 | .useCamelCaseScanner() 17 | .addFiles("..", ".java") 18 | .build(); 19 | 20 | System.out.println(hapax.getIndex()); 21 | 22 | Viz viz = VIZ ? new Viz().open() : null; 23 | new MultidimensionalScaling() 24 | .similarities(hapax.getIndex().documentCorrelation().asArray()) 25 | .verbose() 26 | .listener(viz) 27 | .iterations(Integer.MAX_VALUE) 28 | .run(); 29 | 30 | 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/All.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | 4 | /** 5 | * A utility class to realize universally quantified checks of an entire 6 | * collection. 7 | * 8 | * @author Adrian Kuhn 9 | * @author Yossi Gil, 21/06/2008 10 | * 11 | */ 12 | public class All { 13 | 14 | public static boolean notNull(Iterable iter) { 15 | assert iter != null; 16 | for (T t: iter) if (t == null) return false; 17 | return true; 18 | } 19 | 20 | public static boolean notNull(Object... values) { 21 | assert values != null; 22 | for (Object each: values) if (each == null) return false; 23 | return true; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Arrays.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | 4 | public abstract class Arrays { 5 | 6 | public static E[] append(E[] array, E element) { 7 | E[] result = java.util.Arrays.copyOf(array, array.length + 1); 8 | result[array.length] = element; 9 | return result; 10 | } 11 | 12 | public static java.util.List asList(E... a) { 13 | return java.util.Arrays.asList(a); 14 | } 15 | 16 | public static int indexOf(Object[] array, Object element) { 17 | for (int n = 0; n < array.length; n++) { 18 | if (array[n] == element) return n; 19 | } 20 | return -1; 21 | } 22 | 23 | public static int[] copyOf(int[] original, int newLength) { 24 | return java.util.Arrays.copyOf(original, newLength); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Assert.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Assert { 4 | 5 | // TODO moar methods to check range of numebrs 6 | 7 | public static final T notNull(T t) { 8 | if (t == null) throw new AssertionError(); 9 | return t; 10 | } 11 | 12 | public static final void notNull(Object object, Object... more) { 13 | if (object == null) throw new AssertionError(); 14 | for (Object each: more) if (each == null) throw new AssertionError(); 15 | } 16 | 17 | public static final String notEmpty(String string) { 18 | assert string != null && string.length() > 0; 19 | return string; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Cycle.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Iterator; 4 | 5 | public class Cycle { 6 | 7 | /** 8 | * Iterate indefinitely over iterable. 9 | * 10 | */ 11 | public static final Iterable forever(final Iterable iterable) { 12 | return new Iterable() { 13 | public Iterator iterator() { 14 | return new Iterator() { 15 | private Iterator it = iterable.iterator(); 16 | 17 | public boolean hasNext() { 18 | if (!it.hasNext()) it = iterable.iterator(); 19 | return it.hasNext(); 20 | } 21 | 22 | public E next() { 23 | if (!it.hasNext()) it = iterable.iterator(); 24 | return it.next(); 25 | } 26 | 27 | public void remove() { 28 | it.remove(); 29 | } 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Defaults.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Replaces a null value with some default. Writing 5 | * String guess = Defaults.to(answer,"A") will assign the String 6 | * "A" to variable guess in the case that answer is null. If however, answer is 7 | * not null then guess's value will be that of answer. 8 | * 9 | * @author Yossi Gil, 2008/06/20 10 | */ 11 | public final class Defaults { 12 | 13 | public static int to(final Integer v, final int defaultValue) { 14 | return v != null ? v.intValue() : defaultValue; 15 | } 16 | 17 | public static T to(final T v, final T defaultValue) { 18 | return v != null ? v : defaultValue; 19 | } 20 | 21 | private Defaults() { 22 | throw new RuntimeException("Cannot instantiate."); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Is.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Is { 4 | 5 | public static boolean equal(Object a, Object b) { 6 | return a == null ? b == null : a.equals(b); 7 | } 8 | 9 | /** 10 | * Checks if iterable has no elements. 11 | */ 12 | public static final boolean empty(final Iterable iterable) { 13 | return !iterable.iterator().hasNext(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/IterableIterator.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Iterator; 5 | 6 | public interface IterableIterator extends Iterable, Iterator, Enumeration { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/IterableIteratorFactory.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Iterator; 4 | 5 | public class IterableIteratorFactory { 6 | 7 | private final static class Iter implements IterableIterator { 8 | 9 | private Iterator iterator; 10 | 11 | public Iter(final Iterator iterator) { 12 | this.iterator = iterator; 13 | } 14 | 15 | public boolean hasMoreElements() { 16 | return iterator.hasNext(); 17 | } 18 | 19 | public boolean hasNext() { 20 | return iterator.hasNext(); 21 | } 22 | 23 | public Iterator iterator() { 24 | return iterator; 25 | } 26 | 27 | public E next() { 28 | return iterator.next(); 29 | } 30 | 31 | public E nextElement() { 32 | return iterator.next(); 33 | } 34 | 35 | public void remove() { 36 | iterator.remove(); 37 | } 38 | 39 | } 40 | 41 | public final static IterableIterator create(final Iterator iterator) { 42 | return new Iter(iterator); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Out.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Out { 4 | 5 | private static final PrintOn out = new PrintOn(System.out); 6 | 7 | private Out() { 8 | // cannot instantiate 9 | } 10 | 11 | public static final PrintOn puts(Object object) { 12 | out.print(object).cr(); 13 | return out; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Separator.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Separates elements of a collection while printing. Does not require special 5 | * case treatment of first or last element. For example, the following program 6 | * prints a list of its arguments separated by commas, without using any 7 | * conditionals. 8 | * 9 | *

10 |  * Separator s = new Separator(", ");
11 |  * or (String a : args) {
12 |  *    System.out.println(s + a);
13 |  * 
14 |  * 
15 | * 16 | * The implementation of class Separator is straight forward. It 17 | * wraps a string that is returned on every call of toString() except for the 18 | * first call, which returns an empty string. 19 | * 20 | * @author Yossi Gil 21 | * 22 | */ 23 | public class Separator { 24 | 25 | private boolean omitNext; 26 | private final String value; 27 | 28 | public Separator() { 29 | this(", "); 30 | } 31 | 32 | public Separator(String value) { 33 | this.value = value; 34 | this.omitNext = true; 35 | } 36 | 37 | public void reset() { 38 | omitNext = true; 39 | } 40 | 41 | public String toString() { 42 | String $ = omitNext ? "" : value; 43 | omitNext = false; 44 | return $; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Size.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Collection; 4 | import java.util.Enumeration; 5 | import java.util.Iterator; 6 | 7 | /** Returns the size of iterables, useful for testing. 8 | * 9 | * @author Adrian Kuhn 10 | * 11 | */ 12 | public class Size { 13 | 14 | @SuppressWarnings("unchecked") 15 | public static final int of(Iterable collection) { 16 | if (collection instanceof Collection) return ((Collection) collection).size(); 17 | int count = 0; 18 | for (@SuppressWarnings("unused") T each: collection) count++; 19 | return count; 20 | } 21 | 22 | public static final int of(Iterator iterator) { 23 | int count = 0; 24 | while (iterator.hasNext()) count++; 25 | return count; 26 | } 27 | 28 | public static final int of(Enumeration enumeration) { 29 | int count = 0; 30 | while (enumeration.hasMoreElements()) count++; 31 | return count; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Stopwatch.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.io.IOException; 4 | 5 | public class Stopwatch { 6 | 7 | private int n = 0; 8 | private long time = Long.MAX_VALUE; 9 | private long collect = 0; 10 | 11 | public void print(String message) { 12 | privatePrint((time - (time = System.nanoTime())) * -1, message); 13 | } 14 | 15 | private void privatePrint(long nanos, String message) { 16 | System.out.print("\t("+n+")"); 17 | if (nanos > 0) System.out.print(" "+(1e-9)*nanos); 18 | if (message != null) System.out.print(" " + message); 19 | System.out.println(); 20 | } 21 | 22 | private static Stopwatch SINGELTON = new Stopwatch(); 23 | 24 | public static void p(String message) { 25 | SINGELTON.print(message); 26 | } 27 | 28 | public static void p() { 29 | SINGELTON.print(null); 30 | } 31 | 32 | public void on() { 33 | time = System.nanoTime(); 34 | } 35 | 36 | public T off(T t) { 37 | collect += (System.nanoTime() - time); 38 | time = 0; 39 | return t; 40 | } 41 | 42 | public void total(String message) { 43 | privatePrint(collect, message); 44 | collect = 0; 45 | } 46 | 47 | public static void enter() { 48 | try { 49 | System.out.print("Press enter: "); 50 | System.in.read(); 51 | } catch (IOException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Tab.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Indents lines while printing them. 5 | * 6 | * @author Adrian Kuhn, 2008/07/21 7 | * @author Thanks to Yossi Gil for suggesting better class and method names. 8 | */ 9 | 10 | public class Tab { 11 | 12 | private String s; 13 | private final String tab; 14 | 15 | public Tab() { 16 | this("\t"); 17 | } 18 | 19 | public Tab(String tab) { 20 | this.tab = tab; 21 | this.s = ""; 22 | } 23 | 24 | public String begin() { 25 | try { 26 | return toString(); 27 | } finally { 28 | this.more(); 29 | } 30 | } 31 | 32 | public String end() { 33 | return this.less().toString(); 34 | } 35 | 36 | public boolean isEmpty() { 37 | return s.length() == 0; 38 | } 39 | 40 | public Tab less() { 41 | if (isEmpty()) throw new IllegalStateException(); 42 | s = s.substring(0, s.length() - tab.length()); 43 | return this; 44 | } 45 | 46 | public Tab more() { 47 | s += tab; 48 | return this; 49 | } 50 | 51 | public String toString() { 52 | return s; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/src/ch/akuhn/util/Throw.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Throws checked exceptions without the hassle of having to declare them. 5 | * 6 | * @see http://blog.uncommons.org/2008/08/26/more-stupid-java-tricks/ 7 | * 8 | */ 9 | public class Throw { 10 | 11 | @SuppressWarnings("deprecation") 12 | public static RuntimeException exception(Throwable cause) { 13 | if (cause instanceof RuntimeException) throw (RuntimeException) cause; 14 | if (cause instanceof Error) throw (Error) cause; 15 | Thread.currentThread().stop(cause); 16 | throw runtimeException(cause); 17 | } 18 | 19 | public static RuntimeException runtimeException(Throwable cause) { 20 | if (cause instanceof RuntimeException) throw (RuntimeException) cause; 21 | if (cause instanceof Error) throw (Error) cause; 22 | throw new RuntimeException(cause); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/edu/mit/tedlab/Dat3.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.edu.mit.tedlab; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | 6 | 7 | 8 | public class Dat3 { 9 | 10 | public static void main(String... args) throws FileNotFoundException { 11 | Svdlib svdlib = new Svdlib(); 12 | SMat A = Svdlib.svdLoadSparseTextHBFile(new File("lib/dat3.txt")); 13 | int dimensions = Math.min(A.cols, A.rows); 14 | int iterations = 100; 15 | double[] end = new double[] { -1e-30, 1e-30 }; 16 | double kappa = 1e-6; 17 | long time = System.currentTimeMillis(); 18 | SVDRec R = svdlib.svdLAS2(A, dimensions, iterations, end, kappa); 19 | System.out.println("-----------" + (System.currentTimeMillis() - time)); 20 | for (int n = 0; n < R.d; n++) { 21 | System.out.println(R.S[n]); 22 | } 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/edu/mit/tedlab/RegressionTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.edu.mit.tedlab; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.File; 6 | import java.io.FileNotFoundException; 7 | 8 | import org.junit.Test; 9 | 10 | public class RegressionTest { 11 | 12 | private static final double KAPPA = 1e-6; 13 | private static final double[] END = new double[] { 1e-30, 1e30 } ; 14 | 15 | @Test 16 | public void dat1() throws FileNotFoundException { 17 | test("lib/dat1.txt"); 18 | } 19 | 20 | @Test 21 | public void dat2() throws FileNotFoundException { 22 | test("lib/dat2.txt"); 23 | } 24 | 25 | @Test 26 | public void dat3() throws FileNotFoundException { 27 | test("lib/dat3.txt"); 28 | } 29 | 30 | private void test(String name) throws FileNotFoundException { 31 | Revision39.SMat s39 = new Revision39().svdLoadSparseTextHBFile(new File(name)); 32 | Revision39.SVDRec r39 = new Revision39().svdLAS2(s39, 20, 0, END, KAPPA); 33 | SMat s = Svdlib.svdLoadSparseTextHBFile(new File(name)); 34 | SVDRec r = new Svdlib().svdLAS2(s, 20, 0, END, KAPPA); 35 | assertEquals(20, r39.S.length); 36 | assertEquals(20, r.S.length); 37 | for (int n = 0; n < 20; n++) { 38 | assertEquals(r39.S[n], r.S[n], KAPPA); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/edu/mit/tedlab/SmallMatricesTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.edu.mit.tedlab; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class SmallMatricesTest { 8 | 9 | @Test 10 | public void emptyMatrix() { 11 | DMat d = new DMat(0,0); 12 | SMat s = Svdlib.svdConvertDtoS(d); 13 | SVDRec rec = new Svdlib().svdLAS2A(s, 20); 14 | assertEquals(0, rec.Ut.value.length); 15 | assertEquals(0, rec.Vt.value.length); 16 | assertEquals(0, rec.S.length); 17 | } 18 | 19 | @Test 20 | public void oneOnOneMatrix() { 21 | DMat d = new DMat(1,1); 22 | SMat s = Svdlib.svdConvertDtoS(d); 23 | SVDRec rec = new Svdlib().svdLAS2A(s, 20); 24 | assertEquals(1, rec.Ut.value.length); 25 | assertEquals(1, rec.Vt.value.length); 26 | assertEquals(1, rec.S.length); 27 | } 28 | 29 | @Test 30 | public void ThreeOnThreeMatrix() { 31 | DMat d = new DMat(3,3); 32 | SMat s = Svdlib.svdConvertDtoS(d); 33 | SVDRec rec = new Svdlib().svdLAS2A(s, 20); 34 | assertEquals(3, rec.Ut.value.length); 35 | assertEquals(3, rec.Vt.value.length); 36 | assertEquals(3, rec.S.length); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/isomap/IsomapTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.isomap; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import ch.akuhn.org.ggobi.plugins.ggvis.Points; 8 | 9 | public class IsomapTest { 10 | 11 | private static class NullIsomap extends Isomap { 12 | 13 | public NullIsomap(int size) { 14 | super(size); 15 | assert size <= 1; 16 | } 17 | 18 | @Override 19 | protected double dist(int i, int j) { 20 | throw new AssertionError("should not be called"); 21 | } 22 | 23 | } 24 | 25 | @Test 26 | public void testIsomapSizeZero() { 27 | Isomap isomap = new NullIsomap(0); 28 | isomap.run(); 29 | Points points = isomap.getPoints(); 30 | assertEquals(0, points.size()); 31 | } 32 | 33 | @Test 34 | public void testIsomapSizeOne() { 35 | Isomap isomap = new NullIsomap(1); 36 | isomap.run(); 37 | Points points = isomap.getPoints(); 38 | assertEquals(1, points.size()); 39 | assertEquals(0, points.x[0], Double.MIN_VALUE); 40 | assertEquals(0, points.y[0], Double.MIN_VALUE); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/isomap/SwissRoll.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.isomap; 2 | 3 | import ch.akuhn.matrix.DenseMatrix; 4 | import ch.akuhn.matrix.Matrix; 5 | 6 | public class SwissRoll { 7 | 8 | public double[] x, y, z; 9 | 10 | public SwissRoll(int n) { 11 | x = new double[n]; 12 | y = new double[n]; 13 | z = new double[n]; 14 | for (int i = 0; i < n; i++) { 15 | double len = Math.PI * (Math.random() * 3 + 1); 16 | x[i] = Math.cos(len) * (1 + len / 4); 17 | y[i] = Math.sin(len) * (1 + len / 4); 18 | z[i] = Math.random() * 4 - 2; 19 | } 20 | } 21 | 22 | public Matrix asDistanceMatrix() { 23 | double[][] dist = new double[x.length][x.length]; 24 | for (int i = 0; i < x.length; i++) { 25 | for (int j = 0; j < x.length; j++) { 26 | dist[i][j] = dist(i,j); 27 | } 28 | } 29 | return new DenseMatrix(dist); 30 | } 31 | 32 | public double dist(int i, int j) { 33 | return Math.sqrt( 34 | (x[i] - x[j]) * (x[i] - x[j]) + 35 | (y[i] - y[j]) * (y[i] - y[j]) + 36 | (z[i] - z[j]) * (z[i] - z[j])); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/matrix/SymetricMatrixTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.matrix; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class SymetricMatrixTest { 8 | 9 | @Test 10 | public void shouldMultiplyMatrixWithVector() { 11 | Matrix m = SymmetricMatrix.fromJagged(new double[][] {{0},{1,0},{2,3,0},{4,5,6,0}}); 12 | Vector v = Vector.from(10, 20, 30, 40); 13 | Vector w = m.mult(v); 14 | assertEquals(0*10+1*20+2*30+4*40, w.get(0), Double.MIN_VALUE); 15 | assertEquals(1*10+0*20+3*30+5*40, w.get(1), Double.MIN_VALUE); 16 | assertEquals(2*10+3*20+0*30+6*40, w.get(2), Double.MIN_VALUE); 17 | assertEquals(4*10+5*20+6*30+0*40, w.get(3), Double.MIN_VALUE); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/matrix/eigenvalues/AllEigenvaluesTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.matrix.eigenvalues; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import ch.akuhn.matrix.Matrix; 8 | 9 | public class AllEigenvaluesTest { 10 | 11 | private static final double epsilon = 1e-9; 12 | 13 | @Test 14 | public void shouldFindEigenvalues() { 15 | Matrix A = Matrix.from(3, 3, 16 | 0, 1, -1, 17 | 1, 1, 0, 18 | -1, 0, 1); 19 | Eigenvalues eigen = new AllEigenvalues(A).run(); 20 | 21 | assertEquals(-1, eigen.value[0], epsilon); 22 | assertEquals(1, eigen.value[1], epsilon); 23 | assertEquals(2, eigen.value[2], epsilon); 24 | 25 | assert A.mult(eigen.vector[0]).equals(eigen.vector[0].times(eigen.value[0]), epsilon); 26 | assert A.mult(eigen.vector[1]).equals(eigen.vector[1].times(eigen.value[1]), epsilon); 27 | assert A.mult(eigen.vector[2]).equals(eigen.vector[2].times(eigen.value[2]), epsilon); 28 | } 29 | 30 | @Test 31 | public void shouldReturnLargest() { 32 | Matrix A = Matrix.dense(10, 10); 33 | for (int n = 0; n < 10; n++) A.put(n, n, n); 34 | Eigenvalues eigen = new AllEigenvalues(A).largest(3).run(); 35 | assertEquals(3, eigen.value.length); 36 | assertEquals(7, eigen.value[0], epsilon); 37 | assertEquals(8, eigen.value[1], epsilon); 38 | assertEquals(9, eigen.value[2], epsilon); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/org/ggobi/plugins/ggvis/GGvisTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.org.ggobi.plugins.ggvis; 2 | 3 | public class GGvisTest { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/util/AssertionsEnabledTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1998-2008 Adrian Kuhn 2 | // 3 | // This file is part of ch.akuhn.util. 4 | // 5 | // ch.akuhn.util is free software: you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by the 7 | // Free Software Foundation, either version 3 of the License, or (at your 8 | // option) any later version. 9 | // 10 | // ch.akuhn.util is distributed in the hope that it will be useful, but 11 | // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with ch.akuhn.util. If not, see . 17 | // 18 | 19 | package ch.akuhn.util; 20 | 21 | import org.junit.Test; 22 | 23 | public class AssertionsEnabledTest { 24 | 25 | @Test(expected = AssertionError.class) 26 | public void assetionsEnabled() { 27 | assert false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/util/DefaultsTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.lang.reflect.Constructor; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | import org.junit.Test; 9 | 10 | public class DefaultsTest { 11 | 12 | @Test(expected = InvocationTargetException.class) 13 | public void cannotInstantiate() throws Exception { 14 | Constructor init = Defaults.class.getDeclaredConstructor(); 15 | init.setAccessible(true); 16 | init.newInstance(); 17 | } 18 | 19 | @Test 20 | public void testInteger() { 21 | Integer n = 23; 22 | assertEquals(23, Defaults.to(n, 42)); 23 | } 24 | 25 | @Test 26 | public void testNull() { 27 | String answer = null; 28 | assertEquals("A", Defaults.to(answer, "A")); 29 | } 30 | 31 | @Test 32 | public void testNullInteger() { 33 | Integer n = null; 34 | assertEquals(42, Defaults.to(n, 42)); 35 | } 36 | 37 | @Test 38 | public void testValue() { 39 | String answer = "B"; 40 | assertEquals("B", Defaults.to(answer, "A")); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ch.akuhn.matrix/test/ch/akuhn/util/SeparatorTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class SeparatorTest { 8 | 9 | @Test 10 | public void defaultValue() { 11 | Separator s = new Separator(); 12 | assertEquals("", s.toString()); 13 | assertEquals(", ", s.toString()); 14 | assertEquals(", ", s.toString()); 15 | assertEquals(", ", s.toString()); 16 | } 17 | 18 | @Test 19 | public void testReset() { 20 | Separator s = new Separator("abc"); 21 | assertEquals("", s.toString()); 22 | assertEquals("abc", s.toString()); 23 | assertEquals("abc", s.toString()); 24 | s.reset(); 25 | assertEquals("", s.toString()); 26 | assertEquals("abc", s.toString()); 27 | assertEquals("abc", s.toString()); 28 | } 29 | 30 | @Test 31 | public void testSequence() { 32 | Separator s = new Separator("abc"); 33 | assertEquals("", s.toString()); 34 | assertEquals("abc", s.toString()); 35 | assertEquals("abc", s.toString()); 36 | assertEquals("abc", s.toString()); 37 | assertEquals("abc", s.toString()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ch.akuhn.util/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ch.akuhn.util/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ch.akuhn.util 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /ch.akuhn.util/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Fri Dec 05 05:06:49 CET 2008 2 | cleanup_settings_version=2 3 | eclipse.preferences.version=1 4 | formatter_settings_version=11 5 | org.eclipse.jdt.ui.text.custom_code_templates= 6 | -------------------------------------------------------------------------------- /ch.akuhn.util/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Adrian Kuhn 2 | 3 | http://github.com/akuhn/ch.akuhn.util 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /ch.akuhn.util/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Adrian's utility classes 4 | Bundle-SymbolicName: ch.akuhn.util 5 | Bundle-Version: 2.1.277.qualifier 6 | Bundle-Vendor: Adrian Kuhn 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 8 | Bundle-ClassPath: . 9 | Export-Package: ch.akuhn.foreach, 10 | ch.akuhn.util, 11 | ch.akuhn.values 12 | -------------------------------------------------------------------------------- /ch.akuhn.util/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | . -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/Each.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | 4 | public class Each { 5 | 6 | public int index; 7 | public E value; 8 | public E yield; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/EachAs.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachAs { 4 | 5 | public int index; 6 | public E value; 7 | public R yield; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/EachB.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachB { 4 | 5 | public E value; 6 | public boolean yield; 7 | public int index; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/EachXY.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class EachXY { 4 | 5 | public final int width; 6 | public final int height; 7 | public int x = 0; 8 | public int y = 0; 9 | 10 | public EachXY(int width, int height) { 11 | this.width = width; 12 | this.height = height; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/State.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | /*default*/ enum State { 4 | 5 | NULL, FIRST, EACH, DONE, BROKEN, VOID, YIELD; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/foreach/Times.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.foreach; 2 | 3 | public class Times { 4 | 5 | public static Iterable repeat(int times) { 6 | return For.range(times); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/All.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | 4 | /** 5 | * A utility class to realize universally quantified checks of an entire 6 | * collection. 7 | * 8 | * @author Adrian Kuhn 9 | * @author Yossi Gil, 21/06/2008 10 | * 11 | */ 12 | public class All { 13 | 14 | public static boolean notNull(Iterable iter) { 15 | assert iter != null; 16 | for (T t: iter) if (t == null) return false; 17 | return true; 18 | } 19 | 20 | public static boolean notNull(Object... values) { 21 | assert values != null; 22 | for (Object each: values) if (each == null) return false; 23 | return true; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Arrays.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | 4 | public abstract class Arrays { 5 | 6 | public static E[] append(E[] array, E element) { 7 | E[] result = java.util.Arrays.copyOf(array, array.length + 1); 8 | result[array.length] = element; 9 | return result; 10 | } 11 | 12 | public static java.util.List asList(E... a) { 13 | return java.util.Arrays.asList(a); 14 | } 15 | 16 | public static int indexOf(Object[] array, Object element) { 17 | for (int n = 0; n < array.length; n++) { 18 | if (array[n] == element) return n; 19 | } 20 | return -1; 21 | } 22 | 23 | public static int[] copyOf(int[] original, int newLength) { 24 | return java.util.Arrays.copyOf(original, newLength); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Assert.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Assert { 4 | 5 | // TODO moar methods to check range of numebrs 6 | 7 | public static final T notNull(T t) { 8 | if (t == null) throw new AssertionError(); 9 | return t; 10 | } 11 | 12 | public static final void notNull(Object object, Object... more) { 13 | if (object == null) throw new AssertionError(); 14 | for (Object each: more) if (each == null) throw new AssertionError(); 15 | } 16 | 17 | public static final String notEmpty(String string) { 18 | assert string != null && string.length() > 0; 19 | return string; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Cycle.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Iterator; 4 | 5 | public class Cycle { 6 | 7 | /** 8 | * Iterate indefinitely over iterable. 9 | * 10 | */ 11 | public static final Iterable forever(final Iterable iterable) { 12 | return new Iterable() { 13 | public Iterator iterator() { 14 | return new Iterator() { 15 | private Iterator it = iterable.iterator(); 16 | 17 | public boolean hasNext() { 18 | if (!it.hasNext()) it = iterable.iterator(); 19 | return it.hasNext(); 20 | } 21 | 22 | public E next() { 23 | if (!it.hasNext()) it = iterable.iterator(); 24 | return it.next(); 25 | } 26 | 27 | public void remove() { 28 | it.remove(); 29 | } 30 | }; 31 | } 32 | }; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Defaults.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Replaces a null value with some default. Writing 5 | * String guess = Defaults.to(answer,"A") will assign the String 6 | * "A" to variable guess in the case that answer is null. If however, answer is 7 | * not null then guess's value will be that of answer. 8 | * 9 | * @author Yossi Gil, 2008/06/20 10 | */ 11 | public final class Defaults { 12 | 13 | public static int to(final Integer v, final int defaultValue) { 14 | return v != null ? v.intValue() : defaultValue; 15 | } 16 | 17 | public static T to(final T v, final T defaultValue) { 18 | return v != null ? v : defaultValue; 19 | } 20 | 21 | private Defaults() { 22 | throw new RuntimeException("Cannot instantiate."); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Extensions.java: -------------------------------------------------------------------------------- 1 | 2 | package ch.akuhn.util; 3 | 4 | 5 | /** 6 | * Methods for static import. 7 | * 8 | * @author Adrian Kuhn 9 | * 10 | */ 11 | @SuppressWarnings("unchecked") 12 | public abstract class Extensions { 13 | 14 | // private final static Object NONE = new Object(); 15 | 16 | public static Class leastUpperBound(Class initial, Object... os) { 17 | Class $ = initial; 18 | for (Object o : os) { 19 | while (!$.isAssignableFrom(o.getClass())) { 20 | $ = $.getSuperclass(); 21 | if ($ == null) return Object.class; 22 | } 23 | } 24 | return $; 25 | } 26 | 27 | private Extensions() { 28 | throw new AssertionError(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Is.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Is { 4 | 5 | public static boolean equal(Object a, Object b) { 6 | return a == null ? b == null : a.equals(b); 7 | } 8 | 9 | /** 10 | * Checks if iterable has no elements. 11 | */ 12 | public static final boolean empty(final Iterable iterable) { 13 | return !iterable.iterator().hasNext(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/IterableIterator.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Iterator; 5 | 6 | public interface IterableIterator extends Iterable, Iterator, Enumeration { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/IterableIteratorFactory.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Iterator; 4 | 5 | public class IterableIteratorFactory { 6 | 7 | private final static class Iter implements IterableIterator { 8 | 9 | private Iterator iterator; 10 | 11 | public Iter(final Iterator iterator) { 12 | this.iterator = iterator; 13 | } 14 | 15 | public boolean hasMoreElements() { 16 | return iterator.hasNext(); 17 | } 18 | 19 | public boolean hasNext() { 20 | return iterator.hasNext(); 21 | } 22 | 23 | public Iterator iterator() { 24 | return iterator; 25 | } 26 | 27 | public E next() { 28 | return iterator.next(); 29 | } 30 | 31 | public E nextElement() { 32 | return iterator.next(); 33 | } 34 | 35 | public void remove() { 36 | iterator.remove(); 37 | } 38 | 39 | } 40 | 41 | public final static IterableIterator create(final Iterator iterator) { 42 | return new Iter(iterator); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Out.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | public class Out { 4 | 5 | private static final PrintOn out = new PrintOn(System.out); 6 | 7 | private Out() { 8 | // cannot instantiate 9 | } 10 | 11 | public static final PrintOn puts(Object object) { 12 | out.print(object).cr(); 13 | return out; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Separator.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Separates elements of a collection while printing. Does not require special 5 | * case treatment of first or last element. For example, the following program 6 | * prints a list of its arguments separated by commas, without using any 7 | * conditionals. 8 | * 9 | *
10 |  * Separator s = new Separator(", ");
11 |  * or (String a : args) {
12 |  *    System.out.println(s + a);
13 |  * 
14 |  * 
15 | * 16 | * The implementation of class Separator is straight forward. It 17 | * wraps a string that is returned on every call of toString() except for the 18 | * first call, which returns an empty string. 19 | * 20 | * @author Yossi Gil 21 | * 22 | */ 23 | public class Separator { 24 | 25 | private boolean omitNext; 26 | private final String value; 27 | 28 | public Separator() { 29 | this(", "); 30 | } 31 | 32 | public Separator(String value) { 33 | this.value = value; 34 | this.omitNext = true; 35 | } 36 | 37 | public void reset() { 38 | omitNext = true; 39 | } 40 | 41 | public String toString() { 42 | String $ = omitNext ? "" : value; 43 | omitNext = false; 44 | return $; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Size.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.util.Collection; 4 | import java.util.Enumeration; 5 | import java.util.Iterator; 6 | 7 | /** Returns the size of iterables, useful for testing. 8 | * 9 | * @author Adrian Kuhn 10 | * 11 | */ 12 | public class Size { 13 | 14 | @SuppressWarnings("unchecked") 15 | public static final int of(Iterable collection) { 16 | if (collection instanceof Collection) return ((Collection) collection).size(); 17 | int count = 0; 18 | for (@SuppressWarnings("unused") T each: collection) count++; 19 | return count; 20 | } 21 | 22 | public static final int of(Iterator iterator) { 23 | int count = 0; 24 | while (iterator.hasNext()) count++; 25 | return count; 26 | } 27 | 28 | public static final int of(Enumeration enumeration) { 29 | int count = 0; 30 | while (enumeration.hasMoreElements()) count++; 31 | return count; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Stopwatch.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import java.io.IOException; 4 | 5 | public class Stopwatch { 6 | 7 | private int n = 0; 8 | private long time = Long.MAX_VALUE; 9 | private long collect = 0; 10 | 11 | public void print(String message) { 12 | privatePrint((time - (time = System.nanoTime())) * -1, message); 13 | } 14 | 15 | private void privatePrint(long nanos, String message) { 16 | System.out.print("\t("+n+")"); 17 | if (nanos > 0) System.out.print(" "+(1e-9)*nanos); 18 | if (message != null) System.out.print(" " + message); 19 | System.out.println(); 20 | } 21 | 22 | private static Stopwatch SINGELTON = new Stopwatch(); 23 | 24 | public static void p(String message) { 25 | SINGELTON.print(message); 26 | } 27 | 28 | public static void p() { 29 | SINGELTON.print(null); 30 | } 31 | 32 | public void on() { 33 | time = System.nanoTime(); 34 | } 35 | 36 | public T off(T t) { 37 | collect += (System.nanoTime() - time); 38 | time = 0; 39 | return t; 40 | } 41 | 42 | public void total(String message) { 43 | privatePrint(collect, message); 44 | collect = 0; 45 | } 46 | 47 | public static void enter() { 48 | try { 49 | System.out.print("Press enter: "); 50 | System.in.read(); 51 | } catch (IOException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Tab.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Indents lines while printing them. 5 | * 6 | * @author Adrian Kuhn, 2008/07/21 7 | * @author Thanks to Yossi Gil for suggesting better class and method names. 8 | */ 9 | 10 | public class Tab { 11 | 12 | private String s; 13 | private final String tab; 14 | 15 | public Tab() { 16 | this("\t"); 17 | } 18 | 19 | public Tab(String tab) { 20 | this.tab = tab; 21 | this.s = ""; 22 | } 23 | 24 | public String begin() { 25 | try { 26 | return toString(); 27 | } finally { 28 | this.more(); 29 | } 30 | } 31 | 32 | public String end() { 33 | return this.less().toString(); 34 | } 35 | 36 | public boolean isEmpty() { 37 | return s.length() == 0; 38 | } 39 | 40 | public Tab less() { 41 | if (isEmpty()) throw new IllegalStateException(); 42 | s = s.substring(0, s.length() - tab.length()); 43 | return this; 44 | } 45 | 46 | public Tab more() { 47 | s += tab; 48 | return this; 49 | } 50 | 51 | public String toString() { 52 | return s; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/util/Throw.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | /** 4 | * Throws checked exceptions without the hassle of having to declare them. 5 | * 6 | * @see http://blog.uncommons.org/2008/08/26/more-stupid-java-tricks/ 7 | * 8 | */ 9 | public class Throw { 10 | 11 | @SuppressWarnings("deprecation") 12 | public static RuntimeException exception(Throwable cause) { 13 | if (cause instanceof RuntimeException) throw (RuntimeException) cause; 14 | if (cause instanceof Error) throw (Error) cause; 15 | Thread.currentThread().stop(cause); 16 | throw runtimeException(cause); 17 | } 18 | 19 | public static RuntimeException runtimeException(Throwable cause) { 20 | if (cause instanceof RuntimeException) throw (RuntimeException) cause; 21 | if (cause instanceof Error) throw (Error) cause; 22 | throw new RuntimeException(cause); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/ActionValue.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | import java.util.EventObject; 4 | 5 | public abstract class ActionValue extends ReferenceValue { 6 | 7 | private final Value[] arguments; 8 | 9 | public ActionValue(Value... arguments) { 10 | this.arguments = arguments; 11 | for (Value each: arguments) each.addDependent(this); 12 | this.value = performAction(new Arguments(arguments)); 13 | } 14 | 15 | protected abstract V performAction(Arguments args); 16 | 17 | @Override 18 | public void setValue(V value) { 19 | throw new UnsupportedOperationException(); 20 | } 21 | 22 | public void resetValue() { 23 | value = performAction(new Arguments(arguments)); 24 | this.changed(); 25 | } 26 | 27 | @Override 28 | public void valueChanged(EventObject event) { 29 | this.resetValue(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/Arguments.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | public class Arguments { 4 | 5 | private int index = 0; 6 | private Value[] values; 7 | 8 | public Arguments(Value[] arguments) { 9 | this.index = 0; 10 | this.values = arguments; 11 | } 12 | 13 | @SuppressWarnings("unchecked") 14 | public A nextOrFail() { 15 | if (index >= values.length) return null; 16 | return (A) values[index++].getValueOrFail(); 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public A nextOrNull() { 21 | if (index >= values.length) return null; 22 | return (A) values[index++].getValue(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/BooleanValue.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | public class BooleanValue extends AbstractValue { 4 | 5 | private boolean booleanValue; 6 | 7 | public BooleanValue(boolean initial) { 8 | booleanValue = initial; 9 | } 10 | 11 | @Override 12 | public Throwable getError() { 13 | return null; 14 | } 15 | 16 | @Override 17 | public Boolean getValue() { 18 | return booleanValue; 19 | } 20 | 21 | @Override 22 | public void setValue(Boolean value) { 23 | if (value == null) throw new IllegalArgumentException(); 24 | this.setValue(value.booleanValue()); 25 | } 26 | 27 | public void setValue(boolean bool) { 28 | boolean oldValue = booleanValue; 29 | booleanValue = bool; 30 | if (oldValue != booleanValue) changed(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/IntegerValue.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | public class IntegerValue extends AbstractValue { 4 | 5 | private int intValue; 6 | 7 | public IntegerValue(int initialValue) { 8 | this.intValue = initialValue; 9 | } 10 | 11 | @Override 12 | public Throwable getError() { 13 | return null; 14 | } 15 | 16 | @Override 17 | public Integer getValue() { 18 | return intValue; 19 | } 20 | 21 | public int intValue() { 22 | return intValue; 23 | } 24 | 25 | @Override 26 | public void setValue(Integer value) { 27 | if (value == null) throw new IllegalArgumentException(); 28 | this.setValue(value.intValue()); 29 | } 30 | 31 | public void setValue(int intValue) { 32 | int oldValue = this.intValue; 33 | this.intValue = intValue; 34 | if (oldValue != this.intValue) changed(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/ReferenceValue.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | import java.util.EventObject; 4 | 5 | 6 | public class ReferenceValue extends AbstractValue implements ValueChangedListener { 7 | 8 | protected V value; 9 | 10 | public void setValue(V value) { 11 | V prev = this.value; 12 | this.value = value; 13 | if (!Values.equal(prev, value)) this.changed(); 14 | } 15 | 16 | public ReferenceValue() { 17 | this.value = null; 18 | } 19 | 20 | public ReferenceValue(V value) { 21 | this.value = value; 22 | } 23 | 24 | @Override 25 | public Throwable getError() { 26 | return null; 27 | } 28 | 29 | @Override 30 | public void setError(Throwable error) { 31 | throw new UnsupportedOperationException(); 32 | } 33 | 34 | @Override 35 | public V getValue() { 36 | return value; 37 | } 38 | 39 | @Override 40 | public void valueChanged(EventObject event) { 41 | // ignore 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/TaskFactory.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | import ch.akuhn.util.ProgressMonitor; 4 | 5 | public class TaskFactory { 6 | 7 | public Task makeTask() { 8 | return new Task() { 9 | 10 | @Override 11 | public void start(Callback callback) { 12 | callback.run(ProgressMonitor.NULL); 13 | } 14 | 15 | @Override 16 | public void stop() { 17 | // ignore 18 | } 19 | 20 | }; 21 | } 22 | 23 | public interface Callback { 24 | 25 | public String getName(); 26 | public Throwable run(ProgressMonitor monitor); 27 | 28 | } 29 | 30 | public interface Task { 31 | 32 | public void start(Callback callback); 33 | public void stop(); 34 | 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/Value.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | public interface Value { 4 | 5 | public V getValue(); 6 | 7 | public Throwable getError(); 8 | 9 | public ImmutableValue asImmutable(); 10 | 11 | public void setValue(V value); 12 | 13 | public void setError(Throwable error); 14 | 15 | public boolean isError(); 16 | 17 | public V getValueOrFail(); 18 | 19 | public void addDependent(ValueChangedListener dependent); 20 | 21 | public void removeDependent(ValueChangedListener dependent); 22 | 23 | } -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/ValueChangedListener.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | import java.util.EventListener; 4 | import java.util.EventObject; 5 | 6 | public interface ValueChangedListener extends EventListener { 7 | 8 | public void valueChanged(EventObject event); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch.akuhn.util/src/ch/akuhn/values/Values.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.values; 2 | 3 | public class Values { 4 | 5 | public static boolean equal(Object a, Object b) { 6 | return a == null ? b == null : a.equals(b); 7 | } 8 | 9 | public static Error throwError(Throwable error) { 10 | if (error instanceof Error) throw (Error) error; 11 | if (error instanceof RuntimeException) throw (RuntimeException) error; 12 | throw new RuntimeException(error); 13 | } 14 | 15 | public static Value of(V object) { 16 | return new ReferenceValue(object); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ch.akuhn.util/test/ch/akuhn/util/AssertionsEnabledTest.java: -------------------------------------------------------------------------------- 1 | 2 | package ch.akuhn.util; 3 | 4 | import org.junit.Test; 5 | 6 | public class AssertionsEnabledTest { 7 | 8 | @Test(expected = AssertionError.class) 9 | public void assetionsEnabled() { 10 | assert false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch.akuhn.util/test/ch/akuhn/util/DefaultsTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.lang.reflect.Constructor; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | import org.junit.Test; 9 | 10 | public class DefaultsTest { 11 | 12 | @Test(expected = InvocationTargetException.class) 13 | public void cannotInstantiate() throws Exception { 14 | Constructor init = Defaults.class.getDeclaredConstructor(); 15 | init.setAccessible(true); 16 | init.newInstance(); 17 | } 18 | 19 | @Test 20 | public void testInteger() { 21 | Integer n = 23; 22 | assertEquals(23, Defaults.to(n, 42)); 23 | } 24 | 25 | @Test 26 | public void testNull() { 27 | String answer = null; 28 | assertEquals("A", Defaults.to(answer, "A")); 29 | } 30 | 31 | @Test 32 | public void testNullInteger() { 33 | Integer n = null; 34 | assertEquals(42, Defaults.to(n, 42)); 35 | } 36 | 37 | @Test 38 | public void testValue() { 39 | String answer = "B"; 40 | assertEquals("B", Defaults.to(answer, "A")); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ch.akuhn.util/test/ch/akuhn/util/SeparatorTest.java: -------------------------------------------------------------------------------- 1 | package ch.akuhn.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | public class SeparatorTest { 8 | 9 | @Test 10 | public void defaultValue() { 11 | Separator s = new Separator(); 12 | assertEquals("", s.toString()); 13 | assertEquals(", ", s.toString()); 14 | assertEquals(", ", s.toString()); 15 | assertEquals(", ", s.toString()); 16 | } 17 | 18 | @Test 19 | public void testReset() { 20 | Separator s = new Separator("abc"); 21 | assertEquals("", s.toString()); 22 | assertEquals("abc", s.toString()); 23 | assertEquals("abc", s.toString()); 24 | s.reset(); 25 | assertEquals("", s.toString()); 26 | assertEquals("abc", s.toString()); 27 | assertEquals("abc", s.toString()); 28 | } 29 | 30 | @Test 31 | public void testSequence() { 32 | Separator s = new Separator("abc"); 33 | assertEquals("", s.toString()); 34 | assertEquals("abc", s.toString()); 35 | assertEquals("abc", s.toString()); 36 | assertEquals("abc", s.toString()); 37 | assertEquals("abc", s.toString()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.example.lawofdemeter 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/.settings/org.codemap.points.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jan 18 11:23:12 CET 2010 2 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/IJavaElementVisitor.java=0.05@0.4853953685112276 3 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/LawOfDemeter.java=0.7093057525870233@0.7585707706149254 4 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/MyCompilationParticipant.java=0.1110263370770958@0.7628047642417873 5 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/MyElementChangedListener.java=0.4950451968893632@0.9500000000000001 6 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/model/Field.java=0.5977162867950356@0.06019303110298668 7 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/model/Method.java=0.4423670469257487@0.05 8 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/model/Type.java=0.17111948626896106@0.060738280049782496 9 | ///com.example.lawofdemeter/src/com/example/lawofdemeter/views/SampleView.java=0.9500000000000001@0.46141930858061897 10 | eclipse.preferences.version=1 11 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/.settings/org.codemap.ui.mapview.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jan 18 11:23:12 CET 2010 2 | eclipse.preferences.version=1 3 | org.codemap.call_hierarchy=true 4 | org.codemap.coloring=HEATMAP 5 | org.codemap.labeling=NONE 6 | org.codemap.marker=false 7 | org.codemap.search_results=true 8 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Mon Jan 18 01:12:45 CET 2010 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Lawofdemeter 4 | Bundle-SymbolicName: com.example.lawofdemeter;singleton:=true 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Activator: com.example.lawofdemeter.LawOfDemeter 7 | Bundle-Vendor: Adrian Kuhn 8 | Require-Bundle: org.eclipse.ui, 9 | org.eclipse.core.runtime, 10 | org.eclipse.jdt.core, 11 | org.eclipse.ui, 12 | org.eclipse.core.runtime, 13 | org.eclipse.core.resources 14 | Bundle-RequiredExecutionEnvironment: JavaSE-1.6 15 | Bundle-ActivationPolicy: lazy 16 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | . 6 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 10 | 11 | 16 | 17 | 18 | 20 | 22 | 23 | 24 | 26 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/src/com/example/lawofdemeter/MyElementChangedListener.java: -------------------------------------------------------------------------------- 1 | package com.example.lawofdemeter; 2 | 3 | import org.eclipse.jdt.core.ElementChangedEvent; 4 | import org.eclipse.jdt.core.IElementChangedListener; 5 | import org.eclipse.jdt.core.IJavaElementDelta; 6 | 7 | public class MyElementChangedListener implements IElementChangedListener { 8 | 9 | @Override 10 | public void elementChanged(ElementChangedEvent event) { 11 | IJavaElementDelta delta = event.getDelta(); 12 | //System.out.println(delta); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/src/com/example/lawofdemeter/model/Field.java: -------------------------------------------------------------------------------- 1 | package com.example.lawofdemeter.model; 2 | 3 | public class Field { 4 | 5 | private String name; 6 | 7 | private Type type; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public Field() { 14 | } 15 | 16 | public void setType(Type type) { 17 | this.type = type; 18 | } 19 | 20 | public Type getType() { 21 | return type; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/src/com/example/lawofdemeter/model/Method.java: -------------------------------------------------------------------------------- 1 | package com.example.lawofdemeter.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.Collection; 6 | 7 | public class Method { 8 | 9 | private String name; 10 | 11 | private Type returnType; 12 | 13 | private Collection parameterTypes; 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public Method() { 20 | this.parameterTypes = new ArrayList(); 21 | } 22 | 23 | public Iterable parameterTypes() { 24 | return parameterTypes; 25 | } 26 | 27 | public void setReturnType(Type returnType) { 28 | this.returnType = returnType; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public Type getReturnType() { 36 | return returnType; 37 | } 38 | 39 | public void setParameterTypes(Type... parameterTypes) { 40 | this.parameterTypes = Arrays.asList(parameterTypes); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/src/com/example/lawofdemeter/model/Model.java: -------------------------------------------------------------------------------- 1 | package com.example.lawofdemeter.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Model { 7 | 8 | private Map map; 9 | 10 | public Model() { 11 | this.map = new HashMap(); 12 | } 13 | 14 | public Type get(Object key) { 15 | Type type = map.get(key); 16 | if (type == null) map.put(key, type = new Type()); 17 | return type; 18 | } 19 | 20 | public void remove(Object key) { 21 | map.remove(key); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /com.example.lawofdemeter/src/com/example/lawofdemeter/views/SampleView.java: -------------------------------------------------------------------------------- 1 | package com.example.lawofdemeter.views; 2 | 3 | import org.eclipse.swt.SWT; 4 | import org.eclipse.swt.widgets.Composite; 5 | import org.eclipse.swt.widgets.Text; 6 | import org.eclipse.ui.part.*; 7 | 8 | 9 | public class SampleView extends ViewPart { 10 | 11 | private Text text; 12 | 13 | @Override 14 | public void createPartControl(Composite parent) { 15 | text = new Text(parent, SWT.MULTI | SWT.READ_ONLY); 16 | text.append("Hello Kitty!"); 17 | } 18 | 19 | @Override 20 | public void setFocus() { 21 | 22 | } 23 | 24 | public void append(String string) { 25 | text.append(string); 26 | text.append("\n"); 27 | }; 28 | 29 | } -------------------------------------------------------------------------------- /org.codemap.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codemap.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | org.codemap.HapaxBuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.pde.FeatureNature 21 | 22 | 23 | -------------------------------------------------------------------------------- /org.codemap.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml,\ 2 | feature.properties 3 | -------------------------------------------------------------------------------- /org.codemap.test/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /org.codemap.test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codemap.test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | ch.unibe.softwaremap.HapaxBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.pde.PluginNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /org.codemap.test/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jun 18 16:36:09 CEST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 8 | org.eclipse.jdt.core.compiler.source=1.6 9 | -------------------------------------------------------------------------------- /org.codemap.test/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Softwaremap Tests 4 | Bundle-SymbolicName: org.codemap.test 5 | Bundle-Version: 1.0.0.qualifier 6 | Fragment-Host: org.codemap 7 | Require-Bundle: org.junit4;bundle-version="4.5.0", 8 | org.eclipse.jdt.launching;bundle-version="3.5.0" 9 | Bundle-ClassPath: lib/jexample-r285.jar, 10 | . 11 | -------------------------------------------------------------------------------- /org.codemap.test/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | lib/jexample-r285.jar 6 | -------------------------------------------------------------------------------- /org.codemap.test/lib/jexample-r285.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap.test/lib/jexample-r285.jar -------------------------------------------------------------------------------- /org.codemap.test/src/ch/unibe/softwaremap/BaseTest.java: -------------------------------------------------------------------------------- 1 | package ch.unibe.softwaremap; 2 | 3 | import org.eclipse.core.runtime.jobs.Job; 4 | import org.eclipse.swt.widgets.Display; 5 | 6 | public abstract class BaseTest { 7 | 8 | /** 9 | * Process UI input but do not return for the specified time interval. 10 | * 11 | * @param waitTimeMillis the number of milliseconds 12 | */ 13 | protected static void delay(long waitTimeMillis) { 14 | Display display = Display.getCurrent(); 15 | // If this is the UI thread, 16 | // then process input. 17 | 18 | if (display != null) { 19 | long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; 20 | while (System.currentTimeMillis() < endTimeMillis) { 21 | display.readAndDispatch(); 22 | // just busy wait as sleep() seems to block until some input is recieved (e.g. mouse moved) 23 | // if (!display.readAndDispatch()) 24 | // display.sleep(); 25 | } 26 | display.update(); 27 | } 28 | // Otherwise, perform a simple sleep. 29 | 30 | else { 31 | try { 32 | Thread.sleep(waitTimeMillis); 33 | } catch (InterruptedException e) { 34 | // Ignored. 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * Wait until all background tasks are complete. 41 | */ 42 | public static void waitForJobs() { 43 | while (!Job.getJobManager().isIdle()) 44 | delay(65); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /org.codemap.update/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codemap.update 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.UpdateSiteBuilder 10 | 11 | 12 | 13 | 14 | org.codemap.HapaxBuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.pde.UpdateSiteNature 21 | 22 | 23 | -------------------------------------------------------------------------------- /org.codemap.update/ant-clean.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /org.codemap.update/ant-upload.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /org.codemap.update/site_qualifier.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Software Cartography, your roadmap to software. 9 | 10 | 11 | -------------------------------------------------------------------------------- /org.codemap/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /org.codemap/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codemap 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /org.codemap/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sun Apr 26 23:21:21 CEST 2009 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /org.codemap/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Tue Nov 17 13:32:41 CET 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /org.codemap/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Tue Nov 17 13:38:28 CET 2009 2 | cleanup_settings_version=2 3 | eclipse.preferences.version=1 4 | formatter_settings_version=11 5 | -------------------------------------------------------------------------------- /org.codemap/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | #Tue Nov 17 13:32:39 CET 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 4 | -------------------------------------------------------------------------------- /org.codemap/.settings/org.eclipse.wst.html.core.prefs: -------------------------------------------------------------------------------- 1 | #Wed Nov 11 16:22:43 CET 2009 2 | attrDuplicate=2 3 | attrInvalidName=2 4 | attrInvalidValue=2 5 | attrNameMismatch=2 6 | attrUndefName=2 7 | attrUndefValue=2 8 | attrValueMismatch=1 9 | attrValueUnclosed=2 10 | cdataInvalidContent=2 11 | cdataUnclosed=1 12 | commentInvalidContent=2 13 | commentUnclosed=1 14 | docDoctypeUnclosed=1 15 | docDuplicateTag=1 16 | docInvalidChar=2 17 | docInvalidContent=2 18 | eclipse.preferences.version=1 19 | elemCoexistence=2 20 | elemDuplicate=2 21 | elemEndInvalidCase=1 22 | elemInvalidContent=2 23 | elemInvalidDirective=1 24 | elemInvalidEmptyTag=2 25 | elemInvalidName=1 26 | elemMissingEnd=2 27 | elemMissingStart=2 28 | elemStartInvalidCase=2 29 | elemUnclosedEndTag=1 30 | elemUnclosedStartTag=1 31 | elemUnknownName=2 32 | elemUnnecessaryEnd=2 33 | piInvalidContent=2 34 | piUnclosed=1 35 | piUndefined=2 36 | refInvalidContent=2 37 | -------------------------------------------------------------------------------- /org.codemap/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = plugin.xml,\ 4 | icons/,\ 5 | .,\ 6 | META-INF/,\ 7 | intro/,\ 8 | lib/jexample-4.4-r281.jar 9 | bin.excludes = intro/codemapintro.md 10 | 11 | -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/call_hierarchy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/call_hierarchy.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/coverage.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/coverage.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/error_obj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/error_obj.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/file.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/file.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/flow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/flow.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/force_selection.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/force_selection.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/green_circle.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/green_circle.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/info_obj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/info_obj.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/labels.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/labels.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/layers.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/layers.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/linked.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/linked.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/markers.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/markers.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/meeple.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/meeple.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/packages.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/packages.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/palette.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/palette.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/search.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/search.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/selection.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/selection.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/trace.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/trace.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/warning_obj.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/warning_obj.gif -------------------------------------------------------------------------------- /org.codemap/icons/eclipse/youarehere.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/eclipse/youarehere.gif -------------------------------------------------------------------------------- /org.codemap/icons/sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons/sample.gif -------------------------------------------------------------------------------- /org.codemap/icons_dev/codemap_noshadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons_dev/codemap_noshadow.png -------------------------------------------------------------------------------- /org.codemap/icons_dev/codemap_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/icons_dev/codemap_shadow.png -------------------------------------------------------------------------------- /org.codemap/intro/codemapintro.html: -------------------------------------------------------------------------------- 1 |

Launching Codemap View

2 |

The main feature of Codemap is the Codemap View displaying the acutal map of your code.

3 |

To activate Codemap View go to "Window" → "Show View" → "Other..." and select our view "Codemap View" in the category 4 | "Codemap".

5 |

open codemap

6 |

That's it ... the Codemap View should appear in your IDE.

7 |

open codemap

-------------------------------------------------------------------------------- /org.codemap/intro/codemapintro.md: -------------------------------------------------------------------------------- 1 | ## Launching Codemap View 2 | 3 | The main feature of Codemap is the Codemap View displaying the acutal map of your code. 4 | 5 | To activate Codemap View go to "Window" → "Show View" → "Other..." and select our view "Codemap View" in the category 6 | "Codemap". 7 | 8 | ![open codemap](images/open_codemap.png open codemap left) 9 | 10 | That's it ... the Codemap View should appear in your IDE. 11 | 12 | ![open codemap](images/codemap_view.png open codemap left) -------------------------------------------------------------------------------- /org.codemap/intro/css/overview.css: -------------------------------------------------------------------------------- 1 | a#codmeapIntroLink img { 2 | background-image: url(../images/codemap_shadow.png); 3 | } 4 | 5 | a#codmeapIntroLink:hover img { 6 | background-image: url(../images/codemap_noshadow.png); 7 | } 8 | 9 | #codmeapIntroLinkGroup { 10 | background-color: #FEF7DA; 11 | } -------------------------------------------------------------------------------- /org.codemap/intro/images/codemap_noshadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/intro/images/codemap_noshadow.png -------------------------------------------------------------------------------- /org.codemap/intro/images/codemap_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/intro/images/codemap_shadow.png -------------------------------------------------------------------------------- /org.codemap/intro/images/codemap_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/intro/images/codemap_view.png -------------------------------------------------------------------------------- /org.codemap/intro/images/open_codemap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/intro/images/open_codemap.png -------------------------------------------------------------------------------- /org.codemap/intro/overviewExtensionContent.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | Learn how to use Codemap 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /org.codemap/lib/jexample-4.4-r281.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akuhn/codemap/aab54f10dab8bcbdfdbb16015fd0f43996ded99f/org.codemap/lib/jexample-4.4-r281.jar -------------------------------------------------------------------------------- /org.codemap/src/edu/stanford/hci/flowmap/cluster/FlowLayout.java: -------------------------------------------------------------------------------- 1 | package edu.stanford.hci.flowmap.cluster; 2 | 3 | import java.util.Collection; 4 | 5 | import edu.stanford.hci.flowmap.structure.Node; 6 | 7 | 8 | /** 9 | * Abstract class for running a layout algorithm on a collection of nodes. 10 | * What layout means in this instance is constructing a Flow Tree from a collection 11 | * of nodes that have already been positioned with a NodeLayout and a ForceLayout. 12 | * 13 | * This software is distributed under the Berkeley Software Distribution License. 14 | * Please see http://graphics.stanford.edu/~dphan/code/bsd.license.html 15 | * 16 | */ 17 | public abstract class FlowLayout { 18 | protected Node source; 19 | protected Collection allNodes; 20 | 21 | public FlowLayout(Node source, Collection allNodes) { 22 | this.source = source; 23 | this.allNodes = allNodes; 24 | } 25 | 26 | /** 27 | * Runs the layout algorithm on the given FlowRecord using the FlowScale operator 28 | * @return the source node. 29 | */ 30 | public abstract Node doLayout(); 31 | } 32 | -------------------------------------------------------------------------------- /org.codemap/src/edu/stanford/hci/flowmap/utils/Pair.java: -------------------------------------------------------------------------------- 1 | package edu.stanford.hci.flowmap.utils; 2 | 3 | 4 | /** 5 | * This software is distributed under the Berkeley Software Distribution License. 6 | * Please see http://graphics.stanford.edu/~dphan/code/bsd.license.html 7 | * 8 | */ 9 | public class Pair { 10 | 11 | public Object one; 12 | public Object two; 13 | 14 | public Pair() { 15 | one = two = null; 16 | } 17 | 18 | public Pair(Object a, Object b) { 19 | one = a; 20 | two = b; 21 | } 22 | 23 | public boolean equals(Object o) { 24 | Pair p = (Pair) o; 25 | if ((one != null) && (p.one != null) && (two != null) && (p.two != null)) 26 | return (one.equals(p.one) && two.equals(p.two)); 27 | else 28 | return false; 29 | } 30 | 31 | public String toString() { 32 | StringBuilder sb = new StringBuilder(); 33 | sb.append("("); 34 | sb.append(one.toString()); 35 | sb.append(","); 36 | sb.append(two.toString()); 37 | sb.append(")"); 38 | return sb.toString(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /org.codemap/src/org/codemap/DefaultLabelScheme.java: -------------------------------------------------------------------------------- 1 | package org.codemap; 2 | 3 | import org.codemap.util.MapScheme; 4 | 5 | 6 | public class DefaultLabelScheme extends MapScheme { 7 | 8 | @Override 9 | public String forLocation(Point location) { 10 | // assumes the document names are paths 11 | String name = location.getDocument(); 12 | int lastPathSeparator = Math.max(name.lastIndexOf('\\'), name.lastIndexOf('/')); 13 | int lastDot = name.lastIndexOf('.'); 14 | if (lastPathSeparator < lastDot) return name.substring(lastPathSeparator + 1, lastDot); 15 | return name; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /org.codemap/src/org/codemap/DigitalElevationModel.java: -------------------------------------------------------------------------------- 1 | package org.codemap; 2 | 3 | public class DigitalElevationModel { 4 | 5 | private float[][] DEM; 6 | 7 | public DigitalElevationModel(float[][] DEM) { 8 | this.DEM = DEM; 9 | } 10 | 11 | public float[][] asFloatArray() { 12 | return DEM; 13 | } 14 | 15 | public int getSize() { 16 | return DEM.length; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /org.codemap/src/org/codemap/HillShading.java: -------------------------------------------------------------------------------- 1 | package org.codemap; 2 | 3 | 4 | public class HillShading { 5 | 6 | private double[][] hillShading; 7 | 8 | public HillShading(double[][] hillShading) { 9 | this.hillShading = hillShading; 10 | } 11 | 12 | public double[][] asDoubleArray() { 13 | return hillShading; 14 | } 15 | 16 | public int getSize() { 17 | return hillShading.length; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /org.codemap/src/org/codemap/Labeling.java: -------------------------------------------------------------------------------- 1 | package org.codemap; 2 | 3 | import org.codemap.layers.Label; 4 | 5 | public class Labeling { 6 | 7 | private Iterable